Index: src/gpu/GrGeometryProcessor.h |
diff --git a/src/gpu/GrGeometryProcessor.h b/src/gpu/GrGeometryProcessor.h |
index 50ecac48ba0c74a33d27dbf29bd1f203ab9f3051..d192f8fa5b23573c4d186c072e9727180fa74fae 100644 |
--- a/src/gpu/GrGeometryProcessor.h |
+++ b/src/gpu/GrGeometryProcessor.h |
@@ -21,18 +21,18 @@ class GrBatchTracker { |
public: |
template <typename T> const T& cast() const { |
SkASSERT(sizeof(T) <= kMaxSize); |
- return *reinterpret_cast<const T*>(fData); |
+ return *reinterpret_cast<const T*>(fData.get()); |
} |
template <typename T> T* cast() { |
SkASSERT(sizeof(T) <= kMaxSize); |
- return reinterpret_cast<T*>(fData); |
+ return reinterpret_cast<T*>(fData.get()); |
} |
static const size_t kMaxSize = 32; |
private: |
- uint8_t fData[kMaxSize]; |
+ mutable SkAlignedSStorage<kMaxSize> fData; |
}; |
class GrGLCaps; |
@@ -56,6 +56,12 @@ private: |
typedef GrProcessor INHERITED; |
}; |
+enum GPInput { |
bsalomon
2014/12/12 14:29:35
Can this be nested inside GrGP? Otherwise it needs
|
+ kAllOnes_GPInput, |
+ kAttribute_GPInput, |
+ kUniform_GPInput, |
+}; |
+ |
/** |
* A GrGeometryProcessor is used to perform computation in the vertex shader and |
* add support for custom vertex attributes. A GrGemeotryProcessor is typically |
@@ -151,15 +157,31 @@ public: |
return this->onIsEqual(that); |
} |
+ /* |
+ * This struct allows the optstate to communicate requirements to the GP. |
+ * TODO when the GP can encapsulate draw information in bundles, we can refactor this struct. |
+ * Ultimately, when setColor and setCoverage live on the GP, this struct can be replaced with |
+ * a simple override color passed into initBatchTracker |
bsalomon
2014/12/12 14:29:35
From discussion with Greg, I think this will becom
|
+ */ |
struct InitBT { |
bool fOutputColor; |
bool fOutputCoverage; |
+ bool fRemoveColorAttr; |
+ bool fRemoveCoverageAttr; |
GrColor fColor; |
GrColor fCoverage; |
}; |
- virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {} |
+ virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const = 0; |
+ // TODO this call is temporary. Once we have deferred geometry, GPs can always make themselves |
+ // equal |
+ bool canBatch(const GrBatchTracker& left, const GrBatchTracker& right) const { |
+ return this->onCanBatch(left, right); |
+ } |
+ |
+ virtual bool onCanBatch(const GrBatchTracker&, const GrBatchTracker&) const = 0; |
+ |
GrColor color() const { return fColor; } |
uint8_t coverage() const { return fCoverage; } |
@@ -173,6 +195,30 @@ public: |
void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRIDE; |
protected: |
+ static GPInput GetColorInputType(const InitBT& init, bool hasVertexColor) { |
bsalomon
2014/12/12 14:29:35
Document?
|
+ bool hasUniformColor = (init.fOutputColor && !hasVertexColor) || init.fRemoveColorAttr; |
+ if (!init.fOutputColor) { |
+ return kAllOnes_GPInput; |
+ } else if (hasUniformColor) { |
+ return kUniform_GPInput; |
+ } else { |
+ SkASSERT(hasVertexColor); |
+ return kAttribute_GPInput; |
+ } |
+ } |
+ |
+ static bool CanCombineOutput(GPInput left, GrColor lColor, GPInput right, GrColor rColor) { |
bsalomon
2014/12/12 14:29:35
Document?
|
+ if (left != right) { |
+ return false; |
+ } |
+ |
+ if (kUniform_GPInput == left && lColor != rColor) { |
+ return false; |
+ } |
+ |
+ return true; |
+ } |
+ |
/** |
* Subclasses call this from their constructor to register vertex attributes. Attributes |
* will be padded to the nearest 4 bytes for performance reasons. |