Chromium Code Reviews| Index: src/gpu/batches/GrBatch.h |
| diff --git a/src/gpu/batches/GrBatch.h b/src/gpu/batches/GrBatch.h |
| index b6eec1f969ea1e25de8eb4c86946882a8efa2ba4..0ec47d3de2f3d6dacdade2b0a74cefef51f931c5 100644 |
| --- a/src/gpu/batches/GrBatch.h |
| +++ b/src/gpu/batches/GrBatch.h |
| @@ -41,6 +41,13 @@ class GrBatchFlushState; |
| #define GrBATCH_INFO(...) |
| #endif |
| +// A helper macro to generate a class static id |
|
robertphillips
2015/09/17 14:56:06
DEFINE_BATCH_CLASS_ID ?
|
| +#define BATCH_CLASS_ID \ |
| + static uint32_t ClassID() { \ |
| + static uint32_t kClassID = GenID(&gCurrBatchClassID); \ |
| + return kClassID; \ |
| + } |
| + |
| class GrBatch : public GrNonAtomicRef { |
| public: |
| GrBatch(); |
| @@ -69,10 +76,17 @@ public: |
| } |
| /** |
| - * Helper for down-casting to a GrBatch subclass |
| + * Helper for safely down-casting to a GrBatch subclass |
| */ |
| - template <typename T> const T& cast() const { return *static_cast<const T*>(this); } |
| - template <typename T> T* cast() { return static_cast<T*>(this); } |
| + template <typename T> const T& cast() const { |
| + SkASSERT(T::ClassID() == this->classID()); |
| + return *static_cast<const T*>(this); |
| + } |
| + |
| + template <typename T> T* cast() { |
| + SkASSERT(T::ClassID() == this->classID()); |
| + return static_cast<T*>(this); |
| + } |
| uint32_t classID() const { SkASSERT(kIllegalBatchID != fClassID); return fClassID; } |
| @@ -96,9 +110,10 @@ public: |
| virtual SkString dumpInfo() const = 0; |
| protected: |
|
robertphillips
2015/09/17 14:56:06
// (via BATCH_CLASS_ID macro) ?
We can't do this
|
| - template <typename PROC_SUBCLASS> void initClassID() { |
| - static uint32_t kClassID = GenID(&gCurrBatchClassID); |
| - fClassID = kClassID; |
| + // Caller must have already defined BATCH_SUBCLASS::ClassID() |
| + template <class BATCH_SUBCLASS> void initClassID() { |
| + SkASSERT(kIllegalBatchID == fClassID); |
| + fClassID = BATCH_SUBCLASS::ClassID(); |
| } |
| // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setLargest on the bounds |
| @@ -109,14 +124,6 @@ protected: |
| return fBounds.joinPossiblyEmptyRect(otherBounds); |
| } |
| - SkRect fBounds; |
| - |
| -private: |
| - virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0; |
| - |
| - virtual void onPrepare(GrBatchFlushState*) = 0; |
| - virtual void onDraw(GrBatchFlushState*) = 0; |
| - |
| static uint32_t GenID(int32_t* idCounter) { |
|
robertphillips
2015/09/17 14:56:06
fCurrProcessorClassID -> idCounter ?
|
| // fCurrProcessorClassID has been initialized to kIllegalProcessorClassID. The |
| // atomic inc returns the old value not the incremented value. So we add |
| @@ -129,17 +136,25 @@ private: |
| return id; |
| } |
| + SkRect fBounds; |
| + uint32_t fClassID; |
|
robertphillips
2015/09/17 14:56:06
= kIllegalBatchID; ?
|
| + static int32_t gCurrBatchClassID; |
| + |
| +private: |
| + virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0; |
| + |
| + virtual void onPrepare(GrBatchFlushState*) = 0; |
| + virtual void onDraw(GrBatchFlushState*) = 0; |
| + |
| enum { |
| kIllegalBatchID = 0, |
| }; |
| - uint32_t fClassID; |
| SkDEBUGCODE(bool fUsed;) |
| #if GR_BATCH_SPEW |
| uint32_t fUniqueID; |
| static int32_t gCurrBatchUniqueID; |
| #endif |
| - static int32_t gCurrBatchClassID; |
| typedef GrNonAtomicRef INHERITED; |
| }; |