simplify setMetricsAndImage API

Just return the amount allocated during the merge.
Add TODO to simplify when I'm sure there are no
collisions during the merge.

Change-Id: Ieb568c4096fc547c54303689b232c68d78f3f36b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317382
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2020-09-16 14:17:06 -04:00 committed by Skia Commit-Bot
parent 2780656ef4
commit ef3aadbd27
3 changed files with 16 additions and 13 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -113,7 +113,6 @@ std::tuple<SkGlyph*, size_t> 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<SkGlyph*, size_t> 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<SkSpan<const SkGlyph*>, size_t> SkScalerCache::metrics(