diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index afdb4f9940..367105ddda 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -2429,7 +2429,7 @@ void SkCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkSca LOOPER_BEGIN(paint, nullptr) while (iter.next()) { - fScratchGlyphRunBuilder->prepareDrawText( + fScratchGlyphRunBuilder->drawText( looper.paint(), text, byteLength, SkPoint::Make(x, y)); auto glyphRun = fScratchGlyphRunBuilder->useGlyphRun(); iter.fDevice->drawGlyphRun(looper.paint(), glyphRun); @@ -2444,7 +2444,7 @@ void SkCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint LOOPER_BEGIN(paint, nullptr) while (iter.next()) { - fScratchGlyphRunBuilder->prepareDrawPosText(looper.paint(), text, byteLength, pos); + fScratchGlyphRunBuilder->drawPosText(looper.paint(), text, byteLength, pos); auto glyphRun = fScratchGlyphRunBuilder->useGlyphRun(); iter.fDevice->drawGlyphRun(looper.paint(), glyphRun); } @@ -2458,7 +2458,7 @@ void SkCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScala LOOPER_BEGIN(paint, nullptr) while (iter.next()) { - fScratchGlyphRunBuilder->prepareDrawPosTextH( + fScratchGlyphRunBuilder->drawPosTextH( looper.paint(), text, byteLength, xpos, constY); const auto& glyphRun = fScratchGlyphRunBuilder->useGlyphRun(); iter.fDevice->drawGlyphRun(looper.paint(), glyphRun); diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index b6f52913eb..5ca8f5ec5e 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -156,7 +156,7 @@ void SkBaseDevice::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, case SkTextBlob::kDefault_Positioning: { auto origin = SkPoint::Make(x + offset.x(), y + offset.y()); SkGlyphRunBuilder builder; - builder.prepareDrawText(runPaint, (const char*) it.glyphs(), textLen, origin); + builder.drawText(runPaint, (const char*) it.glyphs(), textLen, origin); auto glyphRun = builder.useGlyphRun(); glyphRun->temporaryShuntToDrawPosText(this); } diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp index 3bd9efc90f..781263c103 100644 --- a/src/core/SkGlyphRun.cpp +++ b/src/core/SkGlyphRun.cpp @@ -132,32 +132,34 @@ SkSpan SkGlyphIDSet::uniquifyGlyphIDs( } // -- SkGlyphRunBuilder ---------------------------------------------------------------------------- -void SkGlyphRunBuilder::prepareDrawText( +void SkGlyphRunBuilder::drawText( const SkPaint& paint, const void* bytes, size_t byteLength, SkPoint origin) { auto glyphIDs = textToGlyphIDs(paint, bytes, byteLength); if (!glyphIDs.empty()) { this->initialize(glyphIDs.size()); - this->drawText(paint, glyphIDs, origin, SkSpan(), SkSpan()); + this->simplifyDrawText( + paint, glyphIDs, origin, fUniqueGlyphIDIndices, fUniqueGlyphIDs, fPositions); } } -void SkGlyphRunBuilder::prepareDrawPosTextH(const SkPaint& paint, const void* bytes, - size_t byteLength, const SkScalar* xpos, - SkScalar constY) { +void SkGlyphRunBuilder::drawPosTextH(const SkPaint& paint, const void* bytes, + size_t byteLength, const SkScalar* xpos, + SkScalar constY) { auto glyphIDs = textToGlyphIDs(paint, bytes, byteLength); if (!glyphIDs.empty()) { this->initialize(glyphIDs.size()); - this->drawPosTextH( - paint, glyphIDs, xpos, constY, SkSpan(), SkSpan()); + this->simplifyDrawPosTextH( + paint, glyphIDs, xpos, constY, fUniqueGlyphIDIndices, fUniqueGlyphIDs, fPositions); } } -void SkGlyphRunBuilder::prepareDrawPosText(const SkPaint& paint, const void* bytes, - size_t byteLength, const SkPoint* pos) { +void SkGlyphRunBuilder::drawPosText(const SkPaint& paint, const void* bytes, + size_t byteLength, const SkPoint* pos) { auto glyphIDs = textToGlyphIDs(paint, bytes, byteLength); if (!glyphIDs.empty()) { this->initialize(glyphIDs.size()); - this->drawPosText(paint, glyphIDs, pos, SkSpan(), SkSpan()); + this->simplifyDrawPosText( + paint, glyphIDs, pos, fUniqueGlyphIDIndices, fUniqueGlyphIDs); } } @@ -201,15 +203,18 @@ SkSpan SkGlyphRunBuilder::textToGlyphIDs( SkSpan SkGlyphRunBuilder::addDenseAndUnique( const SkPaint& paint, - SkSpan glyphIDs) { + SkSpan glyphIDs, + uint16_t* uniqueGlyphIDIndices, + SkGlyphID* uniqueGlyphIDs) { SkSpan uniquifiedGlyphIDs; if (!glyphIDs.empty()) { auto typeface = SkPaintPriv::GetTypefaceOrDefault(paint); auto glyphUniverseSize = typeface->countGlyphs(); + // There better be glyphs in the font if we want to uniqify. if (glyphUniverseSize > 0) { uniquifiedGlyphIDs = fGlyphIDSet.uniquifyGlyphIDs( - glyphUniverseSize, glyphIDs, fUniqueGlyphIDs, fUniqueGlyphIDIndices); + glyphUniverseSize, glyphIDs, uniqueGlyphIDs, uniqueGlyphIDIndices); } } @@ -243,14 +248,17 @@ void SkGlyphRunBuilder::makeGlyphRun( } } -void SkGlyphRunBuilder::drawText( +void SkGlyphRunBuilder::simplifyDrawText( const SkPaint& paint, SkSpan glyphIDs, SkPoint origin, + uint16_t* uniqueGlyphIDIndicesBuffer, SkGlyphID* uniqueGlyphIDsBuffer, SkPoint* positions, SkSpan text, SkSpan clusters) { SkASSERT(!glyphIDs.empty()); + auto runSize = glyphIDs.size(); - auto unqiueGlyphIDs = this->addDenseAndUnique(paint, glyphIDs); + auto unqiueGlyphIDs = this->addDenseAndUnique( + paint, glyphIDs, uniqueGlyphIDIndicesBuffer, uniqueGlyphIDsBuffer); if (!unqiueGlyphIDs.empty()) { fScratchAdvances.resize(runSize); @@ -262,7 +270,7 @@ void SkGlyphRunBuilder::drawText( SkPoint endOfLastGlyph = origin; for (size_t i = 0; i < runSize; i++) { - fPositions[i] = endOfLastGlyph; + positions[i] = endOfLastGlyph; endOfLastGlyph += fScratchAdvances[fUniqueGlyphIDIndices[i]]; } @@ -271,16 +279,16 @@ void SkGlyphRunBuilder::drawText( if (paint.getTextAlign() == SkPaint::kCenter_Align) { len.scale(SK_ScalarHalf); } - for (auto& pt : SkSpan{fPositions, runSize}) { + for (auto& pt : SkSpan{positions, runSize}) { pt -= len; } - } + } this->makeGlyphRun( paint, glyphIDs, - SkSpan{fPositions, runSize}, + SkSpan{positions, runSize}, SkSpan{fUniqueGlyphIDIndices, runSize}, unqiueGlyphIDs, text, @@ -288,43 +296,34 @@ void SkGlyphRunBuilder::drawText( } } -void SkGlyphRunBuilder::drawPosTextH(const SkPaint& paint, SkSpan glyphIDs, - const SkScalar* xpos, SkScalar constY, - SkSpan text, SkSpan clusters) { - SkASSERT(!glyphIDs.empty()); - auto runSize = glyphIDs.size(); +void SkGlyphRunBuilder::simplifyDrawPosTextH( + const SkPaint& paint, SkSpan glyphIDs, + const SkScalar* xpos, SkScalar constY, + uint16_t* uniqueGlyphIDIndicesBuffer, SkGlyphID* uniqueGlyphIDsBuffer, SkPoint* positions, + SkSpan text, SkSpan clusters) { - // The dense indices are not used by the rest of the stack yet. - #ifdef SK_DEBUG - this->addDenseAndUnique(paint, glyphIDs); - #endif - - // TODO: when using the unique glyph system have a guard that there are actually glyphs like - // drawText above. - auto posCursor = fPositions.get(); - for (auto x : SkSpan{xpos, runSize}) { + auto posCursor = positions; + for (auto x : SkSpan{xpos, glyphIDs.size()}) { *posCursor++ = SkPoint::Make(x, constY); } - this->makeGlyphRun( - paint, - glyphIDs, - SkSpan{fPositions, runSize}, - SkSpan{}, - SkSpan{}, - text, - clusters); + this->simplifyDrawPosText( + paint, glyphIDs, positions, + uniqueGlyphIDIndicesBuffer, uniqueGlyphIDsBuffer, + text, clusters); } -void SkGlyphRunBuilder::drawPosText(const SkPaint& paint, SkSpan glyphIDs, - const SkPoint* pos, - SkSpan text, SkSpan clusters) { - SkASSERT(!glyphIDs.empty()); +void SkGlyphRunBuilder::simplifyDrawPosText( + const SkPaint& paint, SkSpan glyphIDs, const SkPoint* pos, + uint16_t* uniqueGlyphIDIndicesBuffer, SkGlyphID* uniqueGlyphIDsBuffer, + SkSpan text, SkSpan clusters) { auto runSize = glyphIDs.size(); // The dense indices are not used by the rest of the stack yet. + SkSpan uniqueGlyphIDs; #ifdef SK_DEBUG - this->addDenseAndUnique(paint, glyphIDs); + uniqueGlyphIDs = this->addDenseAndUnique( + paint, glyphIDs, uniqueGlyphIDIndicesBuffer, uniqueGlyphIDsBuffer); #endif // TODO: when using the unique glyph system have a guard that there are actually glyphs like @@ -333,8 +332,8 @@ void SkGlyphRunBuilder::drawPosText(const SkPaint& paint, SkSpan{pos, runSize}, - SkSpan{}, - SkSpan{}, + SkSpan{uniqueGlyphIDIndicesBuffer, runSize}, + uniqueGlyphIDs, text, clusters); } diff --git a/src/core/SkGlyphRun.h b/src/core/SkGlyphRun.h index affc044f76..a1124fd58e 100644 --- a/src/core/SkGlyphRun.h +++ b/src/core/SkGlyphRun.h @@ -95,14 +95,15 @@ private: class SkGlyphRunBuilder { public: - SkGlyphRunBuilder() = default; - void prepareDrawText( - const SkPaint& paint, const void* bytes, size_t byteLength, SkPoint origin); - void prepareDrawPosTextH( + void drawText( const SkPaint& paint, const void* bytes, size_t byteLength, - const SkScalar xpos[], SkScalar constY); - void prepareDrawPosText( - const SkPaint& paint, const void* bytes, size_t byteLength, const SkPoint pos[]); + SkPoint origin); + void drawPosTextH( + const SkPaint& paint, const void* bytes, size_t byteLength, + const SkScalar* xpos, SkScalar constY); + void drawPosText( + const SkPaint& paint, const void* bytes, size_t byteLength, + const SkPoint* pos); SkGlyphRun* useGlyphRun(); @@ -114,7 +115,9 @@ private: // Returns the span of unique glyph IDs. SkSpan addDenseAndUnique( const SkPaint& paint, - SkSpan glyphIDs); + SkSpan glyphIDs, + uint16_t* uniqueGlyphIDIndices, + SkGlyphID* uniqueGlyphIDs); void makeGlyphRun( const SkPaint& runPaint, @@ -125,16 +128,22 @@ private: SkSpan text, SkSpan clusters); - void drawText( + void simplifyDrawText( const SkPaint& paint, SkSpan glyphIDs, SkPoint origin, - SkSpan text, SkSpan clusters); - void drawPosTextH( + uint16_t* uniqueGlyphIDIndices, SkGlyphID* uniqueGlyphIDs, SkPoint* positions, + SkSpan text = SkSpan{}, + SkSpan clusters = SkSpan{}); + void simplifyDrawPosTextH( const SkPaint& paint, SkSpan glyphIDs, const SkScalar* xpos, SkScalar constY, - SkSpan text, SkSpan clusters); - void drawPosText( + uint16_t* uniqueGlyphIDIndices, SkGlyphID* uniqueGlyphIDs, SkPoint* positions, + SkSpan text = SkSpan{}, + SkSpan clusters = SkSpan{}); + void simplifyDrawPosText( const SkPaint& paint, SkSpan glyphIDs, const SkPoint* pos, - SkSpan text, SkSpan clusters); + uint16_t* uniqueGlyphIDIndices, SkGlyphID* uniqueGlyphIDs, + SkSpan text = SkSpan{}, + SkSpan clusters = SkSpan{}); uint64_t fUniqueID{0}; diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp index 28204eb7af..04d92aef39 100644 --- a/src/gpu/text/GrTextContext.cpp +++ b/src/gpu/text/GrTextContext.cpp @@ -211,8 +211,8 @@ void GrTextContext::regenerateTextBlob(GrTextBlob* cacheBlob, case SkTextBlob::kDefault_Positioning: { auto origin = SkPoint::Make(x + offset.x(), y + offset.y()); SkGlyphRunBuilder builder; - builder.prepareDrawText(runPaint.skPaint(), - (const char*)it.glyphs(), textLen, origin); + builder.drawText(runPaint.skPaint(), + (const char*) it.glyphs(), textLen, origin); auto glyphRun = builder.useGlyphRun(); @@ -246,8 +246,8 @@ void GrTextContext::regenerateTextBlob(GrTextBlob* cacheBlob, case SkTextBlob::kDefault_Positioning: { auto origin = SkPoint::Make(x + offset.x(), y + offset.y()); SkGlyphRunBuilder builder; - builder.prepareDrawText(runPaint.skPaint(), - (const char*)it.glyphs(), textLen, origin); + builder.drawText(runPaint.skPaint(), + (const char*) it.glyphs(), textLen, origin); auto glyphRun = builder.useGlyphRun(); @@ -780,7 +780,7 @@ std::unique_ptr GrTextContext::createOp_TestingOnly(GrContext* context auto origin = SkPoint::Make(x, y); SkGlyphRunBuilder builder; - builder.prepareDrawText(skPaint, text, textLen, origin); + builder.drawText(skPaint, text, textLen, origin); sk_sp blob; auto glyphRun = builder.useGlyphRun(); diff --git a/tests/GlyphRunTest.cpp b/tests/GlyphRunTest.cpp index 7ec14240e7..b87edc7731 100644 --- a/tests/GlyphRunTest.cpp +++ b/tests/GlyphRunTest.cpp @@ -47,5 +47,5 @@ DEF_TEST(GlyphRunBasic, reporter) { paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); SkGlyphRunBuilder builder; - builder.prepareDrawText(paint, glyphs, count, SkPoint::Make(0, 0)); + builder.drawText(paint, glyphs, count, SkPoint::Make(0, 0)); }