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

Bug 1332969: stylo: Synchronously do a style update when the device changes #15157

Merged
merged 1 commit into from Jan 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 14 additions & 19 deletions components/style/gecko/data.rs
Expand Up @@ -35,9 +35,6 @@ pub struct PerDocumentStyleDataImpl {
/// Whether the stylesheets list above has changed since the last restyle.
pub stylesheets_changed: bool,

/// Whether the device has changed since the last restyle.
pub device_changed: bool,

// FIXME(bholley): Hook these up to something.
/// Unused. Will go away when we actually implement transitions and
/// animations properly.
Expand Down Expand Up @@ -85,7 +82,6 @@ impl PerDocumentStyleData {
stylist: Arc::new(Stylist::new(device)),
stylesheets: vec![],
stylesheets_changed: true,
device_changed: true,
new_animations_sender: new_anims_sender,
new_animations_receiver: new_anims_receiver,
running_animations: Arc::new(RwLock::new(HashMap::new())),
Expand Down Expand Up @@ -113,30 +109,29 @@ impl PerDocumentStyleData {
}

impl PerDocumentStyleDataImpl {
/// Recreate the style data if the stylesheets have changed.
pub fn flush_stylesheets(&mut self) {
let mut stylist = if self.device_changed || self.stylesheets_changed {
Some(Arc::get_mut(&mut self.stylist).unwrap())
} else {
None
};

if self.device_changed {
Arc::get_mut(&mut stylist.as_mut().unwrap().device).unwrap().reset();
self.device_changed = false;
// Force a stylesheet flush if the device has changed.
self.stylesheets_changed = true;
/// Reset the device state because it may have changed.
///
/// Implies also a stylesheet flush.
pub fn reset_device(&mut self) {
{
let mut stylist = Arc::get_mut(&mut self.stylist).unwrap();
Arc::get_mut(&mut stylist.device).unwrap().reset();
}
self.stylesheets_changed = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to mark the stylesheets as having changed if the device changes? It seems like we need to recascade the DOM and reevaluate media queries, but stylesheets_changed does more work, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to reconstruct the style data because different rules may match.

We can definitely be more granular in the future, but that mechanism isn't there right now.

Copy link
Member Author

Choose a reason for hiding this comment

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

s/may match/may apply/

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to reconstruct the style data because different rules may match.

Oh ok. So We should put a RESTYLE_SELF | RESTYLE_DESCENDANTS hint on the root then.

We can definitely be more granular in the future, but that mechanism isn't there right now.

My understanding is that the servo architecture already differentiates between "stylesheets changed" and "device changed". What machinery is missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to do the restyle stuff after I've finished all the medialist work, because gecko has its own control about which media queries have matched and not, and can provide us with an adequate restyle hint if we do the right thing.

Servo does indeed have the concept of "setting a new device", but there are fundamental differences between a servo device and a Gecko device that don't allow us to do that for gecko.

Concretely, in gecko right now the device is represented by the pres context and effectively unique. There's no easy way to compare against a previous state of the pres context (and I think its not bad, but we can't just reuse that piece of code so easily)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok - Just add a comment indicating that Gecko doesn't use that machinery?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, and just so that I understand - if Gecko does provide us with such a restyle hint, will it avoid invoke RebuildAllStyleData? Because otherwise we're still going to dirty everything.

I guess I'm probably enough context here that it makes sense for heycam to review it, since he reviewed the media query stuff.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, RebuildAllStyleData receives a hint and a change hint.

self.flush_stylesheets();
}

/// Recreate the style data if the stylesheets have changed.
pub fn flush_stylesheets(&mut self) {
if self.stylesheets_changed {
let _ = stylist.unwrap().update(&self.stylesheets, None, true);
let mut stylist = Arc::get_mut(&mut self.stylist).unwrap();
stylist.update(&self.stylesheets, None, true);
self.stylesheets_changed = false;
}
}

/// Get the default computed values for this document.
pub fn default_computed_values(&self) -> &Arc<ComputedValues> {
debug_assert!(!self.device_changed, "A device flush was pending");
self.stylist.device.default_values_arc()
}
}
Expand Down
2 changes: 1 addition & 1 deletion ports/geckolib/glue.rs
Expand Up @@ -685,7 +685,7 @@ pub extern "C" fn Servo_StyleSet_Init(pres_context: RawGeckoPresContextOwned)
#[no_mangle]
pub extern "C" fn Servo_StyleSet_RebuildData(raw_data: RawServoStyleSetBorrowed) {
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
data.device_changed = true;
data.reset_device();
}

#[no_mangle]
Expand Down