aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-05-23 16:38:09 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-24 19:47:49 +0000
commitb12175f40fcd3d049de3f38d5388f6eb483ab268 (patch)
tree577a8834a751af42a390443863fc0b2460c20eb1 /src
parentef839a96ff92a2bd96b1f21719f239565f91e96f (diff)
Remove memory pool use from SkTextBlobCache
Track used size explicitly in the cache enabling DDL to use the LRU. Change-Id: I3fef593e9252172dd160fd7636254550b95ca0a2 Reviewed-on: https://skia-review.googlesource.com/130022 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrContext.cpp2
-rw-r--r--src/gpu/text/GrAtlasTextBlob.cpp12
-rw-r--r--src/gpu/text/GrAtlasTextBlob.h16
-rw-r--r--src/gpu/text/GrTextBlobCache.cpp21
-rw-r--r--src/gpu/text/GrTextBlobCache.h20
5 files changed, 25 insertions, 46 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 24c28e6d86..7195405833 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -136,7 +136,7 @@ bool GrContext::initCommon(const GrContextOptions& options) {
fGlyphCache = new GrGlyphCache(fCaps.get(), options.fGlyphCacheTextureMaximumBytes);
fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB,
- this, this->uniqueID(), SkToBool(fGpu)));
+ this, this->uniqueID()));
// DDL TODO: we need to think through how the task group & persistent cache
// get passed on to/shared between all the DDLRecorders created with this context.
diff --git a/src/gpu/text/GrAtlasTextBlob.cpp b/src/gpu/text/GrAtlasTextBlob.cpp
index f508c1f3f1..f1c0f392a9 100644
--- a/src/gpu/text/GrAtlasTextBlob.cpp
+++ b/src/gpu/text/GrAtlasTextBlob.cpp
@@ -19,7 +19,7 @@
#include "SkTextToPathIter.h"
#include "ops/GrAtlasTextOp.h"
-sk_sp<GrAtlasTextBlob> GrAtlasTextBlob::Make(GrMemoryPool* pool, int glyphCount, int runCount) {
+sk_sp<GrAtlasTextBlob> GrAtlasTextBlob::Make(int glyphCount, int runCount) {
// We allocate size for the GrAtlasTextBlob itself, plus size for the vertices array,
// and size for the glyphIds array.
size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize;
@@ -28,12 +28,8 @@ sk_sp<GrAtlasTextBlob> GrAtlasTextBlob::Make(GrMemoryPool* pool, int glyphCount,
glyphCount * sizeof(GrGlyph**) +
sizeof(GrAtlasTextBlob::Run) * runCount;
- void* allocation;
- if (pool) {
- allocation = pool->allocate(size);
- } else {
- allocation = ::operator new (size);
- }
+ void* allocation = ::operator new (size);
+
if (CACHE_SANITY_CHECK) {
sk_bzero(allocation, size);
}
@@ -51,7 +47,6 @@ sk_sp<GrAtlasTextBlob> GrAtlasTextBlob::Make(GrMemoryPool* pool, int glyphCount,
new (&cacheBlob->fRuns[i]) GrAtlasTextBlob::Run;
}
cacheBlob->fRunCount = runCount;
- cacheBlob->fPool = pool;
return cacheBlob;
}
@@ -400,7 +395,6 @@ std::unique_ptr<GrDrawOp> GrAtlasTextBlob::test_makeOp(
void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlob& r) {
SkASSERT_RELEASE(l.fSize == r.fSize);
- SkASSERT_RELEASE(l.fPool == r.fPool);
SkASSERT_RELEASE(l.fBlurRec.fSigma == r.fBlurRec.fSigma);
SkASSERT_RELEASE(l.fBlurRec.fStyle == r.fBlurRec.fStyle);
diff --git a/src/gpu/text/GrAtlasTextBlob.h b/src/gpu/text/GrAtlasTextBlob.h
index 2c656ad7f8..d7e1b6def6 100644
--- a/src/gpu/text/GrAtlasTextBlob.h
+++ b/src/gpu/text/GrAtlasTextBlob.h
@@ -55,7 +55,7 @@ public:
class VertexRegenerator;
- static sk_sp<GrAtlasTextBlob> Make(GrMemoryPool*, int glyphCount, int runCount);
+ static sk_sp<GrAtlasTextBlob> Make(int glyphCount, int runCount);
/**
* We currently force regeneration of a blob if old or new matrix differ in having perspective.
@@ -106,22 +106,15 @@ public:
}
void operator delete(void* p) {
- GrAtlasTextBlob* blob = reinterpret_cast<GrAtlasTextBlob*>(p);
- if (blob->fPool) {
- blob->fPool->release(p);
- } else {
- ::operator delete(p);
- }
+ ::operator delete(p);
}
+
void* operator new(size_t) {
SK_ABORT("All blobs are created by placement new.");
return sk_malloc_throw(0);
}
void* operator new(size_t, void* p) { return p; }
- void operator delete(void* target, void* placement) {
- ::operator delete(target, placement);
- }
bool hasDistanceField() const { return SkToBool(fTextType & kHasDistanceField_TextType); }
bool hasBitmap() const { return SkToBool(fTextType & kHasBitmap_TextType); }
@@ -275,6 +268,8 @@ public:
const Key& key() const { return fKey; }
+ size_t size() const { return fSize; }
+
~GrAtlasTextBlob() {
for (int i = 0; i < fRunCount; i++) {
fRuns[i].~Run();
@@ -540,7 +535,6 @@ private:
char* fVertices;
GrGlyph** fGlyphs;
Run* fRuns;
- GrMemoryPool* fPool; // this will be null when DDLs are being recorded
SkMaskFilterBase::BlurRec fBlurRec;
StrokeInfo fStrokeInfo;
Key fKey;
diff --git a/src/gpu/text/GrTextBlobCache.cpp b/src/gpu/text/GrTextBlobCache.cpp
index 88cbaeb2c7..5b951462f0 100644
--- a/src/gpu/text/GrTextBlobCache.cpp
+++ b/src/gpu/text/GrTextBlobCache.cpp
@@ -11,7 +11,6 @@ DECLARE_SKMESSAGEBUS_MESSAGE(GrTextBlobCache::PurgeBlobMessage)
GrTextBlobCache::~GrTextBlobCache() {
this->freeAll();
- delete fPool;
}
void GrTextBlobCache::freeAll() {
@@ -23,8 +22,9 @@ void GrTextBlobCache::freeAll() {
fBlobIDCache.reset();
+ fCurrentSize = 0;
+
// There should be no allocations in the memory pool at this point
- SkASSERT(!fPool || fPool->isEmpty());
SkASSERT(fBlobList.isEmpty());
}
@@ -46,6 +46,7 @@ void GrTextBlobCache::purgeStaleBlobs() {
// remove all blob entries from the LRU list
for (const auto& blob : idEntry->fBlobs) {
+ fCurrentSize -= blob->size();
fBlobList.remove(blob.get());
}
@@ -54,26 +55,16 @@ void GrTextBlobCache::purgeStaleBlobs() {
}
}
-bool GrTextBlobCache::overBudget() const {
- if (fPool) {
- return fPool->size() > fBudget;
- }
-
- // When DDLs are being recorded no GrAtlasTextBlob will be deleted so the cache budget is
- // somewhat meaningless.
- return false;
-}
-
void GrTextBlobCache::checkPurge(GrAtlasTextBlob* blob) {
// First, purge all stale blob IDs.
this->purgeStaleBlobs();
// If we are still over budget, then unref until we are below budget again
- if (this->overBudget()) {
+ if (fCurrentSize > fSizeBudget) {
BitmapBlobList::Iter iter;
iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart);
GrAtlasTextBlob* lruBlob = nullptr;
- while (this->overBudget() && (lruBlob = iter.get()) && lruBlob != blob) {
+ while (fCurrentSize > fSizeBudget && (lruBlob = iter.get()) && lruBlob != blob) {
// Backup the iterator before removing and unrefing the blob
iter.prev();
@@ -88,7 +79,7 @@ void GrTextBlobCache::checkPurge(GrAtlasTextBlob* blob) {
}
#ifdef SPEW_BUDGET_MESSAGE
- if (this->overBudget()) {
+ if (fCurrentSize > fSizeBudget) {
SkDebugf("Single textblob is larger than our whole budget");
}
#endif
diff --git a/src/gpu/text/GrTextBlobCache.h b/src/gpu/text/GrTextBlobCache.h
index eb2789a7c1..4931667c61 100644
--- a/src/gpu/text/GrTextBlobCache.h
+++ b/src/gpu/text/GrTextBlobCache.h
@@ -23,11 +23,10 @@ public:
*/
typedef void (*PFOverBudgetCB)(void* data);
- GrTextBlobCache(PFOverBudgetCB cb, void* data, uint32_t uniqueID, bool usePool)
- : fPool(usePool ? new GrMemoryPool(0u, kMinGrowthSize) : nullptr)
- , fCallback(cb)
+ GrTextBlobCache(PFOverBudgetCB cb, void* data, uint32_t uniqueID)
+ : fCallback(cb)
, fData(data)
- , fBudget(kDefaultBudget)
+ , fSizeBudget(kDefaultBudget)
, fUniqueID(uniqueID)
, fPurgeBlobInbox(uniqueID) {
SkASSERT(cb && data);
@@ -36,14 +35,14 @@ public:
// creates an uncached blob
sk_sp<GrAtlasTextBlob> makeBlob(int glyphCount, int runCount) {
- return GrAtlasTextBlob::Make(fPool, glyphCount, runCount);
+ return GrAtlasTextBlob::Make(glyphCount, runCount);
}
sk_sp<GrAtlasTextBlob> makeBlob(const SkTextBlob* blob) {
int glyphCount = 0;
int runCount = 0;
BlobGlyphCount(&glyphCount, &runCount, blob);
- return GrAtlasTextBlob::Make(fPool, glyphCount, runCount);
+ return GrAtlasTextBlob::Make(glyphCount, runCount);
}
sk_sp<GrAtlasTextBlob> makeCachedBlob(const SkTextBlob* blob,
@@ -67,6 +66,7 @@ public:
auto* idEntry = fBlobIDCache.find(id);
SkASSERT(idEntry);
+ fCurrentSize -= blob->size();
fBlobList.remove(blob);
idEntry->removeBlob(blob);
if (idEntry->fBlobs.empty()) {
@@ -94,7 +94,7 @@ public:
}
void setBudget(size_t budget) {
- fBudget = budget;
+ fSizeBudget = budget;
this->checkPurge();
}
@@ -165,22 +165,22 @@ private:
// Safe to retain a raw ptr temporarily here, because the cache will hold a ref.
GrAtlasTextBlob* rawBlobPtr = blob.get();
fBlobList.addToHead(rawBlobPtr);
+ fCurrentSize += blob->size();
idEntry->addBlob(std::move(blob));
this->checkPurge(rawBlobPtr);
}
void checkPurge(GrAtlasTextBlob* blob = nullptr);
- bool overBudget() const;
static const int kMinGrowthSize = 1 << 16;
static const int kDefaultBudget = 1 << 22;
- GrMemoryPool* fPool;
BitmapBlobList fBlobList;
SkTHashMap<uint32_t, BlobIDCacheEntry> fBlobIDCache;
PFOverBudgetCB fCallback;
void* fData;
- size_t fBudget;
+ size_t fSizeBudget;
+ size_t fCurrentSize{0};
uint32_t fUniqueID; // unique id to use for messaging
SkMessageBus<PurgeBlobMessage>::Inbox fPurgeBlobInbox;
};