diff options
author | Herb Derby <herb@google.com> | 2018-06-18 16:25:52 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-06-19 19:56:25 +0000 |
commit | 9d85d63468eede1324c88b6e174834eb096113fe (patch) | |
tree | b08d9d455cb2323aadea851abc10cf6d40d2a458 /src/core/SkGlyphRun.cpp | |
parent | 91e260f4dbcb4006c3b177c2eba7ed0dc1af3e3d (diff) |
Use SkGlyphRun instead of builder
Move from passing builder down the stack to passing the
object we really want to be the interface down the stack.
Move code that shunts from glyph run style to drawTextPos
to the SkGlyphRun from the builder.
Change-Id: Iefaca69104737ce46c06fbb26dc99996784b2bdb
Reviewed-on: https://skia-review.googlesource.com/135620
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/core/SkGlyphRun.cpp')
-rw-r--r-- | src/core/SkGlyphRun.cpp | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp index caea07a076..29c1dfdb78 100644 --- a/src/core/SkGlyphRun.cpp +++ b/src/core/SkGlyphRun.cpp @@ -76,6 +76,24 @@ void SkGlyphSet::reuse(uint32_t glyphUniverseSize, std::vector<SkGlyphID>* uniqu // correctly even when the fIndexes buffer is uninitialized! } +// -- SkGlyphRun ----------------------------------------------------------------------------------- + +void SkGlyphRun::temporaryShuntToDrawPosText(const SkPaint& paint, SkBaseDevice* device) { + + auto pos = (const SkScalar*) fPositions.data(); + + device->drawPosText( + fTemporaryShuntGlyphIDs.data(), fDenseIndex.size() * sizeof(SkGlyphID), + pos, 2, SkPoint::Make(0, 0), paint); +} + +void SkGlyphRun::temporaryShuntToCallback(TemporaryShuntCallback callback) { + auto bytes = (const char *)fTemporaryShuntGlyphIDs.data(); + auto pos = (const SkScalar*)fPositions.data(); + callback(this->runSize(), bytes, pos); +} + + // -- SkGlyphRunBuilder ---------------------------------------------------------------------------- void SkGlyphRunBuilder::prepareDrawText( const SkPaint& paint, const void* bytes, size_t byteLength, SkPoint origin) { @@ -127,26 +145,14 @@ void SkGlyphRunBuilder::prepareDrawPosText(const SkPaint& paint, const void* byt } } -const SkGlyphRun& SkGlyphRunBuilder::useGlyphRun() const { +SkGlyphRun* SkGlyphRunBuilder::useGlyphRun() { + fScratchGlyphRun.~SkGlyphRun(); new ((void*)&fScratchGlyphRun) SkGlyphRun{SkSpan<uint16_t>(fDenseIndex), - SkSpan<SkPoint>(fPositions), - SkSpan<SkGlyphID>(fUniqueGlyphs)}; - return fScratchGlyphRun; -} - -void SkGlyphRunBuilder::temporaryShuntToDrawPosText(const SkPaint& paint, SkBaseDevice* device) { - - auto pos = (const SkScalar*) fPositions.data(); - - device->drawPosText( - fTemporaryShuntGlyphIDs, fDenseIndex.size() * 2, - pos, 2, SkPoint::Make(0, 0), paint); -} - -void SkGlyphRunBuilder::temporaryShuntToCallback(TemporaryShuntCallback callback) { - auto bytes = (const char *)fTemporaryShuntGlyphIDs; - auto pos = (const SkScalar*)fPositions.data(); - callback(this->runSize(), bytes, pos); + SkSpan<SkPoint>(fPositions), + SkSpan<SkGlyphID>( + fTemporaryShuntGlyphIDs, fDenseIndex.size()), + SkSpan<SkGlyphID>(fUniqueGlyphs)}; + return &fScratchGlyphRun; } void SkGlyphRunBuilder::initializeDenseAndUnique( @@ -175,6 +181,8 @@ void SkGlyphRunBuilder::initializeDenseAndUnique( glyphIDs = (const SkGlyphID*)bytes; } + SkASSERT(glyphIDs != nullptr); + if (runSize == 0) { return; } fTemporaryShuntGlyphIDs = glyphIDs; |