stylo: only clear relevant origins when medium features change.

Bug: 1389871
Reviewed-by: heycam
MozReview-Commit-ID: 6ocZc1u1TbU
This commit is contained in:
Emilio Cobos Álvarez 2017-08-14 10:38:15 +02:00
parent f7eb46f484
commit fd3d38326c
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 26 additions and 15 deletions

View file

@ -40,7 +40,7 @@ use style_traits::viewport::ViewportConstraints;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use stylesheets::{CounterStyleRule, FontFaceRule}; use stylesheets::{CounterStyleRule, FontFaceRule};
use stylesheets::{CssRule, StyleRule}; use stylesheets::{CssRule, StyleRule};
use stylesheets::{StylesheetInDocument, Origin, PerOrigin, PerOriginClear}; use stylesheets::{StylesheetInDocument, Origin, OriginSet, PerOrigin, PerOriginClear};
use stylesheets::UserAgentStylesheets; use stylesheets::UserAgentStylesheets;
use stylesheets::keyframes_rule::KeyframesAnimation; use stylesheets::keyframes_rule::KeyframesAnimation;
use stylesheets::viewport_rule::{self, MaybeNew, ViewportRule}; use stylesheets::viewport_rule::{self, MaybeNew, ViewportRule};
@ -977,16 +977,16 @@ impl Stylist {
stylesheets.iter().map(|s| &**s), stylesheets.iter().map(|s| &**s),
guard guard
); );
self.is_device_dirty |= features_changed; self.is_device_dirty |= !features_changed.is_empty();
} }
/// Returns whether, given a media feature change, any previously-applicable /// Returns whether, given a media feature change, any previously-applicable
/// style has become non-applicable, or vice-versa. /// style has become non-applicable, or vice-versa for each origin.
pub fn media_features_change_changed_style<'a, I, S>( pub fn media_features_change_changed_style<'a, I, S>(
&self, &self,
stylesheets: I, stylesheets: I,
guard: &SharedRwLockReadGuard, guard: &SharedRwLockReadGuard,
) -> bool ) -> OriginSet
where where
I: Iterator<Item = &'a S>, I: Iterator<Item = &'a S>,
S: StylesheetInDocument + ToMediaListKey + 'static, S: StylesheetInDocument + ToMediaListKey + 'static,
@ -995,11 +995,18 @@ impl Stylist {
debug!("Stylist::media_features_change_changed_style"); debug!("Stylist::media_features_change_changed_style");
for stylesheet in stylesheets { let mut origins = OriginSet::empty();
'stylesheets_loop: for stylesheet in stylesheets {
let effective_now = let effective_now =
stylesheet.is_effective_for_device(&self.device, guard); stylesheet.is_effective_for_device(&self.device, guard);
let origin = stylesheet.origin(guard); let origin = stylesheet.origin(guard);
if origins.contains(origin.into()) {
continue;
}
let origin_cascade_data = let origin_cascade_data =
self.cascade_data.borrow_for_origin(&origin); self.cascade_data.borrow_for_origin(&origin);
@ -1011,7 +1018,8 @@ impl Stylist {
if effective_now != effective_then { if effective_now != effective_then {
debug!(" > Stylesheet changed -> {}, {}", debug!(" > Stylesheet changed -> {}, {}",
effective_then, effective_now); effective_then, effective_now);
return true origins |= origin;
continue;
} }
if !effective_now { if !effective_now {
@ -1051,7 +1059,8 @@ impl Stylist {
if effective_now != effective_then { if effective_now != effective_then {
debug!(" > @import rule changed {} -> {}", debug!(" > @import rule changed {} -> {}",
effective_then, effective_now); effective_then, effective_now);
return true; origins |= origin;
continue 'stylesheets_loop;
} }
if !effective_now { if !effective_now {
@ -1070,7 +1079,8 @@ impl Stylist {
if effective_now != effective_then { if effective_now != effective_then {
debug!(" > @media rule changed {} -> {}", debug!(" > @media rule changed {} -> {}",
effective_then, effective_now); effective_then, effective_now);
return true; origins |= origin;
continue 'stylesheets_loop;
} }
if !effective_now { if !effective_now {
@ -1081,7 +1091,7 @@ impl Stylist {
} }
} }
return false; return origins
} }
/// Returns the viewport constraints that apply to this document because of /// Returns the viewport constraints that apply to this document because of

View file

@ -899,7 +899,7 @@ pub extern "C" fn Servo_StyleSet_AppendStyleSheet(
pub extern "C" fn Servo_StyleSet_MediumFeaturesChanged( pub extern "C" fn Servo_StyleSet_MediumFeaturesChanged(
raw_data: RawServoStyleSetBorrowed, raw_data: RawServoStyleSetBorrowed,
viewport_units_used: *mut bool, viewport_units_used: *mut bool,
) -> bool { ) -> OriginFlags {
let global_style_data = &*GLOBAL_STYLE_DATA; let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read(); let guard = global_style_data.shared_lock.read();
@ -919,12 +919,13 @@ pub extern "C" fn Servo_StyleSet_MediumFeaturesChanged(
*viewport_units_used = data.stylist.device().used_viewport_size(); *viewport_units_used = data.stylist.device().used_viewport_size();
} }
data.stylist.device_mut().reset_computed_values(); data.stylist.device_mut().reset_computed_values();
let rules_changed = data.stylist.media_features_change_changed_style( let origins_in_which_rules_changed =
data.stylesheets.iter(), data.stylist.media_features_change_changed_style(
&guard, data.stylesheets.iter(),
); &guard,
);
rules_changed OriginFlags::from(origins_in_which_rules_changed)
} }
#[no_mangle] #[no_mangle]