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

Side by Side Diff: src/gpu/text/GrTextBlobCache.h

Issue 1686113002: Remove GrTextBlobCache/GrAtlasTextBlob friendliness (Closed) Base URL: https://skia.googlesource.com/skia.git@tc-cleanup-1
Patch Set: build warnings Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/gpu/text/GrAtlasTextContext.cpp ('k') | src/gpu/text/GrTextBlobCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrTextBlobCache_DEFINED 8 #ifndef GrTextBlobCache_DEFINED
9 #define GrTextBlobCache_DEFINED 9 #define GrTextBlobCache_DEFINED
10 10
(...skipping 12 matching lines...) Expand all
23 GrTextBlobCache(PFOverBudgetCB cb, void* data) 23 GrTextBlobCache(PFOverBudgetCB cb, void* data)
24 : fPool(kPreAllocSize, kMinGrowthSize) 24 : fPool(kPreAllocSize, kMinGrowthSize)
25 , fCallback(cb) 25 , fCallback(cb)
26 , fData(data) 26 , fData(data)
27 , fBudget(kDefaultBudget) { 27 , fBudget(kDefaultBudget) {
28 SkASSERT(cb && data); 28 SkASSERT(cb && data);
29 } 29 }
30 ~GrTextBlobCache(); 30 ~GrTextBlobCache();
31 31
32 // creates an uncached blob 32 // creates an uncached blob
33 GrAtlasTextBlob* createBlob(int glyphCount, int runCount, size_t maxVASize); 33 GrAtlasTextBlob* createBlob(int glyphCount, int runCount) {
34 GrAtlasTextBlob* createBlob(const SkTextBlob* blob, size_t maxVAStride) { 34 return GrAtlasTextBlob::Create(&fPool, glyphCount, runCount);
35 }
36 GrAtlasTextBlob* createBlob(const SkTextBlob* blob) {
35 int glyphCount = 0; 37 int glyphCount = 0;
36 int runCount = 0; 38 int runCount = 0;
37 BlobGlyphCount(&glyphCount, &runCount, blob); 39 BlobGlyphCount(&glyphCount, &runCount, blob);
38 GrAtlasTextBlob* cacheBlob = this->createBlob(glyphCount, runCount, maxV AStride); 40 GrAtlasTextBlob* cacheBlob = GrAtlasTextBlob::Create(&fPool, glyphCount, runCount);
39 return cacheBlob; 41 return cacheBlob;
40 } 42 }
41 43
42 static void SetupCacheBlobKey(GrAtlasTextBlob* cacheBlob,
43 const GrAtlasTextBlob::Key& key,
44 const SkMaskFilter::BlurRec& blurRec,
45 const SkPaint& paint) {
46 cacheBlob->fKey = key;
47 if (key.fHasBlur) {
48 cacheBlob->fBlurRec = blurRec;
49 }
50 if (key.fStyle != SkPaint::kFill_Style) {
51 cacheBlob->fStrokeInfo.fFrameWidth = paint.getStrokeWidth();
52 cacheBlob->fStrokeInfo.fMiterLimit = paint.getStrokeMiter();
53 cacheBlob->fStrokeInfo.fJoin = paint.getStrokeJoin();
54 }
55 }
56
57 GrAtlasTextBlob* createCachedBlob(const SkTextBlob* blob, 44 GrAtlasTextBlob* createCachedBlob(const SkTextBlob* blob,
58 const GrAtlasTextBlob::Key& key, 45 const GrAtlasTextBlob::Key& key,
59 const SkMaskFilter::BlurRec& blurRec, 46 const SkMaskFilter::BlurRec& blurRec,
60 const SkPaint& paint, 47 const SkPaint& paint) {
61 size_t maxVAStride) {
62 int glyphCount = 0; 48 int glyphCount = 0;
63 int runCount = 0; 49 int runCount = 0;
64 BlobGlyphCount(&glyphCount, &runCount, blob); 50 BlobGlyphCount(&glyphCount, &runCount, blob);
65 GrAtlasTextBlob* cacheBlob = this->createBlob(glyphCount, runCount, maxV AStride); 51 GrAtlasTextBlob* cacheBlob = GrAtlasTextBlob::Create(&fPool, glyphCount, runCount);
66 SetupCacheBlobKey(cacheBlob, key, blurRec, paint); 52 cacheBlob->setupKey(key, blurRec, paint);
67 this->add(cacheBlob); 53 this->add(cacheBlob);
68 return cacheBlob; 54 return cacheBlob;
69 } 55 }
70 56
71 GrAtlasTextBlob* find(const GrAtlasTextBlob::Key& key) { 57 GrAtlasTextBlob* find(const GrAtlasTextBlob::Key& key) {
72 return fCache.find(key); 58 return fCache.find(key);
73 } 59 }
74 60
75 void remove(GrAtlasTextBlob* blob) { 61 void remove(GrAtlasTextBlob* blob) {
76 fCache.remove(blob->fKey); 62 fCache.remove(blob->key());
77 fBlobList.remove(blob); 63 fBlobList.remove(blob);
78 blob->unref(); 64 blob->unref();
79 } 65 }
80 66
81 void add(GrAtlasTextBlob* blob) { 67 void add(GrAtlasTextBlob* blob) {
82 fCache.add(blob); 68 fCache.add(blob);
83 fBlobList.addToHead(blob); 69 fBlobList.addToHead(blob);
84 70
85 this->checkPurge(blob); 71 this->checkPurge(blob);
86 } 72 }
(...skipping 25 matching lines...) Expand all
112 private: 98 private:
113 typedef SkTInternalLList<GrAtlasTextBlob> BitmapBlobList; 99 typedef SkTInternalLList<GrAtlasTextBlob> BitmapBlobList;
114 100
115 void checkPurge(GrAtlasTextBlob* blob = nullptr) { 101 void checkPurge(GrAtlasTextBlob* blob = nullptr) {
116 // If we are overbudget, then unref until we are below budget again 102 // If we are overbudget, then unref until we are below budget again
117 if (fPool.size() > fBudget) { 103 if (fPool.size() > fBudget) {
118 BitmapBlobList::Iter iter; 104 BitmapBlobList::Iter iter;
119 iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart); 105 iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart);
120 GrAtlasTextBlob* lruBlob = nullptr; 106 GrAtlasTextBlob* lruBlob = nullptr;
121 while (fPool.size() > fBudget && (lruBlob = iter.get()) && lruBlob ! = blob) { 107 while (fPool.size() > fBudget && (lruBlob = iter.get()) && lruBlob ! = blob) {
122 fCache.remove(lruBlob->fKey); 108 fCache.remove(lruBlob->key());
123 109
124 // Backup the iterator before removing and unrefing the blob 110 // Backup the iterator before removing and unrefing the blob
125 iter.prev(); 111 iter.prev();
126 fBlobList.remove(lruBlob); 112 fBlobList.remove(lruBlob);
127 lruBlob->unref(); 113 lruBlob->unref();
128 } 114 }
129 115
130 // If we break out of the loop with lruBlob == blob, then we haven't purged enough 116 // If we break out of the loop with lruBlob == blob, then we haven't purged enough
131 // use the call back and try to free some more. If we are still ove rbudget after this, 117 // use the call back and try to free some more. If we are still ove rbudget after this,
132 // then this single textblob is over our budget 118 // then this single textblob is over our budget
(...skipping 16 matching lines...) Expand all
149 static const int kDefaultBudget = 1 << 22; 135 static const int kDefaultBudget = 1 << 22;
150 BitmapBlobList fBlobList; 136 BitmapBlobList fBlobList;
151 SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key> fCache; 137 SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key> fCache;
152 GrMemoryPool fPool; 138 GrMemoryPool fPool;
153 PFOverBudgetCB fCallback; 139 PFOverBudgetCB fCallback;
154 void* fData; 140 void* fData;
155 size_t fBudget; 141 size_t fBudget;
156 }; 142 };
157 143
158 #endif 144 #endif
OLDNEW
« no previous file with comments | « src/gpu/text/GrAtlasTextContext.cpp ('k') | src/gpu/text/GrTextBlobCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698