Skip to content

Commit

Permalink
Skip matched declarations cache only for length resolution affecting …
Browse files Browse the repository at this point in the history
…font properties

https://bugs.webkit.org/show_bug.cgi?id=204098

Reviewed by Zalan Bujtas.

* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::equalForLengthResolution):

Put this next to the length resolution function, hopefully helping to keep them in sync.

* css/CSSPrimitiveValue.h:
* css/StyleResolver.cpp:
(WebCore::StyleResolver::applyMatchedProperties):

Replace test for font declaration change with a narrower test that only looks for those properties that affect length resolution.

* style/MatchedDeclarationsCache.cpp:
(WebCore::Style::MatchedDeclarationsCache::Entry::isUsableAfterHighPriorityProperties const):

Factor into function.

* style/MatchedDeclarationsCache.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@252370 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
[email protected] committed Nov 12, 2019
1 parent c07ee6f commit ea57b5f
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 7 deletions.
25 changes: 25 additions & 0 deletions Source/WebCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
2019-11-12 Antti Koivisto <[email protected]>

Skip matched declarations cache only for length resolution affecting font properties
https://bugs.webkit.org/show_bug.cgi?id=204098

Reviewed by Zalan Bujtas.

* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::equalForLengthResolution):

Put this next to the length resolution function, hopefully helping to keep them in sync.

* css/CSSPrimitiveValue.h:
* css/StyleResolver.cpp:
(WebCore::StyleResolver::applyMatchedProperties):

Replace test for font declaration change with a narrower test that only looks for those properties that affect length resolution.

* style/MatchedDeclarationsCache.cpp:
(WebCore::Style::MatchedDeclarationsCache::Entry::isUsableAfterHighPriorityProperties const):

Factor into function.

* style/MatchedDeclarationsCache.h:

2019-11-12 Peng Liu <[email protected]>

Picture-in-Picture events are not fired if we switch the Picture-in-Picture mode through modern media controls
Expand Down
19 changes: 19 additions & 0 deletions Source/WebCore/css/CSSPrimitiveValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,25 @@ double CSSPrimitiveValue::computeNonCalcLengthDouble(const CSSToLengthConversion
return result;
}

bool CSSPrimitiveValue::equalForLengthResolution(const RenderStyle& styleA, const RenderStyle& styleB)
{
// These properties affect results of computeNonCalcLengthDouble above.
if (styleA.fontDescription().computedSize() != styleB.fontDescription().computedSize())
return false;
if (styleA.fontDescription().specifiedSize() != styleB.fontDescription().specifiedSize())
return false;

if (styleA.fontMetrics().xHeight() != styleB.fontMetrics().xHeight())
return false;
if (styleA.fontMetrics().zeroWidth() != styleB.fontMetrics().zeroWidth())
return false;

if (styleA.zoom() != styleB.zoom())
return false;

return true;
}

ExceptionOr<void> CSSPrimitiveValue::setFloatValue(unsigned short, double)
{
// Keeping values immutable makes optimizations easier and allows sharing of the primitive value objects.
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/css/CSSPrimitiveValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ class CSSPrimitiveValue final : public CSSValue {
static double conversionToCanonicalUnitsScaleFactor(UnitType);

static double computeNonCalcLengthDouble(const CSSToLengthConversionData&, UnitType, double value);
// True if computeNonCalcLengthDouble would produce identical results when resolved against both these styles.
static bool equalForLengthResolution(const RenderStyle&, const RenderStyle&);

Ref<DeprecatedCSSOMPrimitiveValue> createDeprecatedCSSOMPrimitiveWrapper(CSSStyleDeclaration&) const;

Expand Down
12 changes: 5 additions & 7 deletions Source/WebCore/css/StyleResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,13 +584,11 @@ void StyleResolver::applyMatchedProperties(State& state, const MatchResult& matc
// High priority properties may affect resolution of other properties (they are mostly font related).
builder.applyHighPriorityProperties();

// If the effective zoom value changes, we can't use the matched properties cache. Start over.
if (cacheEntry && cacheEntry->renderStyle->effectiveZoom() != style.effectiveZoom())
return applyMatchedProperties(state, matchResult, UseMatchedDeclarationsCache::No);

// If the font changed, we can't use the matched properties cache. Start over.
if (cacheEntry && cacheEntry->renderStyle->fontDescription() != style.fontDescription())
return applyMatchedProperties(state, matchResult, UseMatchedDeclarationsCache::No);
if (cacheEntry && !cacheEntry->isUsableAfterHighPriorityProperties(style)) {
// We need to resolve all properties without caching.
applyMatchedProperties(state, matchResult, UseMatchedDeclarationsCache::No);
return;
}

builder.applyLowPriorityProperties();

Expand Down
8 changes: 8 additions & 0 deletions Source/WebCore/style/MatchedDeclarationsCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ bool MatchedDeclarationsCache::isCacheable(const Element& element, const RenderS
return true;
}

bool MatchedDeclarationsCache::Entry::isUsableAfterHighPriorityProperties(const RenderStyle& style) const
{
if (style.effectiveZoom() != renderStyle->effectiveZoom())
return false;

return CSSPrimitiveValue::equalForLengthResolution(style, *renderStyle);
}

unsigned MatchedDeclarationsCache::computeHash(const MatchResult& matchResult)
{
if (!matchResult.isCacheable)
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/style/MatchedDeclarationsCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class MatchedDeclarationsCache {
MatchResult matchResult;
std::unique_ptr<const RenderStyle> renderStyle;
std::unique_ptr<const RenderStyle> parentRenderStyle;

bool isUsableAfterHighPriorityProperties(const RenderStyle&) const;
};

const Entry* find(unsigned hash, const MatchResult&);
Expand Down

0 comments on commit ea57b5f

Please sign in to comment.