diff options
author | Jim Van Verth <jvanverth@google.com> | 2018-05-03 10:40:30 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-05-04 13:56:02 +0000 |
commit | d401da64f0eb94239442018395ab150bc9535746 (patch) | |
tree | 652857da6ce723e4937c375e317a98a852486c78 /src/gpu/text/GrGlyphCache.cpp | |
parent | 9eeede2e710f0e5fab0f65e06e8d40a40cdaebcd (diff) |
Use MaskFilter to create SDFs for text.
Easy way to store SDFs in the glyph cache.
Change-Id: Ia67e5c8619862bdee6aa3b293e30507d029e3bf1
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/123748
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src/gpu/text/GrGlyphCache.cpp')
-rw-r--r-- | src/gpu/text/GrGlyphCache.cpp | 109 |
1 files changed, 13 insertions, 96 deletions
diff --git a/src/gpu/text/GrGlyphCache.cpp b/src/gpu/text/GrGlyphCache.cpp index 8f5e2bad77..b564c93c02 100644 --- a/src/gpu/text/GrGlyphCache.cpp +++ b/src/gpu/text/GrGlyphCache.cpp @@ -62,7 +62,8 @@ static inline GrMaskFormat get_packed_glyph_mask_format(const SkGlyph& glyph) { SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat); switch (format) { case SkMask::kBW_Format: - // fall through to kA8 -- we store BW glyphs in our 8-bit cache + case SkMask::kSDF_Format: + // fall through to kA8 -- we store BW and SDF glyphs in our 8-bit cache case SkMask::kA8_Format: return kA8_GrMaskFormat; case SkMask::k3D_Format: @@ -89,19 +90,6 @@ static inline bool get_packed_glyph_bounds(SkGlyphCache* cache, const SkGlyph& g return true; } -static inline bool get_packed_glyph_df_bounds(SkGlyphCache* cache, const SkGlyph& glyph, - SkIRect* bounds) { -#if 1 - // crbug:510931 - // Retrieving the image from the cache can actually change the mask format. - cache->findImage(glyph); -#endif - bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); - bounds->outset(SK_DistanceFieldPad, SK_DistanceFieldPad); - - return true; -} - // expands each bit in a bitmask to 0 or ~0 of type INT_TYPE. Used to expand a BW glyph mask to // A8, RGB565, or RGBA8888. template <typename INT_TYPE> @@ -182,64 +170,6 @@ static bool get_packed_glyph_image(SkGlyphCache* cache, const SkGlyph& glyph, in return true; } -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); - -#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); - 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; -} - /////////////////////////////////////////////////////////////////////////////// /* @@ -267,14 +197,8 @@ GrTextStrike::~GrTextStrike() { GrGlyph* GrTextStrike::generateGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed, SkGlyphCache* cache) { SkIRect bounds; - if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(packed)) { - if (!get_packed_glyph_df_bounds(cache, skGlyph, &bounds)) { - return nullptr; - } - } else { - if (!get_packed_glyph_bounds(cache, skGlyph, &bounds)) { - return nullptr; - } + if (!get_packed_glyph_bounds(cache, skGlyph, &bounds)) { + return nullptr; } GrMaskFormat format = get_packed_glyph_mask_format(skGlyph); @@ -327,22 +251,15 @@ GrDrawOpAtlas::ErrorCode GrTextStrike::addGlyphToAtlas( SkAutoSMalloc<1024> storage(size); const SkGlyph& skGlyph = GrToSkGlyph(cache, glyph->fPackedID); - if (isSDFGlyph) { - if (!get_packed_glyph_df_image(cache, skGlyph, width, height, - storage.get())) { - return GrDrawOpAtlas::ErrorCode::kError; - } - } else { - void* dataPtr = storage.get(); - if (addPad) { - sk_bzero(dataPtr, size); - dataPtr = (char*)(dataPtr) + rowBytes + bytesPerPixel; - } - if (!get_packed_glyph_image(cache, skGlyph, glyph->width(), glyph->height(), - rowBytes, expectedMaskFormat, - dataPtr)) { - return GrDrawOpAtlas::ErrorCode::kError; - } + void* dataPtr = storage.get(); + if (addPad) { + sk_bzero(dataPtr, size); + dataPtr = (char*)(dataPtr) + rowBytes + bytesPerPixel; + } + if (!get_packed_glyph_image(cache, skGlyph, glyph->width(), glyph->height(), + rowBytes, expectedMaskFormat, + dataPtr)) { + return GrDrawOpAtlas::ErrorCode::kError; } GrDrawOpAtlas::ErrorCode result = fullAtlasManager->addToAtlas( |