Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: Source/core/rendering/RenderGrid.cpp

Issue 22642010: [CSS Grid Layout] Speed up painting on large grids (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebaselined change Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/RenderGrid.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 { 849 {
850 placeItemsOnGrid(); 850 placeItemsOnGrid();
851 851
852 Vector<GridTrack> columnTracks(gridColumnCount()); 852 Vector<GridTrack> columnTracks(gridColumnCount());
853 Vector<GridTrack> rowTracks(gridRowCount()); 853 Vector<GridTrack> rowTracks(gridRowCount());
854 computedUsedBreadthOfGridTracks(ForColumns, columnTracks, rowTracks); 854 computedUsedBreadthOfGridTracks(ForColumns, columnTracks, rowTracks);
855 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, columnTracks)); 855 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, columnTracks));
856 computedUsedBreadthOfGridTracks(ForRows, columnTracks, rowTracks); 856 computedUsedBreadthOfGridTracks(ForRows, columnTracks, rowTracks);
857 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, rowTracks)); 857 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, rowTracks));
858 858
859 populateGridPositions(columnTracks, rowTracks);
860
859 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { 861 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) {
860 // Because the grid area cannot be styled, we don't need to adjust 862 // Because the grid area cannot be styled, we don't need to adjust
861 // the grid breadth to account for 'box-sizing'. 863 // the grid breadth to account for 'box-sizing'.
862 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit(); 864 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit();
863 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit(); 865 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit();
864 866
865 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChild(child, ForColumns, columnTracks); 867 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChild(child, ForColumns, columnTracks);
866 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChild(child, ForRows, rowTracks); 868 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChild(child, ForRows, rowTracks);
867 869
868 SubtreeLayoutScope layoutScope(child); 870 SubtreeLayoutScope layoutScope(child);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox* child, TrackSizi ngDirection direction, const Vector<GridTrack>& tracks) const 1113 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox* child, TrackSizi ngDirection direction, const Vector<GridTrack>& tracks) const
1112 { 1114 {
1113 const GridCoordinate& coordinate = cachedGridCoordinate(child); 1115 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1114 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor dinate.rows; 1116 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor dinate.rows;
1115 LayoutUnit gridAreaBreadth = 0; 1117 LayoutUnit gridAreaBreadth = 0;
1116 for (size_t trackIndex = span.initialPositionIndex; trackIndex <= span.final PositionIndex; ++trackIndex) 1118 for (size_t trackIndex = span.initialPositionIndex; trackIndex <= span.final PositionIndex; ++trackIndex)
1117 gridAreaBreadth += tracks[trackIndex].m_usedBreadth; 1119 gridAreaBreadth += tracks[trackIndex].m_usedBreadth;
1118 return gridAreaBreadth; 1120 return gridAreaBreadth;
1119 } 1121 }
1120 1122
1123 void RenderGrid::populateGridPositions(const Vector<GridTrack>& columnTracks, co nst Vector<GridTrack>& rowTracks)
1124 {
1125 m_columnPositions.resize(columnTracks.size() + 1);
1126 m_columnPositions[0] = borderAndPaddingStart();
1127 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i)
1128 m_columnPositions[i + 1] = m_columnPositions[i] + columnTracks[i].m_used Breadth;
1129
1130 m_rowPositions.resize(rowTracks.size() + 1);
1131 m_rowPositions[0] = borderAndPaddingBefore();
1132 for (size_t i = 0; i < m_rowPositions.size() - 1; ++i)
1133 m_rowPositions[i + 1] = m_rowPositions[i] + rowTracks[i].m_usedBreadth;
1134 }
1135
1121 LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox* child, const Vector< GridTrack>& columnTracks, const Vector<GridTrack>& rowTracks) 1136 LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox* child, const Vector< GridTrack>& columnTracks, const Vector<GridTrack>& rowTracks)
1122 { 1137 {
1123 const GridCoordinate& coordinate = cachedGridCoordinate(child); 1138 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1139 ASSERT(coordinate.columns.initialPositionIndex < columnTracks.size());
1140 ASSERT(coordinate.rows.initialPositionIndex < rowTracks.size());
1124 1141
1125 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. 1142 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted.
1126 LayoutPoint offset(borderAndPaddingStart() + marginStartForChild(child), bor derAndPaddingBefore() + marginBeforeForChild(child)); 1143 return LayoutPoint(m_columnPositions[coordinate.columns.initialPositionIndex ] + marginStartForChild(child), m_rowPositions[coordinate.rows.initialPositionIn dex] + marginBeforeForChild(child));
1127 // FIXME: |columnTrack| and |rowTrack| should be smaller than our column / r ow count. 1144 }
1128 for (size_t i = 0; i < coordinate.columns.initialPositionIndex && i < column Tracks.size(); ++i)
1129 offset.setX(offset.x() + columnTracks[i].m_usedBreadth);
1130 for (size_t i = 0; i < coordinate.rows.initialPositionIndex && i < rowTracks .size(); ++i)
1131 offset.setY(offset.y() + rowTracks[i].m_usedBreadth);
1132 1145
1133 return offset; 1146 static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, LayoutUn it start, LayoutUnit end)
1147 {
1148 // This function does a binary search over the coordinates.
1149 // FIXME: This doesn't work with grid items overflowing their grid areas and should be tested & fixed.
1150
1151 size_t startGridAreaIndex = std::upper_bound(coordinates.begin(), coordinate s.end() - 1, start) - coordinates.begin();
1152 if (startGridAreaIndex > 0)
1153 --startGridAreaIndex;
1154
1155 size_t endGridAreaIndex = std::upper_bound(coordinates.begin() + startGridAr eaIndex, coordinates.end() - 1, end) - coordinates.begin();
1156 return GridSpan(startGridAreaIndex, endGridAreaIndex);
1134 } 1157 }
1135 1158
1136 void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOff set) 1159 void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOff set)
1137 { 1160 {
1138 for (RenderBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) 1161 ASSERT_WITH_SECURITY_IMPLICATION(!gridIsDirty());
1162
1163 LayoutRect localRepaintRect = paintInfo.rect;
1164 localRepaintRect.moveBy(-paintOffset);
1165
1166 GridSpan dirtiedColumns = dirtiedGridAreas(m_columnPositions, localRepaintRe ct.x(), localRepaintRect.maxX());
1167 GridSpan dirtiedRows = dirtiedGridAreas(m_rowPositions, localRepaintRect.y() , localRepaintRect.maxY());
1168
1169 OrderIterator paintIterator(this);
1170 {
1171 OrderIteratorPopulator populator(paintIterator);
1172
1173 for (size_t row = dirtiedRows.initialPositionIndex; row < dirtiedRows.fi nalPositionIndex; ++row) {
1174 for (size_t column = dirtiedColumns.initialPositionIndex; column < d irtiedColumns.finalPositionIndex; ++column) {
1175 const Vector<RenderBox*, 1> children = m_grid[row][column];
1176 // FIXME: If we start adding spanning children in all grid areas they span, this
1177 // would make us paint them several times, which is wrong!
1178 for (size_t j = 0; j < children.size(); ++j)
1179 populator.storeChild(children[j]);
1180 }
1181 }
1182 }
1183
1184 for (RenderBox* child = paintIterator.first(); child; child = paintIterator. next())
1139 paintChild(child, paintInfo, paintOffset); 1185 paintChild(child, paintInfo, paintOffset);
1140 } 1186 }
1141 1187
1142 const char* RenderGrid::renderName() const 1188 const char* RenderGrid::renderName() const
1143 { 1189 {
1144 if (isFloating()) 1190 if (isFloating())
1145 return "RenderGrid (floating)"; 1191 return "RenderGrid (floating)";
1146 if (isOutOfFlowPositioned()) 1192 if (isOutOfFlowPositioned())
1147 return "RenderGrid (positioned)"; 1193 return "RenderGrid (positioned)";
1148 if (isAnonymous()) 1194 if (isAnonymous())
1149 return "RenderGrid (generated)"; 1195 return "RenderGrid (generated)";
1150 if (isRelPositioned()) 1196 if (isRelPositioned())
1151 return "RenderGrid (relative positioned)"; 1197 return "RenderGrid (relative positioned)";
1152 return "RenderGrid"; 1198 return "RenderGrid";
1153 } 1199 }
1154 1200
1155 } // namespace WebCore 1201 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698