From 2685aef48e970518da4f3514ef1db4f74fef656e Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 9 Jul 2015 15:58:16 -0700 Subject: [PATCH] Add HyphenEdit to layout cache We bypass the word layout cache for "complex" cases, which includes things like OpenType features. We were counting a hyphen edit as such a case, but the problem is that we measure a _lot_ of these when doing layout with hyphenation. This patch adds plumbing for hyphen edits to the layout cache, so that word fragments with hyphens can be cached as well. Bug: 22378829 Change-Id: Idba4df4faa14f48a5faccc8a7a7955a36c19ef27 --- engine/src/flutter/include/minikin/MinikinFont.h | 4 ++-- engine/src/flutter/libs/minikin/Layout.cpp | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index ee885f497c..7f65cd7b0a 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -35,6 +35,7 @@ public: HyphenEdit() : hyphen(0) { } HyphenEdit(uint32_t hyphenInt) : hyphen(hyphenInt) { } bool hasHyphen() const { return hyphen != 0; } + bool operator==(const HyphenEdit &other) const { return hyphen == other.hyphen; } private: uint32_t hyphen; }; @@ -48,8 +49,7 @@ struct MinikinPaint { fakery(), fontFeatureSettings() { } bool skipCache() const { - // TODO: add hyphen to cache - return !fontFeatureSettings.empty() || hyphenEdit.hasHyphen(); + return !fontFeatureSettings.empty(); } MinikinFont *font; diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index bac5fc7743..be29e3ca2a 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -110,7 +110,7 @@ public: mStart(start), mCount(count), mId(collection->getId()), mStyle(style), mSize(paint.size), mScaleX(paint.scaleX), mSkewX(paint.skewX), mLetterSpacing(paint.letterSpacing), - mPaintFlags(paint.paintFlags), mIsRtl(dir) { + mPaintFlags(paint.paintFlags), mHyphenEdit(paint.hyphenEdit), mIsRtl(dir) { } bool operator==(const LayoutCacheKey &other) const; hash_t hash() const; @@ -144,6 +144,7 @@ private: float mSkewX; float mLetterSpacing; int32_t mPaintFlags; + HyphenEdit mHyphenEdit; bool mIsRtl; // Note: any fields added to MinikinPaint must also be reflected here. // TODO: language matching (possibly integrate into style) @@ -236,6 +237,7 @@ bool LayoutCacheKey::operator==(const LayoutCacheKey& other) const { && mSkewX == other.mSkewX && mLetterSpacing == other.mLetterSpacing && mPaintFlags == other.mPaintFlags + && mHyphenEdit == other.mHyphenEdit && mIsRtl == other.mIsRtl && mNchars == other.mNchars && !memcmp(mChars, other.mChars, mNchars * sizeof(uint16_t)); @@ -251,6 +253,7 @@ hash_t LayoutCacheKey::hash() const { hash = JenkinsHashMix(hash, hash_type(mSkewX)); hash = JenkinsHashMix(hash, hash_type(mLetterSpacing)); hash = JenkinsHashMix(hash, hash_type(mPaintFlags)); + hash = JenkinsHashMix(hash, hash_type(mHyphenEdit.hasHyphen())); hash = JenkinsHashMix(hash, hash_type(mIsRtl)); hash = JenkinsHashMixShorts(hash, mChars, mNchars); return JenkinsHashWhiten(hash);