From efd88ee9995dca701786cd13204d57899335f569 Mon Sep 17 00:00:00 2001 From: win7-7 Date: Wed, 29 Jan 2020 11:14:34 +0200 Subject: Issue #1355 - Speed up the traversal of a table row frame's child cells Speed up getting the first cellframe in a row and the next cellframe after the given one --- layout/tables/nsTableRowFrame.cpp | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'layout/tables/nsTableRowFrame.cpp') diff --git a/layout/tables/nsTableRowFrame.cpp b/layout/tables/nsTableRowFrame.cpp index ea2477b73..8bbaf50f5 100644 --- a/layout/tables/nsTableRowFrame.cpp +++ b/layout/tables/nsTableRowFrame.cpp @@ -304,18 +304,6 @@ GetBSizeOfRowsSpannedBelowFirst(nsTableCellFrame& aTableCellFrame, return bsize; } -nsTableCellFrame* -nsTableRowFrame::GetFirstCell() -{ - for (nsIFrame* childFrame : mFrames) { - nsTableCellFrame *cellFrame = do_QueryFrame(childFrame); - if (cellFrame) { - return cellFrame; - } - } - return nullptr; -} - /** * Post-reflow hook. This is where the table row does its post-processing */ -- cgit v1.2.3 From c9fd86cb784b81ab30461b773667b7251347fae6 Mon Sep 17 00:00:00 2001 From: win7-7 Date: Sun, 16 Feb 2020 16:06:53 +0200 Subject: Issue #1355 - Make nsTableCellFrame::GetColIndex/GetRowIndex faster We can devirtualize it, remove some branches. --- layout/tables/nsTableRowFrame.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'layout/tables/nsTableRowFrame.cpp') diff --git a/layout/tables/nsTableRowFrame.cpp b/layout/tables/nsTableRowFrame.cpp index 8bbaf50f5..02b85a141 100644 --- a/layout/tables/nsTableRowFrame.cpp +++ b/layout/tables/nsTableRowFrame.cpp @@ -235,7 +235,7 @@ nsTableRowFrame::InsertFrames(ChildListID aListID, // insert the cells into the cell map int32_t colIndex = -1; if (prevCellFrame) { - prevCellFrame->GetColIndex(colIndex); + colIndex = prevCellFrame->ColIndex(); } tableFrame->InsertCells(cellChildren, GetRowIndex(), colIndex); @@ -647,8 +647,7 @@ CalcAvailISize(nsTableFrame& aTableFrame, nsTableCellFrame& aCellFrame) { nscoord cellAvailISize = 0; - int32_t colIndex; - aCellFrame.GetColIndex(colIndex); + uint32_t colIndex = aCellFrame.ColIndex(); int32_t colspan = aTableFrame.GetEffectiveColSpan(aCellFrame); NS_ASSERTION(colspan > 0, "effective colspan should be positive"); nsTableFrame* fifTable = @@ -787,12 +786,12 @@ nsTableRowFrame::ReflowChildren(nsPresContext* aPresContext, } } - int32_t cellColIndex; - cellFrame->GetColIndex(cellColIndex); + uint32_t cellColIndex = cellFrame->ColIndex(); cellColSpan = aTableFrame.GetEffectiveColSpan(*cellFrame); // If the adjacent cell is in a prior row (because of a rowspan) add in the space - if (prevColIndex != (cellColIndex - 1)) { + // NOTE: prevColIndex can be -1 here. + if (prevColIndex != (static_cast(cellColIndex) - 1)) { iCoord += GetSpaceBetween(prevColIndex, cellColIndex, cellColSpan, aTableFrame, false); } @@ -1160,8 +1159,7 @@ nsTableRowFrame::CollapseRowIfNecessary(nscoord aRowOffset, shift = rowRect.BSize(wm); nsTableCellFrame* cellFrame = GetFirstCell(); if (cellFrame) { - int32_t rowIndex; - cellFrame->GetRowIndex(rowIndex); + uint32_t rowIndex = cellFrame->RowIndex(); shift += tableFrame->GetRowSpacing(rowIndex); while (cellFrame) { LogicalRect cRect = cellFrame->GetLogicalRect(wm, containerSize); @@ -1192,13 +1190,13 @@ nsTableRowFrame::CollapseRowIfNecessary(nscoord aRowOffset, for (nsIFrame* kidFrame : mFrames) { nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame); if (cellFrame) { - int32_t cellColIndex; - cellFrame->GetColIndex(cellColIndex); + uint32_t cellColIndex = cellFrame->ColIndex(); int32_t cellColSpan = tableFrame->GetEffectiveColSpan(*cellFrame); // If the adjacent cell is in a prior row (because of a rowspan) add in // the space - if (prevColIndex != (cellColIndex - 1)) { + // NOTE: prevColIndex can be -1 here. + if (prevColIndex != (static_cast(cellColIndex) - 1)) { iPos += GetSpaceBetween(prevColIndex, cellColIndex, cellColSpan, *tableFrame, true); } @@ -1311,9 +1309,9 @@ nsTableRowFrame::InsertCellFrame(nsTableCellFrame* aFrame, for (nsIFrame* child : mFrames) { nsTableCellFrame *cellFrame = do_QueryFrame(child); if (cellFrame) { - int32_t colIndex; - cellFrame->GetColIndex(colIndex); - if (colIndex < aColIndex) { + uint32_t colIndex = cellFrame->ColIndex(); + // Can aColIndex be -1 here? Let's assume it can for now. + if (static_cast(colIndex) < aColIndex) { priorCell = cellFrame; } else break; -- cgit v1.2.3 From cbb61ab832508e9c231a256fb161d38d35faeabf Mon Sep 17 00:00:00 2001 From: win7-7 Date: Tue, 25 Feb 2020 00:17:54 +0200 Subject: Issue #1355 - Better way to create display items for column backgrounds Part 1: Remove current table item, as it's never set. Part 2: Get rid of generic table painting code, and handle each class separately. Part 4: Hoist outline skipping into col(group) frame code. Part 5: Skip box-shadow for table column and column groups. Part 6: Store column and column group backgrounds separately, and then append them before the rest of the table contents. Part 7: Pass rects in display list coordinates to AppendBackgroundItemsToTop. Part 8: Create column and column group background display items as part of the cell's BuildDisplayList. Part 9: Used cached values instead of calling nsDisplayListBuilder::ToReferenceFrame when possible, since it can be expensive when the requested frame isn't the builder's current frame. Part 10: Make sure we build display items for table parts where only the normal position is visible, since we may need to create background items for ancestors at that position. Part 11: Create an AutoBuildingDisplayList when we create background items for table columns and column groups, so that we initialize the invalidation state correctly. --- layout/tables/nsTableRowFrame.cpp | 58 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'layout/tables/nsTableRowFrame.cpp') diff --git a/layout/tables/nsTableRowFrame.cpp b/layout/tables/nsTableRowFrame.cpp index 02b85a141..18f11f876 100644 --- a/layout/tables/nsTableRowFrame.cpp +++ b/layout/tables/nsTableRowFrame.cpp @@ -549,12 +549,66 @@ nsTableRowFrame::CalcBSize(const ReflowInput& aReflowInput) return GetInitialBSize(); } +void nsTableRowFrame::PaintCellBackgroundsForFrame( + nsIFrame* aFrame, nsDisplayListBuilder* aBuilder, + const nsDisplayListSet& aLists, const nsPoint& aOffset) { + // Compute background rect by iterating all cell frame. + const nsPoint toReferenceFrame = aBuilder->ToReferenceFrame(aFrame); + for (nsTableCellFrame* cell = GetFirstCell(); cell; + cell = cell->GetNextCell()) { + if (!cell->ShouldPaintBackground(aBuilder)) { + continue; + } + + auto cellRect = + cell->GetRectRelativeToSelf() + cell->GetNormalPosition() + aOffset; + if (!aBuilder->GetDirtyRect().Intersects(cellRect)) { + continue; + } + cellRect += toReferenceFrame; + nsDisplayBackgroundImage::AppendBackgroundItemsToTop( + aBuilder, aFrame, cellRect, aLists.BorderBackground(), true, nullptr, + aFrame->GetRectRelativeToSelf() + toReferenceFrame, cell); + } +} + void nsTableRowFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, - const nsRect& aDirtyRect, const nsDisplayListSet& aLists) { - nsTableFrame::DisplayGenericTablePart(aBuilder, this, aDirtyRect, aLists); + if (IsVisibleForPainting(aBuilder)) { + // XXXbz should box-shadow for rows/rowgroups/columns/colgroups get painted + // just because we're visible? Or should it depend on the cell visibility + // when we're not the whole table? + + // Paint the outset box-shadows for the table frames + if (StyleEffects()->mBoxShadow) { + aLists.BorderBackground()->AppendNewToTop( + new (aBuilder) nsDisplayBoxShadowOuter + (aBuilder, this)); + } + } + + PaintCellBackgroundsForFrame(this, aBuilder, aLists); + + if (IsVisibleForPainting(aBuilder)) { + // XXXbz should box-shadow for rows/rowgroups/columns/colgroups get painted + // just because we're visible? Or should it depend on the cell visibility + // when we're not the whole table? + + // Paint the inset box-shadows for the table frames + if (StyleEffects()->mBoxShadow) { + aLists.BorderBackground()->AppendNewToTop( + new (aBuilder) nsDisplayBoxShadowInner + (aBuilder, this)); + } + } + + DisplayOutline(aBuilder, aLists); + + for (nsIFrame* kid : PrincipalChildList()) { + BuildDisplayListForChild(aBuilder, kid, aLists); + } } nsIFrame::LogicalSides -- cgit v1.2.3 From dba09fa5c43276bb455cc4da6bd0ec302f798189 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 26 Feb 2020 20:51:22 +0100 Subject: Revert "Issue #1355 - Better way to create display items for column backgrounds" This reverts commit 44c47c50388f526c2d134e16d5debebe94a0faf8. --- layout/tables/nsTableRowFrame.cpp | 58 ++------------------------------------- 1 file changed, 2 insertions(+), 56 deletions(-) (limited to 'layout/tables/nsTableRowFrame.cpp') diff --git a/layout/tables/nsTableRowFrame.cpp b/layout/tables/nsTableRowFrame.cpp index 18f11f876..02b85a141 100644 --- a/layout/tables/nsTableRowFrame.cpp +++ b/layout/tables/nsTableRowFrame.cpp @@ -549,66 +549,12 @@ nsTableRowFrame::CalcBSize(const ReflowInput& aReflowInput) return GetInitialBSize(); } -void nsTableRowFrame::PaintCellBackgroundsForFrame( - nsIFrame* aFrame, nsDisplayListBuilder* aBuilder, - const nsDisplayListSet& aLists, const nsPoint& aOffset) { - // Compute background rect by iterating all cell frame. - const nsPoint toReferenceFrame = aBuilder->ToReferenceFrame(aFrame); - for (nsTableCellFrame* cell = GetFirstCell(); cell; - cell = cell->GetNextCell()) { - if (!cell->ShouldPaintBackground(aBuilder)) { - continue; - } - - auto cellRect = - cell->GetRectRelativeToSelf() + cell->GetNormalPosition() + aOffset; - if (!aBuilder->GetDirtyRect().Intersects(cellRect)) { - continue; - } - cellRect += toReferenceFrame; - nsDisplayBackgroundImage::AppendBackgroundItemsToTop( - aBuilder, aFrame, cellRect, aLists.BorderBackground(), true, nullptr, - aFrame->GetRectRelativeToSelf() + toReferenceFrame, cell); - } -} - void nsTableRowFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, + const nsRect& aDirtyRect, const nsDisplayListSet& aLists) { - if (IsVisibleForPainting(aBuilder)) { - // XXXbz should box-shadow for rows/rowgroups/columns/colgroups get painted - // just because we're visible? Or should it depend on the cell visibility - // when we're not the whole table? - - // Paint the outset box-shadows for the table frames - if (StyleEffects()->mBoxShadow) { - aLists.BorderBackground()->AppendNewToTop( - new (aBuilder) nsDisplayBoxShadowOuter - (aBuilder, this)); - } - } - - PaintCellBackgroundsForFrame(this, aBuilder, aLists); - - if (IsVisibleForPainting(aBuilder)) { - // XXXbz should box-shadow for rows/rowgroups/columns/colgroups get painted - // just because we're visible? Or should it depend on the cell visibility - // when we're not the whole table? - - // Paint the inset box-shadows for the table frames - if (StyleEffects()->mBoxShadow) { - aLists.BorderBackground()->AppendNewToTop( - new (aBuilder) nsDisplayBoxShadowInner - (aBuilder, this)); - } - } - - DisplayOutline(aBuilder, aLists); - - for (nsIFrame* kid : PrincipalChildList()) { - BuildDisplayListForChild(aBuilder, kid, aLists); - } + nsTableFrame::DisplayGenericTablePart(aBuilder, this, aDirtyRect, aLists); } nsIFrame::LogicalSides -- cgit v1.2.3