Remove PackedID from the strike call chain

By removing the PackedID from the call chain, all the information
needed to lookup glyphs is gathered from the SkGlyph. I added some
code to allow this corrispondence between the SkGlyph and the PackedID.
But, in the next CL all that code will be removed as PackeID becomes
SkPackedGlyphID.

Remove unneeded inlines
Remove unused maskFormat parameter to getGlyph

Change-Id: Id6d876d7ad3f1b4303f8b9ecfc38f499fbedcf73
Reviewed-on: https://skia-review.googlesource.com/c/179640
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
Herb Derby 2018-12-20 14:03:47 -05:00 committed by Skia Commit-Bot
parent 2a4c4dfb81
commit 4c35be021c
5 changed files with 30 additions and 25 deletions

View File

@ -633,11 +633,7 @@ void GrTextBlob::Run::appendGlyph(GrTextBlob* blob,
const SkGlyph& skGlyph, GrGlyph::MaskStyle maskStyle,
SkPoint origin, SkScalar textRatio, bool needsTransform) {
GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(),
skGlyph.getSubXFixed(),
skGlyph.getSubYFixed(),
maskStyle);
GrGlyph* glyph = strike->getGlyph(skGlyph, id);
GrGlyph* glyph = strike->getGlyph(skGlyph);
if (!glyph) {
return;
}
@ -667,7 +663,6 @@ void GrTextBlob::Run::appendGlyph(GrTextBlob* blob,
}
}
void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache,
const GrShaderCaps& shaderCaps,
const GrTextContext::Options& options,

View File

@ -37,8 +37,7 @@ struct GrGlyph {
SkTo<uint16_t>(rect.height()));
}
GrGlyph(
GrGlyph::PackedID packed, const SkIRect& bounds, GrMaskFormat format, MaskStyle style)
GrGlyph(GrGlyph::PackedID packed, const SkIRect& bounds, GrMaskFormat format, MaskStyle style)
: fPackedID{packed}
, fMaskFormat{format}
, fMaskStyle{style}
@ -51,7 +50,6 @@ struct GrGlyph {
SkIPoint16 fAtlasLocation{0, 0};
GrDrawOpAtlas::AtlasID fID{GrDrawOpAtlas::kInvalidAtlasID};
int width() const { return fBounds.width(); }
int height() const { return fBounds.height(); }
bool isEmpty() const { return fBounds.isEmpty(); }
@ -61,35 +59,47 @@ struct GrGlyph {
///////////////////////////////////////////////////////////////////////////
static inline unsigned ExtractSubPixelBitsFromFixed(SkFixed pos) {
static unsigned ExtractSubPixelBitsFromFixed(SkFixed pos) {
// two most significant fraction bits from fixed-point
return (pos >> 14) & 3;
}
static inline PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y, MaskStyle ms) {
static PackedID FromSkGlyph(const SkGlyph& skGlyph) {
GrGlyph::MaskStyle maskStyle = (SkMask::Format)skGlyph.fMaskFormat == SkMask::kSDF_Format
? GrGlyph::MaskStyle::kDistance_MaskStyle
: GrGlyph::MaskStyle::kCoverage_MaskStyle;
SkPackedGlyphID skPackedID = skGlyph.getPackedID();
GrGlyph::PackedID packedID = GrGlyph::Pack(skPackedID.code(),
skPackedID.getSubXFixed(),
skPackedID.getSubYFixed(),
maskStyle);
return packedID;
}
static PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y, MaskStyle ms) {
x = ExtractSubPixelBitsFromFixed(x);
y = ExtractSubPixelBitsFromFixed(y);
int dfFlag = (ms == kDistance_MaskStyle) ? 0x1 : 0x0;
return (dfFlag << 20) | (x << 18) | (y << 16) | glyphID;
}
static inline SkFixed UnpackFixedX(PackedID packed) {
static SkFixed UnpackFixedX(PackedID packed) {
return ((packed >> 18) & 3) << 14;
}
static inline SkFixed UnpackFixedY(PackedID packed) {
static SkFixed UnpackFixedY(PackedID packed) {
return ((packed >> 16) & 3) << 14;
}
static inline uint16_t UnpackID(PackedID packed) {
static uint16_t UnpackID(PackedID packed) {
return (uint16_t)packed;
}
static inline const GrGlyph::PackedID& GetKey(const GrGlyph& glyph) {
static const GrGlyph::PackedID& GetKey(const GrGlyph& glyph) {
return glyph.fPackedID;
}
static inline uint32_t Hash(GrGlyph::PackedID key) {
static uint32_t Hash(GrGlyph::PackedID key) {
return SkChecksum::Mix(key);
}
};

View File

@ -192,7 +192,7 @@ static bool get_packed_glyph_image(SkGlyphCache* cache, const SkGlyph& glyph, in
GrTextStrike::GrTextStrike(const SkDescriptor& key)
: fFontScalerKey(key) {}
GrGlyph* GrTextStrike::generateGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed) {
GrGlyph* GrTextStrike::generateGlyph(const SkGlyph& skGlyph) {
SkIRect bounds;
bounds.setXYWH(skGlyph.fLeft, skGlyph.fTop, skGlyph.fWidth, skGlyph.fHeight);
@ -202,7 +202,8 @@ GrGlyph* GrTextStrike::generateGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID p
GrGlyph::MaskStyle maskStyle = (SkMask::Format)skGlyph.fMaskFormat == SkMask::kSDF_Format
? GrGlyph::MaskStyle::kDistance_MaskStyle
: GrGlyph::MaskStyle::kCoverage_MaskStyle;
GrGlyph* glyph = fAlloc.make<GrGlyph>(packed, bounds, format, maskStyle);
GrGlyph* glyph = fAlloc.make<GrGlyph>(
GrGlyph::FromSkGlyph(skGlyph), bounds, format, maskStyle);
fCache.add(glyph);
return glyph;
}

View File

@ -30,10 +30,11 @@ class GrTextStrike : public SkNVRefCnt<GrTextStrike> {
public:
GrTextStrike(const SkDescriptor& fontScalerKey);
GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed) {
GrGlyph* getGlyph(const SkGlyph& skGlyph) {
GrGlyph::PackedID packed = GrGlyph::FromSkGlyph(skGlyph);
GrGlyph* glyph = fCache.find(packed);
if (!glyph) {
glyph = this->generateGlyph(skGlyph, packed);
glyph = this->generateGlyph(skGlyph);
}
return glyph;
}
@ -43,7 +44,6 @@ public:
// draw a clear square.
// skbug:4143 crbug:510931
GrGlyph* getGlyph(GrGlyph::PackedID packed,
GrMaskFormat expectedMaskFormat,
SkGlyphCache* cache) {
GrGlyph* glyph = fCache.find(packed);
if (!glyph) {
@ -51,7 +51,7 @@ public:
// potentially little benefit(ie, if the glyph is not in our font cache, then its not
// in the atlas and we're going to be doing a texture upload anyways).
const SkGlyph& skGlyph = GrToSkGlyph(cache, packed);
glyph = this->generateGlyph(skGlyph, packed);
glyph = this->generateGlyph(skGlyph);
}
return glyph;
}
@ -95,7 +95,7 @@ private:
GrGlyph::UnpackFixedY(id));
}
GrGlyph* generateGlyph(const SkGlyph&, GrGlyph::PackedID);
GrGlyph* generateGlyph(const SkGlyph&);
friend class GrGlyphCache;
};

View File

@ -270,8 +270,7 @@ bool GrTextBlob::VertexRegenerator::doRegen(GrTextBlob::VertexRegenerator::Resul
// Get the id from the old glyph, and use the new strike to lookup
// the glyph.
GrGlyph::PackedID id = fBlob->fGlyphs[glyphOffset]->fPackedID;
fBlob->fGlyphs[glyphOffset] =
strike->getGlyph(id, fSubRun->maskFormat(), fLazyCache->get());
fBlob->fGlyphs[glyphOffset] = strike->getGlyph(id, fLazyCache->get());
SkASSERT(id == fBlob->fGlyphs[glyphOffset]->fPackedID);
}
glyph = fBlob->fGlyphs[glyphOffset];