simplify uniqueID code in picture

patch from issue 750003002 at patchset 1 (http://crrev.com/750003002#ps1)

BUG=skia:

Review URL: https://codereview.chromium.org/752573002
This commit is contained in:
reed 2014-11-21 08:07:41 -08:00 committed by Commit bot
parent 8f81b69ed7
commit 41d2c2e434
2 changed files with 22 additions and 32 deletions

View File

@ -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.
/** Return a non-zero, unique value representing the picture.
*/
uint32_t uniqueID() const;
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<SkPicture>
mutable uint32_t fUniqueID;
const uint32_t fUniqueID;
const SkRect fCullRect;
mutable SkAutoTUnref<const AccelData> fAccelData;
mutable SkTDArray<DeletionListener*> fDeletionListeners; // pointers are refed
SkAutoTDelete<SkRecord> fRecord;
SkAutoTUnref<SkBBoxHierarchy> fBBH;
SkAutoTDelete<const SkRecord> fRecord;
SkAutoTUnref<const SkBBoxHierarchy> fBBH;
SkAutoTUnref<SkData> fDrawablePicts;
// helpers for fDrawablePicts

View File

@ -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