Bug 1364824: Make RebuildAllStyleData's flush async too. r?heycam draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 15 May 2017 09:54:44 +0200
changeset 577690 60ad0daf1c50eba0a497655e0474feb4a5e3ff82
parent 577689 010c1f8b440a2b30686d5476303faa4ae6f94355
child 628558 bcbcc519fddf1a3bfc0fa3d275b17aa69c8e9db4
push id58754
push userbmo:emilio+bugs@crisal.io
push dateMon, 15 May 2017 07:55:44 +0000
reviewersheycam
bugs1364824
milestone55.0a1
Bug 1364824: Make RebuildAllStyleData's flush async too. r?heycam If this turns out to be problematic, I won't land it, but I think it's worth trying. MozReview-Commit-ID: DyZHGArZnTl
layout/base/ServoRestyleManager.cpp
layout/style/ServoBindingList.h
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
servo/components/style/gecko/data.rs
servo/ports/geckolib/glue.rs
--- a/layout/base/ServoRestyleManager.cpp
+++ b/layout/base/ServoRestyleManager.cpp
@@ -69,18 +69,17 @@ ServoRestyleManager::PostRestyleEventFor
 {
   Servo_NoteExplicitHints(aElement, aRestyleHint, nsChangeHint(0));
 }
 
 void
 ServoRestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint,
                                          nsRestyleHint aRestyleHint)
 {
-  // TODO(emilio): We might be able to do the StyleSet flushing async here too.
-  StyleSet()->RebuildData();
+  StyleSet()->ClearData();
 
   mHaveNonAnimationRestyles = true;
 
   // NOTE(emilio): GeckoRestlyeManager does a sync style flush, which seems
   // not to be needed in my testing.
   //
   // If it is, we can just do a content flush and call ProcessPendingRestyles.
   if (Element* root = mPresContext->Document()->GetRootElement()) {
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -41,17 +41,17 @@ SERVO_BINDING_FUNC(Servo_StyleSheet_Clea
                    mozilla::ServoStyleSheet* gecko_stylesheet,
                    const nsACString* data,
                    RawGeckoURLExtraData* extra_data)
 SERVO_BINDING_FUNC(Servo_StyleSheet_HasRules, bool,
                    RawServoStyleSheetBorrowed sheet)
 SERVO_BINDING_FUNC(Servo_StyleSheet_GetRules, ServoCssRulesStrong,
                    RawServoStyleSheetBorrowed sheet)
 SERVO_BINDING_FUNC(Servo_StyleSet_Init, RawServoStyleSetOwned, RawGeckoPresContextOwned pres_context)
-SERVO_BINDING_FUNC(Servo_StyleSet_RebuildData, void,
+SERVO_BINDING_FUNC(Servo_StyleSet_ClearData, void,
                    RawServoStyleSetBorrowed set)
 SERVO_BINDING_FUNC(Servo_StyleSet_Drop, void, RawServoStyleSetOwned set)
 SERVO_BINDING_FUNC(Servo_StyleSet_AppendStyleSheet, void,
                    RawServoStyleSetBorrowed set,
                    RawServoStyleSheetBorrowed sheet,
                    uint64_t unique_id)
 SERVO_BINDING_FUNC(Servo_StyleSet_PrependStyleSheet, void,
                    RawServoStyleSetBorrowed set,
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -958,20 +958,21 @@ ServoStyleSet::ComputeAnimationValue(
 {
   return Servo_AnimationValue_Compute(aDeclarations,
                                       aComputedValues.mCurrentStyle,
                                       aComputedValues.mParentStyle,
                                       mRawSet.get()).Consume();
 }
 
 void
-ServoStyleSet::RebuildData()
+ServoStyleSet::ClearData()
 {
   ClearNonInheritingStyleContexts();
-  Servo_StyleSet_RebuildData(mRawSet.get());
+  Servo_StyleSet_ClearData(mRawSet.get());
+  mStylistMayNeedRebuild = true;
 }
 
 already_AddRefed<ServoComputedValues>
 ServoStyleSet::ResolveServoStyle(Element* aElement)
 {
   MaybeRebuildStylist();
   return Servo_ResolveStyle(aElement, mRawSet.get(),
                             mAllowResolveStaleStyles).Consume();
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -281,20 +281,22 @@ public:
 
 #ifdef DEBUG
   void AssertTreeIsClean();
 #else
   void AssertTreeIsClean() {}
 #endif
 
   /**
-   * Rebuild the style data. This will force a stylesheet flush, and also
-   * recompute the default computed styles.
+   * Clear the style data.
+   *
+   * This will recompute the default computed values, and schedule a stylesheet
+   * flush.
    */
-  void RebuildData();
+  void ClearData();
 
   /**
    * Resolve style for the given element, and return it as a
    * ServoComputedValues, not an nsStyleContext.
    */
   already_AddRefed<ServoComputedValues> ResolveServoStyle(dom::Element* aElement);
 
   bool GetKeyframesForName(const nsString& aName,
--- a/servo/components/style/gecko/data.rs
+++ b/servo/components/style/gecko/data.rs
@@ -86,18 +86,17 @@ impl PerDocumentStyleData {
 }
 
 impl PerDocumentStyleDataImpl {
     /// Reset the device state because it may have changed.
     ///
     /// Implies also a stylesheet flush.
     pub fn reset_device(&mut self, guard: &SharedRwLockReadGuard) {
         Arc::get_mut(&mut self.stylist.device).unwrap().reset();
-        self.stylesheets.force_dirty();
-        self.flush_stylesheets(guard);
+        self.clear_stylist();
     }
 
     /// Recreate the style data if the stylesheets have changed.
     pub fn flush_stylesheets(&mut self, guard: &SharedRwLockReadGuard) {
         if !self.stylesheets.has_changed() {
             return;
         }
 
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -1135,17 +1135,17 @@ pub extern "C" fn Servo_ComputedValues_I
 #[no_mangle]
 pub extern "C" fn Servo_StyleSet_Init(pres_context: RawGeckoPresContextOwned)
   -> RawServoStyleSetOwned {
     let data = Box::new(PerDocumentStyleData::new(pres_context));
     data.into_ffi()
 }
 
 #[no_mangle]
-pub extern "C" fn Servo_StyleSet_RebuildData(raw_data: RawServoStyleSetBorrowed) {
+pub extern "C" fn Servo_StyleSet_ClearData(raw_data: RawServoStyleSetBorrowed) {
     let global_style_data = &*GLOBAL_STYLE_DATA;
     let guard = global_style_data.shared_lock.read();
     let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
     data.reset_device(&guard);
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_StyleSet_Drop(data: RawServoStyleSetOwned) {