Commit 37e02eb9 authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Use base computed style optimization with DCHECKs enabled.

We used to skip the whole base computed style optimization and just
compare the new style with the old stored base, but used the newly
computed style always when DCHECK was enabled.

This CL always computes the computed style without the base, but then,
after verifying it matches the base, use the base computed style.

Bug: 669790
Change-Id: Ifc82de4644fae104d69d8abf91261ba1cfe52f73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2074399Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745043}
parent 826ab6a3
...@@ -53,29 +53,6 @@ void UpdateAnimationFlagsForEffect(const KeyframeEffect& effect, ...@@ -53,29 +53,6 @@ void UpdateAnimationFlagsForEffect(const KeyframeEffect& effect,
style.SetHasCurrentBackdropFilterAnimation(true); style.SetHasCurrentBackdropFilterAnimation(true);
} }
#if DCHECK_IS_ON()
// Under certain conditions ComputedStyle::operator==() may return false for
// differences that are permitted during an animation.
bool ShouldCheckComputedStyles(const ComputedStyle& base_computed_style,
const ComputedStyle& computed_style) {
// The FontFaceCache version number may be increased without forcing a style
// recalc (see crbug.com/471079).
if (!base_computed_style.GetFont().IsFallbackValid())
return false;
// Images use instance equality rather than value equality (see
// crbug.com/781461).
for (CSSPropertyID id :
{CSSPropertyID::kBackgroundImage, CSSPropertyID::kWebkitMaskImage}) {
if (!CSSPropertyEquality::PropertiesEqual(
PropertyHandle(CSSProperty::Get(id)), base_computed_style,
computed_style)) {
return false;
}
}
return true;
}
#endif // DCHECK_IS_ON()
} // namespace } // namespace
ElementAnimations::ElementAnimations() : animation_style_change_(false) {} ElementAnimations::ElementAnimations() : animation_style_change_(false) {}
...@@ -137,13 +114,8 @@ void ElementAnimations::Trace(Visitor* visitor) { ...@@ -137,13 +114,8 @@ void ElementAnimations::Trace(Visitor* visitor) {
} }
const ComputedStyle* ElementAnimations::BaseComputedStyle() const { const ComputedStyle* ElementAnimations::BaseComputedStyle() const {
// When DCHECK is on we lie and claim to never have a base computed style
// stored. This allows us to check that an invariant holds; see the comments in
// |UpdateBaseComputedStyle|.
#if !DCHECK_IS_ON()
if (IsAnimationStyleChange()) if (IsAnimationStyleChange())
return base_computed_style_.get(); return base_computed_style_.get();
#endif
return nullptr; return nullptr;
} }
...@@ -154,18 +126,6 @@ void ElementAnimations::UpdateBaseComputedStyle( ...@@ -154,18 +126,6 @@ void ElementAnimations::UpdateBaseComputedStyle(
base_computed_style_ = nullptr; base_computed_style_ = nullptr;
return; return;
} }
#if DCHECK_IS_ON()
// The invariant in the base computed style optimization is that as long as
// |IsAnimationStyleChange| is true, the computed style that would be
// generated by the style resolver is equivalent to the one we hold
// internally. To ensure this we disable the optimization when DCHECKs are
// enabled, but keep the internal base computed style and make sure the
// equivalency holds here.
if (base_computed_style_ && computed_style &&
ShouldCheckComputedStyles(*base_computed_style_, *computed_style)) {
DCHECK(*base_computed_style_ == *computed_style);
}
#endif
base_computed_style_ = ComputedStyle::Clone(*computed_style); base_computed_style_ = ComputedStyle::Clone(*computed_style);
} }
......
...@@ -139,6 +139,8 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> { ...@@ -139,6 +139,8 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> {
void Trace(Visitor*); void Trace(Visitor*);
private: private:
void InitStyleAndApplyInheritance(Element& element,
StyleResolverState& state);
void ApplyBaseComputedStyle(Element* element, void ApplyBaseComputedStyle(Element* element,
StyleResolverState& state, StyleResolverState& state,
RuleMatchingBehavior matching_behavior, RuleMatchingBehavior matching_behavior,
......
...@@ -52,12 +52,8 @@ TEST_F(StyleResolverTest, AnimationBaseComputedStyle) { ...@@ -52,12 +52,8 @@ TEST_F(StyleResolverTest, AnimationBaseComputedStyle) {
ASSERT_TRUE(resolver->StyleForElement(div)); ASSERT_TRUE(resolver->StyleForElement(div));
EXPECT_EQ(20, resolver->StyleForElement(div)->FontSize()); EXPECT_EQ(20, resolver->StyleForElement(div)->FontSize());
#if DCHECK_IS_ON()
EXPECT_FALSE(animations.BaseComputedStyle());
#else
ASSERT_TRUE(animations.BaseComputedStyle()); ASSERT_TRUE(animations.BaseComputedStyle());
EXPECT_EQ(20, animations.BaseComputedStyle()->FontSize()); EXPECT_EQ(20, animations.BaseComputedStyle()->FontSize());
#endif
// Getting style with customized parent style should not affect cached // Getting style with customized parent style should not affect cached
// animation base computed style. // animation base computed style.
...@@ -66,12 +62,8 @@ TEST_F(StyleResolverTest, AnimationBaseComputedStyle) { ...@@ -66,12 +62,8 @@ TEST_F(StyleResolverTest, AnimationBaseComputedStyle) {
EXPECT_EQ( EXPECT_EQ(
10, 10,
resolver->StyleForElement(div, parent_style, parent_style)->FontSize()); resolver->StyleForElement(div, parent_style, parent_style)->FontSize());
#if DCHECK_IS_ON()
EXPECT_FALSE(animations.BaseComputedStyle());
#else
ASSERT_TRUE(animations.BaseComputedStyle()); ASSERT_TRUE(animations.BaseComputedStyle());
EXPECT_EQ(20, animations.BaseComputedStyle()->FontSize()); EXPECT_EQ(20, animations.BaseComputedStyle()->FontSize());
#endif
EXPECT_EQ(20, resolver->StyleForElement(div)->FontSize()); EXPECT_EQ(20, resolver->StyleForElement(div)->FontSize());
} }
......
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