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

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

Issue 1813383002: Move all fast-path paint invalidation mapping into PaintInvalidationState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 8 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/frame/FrameView.h"
8 #include "core/frame/Settings.h"
7 #include "core/layout/LayoutInline.h" 9 #include "core/layout/LayoutInline.h"
10 #include "core/layout/LayoutPart.h"
8 #include "core/layout/LayoutView.h" 11 #include "core/layout/LayoutView.h"
9 #include "core/layout/svg/LayoutSVGModelObject.h" 12 #include "core/layout/svg/LayoutSVGModelObject.h"
10 #include "core/layout/svg/LayoutSVGRoot.h" 13 #include "core/layout/svg/LayoutSVGRoot.h"
14 #include "core/layout/svg/SVGLayoutSupport.h"
11 #include "core/paint/PaintLayer.h" 15 #include "core/paint/PaintLayer.h"
12 16
13 namespace blink { 17 namespace blink {
14 18
15 PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vec tor<LayoutObject*>& pendingDelayedPaintInvalidations, const PaintInvalidationSta te* ownerPaintInvalidationState) 19 static bool supportsCachedOffsets(const LayoutObject& object)
20 {
21 // TODO(wangxianzhu): Move some conditions to fast path if possible.
22 return !object.hasTransformRelatedProperty()
23 && !object.hasReflection()
24 && !object.hasFilter()
25 && !object.isLayoutFlowThread()
26 && !object.isLayoutMultiColumnSpannerPlaceholder()
27 && object.styleRef().position() != FixedPosition
28 && !object.styleRef().isFlippedBlocksWritingMode();
29 }
30
31 PaintInvalidationState::PaintInvalidationState(const LayoutView& layoutView, Vec tor<LayoutObject*>& pendingDelayedPaintInvalidations)
16 : m_currentObject(layoutView) 32 : m_currentObject(layoutView)
17 , m_clipped(false) 33 , m_clipped(false)
18 , m_cachedOffsetsEnabled(true) 34 , m_cachedOffsetsEnabled(true)
19 , m_forcedSubtreeInvalidationWithinContainer(false) 35 , m_forcedSubtreeInvalidationWithinContainer(false)
20 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(false) 36 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(false)
21 , m_viewClippingAndScrollOffsetDisabled(false)
22 , m_paintInvalidationContainer(layoutView.containerForPaintInvalidation()) 37 , m_paintInvalidationContainer(layoutView.containerForPaintInvalidation())
23 , m_pendingDelayedPaintInvalidations(pendingDelayedPaintInvalidations) 38 , m_pendingDelayedPaintInvalidations(pendingDelayedPaintInvalidations)
24 , m_enclosingSelfPaintingLayer(*layoutView.layer()) 39 , m_enclosingSelfPaintingLayer(*layoutView.layer())
25 #if ENABLE(ASSERT) 40 #if ENABLE(ASSERT)
26 , m_didUpdatePaintOffsetAndClipForChildren(true) 41 , m_didUpdateForChildren(false)
27 #endif 42 #endif
28 { 43 {
29 ASSERT(!ownerPaintInvalidationState || ownerPaintInvalidationState->m_didUpd atePaintOffsetAndClipForChildren); 44 if (!supportsCachedOffsets(layoutView)) {
45 m_cachedOffsetsEnabled = false;
46 return;
47 }
30 48
31 bool establishesPaintInvalidationContainer = layoutView == m_paintInvalidati onContainer; 49 FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), &m_paintInv alidationContainer, TraverseDocumentBoundaries | InputIsInFrameCoordinates);
32 if (!establishesPaintInvalidationContainer) { 50 m_paintOffset = LayoutSize(point.x(), point.y());
33 if ((ownerPaintInvalidationState && !ownerPaintInvalidationState->m_cach edOffsetsEnabled)
34 || !layoutView.supportsPaintInvalidationStateCachedOffsets()) {
35 m_cachedOffsetsEnabled = false;
36 return;
37 }
38 if (ownerPaintInvalidationState && ownerPaintInvalidationState->m_forced SubtreeInvalidationWithinContainer)
39 m_forcedSubtreeInvalidationWithinContainer = true;
40 FloatPoint point = layoutView.localToAncestorPoint(FloatPoint(), &m_pain tInvalidationContainer, TraverseDocumentBoundaries);
41 m_paintOffset = LayoutSize(point.x(), point.y());
42 }
43 m_clipRect = layoutView.viewRect();
44 m_clipRect.move(m_paintOffset);
45 m_clipped = true;
46 } 51 }
47 52
48 // TODO(wangxianzhu): This is temporary for positioned object whose paintInvalid ationContainer is different from 53 // TODO(wangxianzhu): This is temporary for positioned object whose paintInvalid ationContainer is different from
49 // the one we find during tree walk. Remove this after we fix the issue with tre e walk in DOM-order. 54 // the one we find during tree walk. Remove this after we fix the issue with tre e walk in DOM-order.
50 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par entState, const LayoutBoxModelObject& currentObject, const LayoutBoxModelObject& paintInvalidationContainer) 55 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par entState, const LayoutBoxModelObject& currentObject, const LayoutBoxModelObject& paintInvalidationContainer)
51 : m_currentObject(currentObject) 56 : m_currentObject(currentObject)
52 , m_clipped(parentState.m_clipped) 57 , m_clipped(parentState.m_clipped)
53 , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled) 58 , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled)
54 , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInva lidationWithinContainer) 59 , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInva lidationWithinContainer)
55 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedS ubtreeInvalidationRectUpdateWithinContainer) 60 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedS ubtreeInvalidationRectUpdateWithinContainer)
56 , m_viewClippingAndScrollOffsetDisabled(false)
57 , m_clipRect(parentState.m_clipRect) 61 , m_clipRect(parentState.m_clipRect)
58 , m_paintOffset(parentState.m_paintOffset) 62 , m_paintOffset(parentState.m_paintOffset)
59 , m_paintInvalidationContainer(paintInvalidationContainer) 63 , m_paintInvalidationContainer(paintInvalidationContainer)
60 , m_svgTransform(parentState.m_svgTransform) 64 , m_svgTransform(parentState.m_svgTransform)
61 , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalida tionTargets()) 65 , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalida tionTargets())
62 , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(curren tObject)) 66 , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(curren tObject))
63 #if ENABLE(ASSERT) 67 #if ENABLE(ASSERT)
64 , m_didUpdatePaintOffsetAndClipForChildren(true) 68 , m_didUpdateForChildren(true)
65 #endif 69 #endif
66 { 70 {
67 ASSERT(parentState.m_didUpdatePaintOffsetAndClipForChildren); 71 ASSERT(parentState.m_didUpdateForChildren);
68 ASSERT(!m_cachedOffsetsEnabled); 72 ASSERT(!m_cachedOffsetsEnabled);
69 } 73 }
70 74
71 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par entState, const LayoutObject& currentObject) 75 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& par entState, const LayoutObject& currentObject)
72 : m_currentObject(currentObject) 76 : m_currentObject(currentObject)
73 , m_clipped(parentState.m_clipped) 77 , m_clipped(parentState.m_clipped)
74 , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled) 78 , m_cachedOffsetsEnabled(parentState.m_cachedOffsetsEnabled)
75 , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInva lidationWithinContainer) 79 , m_forcedSubtreeInvalidationWithinContainer(parentState.m_forcedSubtreeInva lidationWithinContainer)
76 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedS ubtreeInvalidationRectUpdateWithinContainer) 80 , m_forcedSubtreeInvalidationRectUpdateWithinContainer(parentState.m_forcedS ubtreeInvalidationRectUpdateWithinContainer)
77 , m_viewClippingAndScrollOffsetDisabled(false)
78 , m_clipRect(parentState.m_clipRect) 81 , m_clipRect(parentState.m_clipRect)
79 , m_paintOffset(parentState.m_paintOffset) 82 , m_paintOffset(parentState.m_paintOffset)
80 , m_paintInvalidationContainer(currentObject.isPaintInvalidationContainer() ? toLayoutBoxModelObject(currentObject) : parentState.m_paintInvalidationContain er) 83 , m_paintInvalidationContainer(currentObject.isPaintInvalidationContainer() ? toLayoutBoxModelObject(currentObject) : parentState.m_paintInvalidationContain er)
81 , m_svgTransform(parentState.m_svgTransform) 84 , m_svgTransform(parentState.m_svgTransform)
82 , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalida tionTargets()) 85 , m_pendingDelayedPaintInvalidations(parentState.pendingDelayedPaintInvalida tionTargets())
83 , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(curren tObject)) 86 , m_enclosingSelfPaintingLayer(parentState.enclosingSelfPaintingLayer(curren tObject))
84 #if ENABLE(ASSERT) 87 #if ENABLE(ASSERT)
85 , m_didUpdatePaintOffsetAndClipForChildren(false) 88 , m_didUpdateForChildren(false)
86 #endif 89 #endif
87 { 90 {
88 ASSERT(parentState.m_didUpdatePaintOffsetAndClipForChildren); 91 if (currentObject == parentState.m_currentObject) {
89 } 92 // Sometimes we create a new PaintInvalidationState from parentState on the same object
90 93 // (e.g. LayoutView, and the HorriblySlowRectMapping cases in LayoutBloc k::invalidatePaintOfSubtreesIfNeeded()).
91 void PaintInvalidationState::updatePaintOffsetAndClipForChildren() 94 // TODO(wangxianzhu): Avoid this for RuntimeEnabledFeatures::slimmingPai ntInvalidationEnabled().
92 {
93 #if ENABLE(ASSERT) 95 #if ENABLE(ASSERT)
94 ASSERT(!m_didUpdatePaintOffsetAndClipForChildren); 96 m_didUpdateForChildren = parentState.m_didUpdateForChildren;
95 m_didUpdatePaintOffsetAndClipForChildren = true;
96 #endif 97 #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 calToSVGParentTransform());
106 return; 98 return;
107 } 99 }
108 100
109 bool fixed = m_currentObject.style()->position() == FixedPosition; 101 ASSERT(parentState.m_didUpdateForChildren);
110 102
111 if (!m_currentObject.supportsPaintInvalidationStateCachedOffsets()) 103 if (!currentObject.isBoxModelObject() && !currentObject.isSVG())
104 return;
105
106 if (m_cachedOffsetsEnabled && !supportsCachedOffsets(currentObject))
112 m_cachedOffsetsEnabled = false; 107 m_cachedOffsetsEnabled = false;
113 if (establishesPaintInvalidationContainer) { 108
109 if (currentObject.isSVG()) {
110 if (currentObject.isSVGRoot()) {
111 m_svgTransform = toLayoutSVGRoot(currentObject).localToBorderBoxTran sform();
112 // Don't early return here, because the SVGRoot object needs to exec ute the later code
113 // as a normal LayoutBox.
114 } else {
115 ASSERT(currentObject != m_paintInvalidationContainer);
116 m_svgTransform *= currentObject.localToSVGParentTransform();
117 return;
118 }
119 }
120
121 if (currentObject == m_paintInvalidationContainer) {
114 // When we hit a new paint invalidation container, we don't need to 122 // When we hit a new paint invalidation container, we don't need to
115 // continue forcing a check for paint invalidation, since we're 123 // continue forcing a check for paint invalidation, since we're
116 // descending into a different invalidation container. (For instance if 124 // descending into a different invalidation container. (For instance if
117 // our parents were moved, the entire container will just move.) 125 // our parents were moved, the entire container will just move.)
118 m_forcedSubtreeInvalidationWithinContainer = false; 126 m_forcedSubtreeInvalidationWithinContainer = false;
119 m_forcedSubtreeInvalidationRectUpdateWithinContainer = false; 127 m_forcedSubtreeInvalidationRectUpdateWithinContainer = false;
120 128
121 m_clipped = false; // Will be updated in applyClipIfNeeded(). 129 m_clipped = false; // Will be updated in updateForChildren().
122 m_paintOffset = LayoutSize(); 130 m_paintOffset = LayoutSize();
123 } else { 131 return;
124 if (m_cachedOffsetsEnabled) { 132 }
125 if (fixed) { 133
126 FloatPoint fixedOffset = m_currentObject.localToAncestorPoint(Fl oatPoint(), &m_paintInvalidationContainer, TraverseDocumentBoundaries); 134 if (!m_cachedOffsetsEnabled)
127 m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y()); 135 return;
128 } else if (m_currentObject.isBox() && !m_currentObject.isTableRow()) { 136
129 // We don't add locationOffset of table row because the child ce lls' location offsets include the row's location offset. 137 if (currentObject.isLayoutView()) {
130 m_paintOffset += toLayoutBox(m_currentObject).locationOffset(); 138 ASSERT(&parentState.m_currentObject == toLayoutView(currentObject).frame ()->ownerLayoutObject());
139 m_paintOffset += toLayoutBox(parentState.m_currentObject).contentBoxOffs et();
140 return;
141 }
142
143 if (currentObject.isBox())
144 m_paintOffset += toLayoutBox(currentObject).locationOffset();
145
146 if (currentObject.styleRef().position() == AbsolutePosition) {
147 if (LayoutObject* container = currentObject.container()) {
148 if (container->isInFlowPositioned() && container->isLayoutInline())
149 m_paintOffset += toLayoutInline(container)->offsetForInFlowPosit ionedInline(toLayoutBox(currentObject));
150 }
151 return;
152 }
153
154 if (currentObject.isInFlowPositioned() && currentObject.hasLayer())
155 m_paintOffset += toLayoutBoxModelObject(currentObject).layer()->offsetFo rInFlowPosition();
156 }
157
158 void PaintInvalidationState::updateForChildren()
159 {
160 #if ENABLE(ASSERT)
161 ASSERT(!m_didUpdateForChildren);
162 m_didUpdateForChildren = true;
163 #endif
164
165 if (!m_cachedOffsetsEnabled)
166 return;
167
168 if (!m_currentObject.isBoxModelObject() && !m_currentObject.isSVG())
169 return;
170
171 if (m_currentObject.isLayoutView()) {
172 if (!m_currentObject.document().settings() || !m_currentObject.document( ).settings()->rootLayerScrolls()) {
173 if (m_currentObject != m_paintInvalidationContainer) {
174 m_paintOffset -= toLayoutView(m_currentObject).frameView()->scro llOffset();
175 addClipRectRelativeToPaintOffset(toLayoutView(m_currentObject).v iewRect());
131 } 176 }
132 177 return;
133 if (m_currentObject.isOutOfFlowPositioned() && !fixed) {
134 if (LayoutObject* container = m_currentObject.container()) {
135 if (container->isInFlowPositioned() && container->isLayoutIn line())
136 m_paintOffset += toLayoutInline(container)->offsetForInF lowPositionedInline(toLayoutBox(m_currentObject));
137 }
138 }
139
140 if (m_currentObject.isInFlowPositioned() && m_currentObject.hasLayer ())
141 m_paintOffset += toLayoutBoxModelObject(m_currentObject).layer() ->offsetForInFlowPosition();
142 } 178 }
143 179 } else if (m_currentObject.isSVGRoot()) {
144 m_clipped = !fixed && m_clipped;
145 }
146
147 if (m_cachedOffsetsEnabled && m_currentObject.isSVGRoot()) {
148 const LayoutSVGRoot& svgRoot = toLayoutSVGRoot(m_currentObject); 180 const LayoutSVGRoot& svgRoot = toLayoutSVGRoot(m_currentObject);
149 m_svgTransform = AffineTransform(svgRoot.localToBorderBoxTransform());
150 if (svgRoot.shouldApplyViewportClip()) 181 if (svgRoot.shouldApplyViewportClip())
151 addClipRectRelativeToPaintOffset(LayoutSize(svgRoot.pixelSnappedSize ())); 182 addClipRectRelativeToPaintOffset(LayoutRect(LayoutPoint(), LayoutSiz e(svgRoot.pixelSnappedSize())));
152 } 183 } else if (m_currentObject.isTableRow()) {
153 184 // Child table cell's locationOffset() includes its row's locationOffset ().
154 applyClipIfNeeded(); 185 m_paintOffset -= toLayoutBox(m_currentObject).locationOffset();
155 186 }
156 // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present. 187
157 }
158
159 bool PaintInvalidationState::mapObjectRectToAncestor(const LayoutObject& object, const LayoutBoxModelObject* ancestor, LayoutRect& rect, VisibleRectFlags visibl eRectFlags) const
160 {
161 ASSERT(canMapToAncestor(ancestor));
162
163 if (ancestor == &object) {
164 if (object.isBox() && object.styleRef().isFlippedBlocksWritingMode())
165 toLayoutBox(object).flipForWritingMode(rect);
166 return true;
167 }
168
169 if (object.hasLayer()) {
170 if (const TransformationMatrix* transform = toLayoutBoxModelObject(objec t).layer()->transform())
171 rect = LayoutRect(transform->mapRect(pixelSnappedIntRect(rect)));
172
173 if (object.isInFlowPositioned())
174 rect.move(toLayoutBoxModelObject(object).layer()->offsetForInFlowPos ition());
175 }
176
177 if (object.isBox())
178 rect.moveBy(toLayoutBox(object).location());
179
180 rect.move(m_paintOffset);
181
182 if (m_clipped) {
183 if (visibleRectFlags & EdgeInclusive)
184 return rect.inclusiveIntersect(m_clipRect);
185 rect.intersect(m_clipRect);
186 }
187
188 return !rect.isEmpty();
189 }
190
191 void PaintInvalidationState::addClipRectRelativeToPaintOffset(const LayoutSize& clipSize)
192 {
193 LayoutRect clipRect(toPoint(m_paintOffset), clipSize);
194 if (m_clipped) {
195 m_clipRect.intersect(clipRect);
196 } else {
197 m_clipRect = clipRect;
198 m_clipped = true;
199 }
200 }
201
202 void PaintInvalidationState::applyClipIfNeeded()
203 {
204 if (!m_currentObject.hasOverflowClip()) 188 if (!m_currentObject.hasOverflowClip())
205 return; 189 return;
206 190
207 const LayoutBox& box = toLayoutBox(m_currentObject); 191 const LayoutBox& box = toLayoutBox(m_currentObject);
208 192
209 // Do not clip scroll layer contents because the compositor expects the whol e layer 193 // Do not clip scroll layer contents because the compositor expects the whol e layer
210 // to be always invalidated in-time. 194 // to be always invalidated in-time.
211 if (box.usesCompositedScrolling()) 195 if (box.usesCompositedScrolling())
212 ASSERT(!m_clipped); // The box should establish paint invalidation conta iner, so no m_clipped inherited. 196 ASSERT(!m_clipped); // The box should establish paint invalidation conta iner, so no m_clipped inherited.
213 else 197 else
214 addClipRectRelativeToPaintOffset(LayoutSize(box.layer()->size())); 198 addClipRectRelativeToPaintOffset(LayoutRect(LayoutPoint(), LayoutSize(bo x.layer()->size())));
215 199
216 m_paintOffset -= box.scrolledContentOffset(); 200 m_paintOffset -= box.scrolledContentOffset();
201
202 // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present.
203 }
204
205 static FloatPoint slowLocalToAncestorPoint(const LayoutObject& object, const Lay outBoxModelObject& ancestor, const FloatPoint& point)
206 {
207 if (object.isLayoutView())
208 return toLayoutView(object).localToAncestorPoint(point, &ancestor, Trave rseDocumentBoundaries | InputIsInFrameCoordinates);
209 return object.localToAncestorPoint(point, &ancestor, TraverseDocumentBoundar ies);
210 }
211
212 LayoutPoint PaintInvalidationState::computePositionFromPaintInvalidationBacking( ) const
213 {
214 ASSERT(!m_didUpdateForChildren);
215
216 FloatPoint point;
217 if (m_paintInvalidationContainer != m_currentObject) {
218 if (m_cachedOffsetsEnabled) {
219 if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot())
220 point = m_svgTransform.mapPoint(point);
221 point += FloatPoint(m_paintOffset);
222 #ifndef NDEBUG
223 // Make sure that the fast path and the slow path generate the same point.
224 // TODO(wangxianzhu): We can't enable this ASSERT for now because of crbug.com/597745.
225 // ASSERT(point == slowLocalOriginToAncestorPoint(m_currentObject, m _paintInvalidationContainer, FloatPoint());
226 #endif
227 } else {
228 point = slowLocalToAncestorPoint(m_currentObject, m_paintInvalidatio nContainer, FloatPoint());
229 }
230 }
231
232 if (m_paintInvalidationContainer.layer()->groupedMapping())
233 PaintLayer::mapPointInPaintInvalidationContainerToBacking(m_paintInvalid ationContainer, point);
234
235 return LayoutPoint(point);
236 }
237
238 LayoutRect PaintInvalidationState::computePaintInvalidationRectInBacking() const
239 {
240 ASSERT(!m_didUpdateForChildren);
241
242 if (m_currentObject.isSVG() && !m_currentObject.isSVGRoot())
243 return computePaintInvalidationRectInBackingForSVG();
244
245 LayoutRect rect = m_currentObject.localOverflowRectForPaintInvalidation();
246 mapLocalRectToPaintInvalidationBacking(rect);
247 return rect;
248 }
249
250 LayoutRect PaintInvalidationState::computePaintInvalidationRectInBackingForSVG() const
251 {
252 LayoutRect rect;
253 if (m_cachedOffsetsEnabled) {
254 FloatRect svgRect = SVGLayoutSupport::localOverflowRectForPaintInvalidat ion(m_currentObject);
255 rect = SVGLayoutSupport::transformPaintInvalidationRect(m_currentObject, m_svgTransform, svgRect);
256 rect.move(m_paintOffset);
257 if (m_clipped)
258 rect.intersect(m_clipRect);
259 #if !defined(NDEBUG) && ENABLE(ASSERT)
260 // Make sure that the fast path and the slow path generate the same rect .
261 LayoutRect slowPathRect = SVGLayoutSupport::clippedOverflowRectForPaintI nvalidation(m_currentObject, m_paintInvalidationContainer);
262 // TODO(crbug.com/597902): Slow path misses clipping of paintInvalidatio nContainer.
263 if (m_clipped)
264 slowPathRect.intersect(m_clipRect);
265 // TODO(crbug.com/597903): Fast path and slow path should generate equal empty rects.
266 ASSERT((rect.isEmpty() && slowPathRect.isEmpty()) || rect == slowPathRec t);
267 #endif
268 } else {
269 // TODO(wangxianzhu): Sometimes m_cachedOffsetsEnabled==false doesn't me an we can't use cached
270 // m_svgTransform. We can use hybrid fast-path (for SVG) and slow-path ( for things above the SVGRoot).
271 rect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation(m_curre ntObject, m_paintInvalidationContainer);
272 }
273
274 if (m_paintInvalidationContainer.layer()->groupedMapping())
275 PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalida tionContainer, rect);
276 return rect;
277 }
278
279 static void slowMapToVisibleRectInAncestorSpace(const LayoutObject& object, cons t LayoutBoxModelObject& ancestor, LayoutRect& rect)
280 {
281 // TODO(crbug.com/597965): LayoutBox::mapToVisibleRectInAncestorSpace() inco rrectly flips a rect
282 // in its own space for writing mode. Here flip to workaround the flip.
283 if (object.isBox() && (toLayoutBox(object).isWritingModeRoot() || (ancestor == object && object.styleRef().isFlippedBlocksWritingMode())))
284 toLayoutBox(object).flipForWritingMode(rect);
285
286 if (object.isLayoutView()) {
287 toLayoutView(object).mapToVisibleRectInAncestorSpace(&ancestor, rect, In putIsInFrameCoordinates, DefaultVisibleRectFlags);
288 } else if (object.isSVGRoot()) {
289 // TODO(crbug.com/597813): This is to avoid the extra clip applied in La youtSVGRoot::mapVisibleRectInAncestorSpace().
290 toLayoutSVGRoot(object).LayoutReplaced::mapToVisibleRectInAncestorSpace( &ancestor, rect);
291 } else {
292 object.mapToVisibleRectInAncestorSpace(&ancestor, rect);
293 }
294 }
295
296 void PaintInvalidationState::mapLocalRectToPaintInvalidationBacking(LayoutRect& rect) const
297 {
298 ASSERT(!m_didUpdateForChildren);
299
300 if (m_cachedOffsetsEnabled) {
301 #if !defined(NDEBUG) && ENABLE(ASSERT)
leviw_travelin_and_unemployed 2016/03/25 22:26:31 Drive-by: isn't ENABLE(ASSERT) enough?
Xianzhu 2016/03/25 23:44:43 There are two tests crash because of different res
302 LayoutRect slowPathRect(rect);
303 slowMapToVisibleRectInAncestorSpace(m_currentObject, m_paintInvalidation Container, slowPathRect);
304 #endif
305 rect.move(m_paintOffset);
306 if (m_clipped)
307 rect.intersect(m_clipRect);
308 #if !defined(NDEBUG) && ENABLE(ASSERT)
309 // Make sure that the fast path and the slow path generate the same rect .
310 // TODO(crbug.com/597902): Slow path misses clipping of paintInvalidatio nContainer.
311 if (m_clipped)
312 slowPathRect.intersect(m_clipRect);
313 // TODO(wangxianzhu): The isLayoutView() condition is for cases that a s ub-frame creates a
314 // root PaintInvalidationState which doesn't inherit clip from ancestor frames.
315 // Remove the condition when we eliminate the latter case of PaintInvali dationState(const LayoutView&, ...).
316 // TODO(crbug.com/597903): Fast path and slow path should generate equal empty rects.
317 ASSERT(m_currentObject.isLayoutView() || (rect.isEmpty() && slowPathRect .isEmpty()) || rect == slowPathRect);
318 #endif
319 } else {
320 slowMapToVisibleRectInAncestorSpace(m_currentObject, m_paintInvalidation Container, rect);
321 }
322
323 if (m_paintInvalidationContainer.layer()->groupedMapping())
324 PaintLayer::mapRectInPaintInvalidationContainerToBacking(m_paintInvalida tionContainer, rect);
325 }
326
327 void PaintInvalidationState::addClipRectRelativeToPaintOffset(const LayoutRect& localClipRect)
328 {
329 LayoutRect clipRect = localClipRect;
330 clipRect.move(m_paintOffset);
331 if (m_clipped) {
332 m_clipRect.intersect(clipRect);
333 } else {
334 m_clipRect = clipRect;
335 m_clipped = true;
336 }
217 } 337 }
218 338
219 PaintLayer& PaintInvalidationState::enclosingSelfPaintingLayer(const LayoutObjec t& layoutObject) const 339 PaintLayer& PaintInvalidationState::enclosingSelfPaintingLayer(const LayoutObjec t& layoutObject) const
220 { 340 {
221 if (layoutObject.hasLayer() && toLayoutBoxModelObject(layoutObject).hasSelfP aintingLayer()) 341 if (layoutObject.hasLayer() && toLayoutBoxModelObject(layoutObject).hasSelfP aintingLayer())
222 return *toLayoutBoxModelObject(layoutObject).layer(); 342 return *toLayoutBoxModelObject(layoutObject).layer();
223 343
224 return m_enclosingSelfPaintingLayer; 344 return m_enclosingSelfPaintingLayer;
225 } 345 }
226 346
227 } // namespace blink 347 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698