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

Unified Diff: src/core/SkLiteDL.cpp

Issue 2226813002: SkLiteDL: control reuse by a single parameter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 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 | « src/core/SkLiteDL.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkLiteDL.cpp
diff --git a/src/core/SkLiteDL.cpp b/src/core/SkLiteDL.cpp
index f13255b4946a3fbb2b8907f10114fd64961b464a..778f5c9563c73adf1165166715ba9499aed26af9 100644
--- a/src/core/SkLiteDL.cpp
+++ b/src/core/SkLiteDL.cpp
@@ -663,15 +663,16 @@ SkRect SkLiteDL::onGetBounds() {
return fBounds;
}
-SkLiteDL:: SkLiteDL() {}
-SkLiteDL::~SkLiteDL() {}
+#if !defined(SK_LITEDL_USES)
+ #define SK_LITEDL_USES 16
+#endif
-static const int kFreeStackByteLimit = 128*1024;
-static const int kFreeStackCountLimit = 8;
+SkLiteDL:: SkLiteDL() : fUsesRemaining(SK_LITEDL_USES) {}
+SkLiteDL::~SkLiteDL() {}
+// If you're tempted to make this lock free, please don't forget about ABA.
static SkSpinlock gFreeStackLock;
-static SkLiteDL* gFreeStack = nullptr;
-static int gFreeStackCount = 0;
+static SkLiteDL* gFreeStack = nullptr;
sk_sp<SkLiteDL> SkLiteDL::New(SkRect bounds) {
sk_sp<SkLiteDL> dl;
@@ -680,7 +681,6 @@ sk_sp<SkLiteDL> SkLiteDL::New(SkRect bounds) {
if (gFreeStack) {
dl.reset(gFreeStack); // Adopts the ref the stack's been holding.
gFreeStack = gFreeStack->fNext;
- gFreeStackCount--;
}
}
@@ -700,15 +700,13 @@ void SkLiteDL::internal_dispose() const {
auto self = const_cast<SkLiteDL*>(this);
map(&self->fBytes, [](Op* op) { op->~Op(); });
- if (self->fBytes.reserved() < kFreeStackByteLimit) {
+ if (--self->fUsesRemaining > 0) {
self->fBytes.rewind();
+
SkAutoMutexAcquire lock(gFreeStackLock);
- if (gFreeStackCount < kFreeStackCountLimit) {
- self->fNext = gFreeStack;
- gFreeStack = self;
- gFreeStackCount++;
- return;
- }
+ self->fNext = gFreeStack;
+ gFreeStack = self;
+ return;
}
delete this;
« no previous file with comments | « src/core/SkLiteDL.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698