Change to using SkPackedGlyphID and left top point
Currently, glyph data is communicated to the SubRuns using
SkGlyph* and the glyph origin. In the near future SkGlyph* will
not be an option to pass data to the SubRuns. Switch from using
SkGlyph* to using SkPackedGlyphID and from using the glyph
origin to using the top left corner of the glyph bounding
rectangle.
Change-Id: I912e07312429962067241c13df5b81072f49eefd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/565642
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/core/SkChromeRemoteGlyphCache.cpp b/src/core/SkChromeRemoteGlyphCache.cpp
index 0efcabf..def6880 100644
--- a/src/core/SkChromeRemoteGlyphCache.cpp
+++ b/src/core/SkChromeRemoteGlyphCache.cpp
@@ -412,6 +412,7 @@
const SkGlyphRect glyphBounds =
digest.bounds().scaleAndOffset(strikeToSourceScale, pos);
boundingRect = skglyph::rect_union(boundingRect, glyphBounds);
+ accepted->accept(packedID, glyphBounds.leftTop(), digest.maskFormat());
}
} else {
// Reject things that are too big.
@@ -437,6 +438,7 @@
.inset(SK_DistanceFieldInset, SK_DistanceFieldInset)
.scaleAndOffset(strikeToSourceScale, pos);
boundingRect = skglyph::rect_union(boundingRect, glyphBounds);
+ accepted->accept(packedID, glyphBounds.leftTop(), digest.maskFormat());
}
} else {
// Reject things that are too big.
diff --git a/src/core/SkGlyphBuffer.h b/src/core/SkGlyphBuffer.h
index 38d4588..8162c8a 100644
--- a/src/core/SkGlyphBuffer.h
+++ b/src/core/SkGlyphBuffer.h
@@ -171,6 +171,14 @@
fAcceptedSize++;
}
+ void accept(SkPackedGlyphID glyphID, SkPoint position, SkMask::Format format) {
+ SkASSERT(fPhase == kProcess);
+ fPositions[fAcceptedSize] = position;
+ fMultiBuffer[fAcceptedSize] = glyphID;
+ fFormats[fAcceptedSize] = format;
+ fAcceptedSize++;
+ }
+
// The result after a series of `accept` of accepted SkGlyph* or SkPath*.
SkZip<SkGlyphVariant, SkPoint> accepted() {
SkASSERT(fPhase == kProcess);
diff --git a/src/core/SkScalerCache.cpp b/src/core/SkScalerCache.cpp
index acee67d..6f1b056 100644
--- a/src/core/SkScalerCache.cpp
+++ b/src/core/SkScalerCache.cpp
@@ -282,7 +282,7 @@
const SkGlyphRect glyphBounds =
digest.bounds().scaleAndOffset(strikeToSourceScale, pos);
boundingRect = skglyph::rect_union(boundingRect, glyphBounds);
- accepted->accept(fGlyphForIndex[digest.index()], i);
+ accepted->accept(packedID, glyphBounds.leftTop(), digest.maskFormat());
} else {
rejected->reject(i);
}
@@ -315,7 +315,7 @@
.inset(SK_DistanceFieldInset, SK_DistanceFieldInset)
.scaleAndOffset(strikeToSourceScale, pos);
boundingRect = skglyph::rect_union(boundingRect, glyphBounds);
- accepted->accept(fGlyphForIndex[digest.index()], i);
+ accepted->accept(packedID, glyphBounds.leftTop(), digest.maskFormat());
} else {
// Assume whatever follows SDF doesn't care about the maximum rejected size.
rejected->reject(i);
diff --git a/src/text/gpu/GlyphVector.cpp b/src/text/gpu/GlyphVector.cpp
index 3e22729..a4a43fd 100644
--- a/src/text/gpu/GlyphVector.cpp
+++ b/src/text/gpu/GlyphVector.cpp
@@ -30,7 +30,7 @@
GlyphVector::MakeGlyphs(SkSpan<SkGlyphVariant> glyphs, sktext::gpu::SubRunAllocator* alloc) {
Variant* variants = alloc->makePODArray<Variant>(glyphs.size());
for (auto [i, gv] : SkMakeEnumerate(glyphs)) {
- variants[i] = gv.glyph()->getPackedID();
+ variants[i] = gv.packedID();
}
return variants;
}
diff --git a/src/text/gpu/SubRunContainer.cpp b/src/text/gpu/SubRunContainer.cpp
index e352010..d56b84a 100644
--- a/src/text/gpu/SubRunContainer.cpp
+++ b/src/text/gpu/SubRunContainer.cpp
@@ -204,14 +204,11 @@
SkScalar strikeToSourceScale,
const SkZip<SkGlyphVariant, SkPoint>& accepted,
SubRunAllocator* alloc) {
- const SkPoint paddingInset = SkPoint::Make(strikePadding, strikePadding);
SkSpan<SkPoint> leftTop = alloc->makePODArray<SkPoint>(
accepted,
[&](auto e) -> SkPoint {
auto [variant, pos] = e;
- const SkGlyph* skGlyph = variant;
- SkPoint leftTop = SkPoint::Make(skGlyph->left(), skGlyph->top());
- return (leftTop + paddingInset) * strikeToSourceScale + pos;
+ return pos;
});
return TransformedMaskVertexFiller{maskType, strikeToSourceScale, sourceBounds, leftTop};
}
@@ -1271,9 +1268,8 @@
auto glyphIDs = alloc->makePODArray<GlyphVector::Variant>(accepted.size());
for (auto [i, variant, pos] : SkMakeEnumerate(accepted)) {
- const SkGlyph* const skGlyph = variant;
- glyphLeftTop[i] = SkPoint::Make(skGlyph->left(), skGlyph->top()) + pos;
- glyphIDs[i].packedGlyphID = skGlyph->getPackedID();
+ glyphLeftTop[i] = pos;
+ glyphIDs[i].packedGlyphID = variant.packedID();
}
SkSpan<const SkPoint> leftTop{glyphLeftTop, accepted.size()};
diff --git a/tests/GrGlyphVectorTest.cpp b/tests/GrGlyphVectorTest.cpp
index 1afaf66..d201012 100644
--- a/tests/GrGlyphVectorTest.cpp
+++ b/tests/GrGlyphVectorTest.cpp
@@ -48,11 +48,10 @@
SubRunAllocator alloc;
- SkBulkGlyphMetricsAndImages glyphFinder{strikeSpec};
const int N = 10;
SkGlyphVariant* glyphs = alloc.makePODArray<SkGlyphVariant>(N);
for (int i = 0; i < N; i++) {
- glyphs[i] = glyphFinder.glyph(SkPackedGlyphID(SkTo<SkGlyphID>(i + 1)));
+ glyphs[i] = SkPackedGlyphID(SkGlyphID(i));
}
GlyphVector src = GlyphVector::Make(