summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/fonts/font_fallback_list.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/platform/fonts/font_fallback_list.cc')
-rw-r--r--chromium/third_party/blink/renderer/platform/fonts/font_fallback_list.cc74
1 files changed, 58 insertions, 16 deletions
diff --git a/chromium/third_party/blink/renderer/platform/fonts/font_fallback_list.cc b/chromium/third_party/blink/renderer/platform/fonts/font_fallback_list.cc
index fa1a455e591..d00d18310bb 100644
--- a/chromium/third_party/blink/renderer/platform/fonts/font_fallback_list.cc
+++ b/chromium/third_party/blink/renderer/platform/fonts/font_fallback_list.cc
@@ -39,22 +39,24 @@
namespace blink {
-FontFallbackList::FontFallbackList()
+FontFallbackList::FontFallbackList(FontSelector* font_selector)
: cached_primary_simple_font_data_(nullptr),
- font_selector_(nullptr),
- font_selector_version_(0),
+ font_selector_(font_selector),
+ font_selector_version_(font_selector ? 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) {
+void FontFallbackList::Invalidate() {
ReleaseFontData();
font_list_.clear();
cached_primary_simple_font_data_ = nullptr;
family_index_ = 0;
has_loading_fallback_ = false;
- if (font_selector_ != font_selector)
- font_selector_ = font_selector;
+ can_shape_word_by_word_ = false;
+ can_shape_word_by_word_computed_ = false;
font_selector_version_ = font_selector_ ? font_selector_->Version() : 0;
generation_ = FontCache::GetFontCache()->Generation();
}
@@ -65,13 +67,18 @@ void FontFallbackList::ReleaseFontData() {
if (!font_list_[i]->IsCustomFont()) {
DCHECK(!font_list_[i]->IsSegmented());
FontCache::GetFontCache()->ReleaseFontData(
- ToSimpleFontData(font_list_[i]));
+ To<SimpleFontData>(font_list_[i].get()));
}
}
shape_cache_.reset(); // Clear the weak pointer to the cache instance.
}
bool FontFallbackList::LoadingCustomFonts() const {
+ // This function is only used for style and layout invalidation purposes. We
+ // don't need it for invalidation when the feature below is enabled.
+ if (RuntimeEnabledFeatures::CSSReducedFontLoadingInvalidationsEnabled())
+ return false;
+
if (!has_loading_fallback_)
return false;
@@ -84,6 +91,8 @@ bool FontFallbackList::LoadingCustomFonts() const {
}
bool FontFallbackList::ShouldSkipDrawing() const {
+ DCHECK(IsValid());
+
if (!has_loading_fallback_)
return false;
@@ -96,7 +105,7 @@ bool FontFallbackList::ShouldSkipDrawing() const {
}
const SimpleFontData* FontFallbackList::DeterminePrimarySimpleFontData(
- const FontDescription& font_description) const {
+ const FontDescription& font_description) {
bool should_load_custom_font = true;
for (unsigned font_index = 0;; ++font_index) {
@@ -114,8 +123,8 @@ const SimpleFontData* FontFallbackList::DeterminePrimarySimpleFontData(
return last_resort_fallback;
}
- if (font_data->IsSegmented() &&
- !ToSegmentedFontData(font_data)->ContainsCharacter(kSpaceCharacter))
+ const auto* segmented = DynamicTo<SegmentedFontData>(font_data);
+ if (segmented && !segmented->ContainsCharacter(kSpaceCharacter))
continue;
const SimpleFontData* font_data_for_space =
@@ -128,8 +137,7 @@ const SimpleFontData* FontFallbackList::DeterminePrimarySimpleFontData(
if (!font_data_for_space->IsLoadingFallback())
return font_data_for_space;
- if (font_data->IsSegmented()) {
- const SegmentedFontData* segmented = ToSegmentedFontData(font_data);
+ if (segmented) {
for (unsigned i = 0; i < segmented->NumFaces(); i++) {
const SimpleFontData* range_font_data =
segmented->FaceAt(i)->FontData();
@@ -212,8 +220,9 @@ FallbackListCompositeKey FontFallbackList::CompositeKey(
if (result) {
bool is_unique_match = false;
key.Add(font_description.CacheKey(params, is_unique_match));
- if (!result->IsSegmented() && !result->IsCustomFont())
- FontCache::GetFontCache()->ReleaseFontData(ToSimpleFontData(result));
+ auto* font_data = DynamicTo<SimpleFontData>(result.get());
+ if (!font_data && !result->IsCustomFont())
+ FontCache::GetFontCache()->ReleaseFontData(font_data);
}
}
current_family = current_family->Next();
@@ -224,7 +233,12 @@ FallbackListCompositeKey FontFallbackList::CompositeKey(
const FontData* FontFallbackList::FontDataAt(
const FontDescription& font_description,
- unsigned realized_font_index) const {
+ unsigned realized_font_index) {
+ if (RuntimeEnabledFeatures::CSSReducedFontLoadingInvalidationsEnabled()) {
+ if (!IsValid())
+ Invalidate();
+ }
+
// This fallback font is already in our list.
if (realized_font_index < font_list_.size())
return font_list_[realized_font_index].get();
@@ -250,6 +264,34 @@ const FontData* FontFallbackList::FontDataAt(
return result.get();
}
+bool FontFallbackList::ComputeCanShapeWordByWord(
+ const FontDescription& font_description) {
+ 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) {
+ if (RuntimeEnabledFeatures::CSSReducedFontLoadingInvalidationsEnabled()) {
+ if (!IsValid())
+ Invalidate();
+ }
+
+ 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;