From 64ee30fc47ffb007e1457708cd27f1ec8e8be614 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Sun, 30 Apr 2017 14:41:11 +0800 Subject: [PATCH] Bug 1356103 - Part 3: Make it easy to access the ServoStyleSet currently in traversal. r=bholley In a later patch, we'll want to queue up some tasks to run when the Servo traversal is one, and the ServoStyleSet seems like the natural place to store those tasks. We could probably find the ServoStyleSet by chasing a bunch of pointers from the task-adding call sites, but it seems simpler just to make it available directly. MozReview-Commit-ID: AJoFZEoNaGm --HG-- extra : rebase_source : d8afe0c2cdf1ea4b1681c6e57aea48c9efddea00 --- layout/style/ServoStyleSet.cpp | 12 ++++-------- layout/style/ServoStyleSet.h | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/layout/style/ServoStyleSet.cpp b/layout/style/ServoStyleSet.cpp index 6b7f8cbf4d05..f7a04c28c8c8 100644 --- a/layout/style/ServoStyleSet.cpp +++ b/layout/style/ServoStyleSet.cpp @@ -295,8 +295,7 @@ ServoStyleSet::PrepareAndTraverseSubtree(RawGeckoElementBorrowed aRoot, // is necessary to avoid a data race when updating the cache. mozilla::Unused << aRoot->OwnerDoc()->GetRootElement(); - MOZ_ASSERT(!sInServoTraversal); - sInServoTraversal = true; + AutoSetInServoTraversal guard(this); bool isInitial = !aRoot->HasServoData(); bool forReconstruct = @@ -338,7 +337,6 @@ ServoStyleSet::PrepareAndTraverseSubtree(RawGeckoElementBorrowed aRoot, } } - sInServoTraversal = false; return postTraversalRequired; } @@ -983,8 +981,8 @@ already_AddRefed ServoStyleSet::ResolveStyleLazily(Element* aElement, nsIAtom* aPseudoTag) { mPresContext->EffectCompositor()->PreTraverse(aElement, aPseudoTag); - MOZ_ASSERT(!sInServoTraversal); - sInServoTraversal = true; + + AutoSetInServoTraversal guard(this); /** * NB: This is needed because we process animations and transitions on the @@ -1023,8 +1021,6 @@ ServoStyleSet::ResolveStyleLazily(Element* aElement, nsIAtom* aPseudoTag) mRawSet.get()).Consume(); } - sInServoTraversal = false; - return computedValues.forget(); } @@ -1110,4 +1106,4 @@ ServoStyleSet::RemoveSheetOfType(SheetType aType, return 0; } -bool ServoStyleSet::sInServoTraversal = false; +ServoStyleSet* ServoStyleSet::sInServoTraversal = nullptr; diff --git a/layout/style/ServoStyleSet.h b/layout/style/ServoStyleSet.h index cff75f8ba6f3..540a18401da9 100644 --- a/layout/style/ServoStyleSet.h +++ b/layout/style/ServoStyleSet.h @@ -85,6 +85,11 @@ public: return sInServoTraversal; } + static ServoStyleSet* Current() + { + return sInServoTraversal; + } + ServoStyleSet(); ~ServoStyleSet(); @@ -309,6 +314,23 @@ public: const ServoComputedValuesWithParent& aComputedValues); private: + class MOZ_STACK_CLASS AutoSetInServoTraversal + { + public: + AutoSetInServoTraversal(ServoStyleSet* aSet) + { + MOZ_ASSERT(!sInServoTraversal); + MOZ_ASSERT(aSet); + sInServoTraversal = aSet; + } + + ~AutoSetInServoTraversal() + { + MOZ_ASSERT(sInServoTraversal); + sInServoTraversal = nullptr; + } + }; + already_AddRefed GetContext(already_AddRefed, nsStyleContext* aParentContext, nsIAtom* aPseudoTag, @@ -399,7 +421,7 @@ private: nsCSSAnonBoxes::NonInheriting::_Count, RefPtr> mNonInheritingStyleContexts; - static bool sInServoTraversal; + static ServoStyleSet* sInServoTraversal; }; } // namespace mozilla