Bug 1373018 - Part 10: stylo: Remove StyleSource; r=bholley

MozReview-Commit-ID: 4IcROeDNoBA

--HG--
extra : rebase_source : e2f65c316be2c5640150eb5ff5628505ce446535
This commit is contained in:
Manish Goregaokar 2017-06-10 22:27:45 -07:00
parent abdbfa30c6
commit 3188b9bfd6
21 changed files with 73 additions and 160 deletions

View File

@ -170,7 +170,7 @@ FindAnimationsForCompositor(const nsIFrame* aFrame,
EffectCompositor::GetAnimationElementAndPseudoForFrame(aFrame);
if (pseudoElement) {
StyleBackendType backend =
aFrame->StyleContext()->StyleSource().IsServoComputedValues()
aFrame->StyleContext()->IsServo()
? StyleBackendType::Servo
: StyleBackendType::Gecko;
EffectCompositor::MaybeUpdateCascadeResults(backend,

View File

@ -302,7 +302,7 @@ KeyframeEffectReadOnly::UpdateProperties(nsStyleContext* aStyleContext)
}
const ServoComputedValues* currentStyle =
aStyleContext->StyleSource().AsServoComputedValues();
aStyleContext->ComputedValues();
DoUpdateProperties(currentStyle);
}

View File

@ -69,7 +69,7 @@ nsSMILCSSProperty::GetBaseValue() const
AnimationValue computedValue;
if (mElement->IsStyledByServo()) {
const ServoComputedValues* currentStyle =
mBaseStyleContext->StyleSource().AsServoComputedValues();
mBaseStyleContext->ComputedValues();
computedValue.mServo =
Servo_ComputedValues_ExtractAnimationValue(currentStyle, mPropID)
.Consume();

View File

@ -701,7 +701,7 @@ ValueFromStringHelper(nsCSSPropertyID aPropID,
// Get a suitable style context for Servo
const ServoComputedValues* currentStyle =
aStyleContext->StyleSource().AsServoComputedValues();
aStyleContext->ComputedValues();
// Compute value
aPresContext->StyleSet()->AsServo()->GetAnimationValues(servoDeclarationBlock,

View File

@ -382,7 +382,7 @@ ServoRestyleManager::ProcessPostTraversal(Element* aElement,
// elements, though that is buggy right now even in non-stylo mode, see
// bug 1251799.
const bool recreateContext = oldStyleContext &&
oldStyleContext->StyleSource().AsServoComputedValues() != computedValues;
oldStyleContext->ComputedValues() != computedValues;
RefPtr<nsStyleContext> newContext = nullptr;
if (recreateContext) {

View File

@ -7198,7 +7198,7 @@ nsIFrame::ListGeneric(nsACString& aTo, const char* aPrefix, uint32_t aFlags) con
pseudoTag->ToString(atomString);
aTo += nsPrintfCString("%s", NS_LossyConvertUTF16toASCII(atomString).get());
}
if (mStyleContext->StyleSource().IsGeckoRuleNodeOrNull()) {
if (mStyleContext->IsGecko()) {
if (!mStyleContext->GetParent() ||
(GetParent() && GetParent()->StyleContext() != mStyleContext->GetParent())) {
aTo += nsPrintfCString("^%p", mStyleContext->GetParent());

View File

@ -243,14 +243,13 @@ inDOMUtils::GetCSSStyleRules(nsIDOMElement *aElement,
return NS_OK;
}
NonOwningStyleContextSource source = styleContext->StyleSource();
if (source.IsNull()) {
return NS_OK;
}
nsCOMPtr<nsIMutableArray> rules = nsArray::Create();
if (source.IsGeckoRuleNodeOrNull()) {
nsRuleNode* ruleNode = source.AsGeckoRuleNode();
if (auto gecko = styleContext->GetAsGecko()) {
nsRuleNode* ruleNode = gecko->RuleNode();
if (!ruleNode) {
return NS_OK;
}
AutoTArray<nsRuleNode*, 16> ruleNodes;
while (!ruleNode->IsRoot()) {

View File

@ -212,7 +212,7 @@ GeckoStyleContext::FindChildWithRules(const nsIAtom* aPseudoTag,
if (list) {
GeckoStyleContext *child = list;
do {
if (child->StyleSource() == aSource &&
if (child->RuleNode() == aSource &&
child->mPseudoTag == aPseudoTag &&
!child->IsStyleIfVisited() &&
child->RelevantLinkVisited() == aRelevantLinkVisited) {

View File

@ -94,10 +94,6 @@ public:
bool HasNoChildren() const;
NonOwningStyleContextSource StyleSource() const {
return NonOwningStyleContextSource(mRuleNode);
}
nsRuleNode* RuleNode() const {
MOZ_ASSERT(mRuleNode);
return mRuleNode;

View File

@ -23,9 +23,6 @@ public:
return mPresContext;
}
NonOwningStyleContextSource StyleSource() const {
return NonOwningStyleContextSource(mSource);
}
ServoComputedValues* ComputedValues() const {
return mSource;
}

View File

@ -441,7 +441,7 @@ ServoStyleSet::ResolveStyleForText(nsIContent* aTextNode,
// enough to do on the main thread, which means that the parallel style system
// can avoid worrying about text nodes.
const ServoComputedValues* parentComputedValues =
aParentContext->StyleSource().AsServoComputedValues();
aParentContext->ComputedValues();
RefPtr<ServoComputedValues> computedValues =
Servo_ComputedValues_Inherit(mRawSet.get(),
parentComputedValues,
@ -457,7 +457,7 @@ already_AddRefed<nsStyleContext>
ServoStyleSet::ResolveStyleForFirstLetterContinuation(nsStyleContext* aParentContext)
{
const ServoComputedValues* parent =
aParentContext->StyleSource().AsServoComputedValues();
aParentContext->ComputedValues();
RefPtr<ServoComputedValues> computedValues =
Servo_ComputedValues_Inherit(mRawSet.get(),
parent,
@ -571,7 +571,7 @@ ServoStyleSet::ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
nsCSSAnonBoxes::AnonBoxSkipsParentDisplayBasedStyleFixup(aPseudoTag);
const ServoComputedValues* parentStyle =
aParentContext ? aParentContext->StyleSource().AsServoComputedValues()
aParentContext ? aParentContext->ComputedValues()
: nullptr;
RefPtr<ServoComputedValues> computedValues =
Servo_ComputedValues_GetForAnonymousBox(parentStyle, aPseudoTag, skipFixup,

View File

@ -4789,7 +4789,7 @@ StyleAnimationValue::ExtractComputedValue(nsCSSPropertyID aProperty,
eUnit_Visibility);
return true;
}
if (aStyleContext->StyleSource().IsServoComputedValues()) {
if (aStyleContext->IsServo()) {
NS_ERROR("stylo: extracting discretely animated values not supported");
return false;
}
@ -5360,7 +5360,7 @@ AnimationValue::FromString(nsCSSPropertyID aProperty,
RefPtr<nsStyleContext> styleContext =
nsComputedDOMStyle::GetStyleContext(aElement, nullptr, shell);
if (styleContext->StyleSource().IsServoComputedValues()) {
if (auto servoContext = styleContext->GetAsServo()) {
nsPresContext* presContext = shell->GetPresContext();
if (!presContext) {
return result;
@ -5374,7 +5374,7 @@ AnimationValue::FromString(nsCSSPropertyID aProperty,
}
const ServoComputedValues* computedValues =
styleContext->StyleSource().AsServoComputedValues();
servoContext->ComputedValues();
result.mServo = presContext->StyleSet()
->AsServo()
->ComputeAnimationValue(aElement,

View File

@ -1,79 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef mozilla_StyleContextSource_h
#define mozilla_StyleContextSource_h
#include "mozilla/ServoBindingTypes.h"
#include "nsRuleNode.h"
namespace mozilla {
// Tagged union between Gecko Rule Nodes and Servo Computed Values.
//
// The rule node is the node in the lexicographic tree of rule nodes
// (the "rule tree") that indicates which style rules are used to
// compute the style data, and in what cascading order. The least
// specific rule matched is the one whose rule node is a child of the
// root of the rule tree, and the most specific rule matched is the
// |mRule| member of the rule node.
//
// In the Servo case, we hold an atomically-refcounted handle to a
// Servo ComputedValues struct, which is more or less the Servo equivalent
// of an nsStyleContext.
// Underlying pointer without any strong ownership semantics.
struct NonOwningStyleContextSource
{
MOZ_IMPLICIT NonOwningStyleContextSource(nsRuleNode* aRuleNode)
: mBits(reinterpret_cast<uintptr_t>(aRuleNode)) {}
explicit NonOwningStyleContextSource(const ServoComputedValues* aComputedValues)
: mBits(reinterpret_cast<uintptr_t>(aComputedValues) | 1) {}
bool operator==(const NonOwningStyleContextSource& aOther) const {
MOZ_ASSERT(IsServoComputedValues() == aOther.IsServoComputedValues(),
"Comparing Servo to Gecko - probably a bug");
return mBits == aOther.mBits;
}
bool operator!=(const NonOwningStyleContextSource& aOther) const {
return !(*this == aOther);
}
// We intentionally avoid exposing IsGeckoRuleNode() here, because that would
// encourage callers to do:
//
// if (source.IsGeckoRuleNode()) {
// // Code that we would run unconditionally if it weren't for Servo.
// }
//
// We want these branches to compile away when MOZ_STYLO is disabled, but that
// won't happen if there's an implicit null-check.
bool IsNull() const { return !mBits; }
bool IsGeckoRuleNodeOrNull() const { return !IsServoComputedValues(); }
bool IsServoComputedValues() const {
#ifdef MOZ_STYLO
return mBits & 1;
#else
return false;
#endif
}
nsRuleNode* AsGeckoRuleNode() const {
MOZ_ASSERT(IsGeckoRuleNodeOrNull() && !IsNull());
return reinterpret_cast<nsRuleNode*>(mBits);
}
const ServoComputedValues* AsServoComputedValues() const {
MOZ_ASSERT(IsServoComputedValues());
return reinterpret_cast<ServoComputedValues*>(mBits & ~1);
}
private:
uintptr_t mBits;
};
} // namespace mozilla
#endif // mozilla_StyleContextSource_h

View File

@ -129,7 +129,6 @@ EXPORTS.mozilla += [
'StyleAnimationValue.h',
'StyleBackendType.h',
'StyleComplexColor.h',
'StyleContextSource.h',
'StyleSetHandle.h',
'StyleSetHandleInlines.h',
'StyleSheet.h',

View File

@ -564,7 +564,7 @@ MustReresolveStyle(const nsStyleContext* aContext)
if (aContext->HasPseudoElementData()) {
if (!aContext->GetPseudo() ||
aContext->StyleSource().IsServoComputedValues()) {
aContext->IsServo()) {
// TODO(emilio): When ::first-line is supported in Servo, we may want to
// fix this to avoid re-resolving pseudo-element styles.
return true;
@ -871,7 +871,7 @@ nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush)
if (!mStyleContext || MustReresolveStyle(mStyleContext)) {
#ifdef DEBUG
if (mStyleContext && mStyleContext->StyleSource().IsGeckoRuleNodeOrNull()) {
if (mStyleContext && mStyleContext->IsGecko()) {
// We want to check that going through this path because of
// HasPseudoElementData is rare, because it slows us down a good
// bit. So check that we're really inside something associated

View File

@ -10401,7 +10401,7 @@ nsRuleNode::HasAuthorSpecifiedRules(nsStyleContext* aStyleContext,
bool aAuthorColorsAllowed)
{
#ifdef MOZ_STYLO
if (aStyleContext->StyleSource().IsServoComputedValues()) {
if (aStyleContext->IsServo()) {
NS_WARNING("stylo: nsRuleNode::HasAuthorSpecifiedRules not implemented");
return true;
}

View File

@ -104,9 +104,14 @@ nsStyleContext::FinishConstruction()
static_cast<CSSPseudoElementTypeBase>(
CSSPseudoElementType::MAX),
"pseudo element bits no longer fit in a uint64_t");
MOZ_ASSERT(!StyleSource().IsNull());
#ifdef DEBUG
if (auto servo = GetAsServo()) {
MOZ_ASSERT(servo->ComputedValues());
} else {
MOZ_ASSERT(RuleNode());
}
static_assert(MOZ_ARRAY_LENGTH(nsStyleContext::sDependencyTable)
== nsStyleStructID_Length,
"Number of items in dependency table doesn't match IDs");
@ -127,12 +132,12 @@ nsStyleContext::FinishConstruction()
void
nsStyleContext::Destructor()
{
#ifdef DEBUG
if (const GeckoStyleContext* gecko = GetAsGecko()) {
NS_ASSERTION(gecko->HasNoChildren(), "destructing context with children");
}
MOZ_ASSERT(!IsServo() || !mCachedResetData);
#ifdef DEBUG
if (IsServo()) {
MOZ_ASSERT(!mCachedResetData,
"Servo shouldn't cache reset structs in nsStyleContext");
@ -575,10 +580,6 @@ public:
explicit FakeStyleContext(const ServoComputedValues* aComputedValues)
: mComputedValues(aComputedValues) {}
mozilla::NonOwningStyleContextSource StyleSource() const {
return mozilla::NonOwningStyleContextSource(mComputedValues);
}
nsStyleContext* GetStyleIfVisited() {
// Bug 1364484: Figure out what to do here for Stylo visited values. We can
// get the visited computed values:
@ -688,12 +689,6 @@ void nsStyleContext::List(FILE* out, int32_t aIndent, bool aListDescendants)
}
#endif
NonOwningStyleContextSource
nsStyleContext::StyleSource() const
{
MOZ_STYLO_FORWARD(StyleSource, ())
}
// Overridden to prevent the global delete from being called, since the memory
// came out of an nsIArena instead of the global delete operator's heap.
void

View File

@ -12,7 +12,6 @@
#include "mozilla/RestyleLogging.h"
#include "mozilla/ServoStyleSet.h"
#include "mozilla/ServoUtils.h"
#include "mozilla/StyleContextSource.h"
#include "mozilla/StyleComplexColor.h"
#include "nsCSSAnonBoxes.h"
#include "nsStyleSet.h"
@ -270,6 +269,7 @@ public:
}
inline nsRuleNode* RuleNode();
inline ServoComputedValues* ComputedValues();
void AddStyleBit(const uint64_t& aBit) { mBits |= aBit; }
@ -438,8 +438,6 @@ public:
return cachedData;
}
mozilla::NonOwningStyleContextSource StyleSource() const;
protected:
// protected destructor to discourage deletion outside of Release()
~nsStyleContext() {}
@ -466,7 +464,7 @@ protected:
switch (aSID) {
#define STYLE_STRUCT(name_, checkdata_cb_) \
case eStyleStruct_##name_: \
return Servo_GetStyle##name_(StyleSource().AsServoComputedValues());
return Servo_GetStyle##name_(ComputedValues());
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
default:

View File

@ -30,6 +30,13 @@ nsStyleContext::RuleNode()
return AsGecko()->RuleNode();
}
ServoComputedValues*
nsStyleContext::ComputedValues()
{
MOZ_RELEASE_ASSERT(IsServo());
return AsServo()->ComputedValues();
}
#define STYLE_STRUCT(name_, checkdata_cb_) \
const nsStyle##name_ * \
nsStyleContext::Style##name_() { \
@ -52,7 +59,7 @@ const nsStyle##name_ * nsStyleContext::PeekStyle##name_() { \
#define STYLE_STRUCT_INHERITED(name_, checkdata_cb_) \
template<bool aComputeData> \
const nsStyle##name_ * nsStyleContext::DoGetStyle##name_() { \
if (IsGecko()) { \
if (auto gecko = GetAsGecko()) { \
const nsStyle##name_ * cachedData = \
static_cast<nsStyle##name_*>( \
mCachedInheritedData.mStyleStructs[eStyleStruct_##name_]); \
@ -66,7 +73,7 @@ const nsStyle##name_ * nsStyleContext::DoGetStyle##name_() { \
/* Have the rulenode deal */ \
AUTO_CHECK_DEPENDENCY(eStyleStruct_##name_); \
const nsStyle##name_ * newData = \
StyleSource().AsGeckoRuleNode()-> \
gecko->RuleNode()-> \
GetStyle##name_<aComputeData>(this->AsGecko(), mBits); \
/* always cache inherited data on the style context; the rule */\
/* node set the bit in mBits for us if needed. */ \
@ -74,6 +81,7 @@ const nsStyle##name_ * nsStyleContext::DoGetStyle##name_() { \
const_cast<nsStyle##name_ *>(newData); \
return newData; \
} \
auto servo = AsServo(); \
/** \
* Also (conservatively) set the owning bit in the parent style \
* context if we're a text node. \
@ -108,47 +116,47 @@ const nsStyle##name_ * nsStyleContext::DoGetStyle##name_() { \
} \
\
const nsStyle##name_* data = \
Servo_GetStyle##name_(StyleSource().AsServoComputedValues()); \
Servo_GetStyle##name_(servo->ComputedValues()); \
/* perform any remaining main thread work on the struct */ \
if (needToCompute) { \
MOZ_ASSERT(NS_IsMainThread()); \
MOZ_ASSERT(!mozilla::ServoStyleSet::IsInServoTraversal()); \
const_cast<nsStyle##name_*>(data)->FinishStyle(PresContext()); \
/* the Servo-backed StyleContextSource owns the struct */ \
/* the ServoStyleContext owns the struct */ \
AddStyleBit(NS_STYLE_INHERIT_BIT(name_)); \
} \
return data; \
}
#define STYLE_STRUCT_RESET(name_, checkdata_cb_) \
template<bool aComputeData> \
const nsStyle##name_ * nsStyleContext::DoGetStyle##name_() { \
if (IsGecko()) { \
if (mCachedResetData) { \
const nsStyle##name_ * cachedData = \
static_cast<nsStyle##name_*>( \
mCachedResetData->mStyleStructs[eStyleStruct_##name_]); \
if (cachedData) /* Have it cached already, yay */ \
return cachedData; \
} \
/* Have the rulenode deal */ \
AUTO_CHECK_DEPENDENCY(eStyleStruct_##name_); \
return StyleSource().AsGeckoRuleNode()-> \
GetStyle##name_<aComputeData>(this->AsGecko()); \
} \
const bool needToCompute = !(mBits & NS_STYLE_INHERIT_BIT(name_));\
if (!aComputeData && needToCompute) { \
return nullptr; \
} \
const nsStyle##name_* data = \
Servo_GetStyle##name_(StyleSource().AsServoComputedValues()); \
/* perform any remaining main thread work on the struct */ \
if (needToCompute) { \
const_cast<nsStyle##name_*>(data)->FinishStyle(PresContext()); \
/* the Servo-backed StyleContextSource owns the struct */ \
AddStyleBit(NS_STYLE_INHERIT_BIT(name_)); \
} \
return data; \
#define STYLE_STRUCT_RESET(name_, checkdata_cb_) \
template<bool aComputeData> \
const nsStyle##name_ * nsStyleContext::DoGetStyle##name_() { \
if (auto gecko = GetAsGecko()) { \
if (mCachedResetData) { \
const nsStyle##name_ * cachedData = \
static_cast<nsStyle##name_*>( \
mCachedResetData->mStyleStructs[eStyleStruct_##name_]); \
if (cachedData) /* Have it cached already, yay */ \
return cachedData; \
} \
/* Have the rulenode deal */ \
AUTO_CHECK_DEPENDENCY(eStyleStruct_##name_); \
return gecko->RuleNode()->GetStyle##name_<aComputeData>(this->AsGecko()); \
} \
auto servo = AsServo(); \
const bool needToCompute = !(mBits & NS_STYLE_INHERIT_BIT(name_)); \
if (!aComputeData && needToCompute) { \
return nullptr; \
} \
const nsStyle##name_* data = \
Servo_GetStyle##name_(servo->ComputedValues()); \
/* perform any remaining main thread work on the struct */ \
if (needToCompute) { \
const_cast<nsStyle##name_*>(data)->FinishStyle(PresContext()); \
/* the ServoStyleContext owns the struct */ \
AddStyleBit(NS_STYLE_INHERIT_BIT(name_)); \
} \
return data; \
}
#include "nsStyleStructList.h"
#undef STYLE_STRUCT_RESET

View File

@ -514,7 +514,7 @@ ProcessMatrixOperator(Matrix4x4& aMatrix,
Matrix4x4 matrix2 = readTransform(aData->Item(2));
double progress = aData->Item(3).GetPercentValue();
if (aContext && aContext->StyleSource().IsServoComputedValues()) {
if (aContext && aContext->IsServo()) {
aMatrix =
OperateTransformMatrixByServo<Operator>(matrix1, matrix2, progress)
* aMatrix;

View File

@ -297,7 +297,7 @@ nsTableColGroupFrame::RemoveFrame(ChildListID aListID,
#ifdef DEBUG
nsIFrame* providerFrame;
nsStyleContext* psc = colFrame->GetParentStyleContext(&providerFrame);
if (psc->StyleSource().IsGeckoRuleNodeOrNull()) {
if (psc->IsGecko()) {
// This check code is useful only in Gecko-backed style system.
if (static_cast<nsStyleContext*>(colFrame->StyleContext()->GetParent()) == psc) {
NS_ASSERTION(col->StyleContext() == colFrame->StyleContext() &&