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" |
11 #include "GrTextStrike.h" | 11 #include "GrTextStrike.h" |
12 #include "GrTextStrike_impl.h" | 12 #include "GrTextStrike_impl.h" |
13 | 13 |
14 SK_DEFINE_INST_COUNT(GrFontScaler) | 14 SK_DEFINE_INST_COUNT(GrFontScaler) |
15 SK_DEFINE_INST_COUNT(GrKey) | 15 SK_DEFINE_INST_COUNT(GrKey) |
16 | 16 |
17 /////////////////////////////////////////////////////////////////////////////// | 17 /////////////////////////////////////////////////////////////////////////////// |
18 | 18 |
19 #define FONT_CACHE_STATS 0 | 19 #define FONT_CACHE_STATS 0 |
20 #if FONT_CACHE_STATS | 20 #if FONT_CACHE_STATS |
21 static int g_PurgeCount = 0; | 21 static int g_PurgeCount = 0; |
22 #endif | 22 #endif |
23 | 23 |
24 GrFontCache::GrFontCache(GrGpu* gpu) : fGpu(gpu) { | 24 GrFontCache::GrFontCache(GrGpu* gpu) : fGpu(gpu) { |
25 gpu->ref(); | 25 gpu->ref(); |
26 fAtlasMgr = NULL; | 26 for (int i = 0; i < kMaskFormatCount; ++i) { |
| 27 fAtlasMgr[i] = NULL; |
| 28 } |
27 | 29 |
28 fHead = fTail = NULL; | 30 fHead = fTail = NULL; |
29 } | 31 } |
30 | 32 |
31 GrFontCache::~GrFontCache() { | 33 GrFontCache::~GrFontCache() { |
32 fCache.deleteAll(); | 34 fCache.deleteAll(); |
33 delete fAtlasMgr; | 35 for (int i = 0; i < kMaskFormatCount; ++i) { |
| 36 delete fAtlasMgr[i]; |
| 37 } |
34 fGpu->unref(); | 38 fGpu->unref(); |
35 #if FONT_CACHE_STATS | 39 #if FONT_CACHE_STATS |
36 GrPrintf("Num purges: %d\n", g_PurgeCount); | 40 GrPrintf("Num purges: %d\n", g_PurgeCount); |
37 #endif | 41 #endif |
38 } | 42 } |
39 | 43 |
40 GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler, | 44 GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler, |
41 const Key& key) { | 45 const Key& key) { |
42 if (NULL == fAtlasMgr) { | 46 GrMaskFormat format = scaler->getMaskFormat(); |
43 fAtlasMgr = SkNEW_ARGS(GrAtlasMgr, (fGpu)); | 47 if (NULL == fAtlasMgr[format]) { |
| 48 fAtlasMgr[format] = SkNEW_ARGS(GrAtlasMgr, (fGpu, format)); |
44 } | 49 } |
45 GrTextStrike* strike = SkNEW_ARGS(GrTextStrike, | 50 GrTextStrike* strike = SkNEW_ARGS(GrTextStrike, |
46 (this, scaler->getKey(), | 51 (this, scaler->getKey(), |
47 scaler->getMaskFormat(), fAtlasMgr)); | 52 scaler->getMaskFormat(), fAtlasMgr[format
])); |
48 fCache.insert(key, strike); | 53 fCache.insert(key, strike); |
49 | 54 |
50 if (fHead) { | 55 if (fHead) { |
51 fHead->fPrev = strike; | 56 fHead->fPrev = strike; |
52 } else { | 57 } else { |
53 SkASSERT(NULL == fTail); | 58 SkASSERT(NULL == fTail); |
54 fTail = strike; | 59 fTail = strike; |
55 } | 60 } |
56 strike->fPrev = NULL; | 61 strike->fPrev = NULL; |
57 strike->fNext = fHead; | 62 strike->fNext = fHead; |
58 fHead = strike; | 63 fHead = strike; |
59 | 64 |
60 return strike; | 65 return strike; |
61 } | 66 } |
62 | 67 |
63 void GrFontCache::freeAll() { | 68 void GrFontCache::freeAll() { |
64 fCache.deleteAll(); | 69 fCache.deleteAll(); |
65 delete fAtlasMgr; | 70 for (int i = 0; i < kMaskFormatCount; ++i) { |
66 fAtlasMgr = NULL; | 71 delete fAtlasMgr[i]; |
| 72 fAtlasMgr[i] = NULL; |
| 73 } |
67 fHead = NULL; | 74 fHead = NULL; |
68 fTail = NULL; | 75 fTail = NULL; |
69 } | 76 } |
70 | 77 |
71 void GrFontCache::purgeExceptFor(GrTextStrike* preserveStrike) { | 78 void GrFontCache::purgeExceptFor(GrTextStrike* preserveStrike) { |
72 SkASSERT(NULL != preserveStrike); | 79 SkASSERT(NULL != preserveStrike); |
73 GrTextStrike* strike = fTail; | 80 GrTextStrike* strike = fTail; |
74 bool purge = true; | 81 bool purge = true; |
75 GrMaskFormat maskFormat = preserveStrike->fMaskFormat; | 82 GrMaskFormat maskFormat = preserveStrike->fMaskFormat; |
76 while (strike) { | 83 while (strike) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 SkAutoSMalloc<1024> storage(size); | 249 SkAutoSMalloc<1024> storage(size); |
243 if (!scaler->getPackedGlyphImage(glyph->fPackedID, glyph->width(), | 250 if (!scaler->getPackedGlyphImage(glyph->fPackedID, glyph->width(), |
244 glyph->height(), | 251 glyph->height(), |
245 glyph->width() * bytesPerPixel, | 252 glyph->width() * bytesPerPixel, |
246 storage.get())) { | 253 storage.get())) { |
247 return false; | 254 return false; |
248 } | 255 } |
249 | 256 |
250 GrAtlas* atlas = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(), | 257 GrAtlas* atlas = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(), |
251 glyph->height(), storage.get(), | 258 glyph->height(), storage.get(), |
252 fMaskFormat, | |
253 &glyph->fAtlasLocation); | 259 &glyph->fAtlasLocation); |
254 if (NULL == atlas) { | 260 if (NULL == atlas) { |
255 return false; | 261 return false; |
256 } | 262 } |
257 | 263 |
258 glyph->fAtlas = atlas; | 264 glyph->fAtlas = atlas; |
259 atlas->setDrawToken(currentDrawToken); | 265 atlas->setDrawToken(currentDrawToken); |
260 return true; | 266 return true; |
261 } | 267 } |
OLD | NEW |