Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce StyleFontData to store the FontCascade object #22531

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

smfr
Copy link
Contributor

@smfr smfr commented Jan 9, 2024

b965532

Introduce StyleFontData to store the FontCascade object
https://bugs.webkit.org/show_bug.cgi?id=267252
rdar://120688639

FontCascade::operator== shows up on profiles under RenderStyle::diff() in the Design subtest
of MotionMark, which is animating the `color` property on many elements. `color` and
`fontCascade` are both members of `StyleInheritedData`, so we end up copying and comparing
`StyleInheritedData` a lot.

But FontCascade is large (232 bytes) and expensive to compare, so we can optimize by moving
it into its own ref-counted class that `StyleInheritedData` can own via a `DataRef`. This
approach was chosen, rather than making `FontCascade` directly ref-counted, because it's
used on the stack in various places.

Now RenderStyle can test for `fontData` pointer equality in various places before doing more
expensive checks.

This reveals some cases where we fail to issue correct style invalidations;
fast/css/ios/update-user-interface-level.html shows that we need to explicitly update
the base view background color when "elevated user interface" mode changes, so do this
via `Document::updateElementsAffectedBySystemColors()`.

* Source/WebCore/Headers.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::updateElementsAffectedBySystemColors):
(WebCore::Document::updateElementsAffectedByMediaQueries):
* Source/WebCore/dom/Document.h:
* Source/WebCore/page/Page.cpp:
(WebCore::Page::appearanceDidChange):
* Source/WebCore/rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::hashForTextAutosizing const):
(WebCore::RenderStyle::equalForTextAutosizing const):
(WebCore::RenderStyle::changeRequiresLayout const):
(WebCore::RenderStyle::conservativelyCollectChangedAnimatableProperties const):
(WebCore::RenderStyle::fontCascade const):
(WebCore::RenderStyle::metricsOfPrimaryFont const):
(WebCore::RenderStyle::fontDescription const):
(WebCore::RenderStyle::setFontDescription):
(WebCore::RenderStyle::setLetterSpacing):
(WebCore::RenderStyle::setWordSpacing):
* Source/WebCore/rendering/style/RenderStyleInlines.h:
(WebCore::RenderStyle::letterSpacing const):
(WebCore::RenderStyle::wordSpacing const):
* Source/WebCore/rendering/style/StyleFontData.cpp: Added.
(WebCore::StyleFontData::StyleFontData):
(WebCore::StyleFontData::copy const):
(WebCore::StyleFontData::operator== const):
* Source/WebCore/rendering/style/StyleFontData.h: Added.
(WebCore::StyleFontData::create):
* Source/WebCore/rendering/style/StyleInheritedData.cpp:
(WebCore::StyleInheritedData::StyleInheritedData):
(WebCore::StyleInheritedData::nonFastPathInheritedEqual const):
* Source/WebCore/rendering/style/StyleInheritedData.h:

b965532

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 ❌ πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
βœ… πŸ§ͺ ios-wk2-wpt ❌ πŸ§ͺ mac-wk1 βœ… πŸ›  wpe-skia
❌ πŸ§ͺ api-ios ❌ πŸ§ͺ mac-wk2 βœ… πŸ›  gtk
βœ… πŸ›  tv ❌ πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ›  tv-sim βœ… πŸ§ͺ api-gtk
βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@smfr smfr self-assigned this Jan 9, 2024
@smfr smfr added the CSS Cascading Style Sheets implementation label Jan 9, 2024
Copy link
Contributor

@heycam heycam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with comments addressed.

Source/WebCore/rendering/style/RenderStyle.cpp Outdated Show resolved Hide resolved
Source/WebCore/rendering/style/RenderStyle.cpp Outdated Show resolved Hide resolved
@smfr smfr force-pushed the eng/Introduce-StyleFontData-to-store-the-FontCascade-object branch from db653db to 2744fcf Compare January 9, 2024 05:24
@webkit-early-warning-system
Copy link
Collaborator

Starting EWS tests for 2744fcf. Live statuses available at the PR page, #22531

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jan 9, 2024
return adoptRef(*new StyleFontData(*this));
}

bool StyleFontData::operator==(const StyleFontData& o) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= default ?

@smfr smfr removed the merging-blocked Applied to prevent a change from being merged label Jan 9, 2024
@smfr smfr force-pushed the eng/Introduce-StyleFontData-to-store-the-FontCascade-object branch from 2744fcf to a1376ed Compare January 9, 2024 16:44
@webkit-early-warning-system
Copy link
Collaborator

Starting EWS tests for a1376ed. Live statuses available at the PR page, #22531

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jan 9, 2024
webkit-commit-queue pushed a commit to smfr/WebKit that referenced this pull request Jan 12, 2024
…changes

https://bugs.webkit.org/show_bug.cgi?id=267423
rdar://120854167

Reviewed by Antti Koivisto.

WebKit#22531 caused the TestWebKitAPI.WKWebViewThemeColor.KVO
API test to break, when changing the to the `print` media type failed to cause a change of
theme color when the theme meta tag had `media=screen`.

That PR reduces the frequency of style diffs caused by FontCascade differences. In the API
test, this results in a change to the `print` media type no longer triggering a layout on
the (empty) document. Since the layout no longer occurs, we never hit
`updateStyleForLayout()`, so don't end up calling `updateElementsAffectedByMediaQueries()`.

Fix by calling `document.updateElementsAffectedByMediaQueries()` from
`Page::updateStyleAfterChangeInEnvironment()`, and have `WebPage::setOverriddenMediaType()`
call `updateStyleAfterChangeInEnvironment()` which seems like the right thing to do.

* Source/WebCore/html/HTMLMetaElement.cpp: Whitespace.
* Source/WebCore/page/LocalFrameViewLayoutContext.cpp: Whitespace.
* Source/WebCore/page/Page.cpp:
(WebCore::Page::updateStyleAfterChangeInEnvironment):
* Source/WebCore/page/Page.h:
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setOverriddenMediaType):

Canonical link: https://commits.webkit.org/272947@main
@smfr smfr removed the merging-blocked Applied to prevent a change from being merged label Jan 12, 2024
@smfr smfr force-pushed the eng/Introduce-StyleFontData-to-store-the-FontCascade-object branch from a1376ed to 8f8b49d Compare January 12, 2024 05:09
@webkit-early-warning-system
Copy link
Collaborator

Starting EWS tests for 8f8b49d. Live statuses available at the PR page, #22531

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jan 12, 2024
webkit-commit-queue pushed a commit to smfr/WebKit that referenced this pull request Jan 16, 2024
…y changes

https://bugs.webkit.org/show_bug.cgi?id=267564
rdar://121024996

Reviewed by Antoine Quint.

On iOS with WebKit#22531, fast/attachment/attachment-dynamic-type.html fails,
showing that fonts failed to update after we change `contentSizeCategory()` via Internals.

When the content size category changes via the user setting it in the UI, we get notified
via a `UIContentSizeCategoryDidChangeNotification` notification, and in response to this
we call `FontCache::invalidateAllFontCaches()` (see `fontCacheRegisteredFontsChangedNotificationCallback()`).
So we need to do the same when the content size category is changed through Internals.

This caused webanimations/css-animation-effect-target-change-and-get-keyframes-crash.html to crash
with a null m_target, so add a null check in `computeCSSAnimationBlendingKeyframes()`.

* Source/WebCore/animation/KeyframeEffect.cpp:
(WebCore::KeyframeEffect::computeCSSAnimationBlendingKeyframes):
* Source/WebCore/platform/graphics/cocoa/FontCacheCocoa.mm:
(WebCore::setContentSizeCategory):
* Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::FontCache::platformInit):

Canonical link: https://commits.webkit.org/273070@main
@smfr smfr removed the merging-blocked Applied to prevent a change from being merged label Apr 4, 2024
@smfr smfr force-pushed the eng/Introduce-StyleFontData-to-store-the-FontCascade-object branch from 8f8b49d to bde6612 Compare April 4, 2024 00:52
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 4, 2024
https://bugs.webkit.org/show_bug.cgi?id=267252
rdar://120688639

FontCascade::operator== shows up on profiles under RenderStyle::diff() in the Design subtest
of MotionMark, which is animating the `color` property on many elements. `color` and
`fontCascade` are both members of `StyleInheritedData`, so we end up copying and comparing
`StyleInheritedData` a lot.

But FontCascade is large (232 bytes) and expensive to compare, so we can optimize by moving
it into its own ref-counted class that `StyleInheritedData` can own via a `DataRef`. This
approach was chosen, rather than making `FontCascade` directly ref-counted, because it's
used on the stack in various places.

Now RenderStyle can test for `fontData` pointer equality in various places before doing more
expensive checks.

This reveals some cases where we fail to issue correct style invalidations;
fast/css/ios/update-user-interface-level.html shows that we need to explicitly update
the base view background color when "elevated user interface" mode changes, so do this
via `Document::updateElementsAffectedBySystemColors()`.

* Source/WebCore/Headers.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::updateElementsAffectedBySystemColors):
(WebCore::Document::updateElementsAffectedByMediaQueries):
* Source/WebCore/dom/Document.h:
* Source/WebCore/page/Page.cpp:
(WebCore::Page::appearanceDidChange):
* Source/WebCore/rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::hashForTextAutosizing const):
(WebCore::RenderStyle::equalForTextAutosizing const):
(WebCore::RenderStyle::changeRequiresLayout const):
(WebCore::RenderStyle::conservativelyCollectChangedAnimatableProperties const):
(WebCore::RenderStyle::fontCascade const):
(WebCore::RenderStyle::metricsOfPrimaryFont const):
(WebCore::RenderStyle::fontDescription const):
(WebCore::RenderStyle::setFontDescription):
(WebCore::RenderStyle::setLetterSpacing):
(WebCore::RenderStyle::setWordSpacing):
* Source/WebCore/rendering/style/RenderStyleInlines.h:
(WebCore::RenderStyle::letterSpacing const):
(WebCore::RenderStyle::wordSpacing const):
* Source/WebCore/rendering/style/StyleFontData.cpp: Added.
(WebCore::StyleFontData::StyleFontData):
(WebCore::StyleFontData::copy const):
(WebCore::StyleFontData::operator== const):
* Source/WebCore/rendering/style/StyleFontData.h: Added.
(WebCore::StyleFontData::create):
* Source/WebCore/rendering/style/StyleInheritedData.cpp:
(WebCore::StyleInheritedData::StyleInheritedData):
(WebCore::StyleInheritedData::nonFastPathInheritedEqual const):
* Source/WebCore/rendering/style/StyleInheritedData.h:
@smfr smfr removed the merging-blocked Applied to prevent a change from being merged label Apr 5, 2024
@smfr smfr force-pushed the eng/Introduce-StyleFontData-to-store-the-FontCascade-object branch from bde6612 to b965532 Compare April 5, 2024 22:26
@smfr smfr requested review from cdumez and rniwa as code owners April 5, 2024 22:26
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Cascading Style Sheets implementation merging-blocked Applied to prevent a change from being merged
Projects
None yet
5 participants