Convert SkGlyph::toMask() to SkGlyph::mask()
Change-Id: I749fd152281df8942f488010c356ea0af10c5dea
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/207885
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/core/SkGlyph.cpp b/src/core/SkGlyph.cpp
index 0d226a2..075275f 100644
--- a/src/core/SkGlyph.cpp
+++ b/src/core/SkGlyph.cpp
@@ -11,31 +11,24 @@
#include "SkMakeUnique.h"
#include "SkScalerContext.h"
-void SkGlyph::toMask(SkMask* mask) const {
- SkASSERT(mask);
-
- mask->fImage = (uint8_t*)fImage;
- mask->fBounds.set(fLeft, fTop, fLeft + fWidth, fTop + fHeight);
- mask->fRowBytes = this->rowBytes();
- mask->fFormat = static_cast<SkMask::Format>(fMaskFormat);
-}
-
-SkMask SkGlyph::mask(SkPoint position) const {
- // findImage had to be called.
- SkASSERT(fImage != nullptr);
-
+SkMask SkGlyph::mask() const {
// getMetrics had to be called.
SkASSERT(fMaskFormat != MASK_FORMAT_UNKNOWN);
SkMask mask;
mask.fImage = (uint8_t*)fImage;
mask.fBounds.set(fLeft, fTop, fLeft + fWidth, fTop + fHeight);
- mask.fBounds.offset(SkScalarFloorToInt(position.x()), SkScalarFloorToInt(position.y()));
mask.fRowBytes = this->rowBytes();
mask.fFormat = static_cast<SkMask::Format>(fMaskFormat);
return mask;
}
+SkMask SkGlyph::mask(SkPoint position) const {
+ SkMask answer = this->mask();
+ answer.fBounds.offset(SkScalarFloorToInt(position.x()), SkScalarFloorToInt(position.y()));
+ return answer;
+}
+
void SkGlyph::zeroMetrics() {
fAdvanceX = 0;
fAdvanceY = 0;
diff --git a/src/core/SkGlyph.h b/src/core/SkGlyph.h
index bafeee9..c2606d9 100644
--- a/src/core/SkGlyph.h
+++ b/src/core/SkGlyph.h
@@ -150,7 +150,7 @@
// fImage, fPath, fID, fMaskFormat fields.
void zeroMetrics();
- void toMask(SkMask* mask) const;
+ SkMask mask() const;
SkMask mask(SkPoint position) const;
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index 28f4ca7..4ea2216 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -244,10 +244,10 @@
}
if (fMaskFilter) {
- SkMask src, dst;
+ SkMask src = glyph->mask(),
+ dst;
SkMatrix matrix;
- glyph->toMask(&src);
fRec.getMatrixFrom2x2(&matrix);
src.fImage = nullptr; // only want the bounds from the filter
@@ -521,9 +521,8 @@
generateImage(*glyph);
} else {
SkPath devPath;
- SkMask mask;
+ SkMask mask = glyph->mask();
- glyph->toMask(&mask);
if (!this->internalGetPath(glyph->getPackedID(), &devPath)) {
generateImage(*glyph);
} else {
@@ -534,13 +533,12 @@
}
if (fMaskFilter) {
- SkMask srcM, dstM;
- SkMatrix matrix;
-
// the src glyph image shouldn't be 3D
SkASSERT(SkMask::k3D_Format != glyph->fMaskFormat);
- glyph->toMask(&srcM);
+ SkMask srcM = glyph->mask(),
+ dstM;
+ SkMatrix matrix;
fRec.getMatrixFrom2x2(&matrix);
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index d1d416d..2f8369f 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -560,8 +560,7 @@
};
static ImageAndOffset to_image(SkGlyphID gid, SkStrike* cache) {
(void)cache->findImage(cache->getGlyphIDMetrics(gid));
- SkMask mask;
- cache->getGlyphIDMetrics(gid).toMask(&mask);
+ SkMask mask = cache->getGlyphIDMetrics(gid).mask();
if (!mask.fImage) {
return {nullptr, {0, 0}};
}
diff --git a/src/ports/SkFontHost_FreeType_common.cpp b/src/ports/SkFontHost_FreeType_common.cpp
index cc86672..83ae594 100644
--- a/src/ports/SkFontHost_FreeType_common.cpp
+++ b/src/ports/SkFontHost_FreeType_common.cpp
@@ -464,8 +464,7 @@
return;
}
- SkMask mask;
- glyph.toMask(&mask);
+ SkMask mask = glyph.mask();
#ifdef SK_SHOW_TEXT_BLIT_COVERAGE
memset(mask.fImage, 0x80, mask.fBounds.height() * mask.fRowBytes);
#endif
@@ -579,8 +578,7 @@
// If no scaling needed, directly copy glyph bitmap.
if (bitmapTransform.isIdentity()) {
- SkMask dstMask;
- glyph.toMask(&dstMask);
+ SkMask dstMask = glyph.mask();
copyFTBitmap(face->glyph->bitmap, dstMask);
break;
}
@@ -648,8 +646,7 @@
// If the destination is BW or LCD, convert from A8.
if (SkMask::kBW_Format == maskFormat) {
// Copy the A8 dstBitmap into the A1 glyph.fImage.
- SkMask dstMask;
- glyph.toMask(&dstMask);
+ SkMask dstMask = glyph.mask();
packA8ToA1(dstMask, dstBitmap.getAddr8(0, 0), dstBitmap.rowBytes());
} else if (SkMask::kLCD16_Format == maskFormat) {
// Copy the A8 dstBitmap into the LCD16 glyph.fImage.