Bug 1367904 - Part 3: stylo: Move mPresContext to ServoStyleContext; stop using arena; r?bholley draft
authorManish Goregaokar <manishearth@gmail.com>
Sat, 10 Jun 2017 22:27:45 -0700
changeset 593879 30d4baccf8b8cb7fdd5c08cbca70cce59493e920
parent 593878 7480dfca349e6ad54c3cf6056a7fdacc7777ced4
child 593880 c96341cdd784d3d89a0ecef65bb87786f6fc379e
push id63848
push userbmo:manishearth@gmail.com
push dateWed, 14 Jun 2017 08:07:45 +0000
reviewersbholley
bugs1367904
milestone55.0a1
Bug 1367904 - Part 3: stylo: Move mPresContext to ServoStyleContext; stop using arena; r?bholley MozReview-Commit-ID: 2BmRpIjxEO8
layout/style/GeckoStyleContext.cpp
layout/style/GeckoStyleContext.h
layout/style/ServoStyleContext.cpp
layout/style/ServoStyleContext.h
layout/style/nsStyleContext.cpp
layout/style/nsStyleContext.h
layout/style/nsStyleContextInlines.h
--- a/layout/style/GeckoStyleContext.cpp
+++ b/layout/style/GeckoStyleContext.cpp
@@ -16,19 +16,16 @@ GeckoStyleContext::GeckoStyleContext(nsS
                                      nsIAtom* aPseudoTag,
                                      CSSPseudoElementType aPseudoType,
                                      already_AddRefed<nsRuleNode> aRuleNode,
                                      bool aSkipParentDisplayBasedStyleFixup)
   : nsStyleContext(aParent, OwningStyleContextSource(Move(aRuleNode)),
                    aPseudoTag, aPseudoType)
 {
   mBits |= NS_STYLE_CONTEXT_IS_GECKO;
-#ifdef MOZ_STYLO
-  mPresContext = mSource.AsGeckoRuleNode()->PresContext();
-#endif
 
   if (aParent) {
 #ifdef DEBUG
     nsRuleNode *r1 = mParent->RuleNode(), *r2 = mSource.AsGeckoRuleNode();
     while (r1->GetParent())
       r1 = r1->GetParent();
     while (r2->GetParent())
       r2 = r2->GetParent();
--- a/layout/style/GeckoStyleContext.h
+++ b/layout/style/GeckoStyleContext.h
@@ -15,13 +15,17 @@ class GeckoStyleContext final : public n
 public:
   GeckoStyleContext(nsStyleContext* aParent,
                     nsIAtom* aPseudoTag,
                     CSSPseudoElementType aPseudoType,
                     already_AddRefed<nsRuleNode> aRuleNode,
                     bool aSkipParentDisplayBasedStyleFixup);
 
   void* operator new(size_t sz, nsPresContext* aPresContext);
+
+  nsPresContext* PresContext() const {
+    return mSource.AsGeckoRuleNode()->PresContext();
+  }
 };
 
 }
 
 #endif // mozilla_GeckoStyleContext_h
--- a/layout/style/ServoStyleContext.cpp
+++ b/layout/style/ServoStyleContext.cpp
@@ -16,17 +16,15 @@ using namespace mozilla;
 ServoStyleContext::ServoStyleContext(nsStyleContext* aParent,
                                nsPresContext* aPresContext,
                                nsIAtom* aPseudoTag,
                                CSSPseudoElementType aPseudoType,
                                already_AddRefed<ServoComputedValues> aComputedValues)
   : nsStyleContext(aParent, OwningStyleContextSource(Move(aComputedValues)),
                    aPseudoTag, aPseudoType)
 {
-#ifdef MOZ_STYLO
   mPresContext = aPresContext;
-#endif
 
   FinishConstruction();
 
   // No need to call ApplyStyleFixups here, since fixups are handled by Servo when
   // producing the ServoComputedValues.
 }
--- a/layout/style/ServoStyleContext.h
+++ b/layout/style/ServoStyleContext.h
@@ -13,13 +13,20 @@ namespace mozilla {
 
 class ServoStyleContext final : public nsStyleContext {
 public:
   ServoStyleContext(nsStyleContext* aParent,
                     nsPresContext* aPresContext,
                     nsIAtom* aPseudoTag,
                     CSSPseudoElementType aPseudoType,
                     already_AddRefed<ServoComputedValues> aComputedValues);
+
+  nsPresContext* PresContext() const {
+    return mPresContext;
+  }
+
+private:
+  nsPresContext* mPresContext;
 };
 
 }
 
 #endif // mozilla_ServoStyleContext_h
--- a/layout/style/nsStyleContext.cpp
+++ b/layout/style/nsStyleContext.cpp
@@ -86,19 +86,16 @@ nsStyleContext::nsStyleContext(nsStyleCo
                                OwningStyleContextSource&& aSource,
                                nsIAtom* aPseudoTag,
                                CSSPseudoElementType aPseudoType)
   : mParent(aParent)
   , mChild(nullptr)
   , mEmptyChild(nullptr)
   , mPseudoTag(aPseudoTag)
   , mSource(Move(aSource))
-#ifdef MOZ_STYLO
-  , mPresContext(nullptr)
-#endif
   , mCachedResetData(nullptr)
   , mBits(((uint64_t)aPseudoType) << NS_STYLE_CONTEXT_TYPE_SHIFT)
   , mRefCnt(0)
 #ifdef DEBUG
   , mFrameRefCnt(0)
   , mComputingStruct(nsStyleStructID_None)
 #endif
 {}
--- a/layout/style/nsStyleContext.h
+++ b/layout/style/nsStyleContext.h
@@ -123,23 +123,17 @@ public:
 
   bool HasSingleReference() const {
     NS_ASSERTION(mRefCnt != 0,
                  "do not call HasSingleReference on a newly created "
                  "nsStyleContext with no references yet");
     return mRefCnt == 1;
   }
 
-  nsPresContext* PresContext() const {
-#ifdef MOZ_STYLO
-    return mPresContext;
-#else
-    return mSource.AsGeckoRuleNode()->PresContext();
-#endif
-  }
+  nsPresContext* PresContext() const;
 
   nsStyleContext* GetParent() const {
     MOZ_ASSERT(mSource.IsGeckoRuleNode(),
                "This should be used only in Gecko-backed style system!");
     return mParent;
   }
 
   nsStyleContext* GetParentAllowServo() const {
@@ -726,22 +720,16 @@ protected:
   // the relevant atom.
   nsCOMPtr<nsIAtom> mPseudoTag;
 
   // The source for our style data, either a Gecko nsRuleNode or a Servo
   // ComputedValues struct. This never changes after construction, except
   // when it's released and nulled out during teardown.
   const mozilla::OwningStyleContextSource mSource;
 
-#ifdef MOZ_STYLO
-  // In Gecko, we can get this off the rule node. We make this conditional
-  // on stylo builds to avoid the memory bloat on release.
-  nsPresContext* mPresContext;
-#endif
-
   // mCachedInheritedData and mCachedResetData point to both structs that
   // are owned by this style context and structs that are owned by one of
   // this style context's ancestors (which are indirectly owned since this
   // style context owns a reference to its parent).  If the bit in |mBits|
   // is set for a struct, that means that the pointer for that struct is
   // owned by an ancestor or by the rule node rather than by this style context.
   // Since style contexts typically have some inherited data but only sometimes
   // have reset data, we always allocate the mCachedInheritedData, but only
new file mode 100644
--- /dev/null
+++ b/layout/style/nsStyleContextInlines.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/. */
+
+/*
+ * Inlined methods for nsStyleContext. Will just redirect to
+ * GeckoStyleContext methods when compiled without stylo, but will do
+ * virtual dispatch (by checking which kind of container it is)
+ * in stylo mode.
+ */
+
+#ifndef mozilla_nsStyleContextInlines_h
+#define mozilla_nsStyleContextInlines_h
+
+#include "nsStyleContext.h"
+#include "mozilla/ServoStyleContext.h"
+#include "mozilla/GeckoStyleContext.h"
+#include "mozilla/ServoUtils.h"
+
+using namespace mozilla;
+
+MOZ_DEFINE_STYLO_METHODS(nsStyleContext, GeckoStyleContext, ServoStyleContext);
+
+nsPresContext*
+nsStyleContext::PresContext() const
+{
+    MOZ_STYLO_FORWARD(PresContext, ())
+}
+
+#endif // mozilla_nsStyleContextInlines_h