Start using new APIs for bounds and glyph lookup

Change-Id: I2fa8048b95a48e61c33223257880c2ce8414a5e5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/222507
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Herb Derby 2019-06-20 15:16:13 -04:00 committed by Skia Commit-Bot
parent 0426c38daa
commit 3e8e34e944
6 changed files with 15 additions and 21 deletions

View File

@ -41,13 +41,6 @@ struct GrGlyph {
}
}
static GrIRect16 BoundsFromSkGlyph(const SkGlyph& glyph) {
return GrIRect16::MakeXYWH(glyph.fLeft,
glyph.fTop,
glyph.fWidth,
glyph.fHeight);
}
static MaskStyle MaskStyleFromSkGlyph(const SkGlyph& skGlyph) {
return skGlyph.maskFormat() == SkMask::kSDF_Format
? GrGlyph::MaskStyle::kDistance_MaskStyle
@ -58,7 +51,7 @@ struct GrGlyph {
: fPackedID{skGlyph.getPackedID()}
, fMaskFormat{FormatFromSkGlyph(skGlyph)}
, fMaskStyle{MaskStyleFromSkGlyph(skGlyph)}
, fBounds{BoundsFromSkGlyph(skGlyph)} {}
, fBounds{GrIRect16::Make(skGlyph.iRect())} {}
SkRect destRect(SkPoint origin) {

View File

@ -33,6 +33,12 @@ struct GrIRect16 {
return r;
}
static GrIRect16 SK_WARN_UNUSED_RESULT Make(const SkIRect& ir) {
GrIRect16 r;
r.set(ir);
return r;
}
int width() const { return fRight - fLeft; }
int height() const { return fBottom - fTop; }
int area() const { return this->width() * this->height(); }

View File

@ -83,8 +83,8 @@ static void expand_bits(INT_TYPE* dst,
static bool get_packed_glyph_image(SkStrike* cache, const SkGlyph& glyph, int width,
int height, int dstRB, GrMaskFormat expectedMaskFormat,
void* dst, const SkMasks& masks) {
SkASSERT(glyph.fWidth == width);
SkASSERT(glyph.fHeight == height);
SkASSERT(glyph.width() == width);
SkASSERT(glyph.height() == height);
const void* src = cache->findImage(glyph);
if (nullptr == src) {
return false;
@ -215,13 +215,13 @@ GrDrawOpAtlas::ErrorCode GrTextStrike::addGlyphToAtlas(
}
SkAutoSMalloc<1024> storage(size);
const SkGlyph& skGlyph = skStrikeCache->getGlyphIDMetrics(glyph->fPackedID);
SkGlyph* skGlyph = skStrikeCache->glyph(glyph->fPackedID);
void* dataPtr = storage.get();
if (addPad) {
sk_bzero(dataPtr, size);
dataPtr = (char*)(dataPtr) + rowBytes + bytesPerPixel;
}
if (!get_packed_glyph_image(skStrikeCache, skGlyph, glyph->width(), glyph->height(),
if (!get_packed_glyph_image(skStrikeCache, *skGlyph, glyph->width(), glyph->height(),
rowBytes, expectedMaskFormat,
dataPtr, glyphCache->getMasks())) {
return GrDrawOpAtlas::ErrorCode::kError;

View File

@ -49,8 +49,7 @@ public:
// We could return this to the caller, but in practice it adds code complexity for
// 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 = skStrike->getGlyphIDMetrics(packed);
grGlyph = fAlloc.make<GrGlyph>(skGlyph);
grGlyph = fAlloc.make<GrGlyph>(*skStrike->glyph(packed));
fCache.add(grGlyph);
}
return grGlyph;

View File

@ -714,11 +714,8 @@ struct PositionedGlyph {
static SkRect get_glyph_bounds_device_space(SkGlyphID gid, SkStrike* cache,
SkScalar xScale, SkScalar yScale,
SkPoint xy, const SkMatrix& ctm) {
const SkGlyph& glyph = cache->getGlyphIDMetrics(gid);
SkRect glyphBounds = {glyph.fLeft * xScale,
glyph.fTop * yScale,
(glyph.fLeft + glyph.fWidth) * xScale,
(glyph.fTop + glyph.fHeight) * yScale};
SkGlyph* glyph = cache->glyph(gid);
SkRect glyphBounds = SkMatrix::MakeScale(xScale, yScale).mapRect(glyph->rect());
glyphBounds.offset(xy);
ctm.mapRect(&glyphBounds); // now in dev space.
return glyphBounds;

View File

@ -571,8 +571,7 @@ static void emit_subset_type3(const SkPDFFont& pdfFont, SkPDFDocument* doc) {
characterName.printf("g%X", gID);
SkGlyph* glyph = cache->glyph(gID);
advance = glyph->advanceX();
glyphBBox = SkIRect::MakeXYWH(glyph->fLeft, glyph->fTop,
glyph->fWidth, glyph->fHeight);
glyphBBox = glyph->iRect();
bbox.join(glyphBBox);
const SkPath* path = cache->preparePath(glyph);
SkDynamicMemoryWStream content;