OLD | NEW |
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 #include "GrBatchFontCache.h" | 8 #include "GrBatchFontCache.h" |
9 #include "GrContext.h" | 9 #include "GrContext.h" |
10 #include "GrFontAtlasSizes.h" | 10 #include "GrFontAtlasSizes.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 desc, GrTextureProvider::kApprox_ScratchTexMatch, true); | 32 desc, GrTextureProvider::kApprox_ScratchTexMatch, true); |
33 if (!texture) { | 33 if (!texture) { |
34 return NULL; | 34 return NULL; |
35 } | 35 } |
36 return SkNEW_ARGS(GrBatchAtlas, (texture, numPlotsX, numPlotsY)); | 36 return SkNEW_ARGS(GrBatchAtlas, (texture, numPlotsX, numPlotsY)); |
37 } | 37 } |
38 | 38 |
39 bool GrBatchFontCache::initAtlas(GrMaskFormat format) { | 39 bool GrBatchFontCache::initAtlas(GrMaskFormat format) { |
40 int index = MaskFormatToAtlasIndex(format); | 40 int index = MaskFormatToAtlasIndex(format); |
41 if (!fAtlases[index]) { | 41 if (!fAtlases[index]) { |
42 GrPixelConfig config = this->getPixelConfig(format); | 42 GrPixelConfig config = MaskFormatToPixelConfig(format); |
43 if (kA8_GrMaskFormat == format) { | 43 if (kA8_GrMaskFormat == format) { |
44 fAtlases[index] = make_atlas(fContext, config, | 44 fAtlases[index] = make_atlas(fContext, config, |
45 GR_FONT_ATLAS_A8_TEXTURE_WIDTH, | 45 GR_FONT_ATLAS_A8_TEXTURE_WIDTH, |
46 GR_FONT_ATLAS_TEXTURE_HEIGHT, | 46 GR_FONT_ATLAS_TEXTURE_HEIGHT, |
47 GR_FONT_ATLAS_A8_NUM_PLOTS_X, | 47 GR_FONT_ATLAS_A8_NUM_PLOTS_X, |
48 GR_FONT_ATLAS_NUM_PLOTS_Y); | 48 GR_FONT_ATLAS_NUM_PLOTS_Y); |
49 } else { | 49 } else { |
50 fAtlases[index] = make_atlas(fContext, config, | 50 fAtlases[index] = make_atlas(fContext, config, |
51 GR_FONT_ATLAS_TEXTURE_WIDTH, | 51 GR_FONT_ATLAS_TEXTURE_WIDTH, |
52 GR_FONT_ATLAS_TEXTURE_HEIGHT, | 52 GR_FONT_ATLAS_TEXTURE_HEIGHT, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 (*iter).unref(); | 92 (*iter).unref(); |
93 ++iter; | 93 ++iter; |
94 } | 94 } |
95 fCache.rewind(); | 95 fCache.rewind(); |
96 for (int i = 0; i < kMaskFormatCount; ++i) { | 96 for (int i = 0; i < kMaskFormatCount; ++i) { |
97 SkDELETE(fAtlases[i]); | 97 SkDELETE(fAtlases[i]); |
98 fAtlases[i] = NULL; | 98 fAtlases[i] = NULL; |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 GrPixelConfig GrBatchFontCache::getPixelConfig(GrMaskFormat format) const { | |
103 static const GrPixelConfig kPixelConfigs[] = { | |
104 kAlpha_8_GrPixelConfig, | |
105 kRGB_565_GrPixelConfig, | |
106 kSkia8888_GrPixelConfig | |
107 }; | |
108 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(kPixelConfigs) == kMaskFormatCount, array_s
ize_mismatch); | |
109 | |
110 return kPixelConfigs[format]; | |
111 } | |
112 | |
113 void GrBatchFontCache::HandleEviction(GrBatchAtlas::AtlasID id, void* ptr) { | 102 void GrBatchFontCache::HandleEviction(GrBatchAtlas::AtlasID id, void* ptr) { |
114 GrBatchFontCache* fontCache = reinterpret_cast<GrBatchFontCache*>(ptr); | 103 GrBatchFontCache* fontCache = reinterpret_cast<GrBatchFontCache*>(ptr); |
115 | 104 |
116 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey>::Iter iter(&fontCache->fCac
he); | 105 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey>::Iter iter(&fontCache->fCac
he); |
117 for (; !iter.done(); ++iter) { | 106 for (; !iter.done(); ++iter) { |
118 GrBatchTextStrike* strike = &*iter; | 107 GrBatchTextStrike* strike = &*iter; |
119 strike->removeID(id); | 108 strike->removeID(id); |
120 | 109 |
121 // clear out any empty strikes. We will preserve the strike whose call
to addToAtlas | 110 // clear out any empty strikes. We will preserve the strike whose call
to addToAtlas |
122 // triggered the eviction | 111 // triggered the eviction |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 } | 225 } |
237 | 226 |
238 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, batchTarget, g
lyph->fMaskFormat, | 227 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, batchTarget, g
lyph->fMaskFormat, |
239 glyph->width(), glyph->height(), | 228 glyph->width(), glyph->height(), |
240 storage.get(), &glyph->fAtlasLoca
tion); | 229 storage.get(), &glyph->fAtlasLoca
tion); |
241 if (success) { | 230 if (success) { |
242 fAtlasedGlyphs++; | 231 fAtlasedGlyphs++; |
243 } | 232 } |
244 return success; | 233 return success; |
245 } | 234 } |
OLD | NEW |