Skip to content

Commit

Permalink
Remove use of unique glyphs from the SkGlyphRunBuilder
Browse files Browse the repository at this point in the history
I have determined that the uniquify calculation can only
happen when needed when regenerating the GrTextBlob data.

Change-Id: I142e6dedc3b2e6ab5d0b969a8e7c02deec32e912
Reviewed-on: https://skia-review.googlesource.com/c/165023
Reviewed-by: Mike Klein <[email protected]>
Commit-Queue: Herb Derby <[email protected]>
  • Loading branch information
herbderby authored and Skia Commit-Bot committed Oct 25, 2018
1 parent aedc9d2 commit 1648976
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 36 deletions.
49 changes: 16 additions & 33 deletions src/core/SkGlyphRun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,25 +267,24 @@ void SkGlyphRunBuilder::drawTextBlob(const SkPaint& paint, const SkTextBlob& blo
const SkPoint& offset = it.offset();
auto glyphIDs = SkSpan<const SkGlyphID>{it.glyphs(), runSize};

size_t uniqueGlyphIDsSize = 0;
switch (it.positioning()) {
case SkTextBlobRunIterator::kDefault_Positioning: {
uniqueGlyphIDsSize = this->simplifyDrawText(
this->simplifyDrawText(
paint, it.runFont(), glyphIDs, offset,
currentDenseIndices, currentUniqueGlyphIDs, currentPositions,
text, clusters);
}
break;
case SkTextBlobRunIterator::kHorizontal_Positioning: {
auto constY = offset.y();
uniqueGlyphIDsSize = this->simplifyDrawPosTextH(
this->simplifyDrawPosTextH(
paint, it.runFont(), glyphIDs, it.pos(), constY,
currentDenseIndices, currentUniqueGlyphIDs, currentPositions,
text, clusters);
}
break;
case SkTextBlobRunIterator::kFull_Positioning:
uniqueGlyphIDsSize = this->simplifyDrawPosText(
this->simplifyDrawPosText(
paint, it.runFont(), glyphIDs, (const SkPoint*)it.pos(),
currentDenseIndices, currentUniqueGlyphIDs,
text, clusters);
Expand All @@ -294,7 +293,6 @@ void SkGlyphRunBuilder::drawTextBlob(const SkPaint& paint, const SkTextBlob& blo

currentDenseIndices += runSize;
currentPositions += runSize;
currentUniqueGlyphIDs += uniqueGlyphIDsSize;
}

this->makeGlyphRunList(paint, &blob, origin);
Expand Down Expand Up @@ -398,7 +396,7 @@ void SkGlyphRunBuilder::makeGlyphRunList(
paint, blob, origin, SkSpan<SkGlyphRun>{fGlyphRunListStorage}};
}

size_t SkGlyphRunBuilder::simplifyDrawText(
void SkGlyphRunBuilder::simplifyDrawText(
const SkPaint& paint, const SkRunFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
SkPoint origin, uint16_t* uniqueGlyphIDIndicesBuffer, SkGlyphID* uniqueGlyphIDsBuffer,
SkPoint* positions, SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
Expand All @@ -408,21 +406,18 @@ size_t SkGlyphRunBuilder::simplifyDrawText(

SkPaint runPaint{paint, runFont};

auto unqiueGlyphIDs = this->addDenseAndUnique(
runPaint, glyphIDs, uniqueGlyphIDIndicesBuffer, uniqueGlyphIDsBuffer);

if (!unqiueGlyphIDs.empty()) {
if (!glyphIDs.empty()) {
fScratchAdvances.resize(runSize);
{
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(runPaint);
cache->getAdvances(unqiueGlyphIDs, fScratchAdvances.data());
cache->getAdvances(glyphIDs, fScratchAdvances.data());
}

SkPoint endOfLastGlyph = origin;

for (size_t i = 0; i < runSize; i++) {
positions[i] = endOfLastGlyph;
endOfLastGlyph += fScratchAdvances[uniqueGlyphIDIndicesBuffer[i]];
endOfLastGlyph += fScratchAdvances[i];
}

if (paint.getTextAlign() != SkPaint::kLeft_Align) {
Expand All @@ -433,24 +428,21 @@ size_t SkGlyphRunBuilder::simplifyDrawText(
for (auto& pt : SkSpan<SkPoint>{positions, runSize}) {
pt -= len;
}

}

this->makeGlyphRun(
paint,
runFont,
glyphIDs,
SkSpan<const SkPoint>{positions, runSize},
SkSpan<const uint16_t>{uniqueGlyphIDIndicesBuffer, runSize},
unqiueGlyphIDs,
SkSpan<const uint16_t>{},
SkSpan<const SkGlyphID>{},
text,
clusters);
}

return unqiueGlyphIDs.size();
}

size_t SkGlyphRunBuilder::simplifyDrawPosTextH(
void SkGlyphRunBuilder::simplifyDrawPosTextH(
const SkPaint& paint, const SkRunFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
const SkScalar* xpos, SkScalar constY,
uint16_t* uniqueGlyphIDIndicesBuffer, SkGlyphID* uniqueGlyphIDsBuffer, SkPoint* positions,
Expand All @@ -461,34 +453,25 @@ size_t SkGlyphRunBuilder::simplifyDrawPosTextH(
*posCursor++ = SkPoint::Make(x, constY);
}

return simplifyDrawPosText(paint, runFont, glyphIDs, positions,
uniqueGlyphIDIndicesBuffer, uniqueGlyphIDsBuffer,
text, clusters);
simplifyDrawPosText(paint, runFont, glyphIDs, positions,
uniqueGlyphIDIndicesBuffer, uniqueGlyphIDsBuffer,
text, clusters);
}

size_t SkGlyphRunBuilder::simplifyDrawPosText(
void SkGlyphRunBuilder::simplifyDrawPosText(
const SkPaint& paint, const SkRunFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
const SkPoint* pos, uint16_t* uniqueGlyphIDIndicesBuffer, SkGlyphID* uniqueGlyphIDsBuffer,
SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
auto runSize = glyphIDs.size();

// The dense indices are not used by the rest of the stack yet.
SkSpan<const SkGlyphID> uniqueGlyphIDs;
#ifdef SK_DEBUG
uniqueGlyphIDs = this->addDenseAndUnique(
paint, glyphIDs, uniqueGlyphIDIndicesBuffer, uniqueGlyphIDsBuffer);
#endif

// TODO: when using the unique glyph system have a guard that there are actually glyphs like
// drawText above.
this->makeGlyphRun(
paint,
runFont,
glyphIDs,
SkSpan<const SkPoint>{pos, runSize},
SkSpan<const SkGlyphID>{uniqueGlyphIDIndicesBuffer, runSize},
uniqueGlyphIDs,
SkSpan<const uint16_t>{},
SkSpan<const SkGlyphID>{},
text,
clusters);
return uniqueGlyphIDs.size();
}
6 changes: 3 additions & 3 deletions src/core/SkGlyphRun.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,19 @@ class SkGlyphRunBuilder {

void makeGlyphRunList(const SkPaint& paint, const SkTextBlob* blob, SkPoint origin);

size_t simplifyDrawText(
void simplifyDrawText(
const SkPaint& paint, const SkRunFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
SkPoint origin,uint16_t* uniqueGlyphIDIndices, SkGlyphID* uniqueGlyphIDs,
SkPoint* positions,
SkSpan<const char> text = SkSpan<const char>{},
SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{});
size_t simplifyDrawPosTextH(
void simplifyDrawPosTextH(
const SkPaint& paint, const SkRunFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
const SkScalar* xpos, SkScalar constY,
uint16_t* uniqueGlyphIDIndices, SkGlyphID* uniqueGlyphIDs, SkPoint* positions,
SkSpan<const char> text = SkSpan<const char>{},
SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{});
size_t simplifyDrawPosText(
void simplifyDrawPosText(
const SkPaint& paint, const SkRunFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
const SkPoint* pos, uint16_t* uniqueGlyphIDIndices, SkGlyphID* uniqueGlyphIDs,
SkSpan<const char> text = SkSpan<const char>{},
Expand Down

0 comments on commit 1648976

Please sign in to comment.