| Index: src/gpu/GrTextBlobCache.h
|
| diff --git a/src/gpu/GrTextBlobCache.h b/src/gpu/GrTextBlobCache.h
|
| index 4c9cb14000e7c1642177bea8b185bc37898e4ac7..ac9ee2bf25f1928af8682d709e9a34e40fffeca9 100644
|
| --- a/src/gpu/GrTextBlobCache.h
|
| +++ b/src/gpu/GrTextBlobCache.h
|
| @@ -23,7 +23,8 @@ public:
|
| GrTextBlobCache(PFOverBudgetCB cb, void* data)
|
| : fPool(kPreAllocSize, kMinGrowthSize)
|
| , fCallback(cb)
|
| - , fData(data) {
|
| + , fData(data)
|
| + , fBudget(kDefaultBudget) {
|
| SkASSERT(cb && data);
|
| }
|
| ~GrTextBlobCache();
|
| @@ -81,13 +82,44 @@ public:
|
| fCache.add(blob);
|
| fBlobList.addToHead(blob);
|
|
|
| + this->checkPurge(blob);
|
| + }
|
| +
|
| + void makeMRU(GrAtlasTextBlob* blob) {
|
| + if (fBlobList.head() == blob) {
|
| + return;
|
| + }
|
| +
|
| + fBlobList.remove(blob);
|
| + fBlobList.addToHead(blob);
|
| + }
|
| +
|
| + void freeAll();
|
| +
|
| + // TODO move to SkTextBlob
|
| + static void BlobGlyphCount(int* glyphCount, int* runCount, const SkTextBlob* blob) {
|
| + SkTextBlob::RunIterator itCounter(blob);
|
| + for (; !itCounter.done(); itCounter.next(), (*runCount)++) {
|
| + *glyphCount += itCounter.glyphCount();
|
| + }
|
| + }
|
| +
|
| + void setBudget(size_t budget) {
|
| + fBudget = budget;
|
| + this->checkPurge();
|
| + }
|
| +
|
| +private:
|
| + typedef SkTInternalLList<GrAtlasTextBlob> BitmapBlobList;
|
| +
|
| + void checkPurge(GrAtlasTextBlob* blob = NULL) {
|
| // If we are overbudget, then unref until we are below budget again
|
| - if (fPool.size() > kBudget) {
|
| + if (fPool.size() > fBudget) {
|
| BitmapBlobList::Iter iter;
|
| iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart);
|
| GrAtlasTextBlob* lruBlob = iter.get();
|
| SkASSERT(lruBlob);
|
| - while (fPool.size() > kBudget && (lruBlob = iter.get()) && lruBlob != blob) {
|
| + while (fPool.size() > fBudget && (lruBlob = iter.get()) && lruBlob != blob) {
|
| fCache.remove(lruBlob->fKey);
|
|
|
| // Backup the iterator before removing and unrefing the blob
|
| @@ -99,50 +131,29 @@ public:
|
| // If we break out of the loop with lruBlob == blob, then we haven't purged enough
|
| // use the call back and try to free some more. If we are still overbudget after this,
|
| // then this single textblob is over our budget
|
| - if (lruBlob == blob) {
|
| + if (blob && lruBlob == blob) {
|
| (*fCallback)(fData);
|
| }
|
|
|
| -#ifdef SK_DEBUG
|
| - if (fPool.size() > kBudget) {
|
| +#ifdef SPEW_BUDGET_MESSAGE
|
| + if (fPool.size() > fBudget) {
|
| SkDebugf("Single textblob is larger than our whole budget");
|
| }
|
| #endif
|
| }
|
| }
|
|
|
| - void makeMRU(GrAtlasTextBlob* blob) {
|
| - if (fBlobList.head() == blob) {
|
| - return;
|
| - }
|
| -
|
| - fBlobList.remove(blob);
|
| - fBlobList.addToHead(blob);
|
| - }
|
| -
|
| - void freeAll();
|
| -
|
| - // TODO move to SkTextBlob
|
| - static void BlobGlyphCount(int* glyphCount, int* runCount, const SkTextBlob* blob) {
|
| - SkTextBlob::RunIterator itCounter(blob);
|
| - for (; !itCounter.done(); itCounter.next(), (*runCount)++) {
|
| - *glyphCount += itCounter.glyphCount();
|
| - }
|
| - }
|
| -
|
| -private:
|
| - typedef SkTInternalLList<GrAtlasTextBlob> BitmapBlobList;
|
| -
|
| // Budget was chosen to be ~4 megabytes. The min alloc and pre alloc sizes in the pool are
|
| // based off of the largest cached textblob I have seen in the skps(a couple of kilobytes).
|
| static const int kPreAllocSize = 1 << 17;
|
| static const int kMinGrowthSize = 1 << 17;
|
| - static const int kBudget = 1 << 22;
|
| + static const int kDefaultBudget = 1 << 22;
|
| BitmapBlobList fBlobList;
|
| SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key> fCache;
|
| GrMemoryPool fPool;
|
| PFOverBudgetCB fCallback;
|
| void* fData;
|
| + size_t fBudget;
|
| };
|
|
|
| #endif
|
|
|