Commit 690392f7 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Move computation of Font::CanShapeWordByWord() to FontFallbackList

Font::CanShapeWordByWord() depends on font face specific data, and
hence, will be invalidated after a font face is loaded.

This patch moves the computation and caching from Font to
FontFallbackList, so that we don't need to invalidate Font for the data
after loading a font face.

This is preparation for crrev.com/c/1952189 that reduces invalidations
after font loading.

Bug: 441925
Change-Id: I605ffbc3981a56f6653cb32d5415b291b03f3b0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2026594
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736639}
parent d7f2e347
......@@ -48,27 +48,15 @@
namespace blink {
Font::Font() : can_shape_word_by_word_(0), shape_word_by_word_computed_(0) {}
Font::Font(const FontDescription& fd)
: font_description_(fd),
can_shape_word_by_word_(0),
shape_word_by_word_computed_(0) {}
Font::Font(const Font& other)
: font_description_(other.font_description_),
font_fallback_list_(other.font_fallback_list_),
// TODO(yosin): We should have a comment the reason why don't we copy
// |m_canShapeWordByWord| and |m_shapeWordByWordComputed| from |other|,
// since |operator=()| copies them from |other|.
can_shape_word_by_word_(0),
shape_word_by_word_computed_(0) {}
Font::Font() = default;
Font::Font(const FontDescription& fd) : font_description_(fd) {}
Font::Font(const Font& other) = default;
Font& Font::operator=(const Font& other) {
font_description_ = other.font_description_;
font_fallback_list_ = other.font_fallback_list_;
can_shape_word_by_word_ = other.can_shape_word_by_word_;
shape_word_by_word_computed_ = other.shape_word_by_word_computed_;
return *this;
}
......@@ -426,23 +414,8 @@ ShapeCache* Font::GetShapeCache() const {
}
bool Font::CanShapeWordByWord() const {
if (!shape_word_by_word_computed_) {
can_shape_word_by_word_ = ComputeCanShapeWordByWord();
shape_word_by_word_computed_ = true;
}
return can_shape_word_by_word_;
}
bool Font::ComputeCanShapeWordByWord() const {
if (!GetFontDescription().GetTypesettingFeatures())
return true;
if (!PrimaryFont())
return false;
const FontPlatformData& platform_data = PrimaryFont()->PlatformData();
TypesettingFeatures features = GetFontDescription().GetTypesettingFeatures();
return !platform_data.HasSpaceInLigaturesOrKerning(features);
return font_fallback_list_ &&
font_fallback_list_->CanShapeWordByWord(GetFontDescription());
}
void Font::ReportNotDefGlyph() const {
......
......@@ -213,8 +213,8 @@ class PLATFORM_EXPORT Font {
bool CanShapeWordByWord() const;
void SetCanShapeWordByWordForTesting(bool b) {
can_shape_word_by_word_ = b;
shape_word_by_word_computed_ = true;
if (font_fallback_list_)
font_fallback_list_->SetCanShapeWordByWordForTesting(b);
}
void ReportNotDefGlyph() const;
......@@ -224,8 +224,6 @@ class PLATFORM_EXPORT Font {
GlyphData GetEmphasisMarkGlyphData(const AtomicString&) const;
bool ComputeCanShapeWordByWord() const;
public:
FontSelector* GetFontSelector() const;
FontFallbackIterator CreateFontFallbackIterator(
......@@ -246,8 +244,6 @@ class PLATFORM_EXPORT Font {
private:
FontDescription font_description_;
mutable scoped_refptr<FontFallbackList> font_fallback_list_;
mutable unsigned can_shape_word_by_word_ : 1;
mutable unsigned shape_word_by_word_computed_ : 1;
// For m_fontDescription & m_fontFallbackList access.
friend class CachingWordShaper;
......
......@@ -45,7 +45,9 @@ FontFallbackList::FontFallbackList()
font_selector_version_(0),
family_index_(0),
generation_(FontCache::GetFontCache()->Generation()),
has_loading_fallback_(false) {}
has_loading_fallback_(false),
can_shape_word_by_word_(false),
can_shape_word_by_word_computed_(false) {}
void FontFallbackList::Invalidate(FontSelector* font_selector) {
ReleaseFontData();
......@@ -53,6 +55,8 @@ void FontFallbackList::Invalidate(FontSelector* font_selector) {
cached_primary_simple_font_data_ = nullptr;
family_index_ = 0;
has_loading_fallback_ = false;
can_shape_word_by_word_ = false;
can_shape_word_by_word_computed_ = false;
if (font_selector_ != font_selector)
font_selector_ = font_selector;
font_selector_version_ = font_selector_ ? font_selector_->Version() : 0;
......@@ -250,6 +254,29 @@ const FontData* FontFallbackList::FontDataAt(
return result.get();
}
bool FontFallbackList::ComputeCanShapeWordByWord(
const FontDescription& font_description) const {
if (!font_description.GetTypesettingFeatures())
return true;
const SimpleFontData* primary_font = PrimarySimpleFontData(font_description);
if (!primary_font)
return false;
const FontPlatformData& platform_data = primary_font->PlatformData();
TypesettingFeatures features = font_description.GetTypesettingFeatures();
return !platform_data.HasSpaceInLigaturesOrKerning(features);
}
bool FontFallbackList::CanShapeWordByWord(
const FontDescription& font_description) const {
if (!can_shape_word_by_word_computed_) {
can_shape_word_by_word_ = ComputeCanShapeWordByWord(font_description);
can_shape_word_by_word_computed_ = true;
}
return can_shape_word_by_word_;
}
bool FontFallbackList::IsValid() const {
if (!font_selector_)
return font_selector_version_ == 0;
......
......@@ -71,7 +71,7 @@ class PLATFORM_EXPORT FontFallbackList : public RefCounted<FontFallbackList> {
}
const SimpleFontData* PrimarySimpleFontData(
const FontDescription& font_description) {
const FontDescription& font_description) const {
if (!cached_primary_simple_font_data_) {
cached_primary_simple_font_data_ =
DeterminePrimarySimpleFontData(font_description);
......@@ -83,6 +83,13 @@ class PLATFORM_EXPORT FontFallbackList : public RefCounted<FontFallbackList> {
FallbackListCompositeKey CompositeKey(const FontDescription&) const;
bool CanShapeWordByWord(const FontDescription&) const;
void SetCanShapeWordByWordForTesting(bool b) {
can_shape_word_by_word_ = b;
can_shape_word_by_word_computed_ = true;
}
private:
FontFallbackList();
......@@ -92,6 +99,7 @@ class PLATFORM_EXPORT FontFallbackList : public RefCounted<FontFallbackList> {
const FontDescription&) const;
void ReleaseFontData();
bool ComputeCanShapeWordByWord(const FontDescription&) const;
mutable Vector<scoped_refptr<FontData>, 1> font_list_;
mutable const SimpleFontData* cached_primary_simple_font_data_;
......@@ -100,6 +108,8 @@ class PLATFORM_EXPORT FontFallbackList : public RefCounted<FontFallbackList> {
mutable int family_index_;
uint16_t generation_;
mutable bool has_loading_fallback_ : 1;
mutable bool can_shape_word_by_word_ : 1;
mutable bool can_shape_word_by_word_computed_ : 1;
mutable base::WeakPtr<ShapeCache> shape_cache_;
DISALLOW_COPY_AND_ASSIGN(FontFallbackList);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment