Make a ctor for SkGlyph
Change-Id: I21a5ed81d3e161ddf8a838ea9ac0414265b00ae6 Reviewed-on: https://skia-review.googlesource.com/c/182701 Auto-Submit: Herb Derby <herb@google.com> Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
parent
1400f599f5
commit
f6fca2668d
@ -11,14 +11,6 @@
|
||||
#include "SkMakeUnique.h"
|
||||
#include "SkScalerContext.h"
|
||||
|
||||
void SkGlyph::initWithGlyphID(SkPackedGlyphID glyph_id) {
|
||||
fID = glyph_id;
|
||||
fImage = nullptr;
|
||||
fPathData = nullptr;
|
||||
fMaskFormat = MASK_FORMAT_UNKNOWN;
|
||||
fForceBW = 0;
|
||||
}
|
||||
|
||||
void SkGlyph::toMask(SkMask* mask) const {
|
||||
SkASSERT(mask);
|
||||
|
||||
|
@ -137,7 +137,7 @@ class SkGlyph {
|
||||
struct PathData;
|
||||
|
||||
public:
|
||||
constexpr SkGlyph() = default;
|
||||
constexpr explicit SkGlyph(SkPackedGlyphID id = dotUndef) : fID{id} {}
|
||||
static constexpr SkFixed kSubpixelRound = SK_FixedHalf >> SkPackedID::kSubBits;
|
||||
|
||||
bool isEmpty() const { return fWidth == 0 || fHeight == 0; }
|
||||
@ -148,7 +148,10 @@ public:
|
||||
SkFixed getSubXFixed() const { return fID.getSubXFixed(); }
|
||||
SkFixed getSubYFixed() const { return fID.getSubYFixed(); }
|
||||
|
||||
void initWithGlyphID(SkPackedGlyphID glyph_id);
|
||||
void reset(SkPackedGlyphID glyphID) {
|
||||
this->SkGlyph::~SkGlyph();
|
||||
new (this) SkGlyph{glyphID};
|
||||
}
|
||||
size_t formatAlignment() const;
|
||||
size_t allocImage(SkArenaAlloc* alloc);
|
||||
size_t rowBytes() const;
|
||||
@ -196,9 +199,13 @@ public:
|
||||
// This is a combination of SkMask::Format and SkGlyph state. The SkGlyph can be in one of two
|
||||
// states, just the advances have been calculated, and all the metrics are available. The
|
||||
// illegal mask format is used to signal that only the advances are available.
|
||||
uint8_t fMaskFormat = 0;
|
||||
uint8_t fMaskFormat = MASK_FORMAT_UNKNOWN;
|
||||
|
||||
private:
|
||||
|
||||
// The undefined glyph, which seems to be perfectly well defined.
|
||||
static constexpr SkGlyphID dotUndef = 0;
|
||||
|
||||
// Support horizontal and vertical skipping strike-through / underlines.
|
||||
// The caller walks the linked list looking for a match. For a horizontal underline,
|
||||
// the fBounds contains the top and bottom of the underline. The fInterval pair contains the
|
||||
|
@ -155,8 +155,7 @@ SkGlyph* SkGlyphCache::lookupByPackedGlyphID(SkPackedGlyphID packedGlyphID, Metr
|
||||
SkGlyph* SkGlyphCache::allocateNewGlyph(SkPackedGlyphID packedGlyphID, MetricsType mtype) {
|
||||
fMemoryUsed += sizeof(SkGlyph);
|
||||
|
||||
SkGlyph* glyphPtr = fAlloc.make<SkGlyph>();
|
||||
glyphPtr->initWithGlyphID(packedGlyphID);
|
||||
SkGlyph* glyphPtr = fAlloc.make<SkGlyph>(packedGlyphID);
|
||||
fGlyphMap.set(glyphPtr);
|
||||
|
||||
if (kNothing_MetricsType == mtype) {
|
||||
|
@ -471,8 +471,7 @@ void SkStrikeServer::SkGlyphCacheState::writePendingGlyphs(Serializer* serialize
|
||||
// Write glyphs images.
|
||||
serializer->emplace<uint64_t>(fPendingGlyphImages.size());
|
||||
for (const auto& glyphID : fPendingGlyphImages) {
|
||||
SkGlyph glyph;
|
||||
glyph.initWithGlyphID(glyphID);
|
||||
SkGlyph glyph{glyphID};
|
||||
fContext->getMetrics(&glyph);
|
||||
writeGlyph(&glyph, serializer);
|
||||
|
||||
@ -489,8 +488,7 @@ void SkStrikeServer::SkGlyphCacheState::writePendingGlyphs(Serializer* serialize
|
||||
// Write glyphs paths.
|
||||
serializer->emplace<uint64_t>(fPendingGlyphPaths.size());
|
||||
for (const auto& glyphID : fPendingGlyphPaths) {
|
||||
SkGlyph glyph;
|
||||
glyph.initWithGlyphID(glyphID);
|
||||
SkGlyph glyph{glyphID};
|
||||
fContext->getMetrics(&glyph);
|
||||
writeGlyph(&glyph, serializer);
|
||||
writeGlyphPath(glyphID, serializer);
|
||||
@ -503,8 +501,7 @@ const SkGlyph& SkStrikeServer::SkGlyphCacheState::findGlyph(SkPackedGlyphID glyp
|
||||
auto* glyph = fGlyphMap.find(glyphID);
|
||||
if (glyph == nullptr) {
|
||||
this->ensureScalerContext();
|
||||
glyph = fGlyphMap.set(glyphID, SkGlyph());
|
||||
glyph->initWithGlyphID(glyphID);
|
||||
glyph = fGlyphMap.set(glyphID, SkGlyph{glyphID});
|
||||
fContext->getMetrics(glyph);
|
||||
}
|
||||
|
||||
@ -597,7 +594,7 @@ SkStrikeClient::~SkStrikeClient() = default;
|
||||
static bool readGlyph(SkGlyph* glyph, Deserializer* deserializer) {
|
||||
SkPackedGlyphID glyphID;
|
||||
if (!deserializer->read<SkPackedGlyphID>(&glyphID)) return false;
|
||||
glyph->initWithGlyphID(glyphID);
|
||||
glyph->reset(glyphID);
|
||||
if (!deserializer->read<float>(&glyph->fAdvanceX)) return false;
|
||||
if (!deserializer->read<float>(&glyph->fAdvanceY)) return false;
|
||||
if (!deserializer->read<uint16_t>(&glyph->fWidth)) return false;
|
||||
|
@ -459,14 +459,14 @@ static void generateMask(const SkMask& mask, const SkPath& path,
|
||||
|
||||
void SkScalerContext::getImage(const SkGlyph& origGlyph) {
|
||||
const SkGlyph* glyph = &origGlyph;
|
||||
SkGlyph tmpGlyph;
|
||||
SkGlyph tmpGlyph;
|
||||
|
||||
// in case we need to call generateImage on a mask-format that is different
|
||||
// (i.e. larger) than what our caller allocated by looking at origGlyph.
|
||||
SkAutoMalloc tmpGlyphImageStorage;
|
||||
|
||||
if (fMaskFilter) { // restore the prefilter bounds
|
||||
tmpGlyph.initWithGlyphID(origGlyph.getPackedID());
|
||||
tmpGlyph.reset(origGlyph.getPackedID());
|
||||
|
||||
// need the original bounds, sans our maskfilter
|
||||
sk_sp<SkMaskFilter> mf = std::move(fMaskFilter);
|
||||
|
@ -773,8 +773,7 @@ DEF_TEST(SkRemoteGlyphCache_ReWriteGlyph, reporter) {
|
||||
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
|
||||
|
||||
auto context = serverTf->createScalerContext(effects, desc, false);
|
||||
SkGlyph glyph;
|
||||
glyph.initWithGlyphID(lostGlyphID);
|
||||
SkGlyph glyph{lostGlyphID};
|
||||
context->getMetrics(&glyph);
|
||||
realMask = glyph.fMaskFormat;
|
||||
REPORTER_ASSERT(reporter, realMask != MASK_FORMAT_UNKNOWN);
|
||||
|
Loading…
Reference in New Issue
Block a user