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

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

Issue 2621243002: Fix paint offset and clips in SPv2 (Closed)
Patch Set: none Created 3 years, 11 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 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Portions are Copyright (C) 1998 Netscape Communications Corporation. 5 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
6 * 6 *
7 * Other contributors: 7 * Other contributors:
8 * Robert O'Callahan <roc+@cs.cmu.edu> 8 * Robert O'Callahan <roc+@cs.cmu.edu>
9 * David Baron <dbaron@fas.harvard.edu> 9 * David Baron <dbaron@fas.harvard.edu>
10 * Christian Biesinger <cbiesinger@web.de> 10 * Christian Biesinger <cbiesinger@web.de>
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 for (const PaintLayer* layer = currentLayer->firstChild(); layer; 203 for (const PaintLayer* layer = currentLayer->firstChild(); layer;
204 layer = layer->nextSibling()) 204 layer = layer->nextSibling())
205 layers.push(layer); 205 layers.push(layer);
206 } 206 }
207 } 207 }
208 208
209 LayoutRect PaintLayerClipper::localClipRect( 209 LayoutRect PaintLayerClipper::localClipRect(
210 const PaintLayer* clippingRootLayer) const { 210 const PaintLayer* clippingRootLayer) const {
211 ClipRectsContext context(clippingRootLayer, PaintingClipRects); 211 ClipRectsContext context(clippingRootLayer, PaintingClipRects);
212 if (m_geometryMapper) { 212 if (m_geometryMapper) {
213 ClipRect clipRect = applyOverflowClipToBackgroundRectWithGeometryMapper( 213 LayoutRect clippedRectInLocalSpace(
214 context, clipRectWithGeometryMapper(context, false)); 214 applyOverflowClipToBackgroundRectWithGeometryMapper(
215 context, clipRectWithGeometryMapper(context, false))
216 .rect());
215 217
216 // The rect now needs to be transformed to the local space of this 218 // The rect now needs to be transformed to the local space of this
217 // PaintLayer. 219 // PaintLayer.
218 bool success = false; 220 LayoutPoint clippingRootOffset;
chrishtr 2017/01/12 00:16:27 The simplest thing to do here is to just offset to
chrishtr 2017/01/12 00:28:14 This statement is incorrect. PaintLayer::physicalB
chrishtr 2017/01/12 00:42:54 Fixed.
219 FloatRect clippedRectInLocalSpace = 221 m_layer.convertToLayerCoords(clippingRootLayer, clippingRootOffset);
220 m_geometryMapper->mapRectToDestinationSpace( 222 clippedRectInLocalSpace.moveBy(-clippingRootOffset);
221 FloatRect(clipRect.rect()), *clippingRootLayer->layoutObject()
222 ->paintProperties()
223 ->localBorderBoxProperties(),
224 *m_layer.layoutObject()
225 ->paintProperties()
226 ->localBorderBoxProperties(),
227 success);
228 DCHECK(success);
229 223
230 return LayoutRect(clippedRectInLocalSpace); 224 return clippedRectInLocalSpace;
231 } 225 }
232 226
233 LayoutRect layerBounds; 227 LayoutRect layerBounds;
234 ClipRect backgroundRect, foregroundRect; 228 ClipRect backgroundRect, foregroundRect;
235 calculateRects(context, LayoutRect(LayoutRect::infiniteIntRect()), 229 calculateRects(context, LayoutRect(LayoutRect::infiniteIntRect()),
236 layerBounds, backgroundRect, foregroundRect); 230 layerBounds, backgroundRect, foregroundRect);
237 231
238 LayoutRect clipRect = backgroundRect.rect(); 232 LayoutRect clipRect = backgroundRect.rect();
239 // TODO(chrishtr): avoid converting to IntRect and back. 233 // TODO(chrishtr): avoid converting to IntRect and back.
240 if (clipRect == LayoutRect(LayoutRect::infiniteIntRect())) 234 if (clipRect == LayoutRect(LayoutRect::infiniteIntRect()))
241 return clipRect; 235 return clipRect;
242 236
243 LayoutPoint clippingRootOffset; 237 LayoutPoint clippingRootOffset;
244 m_layer.convertToLayerCoords(clippingRootLayer, clippingRootOffset); 238 m_layer.convertToLayerCoords(clippingRootLayer, clippingRootOffset);
245 clipRect.moveBy(-clippingRootOffset); 239 clipRect.moveBy(-clippingRootOffset);
246 240
247 return clipRect; 241 return clipRect;
248 } 242 }
249 243
250 #ifdef CHECK_CLIP_RECTS 244 #ifdef CHECK_CLIP_RECTS
251 #define CHECK_RECTS_EQ(expected, actual) \ 245 #define CHECK_RECTS_EQ(expected, actual) \
252 CHECK((expected.isEmpty() && actual.isEmpty()) || expected == actual) \ 246 CHECK((expected.isEmpty() && actual.isEmpty()) || expected == actual) \
253 << "expected=" << expected.toString() << " actual=" << actual.toString() 247 << "expected=" << expected.toString() << " actual=" << actual.toString()
254 #endif 248 #endif
255 249
256 void PaintLayerClipper::mapLocalToRootWithGeometryMapper( 250 void PaintLayerClipper::mapLocalToRootWithGeometryMapper(
257 const ClipRectsContext& context, 251 const ClipRectsContext& context,
258 LayoutRect& layoutRect) const { 252 LayoutRect& rectToMap) const {
259 DCHECK(m_geometryMapper); 253 DCHECK(m_geometryMapper);
260 bool success; 254 bool success;
261 255
262 const auto* layerBorderBoxProperties = 256 const auto* layerBorderBoxProperties =
263 m_layer.layoutObject()->paintProperties()->localBorderBoxProperties(); 257 m_layer.layoutObject()->paintProperties()->localBorderBoxProperties();
264 FloatRect localRect(layoutRect); 258 FloatRect localRect(rectToMap);
265 localRect.moveBy(FloatPoint(m_layer.layoutObject()->paintOffset())); 259 localRect.moveBy(FloatPoint(m_layer.layoutObject()->paintOffset()));
266 260
267 layoutRect = LayoutRect(m_geometryMapper->mapRectToDestinationSpace( 261 rectToMap = LayoutRect(m_geometryMapper->mapRectToDestinationSpace(
268 localRect, *layerBorderBoxProperties, *context.rootLayer->layoutObject() 262 localRect, *layerBorderBoxProperties, *context.rootLayer->layoutObject()
269 ->paintProperties() 263 ->paintProperties()
270 ->localBorderBoxProperties(), 264 ->localBorderBoxProperties(),
271 success)); 265 success));
272 DCHECK(success); 266 DCHECK(success);
267 rectToMap.moveBy(-context.rootLayer->layoutObject()->paintOffset());
273 } 268 }
274 269
275 void PaintLayerClipper::calculateRectsWithGeometryMapper( 270 void PaintLayerClipper::calculateRectsWithGeometryMapper(
276 const ClipRectsContext& context, 271 const ClipRectsContext& context,
277 const LayoutRect& paintDirtyRect, 272 const LayoutRect& paintDirtyRect,
278 LayoutRect& layerBounds, 273 LayoutRect& layerBounds,
279 ClipRect& backgroundRect, 274 ClipRect& backgroundRect,
280 ClipRect& foregroundRect, 275 ClipRect& foregroundRect,
281 const LayoutPoint* offsetFromRoot) const { 276 const LayoutPoint* offsetFromRoot) const {
282 backgroundRect = applyOverflowClipToBackgroundRectWithGeometryMapper( 277 backgroundRect = applyOverflowClipToBackgroundRectWithGeometryMapper(
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 } 425 }
431 426
432 ClipRect PaintLayerClipper::clipRectWithGeometryMapper( 427 ClipRect PaintLayerClipper::clipRectWithGeometryMapper(
433 const ClipRectsContext& context, 428 const ClipRectsContext& context,
434 bool isForeground) const { 429 bool isForeground) const {
435 DCHECK(m_geometryMapper); 430 DCHECK(m_geometryMapper);
436 LayoutRect source(LayoutRect::infiniteIntRect()); 431 LayoutRect source(LayoutRect::infiniteIntRect());
437 bool success = false; 432 bool success = false;
438 const auto* properties = m_layer.layoutObject()->paintProperties(); 433 const auto* properties = m_layer.layoutObject()->paintProperties();
439 DCHECK(properties && properties->localBorderBoxProperties()); 434 DCHECK(properties && properties->localBorderBoxProperties());
435
440 PropertyTreeState propertyTreeState = *properties->localBorderBoxProperties(); 436 PropertyTreeState propertyTreeState = *properties->localBorderBoxProperties();
441
442 if (isForeground && shouldClipOverflow(context) && properties->overflowClip())
443 propertyTreeState.setClip(properties->overflowClip());
444
445 const auto* ancestorProperties = 437 const auto* ancestorProperties =
446 context.rootLayer->layoutObject()->paintProperties(); 438 context.rootLayer->layoutObject()->paintProperties();
447 DCHECK(ancestorProperties && ancestorProperties->localBorderBoxProperties()); 439 DCHECK(ancestorProperties && ancestorProperties->localBorderBoxProperties());
448 PropertyTreeState destinationPropertyTreeState = 440 PropertyTreeState destinationPropertyTreeState =
449 *ancestorProperties->localBorderBoxProperties(); 441 *ancestorProperties->localBorderBoxProperties();
450 if (!context.rootLayer->clipper().shouldRespectOverflowClip(context)) { 442
451 if (ancestorProperties->overflowClip()) 443 if (&m_layer == context.rootLayer) {
chrishtr 2017/01/12 00:16:26 Overflow clips are applied if 1. We're not ignori
444 // Set the overflow clip for |propertyTreeState| so that it differs from
445 // destinationPropertyTreeState| in its clip.
446 if (isForeground && context.respectOverflowClip == RespectOverflowClip &&
447 properties->overflowClip())
448 propertyTreeState.setClip(properties->overflowClip());
449 } else {
450 // Set the clip of |destinationPropertyTreeState| to be inside the
451 // ancestor's
wkorman 2017/01/12 00:29:18 fix wrapping
chrishtr 2017/01/12 00:42:54 Done.
452 // overflow clip, so that that clip is not applied.
453 if (context.respectOverflowClip == IgnoreOverflowClip &&
454 ancestorProperties->overflowClip())
452 destinationPropertyTreeState.setClip(ancestorProperties->overflowClip()); 455 destinationPropertyTreeState.setClip(ancestorProperties->overflowClip());
456
457 // Set the overflow clip for |propertyTreeState| so that it differs from
458 // destinationPropertyTreeState| in its clip.
459 if (isForeground && properties->overflowClip())
460 propertyTreeState.setClip(properties->overflowClip());
453 } 461 }
462
454 FloatRect clippedRectInRootLayerSpace = 463 FloatRect clippedRectInRootLayerSpace =
455 m_geometryMapper->mapToVisualRectInDestinationSpace( 464 m_geometryMapper->mapToVisualRectInDestinationSpace(
456 FloatRect(source), propertyTreeState, destinationPropertyTreeState, 465 FloatRect(source), propertyTreeState, destinationPropertyTreeState,
457 success); 466 success);
458 DCHECK(success); 467 DCHECK(success);
468 clippedRectInRootLayerSpace.moveBy(
469 -FloatPoint(context.rootLayer->layoutObject()->paintOffset()));
459 return ClipRect(LayoutRect(clippedRectInRootLayerSpace)); 470 return ClipRect(LayoutRect(clippedRectInRootLayerSpace));
460 } 471 }
461 472
462 ClipRect PaintLayerClipper::applyOverflowClipToBackgroundRectWithGeometryMapper( 473 ClipRect PaintLayerClipper::applyOverflowClipToBackgroundRectWithGeometryMapper(
463 const ClipRectsContext& context, 474 const ClipRectsContext& context,
464 const ClipRect& clip) const { 475 const ClipRect& clip) const {
465 const LayoutObject& layoutObject = *m_layer.layoutObject(); 476 const LayoutObject& layoutObject = *m_layer.layoutObject();
466 FloatRect clipRect(clip.rect()); 477 FloatRect clipRect(clip.rect());
467 if (shouldClipOverflow(context)) { 478 if (shouldClipOverflow(context)) {
468 LayoutRect layerBoundsWithVisualOverflow = 479 LayoutRect layerBoundsWithVisualOverflow =
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 const LayoutSize& subpixelAccumulation) const { 563 const LayoutSize& subpixelAccumulation) const {
553 DCHECK(!m_geometryMapper); 564 DCHECK(!m_geometryMapper);
554 ClipRectsContext context(rootLayer, PaintingClipRects, 565 ClipRectsContext context(rootLayer, PaintingClipRects,
555 IgnoreOverlayScrollbarSize, subpixelAccumulation); 566 IgnoreOverlayScrollbarSize, subpixelAccumulation);
556 if (respectOverflowClip == IgnoreOverflowClip) 567 if (respectOverflowClip == IgnoreOverflowClip)
557 context.setIgnoreOverflowClip(); 568 context.setIgnoreOverflowClip();
558 return getClipRects(context); 569 return getClipRects(context);
559 } 570 }
560 571
561 } // namespace blink 572 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698