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

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

Powered by Google App Engine
This is Rietveld 408576698