Lazy init batch unique ID

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
This commit is contained in:
joshualitt 2016-03-08 09:31:15 -08:00 committed by Commit bot
parent e6eaa320e8
commit 08e65e718a
2 changed files with 10 additions and 11 deletions

View 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;)
}

View 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;
};