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