| Index: src/gpu/GrTextBlobCache.h
|
| diff --git a/src/gpu/GrTextBlobCache.h b/src/gpu/GrTextBlobCache.h
|
| index d3a24cfb58df9cdcb73bb7a28793e5c7ec4dc631..9e1e26f7e6d7a5341e699af3b5389fcb9dc12f23 100644
|
| --- a/src/gpu/GrTextBlobCache.h
|
| +++ b/src/gpu/GrTextBlobCache.h
|
| @@ -9,21 +9,88 @@
|
| #define GrTextBlobCache_DEFINED
|
|
|
| #include "GrAtlasTextContext.h"
|
| -#include "SkTInternalLList.h"
|
| +#include "SkTDynamicHash.h"
|
| +#include "SkTextBlob.h"
|
|
|
| class GrTextBlobCache {
|
| public:
|
| typedef GrAtlasTextContext::BitmapTextBlob BitmapTextBlob;
|
|
|
| + GrTextBlobCache() : fPool(2 << 17, 2 << 17), fBudget(2 << 22) {}
|
| + ~GrTextBlobCache();
|
| +
|
| + // creates an uncached blob
|
| BitmapTextBlob* createBlob(int glyphCount, int runCount, size_t maxVASize);
|
| + BitmapTextBlob* createBlob(const SkTextBlob* blob, size_t maxVAStride) {
|
| + int glyphCount = 0;
|
| + int runCount = 0;
|
| + BlobGlyphCount(&glyphCount, &runCount, blob);
|
| + BitmapTextBlob* cacheBlob = this->createBlob(glyphCount, runCount, maxVAStride);
|
| + return cacheBlob;
|
| + }
|
| +
|
| + BitmapTextBlob* createCachedBlob(const SkTextBlob* blob, size_t maxVAStride) {
|
| + int glyphCount = 0;
|
| + int runCount = 0;
|
| + BlobGlyphCount(&glyphCount, &runCount, blob);
|
| + BitmapTextBlob* cacheBlob = this->createBlob(glyphCount, runCount, maxVAStride);
|
| + cacheBlob->fUniqueID = blob->uniqueID();
|
| + this->add(cacheBlob);
|
| + return cacheBlob;
|
| + }
|
| +
|
| + BitmapTextBlob* find(uint32_t uniqueID) {
|
| + return fCache.find(uniqueID);
|
| + }
|
| +
|
| + void remove(BitmapTextBlob* blob) {
|
| + fCache.remove(blob->fUniqueID);
|
| + fBlobList.remove(blob);
|
| + blob->unref();
|
| + }
|
| +
|
| + void add(BitmapTextBlob* blob) {
|
| + fCache.add(blob);
|
| + fBlobList.addToHead(blob);
|
| +
|
| + // If we are overbudget, then unref until we are below budget again
|
| + if (fPool.size() > fBudget) {
|
| + BitmapBlobList::Iter iter;
|
| + iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart);
|
| + BitmapTextBlob* lruBlob = iter.get();
|
| + SkASSERT(lruBlob);
|
| + do {
|
| + fCache.remove(lruBlob->fUniqueID);
|
| + fBlobList.remove(lruBlob);
|
| + lruBlob->unref();
|
| + iter.prev();
|
| + } while (fPool.size() > fBudget && (lruBlob = iter.get()));
|
| + }
|
| + }
|
| +
|
| + void makeMRU(BitmapTextBlob* blob) {
|
| + if (fBlobList.head() == blob) {
|
| + return;
|
| + }
|
| +
|
| + fBlobList.remove(blob);
|
| + fBlobList.addToHead(blob);
|
| + }
|
|
|
| private:
|
| + // TODO move to SkTextBlob
|
| + void BlobGlyphCount(int* glyphCount, int* runCount, const SkTextBlob* blob) {
|
| + SkTextBlob::RunIterator itCounter(blob);
|
| + for (; !itCounter.done(); itCounter.next(), (*runCount)++) {
|
| + *glyphCount += itCounter.glyphCount();
|
| + }
|
| + }
|
| +
|
| typedef SkTInternalLList<BitmapTextBlob> BitmapBlobList;
|
| BitmapBlobList fBlobList;
|
| SkTDynamicHash<BitmapTextBlob, uint32_t> fCache;
|
| GrMemoryPool fPool;
|
| size_t fBudget;
|
| - size_t fCurrentUsage;
|
| };
|
|
|
| #endif
|
|
|