aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkGlyphRun.h
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-07-09 17:06:09 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-12 05:47:37 +0000
commitfd77fe5d06150b6be17d159f470b5d0f79ceb139 (patch)
tree29a8cc9b630f894dade2619bf1812141d49b4348 /src/core/SkGlyphRun.h
parent2c312c4f58f9c151acab8ca2dd0d39fb77c5e74a (diff)
Use new SkGlyphIDSet - v3
v1 - had problems with msan and unintialized glyphs. v2 - had problems with typefaces with no glyphs in them This adds a check to make sure there are glyphs in the font when going to uniquify. Change-Id: Id27fa4578be33da1e468b4652db19740ddcadfc6 Reviewed-on: https://skia-review.googlesource.com/140785 Commit-Queue: Herb Derby <herb@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src/core/SkGlyphRun.h')
-rw-r--r--src/core/SkGlyphRun.h51
1 files changed, 24 insertions, 27 deletions
diff --git a/src/core/SkGlyphRun.h b/src/core/SkGlyphRun.h
index 7788376c70..7c3a74860c 100644
--- a/src/core/SkGlyphRun.h
+++ b/src/core/SkGlyphRun.h
@@ -83,26 +83,14 @@ private:
const SkPaint fRunPaint;
};
-// 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
-// for Sparse Sets"
-//
-// This implementation assumes that the unique glyphs added are appended to a vector that may
-// already have unique glyph from a previous computation. This allows the packing of multiple
-// UniqueID sequences in a single vector.
-class SkGlyphSet {
+class SkGlyphIDSet {
public:
- SkGlyphSet() = default;
- uint16_t add(SkGlyphID glyphID);
- void reuse(uint32_t glyphUniverseSize, std::vector<SkGlyphID>* uniqueGlyphIDs);
-
+ SkSpan<const SkGlyphID> uniquifyGlyphIDs(
+ uint32_t universeSize, SkSpan<const SkGlyphID> glyphIDs,
+ SkGlyphID* uniqueGlyphIDs, uint16_t* denseindices);
private:
- uint32_t uniqueSize();
- uint32_t fUniverseSize{0};
- size_t fStartOfUniqueIDs{0};
- std::vector<uint16_t> fIndices;
- std::vector<SkGlyphID>* fUniqueGlyphIDs{nullptr};
+ size_t fUniverseToUniqueSize{0};
+ SkAutoTMalloc<uint16_t> fUniverseToUnique;
};
class SkGlyphRunBuilder {
@@ -115,25 +103,35 @@ 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);
SkGlyphRun* useGlyphRun();
private:
- void initialize();
- void addDenseAndUnique(const SkPaint& paint, const void* bytes, size_t byteLength);
+ void initialize(size_t totalRunSize);
+ SkSpan<const SkGlyphID> textToGlyphIDs(
+ const SkPaint& paint, const void* bytes, size_t byteLength);
+
+ // Returns the span of unique glyph IDs.
+ SkSpan<const SkGlyphID> addDenseAndUnique(
+ const SkPaint& paint,
+ SkSpan<const SkGlyphID> glyphIDs);
+
void makeGlyphRun(
- const SkPaint& runPaint, SkSpan<const char> text, SkSpan<const uint32_t> clusters);
+ const SkPaint& runPaint,
+ SkSpan<const SkGlyphID> glyphIDs,
+ SkSpan<const SkPoint> positions,
+ SkSpan<const char> text,
+ SkSpan<const uint32_t> clusters);
void drawText(
- const SkPaint& paint, const void* bytes, size_t byteLength, SkPoint origin,
+ const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs, SkPoint origin,
SkSpan<const char> text, SkSpan<const uint32_t> clusters);
void drawPosTextH(
- const SkPaint& paint, const void* bytes, size_t byteLength,
+ const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs,
const SkScalar* xpos, SkScalar constY,
SkSpan<const char> text, SkSpan<const uint32_t> clusters);
void drawPosText(
- const SkPaint& paint, const void* bytes, size_t byteLength, const SkPoint* pos,
+ const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs, const SkPoint* pos,
SkSpan<const char> text, SkSpan<const uint32_t> clusters);
uint64_t fUniqueID{0};
@@ -141,7 +139,6 @@ private:
std::vector<uint16_t> fDenseIndex;
std::vector<SkPoint> fPositions;
std::vector<SkGlyphID> fUniqueGlyphIDs;
- SkGlyphID* fGlyphIDs{nullptr};
// Used as a temporary for preparing using utfN text. This implies that only one run of
// glyph ids will ever be needed because blobs are already glyph based.
@@ -155,7 +152,7 @@ private:
SkGlyphRun fScratchGlyphRun;
// Used for collecting the set of unique glyphs.
- SkGlyphSet fGlyphSet;
+ SkGlyphIDSet fGlyphIDSet;
};
#endif // SkGlyphRunInfo_DEFINED