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 "GrGeometryData.h" | 11 #include "GrGeometryData.h" |
12 #include "GrProcessor.h" | 12 #include "GrProcessor.h" |
13 #include "GrShaderVar.h" | 13 #include "GrShaderVar.h" |
14 | 14 |
15 /* | 15 /* |
16 * A struct for tracking batching decisions. While this lives on GrOptState, it
is managed | 16 * A struct for tracking batching decisions. While this lives on GrOptState, it
is managed |
17 * entirely by the derived classes of the GP. | 17 * entirely by the derived classes of the GP. |
18 */ | 18 */ |
19 class GrBatchTracker { | 19 class GrBatchTracker { |
20 public: | 20 public: |
21 template <typename T> const T& cast() const { | 21 template <typename T> const T& cast() const { |
22 SkASSERT(sizeof(T) <= kMaxSize); | 22 SkASSERT(sizeof(T) <= kMaxSize); |
23 return *reinterpret_cast<const T*>(fData); | 23 return *reinterpret_cast<const T*>(fData.get()); |
24 } | 24 } |
25 | 25 |
26 template <typename T> T* cast() { | 26 template <typename T> T* cast() { |
27 SkASSERT(sizeof(T) <= kMaxSize); | 27 SkASSERT(sizeof(T) <= kMaxSize); |
28 return reinterpret_cast<T*>(fData); | 28 return reinterpret_cast<T*>(fData.get()); |
29 } | 29 } |
30 | 30 |
31 static const size_t kMaxSize = 32; | 31 static const size_t kMaxSize = 32; |
32 | 32 |
33 private: | 33 private: |
34 uint8_t fData[kMaxSize]; | 34 mutable SkAlignedSStorage<kMaxSize> fData; |
35 }; | 35 }; |
36 | 36 |
37 class GrGLCaps; | 37 class GrGLCaps; |
38 class GrGLGeometryProcessor; | 38 class GrGLGeometryProcessor; |
39 class GrOptDrawState; | 39 class GrOptDrawState; |
40 | 40 |
41 /** | 41 /** |
42 * A GrGeometryProcessor is used to perform computation in the vertex shader and | 42 * A GrGeometryProcessor is used to perform computation in the vertex shader and |
43 * add support for custom vertex attributes. A GrGemeotryProcessor is typically | 43 * add support for custom vertex attributes. A GrGemeotryProcessor is typically |
44 * tied to the code that does a specific type of high-level primitive rendering | 44 * tied to the code that does a specific type of high-level primitive rendering |
45 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw
is | 45 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw
is |
46 * specified using GrDrawState. There can only be one geometry processor active
for | 46 * specified using GrDrawState. There can only be one geometry processor active
for |
47 * a draw. The custom vertex attributes required by the geometry processor must
be | 47 * a draw. The custom vertex attributes required by the geometry processor must
be |
48 * added to the vertex attribute array specified on the GrDrawState. | 48 * added to the vertex attribute array specified on the GrDrawState. |
49 * GrGeometryProcessor subclasses should be immutable after construction. | 49 * GrGeometryProcessor subclasses should be immutable after construction. |
50 */ | 50 */ |
51 class GrGeometryProcessor : public GrProcessor { | 51 class GrGeometryProcessor : public GrProcessor { |
52 public: | 52 public: |
53 GrGeometryProcessor() | 53 GrGeometryProcessor() |
54 : fVertexStride(0) | 54 : /*TODO HACK*/fNewStyle(false), fVertexStride(0) |
55 , fWillUseGeoShader(false) | 55 , fWillUseGeoShader(false) |
56 , fHasVertexColor(false) | 56 , fHasVertexColor(false) |
57 , fHasVertexCoverage(false) | 57 , fHasVertexCoverage(false) |
58 , fHasLocalCoords(false) {} | 58 , fHasLocalCoords(false) {} |
59 | 59 |
60 virtual const char* name() const = 0; | 60 virtual const char* name() const = 0; |
61 | 61 |
62 /** Implemented using GLProcessor::GenKey as described in this class's comme
nt. */ | 62 /** Implemented using GLProcessor::GenKey as described in this class's comme
nt. */ |
63 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 63 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
64 const GrGLCaps& caps, | 64 const GrGLCaps& caps, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 A return value of true from isEqual() should not be used to test whether
the processors | 103 A return value of true from isEqual() should not be used to test whether
the processors |
104 would generate the same shader code. To test for identical code generati
on use the | 104 would generate the same shader code. To test for identical code generati
on use the |
105 processors' keys computed by the GrBackendEffectFactory. */ | 105 processors' keys computed by the GrBackendEffectFactory. */ |
106 bool isEqual(const GrGeometryProcessor& that) const { | 106 bool isEqual(const GrGeometryProcessor& that) const { |
107 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t
hat)) { | 107 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t
hat)) { |
108 return false; | 108 return false; |
109 } | 109 } |
110 return this->onIsEqual(that); | 110 return this->onIsEqual(that); |
111 } | 111 } |
112 | 112 |
| 113 /* |
| 114 * This struct allows the optstate to communicate requirements to the GP. |
| 115 * TODO when the GP can encapsulate draw information in bundles, we can refa
ctor this struct. |
| 116 * Ultimately, when setColor and setCoverage live on the GP, this struct can
be replaced with |
| 117 * a simple override color passed into initBatchTracker |
| 118 */ |
113 struct InitBT { | 119 struct InitBT { |
114 bool fOutputColor; | 120 bool fOutputColor; |
115 bool fOutputCoverage; | 121 bool fOutputCoverage; |
| 122 bool fRemoveColorAttr; |
| 123 bool fRemoveCoverageAttr; |
116 GrColor fColor; | 124 GrColor fColor; |
117 GrColor fCoverage; | 125 GrColor fCoverage; |
118 }; | 126 }; |
119 | 127 |
120 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {} | 128 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {} |
121 | 129 |
| 130 // TODO this call is temporary. Once we have deferred geometry, GPs can alw
ays make themselves |
| 131 // equal |
| 132 virtual bool canBatch(const GrBatchTracker&, const GrBatchTracker&) const {
SkFAIL("s"); return false; } |
| 133 |
122 // TODO this is a total hack until the gp can own whether or not it uses uni
form | 134 // TODO this is a total hack until the gp can own whether or not it uses uni
form |
123 // color / coverage | 135 // color / coverage |
124 bool hasVertexColor() const { return fHasVertexColor; } | 136 bool hasVertexColor() const { return fHasVertexColor; } |
125 bool hasVertexCoverage() const { return fHasVertexCoverage; } | 137 bool hasVertexCoverage() const { return fHasVertexCoverage; } |
126 bool hasLocalCoords() const { return fHasLocalCoords; } | 138 bool hasLocalCoords() const { return fHasLocalCoords; } |
127 | 139 |
| 140 // TODO hack |
| 141 bool fNewStyle; |
| 142 |
128 protected: | 143 protected: |
| 144 enum Output { |
| 145 kAllOnes_Output, |
| 146 kAttribute_Output, |
| 147 kUniform_Output, |
| 148 }; |
| 149 |
| 150 static Output GetColorOutputType(const InitBT& init, bool hasVertexColor) { |
| 151 bool hasUniformColor = (init.fOutputColor && !hasVertexColor) || init.fR
emoveColorAttr; |
| 152 if (!init.fOutputColor) { |
| 153 return kAllOnes_Output; |
| 154 } else if (hasUniformColor) { |
| 155 return kUniform_Output; |
| 156 } else { |
| 157 SkASSERT(hasVertexColor); |
| 158 return kAttribute_Output; |
| 159 } |
| 160 } |
| 161 |
129 /** | 162 /** |
130 * Subclasses call this from their constructor to register vertex attributes
. Attributes | 163 * Subclasses call this from their constructor to register vertex attributes
. Attributes |
131 * will be padded to the nearest 4 bytes for performance reasons. | 164 * will be padded to the nearest 4 bytes for performance reasons. |
132 * TODO After deferred geometry, we should do all of this inline in Generate
Geometry alongside | 165 * TODO After deferred geometry, we should do all of this inline in Generate
Geometry alongside |
133 * the struct used to actually populate the attributes | 166 * the struct used to actually populate the attributes |
134 */ | 167 */ |
135 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { | 168 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { |
136 fVertexStride += attribute.fOffset; | 169 fVertexStride += attribute.fOffset; |
137 return fAttribs.push_back(attribute); | 170 return fAttribs.push_back(attribute); |
138 } | 171 } |
(...skipping 11 matching lines...) Expand all Loading... |
150 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; | 183 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; |
151 size_t fVertexStride; | 184 size_t fVertexStride; |
152 bool fWillUseGeoShader; | 185 bool fWillUseGeoShader; |
153 bool fHasVertexColor; | 186 bool fHasVertexColor; |
154 bool fHasVertexCoverage; | 187 bool fHasVertexCoverage; |
155 bool fHasLocalCoords; | 188 bool fHasLocalCoords; |
156 | 189 |
157 typedef GrProcessor INHERITED; | 190 typedef GrProcessor INHERITED; |
158 }; | 191 }; |
159 #endif | 192 #endif |
OLD | NEW |