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