Chromium Code Reviews| 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 "GrGeometryData.h" |
| 13 #include "GrProcessor.h" | 13 #include "GrProcessor.h" |
| 14 #include "GrShaderVar.h" | 14 #include "GrShaderVar.h" |
| 15 | 15 |
| 16 /* | 16 /* |
| 17 * A struct for tracking batching decisions. While this lives on GrOptState, it is managed | 17 * A struct for tracking batching decisions. While this lives on GrOptState, it is managed |
| 18 * entirely by the derived classes of the GP. | 18 * entirely by the derived classes of the GP. |
| 19 */ | 19 */ |
| 20 class GrBatchTracker { | 20 class GrBatchTracker { |
| 21 public: | 21 public: |
| 22 template <typename T> const T& cast() const { | 22 template <typename T> const T& cast() const { |
| 23 SkASSERT(sizeof(T) <= kMaxSize); | 23 SkASSERT(sizeof(T) <= kMaxSize); |
| 24 return *reinterpret_cast<const T*>(fData); | 24 return *reinterpret_cast<const T*>(fData.get()); |
| 25 } | 25 } |
| 26 | 26 |
| 27 template <typename T> T* cast() { | 27 template <typename T> T* cast() { |
| 28 SkASSERT(sizeof(T) <= kMaxSize); | 28 SkASSERT(sizeof(T) <= kMaxSize); |
| 29 return reinterpret_cast<T*>(fData); | 29 return reinterpret_cast<T*>(fData.get()); |
| 30 } | 30 } |
| 31 | 31 |
| 32 static const size_t kMaxSize = 32; | 32 static const size_t kMaxSize = 32; |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 uint8_t fData[kMaxSize]; | 35 mutable SkAlignedSStorage<kMaxSize> fData; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 class GrGLCaps; | 38 class GrGLCaps; |
| 39 class GrGLGeometryProcessor; | 39 class GrGLGeometryProcessor; |
| 40 class GrOptDrawState; | 40 class GrOptDrawState; |
| 41 | 41 |
| 42 struct GrInitInvariantOutput; | 42 struct GrInitInvariantOutput; |
| 43 | 43 |
| 44 /* | 44 /* |
| 45 * GrGeometryProcessors and GrPathProcessors may effect invariantColor | 45 * GrGeometryProcessors and GrPathProcessors may effect invariantColor |
| 46 */ | 46 */ |
| 47 class GrPrimitiveProcessor : public GrProcessor { | 47 class GrPrimitiveProcessor : public GrProcessor { |
| 48 public: | 48 public: |
| 49 // TODO GPs and PPs have to provide an initial coverage because the coverage invariant code is | 49 // TODO GPs and PPs have to provide an initial coverage because the coverage invariant code is |
| 50 // broken right now | 50 // broken right now |
| 51 virtual uint8_t coverage() const = 0; | 51 virtual uint8_t coverage() const = 0; |
| 52 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; | 52 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; |
| 53 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0; | 53 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0; |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 typedef GrProcessor INHERITED; | 56 typedef GrProcessor INHERITED; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 enum GPInput { | |
|
bsalomon
2014/12/12 14:29:35
Can this be nested inside GrGP? Otherwise it needs
| |
| 60 kAllOnes_GPInput, | |
| 61 kAttribute_GPInput, | |
| 62 kUniform_GPInput, | |
| 63 }; | |
| 64 | |
| 59 /** | 65 /** |
| 60 * A GrGeometryProcessor is used to perform computation in the vertex shader and | 66 * A GrGeometryProcessor is used to perform computation in the vertex shader and |
| 61 * add support for custom vertex attributes. A GrGemeotryProcessor is typically | 67 * add support for custom vertex attributes. A GrGemeotryProcessor is typically |
| 62 * tied to the code that does a specific type of high-level primitive rendering | 68 * tied to the code that does a specific type of high-level primitive rendering |
| 63 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw is | 69 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw is |
| 64 * specified using GrDrawState. There can only be one geometry processor active for | 70 * specified using GrDrawState. There can only be one geometry processor active for |
| 65 * a draw. The custom vertex attributes required by the geometry processor must be | 71 * a draw. The custom vertex attributes required by the geometry processor must be |
| 66 * added to the vertex attribute array specified on the GrDrawState. | 72 * added to the vertex attribute array specified on the GrDrawState. |
| 67 * GrGeometryProcessor subclasses should be immutable after construction. | 73 * GrGeometryProcessor subclasses should be immutable after construction. |
| 68 */ | 74 */ |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 } | 150 } |
| 145 | 151 |
| 146 // TODO this is fragile, most gps set their coverage to 0xff so this is okay. In the long | 152 // TODO this is fragile, most gps set their coverage to 0xff so this is okay. In the long |
| 147 // term this should move to subclasses which set explicit coverage | 153 // term this should move to subclasses which set explicit coverage |
| 148 if (!fHasVertexCoverage && this->coverage() != that.coverage()) { | 154 if (!fHasVertexCoverage && this->coverage() != that.coverage()) { |
| 149 return false; | 155 return false; |
| 150 } | 156 } |
| 151 return this->onIsEqual(that); | 157 return this->onIsEqual(that); |
| 152 } | 158 } |
| 153 | 159 |
| 160 /* | |
| 161 * This struct allows the optstate to communicate requirements to the GP. | |
| 162 * TODO when the GP can encapsulate draw information in bundles, we can refa ctor this struct. | |
| 163 * Ultimately, when setColor and setCoverage live on the GP, this struct can be replaced with | |
| 164 * a simple override color passed into initBatchTracker | |
|
bsalomon
2014/12/12 14:29:35
From discussion with Greg, I think this will becom
| |
| 165 */ | |
| 154 struct InitBT { | 166 struct InitBT { |
| 155 bool fOutputColor; | 167 bool fOutputColor; |
| 156 bool fOutputCoverage; | 168 bool fOutputCoverage; |
| 169 bool fRemoveColorAttr; | |
| 170 bool fRemoveCoverageAttr; | |
| 157 GrColor fColor; | 171 GrColor fColor; |
| 158 GrColor fCoverage; | 172 GrColor fCoverage; |
| 159 }; | 173 }; |
| 160 | 174 |
| 161 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {} | 175 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const = 0; |
| 162 | 176 |
| 177 // TODO this call is temporary. Once we have deferred geometry, GPs can alw ays make themselves | |
| 178 // equal | |
| 179 bool canBatch(const GrBatchTracker& left, const GrBatchTracker& right) const { | |
| 180 return this->onCanBatch(left, right); | |
| 181 } | |
| 182 | |
| 183 virtual bool onCanBatch(const GrBatchTracker&, const GrBatchTracker&) const = 0; | |
| 184 | |
| 163 GrColor color() const { return fColor; } | 185 GrColor color() const { return fColor; } |
| 164 uint8_t coverage() const { return fCoverage; } | 186 uint8_t coverage() const { return fCoverage; } |
| 165 | 187 |
| 166 // TODO this is a total hack until the gp can own whether or not it uses uni form | 188 // TODO this is a total hack until the gp can own whether or not it uses uni form |
| 167 // color / coverage | 189 // color / coverage |
| 168 bool hasVertexColor() const { return fHasVertexColor; } | 190 bool hasVertexColor() const { return fHasVertexColor; } |
| 169 bool hasVertexCoverage() const { return fHasVertexCoverage; } | 191 bool hasVertexCoverage() const { return fHasVertexCoverage; } |
| 170 bool hasLocalCoords() const { return fHasLocalCoords; } | 192 bool hasLocalCoords() const { return fHasLocalCoords; } |
| 171 | 193 |
| 172 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; | 194 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
| 173 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E; | 195 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E; |
| 174 | 196 |
| 175 protected: | 197 protected: |
| 198 static GPInput GetColorInputType(const InitBT& init, bool hasVertexColor) { | |
|
bsalomon
2014/12/12 14:29:35
Document?
| |
| 199 bool hasUniformColor = (init.fOutputColor && !hasVertexColor) || init.fR emoveColorAttr; | |
| 200 if (!init.fOutputColor) { | |
| 201 return kAllOnes_GPInput; | |
| 202 } else if (hasUniformColor) { | |
| 203 return kUniform_GPInput; | |
| 204 } else { | |
| 205 SkASSERT(hasVertexColor); | |
| 206 return kAttribute_GPInput; | |
| 207 } | |
| 208 } | |
| 209 | |
| 210 static bool CanCombineOutput(GPInput left, GrColor lColor, GPInput right, Gr Color rColor) { | |
|
bsalomon
2014/12/12 14:29:35
Document?
| |
| 211 if (left != right) { | |
| 212 return false; | |
| 213 } | |
| 214 | |
| 215 if (kUniform_GPInput == left && lColor != rColor) { | |
| 216 return false; | |
| 217 } | |
| 218 | |
| 219 return true; | |
| 220 } | |
| 221 | |
| 176 /** | 222 /** |
| 177 * Subclasses call this from their constructor to register vertex attributes . Attributes | 223 * Subclasses call this from their constructor to register vertex attributes . Attributes |
| 178 * will be padded to the nearest 4 bytes for performance reasons. | 224 * will be padded to the nearest 4 bytes for performance reasons. |
| 179 * TODO After deferred geometry, we should do all of this inline in Generate Geometry alongside | 225 * TODO After deferred geometry, we should do all of this inline in Generate Geometry alongside |
| 180 * the struct used to actually populate the attributes | 226 * the struct used to actually populate the attributes |
| 181 */ | 227 */ |
| 182 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { | 228 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { |
| 183 fVertexStride += attribute.fOffset; | 229 fVertexStride += attribute.fOffset; |
| 184 return fAttribs.push_back(attribute); | 230 return fAttribs.push_back(attribute); |
| 185 } | 231 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; | 271 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
| 226 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E; | 272 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E; |
| 227 | 273 |
| 228 private: | 274 private: |
| 229 GrPathProcessor(GrColor color) : fColor(color) {} | 275 GrPathProcessor(GrColor color) : fColor(color) {} |
| 230 GrColor fColor; | 276 GrColor fColor; |
| 231 | 277 |
| 232 typedef GrProcessor INHERITED; | 278 typedef GrProcessor INHERITED; |
| 233 }; | 279 }; |
| 234 #endif | 280 #endif |
| OLD | NEW |