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

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

Issue 1250693002: Add sanity check to GrAtlasTextBlob (Closed) Base URL: https://skia.googlesource.com/skia.git@debug
Patch Set: more Created 5 years, 5 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/GrAtlasTextContext.cpp ('k') | src/gpu/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 20 matching lines...) Expand all
31 // creates an uncached blob 31 // creates an uncached blob
32 GrAtlasTextBlob* createBlob(int glyphCount, int runCount, size_t maxVASize); 32 GrAtlasTextBlob* createBlob(int glyphCount, int runCount, size_t maxVASize);
33 GrAtlasTextBlob* createBlob(const SkTextBlob* blob, size_t maxVAStride) { 33 GrAtlasTextBlob* createBlob(const SkTextBlob* blob, size_t maxVAStride) {
34 int glyphCount = 0; 34 int glyphCount = 0;
35 int runCount = 0; 35 int runCount = 0;
36 BlobGlyphCount(&glyphCount, &runCount, blob); 36 BlobGlyphCount(&glyphCount, &runCount, blob);
37 GrAtlasTextBlob* cacheBlob = this->createBlob(glyphCount, runCount, maxV AStride); 37 GrAtlasTextBlob* cacheBlob = this->createBlob(glyphCount, runCount, maxV AStride);
38 return cacheBlob; 38 return cacheBlob;
39 } 39 }
40 40
41 GrAtlasTextBlob* createCachedBlob(const SkTextBlob* blob, 41 static void SetupCacheBlobKey(GrAtlasTextBlob* cacheBlob,
42 const GrAtlasTextBlob::Key& key, 42 const GrAtlasTextBlob::Key& key,
43 const SkMaskFilter::BlurRec& blurRec, 43 const SkMaskFilter::BlurRec& blurRec,
44 const SkPaint& paint, 44 const SkPaint& paint) {
45 size_t maxVAStride) {
46 int glyphCount = 0;
47 int runCount = 0;
48 BlobGlyphCount(&glyphCount, &runCount, blob);
49 GrAtlasTextBlob* cacheBlob = this->createBlob(glyphCount, runCount, maxV AStride);
50 cacheBlob->fKey = key; 45 cacheBlob->fKey = key;
51 if (key.fHasBlur) { 46 if (key.fHasBlur) {
52 cacheBlob->fBlurRec = blurRec; 47 cacheBlob->fBlurRec = blurRec;
53 } 48 }
54 if (key.fStyle != SkPaint::kFill_Style) { 49 if (key.fStyle != SkPaint::kFill_Style) {
55 cacheBlob->fStrokeInfo.fFrameWidth = paint.getStrokeWidth(); 50 cacheBlob->fStrokeInfo.fFrameWidth = paint.getStrokeWidth();
56 cacheBlob->fStrokeInfo.fMiterLimit = paint.getStrokeMiter(); 51 cacheBlob->fStrokeInfo.fMiterLimit = paint.getStrokeMiter();
57 cacheBlob->fStrokeInfo.fJoin = paint.getStrokeJoin(); 52 cacheBlob->fStrokeInfo.fJoin = paint.getStrokeJoin();
58 } 53 }
54 }
55
56 GrAtlasTextBlob* createCachedBlob(const SkTextBlob* blob,
57 const GrAtlasTextBlob::Key& key,
58 const SkMaskFilter::BlurRec& blurRec,
59 const SkPaint& paint,
60 size_t maxVAStride) {
61 int glyphCount = 0;
62 int runCount = 0;
63 BlobGlyphCount(&glyphCount, &runCount, blob);
64 GrAtlasTextBlob* cacheBlob = this->createBlob(glyphCount, runCount, maxV AStride);
65 SetupCacheBlobKey(cacheBlob, key, blurRec, paint);
59 this->add(cacheBlob); 66 this->add(cacheBlob);
60 return cacheBlob; 67 return cacheBlob;
61 } 68 }
62 69
63 GrAtlasTextBlob* find(const GrAtlasTextBlob::Key& key) { 70 GrAtlasTextBlob* find(const GrAtlasTextBlob::Key& key) {
64 return fCache.find(key); 71 return fCache.find(key);
65 } 72 }
66 73
67 void remove(GrAtlasTextBlob* blob) { 74 void remove(GrAtlasTextBlob* blob) {
68 fCache.remove(blob->fKey); 75 fCache.remove(blob->fKey);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 if (fBlobList.head() == blob) { 115 if (fBlobList.head() == blob) {
109 return; 116 return;
110 } 117 }
111 118
112 fBlobList.remove(blob); 119 fBlobList.remove(blob);
113 fBlobList.addToHead(blob); 120 fBlobList.addToHead(blob);
114 } 121 }
115 122
116 void freeAll(); 123 void freeAll();
117 124
118 private:
119 // TODO move to SkTextBlob 125 // TODO move to SkTextBlob
120 void BlobGlyphCount(int* glyphCount, int* runCount, const SkTextBlob* blob) { 126 static void BlobGlyphCount(int* glyphCount, int* runCount, const SkTextBlob* blob) {
121 SkTextBlob::RunIterator itCounter(blob); 127 SkTextBlob::RunIterator itCounter(blob);
122 for (; !itCounter.done(); itCounter.next(), (*runCount)++) { 128 for (; !itCounter.done(); itCounter.next(), (*runCount)++) {
123 *glyphCount += itCounter.glyphCount(); 129 *glyphCount += itCounter.glyphCount();
124 } 130 }
125 } 131 }
126 132
133 private:
127 typedef SkTInternalLList<GrAtlasTextBlob> BitmapBlobList; 134 typedef SkTInternalLList<GrAtlasTextBlob> BitmapBlobList;
128 135
129 // Budget was chosen to be ~4 megabytes. The min alloc and pre alloc sizes in the pool are 136 // Budget was chosen to be ~4 megabytes. The min alloc and pre alloc sizes in the pool are
130 // based off of the largest cached textblob I have seen in the skps(a couple of kilobytes). 137 // based off of the largest cached textblob I have seen in the skps(a couple of kilobytes).
131 static const int kPreAllocSize = 1 << 17; 138 static const int kPreAllocSize = 1 << 17;
132 static const int kMinGrowthSize = 1 << 17; 139 static const int kMinGrowthSize = 1 << 17;
133 static const int kBudget = 1 << 22; 140 static const int kBudget = 1 << 22;
134 BitmapBlobList fBlobList; 141 BitmapBlobList fBlobList;
135 SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key> fCache; 142 SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key> fCache;
136 GrMemoryPool fPool; 143 GrMemoryPool fPool;
137 PFOverBudgetCB fCallback; 144 PFOverBudgetCB fCallback;
138 void* fData; 145 void* fData;
139 }; 146 };
140 147
141 #endif 148 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAtlasTextContext.cpp ('k') | src/gpu/GrTextBlobCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698