Lazy init batch unique ID
authorjoshualitt <joshualitt@chromium.org>
Tue, 8 Mar 2016 17:31:15 +0000 (09:31 -0800)
committerCommit bot <commit-bot@chromium.org>
Tue, 8 Mar 2016 17:31:15 +0000 (09:31 -0800)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1772023003

Review URL: https://codereview.chromium.org/1772023003

src/gpu/batches/GrBatch.cpp
src/gpu/batches/GrBatch.h

index 8af1c1e0880ddd0673cbeeb1adf628c25c47b69f..900f889ff870f759ba09ab7dbf1d7c26d527ef42 100644 (file)
@@ -36,7 +36,7 @@ public:
 
 int32_t GrBatch::gCurrBatchClassID = GrBatch::kIllegalBatchID;
 
-GrBATCH_SPEW(int32_t GrBatch::gCurrBatchUniqueID = GrBatch::kIllegalBatchID;)
+int32_t GrBatch::gCurrBatchUniqueID = GrBatch::kIllegalBatchID;
 
 void* GrBatch::operator new(size_t size) {
     return MemoryPoolAccessor().pool()->allocate(size);
@@ -48,10 +48,7 @@ void GrBatch::operator delete(void* target) {
 
 GrBatch::GrBatch(uint32_t classID)
     : fClassID(classID)
-#if GR_BATCH_SPEW
-    , fUniqueID(GenBatchID())
-#endif
-{
+    , fUniqueID(kIllegalBatchID) {
     SkDEBUGCODE(fUsed = false;)
 }
 
index b29c8a49b701ccccee3290233350f9ee1591877f..aae726eba95c4094462b3fa76e663100cc362b76 100644 (file)
@@ -95,9 +95,13 @@ public:
 
     uint32_t classID() const { SkASSERT(kIllegalBatchID != fClassID); return fClassID; }
 
-#if GR_BATCH_SPEW
-    uint32_t uniqueID() const { return fUniqueID; }
-#endif
+    // We lazily initialize the uniqueID because currently the only user is GrAuditTrail
+    uint32_t uniqueID() const { 
+        if (kIllegalBatchID == fUniqueID) {
+            fUniqueID = GenBatchID();
+        }
+        return fUniqueID; 
+    }
     SkDEBUGCODE(bool isUsed() const { return fUsed; })
 
     /** Called prior to drawing. The batch should perform any resource creation necessary to
@@ -153,11 +157,9 @@ private:
 
     SkDEBUGCODE(bool                    fUsed;)
     const uint32_t                      fClassID;
-#if GR_BATCH_SPEW
     static uint32_t GenBatchID() { return GenID(&gCurrBatchUniqueID); }
-    const uint32_t                      fUniqueID;
+    mutable uint32_t                    fUniqueID;
     static int32_t                      gCurrBatchUniqueID;
-#endif
     static int32_t                      gCurrBatchClassID;
 };