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 "GrFontAtlasSizes.h" |
10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 delete strike; | 106 delete strike; |
107 } | 107 } |
108 | 108 |
109 | 109 |
110 GrPlot* GrFontCache::addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* u
sage, | 110 GrPlot* GrFontCache::addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* u
sage, |
111 int width, int height, const void* image, | 111 int width, int height, const void* image, |
112 SkIPoint16* loc) { | 112 SkIPoint16* loc) { |
113 GrPixelConfig config = mask_format_to_pixel_config(format); | 113 GrPixelConfig config = mask_format_to_pixel_config(format); |
114 int atlasIndex = mask_format_to_atlas_index(format); | 114 int atlasIndex = mask_format_to_atlas_index(format); |
115 if (NULL == fAtlases[atlasIndex]) { | 115 if (NULL == fAtlases[atlasIndex]) { |
116 SkISize textureSize = SkISize::Make(GR_FONT_ATLAS_TEXTURE_WIDTH, | 116 if (kA8_GrMaskFormat == format) { |
117 GR_FONT_ATLAS_TEXTURE_HEIGHT); | 117 SkISize textureSize = SkISize::Make(GR_FONT_ATLAS_A8_TEXTURE_WIDTH, |
118 fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrSurfac
eFlags, | 118 GR_FONT_ATLAS_TEXTURE_HEIGHT); |
119 textureSize, | 119 fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrSu
rfaceFlags, |
120 GR_FONT_ATLAS_NUM_PLOTS_X, | 120 textureSize, |
121 GR_FONT_ATLAS_NUM_PLOTS_Y, | 121 GR_FONT_ATLAS_A8_NUM_PLO
TS_X, |
122 true)); | 122 GR_FONT_ATLAS_NUM_PLOTS_
Y, |
| 123 true)); |
| 124 } else { |
| 125 SkISize textureSize = SkISize::Make(GR_FONT_ATLAS_TEXTURE_WIDTH, |
| 126 GR_FONT_ATLAS_TEXTURE_HEIGHT); |
| 127 fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrSu
rfaceFlags, |
| 128 textureSize, |
| 129 GR_FONT_ATLAS_NUM_PLOTS_
X, |
| 130 GR_FONT_ATLAS_NUM_PLOTS_
Y, |
| 131 true)); |
| 132 } |
123 } | 133 } |
124 return fAtlases[atlasIndex]->addToAtlas(usage, width, height, image, loc); | 134 return fAtlases[atlasIndex]->addToAtlas(usage, width, height, image, loc); |
125 } | 135 } |
126 | 136 |
127 | 137 |
128 bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* gl
yph) { | 138 bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* gl
yph) { |
129 SkASSERT(preserveStrike); | 139 SkASSERT(preserveStrike); |
130 | 140 |
131 int index = mask_format_to_atlas_index(glyph->fMaskFormat); | 141 int index = mask_format_to_atlas_index(glyph->fMaskFormat); |
132 GrAtlas* atlas = fAtlases[index]; | 142 GrAtlas* atlas = fAtlases[index]; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 ++iter; | 284 ++iter; |
275 } | 285 } |
276 | 286 |
277 GrAtlas::RemovePlot(&fPlotUsage, plot); | 287 GrAtlas::RemovePlot(&fPlotUsage, plot); |
278 } | 288 } |
279 | 289 |
280 bool GrTextStrike::glyphTooLargeForAtlas(GrGlyph* glyph) { | 290 bool GrTextStrike::glyphTooLargeForAtlas(GrGlyph* glyph) { |
281 int width = glyph->fBounds.width(); | 291 int width = glyph->fBounds.width(); |
282 int height = glyph->fBounds.height(); | 292 int height = glyph->fBounds.height(); |
283 int pad = fUseDistanceField ? 2 * SK_DistanceFieldPad : 0; | 293 int pad = fUseDistanceField ? 2 * SK_DistanceFieldPad : 0; |
284 if (width + pad > GR_FONT_ATLAS_PLOT_WIDTH) { | 294 int plotWidth = (kA8_GrMaskFormat == glyph->fMaskFormat) ? GR_FONT_ATLAS_A8_
PLOT_WIDTH |
| 295 : GR_FONT_ATLAS_PLO
T_WIDTH; |
| 296 if (width + pad > plotWidth) { |
285 return true; | 297 return true; |
286 } | 298 } |
287 if (height + pad > GR_FONT_ATLAS_PLOT_HEIGHT) { | 299 if (height + pad > GR_FONT_ATLAS_PLOT_HEIGHT) { |
288 return true; | 300 return true; |
289 } | 301 } |
290 | 302 |
291 return false; | 303 return false; |
292 } | 304 } |
293 | 305 |
294 bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) { | 306 bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 glyph->width(), glyph->height(), | 340 glyph->width(), glyph->height(), |
329 storage.get(), &glyph->fAtlasLocation)
; | 341 storage.get(), &glyph->fAtlasLocation)
; |
330 | 342 |
331 if (NULL == plot) { | 343 if (NULL == plot) { |
332 return false; | 344 return false; |
333 } | 345 } |
334 | 346 |
335 glyph->fPlot = plot; | 347 glyph->fPlot = plot; |
336 return true; | 348 return true; |
337 } | 349 } |
OLD | NEW |