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 "GrFontCache.h" | 8 #include "GrFontCache.h" |
| 9 #include "GrFontAtlasSizes.h" |
9 #include "GrGpu.h" | 10 #include "GrGpu.h" |
10 #include "GrRectanizer.h" | 11 #include "GrRectanizer.h" |
11 #include "GrSurfacePriv.h" | 12 #include "GrSurfacePriv.h" |
12 #include "SkString.h" | 13 #include "SkString.h" |
13 | 14 |
14 #include "SkDistanceFieldGen.h" | 15 #include "SkDistanceFieldGen.h" |
15 | 16 |
16 /////////////////////////////////////////////////////////////////////////////// | 17 /////////////////////////////////////////////////////////////////////////////// |
17 | 18 |
18 #define GR_ATLAS_TEXTURE_WIDTH 1024 | |
19 #define GR_ATLAS_TEXTURE_HEIGHT 2048 | |
20 | |
21 #define GR_PLOT_WIDTH 256 | |
22 #define GR_PLOT_HEIGHT 256 | |
23 | |
24 #define GR_NUM_PLOTS_X (GR_ATLAS_TEXTURE_WIDTH / GR_PLOT_WIDTH) | |
25 #define GR_NUM_PLOTS_Y (GR_ATLAS_TEXTURE_HEIGHT / GR_PLOT_HEIGHT) | |
26 | |
27 #define FONT_CACHE_STATS 0 | 19 #define FONT_CACHE_STATS 0 |
28 #if FONT_CACHE_STATS | 20 #if FONT_CACHE_STATS |
29 static int g_PurgeCount = 0; | 21 static int g_PurgeCount = 0; |
30 #endif | 22 #endif |
31 | 23 |
32 GrFontCache::GrFontCache(GrGpu* gpu) : fGpu(gpu) { | 24 GrFontCache::GrFontCache(GrGpu* gpu) : fGpu(gpu) { |
33 gpu->ref(); | 25 gpu->ref(); |
34 for (int i = 0; i < kAtlasCount; ++i) { | 26 for (int i = 0; i < kAtlasCount; ++i) { |
35 fAtlases[i] = NULL; | 27 fAtlases[i] = NULL; |
36 } | 28 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 delete strike; | 106 delete strike; |
115 } | 107 } |
116 | 108 |
117 | 109 |
118 GrPlot* GrFontCache::addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* u
sage, | 110 GrPlot* GrFontCache::addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* u
sage, |
119 int width, int height, const void* image, | 111 int width, int height, const void* image, |
120 SkIPoint16* loc) { | 112 SkIPoint16* loc) { |
121 GrPixelConfig config = mask_format_to_pixel_config(format); | 113 GrPixelConfig config = mask_format_to_pixel_config(format); |
122 int atlasIndex = mask_format_to_atlas_index(format); | 114 int atlasIndex = mask_format_to_atlas_index(format); |
123 if (NULL == fAtlases[atlasIndex]) { | 115 if (NULL == fAtlases[atlasIndex]) { |
124 SkISize textureSize = SkISize::Make(GR_ATLAS_TEXTURE_WIDTH, | 116 SkISize textureSize = SkISize::Make(GR_FONT_ATLAS_TEXTURE_WIDTH, |
125 GR_ATLAS_TEXTURE_HEIGHT); | 117 GR_FONT_ATLAS_TEXTURE_HEIGHT); |
126 fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrSurfac
eFlags, | 118 fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrSurfac
eFlags, |
127 textureSize, | 119 textureSize, |
128 GR_NUM_PLOTS_X, | 120 GR_FONT_ATLAS_NUM_PLOTS_X, |
129 GR_NUM_PLOTS_Y, | 121 GR_FONT_ATLAS_NUM_PLOTS_Y, |
130 true)); | 122 true)); |
131 } | 123 } |
132 return fAtlases[atlasIndex]->addToAtlas(usage, width, height, image, loc); | 124 return fAtlases[atlasIndex]->addToAtlas(usage, width, height, image, loc); |
133 } | 125 } |
134 | 126 |
135 | 127 |
136 bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* gl
yph) { | 128 bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* gl
yph) { |
137 SkASSERT(preserveStrike); | 129 SkASSERT(preserveStrike); |
138 | 130 |
139 int index = mask_format_to_atlas_index(glyph->fMaskFormat); | 131 int index = mask_format_to_atlas_index(glyph->fMaskFormat); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 ++iter; | 274 ++iter; |
283 } | 275 } |
284 | 276 |
285 GrAtlas::RemovePlot(&fPlotUsage, plot); | 277 GrAtlas::RemovePlot(&fPlotUsage, plot); |
286 } | 278 } |
287 | 279 |
288 bool GrTextStrike::glyphTooLargeForAtlas(GrGlyph* glyph) { | 280 bool GrTextStrike::glyphTooLargeForAtlas(GrGlyph* glyph) { |
289 int width = glyph->fBounds.width(); | 281 int width = glyph->fBounds.width(); |
290 int height = glyph->fBounds.height(); | 282 int height = glyph->fBounds.height(); |
291 int pad = fUseDistanceField ? 2 * SK_DistanceFieldPad : 0; | 283 int pad = fUseDistanceField ? 2 * SK_DistanceFieldPad : 0; |
292 if (width + pad > GR_PLOT_WIDTH) { | 284 if (width + pad > GR_FONT_ATLAS_PLOT_WIDTH) { |
293 return true; | 285 return true; |
294 } | 286 } |
295 if (height + pad > GR_PLOT_HEIGHT) { | 287 if (height + pad > GR_FONT_ATLAS_PLOT_HEIGHT) { |
296 return true; | 288 return true; |
297 } | 289 } |
298 | 290 |
299 return false; | 291 return false; |
300 } | 292 } |
301 | 293 |
302 bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) { | 294 bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) { |
303 #if 0 // testing hack to force us to flush our cache often | 295 #if 0 // testing hack to force us to flush our cache often |
304 static int gCounter; | 296 static int gCounter; |
305 if ((++gCounter % 10) == 0) return false; | 297 if ((++gCounter % 10) == 0) return false; |
(...skipping 30 matching lines...) Expand all Loading... |
336 glyph->width(), glyph->height(), | 328 glyph->width(), glyph->height(), |
337 storage.get(), &glyph->fAtlasLocation)
; | 329 storage.get(), &glyph->fAtlasLocation)
; |
338 | 330 |
339 if (NULL == plot) { | 331 if (NULL == plot) { |
340 return false; | 332 return false; |
341 } | 333 } |
342 | 334 |
343 glyph->fPlot = plot; | 335 glyph->fPlot = plot; |
344 return true; | 336 return true; |
345 } | 337 } |
OLD | NEW |