aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/core/SkGlyphCache.cpp6
-rw-r--r--src/core/SkGlyphRun.cpp72
-rw-r--r--src/core/SkGlyphRun.h19
-rw-r--r--src/core/SkStrikeCache.cpp1
-rw-r--r--tests/GlyphRunTest.cpp2
5 files changed, 35 insertions, 65 deletions
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 30f7def312..61e01af894 100644
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -131,9 +131,9 @@ const SkGlyph& SkGlyphCache::getGlyphIDMetrics(uint16_t glyphID, SkFixed x, SkFi
}
void SkGlyphCache::getAdvances(SkSpan<const SkGlyphID> glyphIDs, SkPoint advances[]) {
- for (auto glyphID : glyphIDs) {
- auto glyph = this->getGlyphIDAdvance(glyphID);
- *advances++ = SkPoint::Make(glyph.fAdvanceX, glyph.fAdvanceY);
+ for (ptrdiff_t i = 0; i < glyphIDs.size(); i++) {
+ auto glyph = this->getGlyphIDAdvance(glyphIDs[i]);
+ advances[i] = SkPoint::Make(glyph.fAdvanceX, glyph.fAdvanceY);
}
}
diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp
index 85de9ba197..6791cf3ab2 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_mark_initialized(fUniverseToUnique, universeSize * sizeof(SkGlyphID))
+ // msan = sk_msan_assert_initialized(fUniverseToUnique, universeSize * sizeof(SkGlyphID))
sk_bzero(fUniverseToUnique, universeSize * sizeof(SkGlyphID));
}
@@ -166,12 +166,10 @@ SkGlyphRun* SkGlyphRunBuilder::useGlyphRun() {
void SkGlyphRunBuilder::initialize(size_t totalRunSize) {
fUniqueID = 0;
- if (totalRunSize > fMaxTotalRunSize) {
- fMaxTotalRunSize = totalRunSize;
- fUniqueGlyphIDIndices.reset(fMaxTotalRunSize);
- fPositions.reset(fMaxTotalRunSize);
- fUniqueGlyphIDs.reset(fMaxTotalRunSize);
- }
+ // Using resize is temporary until simpler buffers are in place.
+ fDenseIndex.resize(totalRunSize);
+ fPositions.resize(totalRunSize);
+ fUniqueGlyphIDs.resize(totalRunSize);
// Be sure to clean up the last run before we reuse it.
fScratchGlyphRun.~SkGlyphRun();
@@ -205,7 +203,7 @@ SkSpan<const SkGlyphID> SkGlyphRunBuilder::addDenseAndUnique(
auto typeface = SkPaintPriv::GetTypefaceOrDefault(paint);
auto glyphUniverseSize = typeface->countGlyphs();
uniquifiedGlyphIDs = fGlyphIDSet.uniquifyGlyphIDs(
- glyphUniverseSize, glyphIDs, fUniqueGlyphIDs, fUniqueGlyphIDIndices);
+ glyphUniverseSize, glyphIDs, fUniqueGlyphIDs.data(), fDenseIndex.data());
}
return uniquifiedGlyphIDs;
@@ -215,23 +213,21 @@ 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 (!glyphIDs.empty()) {
+ if (!fDenseIndex.empty()) {
SkPaint glyphRunPaint{runPaint};
glyphRunPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
glyphRunPaint.setTextAlign(SkPaint::kLeft_Align);
new ((void*)&fScratchGlyphRun) SkGlyphRun{
std::move(glyphRunPaint),
- uniqueGlyphIDIndices,
+ SkSpan<const uint16_t>{fDenseIndex},
positions,
glyphIDs,
- uniqueGlyphIDs,
+ SkSpan<const SkGlyphID>{fUniqueGlyphIDs},
text,
clusters
};
@@ -242,11 +238,9 @@ void SkGlyphRunBuilder::drawText(
const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs, SkPoint origin,
SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
- auto runSize = glyphIDs.size();
-
auto unqiueGlyphIDs = this->addDenseAndUnique(paint, glyphIDs);
- fScratchAdvances.resize(runSize);
+ fScratchAdvances.resize(fUniqueGlyphIDs.size());
{
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(paint);
cache->getAdvances(unqiueGlyphIDs, fScratchAdvances.data());
@@ -254,9 +248,9 @@ void SkGlyphRunBuilder::drawText(
SkPoint endOfLastGlyph = origin;
- for (size_t i = 0; i < runSize; i++) {
+ for (size_t i = 0; i < fDenseIndex.size(); i++) {
fPositions[i] = endOfLastGlyph;
- endOfLastGlyph += fScratchAdvances[fUniqueGlyphIDIndices[i]];
+ endOfLastGlyph += fScratchAdvances[fDenseIndex[i]];
}
if (paint.getTextAlign() != SkPaint::kLeft_Align) {
@@ -264,64 +258,44 @@ void SkGlyphRunBuilder::drawText(
if (paint.getTextAlign() == SkPaint::kCenter_Align) {
len.scale(SK_ScalarHalf);
}
- for (auto& pt : SkSpan<SkPoint>{fPositions, runSize}) {
- pt -= len;
+ for (size_t i = 0; i < fDenseIndex.size(); i++) {
+ fPositions[i] -= len;
}
}
- this->makeGlyphRun(
- paint,
- glyphIDs,
- SkSpan<const SkPoint>{fPositions, runSize},
- SkSpan<const uint16_t>{fUniqueGlyphIDIndices, runSize},
- unqiueGlyphIDs,
- text,
- clusters);
+ this->makeGlyphRun(paint, glyphIDs, SkSpan<const SkPoint>{fPositions}, text, clusters);
}
void SkGlyphRunBuilder::drawPosTextH(const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs,
const SkScalar* xpos, SkScalar constY,
SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
- auto runSize = glyphIDs.size();
// The dense indices are not used by the rest of the stack yet.
#ifdef SK_DEBUG
this->addDenseAndUnique(paint, glyphIDs);
#endif
- auto posCursor = fPositions.get();
- for (auto x : SkSpan<const SkScalar>{xpos, runSize}) {
- *posCursor++ = SkPoint::Make(x, constY);
+ for (size_t i = 0; i < fDenseIndex.size(); i++) {
+ fPositions[i] = SkPoint::Make(xpos[i], constY);
}
- this->makeGlyphRun(
- paint,
- glyphIDs,
- SkSpan<const SkPoint>{fPositions, runSize},
- SkSpan<const uint16_t>{},
- SkSpan<const SkGlyphID>{},
- text,
- clusters);
+ this->makeGlyphRun(paint, glyphIDs, SkSpan<const SkPoint>{fPositions}, text, clusters);
}
void SkGlyphRunBuilder::drawPosText(const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs,
const SkPoint* pos,
SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
- auto runSize = glyphIDs.size();
// The dense indices are not used by the rest of the stack yet.
#ifdef SK_DEBUG
this->addDenseAndUnique(paint, glyphIDs);
#endif
- this->makeGlyphRun(
- paint,
- glyphIDs,
- SkSpan<const SkPoint>{pos, runSize},
- SkSpan<const uint16_t>{},
- SkSpan<const SkGlyphID>{},
- text,
- clusters);
+ for (size_t i = 0; i < fDenseIndex.size(); i++) {
+ fPositions[i] = pos[i];
+ }
+
+ this->makeGlyphRun(paint, glyphIDs, SkSpan<const SkPoint>{fPositions}, text, clusters);
}
diff --git a/src/core/SkGlyphRun.h b/src/core/SkGlyphRun.h
index affc044f76..7c3a74860c 100644
--- a/src/core/SkGlyphRun.h
+++ b/src/core/SkGlyphRun.h
@@ -24,23 +24,23 @@ template <typename T>
class SkSpan {
public:
SkSpan() : fPtr{nullptr}, fSize{0} {}
- SkSpan(T* ptr, size_t size) : fPtr{ptr}, fSize{size} { }
+ SkSpan(T* ptr, ptrdiff_t size) : fPtr{ptr}, fSize{size} { SkASSERT(size >= 0); }
template <typename U>
- explicit SkSpan(std::vector<U>& v) : fPtr{v.data()}, fSize{v.size()} {}
+ explicit SkSpan(std::vector<U>& v) : fPtr{v.data()}, fSize{SkTo<ptrdiff_t>(v.size())} {}
SkSpan(const SkSpan<T>& o) = default;
SkSpan& operator=( const SkSpan& other ) = default;
- T& operator [] (size_t i) const { return fPtr[i]; }
+ 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; }
- size_t size() const { return fSize; }
+ ptrdiff_t size() const { return fSize; }
bool empty() const { return fSize == 0; }
private:
T* fPtr;
- size_t fSize;
+ ptrdiff_t fSize;
};
class SkGlyphRun {
@@ -120,8 +120,6 @@ private:
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);
@@ -138,10 +136,9 @@ private:
uint64_t fUniqueID{0};
- size_t fMaxTotalRunSize{0};
- SkAutoTMalloc<uint16_t> fUniqueGlyphIDIndices;
- SkAutoTMalloc<SkPoint> fPositions;
- SkAutoTMalloc<SkGlyphID> fUniqueGlyphIDs;
+ std::vector<uint16_t> fDenseIndex;
+ std::vector<SkPoint> fPositions;
+ std::vector<SkGlyphID> fUniqueGlyphIDs;
// 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.
diff --git a/src/core/SkStrikeCache.cpp b/src/core/SkStrikeCache.cpp
index 47b3c9bf8b..94f8c6d8bd 100644
--- a/src/core/SkStrikeCache.cpp
+++ b/src/core/SkStrikeCache.cpp
@@ -12,7 +12,6 @@
#include "SkGlyphCache.h"
#include "SkGraphics.h"
#include "SkMutex.h"
-#include "SkTemplates.h"
#include "SkTraceMemoryDump.h"
#include "SkTypeface.h"
#include "SkPaintPriv.h"
diff --git a/tests/GlyphRunTest.cpp b/tests/GlyphRunTest.cpp
index 7ec14240e7..0e0c441b75 100644
--- a/tests/GlyphRunTest.cpp
+++ b/tests/GlyphRunTest.cpp
@@ -24,7 +24,7 @@ DEF_TEST(GlyphRunGlyphIDSetBasic, reporter) {
std::vector<SkGlyphID> test{uniqueGlyphIDs.begin(), uniqueGlyphIDs.end()};
std::sort(test.begin(), test.end());
auto newEnd = std::unique(test.begin(), test.end());
- REPORTER_ASSERT(reporter, uniqueGlyphIDs.size() == (size_t)(newEnd - test.begin()));
+ REPORTER_ASSERT(reporter, uniqueGlyphIDs.size() == newEnd - test.begin());
REPORTER_ASSERT(reporter, uniqueGlyphIDs.size() == 4);
{
uint16_t answer[] = {0, 1, 2, 1, 3};