Bug 1251496 - Introduce a servo-side data structure to represent the style set. r=heycam
authorBobby Holley <bobbyholley@gmail.com>
Tue, 26 Jan 2016 18:02:04 -0800
changeset 322300 49904442faec1c1f4ca91cbbea0e8ebcfb2a5b6a
parent 322299 7d1baa75f591451a5df54c7f9ea1bc0fece43669
child 322301 621f1087e51a5e7ebe66edcfab6a407424ea97f9
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1251496
milestone47.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 1251496 - Introduce a servo-side data structure to represent the style set. r=heycam
layout/style/ServoBindingHelpers.h
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
mfbt/UniquePtr.h
--- a/layout/style/ServoBindingHelpers.h
+++ b/layout/style/ServoBindingHelpers.h
@@ -4,25 +4,36 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_ServoBindingHelpers_h
 #define mozilla_ServoBindingHelpers_h
 
 #include "mozilla/RefPtr.h"
 #include "mozilla/ServoBindings.h"
+#include "mozilla/UniquePtr.h"
 
 namespace mozilla {
 
 template<>
 struct RefPtrTraits<RawServoStyleSheet>
 {
   static void AddRef(RawServoStyleSheet* aPtr) {
     MOZ_CRASH("stylo: not implemented");
   }
   static void Release(RawServoStyleSheet* aPtr) {
     Servo_ReleaseStylesheet(aPtr);
   }
 };
 
+template<>
+class DefaultDelete<RawServoStyleSet>
+{
+public:
+  void operator()(RawServoStyleSet* aPtr) const
+  {
+    Servo_DropStyleSet(aPtr);
+  }
+};
+
 } // namespace mozilla
 
 #endif // mozilla_ServoBindingHelpers_h
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -165,15 +165,29 @@ Servo_StylesheetFromUTF8Bytes(const uint
 
 void
 Servo_ReleaseStylesheet(RawServoStyleSheet* sheet)
 {
   MOZ_CRASH("stylo: shouldn't be calling Servo_ReleaseStylesheet in a "
             "non-MOZ_STYLO build");
 }
 
+RawServoStyleSet*
+Servo_InitStyleSet()
+{
+  MOZ_CRASH("stylo: shouldn't be calling Servo_InitStyleSet in a "
+            "non-MOZ_STYLO build");
+}
+
 void
-Servo_RestyleDocument(RawGeckoDocument* aDoc)
+Servo_DropStyleSet(RawServoStyleSet* set)
+{
+  MOZ_CRASH("stylo: shouldn't be calling Servo_DropStyleSet in a "
+            "non-MOZ_STYLO build");
+}
+
+void
+Servo_RestyleDocument(RawGeckoDocument* doc, RawServoStyleSet* set)
 {
   MOZ_CRASH("stylo: shouldn't be calling Servo_RestyleDocument in a "
             "non-MOZ_STYLO build");
 }
 #endif
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -22,27 +22,30 @@ class nsINode;
 typedef nsINode RawGeckoNode;
 namespace mozilla { namespace dom { class Element; } }
 using mozilla::dom::Element;
 typedef mozilla::dom::Element RawGeckoElement;
 class nsIDocument;
 typedef nsIDocument RawGeckoDocument;
 struct ServoNodeData;
 struct RawServoStyleSheet;
+struct RawServoStyleSet;
 #else
 struct RawGeckoNode;
 typedef struct RawGeckoNode RawGeckoNode;
 struct RawGeckoElement;
 typedef struct RawGeckoElement RawGeckoElement;
 struct RawGeckoDocument;
 typedef struct RawGeckoDocument RawGeckoDocument;
 struct ServoNodeData;
 typedef struct ServoNodeData ServoNodeData;
 struct RawServoStyleSheet;
 typedef struct RawServoStyleSheet RawServoStyleSheet;
+struct RawServoStyleSet;
+typedef struct RawServoStyleSet RawServoStyleSet;
 #endif
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 // DOM Traversal.
 uint32_t Gecko_ChildrenCount(RawGeckoNode* node);
@@ -68,21 +71,25 @@ int Gecko_IsVisitedLink(RawGeckoElement*
 int Gecko_IsUnvisitedLink(RawGeckoElement* element);
 int Gecko_IsRootElement(RawGeckoElement* element);
 
 // Node data.
 ServoNodeData* Gecko_GetNodeData(RawGeckoNode* node);
 void Gecko_SetNodeData(RawGeckoNode* node, ServoNodeData* data);
 void Servo_DropNodeData(ServoNodeData* data);
 
-// Stylesheet management.
-// XXXheycam: Make this return an already_AddRefed<RawServoStyleSheet>.
+// Styleset and Stylesheet management.
+//
+// TODO: Make these return already_AddRefed and UniquePtr when the binding
+// generator is smart enough to handle them.
 RawServoStyleSheet* Servo_StylesheetFromUTF8Bytes(const uint8_t* bytes, uint32_t length);
 void Servo_ReleaseStylesheet(RawServoStyleSheet* sheet);
+RawServoStyleSet* Servo_InitStyleSet();
+void Servo_DropStyleSet(RawServoStyleSet* set);
 
 // Servo API.
-void Servo_RestyleDocument(RawGeckoDocument* aDoc);
+void Servo_RestyleDocument(RawGeckoDocument* doc, RawServoStyleSet* set);
 
 #ifdef __cplusplus
 } // extern "C"
 #endif
 
 #endif // mozilla_ServoBindings_h
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -8,33 +8,35 @@
 
 #include "nsCSSAnonBoxes.h"
 #include "nsStyleSet.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 ServoStyleSet::ServoStyleSet()
-  : mBatching(0)
+  : mRawSet(Servo_InitStyleSet())
+  , mBatching(0)
 {
 }
 
 void
 ServoStyleSet::Init(nsPresContext* aPresContext)
 {
 }
 
 void
 ServoStyleSet::BeginShutdown()
 {
 }
 
 void
 ServoStyleSet::Shutdown()
 {
+  mRawSet = nullptr;
 }
 
 bool
 ServoStyleSet::GetAuthorStyleDisabled() const
 {
   return false;
 }
 
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -5,18 +5,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_ServoStyleSet_h
 #define mozilla_ServoStyleSet_h
 
 #include "mozilla/EnumeratedArray.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/RefPtr.h"
+#include "mozilla/ServoBindingHelpers.h"
 #include "mozilla/ServoStyleSheet.h"
 #include "mozilla/SheetType.h"
+#include "mozilla/UniquePtr.h"
 #include "nsChangeHint.h"
 #include "nsCSSPseudoElements.h"
 #include "nsIAtom.h"
 #include "nsTArray.h"
 
 namespace mozilla {
 namespace dom {
 class Element;
@@ -107,16 +109,17 @@ public:
   nsRestyleHint HasStateDependentStyle(dom::Element* aElement,
                                        EventStates aStateMask);
   nsRestyleHint HasStateDependentStyle(dom::Element* aElement,
                                        mozilla::CSSPseudoElementType aPseudoType,
                                        dom::Element* aPseudoElement,
                                        EventStates aStateMask);
 
 private:
-  mozilla::EnumeratedArray<mozilla::SheetType, mozilla::SheetType::Count,
-                           nsTArray<RefPtr<mozilla::ServoStyleSheet>>> mSheets;
+  UniquePtr<RawServoStyleSet> mRawSet;
+  EnumeratedArray<SheetType, SheetType::Count,
+                  nsTArray<RefPtr<ServoStyleSheet>>> mSheets;
   int32_t mBatching;
 };
 
 } // namespace mozilla
 
 #endif // mozilla_ServoStyleSet_h
--- a/mfbt/UniquePtr.h
+++ b/mfbt/UniquePtr.h
@@ -458,17 +458,29 @@ public:
   void reset(U) = delete;
 
   void swap(UniquePtr& aOther) { mTuple.swap(aOther.mTuple); }
 
   UniquePtr(const UniquePtr& aOther) = delete; // construct using Move()!
   void operator=(const UniquePtr& aOther) = delete; // assign using Move()!
 };
 
-/** A default deletion policy using plain old operator delete. */
+/**
+ * A default deletion policy using plain old operator delete.
+ *
+ * Note that this type can be specialized, but authors should beware of the risk
+ * that the specialization may at some point cease to match (either because it
+ * gets moved to a different compilation unit or the signature changes). If the
+ * non-specialized (|delete|-based) version compiles for that type but does the
+ * wrong thing, bad things could happen.
+ *
+ * This is a non-issue for types which are always incomplete (i.e. opaque handle
+ * types), since |delete|-ing such a type will always trigger a compilation
+ * error.
+ */
 template<typename T>
 class DefaultDelete
 {
 public:
   MOZ_CONSTEXPR DefaultDelete() {}
 
   template<typename U>
   MOZ_IMPLICIT DefaultDelete(const DefaultDelete<U>& aOther,