Skip to content

Commit

Permalink
stylo: only clear relevant origins when medium features change.
Browse files Browse the repository at this point in the history
Bug: 1389871
Reviewed-by: heycam
MozReview-Commit-ID: 6ocZc1u1TbU
  • Loading branch information
emilio committed Aug 14, 2017
1 parent f7eb46f commit fd3d383
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
28 changes: 19 additions & 9 deletions components/style/stylist.rs
Expand Up @@ -40,7 +40,7 @@ use style_traits::viewport::ViewportConstraints;
#[cfg(feature = "gecko")]
use stylesheets::{CounterStyleRule, FontFaceRule};
use stylesheets::{CssRule, StyleRule};
use stylesheets::{StylesheetInDocument, Origin, PerOrigin, PerOriginClear};
use stylesheets::{StylesheetInDocument, Origin, OriginSet, PerOrigin, PerOriginClear};
use stylesheets::UserAgentStylesheets;
use stylesheets::keyframes_rule::KeyframesAnimation;
use stylesheets::viewport_rule::{self, MaybeNew, ViewportRule};
Expand Down Expand Up @@ -977,16 +977,16 @@ impl Stylist {
stylesheets.iter().map(|s| &**s),
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
/// 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>(
&self,
stylesheets: I,
guard: &SharedRwLockReadGuard,
) -> bool
) -> OriginSet
where
I: Iterator<Item = &'a S>,
S: StylesheetInDocument + ToMediaListKey + 'static,
Expand All @@ -995,11 +995,18 @@ impl Stylist {

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 =
stylesheet.is_effective_for_device(&self.device, guard);

let origin = stylesheet.origin(guard);

if origins.contains(origin.into()) {
continue;
}

let origin_cascade_data =
self.cascade_data.borrow_for_origin(&origin);

Expand All @@ -1011,7 +1018,8 @@ impl Stylist {
if effective_now != effective_then {
debug!(" > Stylesheet changed -> {}, {}",
effective_then, effective_now);
return true
origins |= origin;
continue;
}

if !effective_now {
Expand Down Expand Up @@ -1051,7 +1059,8 @@ impl Stylist {
if effective_now != effective_then {
debug!(" > @import rule changed {} -> {}",
effective_then, effective_now);
return true;
origins |= origin;
continue 'stylesheets_loop;
}

if !effective_now {
Expand All @@ -1070,7 +1079,8 @@ impl Stylist {
if effective_now != effective_then {
debug!(" > @media rule changed {} -> {}",
effective_then, effective_now);
return true;
origins |= origin;
continue 'stylesheets_loop;
}

if !effective_now {
Expand All @@ -1081,7 +1091,7 @@ impl Stylist {
}
}

return false;
return origins
}

/// Returns the viewport constraints that apply to this document because of
Expand Down
13 changes: 7 additions & 6 deletions ports/geckolib/glue.rs
Expand Up @@ -899,7 +899,7 @@ pub extern "C" fn Servo_StyleSet_AppendStyleSheet(
pub extern "C" fn Servo_StyleSet_MediumFeaturesChanged(
raw_data: RawServoStyleSetBorrowed,
viewport_units_used: *mut bool,
) -> bool {
) -> OriginFlags {
let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read();

Expand All @@ -919,12 +919,13 @@ pub extern "C" fn Servo_StyleSet_MediumFeaturesChanged(
*viewport_units_used = data.stylist.device().used_viewport_size();
}
data.stylist.device_mut().reset_computed_values();
let rules_changed = data.stylist.media_features_change_changed_style(
data.stylesheets.iter(),
&guard,
);
let origins_in_which_rules_changed =
data.stylist.media_features_change_changed_style(
data.stylesheets.iter(),
&guard,
);

rules_changed
OriginFlags::from(origins_in_which_rules_changed)
}

#[no_mangle]
Expand Down

0 comments on commit fd3d383

Please sign in to comment.