Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Unified Diff: src/core/SkPicture.cpp

Issue 752573002: simplify uniqueID code in picture (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: simplify loop Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkPicture.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPicture.cpp
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp
index 7f4b33afac0f8e951f2b353da92a2d455212f472..4848345e51c9cf81e33ad9c1b0d0b066a55456f6 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -45,6 +45,18 @@ template <typename T> 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
« no previous file with comments | « include/core/SkPicture.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698