diff --git a/src/core/SkGlyph.cpp b/src/core/SkGlyph.cpp index 6336e3df86..1f911ec492 100644 --- a/src/core/SkGlyph.cpp +++ b/src/core/SkGlyph.cpp @@ -102,7 +102,12 @@ bool SkGlyph::setImage(SkArenaAlloc* alloc, const void* image) { return false; } -bool SkGlyph::setMetricsAndImage(SkArenaAlloc* alloc, const SkGlyph& from) { +size_t SkGlyph::setMetricsAndImage(SkArenaAlloc* alloc, const SkGlyph& from) { + // Since the code no longer tries to find replacement glyphs, the image should always be + // nullptr. + SkASSERT(fImage == nullptr); + + // TODO(herb): remove "if" when we are sure there are no colliding glyphs. if (fImage == nullptr) { fAdvanceX = from.fAdvanceX; fAdvanceY = from.fAdvanceY; @@ -114,9 +119,11 @@ bool SkGlyph::setMetricsAndImage(SkArenaAlloc* alloc, const SkGlyph& from) { fMaskFormat = from.fMaskFormat; // From glyph may not have an image because the glyph is too large. - return from.fImage != nullptr && this->setImage(alloc, from.image()); + if (from.fImage != nullptr && this->setImage(alloc, from.image())) { + return this->imageSize(); + } } - return false; + return 0; } size_t SkGlyph::rowBytes() const { diff --git a/src/core/SkGlyph.h b/src/core/SkGlyph.h index eb22413d46..ac28382db2 100644 --- a/src/core/SkGlyph.h +++ b/src/core/SkGlyph.h @@ -211,11 +211,10 @@ public: bool setImage(SkArenaAlloc* alloc, SkScalerContext* scalerContext); bool setImage(SkArenaAlloc* alloc, const void* image); - // Merge the from glyph into this glyph using alloc to allocate image data. Return true if - // image data was allocated. If the image for this glyph has not been initialized, then copy - // the width, height, top, left, format, and image into this glyph making a copy of the image - // using the alloc. - bool setMetricsAndImage(SkArenaAlloc* alloc, const SkGlyph& from); + // Merge the from glyph into this glyph using alloc to allocate image data. Return the number + // of bytes allocated. Copy the width, height, top, left, format, and image into this glyph + // making a copy of the image using the alloc. + size_t setMetricsAndImage(SkArenaAlloc* alloc, const SkGlyph& from); // Returns true if the image has been set. bool setImageHasBeenCalled() const { diff --git a/src/core/SkScalerCache.cpp b/src/core/SkScalerCache.cpp index 31628d7acc..2844e31f1c 100644 --- a/src/core/SkScalerCache.cpp +++ b/src/core/SkScalerCache.cpp @@ -113,7 +113,6 @@ std::tuple SkScalerCache::mergeGlyphAndImage( SkPackedGlyphID toID, const SkGlyph& from) { SkAutoMutexExclusive lock{fMu}; size_t delta = 0; - size_t imageDelta = 0; SkGlyphIndex* denseID = fIndexForPackedGlyphID.find(toID); SkGlyph* glyph; if (denseID != nullptr) { @@ -121,10 +120,8 @@ std::tuple SkScalerCache::mergeGlyphAndImage( } else { std::tie(glyph, delta) = this->makeGlyph(toID); } - if (glyph->setMetricsAndImage(&fAlloc, from)) { - imageDelta= glyph->imageSize(); - } - return {glyph, delta + imageDelta}; + delta += glyph->setMetricsAndImage(&fAlloc, from); + return {glyph, delta}; } std::tuple, size_t> SkScalerCache::metrics(