Reduce use of path generation
Since the prepare for draw generates a path when needed,
a lighter weight hasPath() can be used. The generatePath
only needs to be used until the bitmap device
path ARGB fallback is worked out.
Change-Id: I4b2c6d7907e0f818078841caa166a58a0a989827
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/208510
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/src/core/SkGlyph.h b/src/core/SkGlyph.h
index 812b1c2..3d4cc9b 100644
--- a/src/core/SkGlyph.h
+++ b/src/core/SkGlyph.h
@@ -165,6 +165,16 @@
return fPathData != nullptr && fPathData->fHasPath ? &fPathData->fPath : nullptr;
}
+ bool hasPath() const {
+ // Need to have called getMetrics before calling findPath.
+ SkASSERT(fMaskFormat != MASK_FORMAT_UNKNOWN);
+
+ // Find path must have been called to use this call.
+ SkASSERT(fPathData != nullptr);
+
+ return fPathData != nullptr && fPathData->fHasPath;
+ }
+
int maxDimension() const {
// width and height are only defined if a metrics call was made.
SkASSERT(fMaskFormat != MASK_FORMAT_UNKNOWN);
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index 2708d6c..494da88 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -191,17 +191,15 @@
if (check_glyph_position(position)
&& !glyph.isEmpty()
&& glyph.fMaskFormat != SkMask::kARGB32_Format
- && strike->decideCouldDrawFromPath(glyph))
+ && glyph.hasPath())
{
// Only draw a path if it exists, and this is not a color glyph.
pathsAndPositions.push_back(SkPathPos{glyph.path(), position});
} else {
// TODO: this is here to have chrome layout tests pass. Remove this when
// fallback for CPU works.
- if (check_glyph_position(position)
- && !glyph.isEmpty()
- && strike->decideCouldDrawFromPath(glyph))
- {
+ strike->generatePath(glyph);
+ if (check_glyph_position(position) && !glyph.isEmpty() && glyph.hasPath()) {
pathsAndPositions.push_back(SkPathPos{glyph.path(), position});
}
}
@@ -452,8 +450,7 @@
&& glyph.maxDimension() <= SkStrikeCommon::kSkSideTooBigForAtlas) {
// SDF mask will work.
fGlyphPos[glyphsWithMaskCount++] = glyphPos;
- } else if (glyph.fMaskFormat != SkMask::kARGB32_Format
- && strike->decideCouldDrawFromPath(glyph)) {
+ } else if (glyph.fMaskFormat != SkMask::kARGB32_Format && glyph.hasPath()) {
// If not color but too big, use a path.
fPaths.push_back(glyphPos);
} else {
@@ -529,8 +526,7 @@
SkPoint position = glyphPos.position;
if (glyph.isEmpty()) {
// do nothing
- } else if (glyph.fMaskFormat != SkMask::kARGB32_Format
- && strike->decideCouldDrawFromPath(glyph)) {
+ } else if (glyph.fMaskFormat != SkMask::kARGB32_Format && glyph.hasPath()) {
// Place paths in fGlyphPos
fGlyphPos[glyphsWithPathCount++] = glyphPos;
} else {
@@ -592,8 +588,7 @@
if (glyph.maxDimension() <= SkStrikeCommon::kSkSideTooBigForAtlas) {
fGlyphPos[glyphsWithMaskCount++] = glyphPos;
- } else if (glyph.fMaskFormat != SkMask::kARGB32_Format
- && strike->decideCouldDrawFromPath(glyph)) {
+ } else if (glyph.fMaskFormat != SkMask::kARGB32_Format && glyph.hasPath()) {
fPaths.push_back(glyphPos);
} else {
addFallback(glyph, origin + glyphRun.positions()[glyphPos.index]);
diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp
index 8b4cdac..7bcb29a 100644
--- a/src/core/SkRemoteGlyphCache.cpp
+++ b/src/core/SkRemoteGlyphCache.cpp
@@ -575,7 +575,7 @@
//
// A key reason for no path is the fact that the glyph is a color image or is a bitmap only
// font.
-bool SkStrikeServer::SkGlyphCacheState::decideCouldDrawFromPath(const SkGlyph& glyph) {
+void SkStrikeServer::SkGlyphCacheState::generatePath(const SkGlyph& glyph) {
// Check to see if we have processed this glyph for a path before.
if (glyph.fPathData == nullptr) {
@@ -587,11 +587,8 @@
// A path was added make sure to send it to the GPU.
fCachedGlyphPaths.add(glyph.getPackedID());
fPendingGlyphPaths.push_back(glyph.getPackedID());
- return true;
}
}
-
- return glyph.path() != nullptr;
}
void SkStrikeServer::SkGlyphCacheState::writeGlyphPath(const SkPackedGlyphID& glyphID,
diff --git a/src/core/SkRemoteGlyphCacheImpl.h b/src/core/SkRemoteGlyphCacheImpl.h
index 1d7c9ba..31c8a69 100644
--- a/src/core/SkRemoteGlyphCacheImpl.h
+++ b/src/core/SkRemoteGlyphCacheImpl.h
@@ -49,7 +49,7 @@
int maxDimension,
SkGlyphPos results[]) override;
- bool decideCouldDrawFromPath(const SkGlyph& glyph) override;
+ void generatePath(const SkGlyph& glyph) override;
void onAboutToExitScope() override {}
diff --git a/src/core/SkStrike.cpp b/src/core/SkStrike.cpp
index f7919d3..e248e6f 100644
--- a/src/core/SkStrike.cpp
+++ b/src/core/SkStrike.cpp
@@ -450,8 +450,8 @@
SkDebugf("%s\n", msg.c_str());
}
-bool SkStrike::decideCouldDrawFromPath(const SkGlyph& glyph) {
- return !glyph.isEmpty() && this->findPath(glyph) != nullptr;
+void SkStrike::generatePath(const SkGlyph& glyph) {
+ if (!glyph.isEmpty()) { this->findPath(glyph); }
}
void SkStrike::onAboutToExitScope() { }
diff --git a/src/core/SkStrike.h b/src/core/SkStrike.h
index 76b2fae..194f029 100644
--- a/src/core/SkStrike.h
+++ b/src/core/SkStrike.h
@@ -126,7 +126,7 @@
const SkGlyph& getGlyphMetrics(SkGlyphID glyphID, SkPoint position) override;
- bool decideCouldDrawFromPath(const SkGlyph& glyph) override;
+ void generatePath(const SkGlyph& glyph) override;
const SkDescriptor& getDescriptor() const override;
diff --git a/src/core/SkStrikeCache.cpp b/src/core/SkStrikeCache.cpp
index 02ff8af..a20527c 100644
--- a/src/core/SkStrikeCache.cpp
+++ b/src/core/SkStrikeCache.cpp
@@ -44,8 +44,8 @@
return fStrike.prepareForDrawing(glyphIDs, positions, n, maxDimension, results);
}
- bool decideCouldDrawFromPath(const SkGlyph& glyph) override {
- return fStrike.decideCouldDrawFromPath(glyph);
+ void generatePath(const SkGlyph& glyph) override {
+ fStrike.generatePath(glyph);
}
const SkDescriptor& getDescriptor() const override {
diff --git a/src/core/SkStrikeInterface.h b/src/core/SkStrikeInterface.h
index 9c52c36..6598911 100644
--- a/src/core/SkStrikeInterface.h
+++ b/src/core/SkStrikeInterface.h
@@ -82,7 +82,8 @@
SkGlyphPos results[]) = 0;
virtual const SkGlyph& getGlyphMetrics(SkGlyphID glyphID, SkPoint position) = 0;
- virtual bool decideCouldDrawFromPath(const SkGlyph& glyph) = 0;
+ // TODO: Deprecated. Do not use. Remove when ARGB fallback for bitmap device paths is working.
+ virtual void generatePath(const SkGlyph& glyph) = 0;
virtual void onAboutToExitScope() = 0;
struct Deleter {