Bug 1714584 - Part 2: Remove nsDisplayList::RemoveBottom() r=mstange

Differential Revision: https://phabricator.services.mozilla.com/D138153
This commit is contained in:
Miko Mynttinen
2022-02-22 23:42:18 +00:00
parent 528f0d244b
commit 7bae3ee4f4
7 changed files with 30 additions and 58 deletions

View File

@@ -4692,12 +4692,10 @@ nsRect PresShell::ClipListToRange(nsDisplayListBuilder* aBuilder,
// part of the selection. Then, append the wrapper to the top of the list. // part of the selection. Then, append the wrapper to the top of the list.
// Otherwise, just delete the item and don't append it. // Otherwise, just delete the item and don't append it.
nsRect surfaceRect; nsRect surfaceRect;
nsDisplayList tmpList;
nsDisplayItem* i; for (nsDisplayItem* i : aList->TakeItems()) {
while ((i = aList->RemoveBottom())) {
if (i->GetType() == DisplayItemType::TYPE_CONTAINER) { if (i->GetType() == DisplayItemType::TYPE_CONTAINER) {
tmpList.AppendToTop(i); aList->AppendToTop(i);
surfaceRect.UnionRect( surfaceRect.UnionRect(
surfaceRect, ClipListToRange(aBuilder, i->GetChildren(), aRange)); surfaceRect, ClipListToRange(aBuilder, i->GetChildren(), aRange));
continue; continue;
@@ -4778,7 +4776,7 @@ nsRect PresShell::ClipListToRange(nsDisplayListBuilder* aBuilder,
// list, insert that as well // list, insert that as well
nsDisplayList* sublist = i->GetSameCoordinateSystemChildren(); nsDisplayList* sublist = i->GetSameCoordinateSystemChildren();
if (itemToInsert || sublist) { if (itemToInsert || sublist) {
tmpList.AppendToTop(itemToInsert ? itemToInsert : i); aList->AppendToTop(itemToInsert ? itemToInsert : i);
// if the item is a list, iterate over it as well // if the item is a list, iterate over it as well
if (sublist) if (sublist)
surfaceRect.UnionRect(surfaceRect, surfaceRect.UnionRect(surfaceRect,
@@ -4789,9 +4787,6 @@ nsRect PresShell::ClipListToRange(nsDisplayListBuilder* aBuilder,
} }
} }
// now add all the items back onto the original list again
aList->AppendToTop(&tmpList);
return surfaceRect; return surfaceRect;
} }

View File

@@ -766,9 +766,7 @@ void TextOverflow::ProcessLine(const nsDisplayListSet& aLists, nsLineBox* aLine,
void TextOverflow::PruneDisplayListContents( void TextOverflow::PruneDisplayListContents(
nsDisplayList* aList, const FrameHashtable& aFramesToHide, nsDisplayList* aList, const FrameHashtable& aFramesToHide,
const LogicalRect& aInsideMarkersArea) { const LogicalRect& aInsideMarkersArea) {
nsDisplayList saved; for (nsDisplayItem* item : aList->TakeItems()) {
nsDisplayItem* item;
while ((item = aList->RemoveBottom())) {
nsIFrame* itemFrame = item->Frame(); nsIFrame* itemFrame = item->Frame();
if (IsFrameDescendantOfAny(itemFrame, aFramesToHide, mBlock)) { if (IsFrameDescendantOfAny(itemFrame, aFramesToHide, mBlock)) {
item->Destroy(mBuilder); item->Destroy(mBuilder);
@@ -804,9 +802,8 @@ void TextOverflow::PruneDisplayListContents(
} }
} }
saved.AppendToTop(item); aList->AppendToTop(item);
} }
aList->AppendToTop(&saved);
} }
/* static */ /* static */

View File

@@ -3702,7 +3702,8 @@ void nsIFrame::BuildDisplayListForStackingContext(
nsDisplayItem* separator = nullptr; nsDisplayItem* separator = nullptr;
while (nsDisplayItem* item = resultList.RemoveBottom()) { // TODO: This can be simplified: |participants| is just |resultList|.
for (nsDisplayItem* item : resultList.TakeItems()) {
if (ItemParticipatesIn3DContext(this, item) && if (ItemParticipatesIn3DContext(this, item) &&
!item->GetClip().HasClip()) { !item->GetClip().HasClip()) {
// The frame of this item participates the same 3D context. // The frame of this item participates the same 3D context.
@@ -3883,7 +3884,8 @@ void nsIFrame::BuildDisplayListForStackingContext(
container = MakeDisplayItem<nsDisplayContainer>( container = MakeDisplayItem<nsDisplayContainer>(
aBuilder, this, containerItemASR, &resultList); aBuilder, this, containerItemASR, &resultList);
} else { } else {
container = resultList.RemoveBottom(); MOZ_ASSERT(resultList.Length() == 1);
resultList.Clear();
} }
// Mark the outermost display item as reusable. These display items and // Mark the outermost display item as reusable. These display items and
@@ -3923,7 +3925,8 @@ static nsDisplayItem* WrapInWrapList(nsDisplayListBuilder* aBuilder,
// invalidation) or we're doing a full build and don't need a wrap list, then // invalidation) or we're doing a full build and don't need a wrap list, then
// we can skip adding one. // we can skip adding one.
if (aBuiltContainerItem || (!aBuilder->IsPartialUpdate() && !needsWrapList)) { if (aBuiltContainerItem || (!aBuilder->IsPartialUpdate() && !needsWrapList)) {
aList->RemoveBottom(); MOZ_ASSERT(aList->Length() == 1);
aList->Clear();
return item; return item;
} }
@@ -3940,7 +3943,8 @@ static nsDisplayItem* WrapInWrapList(nsDisplayListBuilder* aBuilder,
if (needsWrapList) { if (needsWrapList) {
DiscardOldItems(aFrame); DiscardOldItems(aFrame);
} else { } else {
aList->RemoveBottom(); MOZ_ASSERT(aList->Length() == 1);
aList->Clear();
return item; return item;
} }
} }

View File

@@ -267,10 +267,7 @@ static void BuildPreviousPageOverflow(nsDisplayListBuilder* aBuilder,
static void PruneDisplayListForExtraPage(nsDisplayListBuilder* aBuilder, static void PruneDisplayListForExtraPage(nsDisplayListBuilder* aBuilder,
nsPageFrame* aPage, nsPageFrame* aPage,
nsDisplayList* aList) { nsDisplayList* aList) {
nsDisplayList newList; for (nsDisplayItem* i : aList->TakeItems()) {
while (true) {
nsDisplayItem* i = aList->RemoveBottom();
if (!i) break; if (!i) break;
nsDisplayList* subList = i->GetSameCoordinateSystemChildren(); nsDisplayList* subList = i->GetSameCoordinateSystemChildren();
if (subList) { if (subList) {
@@ -285,9 +282,8 @@ static void PruneDisplayListForExtraPage(nsDisplayListBuilder* aBuilder,
continue; continue;
} }
} }
newList.AppendToTop(i); aList->AppendToTop(i);
} }
aList->AppendToTop(&newList);
} }
static void BuildDisplayListForExtraPage(nsDisplayListBuilder* aBuilder, static void BuildDisplayListForExtraPage(nsDisplayListBuilder* aBuilder,

View File

@@ -306,9 +306,7 @@ ScreenIntSize nsSubDocumentFrame::GetSubdocumentSize() {
static void WrapBackgroundColorInOwnLayer(nsDisplayListBuilder* aBuilder, static void WrapBackgroundColorInOwnLayer(nsDisplayListBuilder* aBuilder,
nsIFrame* aFrame, nsIFrame* aFrame,
nsDisplayList* aList) { nsDisplayList* aList) {
nsDisplayList tempItems; for (nsDisplayItem* item : aList->TakeItems()) {
nsDisplayItem* item;
while ((item = aList->RemoveBottom()) != nullptr) {
if (item->GetType() == DisplayItemType::TYPE_BACKGROUND_COLOR) { if (item->GetType() == DisplayItemType::TYPE_BACKGROUND_COLOR) {
nsDisplayList tmpList(aBuilder); nsDisplayList tmpList(aBuilder);
tmpList.AppendToTop(item); tmpList.AppendToTop(item);
@@ -317,11 +315,8 @@ static void WrapBackgroundColorInOwnLayer(nsDisplayListBuilder* aBuilder,
&tmpList, aBuilder->CurrentActiveScrolledRoot(), &tmpList, aBuilder->CurrentActiveScrolledRoot(),
nsDisplayOwnLayerFlags::None, ScrollbarData{}, true, false); nsDisplayOwnLayerFlags::None, ScrollbarData{}, true, false);
} }
if (item) { aList->AppendToTop(item);
tempItems.AppendToTop(item);
}
} }
aList->AppendToTop(&tempItems);
} }
void nsSubDocumentFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, void nsSubDocumentFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,

View File

@@ -203,10 +203,8 @@ bool RetainedDisplayListBuilder::PreProcessDisplayList(
aList->mDAG.Length() == aList->mDAG.Length() ==
(initializeOldItems ? aList->Length() : aList->mOldItems.Length())); (initializeOldItems ? aList->Length() : aList->mOldItems.Length()));
nsDisplayList out;
size_t i = 0; size_t i = 0;
while (nsDisplayItem* item = aList->RemoveBottom()) { for (nsDisplayItem* item : aList->TakeItems()) {
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
item->SetMergedPreProcessed(false, true); item->SetMergedPreProcessed(false, true);
#endif #endif
@@ -343,16 +341,13 @@ bool RetainedDisplayListBuilder::PreProcessDisplayList(
if (item->GetType() == DisplayItemType::TYPE_SUBDOCUMENT) { if (item->GetType() == DisplayItemType::TYPE_SUBDOCUMENT) {
IncrementSubDocPresShellPaintCount(item); IncrementSubDocPresShellPaintCount(item);
} }
out.AppendToTop(item); aList->AppendToTop(item);
} }
i++; i++;
} }
MOZ_RELEASE_ASSERT(aList->mOldItems.Length() == aList->mDAG.Length()); MOZ_RELEASE_ASSERT(aList->mOldItems.Length() == aList->mDAG.Length());
if (aKeepLinked) {
aList->AppendToTop(&out);
}
return true; return true;
} }
@@ -856,7 +851,7 @@ bool RetainedDisplayListBuilder::MergeDisplayLists(
MergeState merge(this, *aOldList, aOuterItem); MergeState merge(this, *aOldList, aOuterItem);
Maybe<MergedListIndex> previousItemIndex; Maybe<MergedListIndex> previousItemIndex;
while (nsDisplayItem* item = aNewList->RemoveBottom()) { for (nsDisplayItem* item : aNewList->TakeItems()) {
Metrics()->mNewItems++; Metrics()->mNewItems++;
previousItemIndex = merge.ProcessItemFromNewList(item, previousItemIndex); previousItemIndex = merge.ProcessItemFromNewList(item, previousItemIndex);
} }
@@ -1561,9 +1556,7 @@ bool IsReuseableStackingContextItem(nsDisplayItem* aItem) {
void CollectStackingContextItems(nsDisplayListBuilder* aBuilder, void CollectStackingContextItems(nsDisplayListBuilder* aBuilder,
nsDisplayList* aList, nsIFrame* aOuterFrame, nsDisplayList* aList, nsIFrame* aOuterFrame,
int aDepth = 0, bool aParentReused = false) { int aDepth = 0, bool aParentReused = false) {
nsDisplayList out; for (nsDisplayItem* item : aList->TakeItems()) {
for (nsDisplayItem* item : *aList) {
if (DL_LOG_TEST(LogLevel::Debug)) { if (DL_LOG_TEST(LogLevel::Debug)) {
DL_LOGD( DL_LOGD(
"%*s Preprocessing item %p (%s) (frame: %p) " "%*s Preprocessing item %p (%s) (frame: %p) "
@@ -1600,7 +1593,7 @@ void CollectStackingContextItems(nsDisplayListBuilder* aBuilder,
if (aParentReused) { if (aParentReused) {
// Keep the contents of the current container item linked. // Keep the contents of the current container item linked.
RDLUtils::AssertDisplayItemUnmodified(item); RDLUtils::AssertDisplayItemUnmodified(item);
out.AppendToTop(item); aList->AppendToTop(item);
} else if (isStackingContextItem) { } else if (isStackingContextItem) {
// |item| is a stacking context item that can be reused. // |item| is a stacking context item that can be reused.
ReuseStackingContextItem(aBuilder, item); ReuseStackingContextItem(aBuilder, item);
@@ -1615,9 +1608,6 @@ void CollectStackingContextItems(nsDisplayListBuilder* aBuilder,
IncrementPresShellPaintCount(aBuilder, item); IncrementPresShellPaintCount(aBuilder, item);
} }
} }
aList->Clear();
aList->AppendToTop(&out);
} }
} // namespace RDL } // namespace RDL

View File

@@ -2326,8 +2326,7 @@ void nsDisplayList::PaintRoot(nsDisplayListBuilder* aBuilder, gfxContext* aCtx,
} }
void nsDisplayList::DeleteAll(nsDisplayListBuilder* aBuilder) { void nsDisplayList::DeleteAll(nsDisplayListBuilder* aBuilder) {
nsDisplayItem* item; for (auto* item : TakeItems()) {
while ((item = RemoveBottom()) != nullptr) {
item->Destroy(aBuilder); item->Destroy(aBuilder);
} }
} }
@@ -4674,17 +4673,14 @@ static nsresult WrapDisplayList(nsDisplayListBuilder* aBuilder,
static nsresult WrapEachDisplayItem(nsDisplayListBuilder* aBuilder, static nsresult WrapEachDisplayItem(nsDisplayListBuilder* aBuilder,
nsDisplayList* aList, nsDisplayList* aList,
nsDisplayItemWrapper* aWrapper) { nsDisplayItemWrapper* aWrapper) {
nsDisplayList newList; for (nsDisplayItem* item : aList->TakeItems()) {
nsDisplayItem* item;
while ((item = aList->RemoveBottom())) {
item = aWrapper->WrapItem(aBuilder, item); item = aWrapper->WrapItem(aBuilder, item);
if (!item) { if (!item) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
newList.AppendToTop(item); aList->AppendToTop(item);
} }
// aList was emptied // aList was emptied
aList->AppendToTop(&newList);
return NS_OK; return NS_OK;
} }
@@ -8543,15 +8539,14 @@ void nsDisplayListCollection::SerializeWithCorrectZOrder(
// 1,2: backgrounds and borders // 1,2: backgrounds and borders
aOutResultList->AppendToTop(BorderBackground()); aOutResultList->AppendToTop(BorderBackground());
// 3: negative z-index children. // 3: negative z-index children.
for (;;) { for (auto* item : PositionedDescendants()->TakeItems()) {
nsDisplayItem* item = PositionedDescendants()->GetBottom(); if (item->ZIndex() < 0) {
if (item && item->ZIndex() < 0) {
PositionedDescendants()->RemoveBottom();
aOutResultList->AppendToTop(item); aOutResultList->AppendToTop(item);
continue; } else {
PositionedDescendants()->AppendToTop(item);
} }
break;
} }
// 4: block backgrounds // 4: block backgrounds
aOutResultList->AppendToTop(BlockBorderBackgrounds()); aOutResultList->AppendToTop(BlockBorderBackgrounds());
// 5: floats // 5: floats