diff options
Diffstat (limited to 'src/core/SkGlyphRun.h')
-rw-r--r-- | src/core/SkGlyphRun.h | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/src/core/SkGlyphRun.h b/src/core/SkGlyphRun.h index eeb9c2924e..243d5d121c 100644 --- a/src/core/SkGlyphRun.h +++ b/src/core/SkGlyphRun.h @@ -23,13 +23,17 @@ class SkBaseDevice; template <typename T> class SkSpan { public: - SkSpan() = default; + SkSpan() : fPtr{nullptr}, fSize{0} {} 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]; } - const T* begin() const { return fPtr; } - const T* end() const { return fPtr + fSize; } + T* begin() const { return fPtr; } + T* end() const { return fPtr + fSize; } + const T* cbegin() const { return fPtr; } + const T* cend() const { return fPtr + fSize; } + const T* data() const { return fPtr; } ptrdiff_t size() const { return fSize; } + bool empty() const { return fSize == 0; } private: const T* fPtr; @@ -39,20 +43,37 @@ private: class SkGlyphRun { public: SkGlyphRun() = default; - SkGlyphRun(SkSpan<uint16_t> denseIndex, SkSpan<SkPoint> positions, + SkGlyphRun(SkSpan<uint16_t> denseIndex, + SkSpan<SkPoint> positions, + SkSpan<SkGlyphID> scratchGlyphs, SkSpan<SkGlyphID> uniqueGlyphIDs) : fDenseIndex{denseIndex} , fPositions{positions} - , fUniqueGlyphIDs{uniqueGlyphIDs} {} + , 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. + void temporaryShuntToDrawPosText(const SkPaint& paint, SkBaseDevice* device); + using TemporaryShuntCallback = std::function<void(size_t, const char*, const SkScalar*)>; + void temporaryShuntToCallback(TemporaryShuntCallback callback); size_t runSize() const { return fDenseIndex.size(); } uint16_t uniqueSize() const { return fUniqueGlyphIDs.size(); } SkSpan<SkPoint> positions() const { return SkSpan<SkPoint>(fPositions); } private: - SkSpan<uint16_t> fDenseIndex; - SkSpan<SkPoint> fPositions; - SkSpan<SkGlyphID> fUniqueGlyphIDs; + // Indices into the unique glyph IDs. On for each original glyph. + const SkSpan<uint16_t> fDenseIndex; + // The base line position of all the glyphs in source space. + const SkSpan<SkPoint> fPositions; + // This is temporary while converting from the old per glyph code to the bulk code. + const SkSpan<SkGlyphID> fTemporaryShuntGlyphIDs; + // The set of unique glyphs in the run. + const SkSpan<SkGlyphID> fUniqueGlyphIDs; }; // A faster set implementation that does not need any initialization, and reading the set items @@ -89,13 +110,7 @@ public: size_t runSize() const {return fDenseIndex.size();} size_t uniqueSize() const {return fUniqueGlyphs.size();} - const SkGlyphRun& useGlyphRun() const; - - // The temporaryShunt calls are to allow inter-operating with existing code while glyph runs - // are developed. - void temporaryShuntToDrawPosText(const SkPaint& paint, SkBaseDevice* device); - using TemporaryShuntCallback = std::function<void(size_t, const char*, const SkScalar*)>; - void temporaryShuntToCallback(TemporaryShuntCallback callback); + SkGlyphRun* useGlyphRun(); private: void initializeDenseAndUnique(const SkPaint& paint, const void* bytes, size_t byteLength); @@ -119,7 +134,7 @@ private: const SkGlyphID* fTemporaryShuntGlyphIDs{nullptr}; // Used for collecting the set of unique glyphs. - SkGlyphSet fGlyphSet; + SkGlyphSet fGlyphSet; }; #endif // SkGlyphRunInfo_DEFINED |