aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkGlyphRun.cpp
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 19:24:34 +0000
commitff19d3473b6099c908803fb41cd9a8a36f03a1a6 (patch)
tree5e5b619b101324e139e1914a4ba071fb5f3633a9 /src/core/SkGlyphRun.cpp
parent8b5092671b1d0802e88b5202f67ceb94c9e5d236 (diff)
Use simple buffers instead of vectors
Start using simple buffers, these will be used for multiple runs latter on. Change-Id: Iab0559d5a47eb5e54254a985051d5d25a91be69f Reviewed-on: https://skia-review.googlesource.com/140791 Commit-Queue: Herb Derby <herb@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src/core/SkGlyphRun.cpp')
-rw-r--r--src/core/SkGlyphRun.cpp73
1 files changed, 50 insertions, 23 deletions
diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp
index 87274d4def..3bd9efc90f 100644
--- a/src/core/SkGlyphRun.cpp
+++ b/src/core/SkGlyphRun.cpp
@@ -91,7 +91,7 @@ SkSpan<const SkGlyphID> SkGlyphIDSet::uniquifyGlyphIDs(
// If the following bzero becomes a performance problem, the memory can be marked as
// initialized for valgrind and msan.
// valgrind = VALGRIND_MAKE_MEM_DEFINED(fUniverseToUnique, universeSize * sizeof(SkGlyphID))
- // msan = sk_msan_assert_initialized(fUniverseToUnique, universeSize * sizeof(SkGlyphID))
+ // msan = sk_msan_mark_initialized(fUniverseToUnique, universeSize * sizeof(SkGlyphID))
sk_bzero(fUniverseToUnique, universeSize * sizeof(SkGlyphID));
}
@@ -168,10 +168,12 @@ SkGlyphRun* SkGlyphRunBuilder::useGlyphRun() {
void SkGlyphRunBuilder::initialize(size_t totalRunSize) {
fUniqueID = 0;
- // Using resize is temporary until simpler buffers are in place.
- fDenseIndex.resize(totalRunSize);
- fPositions.resize(totalRunSize);
- fUniqueGlyphIDs.resize(totalRunSize);
+ if (totalRunSize > fMaxTotalRunSize) {
+ fMaxTotalRunSize = totalRunSize;
+ fUniqueGlyphIDIndices.reset(fMaxTotalRunSize);
+ fPositions.reset(fMaxTotalRunSize);
+ fUniqueGlyphIDs.reset(fMaxTotalRunSize);
+ }
// Be sure to clean up the last run before we reuse it.
fScratchGlyphRun.~SkGlyphRun();
@@ -207,7 +209,7 @@ SkSpan<const SkGlyphID> SkGlyphRunBuilder::addDenseAndUnique(
// There better be glyphs in the font if we want to uniqify.
if (glyphUniverseSize > 0) {
uniquifiedGlyphIDs = fGlyphIDSet.uniquifyGlyphIDs(
- glyphUniverseSize, glyphIDs, fUniqueGlyphIDs.data(), fDenseIndex.data());
+ glyphUniverseSize, glyphIDs, fUniqueGlyphIDs, fUniqueGlyphIDIndices);
}
}
@@ -218,21 +220,23 @@ void SkGlyphRunBuilder::makeGlyphRun(
const SkPaint& runPaint,
SkSpan<const SkGlyphID> glyphIDs,
SkSpan<const SkPoint> positions,
+ SkSpan<const uint16_t> uniqueGlyphIDIndices,
+ SkSpan<const SkGlyphID> uniqueGlyphIDs,
SkSpan<const char> text,
SkSpan<const uint32_t> clusters) {
// Ignore empty runs.
- if (!fDenseIndex.empty()) {
+ if (!glyphIDs.empty()) {
SkPaint glyphRunPaint{runPaint};
glyphRunPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
glyphRunPaint.setTextAlign(SkPaint::kLeft_Align);
new ((void*)&fScratchGlyphRun) SkGlyphRun{
std::move(glyphRunPaint),
- SkSpan<const uint16_t>{fDenseIndex},
+ uniqueGlyphIDIndices,
positions,
glyphIDs,
- SkSpan<const SkGlyphID>{fUniqueGlyphIDs},
+ uniqueGlyphIDs,
text,
clusters
};
@@ -244,10 +248,12 @@ void SkGlyphRunBuilder::drawText(
SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
SkASSERT(!glyphIDs.empty());
+ auto runSize = glyphIDs.size();
+
auto unqiueGlyphIDs = this->addDenseAndUnique(paint, glyphIDs);
if (!unqiueGlyphIDs.empty()) {
- fScratchAdvances.resize(fUniqueGlyphIDs.size());
+ fScratchAdvances.resize(runSize);
{
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(paint);
cache->getAdvances(unqiueGlyphIDs, fScratchAdvances.data());
@@ -255,9 +261,9 @@ void SkGlyphRunBuilder::drawText(
SkPoint endOfLastGlyph = origin;
- for (size_t i = 0; i < fDenseIndex.size(); i++) {
+ for (size_t i = 0; i < runSize; i++) {
fPositions[i] = endOfLastGlyph;
- endOfLastGlyph += fScratchAdvances[fDenseIndex[i]];
+ endOfLastGlyph += fScratchAdvances[fUniqueGlyphIDIndices[i]];
}
if (paint.getTextAlign() != SkPaint::kLeft_Align) {
@@ -265,12 +271,20 @@ void SkGlyphRunBuilder::drawText(
if (paint.getTextAlign() == SkPaint::kCenter_Align) {
len.scale(SK_ScalarHalf);
}
- for (size_t i = 0; i < fDenseIndex.size(); i++) {
- fPositions[i] -= len;
+ for (auto& pt : SkSpan<SkPoint>{fPositions, runSize}) {
+ pt -= len;
}
}
- this->makeGlyphRun(paint, glyphIDs, SkSpan<const SkPoint>{fPositions}, text, clusters);
+
+ this->makeGlyphRun(
+ paint,
+ glyphIDs,
+ SkSpan<const SkPoint>{fPositions, runSize},
+ SkSpan<const uint16_t>{fUniqueGlyphIDIndices, runSize},
+ unqiueGlyphIDs,
+ text,
+ clusters);
}
}
@@ -278,6 +292,7 @@ void SkGlyphRunBuilder::drawPosTextH(const SkPaint& paint, SkSpan<const SkGlyphI
const SkScalar* xpos, SkScalar constY,
SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
SkASSERT(!glyphIDs.empty());
+ auto runSize = glyphIDs.size();
// The dense indices are not used by the rest of the stack yet.
#ifdef SK_DEBUG
@@ -286,17 +301,26 @@ void SkGlyphRunBuilder::drawPosTextH(const SkPaint& paint, SkSpan<const SkGlyphI
// TODO: when using the unique glyph system have a guard that there are actually glyphs like
// drawText above.
- for (size_t i = 0; i < fDenseIndex.size(); i++) {
- fPositions[i] = SkPoint::Make(xpos[i], constY);
+ auto posCursor = fPositions.get();
+ for (auto x : SkSpan<const SkScalar>{xpos, runSize}) {
+ *posCursor++ = SkPoint::Make(x, constY);
}
- this->makeGlyphRun(paint, glyphIDs, SkSpan<const SkPoint>{fPositions}, text, clusters);
+ this->makeGlyphRun(
+ paint,
+ glyphIDs,
+ SkSpan<const SkPoint>{fPositions, runSize},
+ SkSpan<const uint16_t>{},
+ SkSpan<const SkGlyphID>{},
+ text,
+ clusters);
}
void SkGlyphRunBuilder::drawPosText(const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs,
const SkPoint* pos,
SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
SkASSERT(!glyphIDs.empty());
+ auto runSize = glyphIDs.size();
// The dense indices are not used by the rest of the stack yet.
#ifdef SK_DEBUG
@@ -305,11 +329,14 @@ void SkGlyphRunBuilder::drawPosText(const SkPaint& paint, SkSpan<const SkGlyphID
// TODO: when using the unique glyph system have a guard that there are actually glyphs like
// drawText above.
- for (size_t i = 0; i < fDenseIndex.size(); i++) {
- fPositions[i] = pos[i];
- }
-
- this->makeGlyphRun(paint, glyphIDs, SkSpan<const SkPoint>{fPositions}, text, clusters);
+ this->makeGlyphRun(
+ paint,
+ glyphIDs,
+ SkSpan<const SkPoint>{pos, runSize},
+ SkSpan<const uint16_t>{},
+ SkSpan<const SkGlyphID>{},
+ text,
+ clusters);
}