OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 #include "GrAtlas.h" | 8 #include "GrAtlas.h" |
9 #include "GrGpu.h" | 9 #include "GrGpu.h" |
10 #include "GrRectanizer.h" | 10 #include "GrRectanizer.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 SkASSERT(index >= 0); | 108 SkASSERT(index >= 0); |
109 fCache.removeAt(index, strikeToPurge->fFontScalerKey->getHash())
; | 109 fCache.removeAt(index, strikeToPurge->fFontScalerKey->getHash())
; |
110 this->detachStrikeFromList(strikeToPurge); | 110 this->detachStrikeFromList(strikeToPurge); |
111 delete strikeToPurge; | 111 delete strikeToPurge; |
112 } | 112 } |
113 break; | 113 break; |
114 } | 114 } |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 #if GR_DEBUG | 118 #if SK_DEBUG |
119 void GrFontCache::validate() const { | 119 void GrFontCache::validate() const { |
120 int count = fCache.count(); | 120 int count = fCache.count(); |
121 if (0 == count) { | 121 if (0 == count) { |
122 SkASSERT(!fHead); | 122 SkASSERT(!fHead); |
123 SkASSERT(!fTail); | 123 SkASSERT(!fTail); |
124 } else if (1 == count) { | 124 } else if (1 == count) { |
125 SkASSERT(fHead == fTail); | 125 SkASSERT(fHead == fTail); |
126 } else { | 126 } else { |
127 SkASSERT(fHead != fTail); | 127 SkASSERT(fHead != fTail); |
128 } | 128 } |
(...skipping 11 matching lines...) Expand all Loading... |
140 while (strike) { | 140 while (strike) { |
141 count2 += 1; | 141 count2 += 1; |
142 strike = strike->fPrev; | 142 strike = strike->fPrev; |
143 } | 143 } |
144 SkASSERT(count == count2); | 144 SkASSERT(count == count2); |
145 } | 145 } |
146 #endif | 146 #endif |
147 | 147 |
148 /////////////////////////////////////////////////////////////////////////////// | 148 /////////////////////////////////////////////////////////////////////////////// |
149 | 149 |
150 #if GR_DEBUG | 150 #if SK_DEBUG |
151 static int gCounter; | 151 static int gCounter; |
152 #endif | 152 #endif |
153 | 153 |
154 /* | 154 /* |
155 The text strike is specific to a given font/style/matrix setup, which is | 155 The text strike is specific to a given font/style/matrix setup, which is |
156 represented by the GrHostFontScaler object we are given in getGlyph(). | 156 represented by the GrHostFontScaler object we are given in getGlyph(). |
157 | 157 |
158 We map a 32bit glyphID to a GrGlyph record, which in turn points to a | 158 We map a 32bit glyphID to a GrGlyph record, which in turn points to a |
159 atlas and a position within that texture. | 159 atlas and a position within that texture. |
160 */ | 160 */ |
161 | 161 |
162 GrTextStrike::GrTextStrike(GrFontCache* cache, const GrKey* key, | 162 GrTextStrike::GrTextStrike(GrFontCache* cache, const GrKey* key, |
163 GrMaskFormat format, | 163 GrMaskFormat format, |
164 GrAtlasMgr* atlasMgr) : fPool(64) { | 164 GrAtlasMgr* atlasMgr) : fPool(64) { |
165 fFontScalerKey = key; | 165 fFontScalerKey = key; |
166 fFontScalerKey->ref(); | 166 fFontScalerKey->ref(); |
167 | 167 |
168 fFontCache = cache; // no need to ref, it won't go away before we do | 168 fFontCache = cache; // no need to ref, it won't go away before we do |
169 fAtlasMgr = atlasMgr; // no need to ref, it won't go away before we do | 169 fAtlasMgr = atlasMgr; // no need to ref, it won't go away before we do |
170 fAtlas = NULL; | 170 fAtlas = NULL; |
171 | 171 |
172 fMaskFormat = format; | 172 fMaskFormat = format; |
173 | 173 |
174 #if GR_DEBUG | 174 #if SK_DEBUG |
175 // GrPrintf(" GrTextStrike %p %d\n", this, gCounter); | 175 // GrPrintf(" GrTextStrike %p %d\n", this, gCounter); |
176 gCounter += 1; | 176 gCounter += 1; |
177 #endif | 177 #endif |
178 } | 178 } |
179 | 179 |
180 // these signatures are needed because they're used with | 180 // these signatures are needed because they're used with |
181 // SkTDArray::visitAll() (see destructor & removeUnusedAtlases()) | 181 // SkTDArray::visitAll() (see destructor & removeUnusedAtlases()) |
182 static void free_glyph(GrGlyph*& glyph) { glyph->free(); } | 182 static void free_glyph(GrGlyph*& glyph) { glyph->free(); } |
183 | 183 |
184 static void invalidate_glyph(GrGlyph*& glyph) { | 184 static void invalidate_glyph(GrGlyph*& glyph) { |
185 if (glyph->fAtlas && glyph->fAtlas->drawToken().isIssued()) { | 185 if (glyph->fAtlas && glyph->fAtlas->drawToken().isIssued()) { |
186 glyph->fAtlas = NULL; | 186 glyph->fAtlas = NULL; |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 GrTextStrike::~GrTextStrike() { | 190 GrTextStrike::~GrTextStrike() { |
191 GrAtlas::FreeLList(fAtlas); | 191 GrAtlas::FreeLList(fAtlas); |
192 fFontScalerKey->unref(); | 192 fFontScalerKey->unref(); |
193 fCache.getArray().visitAll(free_glyph); | 193 fCache.getArray().visitAll(free_glyph); |
194 | 194 |
195 #if GR_DEBUG | 195 #if SK_DEBUG |
196 gCounter -= 1; | 196 gCounter -= 1; |
197 // GrPrintf("~GrTextStrike %p %d\n", this, gCounter); | 197 // GrPrintf("~GrTextStrike %p %d\n", this, gCounter); |
198 #endif | 198 #endif |
199 } | 199 } |
200 | 200 |
201 GrGlyph* GrTextStrike::generateGlyph(GrGlyph::PackedID packed, | 201 GrGlyph* GrTextStrike::generateGlyph(GrGlyph::PackedID packed, |
202 GrFontScaler* scaler) { | 202 GrFontScaler* scaler) { |
203 SkIRect bounds; | 203 SkIRect bounds; |
204 if (!scaler->getPackedGlyphBounds(packed, &bounds)) { | 204 if (!scaler->getPackedGlyphBounds(packed, &bounds)) { |
205 return NULL; | 205 return NULL; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 fMaskFormat, | 248 fMaskFormat, |
249 &glyph->fAtlasLocation); | 249 &glyph->fAtlasLocation); |
250 if (NULL == atlas) { | 250 if (NULL == atlas) { |
251 return false; | 251 return false; |
252 } | 252 } |
253 | 253 |
254 glyph->fAtlas = atlas; | 254 glyph->fAtlas = atlas; |
255 atlas->setDrawToken(currentDrawToken); | 255 atlas->setDrawToken(currentDrawToken); |
256 return true; | 256 return true; |
257 } | 257 } |
OLD | NEW |