diff options
author | Herb Derby <herb@google.com> | 2018-06-21 20:03:04 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-06-21 20:03:07 +0000 |
commit | 149b541d8889198b61cec85dcfcb85dd872eccc4 (patch) | |
tree | 221b4edf90e0985a5b5dc5630ca12231ecde3e84 /src/core/SkGlyphRun.h | |
parent | 5c0c7983bb6371c493561dbc97671e4997f822d5 (diff) |
Revert "Add SkGlyphRunList"
This reverts commit f2e4a039df33d9246bd0ec68602d4d06e6199553.
Reason for revert: Breaks asan tests
Original change's description:
> Add SkGlyphRunList
>
> Extend the glyph run system with a glyph run list. This
> allows the processing of text blobs.
>
> Add original text an cluster to runs for PDF.
>
> Change-Id: If4867d000e45f8975a30e982fc8fdbe104ef4332
> Reviewed-on: https://skia-review.googlesource.com/135627
> Reviewed-by: Ben Wagner <bungeman@google.com>
> Commit-Queue: Herb Derby <herb@google.com>
TBR=bungeman@google.com,herb@google.com
Change-Id: I903592714da901383efc7e5f47ce3dfd529e2aca
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/136761
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src/core/SkGlyphRun.h')
-rw-r--r-- | src/core/SkGlyphRun.h | 98 |
1 files changed, 34 insertions, 64 deletions
diff --git a/src/core/SkGlyphRun.h b/src/core/SkGlyphRun.h index e4676d22df..243d5d121c 100644 --- a/src/core/SkGlyphRun.h +++ b/src/core/SkGlyphRun.h @@ -24,32 +24,36 @@ template <typename T> class SkSpan { public: SkSpan() : fPtr{nullptr}, fSize{0} {} - SkSpan(T* ptr, size_t size) : fPtr{ptr}, fSize{size} {} - explicit SkSpan(std::vector<T>& v) : fPtr{v.data()}, fSize{v.size()} {} - SkSpan& operator=( const SkSpan& other ) = default; - T& operator [] (ptrdiff_t i) const { return fPtr[i]; } + SkSpan(const T* ptr, size_t size) : fPtr{ptr}, fSize{size} {} + explicit SkSpan(const std::vector<T>& v) : fPtr{v.data()}, fSize{v.size()} {} + const T& operator [] (ptrdiff_t i) const { return fPtr[i]; } T* begin() const { return fPtr; } T* end() const { return fPtr + fSize; } const T* cbegin() const { return fPtr; } const T* cend() const { return fPtr + fSize; } - T* data() const { return fPtr; } + const T* data() const { return fPtr; } ptrdiff_t size() const { return fSize; } bool empty() const { return fSize == 0; } private: - T* fPtr; + const T* fPtr; size_t fSize; }; class SkGlyphRun { public: SkGlyphRun() = default; - SkGlyphRun(SkSpan<uint16_t> denseIndex, - SkSpan<SkPoint> positions, - SkSpan<SkGlyphID> scratchGlyphs, - SkSpan<SkGlyphID> uniqueGlyphIDs, - SkSpan<const char> text, - SkSpan<uint32_t> clusters); + SkGlyphRun(SkSpan<uint16_t> denseIndex, + SkSpan<SkPoint> positions, + SkSpan<SkGlyphID> scratchGlyphs, + SkSpan<SkGlyphID> uniqueGlyphIDs) + : fDenseIndex{denseIndex} + , fPositions{positions} + , fTemporaryShuntGlyphIDs{scratchGlyphs} + , fUniqueGlyphIDs{uniqueGlyphIDs} { + SkASSERT(denseIndex.size() == positions.size()); + SkASSERT(denseIndex.size() == scratchGlyphs.size()); + } // The temporaryShunt calls are to allow inter-operating with existing code while glyph runs // are developed. @@ -63,33 +67,13 @@ public: private: // Indices into the unique glyph IDs. On for each original glyph. - const SkSpan<uint16_t> fDenseIndex; + const SkSpan<uint16_t> fDenseIndex; // The base line position of all the glyphs in source space. - const SkSpan<SkPoint> fPositions; + const SkSpan<SkPoint> fPositions; // This is temporary while converting from the old per glyph code to the bulk code. - const SkSpan<SkGlyphID> fTemporaryShuntGlyphIDs; + const SkSpan<SkGlyphID> fTemporaryShuntGlyphIDs; // The set of unique glyphs in the run. - const SkSpan<SkGlyphID> fUniqueGlyphIDs; - // Original text from SkTextBlob if present. Will be empty of not present. - const SkSpan<const char> fText; - // Original clusters from SkTextBlob if present. Will be empty if not present. - 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]; } + const SkSpan<SkGlyphID> fUniqueGlyphIDs; }; // A faster set implementation that does not need any initialization, and reading the set items @@ -108,6 +92,10 @@ private: std::vector<SkGlyphID>* fUniqueGlyphIDs{nullptr}; }; +// Currently the old code is passing around SkGlyphRunBuilder because it facilitates working in the +// old single glyph lookup style with the cache. When the lower level code is transitioned over to +// the bulk glyph cache style, then the builder will only be used in the canvas, and only runs will +// be passed around. class SkGlyphRunBuilder { public: SkGlyphRunBuilder() = default; @@ -118,50 +106,32 @@ public: const SkScalar xpos[], SkScalar constY); void prepareDrawPosText( const SkPaint& paint, const void* bytes, size_t byteLength, const SkPoint pos[]); - void prepareTextBlob(const SkPaint& paint, const SkTextBlob& blob, SkPoint origin); - SkGlyphRunList* useGlyphRunList(); + size_t runSize() const {return fDenseIndex.size();} + size_t uniqueSize() const {return fUniqueGlyphs.size();} + SkGlyphRun* useGlyphRun(); private: - size_t runSize() const; - size_t uniqueSize() const; - void initialize(); - SkGlyphID* addDenseAndUnique(const SkPaint& paint, const void* bytes, size_t byteLength); - void addGlyphRunToList( - SkGlyphID* temporaryShuntGlyphIDs, SkSpan<const char> text, SkSpan<uint32_t> clusters); - - void drawText( - const SkPaint& paint, const void* bytes, size_t byteLength, SkPoint origin, - SkSpan<const char> text, SkSpan<uint32_t> clusters); - void drawPosTextH( - const SkPaint& paint, const void* bytes, size_t byteLength, - const SkScalar* xpos, SkScalar constY, - SkSpan<const char> text, SkSpan<uint32_t> clusters); - void drawPosText( - const SkPaint& paint, const void* bytes, size_t byteLength, const SkPoint* pos, - SkSpan<const char> text, SkSpan<uint32_t> clusters); - - uint64_t fUniqueID{0}; + void initializeDenseAndUnique(const SkPaint& paint, const void* bytes, size_t byteLength); std::vector<uint16_t> fDenseIndex; std::vector<SkPoint> fPositions; std::vector<SkGlyphID> fUniqueGlyphs; - size_t fLastDenseIndex{0}; - size_t fLastUniqueIndex{0}; - // Used as a temporary for preparing using utfN text. std::vector<SkGlyphID> fScratchGlyphIDs; // 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 to temporarily use of a glyph run for bulk cache API calls (just an experiment at + // this point). + SkGlyphRun fScratchGlyphRun; - // Used as temporary glyph run for the rest of the Text stack. - SkGlyphRunList fScratchGlyphRunList; + // Used as an aid to shunt from glyph runs to drawPosText. It will either be fScratchIDs or + // the bytes passed in. + const SkGlyphID* fTemporaryShuntGlyphIDs{nullptr}; // Used for collecting the set of unique glyphs. SkGlyphSet fGlyphSet; |