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 "GrAtlasGlyphCache.h" | 8 #include "GrAtlasGlyphCache.h" |
9 #include "GrContext.h" | 9 #include "GrContext.h" |
10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
11 #include "GrRectanizer.h" | 11 #include "GrRectanizer.h" |
12 #include "GrResourceProvider.h" | 12 #include "GrResourceProvider.h" |
13 #include "GrSurfacePriv.h" | 13 #include "GrSurfacePriv.h" |
14 #include "SkString.h" | 14 #include "SkString.h" |
15 | 15 |
16 #include "SkDistanceFieldGen.h" | 16 #include "SkDistanceFieldGen.h" |
17 #include "GrDistanceFieldGenFromVector.h" | |
18 | 17 |
19 bool GrAtlasGlyphCache::initAtlas(GrMaskFormat format) { | 18 bool GrAtlasGlyphCache::initAtlas(GrMaskFormat format) { |
20 int index = MaskFormatToAtlasIndex(format); | 19 int index = MaskFormatToAtlasIndex(format); |
21 if (!fAtlases[index]) { | 20 if (!fAtlases[index]) { |
22 GrPixelConfig config = MaskFormatToPixelConfig(format, *fContext->caps()
); | 21 GrPixelConfig config = MaskFormatToPixelConfig(format, *fContext->caps()
); |
23 int width = fAtlasConfigs[index].fWidth; | 22 int width = fAtlasConfigs[index].fWidth; |
24 int height = fAtlasConfigs[index].fHeight; | 23 int height = fAtlasConfigs[index].fHeight; |
25 int numPlotsX = fAtlasConfigs[index].numPlotsX(); | 24 int numPlotsX = fAtlasConfigs[index].numPlotsX(); |
26 int numPlotsY = fAtlasConfigs[index].numPlotsY(); | 25 int numPlotsY = fAtlasConfigs[index].numPlotsY(); |
27 | 26 |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 dst = (char*)dst + dstRB; | 313 dst = (char*)dst + dstRB; |
315 } | 314 } |
316 } | 315 } |
317 return true; | 316 return true; |
318 } | 317 } |
319 | 318 |
320 static bool get_packed_glyph_df_image(SkGlyphCache* cache, const SkGlyph& glyph, | 319 static bool get_packed_glyph_df_image(SkGlyphCache* cache, const SkGlyph& glyph, |
321 int width, int height, void* dst) { | 320 int width, int height, void* dst) { |
322 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); | 321 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); |
323 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); | 322 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); |
324 | 323 const void* image = cache->findImage(glyph); |
325 #ifndef SK_USE_LEGACY_DISTANCE_FIELDS | 324 if (nullptr == image) { |
326 const SkPath* path = cache->findPath(glyph); | 325 return false; |
327 if (nullptr == path) { | 326 } |
| 327 // now generate the distance field |
| 328 SkASSERT(dst); |
| 329 SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); |
| 330 if (SkMask::kA8_Format == maskFormat) { |
| 331 // make the distance field from the image |
| 332 SkGenerateDistanceFieldFromA8Image((unsigned char*)dst, |
| 333 (unsigned char*)image, |
| 334 glyph.fWidth, glyph.fHeight, |
| 335 glyph.rowBytes()); |
| 336 } else if (SkMask::kBW_Format == maskFormat) { |
| 337 // make the distance field from the image |
| 338 SkGenerateDistanceFieldFromBWImage((unsigned char*)dst, |
| 339 (unsigned char*)image, |
| 340 glyph.fWidth, glyph.fHeight, |
| 341 glyph.rowBytes()); |
| 342 } else { |
328 return false; | 343 return false; |
329 } | 344 } |
330 | 345 |
331 // now generate the distance field | |
332 SkASSERT(dst); | |
333 SkMatrix drawMatrix; | |
334 drawMatrix.setTranslate((SkScalar)-glyph.fLeft, (SkScalar)-glyph.fTop); | |
335 | |
336 // Generate signed distance field directly from SkPath | |
337 bool succeed = GrGenerateDistanceFieldFromPath((unsigned char*)dst, | |
338 *path, drawMatrix, | |
339 width, height, width * sizeof(unsigne
d char)); | |
340 | |
341 if (!succeed) { | |
342 #endif | |
343 const void* image = cache->findImage(glyph); | |
344 if (nullptr == image) { | |
345 return false; | |
346 } | |
347 | |
348 // now generate the distance field | |
349 SkASSERT(dst); | |
350 SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskForma
t); | |
351 if (SkMask::kA8_Format == maskFormat) { | |
352 // make the distance field from the image | |
353 SkGenerateDistanceFieldFromA8Image((unsigned char*)dst, | |
354 (unsigned char*)image, | |
355 glyph.fWidth, glyph.fHeight, | |
356 glyph.rowBytes()); | |
357 } else if (SkMask::kBW_Format == maskFormat) { | |
358 // make the distance field from the image | |
359 SkGenerateDistanceFieldFromBWImage((unsigned char*)dst, | |
360 (unsigned char*)image, | |
361 glyph.fWidth, glyph.fHeight, | |
362 glyph.rowBytes()); | |
363 } else { | |
364 return false; | |
365 } | |
366 #ifndef SK_USE_LEGACY_DISTANCE_FIELDS | |
367 } | |
368 #endif | |
369 return true; | 346 return true; |
370 } | 347 } |
371 | 348 |
372 /////////////////////////////////////////////////////////////////////////////// | 349 /////////////////////////////////////////////////////////////////////////////// |
373 | 350 |
374 /* | 351 /* |
375 The text strike is specific to a given font/style/matrix setup, which is | 352 The text strike is specific to a given font/style/matrix setup, which is |
376 represented by the GrHostFontScaler object we are given in getGlyph(). | 353 represented by the GrHostFontScaler object we are given in getGlyph(). |
377 | 354 |
378 We map a 32bit glyphID to a GrGlyph record, which in turn points to a | 355 We map a 32bit glyphID to a GrGlyph record, which in turn points to a |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 | 432 |
456 bool success = fAtlasGlyphCache->addToAtlas(this, &glyph->fID, target, expec
tedMaskFormat, | 433 bool success = fAtlasGlyphCache->addToAtlas(this, &glyph->fID, target, expec
tedMaskFormat, |
457 glyph->width(), glyph->height(), | 434 glyph->width(), glyph->height(), |
458 storage.get(), &glyph->fAtlasLoca
tion); | 435 storage.get(), &glyph->fAtlasLoca
tion); |
459 if (success) { | 436 if (success) { |
460 SkASSERT(GrDrawOpAtlas::kInvalidAtlasID != glyph->fID); | 437 SkASSERT(GrDrawOpAtlas::kInvalidAtlasID != glyph->fID); |
461 fAtlasedGlyphs++; | 438 fAtlasedGlyphs++; |
462 } | 439 } |
463 return success; | 440 return success; |
464 } | 441 } |
OLD | NEW |