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