Bug 1844832 - Share document-independent struct allocations. r=boris

In bug 1844755, a bunch of the time is spent allocating initial values.

There used to be more document-dependent initial values before
bug 1834487, but now that's only about default-font and direction.

This improves the situation by sharing initial structs that don't depend
on the document.

Differential Revision: https://phabricator.services.mozilla.com/D184256
This commit is contained in:
Emilio Cobos Álvarez 2023-07-26 09:16:26 +00:00
parent bcc4d5e330
commit b5d6ad43a2
8 changed files with 152 additions and 250 deletions

View File

@ -204,7 +204,7 @@ void nsColumnSetFrame::CreateBorderRenderers(
// the column rule as the left border. PaintBorder() does all the rendering
// for us, so we not only save an enormous amount of code but we'll support
// all the line styles that we support on borders!
nsStyleBorder border(*pc->Document());
nsStyleBorder border;
Sides skipSides;
if (isVertical) {
border.SetBorderWidth(eSideTop, ruleWidth, pc->AppUnitsPerDevPixel());

View File

@ -1807,9 +1807,8 @@ void nsImageFrame::DisplayAltText(nsPresContext* aPresContext,
}
struct nsRecessedBorder : public nsStyleBorder {
nsRecessedBorder(nscoord aBorderWidth, nsPresContext* aPresContext)
: nsStyleBorder(*aPresContext->Document()) {
for (const auto side : mozilla::AllPhysicalSides()) {
explicit nsRecessedBorder(nscoord aBorderWidth) {
for (const auto side : AllPhysicalSides()) {
BorderColorFor(side) = StyleColor::Black();
mBorder.Side(side) = aBorderWidth;
// Note: use SetBorderStyle here because we want to affect
@ -1891,7 +1890,7 @@ ImgDrawResult nsImageFrame::DisplayAltFeedback(gfxContext& aRenderingContext,
// Paint the border
if (!isLoading) {
nsRecessedBorder recessedBorder(borderEdgeWidth, PresContext());
nsRecessedBorder recessedBorder(borderEdgeWidth);
// Assert that we're not drawing a border-image here; if we were, we
// couldn't ignore the ImgDrawResult that PaintBorderWithStyleBorder
@ -2067,7 +2066,7 @@ ImgDrawResult nsImageFrame::DisplayAltFeedbackWithoutLayer(
// Paint the border
if (!isLoading) {
nsRecessedBorder recessedBorder(borderEdgeWidth, PresContext());
nsRecessedBorder recessedBorder(borderEdgeWidth);
// Assert that we're not drawing a border-image here; if we were, we
// couldn't ignore the ImgDrawResult that PaintBorderWithStyleBorder
// returns.

View File

@ -24,10 +24,19 @@
namespace mozilla {
namespace detail {
template <typename T, typename Enable = void>
struct HasTriggerImageLoads : public std::false_type {};
template <typename T>
struct HasTriggerImageLoads<T, decltype(std::declval<T&>().TriggerImageLoads(
std::declval<dom::Document&>(), nullptr))>
: public std::true_type {};
template <typename T, const T* (ComputedStyle::*Method)() const>
void TriggerImageLoads(dom::Document& aDocument, const ComputedStyle* aOldStyle,
ComputedStyle* aStyle) {
if constexpr (T::kHasTriggerImageLoads) {
if constexpr (HasTriggerImageLoads<T>::value) {
auto* old = aOldStyle ? (aOldStyle->*Method)() : nullptr;
auto* current = const_cast<T*>((aStyle->*Method)());
current->TriggerImageLoads(aDocument, old);
@ -36,6 +45,7 @@ void TriggerImageLoads(dom::Document& aDocument, const ComputedStyle* aOldStyle,
Unused << aStyle;
}
}
} // namespace detail
void ComputedStyle::StartImageLoads(dom::Document& aDocument,
@ -56,7 +66,7 @@ StylePointerEvents ComputedStyle::PointerEvents() const {
// work.
return StylePointerEvents::Auto;
}
auto& ui = *StyleUI();
const auto& ui = *StyleUI();
if (ui.IsInert()) {
return StylePointerEvents::None;
}

View File

@ -1498,22 +1498,6 @@ void Gecko_AddPropertyToSet(nsCSSPropertyIDSet* aPropertySet,
aPropertySet->AddProperty(aProperty);
}
#define STYLE_STRUCT(name) \
\
void Gecko_Construct_Default_nsStyle##name(nsStyle##name* ptr, \
const Document* doc) { \
new (ptr) nsStyle##name(*doc); \
} \
\
void Gecko_CopyConstruct_nsStyle##name(nsStyle##name* ptr, \
const nsStyle##name* other) { \
new (ptr) nsStyle##name(*other); \
} \
\
void Gecko_Destroy_nsStyle##name(nsStyle##name* ptr) { \
ptr->~nsStyle##name(); \
}
bool Gecko_DocumentRule_UseForPresentation(
const Document* aDocument, const nsACString* aPattern,
DocumentMatchingFunction aMatchingFunction) {
@ -1537,6 +1521,33 @@ void Gecko_SetJemallocThreadLocalArena(bool enabled) {
#endif
}
template <typename T>
void Construct(T* aPtr, const Document* aDoc) {
if constexpr (std::is_constructible_v<T, const Document&>) {
MOZ_ASSERT(aDoc);
new (KnownNotNull, aPtr) T(*aDoc);
} else {
MOZ_ASSERT(!aDoc);
new (KnownNotNull, aPtr) T();
// These instance are intentionally global, and we don't want leakcheckers
// to report them.
aPtr->MarkLeaked();
}
}
#define STYLE_STRUCT(name) \
void Gecko_Construct_Default_nsStyle##name(nsStyle##name* ptr, \
const Document* doc) { \
Construct(ptr, doc); \
} \
void Gecko_CopyConstruct_nsStyle##name(nsStyle##name* ptr, \
const nsStyle##name* other) { \
new (ptr) nsStyle##name(*other); \
} \
void Gecko_Destroy_nsStyle##name(nsStyle##name* ptr) { \
ptr->~nsStyle##name(); \
}
#include "nsStyleStructList.h"
#undef STYLE_STRUCT

View File

@ -305,7 +305,7 @@ static StyleRect<T> StyleRectWithAllSides(const T& aSide) {
return {aSide, aSide, aSide, aSide};
}
nsStyleMargin::nsStyleMargin(const Document& aDocument)
nsStyleMargin::nsStyleMargin()
: mMargin(StyleRectWithAllSides(
LengthPercentageOrAuto::LengthPercentage(LengthPercentage::Zero()))),
mScrollMargin(StyleRectWithAllSides(StyleLength{0.})),
@ -343,7 +343,7 @@ nsChangeHint nsStyleMargin::CalcDifference(
return hint;
}
nsStylePadding::nsStylePadding(const Document& aDocument)
nsStylePadding::nsStylePadding()
: mPadding(StyleRectWithAllSides(LengthPercentage::Zero())),
mScrollPadding(StyleRectWithAllSides(LengthPercentageOrAuto::Auto())) {
MOZ_COUNT_CTOR(nsStylePadding);
@ -383,7 +383,7 @@ static inline BorderRadius ZeroBorderRadius() {
return {{{zero, zero}}, {{zero, zero}}, {{zero, zero}}, {{zero, zero}}};
}
nsStyleBorder::nsStyleBorder(const Document& aDocument)
nsStyleBorder::nsStyleBorder()
: mBorderRadius(ZeroBorderRadius()),
mBorderImageSource(StyleImage::None()),
mBorderImageWidth(
@ -433,8 +433,6 @@ nsStyleBorder::nsStyleBorder(const nsStyleBorder& aSrc)
}
}
nsStyleBorder::~nsStyleBorder() { MOZ_COUNT_DTOR(nsStyleBorder); }
void nsStyleBorder::TriggerImageLoads(Document& aDocument,
const nsStyleBorder* aOldStyle) {
MOZ_ASSERT(NS_IsMainThread());
@ -541,7 +539,7 @@ nsChangeHint nsStyleBorder::CalcDifference(
return nsChangeHint(0);
}
nsStyleOutline::nsStyleOutline(const Document& aDocument)
nsStyleOutline::nsStyleOutline()
: mOutlineWidth(kMediumBorderWidth),
mOutlineOffset({0.0f}),
mOutlineColor(StyleColor::CurrentColor()),
@ -589,7 +587,7 @@ nsChangeHint nsStyleOutline::CalcDifference(
// --------------------
// nsStyleList
//
nsStyleList::nsStyleList(const Document& aDocument)
nsStyleList::nsStyleList()
: mListStylePosition(StyleListStylePosition::Outside),
mQuotes(StyleQuotes::Auto()),
mListStyleImage(StyleImage::None()) {
@ -599,8 +597,6 @@ nsStyleList::nsStyleList(const Document& aDocument)
mCounterStyle = nsGkAtoms::disc;
}
nsStyleList::~nsStyleList() { MOZ_COUNT_DTOR(nsStyleList); }
nsStyleList::nsStyleList(const nsStyleList& aSource)
: mListStylePosition(aSource.mListStylePosition),
mCounterStyle(aSource.mCounterStyle),
@ -659,7 +655,7 @@ already_AddRefed<nsIURI> nsStyleList::GetListStyleImageURI() const {
// --------------------
// nsStyleXUL
//
nsStyleXUL::nsStyleXUL(const Document& aDocument)
nsStyleXUL::nsStyleXUL()
: mBoxFlex(0.0f),
mBoxOrdinal(1),
mBoxAlign(StyleBoxAlign::Stretch),
@ -669,8 +665,6 @@ nsStyleXUL::nsStyleXUL(const Document& aDocument)
MOZ_COUNT_CTOR(nsStyleXUL);
}
nsStyleXUL::~nsStyleXUL() { MOZ_COUNT_DTOR(nsStyleXUL); }
nsStyleXUL::nsStyleXUL(const nsStyleXUL& aSource)
: mBoxFlex(aSource.mBoxFlex),
mBoxOrdinal(aSource.mBoxOrdinal),
@ -700,7 +694,7 @@ nsChangeHint nsStyleXUL::CalcDifference(const nsStyleXUL& aNewData) const {
/* static */ const uint32_t nsStyleColumn::kMaxColumnCount;
/* static */ const uint32_t nsStyleColumn::kColumnCountAuto;
nsStyleColumn::nsStyleColumn(const Document& aDocument)
nsStyleColumn::nsStyleColumn()
: mColumnWidth(LengthOrAuto::Auto()),
mColumnRuleColor(StyleColor::CurrentColor()),
mColumnRuleStyle(StyleBorderStyle::None),
@ -709,8 +703,6 @@ nsStyleColumn::nsStyleColumn(const Document& aDocument)
MOZ_COUNT_CTOR(nsStyleColumn);
}
nsStyleColumn::~nsStyleColumn() { MOZ_COUNT_DTOR(nsStyleColumn); }
nsStyleColumn::nsStyleColumn(const nsStyleColumn& aSource)
: mColumnCount(aSource.mColumnCount),
mColumnWidth(aSource.mColumnWidth),
@ -758,7 +750,7 @@ using SVGPaintFallback = StyleGenericSVGPaintFallback<StyleColor>;
// --------------------
// nsStyleSVG
//
nsStyleSVG::nsStyleSVG(const Document& aDocument)
nsStyleSVG::nsStyleSVG()
: mFill{StyleSVGPaintKind::Color(StyleColor::Black()),
SVGPaintFallback::Unset()},
mStroke{StyleSVGPaintKind::None(), SVGPaintFallback::Unset()},
@ -787,8 +779,6 @@ nsStyleSVG::nsStyleSVG(const Document& aDocument)
MOZ_COUNT_CTOR(nsStyleSVG);
}
nsStyleSVG::~nsStyleSVG() { MOZ_COUNT_DTOR(nsStyleSVG); }
nsStyleSVG::nsStyleSVG(const nsStyleSVG& aSource)
: mFill(aSource.mFill),
mStroke(aSource.mStroke),
@ -898,7 +888,7 @@ nsChangeHint nsStyleSVG::CalcDifference(const nsStyleSVG& aNewData) const {
// --------------------
// nsStyleSVGReset
//
nsStyleSVGReset::nsStyleSVGReset(const Document& aDocument)
nsStyleSVGReset::nsStyleSVGReset()
: mX(LengthPercentage::Zero()),
mY(LengthPercentage::Zero()),
mCx(LengthPercentage::Zero()),
@ -919,8 +909,6 @@ nsStyleSVGReset::nsStyleSVGReset(const Document& aDocument)
MOZ_COUNT_CTOR(nsStyleSVGReset);
}
nsStyleSVGReset::~nsStyleSVGReset() { MOZ_COUNT_DTOR(nsStyleSVGReset); }
nsStyleSVGReset::nsStyleSVGReset(const nsStyleSVGReset& aSource)
: mX(aSource.mX),
mY(aSource.mY),
@ -1027,6 +1015,13 @@ bool nsStyleSVGReset::HasMask() const {
// nsStylePage
//
nsStylePage::nsStylePage(const nsStylePage& aSrc)
: mSize(aSrc.mSize),
mPage(aSrc.mPage),
mPageOrientation(aSrc.mPageOrientation) {
MOZ_COUNT_CTOR(nsStylePage);
}
nsChangeHint nsStylePage::CalcDifference(const nsStylePage& aNewData) const {
// Page rule styling only matters when printing or using print preview.
if (aNewData.mSize != mSize || aNewData.mPage != mPage ||
@ -1039,7 +1034,7 @@ nsChangeHint nsStylePage::CalcDifference(const nsStylePage& aNewData) const {
// --------------------
// nsStylePosition
//
nsStylePosition::nsStylePosition(const Document& aDocument)
nsStylePosition::nsStylePosition()
: mObjectPosition(Position::FromPercentage(0.5f)),
mOffset(StyleRectWithAllSides(LengthPercentageOrAuto::Auto())),
mWidth(StyleSize::Auto()),
@ -1085,8 +1080,6 @@ nsStylePosition::nsStylePosition(const Document& aDocument)
// mGrid{Column,Row}{Start,End}: false/0/empty values for 'auto'
}
nsStylePosition::~nsStylePosition() { MOZ_COUNT_DTOR(nsStylePosition); }
nsStylePosition::nsStylePosition(const nsStylePosition& aSource)
: mAlignTracks(aSource.mAlignTracks),
mJustifyTracks(aSource.mJustifyTracks),
@ -1340,13 +1333,11 @@ StyleJustifySelf nsStylePosition::UsedJustifySelf(
// nsStyleTable
//
nsStyleTable::nsStyleTable(const Document& aDocument)
nsStyleTable::nsStyleTable()
: mLayoutStrategy(StyleTableLayout::Auto), mXSpan(1) {
MOZ_COUNT_CTOR(nsStyleTable);
}
nsStyleTable::~nsStyleTable() { MOZ_COUNT_DTOR(nsStyleTable); }
nsStyleTable::nsStyleTable(const nsStyleTable& aSource)
: mLayoutStrategy(aSource.mLayoutStrategy), mXSpan(aSource.mXSpan) {
MOZ_COUNT_CTOR(nsStyleTable);
@ -1363,7 +1354,7 @@ nsChangeHint nsStyleTable::CalcDifference(const nsStyleTable& aNewData) const {
// -----------------------
// nsStyleTableBorder
nsStyleTableBorder::nsStyleTableBorder(const Document& aDocument)
nsStyleTableBorder::nsStyleTableBorder()
: mBorderSpacingCol(0),
mBorderSpacingRow(0),
mBorderCollapse(StyleBorderCollapse::Separate),
@ -1372,10 +1363,6 @@ nsStyleTableBorder::nsStyleTableBorder(const Document& aDocument)
MOZ_COUNT_CTOR(nsStyleTableBorder);
}
nsStyleTableBorder::~nsStyleTableBorder() {
MOZ_COUNT_DTOR(nsStyleTableBorder);
}
nsStyleTableBorder::nsStyleTableBorder(const nsStyleTableBorder& aSource)
: mBorderSpacingCol(aSource.mBorderSpacingCol),
mBorderSpacingRow(aSource.mBorderSpacingRow),
@ -1692,8 +1679,6 @@ nsStyleImageLayers::nsStyleImageLayers(nsStyleImageLayers::LayerType aType)
mBlendModeCount(1),
mCompositeCount(1),
mLayers(nsStyleAutoArray<Layer>::WITH_SINGLE_INITIAL_ELEMENT) {
MOZ_COUNT_CTOR(nsStyleImageLayers);
// Ensure first layer is initialized as specified layer type
mLayers[0].Initialize(aType);
}
@ -1710,9 +1695,7 @@ nsStyleImageLayers::nsStyleImageLayers(const nsStyleImageLayers& aSource)
mMaskModeCount(aSource.mMaskModeCount),
mBlendModeCount(aSource.mBlendModeCount),
mCompositeCount(aSource.mCompositeCount),
mLayers(aSource.mLayers.Clone()) {
MOZ_COUNT_CTOR(nsStyleImageLayers);
}
mLayers(aSource.mLayers.Clone()) {}
static bool AnyLayerIsElementImage(const nsStyleImageLayers& aLayers) {
NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, aLayers) {
@ -2052,7 +2035,7 @@ nsChangeHint nsStyleImageLayers::Layer::CalcDifference(
// nsStyleBackground
//
nsStyleBackground::nsStyleBackground(const Document& aDocument)
nsStyleBackground::nsStyleBackground()
: mImage(nsStyleImageLayers::LayerType::Background),
mBackgroundColor(StyleColor::Transparent()) {
MOZ_COUNT_CTOR(nsStyleBackground);
@ -2063,8 +2046,6 @@ nsStyleBackground::nsStyleBackground(const nsStyleBackground& aSource)
MOZ_COUNT_CTOR(nsStyleBackground);
}
nsStyleBackground::~nsStyleBackground() { MOZ_COUNT_DTOR(nsStyleBackground); }
void nsStyleBackground::TriggerImageLoads(Document& aDocument,
const nsStyleBackground* aOldStyle) {
MOZ_ASSERT(NS_IsMainThread());
@ -2158,7 +2139,7 @@ bool StyleAnimation::operator==(const StyleAnimation& aOther) const {
// --------------------
// nsStyleDisplay
//
nsStyleDisplay::nsStyleDisplay(const Document& aDocument)
nsStyleDisplay::nsStyleDisplay()
: mDisplay(StyleDisplay::Inline),
mOriginalDisplay(StyleDisplay::Inline),
mContentVisibility(StyleContentVisibility::Visible),
@ -2189,6 +2170,7 @@ nsStyleDisplay::nsStyleDisplay(const Document& aDocument)
mOverflowAnchor(StyleOverflowAnchor::Auto),
mScrollSnapAlign{StyleScrollSnapAlignKeyword::None,
StyleScrollSnapAlignKeyword::None},
mScrollSnapStop{StyleScrollSnapStop::Normal},
mScrollSnapType{StyleScrollSnapAxis::Both,
StyleScrollSnapStrictness::None},
mBackfaceVisibility(StyleBackfaceVisibility::Visible),
@ -2247,6 +2229,7 @@ nsStyleDisplay::nsStyleDisplay(const nsStyleDisplay& aSource)
mOverscrollBehaviorY(aSource.mOverscrollBehaviorY),
mOverflowAnchor(aSource.mOverflowAnchor),
mScrollSnapAlign(aSource.mScrollSnapAlign),
mScrollSnapStop(aSource.mScrollSnapStop),
mScrollSnapType(aSource.mScrollSnapType),
mBackfaceVisibility(aSource.mBackfaceVisibility),
mTransformStyle(aSource.mTransformStyle),
@ -2274,8 +2257,6 @@ nsStyleDisplay::nsStyleDisplay(const nsStyleDisplay& aSource)
MOZ_COUNT_CTOR(nsStyleDisplay);
}
nsStyleDisplay::~nsStyleDisplay() { MOZ_COUNT_DTOR(nsStyleDisplay); }
void nsStyleDisplay::TriggerImageLoads(Document& aDocument,
const nsStyleDisplay* aOldStyle) {
MOZ_ASSERT(NS_IsMainThread());
@ -2772,13 +2753,10 @@ StyleImageOrientation nsStyleVisibility::UsedImageOrientation(
// nsStyleContent
//
nsStyleContent::nsStyleContent(const Document& aDocument)
: mContent(StyleContent::Normal()) {
nsStyleContent::nsStyleContent() : mContent(StyleContent::Normal()) {
MOZ_COUNT_CTOR(nsStyleContent);
}
nsStyleContent::~nsStyleContent() { MOZ_COUNT_DTOR(nsStyleContent); }
nsStyleContent::nsStyleContent(const nsStyleContent& aSource)
: mContent(aSource.mContent),
mCounterIncrement(aSource.mCounterIncrement),
@ -2832,7 +2810,7 @@ void nsStyleContent::TriggerImageLoads(Document& aDoc,
// nsStyleTextReset
//
nsStyleTextReset::nsStyleTextReset(const Document& aDocument)
nsStyleTextReset::nsStyleTextReset()
: mTextOverflow(),
mTextDecorationLine(StyleTextDecorationLine::NONE),
mTextDecorationStyle(StyleTextDecorationStyle::Solid),
@ -2856,8 +2834,6 @@ nsStyleTextReset::nsStyleTextReset(const nsStyleTextReset& aSource)
MOZ_COUNT_CTOR(nsStyleTextReset);
}
nsStyleTextReset::~nsStyleTextReset() { MOZ_COUNT_DTOR(nsStyleTextReset); }
nsChangeHint nsStyleTextReset::CalcDifference(
const nsStyleTextReset& aNewData) const {
if (mUnicodeBidi != aNewData.mUnicodeBidi ||
@ -2976,8 +2952,6 @@ nsStyleText::nsStyleText(const nsStyleText& aSource)
MOZ_COUNT_CTOR(nsStyleText);
}
nsStyleText::~nsStyleText() { MOZ_COUNT_DTOR(nsStyleText); }
nsChangeHint nsStyleText::CalcDifference(const nsStyleText& aNewData) const {
if (WhiteSpaceOrNewlineIsSignificant() !=
aNewData.WhiteSpaceOrNewlineIsSignificant()) {
@ -3083,7 +3057,7 @@ LogicalSide nsStyleText::TextEmphasisSide(WritingMode aWM) const {
// nsStyleUI
//
nsStyleUI::nsStyleUI(const Document& aDocument)
nsStyleUI::nsStyleUI()
: mInert(StyleInert::None),
mUserInput(StyleUserInput::Auto),
mUserModify(StyleUserModify::ReadOnly),
@ -3111,8 +3085,6 @@ nsStyleUI::nsStyleUI(const nsStyleUI& aSource)
MOZ_COUNT_CTOR(nsStyleUI);
}
nsStyleUI::~nsStyleUI() { MOZ_COUNT_DTOR(nsStyleUI); }
void nsStyleUI::TriggerImageLoads(Document& aDocument,
const nsStyleUI* aOldStyle) {
MOZ_ASSERT(NS_IsMainThread());
@ -3177,7 +3149,7 @@ nsChangeHint nsStyleUI::CalcDifference(const nsStyleUI& aNewData) const {
// nsStyleUIReset
//
nsStyleUIReset::nsStyleUIReset(const Document& aDocument)
nsStyleUIReset::nsStyleUIReset()
: mUserSelect(StyleUserSelect::Auto),
mScrollbarWidth(StyleScrollbarWidth::Auto),
mMozForceBrokenImageIcon(false),
@ -3260,8 +3232,6 @@ nsStyleUIReset::nsStyleUIReset(const nsStyleUIReset& aSource)
MOZ_COUNT_CTOR(nsStyleUIReset);
}
nsStyleUIReset::~nsStyleUIReset() { MOZ_COUNT_DTOR(nsStyleUIReset); }
nsChangeHint nsStyleUIReset::CalcDifference(
const nsStyleUIReset& aNewData) const {
nsChangeHint hint = nsChangeHint(0);
@ -3342,7 +3312,7 @@ StyleScrollbarWidth nsStyleUIReset::ScrollbarWidth() const {
// nsStyleEffects
//
nsStyleEffects::nsStyleEffects(const Document&)
nsStyleEffects::nsStyleEffects()
: mClip(StyleClipRectOrAuto::Auto()),
mOpacity(1.0f),
mMixBlendMode(StyleBlend::Normal) {
@ -3359,8 +3329,6 @@ nsStyleEffects::nsStyleEffects(const nsStyleEffects& aSource)
MOZ_COUNT_CTOR(nsStyleEffects);
}
nsStyleEffects::~nsStyleEffects() { MOZ_COUNT_DTOR(nsStyleEffects); }
static bool AnyAutonessChanged(const StyleClipRectOrAuto& aOld,
const StyleClipRectOrAuto& aNew) {
if (aOld.IsAuto() != aNew.IsAuto()) {

View File

@ -101,13 +101,15 @@ struct ContainSizeAxes {
} // namespace mozilla
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleFont {
nsStyleFont(const nsStyleFont&);
explicit nsStyleFont(const mozilla::dom::Document&);
MOZ_COUNTED_DTOR(nsStyleFont)
static constexpr bool kHasTriggerImageLoads = false;
#define STYLE_STRUCT(name_) \
name_(const name_&); \
MOZ_COUNTED_DTOR(name_); \
void MarkLeaked() const { MOZ_COUNT_DTOR(name_); } \
nsChangeHint CalcDifference(const name_&) const;
nsChangeHint CalcDifference(const nsStyleFont& aNewData) const;
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleFont {
STYLE_STRUCT(nsStyleFont)
explicit nsStyleFont(const mozilla::dom::Document&);
/**
* Return a given size multiplied by the current text zoom factor (in
@ -166,7 +168,6 @@ struct nsStyleImageLayers {
explicit nsStyleImageLayers(LayerType aType);
nsStyleImageLayers(const nsStyleImageLayers& aSource);
MOZ_COUNTED_DTOR(nsStyleImageLayers)
struct Repeat {
mozilla::StyleImageLayerRepeat mXRepeat, mYRepeat;
@ -324,17 +325,9 @@ struct nsStyleImageLayers {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleBackground {
explicit nsStyleBackground(const mozilla::dom::Document&);
nsStyleBackground(const nsStyleBackground& aOther);
~nsStyleBackground();
// Resolves and tracks the images in mImage. Only called with a Servo-backed
// style system, where those images must be resolved later than the OMT
// nsStyleBackground constructor call.
STYLE_STRUCT(nsStyleBackground)
nsStyleBackground();
void TriggerImageLoads(mozilla::dom::Document&, const nsStyleBackground*);
static constexpr bool kHasTriggerImageLoads = true;
nsChangeHint CalcDifference(const nsStyleBackground& aNewData) const;
// Return the background color as nscolor.
nscolor BackgroundColor(const nsIFrame* aFrame) const;
@ -363,12 +356,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleBackground {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleMargin {
explicit nsStyleMargin(const mozilla::dom::Document&);
nsStyleMargin(const nsStyleMargin& aMargin);
MOZ_COUNTED_DTOR(nsStyleMargin)
static constexpr bool kHasTriggerImageLoads = false;
nsChangeHint CalcDifference(const nsStyleMargin& aNewData) const;
STYLE_STRUCT(nsStyleMargin)
nsStyleMargin();
bool GetMargin(nsMargin& aMargin) const {
bool convertsToLength = mMargin.All(
@ -405,12 +394,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleMargin {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePadding {
explicit nsStylePadding(const mozilla::dom::Document&);
nsStylePadding(const nsStylePadding& aPadding);
MOZ_COUNTED_DTOR(nsStylePadding)
static constexpr bool kHasTriggerImageLoads = false;
nsChangeHint CalcDifference(const nsStylePadding& aNewData) const;
STYLE_STRUCT(nsStylePadding)
nsStylePadding();
mozilla::StyleRect<mozilla::NonNegativeLengthPercentage> mPadding;
mozilla::StyleRect<mozilla::NonNegativeLengthPercentageOrAuto> mScrollPadding;
@ -446,17 +431,9 @@ static bool IsVisibleBorderStyle(mozilla::StyleBorderStyle aStyle) {
}
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleBorder {
explicit nsStyleBorder(const mozilla::dom::Document&);
nsStyleBorder(const nsStyleBorder& aBorder);
~nsStyleBorder();
// Resolves and tracks mBorderImageSource. Only called with a Servo-backed
// style system, where those images must be resolved later than the OMT
// nsStyleBorder constructor call.
STYLE_STRUCT(nsStyleBorder)
nsStyleBorder();
void TriggerImageLoads(mozilla::dom::Document&, const nsStyleBorder*);
static constexpr bool kHasTriggerImageLoads = true;
nsChangeHint CalcDifference(const nsStyleBorder& aNewData) const;
// Return whether aStyle is a visible style. Invisible styles cause
// the relevant computed border width to be 0.
@ -613,12 +590,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleBorder {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleOutline {
explicit nsStyleOutline(const mozilla::dom::Document&);
nsStyleOutline(const nsStyleOutline& aOutline);
MOZ_COUNTED_DTOR(nsStyleOutline)
static constexpr bool kHasTriggerImageLoads = false;
nsChangeHint CalcDifference(const nsStyleOutline& aNewData) const;
STYLE_STRUCT(nsStyleOutline)
nsStyleOutline();
// This is the specified value of outline-width, but with length values
// computed to absolute. mActualOutlineWidth stores the outline-width
@ -653,17 +626,11 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleOutline {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleList {
explicit nsStyleList(const mozilla::dom::Document&);
nsStyleList(const nsStyleList& aStyleList);
~nsStyleList();
private:
nsStyleList& operator=(const nsStyleList& aOther) = delete;
public:
STYLE_STRUCT(nsStyleList)
nsStyleList();
void TriggerImageLoads(mozilla::dom::Document&, const nsStyleList*);
static constexpr bool kHasTriggerImageLoads = true;
nsStyleList& operator=(const nsStyleList& aOther) = delete;
nsChangeHint CalcDifference(const nsStyleList& aNewData,
const nsStyleDisplay& aOldDisplay) const;
@ -677,28 +644,25 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleList {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePage {
STYLE_STRUCT(nsStylePage)
MOZ_COUNTED_DEFAULT_CTOR(nsStylePage)
using StylePageOrientation = mozilla::StylePageOrientation;
using StylePageSize = mozilla::StylePageSize;
using StylePageName = mozilla::StylePageName;
nsStylePage(const nsStylePage& aOther) = default;
nsStylePage& operator=(const nsStylePage& aOther) = default;
explicit nsStylePage(const mozilla::dom::Document&)
: mSize(StylePageSize::Auto()),
mPage(StylePageName::Auto()),
mPageOrientation(StylePageOrientation::Upright) {}
static constexpr bool kHasTriggerImageLoads = false;
nsChangeHint CalcDifference(const nsStylePage& aNewData) const;
// page-size property.
StylePageSize mSize;
StylePageSize mSize = StylePageSize::Auto();
// page-name property.
StylePageName mPage;
StylePageName mPage = StylePageName::Auto();
// page-orientation property.
StylePageOrientation mPageOrientation;
StylePageOrientation mPageOrientation = StylePageOrientation::Upright;
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition {
STYLE_STRUCT(nsStylePosition)
nsStylePosition();
using LengthPercentageOrAuto = mozilla::LengthPercentageOrAuto;
using Position = mozilla::Position;
template <typename T>
@ -712,11 +676,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition {
using StyleAlignSelf = mozilla::StyleAlignSelf;
using StyleJustifySelf = mozilla::StyleJustifySelf;
explicit nsStylePosition(const mozilla::dom::Document&);
nsStylePosition(const nsStylePosition& aOther);
~nsStylePosition();
static constexpr bool kHasTriggerImageLoads = false;
nsChangeHint CalcDifference(
const nsStylePosition& aNewData,
const nsStyleVisibility& aOldStyleVisibility) const;
@ -855,10 +814,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTextReset {
explicit nsStyleTextReset(const mozilla::dom::Document&);
nsStyleTextReset(const nsStyleTextReset& aOther);
~nsStyleTextReset();
static constexpr bool kHasTriggerImageLoads = false;
STYLE_STRUCT(nsStyleTextReset)
nsStyleTextReset();
// Note the difference between this and
// ComputedStyle::HasTextDecorationLines.
@ -868,8 +825,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTextReset {
mozilla::StyleTextDecorationLine::COLOR_OVERRIDE;
}
nsChangeHint CalcDifference(const nsStyleTextReset& aNewData) const;
mozilla::StyleTextOverflow mTextOverflow;
mozilla::StyleTextDecorationLine mTextDecorationLine;
@ -882,12 +837,9 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTextReset {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText {
explicit nsStyleText(const mozilla::dom::Document&);
nsStyleText(const nsStyleText& aOther);
~nsStyleText();
static constexpr bool kHasTriggerImageLoads = false;
STYLE_STRUCT(nsStyleText)
nsChangeHint CalcDifference(const nsStyleText& aNewData) const;
explicit nsStyleText(const mozilla::dom::Document&);
mozilla::StyleAbsoluteColor mColor;
mozilla::StyleForcedColorAdjust mForcedColorAdjust;
@ -1076,10 +1028,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleVisibility {
STYLE_STRUCT(nsStyleVisibility)
explicit nsStyleVisibility(const mozilla::dom::Document&);
nsStyleVisibility(const nsStyleVisibility& aVisibility);
MOZ_COUNTED_DTOR(nsStyleVisibility)
nsChangeHint CalcDifference(const nsStyleVisibility& aNewData) const;
bool IsVisible() const {
return mVisible == mozilla::StyleVisibility::Visible;
@ -1123,7 +1073,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleVisibility {
static mozilla::StyleImageOrientation UsedImageOrientation(
imgIRequest* aRequest, mozilla::StyleImageOrientation aOrientation);
static constexpr bool kHasTriggerImageLoads = false;
mozilla::StyleDirection mDirection;
mozilla::StyleVisibility mVisible;
mozilla::StyleImageRendering mImageRendering;
@ -1293,18 +1242,13 @@ struct StyleViewTimeline {
} // namespace mozilla
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleDisplay {
private:
STYLE_STRUCT(nsStyleDisplay)
nsStyleDisplay();
void TriggerImageLoads(mozilla::dom::Document&, const nsStyleDisplay*);
using StyleContain = mozilla::StyleContain;
using StyleContentVisibility = mozilla::StyleContentVisibility;
public:
explicit nsStyleDisplay(const mozilla::dom::Document&);
nsStyleDisplay(const nsStyleDisplay& aOther);
~nsStyleDisplay();
void TriggerImageLoads(mozilla::dom::Document&, const nsStyleDisplay*);
static constexpr bool kHasTriggerImageLoads = true;
nsChangeHint CalcDifference(const nsStyleDisplay& aNewData,
const nsStylePosition& aOldPosition) const;
@ -1657,24 +1601,16 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleDisplay {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTable {
explicit nsStyleTable(const mozilla::dom::Document&);
nsStyleTable(const nsStyleTable& aOther);
~nsStyleTable();
static constexpr bool kHasTriggerImageLoads = false;
nsChangeHint CalcDifference(const nsStyleTable& aNewData) const;
STYLE_STRUCT(nsStyleTable)
nsStyleTable();
mozilla::StyleTableLayout mLayoutStrategy;
int32_t mXSpan; // The number of columns spanned by a colgroup or col
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTableBorder {
explicit nsStyleTableBorder(const mozilla::dom::Document&);
nsStyleTableBorder(const nsStyleTableBorder& aOther);
~nsStyleTableBorder();
static constexpr bool kHasTriggerImageLoads = false;
nsChangeHint CalcDifference(const nsStyleTableBorder& aNewData) const;
STYLE_STRUCT(nsStyleTableBorder)
nsStyleTableBorder();
nscoord mBorderSpacingCol;
nscoord mBorderSpacingRow;
@ -1684,14 +1620,11 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTableBorder {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleContent {
using CounterPair = mozilla::StyleGenericCounterPair<int32_t>;
explicit nsStyleContent(const mozilla::dom::Document&);
nsStyleContent(const nsStyleContent& aContent);
~nsStyleContent();
STYLE_STRUCT(nsStyleContent)
nsStyleContent();
void TriggerImageLoads(mozilla::dom::Document&, const nsStyleContent*);
static constexpr bool kHasTriggerImageLoads = true;
using CounterPair = mozilla::StyleGenericCounterPair<int32_t>;
size_t ContentCount() const {
return mContent.IsItems() ? mContent.AsItems().Length() : 0;
@ -1701,8 +1634,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleContent {
return mContent.AsItems().AsSpan()[aIndex];
}
nsChangeHint CalcDifference(const nsStyleContent& aNewData) const;
mozilla::StyleContent mContent;
mozilla::StyleCounterIncrement mCounterIncrement;
mozilla::StyleCounterReset mCounterReset;
@ -1710,12 +1641,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleContent {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUIReset {
explicit nsStyleUIReset(const mozilla::dom::Document&);
nsStyleUIReset(const nsStyleUIReset& aOther);
~nsStyleUIReset();
static constexpr bool kHasTriggerImageLoads = false;
nsChangeHint CalcDifference(const nsStyleUIReset& aNewData) const;
STYLE_STRUCT(nsStyleUIReset)
nsStyleUIReset();
private:
mozilla::StyleUserSelect mUserSelect; // Use ComputedStyle::UserSelect()
@ -1825,14 +1752,9 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUIReset {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUI {
explicit nsStyleUI(const mozilla::dom::Document&);
nsStyleUI(const nsStyleUI& aOther);
~nsStyleUI();
STYLE_STRUCT(nsStyleUI)
nsStyleUI();
void TriggerImageLoads(mozilla::dom::Document&, const nsStyleUI*);
static constexpr bool kHasTriggerImageLoads = true;
nsChangeHint CalcDifference(const nsStyleUI& aNewData) const;
mozilla::StyleInert mInert;
@ -1878,12 +1800,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUI {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleXUL {
explicit nsStyleXUL(const mozilla::dom::Document&);
nsStyleXUL(const nsStyleXUL& aSource);
~nsStyleXUL();
static constexpr bool kHasTriggerImageLoads = false;
nsChangeHint CalcDifference(const nsStyleXUL& aNewData) const;
STYLE_STRUCT(nsStyleXUL)
nsStyleXUL();
float mBoxFlex;
int32_t mBoxOrdinal;
@ -1894,12 +1812,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleXUL {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColumn {
explicit nsStyleColumn(const mozilla::dom::Document&);
nsStyleColumn(const nsStyleColumn& aSource);
~nsStyleColumn();
static constexpr bool kHasTriggerImageLoads = false;
nsChangeHint CalcDifference(const nsStyleColumn& aNewData) const;
STYLE_STRUCT(nsStyleColumn)
nsStyleColumn();
// This is the maximum number of columns we can process. It's used in
// nsColumnSetFrame.
@ -1940,12 +1854,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColumn {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleSVG {
explicit nsStyleSVG(const mozilla::dom::Document&);
nsStyleSVG(const nsStyleSVG& aSource);
~nsStyleSVG();
static constexpr bool kHasTriggerImageLoads = false;
nsChangeHint CalcDifference(const nsStyleSVG& aNewData) const;
STYLE_STRUCT(nsStyleSVG)
nsStyleSVG();
mozilla::StyleSVGPaint mFill;
mozilla::StyleSVGPaint mStroke;
@ -2009,17 +1919,9 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleSVG {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleSVGReset {
explicit nsStyleSVGReset(const mozilla::dom::Document&);
nsStyleSVGReset(const nsStyleSVGReset& aSource);
~nsStyleSVGReset();
// Resolves and tracks the images in mMask. Only called with a Servo-backed
// style system, where those images must be resolved later than the OMT
// nsStyleSVGReset constructor call.
STYLE_STRUCT(nsStyleSVGReset)
nsStyleSVGReset();
void TriggerImageLoads(mozilla::dom::Document&, const nsStyleSVGReset*);
static constexpr bool kHasTriggerImageLoads = true;
nsChangeHint CalcDifference(const nsStyleSVGReset& aNewData) const;
bool HasClipPath() const { return !mClipPath.IsNone(); }
@ -2054,12 +1956,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleSVGReset {
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleEffects {
explicit nsStyleEffects(const mozilla::dom::Document&);
nsStyleEffects(const nsStyleEffects& aSource);
~nsStyleEffects();
static constexpr bool kHasTriggerImageLoads = false;
nsChangeHint CalcDifference(const nsStyleEffects& aNewData) const;
STYLE_STRUCT(nsStyleEffects)
nsStyleEffects();
bool HasFilters() const { return !mFilters.IsEmpty(); }
@ -2090,6 +1988,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleEffects {
mozilla::StyleBlend mMixBlendMode;
};
#undef STYLE_STRUCT
#define STATIC_ASSERT_TYPE_LAYOUTS_MATCH(T1, T2) \
static_assert(sizeof(T1) == sizeof(T2), \
"Size mismatch between " #T1 " and " #T2); \

View File

@ -673,6 +673,7 @@ class StyleStruct(object):
self.gecko_name = gecko_name or name
self.gecko_ffi_name = "nsStyle" + self.gecko_name
self.additional_methods = additional_methods or []
self.document_dependent = self.gecko_name in ["Font", "Visibility", "Text"]
class PropertiesData(object):

View File

@ -516,17 +516,30 @@ impl ops::DerefMut for ${style_struct.gecko_struct_name} {
impl ${style_struct.gecko_struct_name} {
#[allow(dead_code, unused_variables)]
pub fn default(document: &structs::Document) -> Arc<Self> {
% if style_struct.document_dependent:
unsafe {
let mut result = UniqueArc::<Self>::new_uninit();
// FIXME(bug 1595895): Zero the memory to keep valgrind happy, but
// these looks like Valgrind false-positives at a quick glance.
ptr::write_bytes::<Self>(result.as_mut_ptr(), 0, 1);
Gecko_Construct_Default_${style_struct.gecko_ffi_name}(
result.as_mut_ptr() as *mut _,
document,
);
UniqueArc::assume_init(result).shareable()
}
% else:
lazy_static! {
static ref DEFAULT: Arc<${style_struct.gecko_struct_name}> = unsafe {
let mut result = UniqueArc::<${style_struct.gecko_struct_name}>::new_uninit();
Gecko_Construct_Default_${style_struct.gecko_ffi_name}(
result.as_mut_ptr() as *mut _,
std::ptr::null(),
);
let arc = UniqueArc::assume_init(result).shareable();
arc.mark_as_intentionally_leaked();
arc
};
};
DEFAULT.clone()
% endif
}
}