diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index dc522a5c9d..e9500b25c5 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -128,12 +128,9 @@ public: */ SkRect cullRect() const { return fCullRect; } - /** Return a non-zero, unique value representing the picture. This call is - only valid when not recording. Between a beginRecording/endRecording - pair it will just return 0 (the invalid ID). Each beginRecording/ - endRecording pair will cause a different generation ID to be returned. - */ - uint32_t uniqueID() const; + /** Return a non-zero, unique value representing the picture. + */ + uint32_t uniqueID() const { return fUniqueID; } /** * Function to encode an SkBitmap to an SkData. A function with this @@ -249,7 +246,6 @@ private: static const uint32_t MIN_PICTURE_VERSION = 19; static const uint32_t CURRENT_PICTURE_VERSION = 37; - void needsNewGenID() { fUniqueID = SK_InvalidGenID; } void callDeletionListeners(); void createHeader(SkPictInfo* info) const; @@ -264,12 +260,12 @@ private: SkPicture const* const drawablePics[], int drawableCount); // uint32_t fRefCnt; from SkNVRefCnt - mutable uint32_t fUniqueID; + const uint32_t fUniqueID; const SkRect fCullRect; mutable SkAutoTUnref fAccelData; mutable SkTDArray fDeletionListeners; // pointers are refed - SkAutoTDelete fRecord; - SkAutoTUnref fBBH; + SkAutoTDelete fRecord; + SkAutoTUnref fBBH; SkAutoTUnref fDrawablePicts; // helpers for fDrawablePicts diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index 7f4b33afac..4848345e51 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -45,6 +45,18 @@ template int SafeCount(const T* obj) { return obj ? obj->count() : 0; } +static int32_t gPictureGenerationID; + +// never returns a 0 +static int32_t next_picture_generation_id() { + // Loop in case our global wraps around. + int32_t genID; + do { + genID = sk_atomic_inc(&gPictureGenerationID) + 1; + } while (0 == genID); + return genID; +} + /////////////////////////////////////////////////////////////////////////////// namespace { @@ -512,33 +524,15 @@ bool SkPicture::hasText() const { return fAnalysis.fHasText; } bool SkPicture::willPlayBackBitmaps() const { return fAnalysis.fWillPlaybackBitmaps; } int SkPicture::approximateOpCount() const { return fRecord->count(); } -static int32_t gPictureGenerationID = SK_InvalidGenID; // This will be set at link time. - -static int32_t next_picture_generation_id() { - // Loop in case our global wraps around. - int32_t genID; - do { - genID = sk_atomic_inc(&gPictureGenerationID) + 1; - } while (SK_InvalidGenID == genID); - return genID; -} - -uint32_t SkPicture::uniqueID() const { - if (SK_InvalidGenID == fUniqueID) { - fUniqueID = next_picture_generation_id(); - } - return fUniqueID; -} - SkPicture::SkPicture(const SkRect& cullRect, SkRecord* record, SkData* drawablePicts, SkBBoxHierarchy* bbh) - : fCullRect(cullRect) + : fUniqueID(next_picture_generation_id()) + , fCullRect(cullRect) , fRecord(record) , fBBH(SkSafeRef(bbh)) , fDrawablePicts(SkSafeRef(drawablePicts)) - , fAnalysis(*fRecord) { - this->needsNewGenID(); -} + , fAnalysis(*fRecord) +{} // Note that we are assuming that this entry point will only be called from // one thread. Currently the only client of this method is