From 4a665f56b1e11e764124ccfb56712ce343037496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 4 Sep 2024 20:35:55 +0000 Subject: [PATCH] Bug 1914735 - Track color-scheme dependencies for non-inherited rule cache. r=firefox-style-system-reviewers,boris Differential Revision: https://phabricator.services.mozilla.com/D220134 --- servo/components/style/rule_cache.rs | 16 ++++++++++++++ .../style/values/specified/color.rs | 9 +++++++- .../color-scheme-rule-cache-ref.html | 22 +++++++++++++++++++ .../color-scheme-rule-cache.html | 21 ++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 testing/web-platform/tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-rule-cache-ref.html create mode 100644 testing/web-platform/tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-rule-cache.html diff --git a/servo/components/style/rule_cache.rs b/servo/components/style/rule_cache.rs index 70c5b797312d..54a150ed2025 100644 --- a/servo/components/style/rule_cache.rs +++ b/servo/components/style/rule_cache.rs @@ -11,6 +11,7 @@ use crate::rule_tree::StrongRuleNode; use crate::selector_parser::PseudoElement; use crate::shared_lock::StylesheetGuards; use crate::values::computed::{NonNegativeLength, Zoom}; +use crate::values::specified::color::ColorSchemeFlags; use fxhash::FxHashMap; use servo_arc::Arc; use smallvec::SmallVec; @@ -22,6 +23,7 @@ pub struct RuleCacheConditions { font_size: Option, line_height: Option, writing_mode: Option, + color_scheme: Option, } impl RuleCacheConditions { @@ -37,6 +39,12 @@ impl RuleCacheConditions { self.line_height = Some(line_height); } + /// Sets the style as depending in the color-scheme property value. + pub fn set_color_scheme_dependency(&mut self, color_scheme: ColorSchemeFlags) { + debug_assert!(self.color_scheme.map_or(true, |cs| cs == color_scheme)); + self.color_scheme = Some(color_scheme); + } + /// Sets the style as uncacheable. pub fn set_uncacheable(&mut self) { self.uncacheable = true; @@ -58,6 +66,7 @@ impl RuleCacheConditions { struct CachedConditions { font_size: Option, line_height: Option, + color_scheme: Option, writing_mode: Option, zoom: Zoom, } @@ -85,6 +94,12 @@ impl CachedConditions { } } + if let Some(cs) = self.color_scheme { + if style.get_inherited_ui().clone_color_scheme().bits != cs { + return false; + } + } + if let Some(wm) = self.writing_mode { if style.writing_mode != wm { return false; @@ -208,6 +223,7 @@ impl RuleCache { writing_mode: conditions.writing_mode, font_size: conditions.font_size, line_height: conditions.line_height, + color_scheme: conditions.color_scheme, zoom: style.effective_zoom, }; self.map diff --git a/servo/components/style/values/specified/color.rs b/servo/components/style/values/specified/color.rs index 850961950d0f..bdb6aecac8a0 100644 --- a/servo/components/style/values/specified/color.rs +++ b/servo/components/style/values/specified/color.rs @@ -141,6 +141,9 @@ impl LightDark { fn compute(&self, cx: &Context) -> ComputedColor { let style_color_scheme = cx.style().get_inherited_ui().clone_color_scheme(); let dark = cx.device().is_dark_color_scheme(&style_color_scheme); + if cx.for_non_inherited_property { + cx.rule_cache_conditions.borrow_mut().set_color_scheme_dependency(style_color_scheme.bits); + } let used = if dark { &self.dark } else { &self.light }; used.to_computed_value(cx) } @@ -421,6 +424,9 @@ impl SystemColor { // TODO: We should avoid cloning here most likely, though it's cheap-ish. let style_color_scheme = cx.style().get_inherited_ui().clone_color_scheme(); let color = cx.device().system_nscolor(*self, &style_color_scheme); + if cx.for_non_inherited_property { + cx.rule_cache_conditions.borrow_mut().set_color_scheme_dependency(style_color_scheme.bits); + } if color == bindings::NS_SAME_AS_FOREGROUND_COLOR { return ComputedColor::currentcolor(); } @@ -930,7 +936,8 @@ bitflags! { pub struct ColorScheme { #[ignore_malloc_size_of = "Arc"] idents: crate::ArcSlice, - bits: ColorSchemeFlags, + /// The computed bits for the known color schemes (plus the only keyword). + pub bits: ColorSchemeFlags, } impl ColorScheme { diff --git a/testing/web-platform/tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-rule-cache-ref.html b/testing/web-platform/tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-rule-cache-ref.html new file mode 100644 index 000000000000..67eaec0f190d --- /dev/null +++ b/testing/web-platform/tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-rule-cache-ref.html @@ -0,0 +1,22 @@ + + +CSS Test Reference + +
+ Always light +
+
+ Always dark +
diff --git a/testing/web-platform/tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-rule-cache.html b/testing/web-platform/tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-rule-cache.html new file mode 100644 index 000000000000..c8835182fc87 --- /dev/null +++ b/testing/web-platform/tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-rule-cache.html @@ -0,0 +1,21 @@ + + + + + + + +Dependencies from color-scheme to non-inherited properties + +
+ Always light +
+
+ Always dark +