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

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 premappedRect =
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.
220 premappedRect.moveBy(context.rootLayer->layoutObject()->paintOffset());
221
218 const auto* clipRootLayerTransform = clippingRootLayer->layoutObject() 222 const auto* clipRootLayerTransform = clippingRootLayer->layoutObject()
219 ->paintProperties() 223 ->paintProperties()
220 ->localBorderBoxProperties() 224 ->localBorderBoxProperties()
221 ->transform(); 225 ->transform();
222 const auto* layerTransform = m_layer.layoutObject() 226 const auto* layerTransform = m_layer.layoutObject()
223 ->paintProperties() 227 ->paintProperties()
224 ->localBorderBoxProperties() 228 ->localBorderBoxProperties()
225 ->transform(); 229 ->transform();
226 FloatRect clippedRectInLocalSpace = 230 FloatRect clippedRectInLocalSpace =
227 m_geometryMapper->sourceToDestinationRect( 231 m_geometryMapper->sourceToDestinationRect(
228 FloatRect(clipRect.rect()), clipRootLayerTransform, layerTransform); 232 FloatRect(premappedRect), clipRootLayerTransform, layerTransform);
233 clippedRectInLocalSpace.moveBy(
234 -FloatPoint(m_layer.layoutObject()->paintOffset()));
229 235
230 return LayoutRect(clippedRectInLocalSpace); 236 return LayoutRect(clippedRectInLocalSpace);
231 } 237 }
232 238
233 LayoutRect layerBounds; 239 LayoutRect layerBounds;
234 ClipRect backgroundRect, foregroundRect; 240 ClipRect backgroundRect, foregroundRect;
235 calculateRects(context, LayoutRect(LayoutRect::infiniteIntRect()), 241 calculateRects(context, LayoutRect(LayoutRect::infiniteIntRect()),
236 layerBounds, backgroundRect, foregroundRect); 242 layerBounds, backgroundRect, foregroundRect);
237 243
238 LayoutRect clipRect = backgroundRect.rect(); 244 LayoutRect clipRect = backgroundRect.rect();
239 // TODO(chrishtr): avoid converting to IntRect and back. 245 // TODO(chrishtr): avoid converting to IntRect and back.
240 if (clipRect == LayoutRect(LayoutRect::infiniteIntRect())) 246 if (clipRect == LayoutRect(LayoutRect::infiniteIntRect()))
241 return clipRect; 247 return clipRect;
242 248
243 LayoutPoint clippingRootOffset; 249 LayoutPoint clippingRootOffset;
244 m_layer.convertToLayerCoords(clippingRootLayer, clippingRootOffset); 250 m_layer.convertToLayerCoords(clippingRootLayer, clippingRootOffset);
245 clipRect.moveBy(-clippingRootOffset); 251 clipRect.moveBy(-clippingRootOffset);
246 252
247 return clipRect; 253 return clipRect;
248 } 254 }
249 255
250 #ifdef CHECK_CLIP_RECTS 256 #ifdef CHECK_CLIP_RECTS
251 #define CHECK_RECTS_EQ(expected, actual) \ 257 #define CHECK_RECTS_EQ(expected, actual) \
252 CHECK((expected.isEmpty() && actual.isEmpty()) || expected == actual) \ 258 CHECK((expected.isEmpty() && actual.isEmpty()) || expected == actual) \
253 << "expected=" << expected.toString() << " actual=" << actual.toString() 259 << "expected=" << expected.toString() << " actual=" << actual.toString()
254 #endif 260 #endif
255 261
256 void PaintLayerClipper::mapLocalToRootWithGeometryMapper( 262 void PaintLayerClipper::mapLocalToRootWithGeometryMapper(
257 const ClipRectsContext& context, 263 const ClipRectsContext& context,
258 LayoutRect& layoutRect) const { 264 LayoutRect& rectToMap) const {
259 DCHECK(m_geometryMapper); 265 DCHECK(m_geometryMapper);
260 266
261 const auto* layerTransform = m_layer.layoutObject() 267 const auto* layerTransform = m_layer.layoutObject()
262 ->paintProperties() 268 ->paintProperties()
263 ->localBorderBoxProperties() 269 ->localBorderBoxProperties()
264 ->transform(); 270 ->transform();
265 const auto* rootTransform = context.rootLayer->layoutObject() 271 const auto* rootTransform = context.rootLayer->layoutObject()
266 ->paintProperties() 272 ->paintProperties()
267 ->localBorderBoxProperties() 273 ->localBorderBoxProperties()
268 ->transform(); 274 ->transform();
269 275
270 FloatRect localRect(layoutRect); 276 FloatRect localRect(rectToMap);
271 localRect.moveBy(FloatPoint(m_layer.layoutObject()->paintOffset())); 277 localRect.moveBy(FloatPoint(m_layer.layoutObject()->paintOffset()));
272 layoutRect = LayoutRect(m_geometryMapper->sourceToDestinationRect( 278 rectToMap = LayoutRect(m_geometryMapper->sourceToDestinationRect(
273 localRect, layerTransform, rootTransform)); 279 localRect, layerTransform, rootTransform));
280 rectToMap.moveBy(-context.rootLayer->layoutObject()->paintOffset());
274 } 281 }
275 282
276 void PaintLayerClipper::calculateRectsWithGeometryMapper( 283 void PaintLayerClipper::calculateRectsWithGeometryMapper(
277 const ClipRectsContext& context, 284 const ClipRectsContext& context,
278 const LayoutRect& paintDirtyRect, 285 const LayoutRect& paintDirtyRect,
279 LayoutRect& layerBounds, 286 LayoutRect& layerBounds,
280 ClipRect& backgroundRect, 287 ClipRect& backgroundRect,
281 ClipRect& foregroundRect, 288 ClipRect& foregroundRect,
282 const LayoutPoint* offsetFromRoot) const { 289 const LayoutPoint* offsetFromRoot) const {
283 backgroundRect = applyOverflowClipToBackgroundRectWithGeometryMapper( 290 backgroundRect = applyOverflowClipToBackgroundRectWithGeometryMapper(
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 return parentRects.overflowClipRect(); 437 return parentRects.overflowClipRect();
431 } 438 }
432 439
433 ClipRect PaintLayerClipper::clipRectWithGeometryMapper( 440 ClipRect PaintLayerClipper::clipRectWithGeometryMapper(
434 const ClipRectsContext& context, 441 const ClipRectsContext& context,
435 bool isForeground) const { 442 bool isForeground) const {
436 DCHECK(m_geometryMapper); 443 DCHECK(m_geometryMapper);
437 LayoutRect source(LayoutRect::infiniteIntRect()); 444 LayoutRect source(LayoutRect::infiniteIntRect());
438 const auto* properties = m_layer.layoutObject()->paintProperties(); 445 const auto* properties = m_layer.layoutObject()->paintProperties();
439 DCHECK(properties && properties->localBorderBoxProperties()); 446 DCHECK(properties && properties->localBorderBoxProperties());
447
440 PropertyTreeState propertyTreeState = *properties->localBorderBoxProperties(); 448 PropertyTreeState propertyTreeState = *properties->localBorderBoxProperties();
441
442 if (isForeground && shouldClipOverflow(context) && properties->overflowClip())
443 propertyTreeState.setClip(properties->overflowClip());
444
445 const auto* ancestorProperties = 449 const auto* ancestorProperties =
446 context.rootLayer->layoutObject()->paintProperties(); 450 context.rootLayer->layoutObject()->paintProperties();
447 DCHECK(ancestorProperties && ancestorProperties->localBorderBoxProperties()); 451 DCHECK(ancestorProperties && ancestorProperties->localBorderBoxProperties());
448 PropertyTreeState destinationPropertyTreeState = 452 PropertyTreeState destinationPropertyTreeState =
449 *ancestorProperties->localBorderBoxProperties(); 453 *ancestorProperties->localBorderBoxProperties();
450 if (!context.rootLayer->clipper().shouldRespectOverflowClip(context)) { 454
451 if (ancestorProperties->overflowClip()) 455 if (&m_layer == context.rootLayer) {
456 // Set the overflow clip for |propertyTreeState| so that it differs from
457 // |destinationPropertyTreeState| in its clip.
458 if (isForeground && context.respectOverflowClip == RespectOverflowClip &&
459 properties->overflowClip())
460 propertyTreeState.setClip(properties->overflowClip());
461 } else {
462 // Set the clip of |destinationPropertyTreeState| to be inside the
463 // ancestor's overflow clip, so that that clip is not applied.
464 if (context.respectOverflowClip == IgnoreOverflowClip &&
465 ancestorProperties->overflowClip())
452 destinationPropertyTreeState.setClip(ancestorProperties->overflowClip()); 466 destinationPropertyTreeState.setClip(ancestorProperties->overflowClip());
467
468 // Set the overflow clip for |propertyTreeState| so that it differs from
469 // destinationPropertyTreeState| in its clip.
470 if (isForeground && properties->overflowClip())
471 propertyTreeState.setClip(properties->overflowClip());
453 } 472 }
473
454 FloatRect clippedRectInRootLayerSpace = 474 FloatRect clippedRectInRootLayerSpace =
455 m_geometryMapper->sourceToDestinationVisualRect( 475 m_geometryMapper->sourceToDestinationVisualRect(
456 FloatRect(source), propertyTreeState, destinationPropertyTreeState); 476 FloatRect(source), propertyTreeState, destinationPropertyTreeState);
477 clippedRectInRootLayerSpace.moveBy(
478 -FloatPoint(context.rootLayer->layoutObject()->paintOffset()));
457 return ClipRect(LayoutRect(clippedRectInRootLayerSpace)); 479 return ClipRect(LayoutRect(clippedRectInRootLayerSpace));
458 } 480 }
459 481
460 ClipRect PaintLayerClipper::applyOverflowClipToBackgroundRectWithGeometryMapper( 482 ClipRect PaintLayerClipper::applyOverflowClipToBackgroundRectWithGeometryMapper(
461 const ClipRectsContext& context, 483 const ClipRectsContext& context,
462 const ClipRect& clip) const { 484 const ClipRect& clip) const {
463 const LayoutObject& layoutObject = *m_layer.layoutObject(); 485 const LayoutObject& layoutObject = *m_layer.layoutObject();
464 FloatRect clipRect(clip.rect()); 486 FloatRect clipRect(clip.rect());
465 if (shouldClipOverflow(context)) { 487 if (shouldClipOverflow(context)) {
466 LayoutRect layerBoundsWithVisualOverflow = 488 LayoutRect layerBoundsWithVisualOverflow =
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 const LayoutSize& subpixelAccumulation) const { 572 const LayoutSize& subpixelAccumulation) const {
551 DCHECK(!m_geometryMapper); 573 DCHECK(!m_geometryMapper);
552 ClipRectsContext context(rootLayer, PaintingClipRects, 574 ClipRectsContext context(rootLayer, PaintingClipRects,
553 IgnoreOverlayScrollbarSize, subpixelAccumulation); 575 IgnoreOverlayScrollbarSize, subpixelAccumulation);
554 if (respectOverflowClip == IgnoreOverflowClip) 576 if (respectOverflowClip == IgnoreOverflowClip)
555 context.setIgnoreOverflowClip(); 577 context.setIgnoreOverflowClip();
556 return getClipRects(context); 578 return getClipRects(context);
557 } 579 }
558 580
559 } // namespace blink 581 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698