Commit cb57d09e authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Chromium LUCI CQ

Remove all implementation of CSSKeyframesMemoryReduction

Since we are not going to use CSSKeyframesMemoryReduction, this patch
removes all of its implementation.

Bug: 1141814
Change-Id: If531461761974d236e6456cd5745356e0caecf11
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2614839Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841082}
parent d58a2d7a
...@@ -59,9 +59,6 @@ ScopedStyleResolver* ScopedStyleResolver::Parent() const { ...@@ -59,9 +59,6 @@ ScopedStyleResolver* ScopedStyleResolver::Parent() const {
} }
void ScopedStyleResolver::AddKeyframeRules(const RuleSet& rule_set) { void ScopedStyleResolver::AddKeyframeRules(const RuleSet& rule_set) {
if (RuntimeEnabledFeatures::CSSKeyframesMemoryReductionEnabled())
return;
const HeapVector<Member<StyleRuleKeyframes>> keyframes_rules = const HeapVector<Member<StyleRuleKeyframes>> keyframes_rules =
rule_set.KeyframesRules(); rule_set.KeyframesRules();
for (auto rule : keyframes_rules) for (auto rule : keyframes_rules)
...@@ -148,42 +145,8 @@ void ScopedStyleResolver::ResetStyle() { ...@@ -148,42 +145,8 @@ void ScopedStyleResolver::ResetStyle() {
needs_append_all_sheets_ = false; needs_append_all_sheets_ = false;
} }
const ActiveStyleSheetVector& ScopedStyleResolver::ActiveStyleSheets() {
StyleSheetCollection* collection =
GetTreeScope().GetDocument().GetStyleEngine().StyleSheetCollectionFor(
*scope_);
DCHECK(collection);
return collection->ActiveStyleSheets();
}
// static
StyleRuleKeyframes*
ScopedStyleResolver::KeyframeStylesForAnimationFromActiveSheets(
const AtomicString& name,
const ActiveStyleSheetVector& sheets) {
// We prefer non-vendor-prefixed over vendor-prefixed rules.
StyleRuleKeyframes* vendor_prefixed_result = nullptr;
for (auto sheet = sheets.rbegin(); sheet != sheets.rend(); ++sheet) {
RuleSet* rule_set = sheet->second;
if (!rule_set)
continue;
if (StyleRuleKeyframes* rule = rule_set->KeyframeStylesForAnimation(name)) {
if (!rule->IsVendorPrefixed())
return rule;
if (!vendor_prefixed_result)
vendor_prefixed_result = rule;
}
}
return vendor_prefixed_result;
}
StyleRuleKeyframes* ScopedStyleResolver::KeyframeStylesForAnimation( StyleRuleKeyframes* ScopedStyleResolver::KeyframeStylesForAnimation(
const AtomicString& animation_name) { const AtomicString& animation_name) {
if (RuntimeEnabledFeatures::CSSKeyframesMemoryReductionEnabled()) {
return KeyframeStylesForAnimationFromActiveSheets(animation_name,
ActiveStyleSheets());
}
if (keyframes_rule_map_.IsEmpty()) if (keyframes_rule_map_.IsEmpty())
return nullptr; return nullptr;
...@@ -195,7 +158,6 @@ StyleRuleKeyframes* ScopedStyleResolver::KeyframeStylesForAnimation( ...@@ -195,7 +158,6 @@ StyleRuleKeyframes* ScopedStyleResolver::KeyframeStylesForAnimation(
} }
void ScopedStyleResolver::AddKeyframeStyle(StyleRuleKeyframes* rule) { void ScopedStyleResolver::AddKeyframeStyle(StyleRuleKeyframes* rule) {
DCHECK(!RuntimeEnabledFeatures::CSSKeyframesMemoryReductionEnabled());
AtomicString name = rule->GetName(); AtomicString name = rule->GetName();
if (rule->IsVendorPrefixed()) { if (rule->IsVendorPrefixed()) {
......
...@@ -57,9 +57,6 @@ class CORE_EXPORT ScopedStyleResolver final ...@@ -57,9 +57,6 @@ class CORE_EXPORT ScopedStyleResolver final
const TreeScope& GetTreeScope() const { return *scope_; } const TreeScope& GetTreeScope() const { return *scope_; }
ScopedStyleResolver* Parent() const; ScopedStyleResolver* Parent() const;
static StyleRuleKeyframes* KeyframeStylesForAnimationFromActiveSheets(
const AtomicString& name,
const ActiveStyleSheetVector& sheets);
StyleRuleKeyframes* KeyframeStylesForAnimation( StyleRuleKeyframes* KeyframeStylesForAnimation(
const AtomicString& animation_name); const AtomicString& animation_name);
...@@ -94,8 +91,6 @@ class CORE_EXPORT ScopedStyleResolver final ...@@ -94,8 +91,6 @@ class CORE_EXPORT ScopedStyleResolver final
void AddKeyframeRules(const RuleSet&); void AddKeyframeRules(const RuleSet&);
void AddKeyframeStyle(StyleRuleKeyframes*); void AddKeyframeStyle(StyleRuleKeyframes*);
const ActiveStyleSheetVector& ActiveStyleSheets();
CounterStyleMap& EnsureCounterStyleMap(); CounterStyleMap& EnsureCounterStyleMap();
Member<TreeScope> scope_; Member<TreeScope> scope_;
......
...@@ -1075,18 +1075,4 @@ TEST_F(StyleResolverTest, InheritStyleImagesFromDisplayContents) { ...@@ -1075,18 +1075,4 @@ TEST_F(StyleResolverTest, InheritStyleImagesFromDisplayContents) {
<< "-webkit-mask-image is fetched"; << "-webkit-mask-image is fetched";
} }
// https://crbug.com/1145406
TEST_F(StyleResolverTest, StyleSheetWithNullRuleSet) {
ScopedCSSKeyframesMemoryReductionForTest enabled_scope(true);
GetDocument().documentElement()->setInnerHTML(R"HTML(
<style>.c6 { animation-name: anim; }</style>
<style media=print></style>
<div class=c6></div>
)HTML");
// Should not crash inside
UpdateAllLifecyclePhasesForTest();
}
} // namespace blink } // namespace blink
...@@ -339,50 +339,6 @@ void RuleSet::AddFontFaceRule(StyleRuleFontFace* rule) { ...@@ -339,50 +339,6 @@ void RuleSet::AddFontFaceRule(StyleRuleFontFace* rule) {
void RuleSet::AddKeyframesRule(StyleRuleKeyframes* rule) { void RuleSet::AddKeyframesRule(StyleRuleKeyframes* rule) {
EnsurePendingRules(); // So that keyframes_rules_.ShrinkToFit() gets called. EnsurePendingRules(); // So that keyframes_rules_.ShrinkToFit() gets called.
keyframes_rules_.push_back(rule); keyframes_rules_.push_back(rule);
keyframes_rules_sorted_ = false;
}
void RuleSet::SortKeyframesRulesIfNeeded() {
if (keyframes_rules_sorted_)
return;
// Sort keyframes rules by name, breaking ties with vendor prefixing.
// Since equal AtomicStrings always have the same impl, there's no need to
// actually compare the contents of two AtomicStrings. Comparing their impl
// addresses is enough.
std::stable_sort(
keyframes_rules_.begin(), keyframes_rules_.end(),
[](const StyleRuleKeyframes* lhs, const StyleRuleKeyframes* rhs) {
if (lhs->GetName() != rhs->GetName())
return lhs->GetName().Impl() < rhs->GetName().Impl();
if (lhs->IsVendorPrefixed() != rhs->IsVendorPrefixed())
return lhs->IsVendorPrefixed();
return false;
});
// Deduplicate rules, erase all but the last one for each animation name,
// since all the preceding ones are overridden.
auto boundary = std::unique(
keyframes_rules_.rbegin(), keyframes_rules_.rend(),
[](const StyleRuleKeyframes* lhs, const StyleRuleKeyframes* rhs) {
return lhs->GetName() == rhs->GetName();
});
keyframes_rules_.erase(keyframes_rules_.begin(), boundary.base());
keyframes_rules_.ShrinkToFit();
keyframes_rules_sorted_ = true;
}
StyleRuleKeyframes* RuleSet::KeyframeStylesForAnimation(
const AtomicString& name) {
SortKeyframesRulesIfNeeded();
Member<StyleRuleKeyframes>* rule_iterator = std::lower_bound(
keyframes_rules_.begin(), keyframes_rules_.end(), name,
[](const StyleRuleKeyframes* rule, const AtomicString& name) {
return rule->GetName().Impl() < name.Impl();
});
if (rule_iterator != keyframes_rules_.end() &&
(*rule_iterator)->GetName() == name) {
return *rule_iterator;
}
return nullptr;
} }
void RuleSet::AddPropertyRule(StyleRuleProperty* rule) { void RuleSet::AddPropertyRule(StyleRuleProperty* rule) {
......
...@@ -313,7 +313,6 @@ class CORE_EXPORT RuleSet final : public GarbageCollected<RuleSet> { ...@@ -313,7 +313,6 @@ class CORE_EXPORT RuleSet final : public GarbageCollected<RuleSet> {
const HeapVector<Member<StyleRuleKeyframes>>& KeyframesRules() const { const HeapVector<Member<StyleRuleKeyframes>>& KeyframesRules() const {
return keyframes_rules_; return keyframes_rules_;
} }
StyleRuleKeyframes* KeyframeStylesForAnimation(const AtomicString& name);
const HeapVector<Member<StyleRuleProperty>>& PropertyRules() const { const HeapVector<Member<StyleRuleProperty>>& PropertyRules() const {
return property_rules_; return property_rules_;
} }
...@@ -421,8 +420,6 @@ class CORE_EXPORT RuleSet final : public GarbageCollected<RuleSet> { ...@@ -421,8 +420,6 @@ class CORE_EXPORT RuleSet final : public GarbageCollected<RuleSet> {
HeapVector<MinimalRuleData> slotted_pseudo_element_rules_; HeapVector<MinimalRuleData> slotted_pseudo_element_rules_;
Vector<MediaQuerySetResult> media_query_set_results_; Vector<MediaQuerySetResult> media_query_set_results_;
bool keyframes_rules_sorted_ = true;
unsigned rule_count_; unsigned rule_count_;
Member<PendingRuleMaps> pending_rules_; Member<PendingRuleMaps> pending_rules_;
......
...@@ -331,63 +331,6 @@ TEST(RuleSetTest, RuleCountNotIncreasedByInvalidRuleData) { ...@@ -331,63 +331,6 @@ TEST(RuleSetTest, RuleCountNotIncreasedByInvalidRuleData) {
EXPECT_EQ(1u, rule_set->RuleCount()); EXPECT_EQ(1u, rule_set->RuleCount());
} }
TEST(RuleSetTest, KeyframesRulesBasic) {
ScopedCSSKeyframesMemoryReductionForTest enabled_scope(true);
css_test_helpers::TestStyleSheet sheet;
sheet.AddCSSRules("@keyframes foo { from {top: 0;} to {top: 100px;} }");
sheet.AddCSSRules("@keyframes bar { from {top: 100px;} to {top: 0;} }");
RuleSet& rule_set = sheet.GetRuleSet();
StyleRuleKeyframes* foo = rule_set.KeyframeStylesForAnimation("foo");
EXPECT_TRUE(foo);
EXPECT_EQ("foo", foo->GetName());
StyleRuleKeyframes* bar = rule_set.KeyframeStylesForAnimation("bar");
EXPECT_TRUE(bar);
EXPECT_EQ("bar", bar->GetName());
StyleRuleKeyframes* nonexist =
rule_set.KeyframeStylesForAnimation("nonexist");
EXPECT_FALSE(nonexist);
}
TEST(RuleSetTest, KeyframesRulesOverriding) {
ScopedCSSKeyframesMemoryReductionForTest enabled_scope(true);
// Among multiple @keyframes rules with the same name, the last one wins.
css_test_helpers::TestStyleSheet sheet;
sheet.AddCSSRules("@keyframes foo { from1 {top: 0;} to1 {top: 100px;} }");
sheet.AddCSSRules("@keyframes foo { from2 {top: 100px;} to2 {top: 0;} }");
RuleSet& rule_set = sheet.GetRuleSet();
StyleRuleKeyframes* rule = rule_set.KeyframeStylesForAnimation("foo");
EXPECT_TRUE(rule);
EXPECT_EQ("foo", rule->GetName());
CSSKeyframesRule* css_rule = To<CSSKeyframesRule>(sheet.CssRules()->item(1));
EXPECT_EQ(rule, css_rule->Keyframes());
}
TEST(RuleSetTest, KeyframesRulesVendorPrefixed) {
ScopedCSSKeyframesMemoryReductionForTest enabled_scope(true);
// Non-vendor-prefixed keyframes rules win against vendor-prefixed ones.
css_test_helpers::TestStyleSheet sheet;
sheet.AddCSSRules("@keyframes foo { from1 {top: 0;} to1 {top: 100px;} }");
sheet.AddCSSRules(
"@-webkit-keyframes foo { from2 {top: 100px;} to2 {top: 0;} }");
RuleSet& rule_set = sheet.GetRuleSet();
StyleRuleKeyframes* rule = rule_set.KeyframeStylesForAnimation("foo");
EXPECT_TRUE(rule);
EXPECT_EQ("foo", rule->GetName());
EXPECT_FALSE(rule->IsVendorPrefixed());
}
TEST(RuleSetTest, UACounterStyleRules) { TEST(RuleSetTest, UACounterStyleRules) {
ScopedCSSAtRuleCounterStyleForTest enabled_scope(true); ScopedCSSAtRuleCounterStyleForTest enabled_scope(true);
......
...@@ -1893,9 +1893,6 @@ bool StyleEngine::AddUserFontFaceRules(const RuleSet& rule_set) { ...@@ -1893,9 +1893,6 @@ bool StyleEngine::AddUserFontFaceRules(const RuleSet& rule_set) {
} }
void StyleEngine::AddUserKeyframeRules(const RuleSet& rule_set) { void StyleEngine::AddUserKeyframeRules(const RuleSet& rule_set) {
if (RuntimeEnabledFeatures::CSSKeyframesMemoryReductionEnabled())
return;
const HeapVector<Member<StyleRuleKeyframes>> keyframes_rules = const HeapVector<Member<StyleRuleKeyframes>> keyframes_rules =
rule_set.KeyframesRules(); rule_set.KeyframesRules();
for (unsigned i = 0; i < keyframes_rules.size(); ++i) for (unsigned i = 0; i < keyframes_rules.size(); ++i)
...@@ -1903,8 +1900,6 @@ void StyleEngine::AddUserKeyframeRules(const RuleSet& rule_set) { ...@@ -1903,8 +1900,6 @@ void StyleEngine::AddUserKeyframeRules(const RuleSet& rule_set) {
} }
void StyleEngine::AddUserKeyframeStyle(StyleRuleKeyframes* rule) { void StyleEngine::AddUserKeyframeStyle(StyleRuleKeyframes* rule) {
DCHECK(!RuntimeEnabledFeatures::CSSKeyframesMemoryReductionEnabled());
AtomicString animation_name(rule->GetName()); AtomicString animation_name(rule->GetName());
if (rule->IsVendorPrefixed()) { if (rule->IsVendorPrefixed()) {
...@@ -1941,11 +1936,6 @@ void StyleEngine::AddScrollTimelineRules(const RuleSet& rule_set) { ...@@ -1941,11 +1936,6 @@ void StyleEngine::AddScrollTimelineRules(const RuleSet& rule_set) {
StyleRuleKeyframes* StyleEngine::KeyframeStylesForAnimation( StyleRuleKeyframes* StyleEngine::KeyframeStylesForAnimation(
const AtomicString& animation_name) { const AtomicString& animation_name) {
if (RuntimeEnabledFeatures::CSSKeyframesMemoryReductionEnabled()) {
return ScopedStyleResolver::KeyframeStylesForAnimationFromActiveSheets(
animation_name, active_user_style_sheets_);
}
if (keyframes_rule_map_.IsEmpty()) if (keyframes_rule_map_.IsEmpty())
return nullptr; return nullptr;
......
...@@ -418,8 +418,6 @@ class CORE_EXPORT StyleEngine final : public GarbageCollected<StyleEngine>, ...@@ -418,8 +418,6 @@ class CORE_EXPORT StyleEngine final : public GarbageCollected<StyleEngine>,
Color ForcedBackgroundColor() const { return forced_background_color_; } Color ForcedBackgroundColor() const { return forced_background_color_; }
Color ColorAdjustBackgroundColor() const; Color ColorAdjustBackgroundColor() const;
TreeScopeStyleSheetCollection* StyleSheetCollectionFor(TreeScope&);
void Trace(Visitor*) const override; void Trace(Visitor*) const override;
const char* NameInHeapSnapshot() const override { return "StyleEngine"; } const char* NameInHeapSnapshot() const override { return "StyleEngine"; }
...@@ -436,6 +434,7 @@ class CORE_EXPORT StyleEngine final : public GarbageCollected<StyleEngine>, ...@@ -436,6 +434,7 @@ class CORE_EXPORT StyleEngine final : public GarbageCollected<StyleEngine>,
} }
TreeScopeStyleSheetCollection& EnsureStyleSheetCollectionFor(TreeScope&); TreeScopeStyleSheetCollection& EnsureStyleSheetCollectionFor(TreeScope&);
TreeScopeStyleSheetCollection* StyleSheetCollectionFor(TreeScope&);
bool ShouldUpdateDocumentStyleSheetCollection() const; bool ShouldUpdateDocumentStyleSheetCollection() const;
bool ShouldUpdateShadowTreeStyleSheetCollection() const; bool ShouldUpdateShadowTreeStyleSheetCollection() const;
......
...@@ -526,14 +526,6 @@ ...@@ -526,14 +526,6 @@
name: "CSSIndependentTransformProperties", name: "CSSIndependentTransformProperties",
status: "experimental", status: "experimental",
}, },
{
// Change ScopedStyleResolve and StyleEngine to use the already stored
// StyleSheetCollection to find @keyframes rules instead of creating their
// own hashmaps, so that we can save memory when there are web components
// with @keyframes rules in their stylesheets.
name: "CSSKeyframesMemoryReduction",
status: "test",
},
{ {
name: "CSSLayoutAPI", name: "CSSLayoutAPI",
status: "experimental", status: "experimental",
......
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