Bug 1304913 - Have Servo manage node data directly without FFI calls. r=Manishearth

MozReview-Commit-ID: H8f8VP18TbM
This commit is contained in:
Bobby Holley 2016-09-21 15:42:45 -07:00
Родитель 6981487fab
Коммит 6351b3ffb8
12 изменённых файлов: 78 добавлений и 56 удалений

Просмотреть файл

@ -1742,7 +1742,7 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
// So for now, we just mark nodes as dirty when they're inserted into a
// document or shadow tree.
if (IsStyledByServo() && IsInComposedDoc()) {
MOZ_ASSERT(!ServoData().get());
MOZ_ASSERT(!HasServoData());
SetIsDirtyForServo();
}
@ -1857,10 +1857,10 @@ Element::UnbindFromTree(bool aDeep, bool aNullParent)
// Computed styled data isn't useful for detached nodes, and we'll need to
// recomputed it anyway if we ever insert the nodes back into a document.
if (IsStyledByServo()) {
ServoData().reset();
ClearServoData();
} else {
#ifdef MOZ_STYLO
MOZ_ASSERT(!ServoData());
MOZ_ASSERT(!HasServoData());
#endif
}

Просмотреть файл

@ -567,7 +567,7 @@ nsGenericDOMDataNode::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
// So for now, we just mark nodes as dirty when they're inserted into a
// document or shadow tree.
if (IsStyledByServo() && IsInComposedDoc()) {
MOZ_ASSERT(!ServoData().get());
MOZ_ASSERT(!HasServoData());
SetIsDirtyForServo();
}
@ -605,10 +605,10 @@ nsGenericDOMDataNode::UnbindFromTree(bool aDeep, bool aNullParent)
// Computed styled data isn't useful for detached nodes, and we'll need to
// recomputed it anyway if we ever insert the nodes back into a document.
if (IsStyledByServo()) {
ServoData().reset();
ClearServoData();
} else {
#ifdef MOZ_STYLO
MOZ_ASSERT(!ServoData());
MOZ_ASSERT(!HasServoData());
#endif
}

Просмотреть файл

@ -152,6 +152,9 @@ nsINode::~nsINode()
{
MOZ_ASSERT(!HasSlots(), "nsNodeUtils::LastRelease was not called?");
MOZ_ASSERT(mSubtreeRoot == this, "Didn't restore state properly?");
#ifdef MOZ_STYLO
ClearServoData();
#endif
}
void*

Просмотреть файл

@ -8,6 +8,7 @@
#define nsINode_h___
#include "mozilla/Likely.h"
#include "mozilla/ServoTypes.h"
#include "mozilla/UniquePtr.h"
#include "nsCOMPtr.h" // for member, local
#include "nsGkAtoms.h" // for nsGkAtoms::baseURIProperty
@ -53,21 +54,7 @@ class nsNodeSupportsWeakRefTearoff;
class nsNodeWeakReference;
class nsDOMMutationObserver;
// We declare the bare minimum infrastructure here to allow us to have a
// UniquePtr<ServoNodeData> on nsINode.
struct ServoNodeData;
extern "C" void Servo_NodeData_Drop(ServoNodeData*);
namespace mozilla {
template<>
class DefaultDelete<ServoNodeData>
{
public:
void operator()(ServoNodeData* aPtr) const
{
Servo_NodeData_Drop(aPtr);
}
};
} // namespace mozilla
extern "C" void Servo_Node_ClearNodeData(nsINode*);
namespace mozilla {
class EventListenerManager;
@ -2090,9 +2077,17 @@ public:
#undef TOUCH_EVENT
#undef EVENT
mozilla::UniquePtr<ServoNodeData>& ServoData() {
bool HasServoData() {
#ifdef MOZ_STYLO
return mServoNodeData;
return !!mServoData.Get();
#else
MOZ_CRASH("Accessing servo node data in non-stylo build");
#endif
}
void ClearServoData() {
#ifdef MOZ_STYLO
Servo_Node_ClearNodeData(this);
#else
MOZ_CRASH("Accessing servo node data in non-stylo build");
#endif
@ -2137,8 +2132,8 @@ protected:
nsSlots* mSlots;
#ifdef MOZ_STYLO
// Layout data managed by Servo.
mozilla::UniquePtr<ServoNodeData> mServoNodeData;
// Per-node data managed by Servo.
mozilla::ServoCell<ServoNodeData*> mServoData;
#endif
};

Просмотреть файл

@ -386,7 +386,7 @@ ServoRestyleManager::ContentInserted(nsINode* aContainer, nsIContent* aChild)
return;
}
if (!aContainer->ServoData().get()) {
if (!aContainer->HasServoData()) {
// This can happen with display:none. Bug 1297249 tracks more investigation
// and assertions here.
return;
@ -417,7 +417,7 @@ void
ServoRestyleManager::ContentAppended(nsIContent* aContainer,
nsIContent* aFirstNewContent)
{
if (!aContainer->ServoData().get()) {
if (!aContainer->HasServoData()) {
// This can happen with display:none. Bug 1297249 tracks more investigation
// and assertions here.
return;

Просмотреть файл

@ -10593,13 +10593,13 @@ nsCSSFrameConstructor::AddFCItemsForAnonymousContent(
// This happens when a native anonymous node is used to implement a
// pseudo-element. Allowing Servo to traverse these nodes would be wasted
// work, so assert that we didn't do that.
MOZ_ASSERT_IF(content->IsStyledByServo(), !content->ServoData());
MOZ_ASSERT_IF(content->IsStyledByServo(), !content->HasServoData());
styleContext = aAnonymousItems[i].mStyleContext.forget();
} else {
// If we don't have an explicit style context, that means we need the
// ordinary computed values. Make sure we eagerly cascaded them when the
// anonymous nodes were created.
MOZ_ASSERT_IF(content->IsStyledByServo(), !!content->ServoData());
MOZ_ASSERT_IF(content->IsStyledByServo(), content->HasServoData());
styleContext = ResolveStyleContext(aFrame, content, &aState);
}

Просмотреть файл

@ -19,7 +19,7 @@
*/
// Node data
SERVO_BINDING_FUNC(Servo_NodeData_Drop, void, ServoNodeDataOwned data)
SERVO_BINDING_FUNC(Servo_Node_ClearNodeData, void, RawGeckoNode* node)
// Styleset and Stylesheet management
SERVO_BINDING_FUNC(Servo_StyleSheet_FromUTF8Bytes, RawServoStyleSheetStrong,

Просмотреть файл

@ -569,19 +569,6 @@ SERVO_IMPL_ELEMENT_ATTR_MATCHING_FUNCTIONS(Gecko_Snapshot, ServoElementSnapshot*
#undef SERVO_IMPL_ELEMENT_ATTR_MATCHING_FUNCTIONS
ServoNodeDataBorrowedOrNull
Gecko_GetNodeData(RawGeckoNodeBorrowed aNode)
{
return aNode->ServoData().get();
}
void
Gecko_SetNodeData(RawGeckoNodeBorrowed aNode, ServoNodeDataOwned aData)
{
MOZ_ASSERT(!aNode->ServoData());
aNode->ServoData().reset(aData);
}
nsIAtom*
Gecko_Atomize(const char* aString, uint32_t aLength)
{

Просмотреть файл

@ -7,8 +7,12 @@
#ifndef mozilla_ServoBindings_h
#define mozilla_ServoBindings_h
#include "mozilla/ServoTypes.h"
#include "mozilla/ServoElementSnapshot.h"
#include "mozilla/css/SheetParsingMode.h"
#include "mozilla/dom/Element.h"
#include "nsIDocument.h"
#include "nsINode.h"
#include "nsChangeHint.h"
#include "nsColor.h"
#include "nsProxyRelease.h"
@ -25,24 +29,17 @@
*/
class nsIAtom;
class nsINode;
typedef nsINode RawGeckoNode;
class nsIPrincipal;
class nsIURI;
struct nsFont;
namespace mozilla {
class FontFamilyList;
enum FontFamilyType : uint32_t;
namespace dom { class Element; }
}
using mozilla::FontFamilyList;
using mozilla::FontFamilyType;
using mozilla::dom::Element;
using mozilla::ServoElementSnapshot;
typedef mozilla::dom::Element RawGeckoElement;
class nsIDocument;
typedef nsIDocument RawGeckoDocument;
struct ServoNodeData;
struct ServoComputedValues;
struct RawServoStyleSheet;
struct RawServoStyleSet;
@ -107,8 +104,6 @@ DECL_ARC_REF_TYPE_FOR(RawServoStyleSheet)
DECL_ARC_REF_TYPE_FOR(ServoDeclarationBlock)
DECL_OWNED_REF_TYPE_FOR(RawServoStyleSet)
DECL_NULLABLE_OWNED_REF_TYPE_FOR(ServoNodeData)
DECL_OWNED_REF_TYPE_FOR(ServoNodeData)
DECL_NULLABLE_OWNED_REF_TYPE_FOR(StyleChildrenIterator)
DECL_OWNED_REF_TYPE_FOR(StyleChildrenIterator)
@ -223,10 +218,6 @@ SERVO_DECLARE_ELEMENT_ATTR_MATCHING_FUNCTIONS(Gecko_Snapshot,
// Style attributes.
ServoDeclarationBlockBorrowedOrNull Gecko_GetServoDeclarationBlock(RawGeckoElementBorrowed element);
// Node data.
ServoNodeDataBorrowedOrNull Gecko_GetNodeData(RawGeckoNodeBorrowed node);
void Gecko_SetNodeData(RawGeckoNodeBorrowed node, ServoNodeDataOwned data);
// Atoms.
nsIAtom* Gecko_Atomize(const char* aString, uint32_t aLength);
void Gecko_AddRefAtom(nsIAtom* aAtom);

40
layout/style/ServoTypes.h Normal file
Просмотреть файл

@ -0,0 +1,40 @@
/* -*- 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/. */
#ifndef mozilla_ServoTypes_h
#define mozilla_ServoTypes_h
/*
* Type definitions used to interact with Servo. This gets included by nsINode,
* so don't add significant include dependencies to this file.
*/
struct ServoNodeData;
namespace mozilla {
/*
* Replaced types. These get mapped to associated Servo types in bindgen.
*/
template<typename T>
struct ServoUnsafeCell {
T value;
// Ensure that primitive types (i.e. pointers) get zero-initialized.
ServoUnsafeCell() : value() {};
};
template<typename T>
struct ServoCell {
ServoUnsafeCell<T> value;
T Get() const { return value.value; }
void Set(T arg) { value.value = arg; }
ServoCell() : value() {};
};
} // namespace mozilla
#endif // mozilla_ServoTypes_h

Просмотреть файл

@ -97,6 +97,7 @@ EXPORTS.mozilla += [
'ServoElementSnapshot.h',
'ServoStyleSet.h',
'ServoStyleSheet.h',
'ServoTypes.h',
'SheetType.h',
'StyleAnimationValue.h',
'StyleBackendType.h',

Просмотреть файл

@ -47,6 +47,11 @@ class nsTextFrame;
class imgIContainer;
struct nsStyleVisibility;
typedef nsINode RawGeckoNode;
typedef mozilla::dom::Element RawGeckoElement;
typedef nsIDocument RawGeckoDocument;
struct ServoNodeData;
// Includes nsStyleStructID.
#include "nsStyleStructFwd.h"