Auto merge of #15157 - emilio:bug-1332969, r=bholley

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

Ideally this would be lazy, but eventually we're going to need to restyle in
RebuildAllStyleData anyway, which would require us to have the style up to date,
so no need to complicate our lives.

r? @heycam or @upsuper or @bholley

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15157)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-01-28 12:56:50 -08:00 committed by GitHub
commit 73bb75989f
2 changed files with 15 additions and 20 deletions

View file

@ -35,9 +35,6 @@ pub struct PerDocumentStyleDataImpl {
/// Whether the stylesheets list above has changed since the last restyle. /// Whether the stylesheets list above has changed since the last restyle.
pub stylesheets_changed: bool, pub stylesheets_changed: bool,
/// Whether the device has changed since the last restyle.
pub device_changed: bool,
// FIXME(bholley): Hook these up to something. // FIXME(bholley): Hook these up to something.
/// Unused. Will go away when we actually implement transitions and /// Unused. Will go away when we actually implement transitions and
/// animations properly. /// animations properly.
@ -85,7 +82,6 @@ impl PerDocumentStyleData {
stylist: Arc::new(Stylist::new(device)), stylist: Arc::new(Stylist::new(device)),
stylesheets: vec![], stylesheets: vec![],
stylesheets_changed: true, stylesheets_changed: true,
device_changed: true,
new_animations_sender: new_anims_sender, new_animations_sender: new_anims_sender,
new_animations_receiver: new_anims_receiver, new_animations_receiver: new_anims_receiver,
running_animations: Arc::new(RwLock::new(HashMap::new())), running_animations: Arc::new(RwLock::new(HashMap::new())),
@ -113,30 +109,29 @@ impl PerDocumentStyleData {
} }
impl PerDocumentStyleDataImpl { impl PerDocumentStyleDataImpl {
/// Recreate the style data if the stylesheets have changed. /// Reset the device state because it may have changed.
pub fn flush_stylesheets(&mut self) { ///
let mut stylist = if self.device_changed || self.stylesheets_changed { /// Implies also a stylesheet flush.
Some(Arc::get_mut(&mut self.stylist).unwrap()) pub fn reset_device(&mut self) {
} else { {
None let mut stylist = Arc::get_mut(&mut self.stylist).unwrap();
}; Arc::get_mut(&mut stylist.device).unwrap().reset();
}
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; self.stylesheets_changed = true;
self.flush_stylesheets();
} }
/// Recreate the style data if the stylesheets have changed.
pub fn flush_stylesheets(&mut self) {
if self.stylesheets_changed { 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; self.stylesheets_changed = false;
} }
} }
/// Get the default computed values for this document. /// Get the default computed values for this document.
pub fn default_computed_values(&self) -> &Arc<ComputedValues> { pub fn default_computed_values(&self) -> &Arc<ComputedValues> {
debug_assert!(!self.device_changed, "A device flush was pending");
self.stylist.device.default_values_arc() self.stylist.device.default_values_arc()
} }
} }

View file

@ -726,7 +726,7 @@ pub extern "C" fn Servo_StyleSet_Init(pres_context: RawGeckoPresContextOwned)
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_StyleSet_RebuildData(raw_data: RawServoStyleSetBorrowed) { pub extern "C" fn Servo_StyleSet_RebuildData(raw_data: RawServoStyleSetBorrowed) {
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut(); let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
data.device_changed = true; data.reset_device();
} }
#[no_mangle] #[no_mangle]