change params to getPaths callback, avoiding a xform/copy up front.
Before
18/18 MB 1 33.1µs 33.3µs 33.4µs 34.2µs 1% █▄▃▂▂▁▁▁▁▂ nonrendering font-path-batch
18/18 MB 12 43.7µs 43.8µs 43.8µs 44.1µs 0% █▂▁▂▁▅▂▂▆▂ nonrendering font-path-loop
After
17/17 MB 1 10.2µs 10.3µs 10.4µs 11µs 2% █▃▂▂▂▂▂▁▁▂ nonrendering font-path-batch
17/17 MB 21 23.4µs 23.4µs 23.4µs 23.4µs 0% █▂▁▃▃▂▄▁▂▂ nonrendering font-path-loop
Bug: skia:
Change-Id: Ib1aa886fd675326bf5936b47b0d459ba02f1681e
Reviewed-on: https://skia-review.googlesource.com/c/172743
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/bench/FontCacheBench.cpp b/bench/FontCacheBench.cpp
index 98caa2b..beae47a 100644
--- a/bench/FontCacheBench.cpp
+++ b/bench/FontCacheBench.cpp
@@ -184,9 +184,9 @@
}
} else {
fFont.getPaths(fGlyphs, SK_ARRAY_COUNT(fGlyphs),
- [](uint16_t, const SkPath* src, void* ctx) {
+ [](const SkPath* src, const SkMatrix& mx, void* ctx) {
if (src) {
- *static_cast<SkPath*>(ctx) = *src;
+ src->transform(mx, static_cast<SkPath*>(ctx));
}
}, &path);
}
diff --git a/include/core/SkFont.h b/include/core/SkFont.h
index d8f7b53..ded498a 100644
--- a/include/core/SkFont.h
+++ b/include/core/SkFont.h
@@ -12,6 +12,7 @@
#include "SkScalar.h"
#include "SkTypeface.h"
+class SkMatrix;
class SkPaint;
class SkPath;
struct SkFontMetrics;
@@ -376,7 +377,7 @@
@param ctx function context
*/
void getPaths(const uint16_t glyphIDs[], int count,
- void (*glyphPathProc)(uint16_t glyphID, const SkPath* pathOrNull, void* ctx),
+ void (*glyphPathProc)(const SkPath* pathOrNull, const SkMatrix& mx, void* ctx),
void* ctx) const;
/** Returns SkFontMetrics associated with SkTypeface.
diff --git a/src/core/SkFont.cpp b/src/core/SkFont.cpp
index 6c3949b..9f2b166 100644
--- a/src/core/SkFont.cpp
+++ b/src/core/SkFont.cpp
@@ -359,22 +359,19 @@
}
void SkFont::getPaths(const uint16_t glyphs[], int count,
- void (*proc)(uint16_t, const SkPath*, void*), void* ctx) const {
+ void (*proc)(const SkPath*, const SkMatrix&, void*), void* ctx) const {
SkFont font(*this);
SkScalar scale = font.setupForAsPaths(nullptr);
+ if (!scale) {
+ scale = 1;
+ }
+ const SkMatrix mx = SkMatrix::MakeScale(scale, scale);
auto exclusive = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font);
auto cache = exclusive.get();
for (int i = 0; i < count; ++i) {
- const SkPath* orig = cache->findPath(cache->getGlyphIDMetrics(glyphs[i]));
- if (orig && scale) {
- SkPath tmp;
- orig->transform(SkMatrix::MakeScale(scale, scale), &tmp);
- proc(glyphs[i], &tmp, ctx);
- } else {
- proc(glyphs[i], orig, ctx);
- }
+ proc(cache->findPath(cache->getGlyphIDMetrics(glyphs[i])), mx, ctx);
}
}
@@ -384,10 +381,10 @@
bool fWasSet;
} pair = { path, false };
- this->getPaths(&glyphID, 1, [](uint16_t, const SkPath* orig, void* ctx) {
+ this->getPaths(&glyphID, 1, [](const SkPath* orig, const SkMatrix& mx, void* ctx) {
Pair* pair = static_cast<Pair*>(ctx);
if (orig) {
- *pair->fPath = *orig;
+ orig->transform(mx, pair->fPath);
pair->fWasSet = true;
}
}, &pair);
diff --git a/src/core/SkPaint_text.cpp b/src/core/SkPaint_text.cpp
index 2a76e6e..a43c46e 100644
--- a/src/core/SkPaint_text.cpp
+++ b/src/core/SkPaint_text.cpp
@@ -495,10 +495,12 @@
SkPath* fDst;
const SkPoint* fPos;
};
-static void PathPosProc(uint16_t, const SkPath* src, void* ctx) {
+static void PathPosProc(const SkPath* src, const SkMatrix& mx, void* ctx) {
PathPosRec* rec = static_cast<PathPosRec*>(ctx);
if (src) {
- rec->fDst->addPath(*src, SkMatrix::MakeTrans(rec->fPos->fX, rec->fPos->fY));
+ SkMatrix m(mx);
+ m.postTranslate(rec->fPos->fX, rec->fPos->fY);
+ rec->fDst->addPath(*src, m);
}
rec->fPos += 1;
}