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