use SkMask::Format in SkGlyph and SkScalerContextRec

Change-Id: I673ddffa0c0e154476ef6d0e8213263327dbe014
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334429
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2020-11-11 10:37:35 -05:00 committed by Skia Commit-Bot
parent a29ed26cfc
commit 0fc077e065
7 changed files with 22 additions and 19 deletions

View File

@ -19,7 +19,7 @@ SkMask SkGlyph::mask() const {
mask.fImage = (uint8_t*)fImage;
mask.fBounds.setXYWH(fLeft, fTop, fWidth, fHeight);
mask.fRowBytes = this->rowBytes();
mask.fFormat = static_cast<SkMask::Format>(fMaskFormat);
mask.fFormat = fMaskFormat;
return mask;
}
@ -124,7 +124,7 @@ size_t SkGlyph::setMetricsAndImage(SkArenaAlloc* alloc, const SkGlyph& from) {
}
size_t SkGlyph::rowBytes() const {
return format_rowbytes(fWidth, (SkMask::Format)fMaskFormat);
return format_rowbytes(fWidth, fMaskFormat);
}
size_t SkGlyph::rowBytesUsingFormat(SkMask::Format format) const {

View File

@ -15,6 +15,7 @@
#include "include/private/SkTo.h"
#include "include/private/SkVx.h"
#include "src/core/SkMask.h"
#include "src/core/SkMathPriv.h"
class SkArenaAlloc;
class SkScalerContext;
@ -229,7 +230,7 @@ struct SkGlyphPrototype;
class SkGlyph {
public:
// SkGlyph() is used for testing.
constexpr SkGlyph() : fID{SkPackedGlyphID()} { }
constexpr SkGlyph() : SkGlyph{SkPackedGlyphID()} { }
constexpr explicit SkGlyph(SkPackedGlyphID id) : fID{id} { }
SkVector advanceVector() const { return SkVector{fAdvanceX, fAdvanceY}; }
@ -300,7 +301,7 @@ public:
// Format
bool isColor() const { return fMaskFormat == SkMask::kARGB32_Format; }
SkMask::Format maskFormat() const { return static_cast<SkMask::Format>(fMaskFormat); }
SkMask::Format maskFormat() const { return fMaskFormat; }
size_t formatAlignment() const;
// Bounds
@ -396,7 +397,7 @@ private:
float fAdvanceX = 0,
fAdvanceY = 0;
uint8_t fMaskFormat = 0;
SkMask::Format fMaskFormat{SkMask::kBW_Format};
// Used by the DirectWrite scaler to track state.
int8_t fForceBW = 0;

View File

@ -22,7 +22,7 @@
struct SkMask {
SkMask() : fImage(nullptr) {}
enum Format {
enum Format : uint8_t {
kBW_Format, //!< 1bit per pixel mask (e.g. monochrome)
kA8_Format, //!< 8bits per pixel mask (e.g. antialiasing)
k3D_Format, //!< 3 8bit per pixl planes: alpha, mul, add

View File

@ -952,8 +952,10 @@ bool SkStrikeClientImpl::ReadGlyph(SkTLazy<SkGlyph>& glyph, Deserializer* deseri
if (!deserializer->read<uint16_t>(&glyph->fHeight)) return false;
if (!deserializer->read<int16_t>(&glyph->fTop)) return false;
if (!deserializer->read<int16_t>(&glyph->fLeft)) return false;
if (!deserializer->read<uint8_t>(&glyph->fMaskFormat)) return false;
if (!SkMask::IsValidFormat(glyph->fMaskFormat)) return false;
uint8_t maskFormat;
if (!deserializer->read<uint8_t>(&maskFormat)) return false;
if (!SkMask::IsValidFormat(maskFormat)) return false;
glyph->fMaskFormat = static_cast<SkMask::Format>(maskFormat);
return true;
}

View File

@ -178,7 +178,7 @@ bool SkScalerContext::GetGammaLUTData(SkScalar contrast, SkScalar paintGamma, Sk
}
SkGlyph SkScalerContext::makeGlyph(SkPackedGlyphID packedID) {
return internalMakeGlyph(packedID, (SkMask::Format) fRec.fMaskFormat);
return internalMakeGlyph(packedID, fRec.fMaskFormat);
}
SkGlyph SkScalerContext::internalMakeGlyph(SkPackedGlyphID packedID, SkMask::Format format) {
@ -232,7 +232,7 @@ SkGlyph SkScalerContext::internalMakeGlyph(SkPackedGlyphID packedID, SkMask::For
glyph.fHeight = 0;
glyph.fTop = 0;
glyph.fLeft = 0;
glyph.fMaskFormat = 0;
glyph.fMaskFormat = SkMask::kBW_Format;
return glyph;
}
@ -537,8 +537,7 @@ void SkScalerContext::getImage(const SkGlyph& origGlyph) {
// need the original bounds, sans our maskfilter
sk_sp<SkMaskFilter> mf = std::move(fMaskFilter);
tmpGlyph = this->internalMakeGlyph(origGlyph.getPackedID(),
(SkMask::Format) fRec.fMaskFormat);
tmpGlyph = this->internalMakeGlyph(origGlyph.getPackedID(), fRec.fMaskFormat);
fMaskFilter = std::move(mf);
// we need the prefilter bounds to be <= filter bounds
@ -987,7 +986,7 @@ void SkScalerContext::MakeRecAndEffects(const SkFont& font, const SkPaint& paint
rec->fStrokeCap = 0;
}
rec->fMaskFormat = SkToU8(compute_mask_format(font));
rec->fMaskFormat = compute_mask_format(font);
if (SkMask::kLCD16_Format == rec->fMaskFormat) {
if (too_big_for_lcd(*rec, checkPost2x2)) {

View File

@ -112,7 +112,8 @@ public:
setContrast(0);
}
uint8_t fMaskFormat;
SkMask::Format fMaskFormat;
private:
uint8_t fStrokeJoin : 4;
uint8_t fStrokeCap : 4;
@ -193,7 +194,7 @@ public:
inline void setHinting(SkFontHinting);
SkMask::Format getFormat() const {
return static_cast<SkMask::Format>(fMaskFormat);
return fMaskFormat;
}
SkColor getLuminanceColor() const {
@ -269,7 +270,7 @@ public:
SkTypeface* getTypeface() const { return fTypeface.get(); }
SkMask::Format getMaskFormat() const {
return (SkMask::Format)fRec.fMaskFormat;
return fRec.fMaskFormat;
}
bool isSubpixel() const {

View File

@ -546,7 +546,7 @@ void SkScalerContext_FreeType_Base::generateGlyphImage(
target.rows = glyph.fHeight;
target.pitch = glyph.rowBytes();
target.buffer = reinterpret_cast<uint8_t*>(glyph.fImage);
target.pixel_mode = compute_pixel_mode( (SkMask::Format)glyph.fMaskFormat);
target.pixel_mode = compute_pixel_mode(glyph.fMaskFormat);
target.num_grays = 256;
FT_Outline_Get_Bitmap(face->glyph->library, outline, &target);