Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7ad393e

Browse files
RusinoSkia Commit-Bot
authored andcommitted
Fix placeholders in cache
Change-Id: I36d488aa7a554131b8e524beeabc4ca9f5777591 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/267696 Reviewed-by: Ben Wagner <[email protected]> Commit-Queue: Julia Lavrova <[email protected]>
1 parent 7c1142d commit 7ad393e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

modules/skparagraph/src/ParagraphCache.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,18 @@ uint32_t ParagraphCache::KeyHash::mix(uint32_t hash, uint32_t data) const {
5656
uint32_t ParagraphCache::KeyHash::operator()(const ParagraphCacheKey& key) const {
5757
uint32_t hash = 0;
5858
for (auto& ph : key.fPlaceholders) {
59+
if (&ph == &key.fPlaceholders.back()) {
60+
// Skip the last "dummy" placeholder
61+
break;
62+
}
5963
hash = mix(hash, SkGoodHash()(ph.fRange.start));
6064
hash = mix(hash, SkGoodHash()(ph.fRange.end));
6165
hash = mix(hash, SkGoodHash()(relax(ph.fStyle.fBaselineOffset)));
6266
hash = mix(hash, SkGoodHash()(ph.fStyle.fBaseline));
6367
hash = mix(hash, SkGoodHash()(ph.fStyle.fAlignment));
68+
if (ph.fStyle.fAlignment == PlaceholderAlignment::kBaseline) {
69+
hash = mix(hash, SkGoodHash()(relax(ph.fStyle.fBaselineOffset)));
70+
}
6471
hash = mix(hash, SkGoodHash()(relax(ph.fStyle.fHeight)));
6572
hash = mix(hash, SkGoodHash()(relax(ph.fStyle.fWidth)));
6673
}
@@ -99,8 +106,8 @@ bool operator==(const ParagraphCacheKey& a, const ParagraphCacheKey& b) {
99106
return false;
100107
}
101108

102-
if (!(a.fParagraphStyle == b.fParagraphStyle)) {
103-
// This is too strong, but at least we will not lose lines
109+
// There is no need to compare default paragraph styles - they are included into fTextStyles
110+
if (a.fParagraphStyle.getHeight() != b.fParagraphStyle.getHeight()) {
104111
return false;
105112
}
106113

@@ -120,7 +127,7 @@ bool operator==(const ParagraphCacheKey& a, const ParagraphCacheKey& b) {
120127
return false;
121128
}
122129
}
123-
for (size_t i = 0; i < a.fPlaceholders.size(); ++i) {
130+
for (size_t i = 0; i < a.fPlaceholders.size() - 1; ++i) {
124131
auto& tsa = a.fPlaceholders[i];
125132
auto& tsb = b.fPlaceholders[i];
126133
if (!(tsa.fStyle.equals(tsb.fStyle))) {
@@ -222,6 +229,7 @@ bool ParagraphCache::findParagraph(ParagraphImpl* paragraph) {
222229
SkAutoMutexExclusive lock(fParagraphMutex);
223230
ParagraphCacheKey key(paragraph);
224231
std::unique_ptr<Entry>* entry = fLRUCacheMap.find(key);
232+
225233
if (!entry) {
226234
// We have a cache miss
227235
#ifdef PARAGRAPH_CACHE_STATS

modules/skparagraph/src/TextStyle.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ bool PlaceholderStyle::equals(const PlaceholderStyle& other) const {
183183
SkScalarNearlyEqual(fHeight, other.fHeight) &&
184184
fAlignment == other.fAlignment &&
185185
fBaseline == other.fBaseline &&
186-
SkScalarNearlyEqual(fBaselineOffset, other.fBaselineOffset);
186+
(fAlignment != PlaceholderAlignment::kBaseline ||
187+
SkScalarNearlyEqual(fBaselineOffset, other.fBaselineOffset));
187188
}
188189

189190
} // namespace textlayout

0 commit comments

Comments
 (0)