diff options
author | Herb Derby <herb@google.com> | 2018-07-09 14:46:48 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-07-10 14:57:55 +0000 |
commit | 45e27c8eed8f1673efebcb6cb2c03b8644c9c7a5 (patch) | |
tree | 74f2c2aa41e286c94eb2ea97f3bdd197743031fe | |
parent | 653f42f72a1ccb4a5d86cdf128993cbb5c9a310b (diff) |
Remove run list code
Temporarily remove run list code to gut some
overly complicated code.
Change-Id: Ib12efc394c05dee391143b440b2fab5bba4f22ae
Reviewed-on: https://skia-review.googlesource.com/139865
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Herb Derby <herb@google.com>
-rw-r--r-- | src/core/SkGlyphRun.cpp | 32 | ||||
-rw-r--r-- | src/core/SkGlyphRun.h | 62 | ||||
-rw-r--r-- | tests/GlyphRunTest.cpp | 55 |
3 files changed, 32 insertions, 117 deletions
diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp index ce1c336d88..fa070da3a7 100644 --- a/src/core/SkGlyphRun.cpp +++ b/src/core/SkGlyphRun.cpp @@ -85,7 +85,7 @@ void SkGlyphSet::reuse(uint32_t glyphUniverseSize, std::vector<SkGlyphID>* uniqu } // -- SkGlyphRun ----------------------------------------------------------------------------------- -SkGlyphRun::SkGlyphRun(const SkIndexedRunInfo& runInfo, +SkGlyphRun::SkGlyphRun(const SkIndexedRunInfo* runInfo, size_t denseOffset, size_t denseSize, size_t uniqueOffset, uint16_t uniqueSize, SkSpan<SkGlyphID> scratchGlyphs, @@ -114,11 +114,6 @@ void SkGlyphRun::temporaryShuntToCallback(TemporaryShuntCallback callback) { callback(this->runSize(), bytes, pos); } -// -- SkGlyphRunList ------------------------------------------------------------------------------- -SkGlyphRunList::SkGlyphRunList(SkSpan<SkGlyphRun> glyphRuns, uint64_t uniqueID) - : fUniqueID{uniqueID} - , fGlyphRuns{glyphRuns} { } - // -- SkGlyphRunBuilder ---------------------------------------------------------------------------- void SkGlyphRunBuilder::prepareDrawText( const SkPaint& paint, const void* bytes, size_t byteLength, SkPoint origin) { @@ -187,14 +182,7 @@ void SkGlyphRunBuilder::prepareTextBlob( } SkGlyphRun* SkGlyphRunBuilder::useGlyphRun() { - auto glyphRunList = this->useGlyphRunList(); - SkASSERT(glyphRunList->size() == 1); - return &(*glyphRunList)[0]; -} - -SkGlyphRunList* SkGlyphRunBuilder::useGlyphRunList() { - new ((void*)&fScratchGlyphRunList) SkGlyphRunList{SkSpan<SkGlyphRun>(fGlyphRuns), fUniqueID}; - return &fScratchGlyphRunList; + return &fScratchGlyphRun; } size_t SkGlyphRunBuilder::runSize() const { return fDenseIndex.size() - fLastDenseIndex; } @@ -206,7 +194,6 @@ void SkGlyphRunBuilder::initialize() { fDenseIndex.clear(); fPositions.clear(); fUniqueGlyphIDs.clear(); - fGlyphRuns.clear(); fLastDenseIndex = 0; fLastUniqueIndex = 0; } @@ -244,7 +231,7 @@ SkGlyphID* SkGlyphRunBuilder::addDenseAndUnique( return glyphIDs; } -void SkGlyphRunBuilder::addGlyphRunToList( +void SkGlyphRunBuilder::makeGlyphRun( SkGlyphID* temporaryShuntGlyphIDs, SkSpan<const char> text, SkSpan<uint32_t> clusters) { // Ignore empty runs. @@ -252,13 +239,14 @@ void SkGlyphRunBuilder::addGlyphRunToList( auto runSize = this->runSize(); auto uniqueSize = this->uniqueSize(); - fGlyphRuns.emplace_back( - fIndexed, + new ((void*)&fScratchGlyphRun) SkGlyphRun{ + &fIndexed, fLastDenseIndex, runSize, fLastUniqueIndex, SkTo<uint16_t>(uniqueSize), SkSpan<SkGlyphID>(temporaryShuntGlyphIDs, runSize), text, - clusters); + clusters + }; fLastDenseIndex = fDenseIndex.size(); fLastUniqueIndex = fUniqueGlyphIDs.size(); @@ -295,7 +283,7 @@ void SkGlyphRunBuilder::drawText( } } - this->addGlyphRunToList(temporaryShuntGlyphIDs, text, clusters); + this->makeGlyphRun(temporaryShuntGlyphIDs, text, clusters); } void SkGlyphRunBuilder::drawPosTextH(const SkPaint& paint, const void* bytes, @@ -309,7 +297,7 @@ void SkGlyphRunBuilder::drawPosTextH(const SkPaint& paint, const void* bytes, fPositions.push_back(SkPoint::Make(xpos[i], constY)); } - this->addGlyphRunToList(temporaryShuntGlyphIDs, text, clusters); + this->makeGlyphRun(temporaryShuntGlyphIDs, text, clusters); } void SkGlyphRunBuilder::drawPosText(const SkPaint& paint, const void* bytes, @@ -321,7 +309,7 @@ void SkGlyphRunBuilder::drawPosText(const SkPaint& paint, const void* bytes, fPositions.push_back(pos[i]); } - this->addGlyphRunToList(temporaryShuntGlyphIDs, text, clusters); + this->makeGlyphRun(temporaryShuntGlyphIDs, text, clusters); } diff --git a/src/core/SkGlyphRun.h b/src/core/SkGlyphRun.h index fe9922b381..653b1f9ae1 100644 --- a/src/core/SkGlyphRun.h +++ b/src/core/SkGlyphRun.h @@ -43,34 +43,35 @@ private: }; struct SkIndexedRunInfo { - SkIndexedRunInfo(const std::vector<uint16_t>& denseIndex, - const std::vector<SkPoint>& positions, - const std::vector<SkGlyphID>& uniqueGlyphIDs) + SkIndexedRunInfo(const std::vector<uint16_t>* denseIndex, + const std::vector<SkPoint>* positions, + const std::vector<SkGlyphID>* uniqueGlyphIDs) : fDenseIndex{denseIndex} , fPositions{positions} , fUniqueGlyphIDs{uniqueGlyphIDs} {} SkSpan<const uint16_t> denseIndex(size_t start, size_t size) { - return SkSpan<const uint16_t>(&fDenseIndex[start], size); + return SkSpan<const uint16_t>(&(*fDenseIndex)[start], size); } SkSpan<const SkPoint> positions(size_t start, size_t size) const { - return SkSpan<const SkPoint>(&fPositions[start], size); + return SkSpan<const SkPoint>(&(*fPositions)[start], size); } SkSpan<const SkGlyphID> uniqueGlyphIDs(size_t start, size_t size) const { - return SkSpan<const SkGlyphID>(&fUniqueGlyphIDs[start], size); + return SkSpan<const SkGlyphID>(&(*fUniqueGlyphIDs)[start], size); } private: - const std::vector<uint16_t>& fDenseIndex; - const std::vector<SkPoint>& fPositions; - const std::vector<SkGlyphID>& fUniqueGlyphIDs; + const std::vector<uint16_t>* fDenseIndex; + const std::vector<SkPoint>* fPositions; + const std::vector<SkGlyphID>* fUniqueGlyphIDs; }; class SkGlyphRun { public: - SkGlyphRun(const SkIndexedRunInfo& runInfo, + SkGlyphRun() = default; + SkGlyphRun(const SkIndexedRunInfo* runInfo, size_t denseOffset, size_t denseSize, size_t fUniqueOffset, uint16_t fUniqueSize, SkSpan<SkGlyphID> scratchGlyphs, @@ -86,18 +87,18 @@ public: size_t runSize() const { return fDenseSize; } uint16_t uniqueSize() const { return fUniqueSize; } SkSpan<const SkPoint> positions() const { - return fRunInfo.positions(fDenseOffset, fDenseSize); + return fRunInfo->positions(fDenseOffset, fDenseSize); } SkSpan<const SkGlyphID> uniqueGlyphIDs() const { - return fRunInfo.uniqueGlyphIDs(fUniqueOffset, fUniqueSize); + return fRunInfo->uniqueGlyphIDs(fUniqueOffset, fUniqueSize); } private: - const SkIndexedRunInfo& fRunInfo; - const size_t fDenseOffset; - const size_t fDenseSize; - const size_t fUniqueOffset; - const uint16_t fUniqueSize; + const SkIndexedRunInfo* fRunInfo; + size_t fDenseOffset; + size_t fDenseSize; + size_t fUniqueOffset; + uint16_t fUniqueSize; // This is temporary while converting from the old per glyph code to the bulk code. const SkSpan<SkGlyphID> fTemporaryShuntGlyphIDs; @@ -107,22 +108,6 @@ private: const SkSpan<uint32_t> fClusters; }; -class SkGlyphRunList { - const uint64_t fUniqueID{0}; - SkSpan<SkGlyphRun> fGlyphRuns; - -public: - SkGlyphRunList() = default; - SkGlyphRunList(SkSpan<SkGlyphRun> glyphRuns, uint64_t uniqueID); - - uint64_t uniqueID() const { return fUniqueID; } - - auto begin() -> decltype(fGlyphRuns.begin()) { return fGlyphRuns.begin(); } - auto end() -> decltype(fGlyphRuns.end()) { return fGlyphRuns.end(); } - auto size() -> decltype(fGlyphRuns.size()) { return fGlyphRuns.size(); } - auto operator [] (ptrdiff_t i) -> decltype(fGlyphRuns[i]) { return fGlyphRuns[i]; } -}; - // A faster set implementation that does not need any initialization, and reading the set items // is order the number of items, and not the size of the universe. // This implementation is based on the paper by Briggs and Torczon, "An Efficient Representation @@ -157,7 +142,6 @@ public: const SkPaint& paint, const void* bytes, size_t byteLength, const SkPoint pos[]); void prepareTextBlob(const SkPaint& paint, const SkTextBlob& blob, SkPoint origin); - SkGlyphRunList* useGlyphRunList(); SkGlyphRun* useGlyphRun(); private: @@ -165,7 +149,7 @@ private: size_t uniqueSize() const; void initialize(); SkGlyphID* addDenseAndUnique(const SkPaint& paint, const void* bytes, size_t byteLength); - void addGlyphRunToList( + void makeGlyphRun( SkGlyphID* temporaryShuntGlyphIDs, SkSpan<const char> text, SkSpan<uint32_t> clusters); void drawText( @@ -185,7 +169,7 @@ private: std::vector<SkPoint> fPositions; std::vector<SkGlyphID> fUniqueGlyphIDs; - SkIndexedRunInfo fIndexed{fDenseIndex, fPositions, fUniqueGlyphIDs}; + SkIndexedRunInfo fIndexed{&fDenseIndex, &fPositions, &fUniqueGlyphIDs}; size_t fLastDenseIndex{0}; size_t fLastUniqueIndex{0}; @@ -197,14 +181,12 @@ private: // Used as temporary storage for calculating positions for drawText. std::vector<SkPoint> fScratchAdvances; - // Vector for accumulating runs. This is later deposited in fScratchGlyphRunList; - std::vector<SkGlyphRun> fGlyphRuns; // Used as temporary glyph run for the rest of the Text stack. - SkGlyphRunList fScratchGlyphRunList; + SkGlyphRun fScratchGlyphRun; // Used for collecting the set of unique glyphs. - SkGlyphSet fGlyphSet; + SkGlyphSet fGlyphSet; }; #endif // SkGlyphRunInfo_DEFINED diff --git a/tests/GlyphRunTest.cpp b/tests/GlyphRunTest.cpp index cd2a221719..46b4715c61 100644 --- a/tests/GlyphRunTest.cpp +++ b/tests/GlyphRunTest.cpp @@ -42,58 +42,3 @@ DEF_TEST(GlyphRunBasic, reporter) { SkGlyphRunBuilder builder; builder.prepareDrawText(paint, glyphs, count, SkPoint::Make(0, 0)); } - -DEF_TEST(GlyphRunBlob, reporter) { - constexpr uint16_t count = 5; - constexpr int runCount = 2; - - auto tf = SkTypeface::MakeFromName("monospace", SkFontStyle()); - - SkPaint font; - font.setTypeface(tf); - font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); - font.setTextAlign(SkPaint::kLeft_Align); - font.setStyle(SkPaint::kFill_Style); - font.setHinting(SkPaint::kNormal_Hinting); - font.setTextSize(1u); - - SkTextBlobBuilder blobBuilder; - for (int runNum = 0; runNum < runCount; runNum++) { - const auto& runBuffer = blobBuilder.allocRunPosH(font, count, runNum); - SkASSERT(runBuffer.utf8text == nullptr); - SkASSERT(runBuffer.clusters == nullptr); - - for (int i = 0; i < count; i++) { - runBuffer.glyphs[i] = static_cast<SkGlyphID>(i + runNum * count); - runBuffer.pos[i] = SkIntToScalar(i + runNum * count); - } - } - - auto blob = blobBuilder.make(); - - SkPaint paint; - paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); - - SkGlyphRunBuilder runBuilder; - runBuilder.prepareTextBlob(font, *blob, SkPoint::Make(0, 0)); - - auto runList = runBuilder.useGlyphRunList(); - - REPORTER_ASSERT(reporter, runList->size() == runCount); - int runIndex = 0; - for (auto& run : *runList) { - REPORTER_ASSERT(reporter, run.runSize() == count); - REPORTER_ASSERT(reporter, run.uniqueSize() == count); - - int index = 0; - for (auto p : run.positions()) { - if (p.x() != runIndex * count + index) { - ERRORF(reporter, "x: %g != k: %d", p.x(), runIndex * count + index); - break; - } - index += 1; - } - - runIndex += 1; - } -}
\ No newline at end of file |