Skip to content

Commit

Permalink
Convert SkGlyph::toMask() to SkGlyph::mask()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
herbderby authored and Skia Commit-Bot committed Apr 13, 2019
1 parent 0c60708 commit 990bfc7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 31 deletions.
21 changes: 7 additions & 14 deletions src/core/SkGlyph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/SkGlyph.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class SkGlyph {
// fImage, fPath, fID, fMaskFormat fields.
void zeroMetrics();

void toMask(SkMask* mask) const;
SkMask mask() const;

SkMask mask(SkPoint position) const;

Expand Down
14 changes: 6 additions & 8 deletions src/core/SkScalerContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ void SkScalerContext::getMetrics(SkGlyph* glyph) {
}

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
Expand Down Expand Up @@ -521,9 +521,8 @@ void SkScalerContext::getImage(const SkGlyph& origGlyph) {
generateImage(*glyph);
} else {
SkPath devPath;
SkMask mask;
SkMask mask = glyph->mask();

glyph->toMask(&mask);
if (!this->internalGetPath(glyph->getPackedID(), &devPath)) {
generateImage(*glyph);
} else {
Expand All @@ -534,13 +533,12 @@ void SkScalerContext::getImage(const SkGlyph& origGlyph) {
}

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);

Expand Down
3 changes: 1 addition & 2 deletions src/pdf/SkPDFFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,7 @@ struct ImageAndOffset {
};
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}};
}
Expand Down
9 changes: 3 additions & 6 deletions src/ports/SkFontHost_FreeType_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,7 @@ void SkScalerContext_FreeType_Base::generateGlyphImage(
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
Expand Down Expand Up @@ -579,8 +578,7 @@ void SkScalerContext_FreeType_Base::generateGlyphImage(

// 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;
}
Expand Down Expand Up @@ -648,8 +646,7 @@ void SkScalerContext_FreeType_Base::generateGlyphImage(
// 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.
Expand Down

0 comments on commit 990bfc7

Please sign in to comment.