diff options
author | 2017-01-09 18:39:43 -0800 | |
---|---|---|
committer | 2017-01-09 18:39:43 -0800 | |
commit | 8cbb4246e58c97e2ac51087d2708795b3b59f5e9 (patch) | |
tree | 809c537951a9ec8c3b3c69ec6d0a3b2d924ebd67 /src/gpu/text/GrAtlasGlyphCache.cpp | |
parent | e57194f74d125c7b0ba767ae5357b97d102792ef (diff) |
Generate Signed Distance Field directly from vector path
Add SkGenerateDistanceFieldFromPath API to generate signed distance field directly from SkPath.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1643143002
Committed: https://skia.googlesource.com/skia/+/4de97a64e8829323a7070b623411d9f9ddb0cd0f
Committed: https://skia.googlesource.com/skia/+/e8f0a7b986f1e5583c9bc162efcdd92fd6430549
Committed: https://skia.googlesource.com/skia/+/67c7c81a82b6351e9fbbf235084d7120162d9268
Review-Url: https://codereview.chromium.org/1643143002
Committed: https://skia.googlesource.com/skia/+/64b70b096ac20833d9737758a4bd5f2a51078bc4
Review-Url: https://codereview.chromium.org/1643143002
Committed: https://skia.googlesource.com/skia/+/6d2f73c364d0d823f14d1ddebc88e0bcbc8f0634
Review-Url: https://codereview.chromium.org/1643143002
Diffstat (limited to 'src/gpu/text/GrAtlasGlyphCache.cpp')
-rw-r--r-- | src/gpu/text/GrAtlasGlyphCache.cpp | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/src/gpu/text/GrAtlasGlyphCache.cpp b/src/gpu/text/GrAtlasGlyphCache.cpp index 803dbb48e1..5d85f4919d 100644 --- a/src/gpu/text/GrAtlasGlyphCache.cpp +++ b/src/gpu/text/GrAtlasGlyphCache.cpp @@ -14,6 +14,7 @@ #include "SkString.h" #include "SkDistanceFieldGen.h" +#include "GrDistanceFieldGenFromVector.h" bool GrAtlasGlyphCache::initAtlas(GrMaskFormat format) { int index = MaskFormatToAtlasIndex(format); @@ -320,29 +321,57 @@ static bool get_packed_glyph_df_image(SkGlyphCache* cache, const SkGlyph& glyph, int width, int height, void* dst) { SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); - const void* image = cache->findImage(glyph); - if (nullptr == image) { + +#ifndef SK_USE_LEGACY_DISTANCE_FIELDS + const SkPath* path = cache->findPath(glyph); + if (nullptr == path) { return false; } + + SkDEBUGCODE(SkRect glyphBounds = SkRect::MakeXYWH(glyph.fLeft, + glyph.fTop, + glyph.fWidth, + glyph.fHeight)); + SkASSERT(glyphBounds.contains(path->getBounds())); + // now generate the distance field SkASSERT(dst); - SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); - if (SkMask::kA8_Format == maskFormat) { - // make the distance field from the image - SkGenerateDistanceFieldFromA8Image((unsigned char*)dst, - (unsigned char*)image, - glyph.fWidth, glyph.fHeight, - glyph.rowBytes()); - } else if (SkMask::kBW_Format == maskFormat) { - // make the distance field from the image - SkGenerateDistanceFieldFromBWImage((unsigned char*)dst, - (unsigned char*)image, - glyph.fWidth, glyph.fHeight, - glyph.rowBytes()); - } else { - return false; - } + SkMatrix drawMatrix; + drawMatrix.setTranslate((SkScalar)-glyph.fLeft, (SkScalar)-glyph.fTop); + // Generate signed distance field directly from SkPath + bool succeed = GrGenerateDistanceFieldFromPath((unsigned char*)dst, + *path, drawMatrix, + width, height, width * sizeof(unsigned char)); + + if (!succeed) { +#endif + const void* image = cache->findImage(glyph); + if (nullptr == image) { + return false; + } + + // now generate the distance field + SkASSERT(dst); + SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); + if (SkMask::kA8_Format == maskFormat) { + // make the distance field from the image + SkGenerateDistanceFieldFromA8Image((unsigned char*)dst, + (unsigned char*)image, + glyph.fWidth, glyph.fHeight, + glyph.rowBytes()); + } else if (SkMask::kBW_Format == maskFormat) { + // make the distance field from the image + SkGenerateDistanceFieldFromBWImage((unsigned char*)dst, + (unsigned char*)image, + glyph.fWidth, glyph.fHeight, + glyph.rowBytes()); + } else { + return false; + } +#ifndef SK_USE_LEGACY_DISTANCE_FIELDS + } +#endif return true; } |