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

Side by Side Diff: third_party/WebKit/Source/core/paint/TableCellPainter.cpp

Issue 1549693002: Optimize collapsed border painting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/paint/TableCellPainter.h" 5 #include "core/paint/TableCellPainter.h"
6 6
7 #include "core/layout/LayoutTableCell.h" 7 #include "core/layout/LayoutTableCell.h"
8 #include "core/paint/BlockPainter.h" 8 #include "core/paint/BlockPainter.h"
9 #include "core/paint/BoxPainter.h" 9 #include "core/paint/BoxPainter.h"
10 #include "core/paint/LayoutObjectDrawingRecorder.h" 10 #include "core/paint/LayoutObjectDrawingRecorder.h"
11 #include "core/paint/PaintInfo.h" 11 #include "core/paint/PaintInfo.h"
12 #include "platform/graphics/GraphicsContextStateSaver.h" 12 #include "platform/graphics/GraphicsContextStateSaver.h"
13 13
14 namespace blink { 14 namespace blink {
15 15
16 inline const CollapsedBorderValue* TableCellPainter::cachedCollapsedLeftBorder(c onst ComputedStyle& styleForCellFlow) const 16 static const CollapsedBorderValue& collapsedLeftBorder(const ComputedStyle& styl eForCellFlow, const LayoutTableCell::CollapsedBorderValues& values)
17 { 17 {
18 if (styleForCellFlow.isHorizontalWritingMode()) { 18 if (styleForCellFlow.isHorizontalWritingMode())
19 return styleForCellFlow.isLeftToRightDirection() 19 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder : values.endBorder;
20 ? m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableC ell, CBSStart) 20 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.afterBorder : values.beforeBorder;
21 : m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableC ell, CBSEnd);
22 }
23 return styleForCellFlow.isFlippedBlocksWritingMode()
24 ? m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSAfter)
25 : m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSBefore);
26 } 21 }
27 22
28 inline const CollapsedBorderValue* TableCellPainter::cachedCollapsedRightBorder( const ComputedStyle& styleForCellFlow) const 23 static const CollapsedBorderValue& collapsedRightBorder(const ComputedStyle& sty leForCellFlow, const LayoutTableCell::CollapsedBorderValues& values)
29 { 24 {
30 if (styleForCellFlow.isHorizontalWritingMode()) { 25 if (styleForCellFlow.isHorizontalWritingMode())
31 return styleForCellFlow.isLeftToRightDirection() 26 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder : va lues.startBorder;
32 ? m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableC ell, CBSEnd) 27 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.beforeBorder : values.afterBorder;
33 : m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableC ell, CBSStart);
34 }
35 return styleForCellFlow.isFlippedBlocksWritingMode()
36 ? m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSBefore)
37 : m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSAfter);
38 } 28 }
39 29
40 inline const CollapsedBorderValue* TableCellPainter::cachedCollapsedTopBorder(co nst ComputedStyle& styleForCellFlow) const 30 static const CollapsedBorderValue& collapsedTopBorder(const ComputedStyle& style ForCellFlow, const LayoutTableCell::CollapsedBorderValues& values)
41 { 31 {
42 if (styleForCellFlow.isHorizontalWritingMode()) 32 if (styleForCellFlow.isHorizontalWritingMode())
43 return m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTable Cell, CBSBefore); 33 return values.beforeBorder;
44 return styleForCellFlow.isLeftToRightDirection() 34 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder : valu es.endBorder;
45 ? m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSStart)
46 : m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSEnd);
47 } 35 }
48 36
49 inline const CollapsedBorderValue* TableCellPainter::cachedCollapsedBottomBorder (const ComputedStyle& styleForCellFlow) const 37 static const CollapsedBorderValue& collapsedBottomBorder(const ComputedStyle& st yleForCellFlow, const LayoutTableCell::CollapsedBorderValues& values)
50 { 38 {
51 if (styleForCellFlow.isHorizontalWritingMode()) 39 if (styleForCellFlow.isHorizontalWritingMode())
52 return m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTable Cell, CBSAfter); 40 return values.afterBorder;
53 return styleForCellFlow.isLeftToRightDirection() 41 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder : values .startBorder;
54 ? m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSEnd)
55 : m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSStart);
56 } 42 }
57 43
58 void TableCellPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& pain tOffset) 44 void TableCellPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& pain tOffset)
59 { 45 {
60 BlockPainter(m_layoutTableCell).paint(paintInfo, paintOffset); 46 BlockPainter(m_layoutTableCell).paint(paintInfo, paintOffset);
61 } 47 }
62 48
63 static EBorderStyle collapsedBorderStyle(EBorderStyle style) 49 static EBorderStyle collapsedBorderStyle(EBorderStyle style)
64 { 50 {
65 if (style == BorderStyleOutset) 51 if (style == BorderStyleOutset)
66 return BorderStyleGroove; 52 return BorderStyleGroove;
67 if (style == BorderStyleInset) 53 if (style == BorderStyleInset)
68 return BorderStyleRidge; 54 return BorderStyleRidge;
69 return style; 55 return style;
70 } 56 }
71 57
72 void TableCellPainter::paintCollapsedBorders(const PaintInfo& paintInfo, const L ayoutPoint& paintOffset, const CollapsedBorderValue& currentBorderValue) 58 void TableCellPainter::paintCollapsedBorders(const PaintInfo& paintInfo, const L ayoutPoint& paintOffset, const CollapsedBorderValue& currentBorderValue)
73 { 59 {
74 if (m_layoutTableCell.style()->visibility() != VISIBLE) 60 if (m_layoutTableCell.style()->visibility() != VISIBLE)
75 return; 61 return;
76 62
63 const LayoutTableCell::CollapsedBorderValues* values = m_layoutTableCell.col lapsedBorderValues();
64 if (!values)
65 return;
66
77 const ComputedStyle& styleForCellFlow = m_layoutTableCell.styleForCellFlow() ; 67 const ComputedStyle& styleForCellFlow = m_layoutTableCell.styleForCellFlow() ;
78 const CollapsedBorderValue* leftBorderValue = cachedCollapsedLeftBorder(styl eForCellFlow); 68 const CollapsedBorderValue& leftBorderValue = collapsedLeftBorder(styleForCe llFlow, *values);
79 const CollapsedBorderValue* rightBorderValue = cachedCollapsedRightBorder(st yleForCellFlow); 69 const CollapsedBorderValue& rightBorderValue = collapsedRightBorder(styleFor CellFlow, *values);
80 const CollapsedBorderValue* topBorderValue = cachedCollapsedTopBorder(styleF orCellFlow); 70 const CollapsedBorderValue& topBorderValue = collapsedTopBorder(styleForCell Flow, *values);
81 const CollapsedBorderValue* bottomBorderValue = cachedCollapsedBottomBorder( styleForCellFlow); 71 const CollapsedBorderValue& bottomBorderValue = collapsedBottomBorder(styleF orCellFlow, *values);
82 72
83 int displayItemType = DisplayItem::TableCollapsedBorderBase; 73 int displayItemType = DisplayItem::TableCollapsedBorderBase;
84 int topWidth = 0; 74 if (topBorderValue.shouldPaint(currentBorderValue))
85 int bottomWidth = 0; 75 displayItemType |= DisplayItem::TableCollapsedBorderTop;
86 int leftWidth = 0; 76 if (bottomBorderValue.shouldPaint(currentBorderValue))
87 int rightWidth = 0; 77 displayItemType |= DisplayItem::TableCollapsedBorderBottom;
88 if (topBorderValue) { 78 if (leftBorderValue.shouldPaint(currentBorderValue))
89 if (topBorderValue->shouldPaint(currentBorderValue)) 79 displayItemType |= DisplayItem::TableCollapsedBorderLeft;
90 displayItemType |= DisplayItem::TableCollapsedBorderTop; 80 if (rightBorderValue.shouldPaint(currentBorderValue))
91 topWidth = topBorderValue->width(); 81 displayItemType |= DisplayItem::TableCollapsedBorderRight;
92 }
93 if (bottomBorderValue) {
94 if (bottomBorderValue->shouldPaint(currentBorderValue))
95 displayItemType |= DisplayItem::TableCollapsedBorderBottom;
96 bottomWidth = bottomBorderValue->width();
97 }
98 if (leftBorderValue) {
99 if (leftBorderValue->shouldPaint(currentBorderValue))
100 displayItemType |= DisplayItem::TableCollapsedBorderLeft;
101 leftWidth = leftBorderValue->width();
102 }
103 if (rightBorderValue) {
104 if (rightBorderValue->shouldPaint(currentBorderValue))
105 displayItemType |= DisplayItem::TableCollapsedBorderRight;
106 rightWidth = rightBorderValue->width();
107 }
108 if (displayItemType == DisplayItem::TableCollapsedBorderBase) 82 if (displayItemType == DisplayItem::TableCollapsedBorderBase)
109 return; 83 return;
110 84
85 int topWidth = topBorderValue.width();
86 int bottomWidth = bottomBorderValue.width();
87 int leftWidth = leftBorderValue.width();
88 int rightWidth = rightBorderValue.width();
89
111 // Adjust our x/y/width/height so that we paint the collapsed borders at the correct location. 90 // Adjust our x/y/width/height so that we paint the collapsed borders at the correct location.
112 LayoutRect paintRect = paintBounds(paintOffset, AddOffsetFromParent); 91 LayoutRect paintRect = paintBounds(paintOffset, AddOffsetFromParent);
113 IntRect borderRect = pixelSnappedIntRect(paintRect.x() - leftWidth / 2, 92 IntRect borderRect = pixelSnappedIntRect(paintRect.x() - leftWidth / 2,
114 paintRect.y() - topWidth / 2, 93 paintRect.y() - topWidth / 2,
115 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, 94 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2,
116 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); 95 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2);
117 96
118 if (!paintInfo.cullRect().intersectsCullRect(borderRect)) 97 if (!paintInfo.cullRect().intersectsCullRect(borderRect))
119 return; 98 return;
120 99
121 GraphicsContext& graphicsContext = paintInfo.context; 100 GraphicsContext& graphicsContext = paintInfo.context;
122 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(graphicsContext, m_layoutTableCell, static_cast<DisplayItem::Type>(displayItemType))) 101 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(graphicsContext, m_layoutTableCell, static_cast<DisplayItem::Type>(displayItemType)))
123 return; 102 return;
124 103
125 LayoutObjectDrawingRecorder recorder(graphicsContext, m_layoutTableCell, sta tic_cast<DisplayItem::Type>(displayItemType), borderRect); 104 LayoutObjectDrawingRecorder recorder(graphicsContext, m_layoutTableCell, sta tic_cast<DisplayItem::Type>(displayItemType), borderRect);
126 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor); 105 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor);
127 106
128 // We never paint diagonals at the joins. We simply let the border with the highest 107 // We never paint diagonals at the joins. We simply let the border with the highest
129 // precedence paint on top of borders with lower precedence. 108 // precedence paint on top of borders with lower precedence.
130 if (displayItemType & DisplayItem::TableCollapsedBorderTop) { 109 if (displayItemType & DisplayItem::TableCollapsedBorderTop) {
131 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde rRect.y(), borderRect.maxX(), borderRect.y() + topWidth, BSTop, 110 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde rRect.y(), borderRect.maxX(), borderRect.y() + topWidth, BSTop,
132 topBorderValue->color().resolve(cellColor), collapsedBorderStyle(top BorderValue->style()), 0, 0, true); 111 topBorderValue.color().resolve(cellColor), collapsedBorderStyle(topB orderValue.style()), 0, 0, true);
133 } 112 }
134 if (displayItemType & DisplayItem::TableCollapsedBorderBottom) { 113 if (displayItemType & DisplayItem::TableCollapsedBorderBottom) {
135 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde rRect.maxY() - bottomWidth, borderRect.maxX(), borderRect.maxY(), BSBottom, 114 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde rRect.maxY() - bottomWidth, borderRect.maxX(), borderRect.maxY(), BSBottom,
136 bottomBorderValue->color().resolve(cellColor), collapsedBorderStyle( bottomBorderValue->style()), 0, 0, true); 115 bottomBorderValue.color().resolve(cellColor), collapsedBorderStyle(b ottomBorderValue.style()), 0, 0, true);
137 } 116 }
138 if (displayItemType & DisplayItem::TableCollapsedBorderLeft) { 117 if (displayItemType & DisplayItem::TableCollapsedBorderLeft) {
139 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde rRect.y(), borderRect.x() + leftWidth, borderRect.maxY(), BSLeft, 118 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde rRect.y(), borderRect.x() + leftWidth, borderRect.maxY(), BSLeft,
140 leftBorderValue->color().resolve(cellColor), collapsedBorderStyle(le ftBorderValue->style()), 0, 0, true); 119 leftBorderValue.color().resolve(cellColor), collapsedBorderStyle(lef tBorderValue.style()), 0, 0, true);
141 } 120 }
142 if (displayItemType & DisplayItem::TableCollapsedBorderRight) { 121 if (displayItemType & DisplayItem::TableCollapsedBorderRight) {
143 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.maxX() - r ightWidth, borderRect.y(), borderRect.maxX(), borderRect.maxY(), BSRight, 122 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.maxX() - r ightWidth, borderRect.y(), borderRect.maxX(), borderRect.maxY(), BSRight,
144 rightBorderValue->color().resolve(cellColor), collapsedBorderStyle(r ightBorderValue->style()), 0, 0, true); 123 rightBorderValue.color().resolve(cellColor), collapsedBorderStyle(ri ghtBorderValue.style()), 0, 0, true);
145 } 124 }
146 } 125 }
147 126
148 void TableCellPainter::paintBackgroundsBehindCell(const PaintInfo& paintInfo, co nst LayoutPoint& paintOffset, const LayoutObject* backgroundObject, DisplayItem: :Type type) 127 void TableCellPainter::paintBackgroundsBehindCell(const PaintInfo& paintInfo, co nst LayoutPoint& paintOffset, const LayoutObject* backgroundObject, DisplayItem: :Type type)
149 { 128 {
150 if (!backgroundObject) 129 if (!backgroundObject)
151 return; 130 return;
152 131
153 if (m_layoutTableCell.style()->visibility() != VISIBLE) 132 if (m_layoutTableCell.style()->visibility() != VISIBLE)
154 return; 133 return;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBo undOffsetBehavior paintBoundOffsetBehavior) 217 LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBo undOffsetBehavior paintBoundOffsetBehavior)
239 { 218 {
240 LayoutPoint adjustedPaintOffset = paintOffset; 219 LayoutPoint adjustedPaintOffset = paintOffset;
241 if (paintBoundOffsetBehavior == AddOffsetFromParent) 220 if (paintBoundOffsetBehavior == AddOffsetFromParent)
242 adjustedPaintOffset.moveBy(m_layoutTableCell.location()); 221 adjustedPaintOffset.moveBy(m_layoutTableCell.location());
243 return LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSna ppedSize())); 222 return LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSna ppedSize()));
244 } 223 }
245 224
246 } // namespace blink 225 } // namespace blink
247 226
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/TableCellPainter.h ('k') | third_party/WebKit/Source/core/style/CollapsedBorderValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698