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

Unified Diff: src/core/SkPicture.cpp

Issue 1061283002: Send SkPicture deletion message lazily. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 months 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 c7e36e7ecd2a6e99eb12b0395925dcda65a29657..a8ddfe6656d5b18446aca9e59f3ae604ad18bf54 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -12,6 +12,7 @@
#include "SkPictureRecord.h"
#include "SkPictureRecorder.h"
+#include "SkAtomics.h"
#include "SkBitmapDevice.h"
#include "SkCanvas.h"
#include "SkChunkAlloc.h"
@@ -46,18 +47,6 @@ 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 {
@@ -247,7 +236,7 @@ bool SkPicture::Analysis::suitableForGpuRasterization(const char** reason,
numSlowPathDashedPaths -= fNumFastPathDashEffects;
}
- int numSlowPaths = fNumAAConcavePaths -
+ int numSlowPaths = fNumAAConcavePaths -
fNumAAHairlineConcavePaths -
fNumAADFEligibleConcavePaths;
@@ -270,9 +259,13 @@ SkPicture const* const* SkPicture::drawablePicts() const {
}
SkPicture::~SkPicture() {
- SkPicture::DeletionMessage msg;
- msg.fUniqueID = this->uniqueID();
- SkMessageBus<SkPicture::DeletionMessage>::Post(msg);
+ // If the ID is still zero, no one has read it, so no need to send this message.
+ uint32_t id = sk_atomic_load(&fUniqueID, sk_memory_order_relaxed);
+ if (id != 0) {
+ SkPicture::DeletionMessage msg;
+ msg.fUniqueID = id;
+ SkMessageBus<SkPicture::DeletionMessage>::Post(msg);
+ }
}
void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) const {
@@ -488,10 +481,27 @@ int SkPicture::approximateOpCount() const { return fRecord->count(); }
SkPicture::SkPicture(const SkRect& cullRect, SkRecord* record, SnapshotArray* drawablePicts,
SkBBoxHierarchy* bbh)
- : fUniqueID(next_picture_generation_id())
+ : fUniqueID(0)
, fCullRect(cullRect)
, fRecord(SkRef(record))
, fBBH(SkSafeRef(bbh))
, fDrawablePicts(drawablePicts) // take ownership
, fAnalysis(*fRecord)
{}
+
+
+static uint32_t gNextID = 1;
+uint32_t SkPicture::uniqueID() const {
+ uint32_t id = sk_atomic_load(&fUniqueID, sk_memory_order_relaxed);
+ while (id == 0) {
+ uint32_t next = sk_atomic_fetch_add(&gNextID, 1u);
+ if (sk_atomic_compare_exchange(&fUniqueID, &id, next,
+ sk_memory_order_relaxed,
+ sk_memory_order_relaxed)) {
+ id = next;
+ } else {
+ // sk_atomic_compare_exchange replaced id with the current value of fUniqueID.
+ }
+ }
+ return id;
+}
« 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