Bug 1289622 - Add an API for Servo traversal to call CalcStyleDifference. r=heycam
authorBobby Holley <bobbyholley@gmail.com>
Tue, 26 Jul 2016 14:22:57 -0700
changeset 306907 196ddcbf522500350d90dfb8af8fbc6fb0f475c5
parent 306906 8801607503feb4314c1a8f9aaa96768fc3277f40
child 306908 37340346a89e3ff5680559afabbc430ffaf9bb74
push id79963
push userbholley@mozilla.com
push dateWed, 27 Jul 2016 20:35:28 +0000
treeherdermozilla-inbound@196ddcbf5225 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1289622
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1289622 - Add an API for Servo traversal to call CalcStyleDifference. r=heycam
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -179,16 +179,41 @@ Gecko_SetNodeFlags(RawGeckoNode* aNode, 
 }
 
 void
 Gecko_UnsetNodeFlags(RawGeckoNode* aNode, uint32_t aFlags)
 {
   aNode->UnsetFlags(aFlags);
 }
 
+nsChangeHint
+Gecko_CalcAndStoreStyleDifference(RawGeckoElement* aElement,
+                                  ServoComputedValues* aComputedValues)
+{
+#ifdef MOZ_STYLO
+  nsStyleContext* oldContext = aElement->GetPrimaryFrame()->StyleContext();
+
+  // Pass the safe thing, which causes us to miss a potential optimization. See
+  // bug 1289863.
+  nsChangeHint forDescendants = nsChangeHint_Hints_NotHandledForDescendants;
+
+  // Eventually, we should compute things out of these flags like
+  // ElementRestyler::RestyleSelf does and pass the result to the caller to
+  // potentially halt traversal. See bug 1289868.
+  uint32_t equalStructs, samePointerStructs;
+  nsChangeHint result =
+    oldContext->CalcStyleDifference(aComputedValues, forDescendants,
+                                    &equalStructs, &samePointerStructs);
+  return result;
+#else
+  MOZ_CRASH("stylo: Shouldn't call Gecko_CalcAndStoreStyleDifference in "
+            "non-stylo build");
+#endif
+}
+
 ServoDeclarationBlock*
 Gecko_GetServoDeclarationBlock(RawGeckoElement* aElement)
 {
   const nsAttrValue* attr = aElement->GetParsedAttr(nsGkAtoms::style);
   if (!attr || attr->Type() != nsAttrValue::eServoCSSDeclaration) {
     return nullptr;
   }
   return attr->GetServoCSSDeclarationValue();
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -181,16 +181,20 @@ void Gecko_SetMozBinding(nsStyleDisplay*
                          ThreadSafePrincipalHolder* principal);
 void Gecko_CopyMozBindingFrom(nsStyleDisplay* des, const nsStyleDisplay* src);
 
 // Dirtiness tracking.
 uint32_t Gecko_GetNodeFlags(RawGeckoNode* node);
 void Gecko_SetNodeFlags(RawGeckoNode* node, uint32_t flags);
 void Gecko_UnsetNodeFlags(RawGeckoNode* node, uint32_t flags);
 
+// Incremental restyle.
+nsChangeHint Gecko_CalcAndStoreStyleDifference(RawGeckoElement* element,
+                                               ServoComputedValues* newstyle);
+
 // `array` must be an nsTArray
 // If changing this signature, please update the
 // friend function declaration in nsTArray.h
 void Gecko_EnsureTArrayCapacity(void* array, size_t capacity, size_t elem_size);
 
 
 void Gecko_EnsureImageLayersLength(nsStyleImageLayers* layers, size_t len);