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 |
11 #include "GrColor.h" | 11 #include "GrColor.h" |
| 12 #include "GrGeometryData.h" |
12 #include "GrProcessor.h" | 13 #include "GrProcessor.h" |
13 #include "GrShaderVar.h" | 14 #include "GrShaderVar.h" |
14 | 15 |
15 /* | 16 /* |
16 * The GrPrimitiveProcessor represents some kind of geometric primitive. This i
ncludes the shape | 17 * The GrPrimitiveProcessor represents some kind of geometric primitive. This i
ncludes the shape |
17 * of the primitive and the inherent color of the primitive. The GrPrimitivePro
cessor is | 18 * of the primitive and the inherent color of the primitive. The GrPrimitivePro
cessor is |
18 * responsible for providing a color and coverage input into the Ganesh renderin
g pipeline. Through | 19 * responsible for providing a color and coverage input into the Ganesh renderin
g pipeline. Through |
19 * optimization, Ganesh may decide a different color, no color, and / or no cove
rage are required | 20 * optimization, Ganesh may decide a different color, no color, and / or no cove
rage are required |
20 * from the GrPrimitiveProcessor, so the GrPrimitiveProcessor must be able to su
pport this | 21 * from the GrPrimitiveProcessor, so the GrPrimitiveProcessor must be able to su
pport this |
21 * functionality. We also use the GrPrimitiveProcessor to make batching decisio
ns. | 22 * functionality. We also use the GrPrimitiveProcessor to make batching decisio
ns. |
(...skipping 16 matching lines...) Expand all Loading... |
38 * it draws. Each primitive draw will bundle all required data to perform the d
raw, and these | 39 * 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 | 40 * 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 | 41 * 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 | 42 * 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. | 43 * it emits the appropriate color, or none at all, as directed. |
43 */ | 44 */ |
44 | 45 |
45 /* | 46 /* |
46 * A struct for tracking batching decisions. While this lives on GrOptState, it
is managed | 47 * A struct for tracking batching decisions. While this lives on GrOptState, it
is managed |
47 * entirely by the derived classes of the GP. | 48 * 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 */ | 49 */ |
51 class GrBatchTracker { | 50 class GrBatchTracker { |
52 public: | 51 public: |
53 template <typename T> const T& cast() const { | 52 template <typename T> const T& cast() const { |
54 SkASSERT(sizeof(T) <= kMaxSize); | 53 SkASSERT(sizeof(T) <= kMaxSize); |
55 return *reinterpret_cast<const T*>(fData.get()); | 54 return *reinterpret_cast<const T*>(fData.get()); |
56 } | 55 } |
57 | 56 |
58 template <typename T> T* cast() { | 57 template <typename T> T* cast() { |
59 SkASSERT(sizeof(T) <= kMaxSize); | 58 SkASSERT(sizeof(T) <= kMaxSize); |
60 return reinterpret_cast<T*>(fData.get()); | 59 return reinterpret_cast<T*>(fData.get()); |
61 } | 60 } |
62 | 61 |
63 static const size_t kMaxSize = 32; | 62 static const size_t kMaxSize = 32; |
64 | 63 |
65 private: | 64 private: |
66 SkAlignedSStorage<kMaxSize> fData; | 65 SkAlignedSStorage<kMaxSize> fData; |
67 }; | 66 }; |
68 | 67 |
69 class GrIndexBufferAllocPool; | |
70 class GrGLCaps; | 68 class GrGLCaps; |
71 class GrGLPrimitiveProcessor; | 69 class GrGLPrimitiveProcessor; |
72 class GrVertexBufferAllocPool; | 70 class GrOptDrawState; |
73 | 71 |
74 struct GrInitInvariantOutput; | 72 struct GrInitInvariantOutput; |
75 | 73 |
76 /* | |
77 * This struct allows the GrPipeline to communicate information about the pipeli
ne. Most of this | |
78 * is overrides, but some of it is general information. Logically it should liv
e in GrPipeline.h, | |
79 * but this is problematic due to circular dependencies. | |
80 */ | |
81 struct GrPipelineInfo { | |
82 bool fColorIgnored; | |
83 bool fCoverageIgnored; | |
84 GrColor fOverrideColor; | |
85 bool fUsesLocalCoords; | |
86 }; | |
87 | 74 |
88 /* | 75 /* |
89 * This enum is shared by GrPrimitiveProcessors and GrGLPrimitiveProcessors to c
oordinate shaders | 76 * This enum is shared by GrPrimitiveProcessors and GrGLPrimitiveProcessors to c
oordinate shaders |
90 * with vertex attributes / uniforms. | 77 * with vertex attributes / uniforms. |
91 */ | 78 */ |
92 enum GrGPInput { | 79 enum GrGPInput { |
93 kAllOnes_GrGPInput, | 80 kAllOnes_GrGPInput, |
94 kAttribute_GrGPInput, | 81 kAttribute_GrGPInput, |
95 kUniform_GrGPInput, | 82 kUniform_GrGPInput, |
96 kIgnored_GrGPInput, | 83 kIgnored_GrGPInput, |
97 }; | 84 }; |
98 | 85 |
99 /* | 86 /* |
100 * GrPrimitiveProcessor defines an interface which all subclasses must implement
. All | 87 * GrPrimitiveProcessor defines an interface which all subclasses must implement
. All |
101 * 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 |
102 * pipelines, and they must provide some notion of equality | 89 * pipelines, and they must provide some notion of equality |
103 */ | 90 */ |
104 class GrPrimitiveProcessor : public GrProcessor { | 91 class GrPrimitiveProcessor : public GrProcessor { |
105 public: | 92 public: |
106 // 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 |
107 // bundle of primitive data | 94 // bundle of primitive data |
108 const SkMatrix& viewMatrix() const { return fViewMatrix; } | 95 const SkMatrix& viewMatrix() const { return fViewMatrix; } |
109 const SkMatrix& localMatrix() const { return fLocalMatrix; } | 96 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
110 | 97 |
111 virtual void initBatchTracker(GrBatchTracker*, const GrPipelineInfo&) const
= 0; | 98 /* |
| 99 * This struct allows the optstate to communicate requirements to the GrPrim
itiveProcessor. |
| 100 */ |
| 101 struct InitBT { |
| 102 bool fColorIgnored; |
| 103 bool fCoverageIgnored; |
| 104 GrColor fOverrideColor; |
| 105 bool fUsesLocalCoords; |
| 106 }; |
| 107 |
| 108 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const = 0; |
112 | 109 |
113 virtual bool canMakeEqual(const GrBatchTracker& mine, | 110 virtual bool canMakeEqual(const GrBatchTracker& mine, |
114 const GrPrimitiveProcessor& that, | 111 const GrPrimitiveProcessor& that, |
115 const GrBatchTracker& theirs) const = 0; | 112 const GrBatchTracker& theirs) const = 0; |
116 | 113 |
117 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; | 114 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; |
118 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const =
0; | 115 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const =
0; |
119 | 116 |
120 // Only the GrGeometryProcessor subclass actually has a geo shader or vertex
attributes, but | 117 // Only the GrGeometryProcessor subclass actually has a geo shader or vertex
attributes, but |
121 // we put these calls on the base class to prevent having to cast | 118 // we put these calls on the base class to prevent having to cast |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 /* | 297 /* |
301 * An optional simple helper function to determine by what means the GrGeome
tryProcessor should | 298 * An optional simple helper function to determine by what means the GrGeome
tryProcessor should |
302 * use to provide color. If we are given an override color(ie the given ove
rridecolor is NOT | 299 * use to provide color. If we are given an override color(ie the given ove
rridecolor is NOT |
303 * GrColor_ILLEGAL) then we must always emit that color(currently overrides
are only supported | 300 * GrColor_ILLEGAL) then we must always emit that color(currently overrides
are only supported |
304 * via uniform, but with deferred Geometry we could use attributes). Otherw
ise, if our color is | 301 * via uniform, but with deferred Geometry we could use attributes). Otherw
ise, if our color is |
305 * ignored then we should not emit a color. Lastly, if we don't have vertex
colors then we must | 302 * ignored then we should not emit a color. Lastly, if we don't have vertex
colors then we must |
306 * emit a color via uniform | 303 * emit a color via uniform |
307 * TODO this function changes quite a bit with deferred geometry. There the
GrGeometryProcessor | 304 * TODO this function changes quite a bit with deferred geometry. There the
GrGeometryProcessor |
308 * can upload a new color via attribute if needed. | 305 * can upload a new color via attribute if needed. |
309 */ | 306 */ |
310 static GrGPInput GetColorInputType(GrColor* color, GrColor primitiveColor, | 307 static GrGPInput GetColorInputType(GrColor* color, GrColor primitiveColor, c
onst InitBT& init, |
311 const GrPipelineInfo& init, | |
312 bool hasVertexColor) { | 308 bool hasVertexColor) { |
313 if (init.fColorIgnored) { | 309 if (init.fColorIgnored) { |
314 *color = GrColor_ILLEGAL; | 310 *color = GrColor_ILLEGAL; |
315 return kIgnored_GrGPInput; | 311 return kIgnored_GrGPInput; |
316 } else if (GrColor_ILLEGAL != init.fOverrideColor) { | 312 } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
317 *color = init.fOverrideColor; | 313 *color = init.fOverrideColor; |
318 return kUniform_GrGPInput; | 314 return kUniform_GrGPInput; |
319 } | 315 } |
320 | 316 |
321 *color = primitiveColor; | 317 *color = primitiveColor; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 * extending this class to handle all nvpr uniform / varying / program work. | 371 * extending this class to handle all nvpr uniform / varying / program work. |
376 */ | 372 */ |
377 class GrPathProcessor : public GrPrimitiveProcessor { | 373 class GrPathProcessor : public GrPrimitiveProcessor { |
378 public: | 374 public: |
379 static GrPathProcessor* Create(GrColor color, | 375 static GrPathProcessor* Create(GrColor color, |
380 const SkMatrix& viewMatrix = SkMatrix::I(), | 376 const SkMatrix& viewMatrix = SkMatrix::I(), |
381 const SkMatrix& localMatrix = SkMatrix::I())
{ | 377 const SkMatrix& localMatrix = SkMatrix::I())
{ |
382 return SkNEW_ARGS(GrPathProcessor, (color, viewMatrix, localMatrix)); | 378 return SkNEW_ARGS(GrPathProcessor, (color, viewMatrix, localMatrix)); |
383 } | 379 } |
384 | 380 |
385 void initBatchTracker(GrBatchTracker*, const GrPipelineInfo&) const SK_OVERR
IDE; | 381 void initBatchTracker(GrBatchTracker*, const InitBT&) const SK_OVERRIDE; |
386 | 382 |
387 bool canMakeEqual(const GrBatchTracker& mine, | 383 bool canMakeEqual(const GrBatchTracker& mine, |
388 const GrPrimitiveProcessor& that, | 384 const GrPrimitiveProcessor& that, |
389 const GrBatchTracker& theirs) const SK_OVERRIDE; | 385 const GrBatchTracker& theirs) const SK_OVERRIDE; |
390 | 386 |
391 const char* name() const SK_OVERRIDE { return "PathProcessor"; } | 387 const char* name() const SK_OVERRIDE { return "PathProcessor"; } |
392 | 388 |
393 GrColor color() const { return fColor; } | 389 GrColor color() const { return fColor; } |
394 | 390 |
395 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; | 391 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
(...skipping 13 matching lines...) Expand all Loading... |
409 | 405 |
410 private: | 406 private: |
411 bool hasExplicitLocalCoords() const SK_OVERRIDE { return false; } | 407 bool hasExplicitLocalCoords() const SK_OVERRIDE { return false; } |
412 | 408 |
413 GrColor fColor; | 409 GrColor fColor; |
414 | 410 |
415 typedef GrPrimitiveProcessor INHERITED; | 411 typedef GrPrimitiveProcessor INHERITED; |
416 }; | 412 }; |
417 | 413 |
418 #endif | 414 #endif |
OLD | NEW |