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

Side by Side Diff: third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp

Issue 1804963005: Avoid paintInvalidationContainer parameter of invalidatePaintIfNeeded() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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/layout/PaintInvalidationState.h" 5 #include "core/layout/PaintInvalidationState.h"
6 6
7 #include "core/layout/LayoutInline.h" 7 #include "core/layout/LayoutInline.h"
8 #include "core/layout/LayoutView.h" 8 #include "core/layout/LayoutView.h"
9 #include "core/layout/svg/LayoutSVGModelObject.h" 9 #include "core/layout/svg/LayoutSVGModelObject.h"
10 #include "core/layout/svg/LayoutSVGRoot.h" 10 #include "core/layout/svg/LayoutSVGRoot.h"
11 #include "core/paint/PaintLayer.h" 11 #include "core/paint/PaintLayer.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vec tor<LayoutObject*>& pendingDelayedPaintInvalidations, PaintInvalidationState* ow nerPaintInvalidationState) 15 PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vec tor<LayoutObject*>& pendingDelayedPaintInvalidations, const PaintInvalidationSta te* ownerPaintInvalidationState)
16 : m_clipped(false) 16 : m_currentObject(layoutView)
17 , m_clipped(false)
17 , m_cachedOffsetsEnabled(true) 18 , m_cachedOffsetsEnabled(true)
18 , m_forcedSubtreeInvalidationWithinContainer(false) 19 , m_forcedSubtreeInvalidationWithinContainer(false)
19 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(false) 20 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(false)
20 , m_viewClippingAndScrollOffsetDisabled(false) 21 , m_viewClippingAndScrollOffsetDisabled(false)
21 , m_paintInvalidationContainer(layoutView.containerForPaintInvalidation()) 22 , m_paintInvalidationContainer(layoutView.containerForPaintInvalidation())
22 , m_pendingDelayedPaintInvalidations(pendingDelayedPaintInvalidations) 23 , m_pendingDelayedPaintInvalidations(pendingDelayedPaintInvalidations)
23 , m_enclosingSelfPaintingLayer(*layoutView.layer()) 24 , m_enclosingSelfPaintingLayer(*layoutView.layer())
25 #if ENABLE(ASSERT)
26 , m_didUpdatePaintOffsetAndClipForChildren(true)
27 #endif
24 { 28 {
29 ASSERT(!ownerPaintInvalidationState || ownerPaintInvalidationState->m_didUpd atePaintOffsetAndClipForChildren);
30
25 bool establishesPaintInvalidationContainer = layoutView == m_paintInvalidati onContainer; 31 bool establishesPaintInvalidationContainer = layoutView == m_paintInvalidati onContainer;
26 if (!establishesPaintInvalidationContainer) { 32 if (!establishesPaintInvalidationContainer) {
27 if ((ownerPaintInvalidationState && !ownerPaintInvalidationState->m_cach edOffsetsEnabled) 33 if ((ownerPaintInvalidationState && !ownerPaintInvalidationState->m_cach edOffsetsEnabled)
28 || !layoutView.supportsPaintInvalidationStateCachedOffsets()) { 34 || !layoutView.supportsPaintInvalidationStateCachedOffsets()) {
29 m_cachedOffsetsEnabled = false; 35 m_cachedOffsetsEnabled = false;
30 return; 36 return;
31 } 37 }
32 if (ownerPaintInvalidationState && ownerPaintInvalidationState->m_forced SubtreeInvalidationWithinContainer) 38 if (ownerPaintInvalidationState && ownerPaintInvalidationState->m_forced SubtreeInvalidationWithinContainer)
33 m_forcedSubtreeInvalidationWithinContainer = true; 39 m_forcedSubtreeInvalidationWithinContainer = true;
34 FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), &m_pain tInvalidationContainer, TraverseDocumentBoundaries); 40 FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), &m_pain tInvalidationContainer, TraverseDocumentBoundaries);
35 m_paintOffset = LayoutSize(point.x(), point.y()); 41 m_paintOffset = LayoutSize(point.x(), point.y());
36 } 42 }
37 m_clipRect = layoutView.viewRect(); 43 m_clipRect = layoutView.viewRect();
38 m_clipRect.move(m_paintOffset); 44 m_clipRect.move(m_paintOffset);
39 m_clipped = true; 45 m_clipped = true;
40 } 46 }
41 47
42 PaintInvalidationState::PaintInvalidationState(PaintInvalidationState& next, Lay outBoxModelObject& layoutObject, const LayoutBoxModelObject& paintInvalidationCo ntainer) 48 // TODO(wangxianzhu): This is temporary for positioned object whose paintInvalid ationContainer is different from
43 : m_clipped(false) 49 // the one we find during tree walk. Remove this after we fix the issue with tre e walk in DOM-order.
44 , m_cachedOffsetsEnabled(true) 50 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par entState, const LayoutBoxModelObject& currentObject, const LayoutBoxModelObject& paintInvalidationContainer)
45 , m_forcedSubtreeInvalidationWithinContainer(next.m_forcedSubtreeInvalidatio nWithinContainer) 51 : m_currentObject(currentObject)
46 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(next.m_forcedSubtreeI nvalidationRectUpdateWithinContainer) 52 , m_clipped(parentState.m_clipped)
53 , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled)
54 , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInva lidationWithinContainer)
55 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedS ubtreeInvalidationRectUpdateWithinContainer)
47 , m_viewClippingAndScrollOffsetDisabled(false) 56 , m_viewClippingAndScrollOffsetDisabled(false)
57 , m_clipRect(parentState.m_clipRect)
58 , m_paintOffset(parentState.m_paintOffset)
48 , m_paintInvalidationContainer(paintInvalidationContainer) 59 , m_paintInvalidationContainer(paintInvalidationContainer)
49 , m_pendingDelayedPaintInvalidations(next.pendingDelayedPaintInvalidationTar gets()) 60 , m_svgTransform(parentState.m_svgTransform)
50 , m_enclosingSelfPaintingLayer(next.enclosingSelfPaintingLayer(layoutObject) ) 61 , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalida tionTargets())
62 , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(curren tObject))
63 #if ENABLE(ASSERT)
64 , m_didUpdatePaintOffsetAndClipForChildren(true)
65 #endif
51 { 66 {
52 // FIXME: SVG could probably benefit from a stack-based optimization like ht ml does. crbug.com/391054 67 ASSERT(parentState.m_didUpdatePaintOffsetAndClipForChildren);
53 bool establishesPaintInvalidationContainer = layoutObject == m_paintInvalida tionContainer; 68 ASSERT(!m_cachedOffsetsEnabled);
54 bool fixed = layoutObject.style()->position() == FixedPosition; 69 }
55 70
56 if (!layoutObject.supportsPaintInvalidationStateCachedOffsets() || !next.m_c achedOffsetsEnabled) 71 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par entState, const LayoutObject& currentObject)
72 : m_currentObject(currentObject)
73 , m_clipped(parentState.m_clipped)
74 , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled)
75 , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInva lidationWithinContainer)
76 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedS ubtreeInvalidationRectUpdateWithinContainer)
77 , m_viewClippingAndScrollOffsetDisabled(false)
78 , m_clipRect(parentState.m_clipRect)
79 , m_paintOffset(parentState.m_paintOffset)
80 , m_paintInvalidationContainer(currentObject.isPaintInvalidationContainer() ? toLayoutBoxModelObject(currentObject) : parentState.m_paintInvalidationContain er)
81 , m_svgTransform(parentState.m_svgTransform)
82 , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalida tionTargets())
83 , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(curren tObject))
84 #if ENABLE(ASSERT)
85 , m_didUpdatePaintOffsetAndClipForChildren(false)
86 #endif
87 {
88 ASSERT(parentState.m_didUpdatePaintOffsetAndClipForChildren);
89 }
90
91 void PaintInvalidationState::updatePaintOffsetAndClipForChildren()
92 {
93 #if ENABLE(ASSERT)
94 ASSERT(!m_didUpdatePaintOffsetAndClipForChildren);
95 m_didUpdatePaintOffsetAndClipForChildren = true;
96 #endif
97
98 bool establishesPaintInvalidationContainer = m_currentObject == m_paintInval idationContainer;
99
100 if (!m_currentObject.isBoxModelObject()) {
101 // TODO(wangxianzhu): SVG could probably benefit from a stack-based opti mization like html does. crbug.com/391054.
102 ASSERT(m_currentObject.isSVG());
103 ASSERT(!establishesPaintInvalidationContainer);
104 if (m_cachedOffsetsEnabled)
105 m_svgTransform = AffineTransform(m_svgTransform * m_currentObject.lo calToParentTransform());
106 return;
107 }
108
109 bool fixed = m_currentObject.style()->position() == FixedPosition;
110
111 if (!m_currentObject.supportsPaintInvalidationStateCachedOffsets())
57 m_cachedOffsetsEnabled = false; 112 m_cachedOffsetsEnabled = false;
58 if (establishesPaintInvalidationContainer) { 113 if (establishesPaintInvalidationContainer) {
59 // When we hit a new paint invalidation container, we don't need to 114 // When we hit a new paint invalidation container, we don't need to
60 // continue forcing a check for paint invalidation, since we're 115 // continue forcing a check for paint invalidation, since we're
61 // descending into a different invalidation container. (For instance if 116 // descending into a different invalidation container. (For instance if
62 // our parents were moved, the entire container will just move.) 117 // our parents were moved, the entire container will just move.)
63 m_forcedSubtreeInvalidationWithinContainer = false; 118 m_forcedSubtreeInvalidationWithinContainer = false;
119 m_forcedSubtreeInvalidationRectUpdateWithinContainer = false;
120
121 m_clipped = false; // Will be updated in applyClipIfNeeded().
122 m_paintOffset = LayoutSize();
64 } else { 123 } else {
65 if (m_cachedOffsetsEnabled) { 124 if (m_cachedOffsetsEnabled) {
66 if (fixed) { 125 if (fixed) {
67 FloatPoint fixedOffset = layoutObject.localToAncestorPoint(Float Point(), &m_paintInvalidationContainer, TraverseDocumentBoundaries); 126 FloatPoint fixedOffset = m_currentObject.localToAncestorPoint(Fl oatPoint(), &m_paintInvalidationContainer, TraverseDocumentBoundaries);
68 m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y()); 127 m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y());
69 } else { 128 } else if (m_currentObject.isBox() && !m_currentObject.isTableRow()) {
70 LayoutSize offset = layoutObject.isBox() && !layoutObject.isTabl eRow() ? toLayoutBox(layoutObject).locationOffset() : LayoutSize(); 129 // We don't add locationOffset of table row because the child ce lls' location offsets include the row's location offset.
71 m_paintOffset = next.m_paintOffset + offset; 130 m_paintOffset += toLayoutBox(m_currentObject).locationOffset();
72 } 131 }
73 132
74 if (layoutObject.isOutOfFlowPositioned() && !fixed) { 133 if (m_currentObject.isOutOfFlowPositioned() && !fixed) {
75 if (LayoutObject* container = layoutObject.container()) { 134 if (LayoutObject* container = m_currentObject.container()) {
76 if (container->isInFlowPositioned() && container->isLayoutIn line()) 135 if (container->isInFlowPositioned() && container->isLayoutIn line())
77 m_paintOffset += toLayoutInline(container)->offsetForInF lowPositionedInline(toLayoutBox(layoutObject)); 136 m_paintOffset += toLayoutInline(container)->offsetForInF lowPositionedInline(toLayoutBox(m_currentObject));
78 } 137 }
79 } 138 }
80 139
81 if (layoutObject.isInFlowPositioned() && layoutObject.hasLayer()) 140 if (m_currentObject.isInFlowPositioned() && m_currentObject.hasLayer ())
82 m_paintOffset += layoutObject.layer()->offsetForInFlowPosition() ; 141 m_paintOffset += toLayoutBoxModelObject(m_currentObject).layer() ->offsetForInFlowPosition();
83 } 142 }
84 143
85 m_clipped = !fixed && next.m_clipped; 144 m_clipped = !fixed && m_clipped;
86 if (m_clipped)
87 m_clipRect = next.m_clipRect;
88 } 145 }
89 146
90 if (m_cachedOffsetsEnabled && layoutObject.isSVGRoot()) { 147 if (m_cachedOffsetsEnabled && m_currentObject.isSVGRoot()) {
91 const LayoutSVGRoot& svgRoot = toLayoutSVGRoot(layoutObject); 148 const LayoutSVGRoot& svgRoot = toLayoutSVGRoot(m_currentObject);
92 m_svgTransform = AffineTransform(svgRoot.localToBorderBoxTransform()); 149 m_svgTransform = AffineTransform(svgRoot.localToBorderBoxTransform());
93 if (svgRoot.shouldApplyViewportClip()) 150 if (svgRoot.shouldApplyViewportClip())
94 addClipRectRelativeToPaintOffset(LayoutSize(svgRoot.pixelSnappedSize ())); 151 addClipRectRelativeToPaintOffset(LayoutSize(svgRoot.pixelSnappedSize ()));
95 } 152 }
96 153
97 applyClipIfNeeded(layoutObject); 154 applyClipIfNeeded();
98 155
99 // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present. 156 // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present.
100 } 157 }
101 158
102 PaintInvalidationState::PaintInvalidationState(PaintInvalidationState& next, con st LayoutSVGModelObject& layoutObject)
103 : m_clipped(next.m_clipped)
104 , m_cachedOffsetsEnabled(next.m_cachedOffsetsEnabled)
105 , m_forcedSubtreeInvalidationWithinContainer(next.m_forcedSubtreeInvalidatio nWithinContainer)
106 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(next.m_forcedSubtreeI nvalidationRectUpdateWithinContainer)
107 , m_viewClippingAndScrollOffsetDisabled(false)
108 , m_clipRect(next.m_clipRect)
109 , m_paintOffset(next.m_paintOffset)
110 , m_paintInvalidationContainer(next.m_paintInvalidationContainer)
111 , m_pendingDelayedPaintInvalidations(next.pendingDelayedPaintInvalidationTar gets())
112 , m_enclosingSelfPaintingLayer(next.enclosingSelfPaintingLayer(layoutObject) )
113 {
114 ASSERT(layoutObject != m_paintInvalidationContainer);
115
116 if (m_cachedOffsetsEnabled)
117 m_svgTransform = AffineTransform(next.svgTransform() * layoutObject.loca lToParentTransform());
118 }
119
120 void PaintInvalidationState::mapObjectRectToAncestor(const LayoutObject& object, const LayoutBoxModelObject* ancestor, LayoutRect& rect) const 159 void PaintInvalidationState::mapObjectRectToAncestor(const LayoutObject& object, const LayoutBoxModelObject* ancestor, LayoutRect& rect) const
121 { 160 {
122 ASSERT(canMapToAncestor(ancestor)); 161 ASSERT(canMapToAncestor(ancestor));
123 162
124 if (ancestor == &object) { 163 if (ancestor == &object) {
125 if (object.isBox() && object.styleRef().isFlippedBlocksWritingMode()) 164 if (object.isBox() && object.styleRef().isFlippedBlocksWritingMode())
126 toLayoutBox(object).flipForWritingMode(rect); 165 toLayoutBox(object).flipForWritingMode(rect);
127 return; 166 return;
128 } 167 }
129 168
(...skipping 18 matching lines...) Expand all
148 { 187 {
149 LayoutRect clipRect(toPoint(m_paintOffset), clipSize); 188 LayoutRect clipRect(toPoint(m_paintOffset), clipSize);
150 if (m_clipped) { 189 if (m_clipped) {
151 m_clipRect.intersect(clipRect); 190 m_clipRect.intersect(clipRect);
152 } else { 191 } else {
153 m_clipRect = clipRect; 192 m_clipRect = clipRect;
154 m_clipped = true; 193 m_clipped = true;
155 } 194 }
156 } 195 }
157 196
158 void PaintInvalidationState::applyClipIfNeeded(const LayoutObject& layoutObject) 197 void PaintInvalidationState::applyClipIfNeeded()
159 { 198 {
160 if (!layoutObject.hasOverflowClip()) 199 if (!m_currentObject.hasOverflowClip())
161 return; 200 return;
162 201
163 const LayoutBox& box = toLayoutBox(layoutObject); 202 const LayoutBox& box = toLayoutBox(m_currentObject);
164 203
165 // Do not clip scroll layer contents because the compositor expects the whol e layer 204 // Do not clip scroll layer contents because the compositor expects the whol e layer
166 // to be always invalidated in-time. 205 // to be always invalidated in-time.
167 if (box.usesCompositedScrolling()) 206 if (box.usesCompositedScrolling())
168 ASSERT(!m_clipped); // The box should establish paint invalidation conta iner, so no m_clipped inherited. 207 ASSERT(!m_clipped); // The box should establish paint invalidation conta iner, so no m_clipped inherited.
169 else 208 else
170 addClipRectRelativeToPaintOffset(LayoutSize(box.layer()->size())); 209 addClipRectRelativeToPaintOffset(LayoutSize(box.layer()->size()));
171 210
172 m_paintOffset -= box.scrolledContentOffset(); 211 m_paintOffset -= box.scrolledContentOffset();
173 } 212 }
174 213
175 PaintLayer& PaintInvalidationState::enclosingSelfPaintingLayer(const LayoutObjec t& layoutObject) const 214 PaintLayer& PaintInvalidationState::enclosingSelfPaintingLayer(const LayoutObjec t& layoutObject) const
176 { 215 {
177 if (layoutObject.hasLayer() && toLayoutBoxModelObject(layoutObject).hasSelfP aintingLayer()) 216 if (layoutObject.hasLayer() && toLayoutBoxModelObject(layoutObject).hasSelfP aintingLayer())
178 return *toLayoutBoxModelObject(layoutObject).layer(); 217 return *toLayoutBoxModelObject(layoutObject).layer();
179 218
180 return m_enclosingSelfPaintingLayer; 219 return m_enclosingSelfPaintingLayer;
181 } 220 }
182 221
183 } // namespace blink 222 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698