From d29fade4c25b5334e7caf2f30286faf5649dfb5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 23 Jan 2017 18:46:27 +0100 Subject: [PATCH] Bug 1332969: stylo: Synchronously do a style update when the device changes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. MozReview-Commit-ID: AlmUGRCNm2z Signed-off-by: Emilio Cobos Álvarez --- components/style/gecko/data.rs | 33 ++++++++++++++------------------- ports/geckolib/glue.rs | 2 +- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index f4182d365e2..4ecfe1df520 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -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. @@ -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())), @@ -113,30 +109,29 @@ impl PerDocumentStyleData { } impl PerDocumentStyleDataImpl { + /// 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; + self.flush_stylesheets(); + } + /// 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; - } - 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 { - debug_assert!(!self.device_changed, "A device flush was pending"); self.stylist.device.default_values_arc() } } diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 5e2550793e8..c3ce9ef2099 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -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]