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

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

Issue 2822653003: [SPInvalidation] Micro-optimize PaintLayerClipper::calculateRects (Closed)
Patch Set: none Created 3 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 /* 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } while (false); 259 } while (false);
260 #endif 260 #endif
261 261
262 void PaintLayerClipper::CalculateRectsWithGeometryMapper( 262 void PaintLayerClipper::CalculateRectsWithGeometryMapper(
263 const ClipRectsContext& context, 263 const ClipRectsContext& context,
264 const LayoutRect& paint_dirty_rect, 264 const LayoutRect& paint_dirty_rect,
265 LayoutRect& layer_bounds, 265 LayoutRect& layer_bounds,
266 ClipRect& background_rect, 266 ClipRect& background_rect,
267 ClipRect& foreground_rect, 267 ClipRect& foreground_rect,
268 const LayoutPoint* offset_from_root) const { 268 const LayoutPoint* offset_from_root) const {
269 LayoutPoint offset(context.sub_pixel_accumulation);
270 if (offset_from_root)
271 offset = *offset_from_root;
272 else
273 layer_.ConvertToLayerCoords(context.root_layer, offset);
274 layer_bounds = LayoutRect(offset, LayoutSize(layer_.size()));
275
269 // TODO(chrishtr): fix the underlying bug that causes this situation. 276 // TODO(chrishtr): fix the underlying bug that causes this situation.
270 if (!layer_.GetLayoutObject().PaintProperties() && 277 if (!layer_.GetLayoutObject().PaintProperties() &&
271 !layer_.GetLayoutObject().LocalBorderBoxProperties()) { 278 !layer_.GetLayoutObject().LocalBorderBoxProperties()) {
272 background_rect = ClipRect(LayoutRect(LayoutRect::InfiniteIntRect())); 279 background_rect = ClipRect(LayoutRect(LayoutRect::InfiniteIntRect()));
273 foreground_rect = ClipRect(LayoutRect(LayoutRect::InfiniteIntRect())); 280 foreground_rect = ClipRect(LayoutRect(LayoutRect::InfiniteIntRect()));
274 } else { 281 } else {
275 CalculateBackgroundClipRectWithGeometryMapper(context, background_rect); 282 CalculateBackgroundClipRectWithGeometryMapper(context, background_rect);
276 background_rect.Move(context.sub_pixel_accumulation); 283 background_rect.Move(context.sub_pixel_accumulation);
277 background_rect.Intersect(paint_dirty_rect); 284 background_rect.Intersect(paint_dirty_rect);
278 285
279 CalculateForegroundClipRectWithGeometryMapper(context, foreground_rect); 286 foreground_rect = background_rect;
280 foreground_rect.Move(context.sub_pixel_accumulation); 287
281 foreground_rect.Intersect(paint_dirty_rect); 288 LayoutBoxModelObject& layout_object = layer_.GetLayoutObject();
289 if (layout_object.HasClip()) {
290 LayoutRect new_pos_clip = ToLayoutBox(layout_object).ClipRect(offset);
291 foreground_rect.Intersect(new_pos_clip);
292 }
293 if (ShouldClipOverflow(context)) {
294 LayoutRect overflow_and_clip_rect =
295 ToLayoutBox(layout_object)
296 .OverflowClipRect(offset,
297 context.overlay_scrollbar_clip_behavior);
298 foreground_rect.Intersect(overflow_and_clip_rect);
299 if (layout_object.StyleRef().HasBorderRadius())
300 foreground_rect.SetHasRadius(true);
301 }
282 } 302 }
283 303
284 LayoutPoint offset;
285 if (offset_from_root)
286 offset = *offset_from_root;
287 else
288 layer_.ConvertToLayerCoords(context.root_layer, offset);
289 layer_bounds = LayoutRect(offset, LayoutSize(layer_.size()));
290
291 #ifdef CHECK_CLIP_RECTS 304 #ifdef CHECK_CLIP_RECTS
292 ClipRect testBackgroundRect, testForegroundRect; 305 ClipRect testBackgroundRect, testForegroundRect;
293 LayoutRect testLayerBounds; 306 LayoutRect testLayerBounds;
294 PaintLayerClipper(m_layer, nullptr) 307 PaintLayerClipper(m_layer, nullptr)
295 .calculateRects(context, paintDirtyRect, testLayerBounds, 308 .calculateRects(context, paintDirtyRect, testLayerBounds,
296 testBackgroundRect, testForegroundRect, offsetFromRoot); 309 testBackgroundRect, testForegroundRect, offsetFromRoot);
297 CHECK_RECTS_EQ(testBackgroundRect, backgroundRect); 310 CHECK_RECTS_EQ(testBackgroundRect, backgroundRect);
298 CHECK_RECTS_EQ(testForegroundRect, foregroundRect); 311 CHECK_RECTS_EQ(testForegroundRect, foregroundRect);
299 CHECK_RECTS_EQ(testLayerBounds, layerBounds); 312 CHECK_RECTS_EQ(testLayerBounds, layerBounds);
300 #endif 313 #endif
(...skipping 19 matching lines...) Expand all
320 if (!is_clipping_root && layer_.Parent()) { 333 if (!is_clipping_root && layer_.Parent()) {
321 CalculateBackgroundClipRect(context, background_rect); 334 CalculateBackgroundClipRect(context, background_rect);
322 background_rect.Move(context.sub_pixel_accumulation); 335 background_rect.Move(context.sub_pixel_accumulation);
323 background_rect.Intersect(paint_dirty_rect); 336 background_rect.Intersect(paint_dirty_rect);
324 } else { 337 } else {
325 background_rect = paint_dirty_rect; 338 background_rect = paint_dirty_rect;
326 } 339 }
327 340
328 foreground_rect = background_rect; 341 foreground_rect = background_rect;
329 342
330 LayoutPoint offset; 343 LayoutPoint offset(context.sub_pixel_accumulation);
331 if (offset_from_root) 344 if (offset_from_root)
332 offset = *offset_from_root; 345 offset = *offset_from_root;
333 else 346 else
334 layer_.ConvertToLayerCoords(context.root_layer, offset); 347 layer_.ConvertToLayerCoords(context.root_layer, offset);
335 layer_bounds = LayoutRect(offset, LayoutSize(layer_.size())); 348 layer_bounds = LayoutRect(offset, LayoutSize(layer_.size()));
336 349
337 // Update the clip rects that will be passed to child layers. 350 // Update the clip rects that will be passed to child layers.
338 if (ShouldClipOverflow(context)) { 351 if (ShouldClipOverflow(context)) {
339 LayoutRect overflow_and_clip_rect = 352 LayoutRect overflow_and_clip_rect =
340 ToLayoutBox(layout_object) 353 ToLayoutBox(layout_object)
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 const auto* ancestor_css_clip = 491 const auto* ancestor_css_clip =
479 ancestor_properties ? ancestor_properties->CssClip() : nullptr; 492 ancestor_properties ? ancestor_properties->CssClip() : nullptr;
480 // CSS clip of the root is always applied. 493 // CSS clip of the root is always applied.
481 if (ancestor_css_clip) { 494 if (ancestor_css_clip) {
482 DCHECK(destination_property_tree_state.Clip() == 495 DCHECK(destination_property_tree_state.Clip() ==
483 ancestor_properties->CssClip()); 496 ancestor_properties->CssClip());
484 destination_property_tree_state.SetClip(ancestor_css_clip->Parent()); 497 destination_property_tree_state.SetClip(ancestor_css_clip->Parent());
485 } 498 }
486 } 499 }
487 500
488 void PaintLayerClipper::CalculateForegroundClipRectWithGeometryMapper(
489 const ClipRectsContext& context,
490 ClipRect& output) const {
491 DCHECK(use_geometry_mapper_);
492 PropertyTreeState source_property_tree_state(nullptr, nullptr, nullptr);
493 PropertyTreeState destination_property_tree_state(nullptr, nullptr, nullptr);
494 InitializeCommonClipRectState(context, source_property_tree_state,
495 destination_property_tree_state);
496 const auto* properties = layer_.GetLayoutObject().PaintProperties();
497
498 if (&layer_ == context.root_layer) {
499 // Set the overflow clip for |sourcePropertyTreeState| so that it differs
500 // from |destinationPropertyTreeState| in its clip.
501 if (context.respect_overflow_clip == kRespectOverflowClip && properties &&
502 properties->OverflowClip())
503 source_property_tree_state.SetClip(properties->OverflowClip());
504 } else {
505 const auto* ancestor_properties =
506 context.root_layer->GetLayoutObject().PaintProperties();
507
508 // Set the clip of |destinationPropertyTreeState| to be inside the
509 // ancestor's overflow clip, so that that clip is not applied.
510 if (context.respect_overflow_clip == kIgnoreOverflowClip &&
511 ancestor_properties && ancestor_properties->OverflowClip())
512 destination_property_tree_state.SetClip(
513 ancestor_properties->OverflowClip());
514
515 // Set the overflow clip for |sourcePropertyTreeState| so that it differs
516 // from destinationPropertyTreeState| in its clip.
517 if (properties && properties->OverflowClip())
518 source_property_tree_state.SetClip(properties->OverflowClip());
519 }
520
521 const FloatClipRect& clipped_rect_in_root_layer_space =
522 GeometryMapper::SourceToDestinationClipRect(
523 source_property_tree_state, destination_property_tree_state);
524 output.SetRect(clipped_rect_in_root_layer_space);
525
526 output.MoveBy(-context.root_layer->GetLayoutObject().PaintOffset());
527 }
528
529 LayoutRect PaintLayerClipper::LocalVisualRect() const { 501 LayoutRect PaintLayerClipper::LocalVisualRect() const {
530 const LayoutObject& layout_object = layer_.GetLayoutObject(); 502 const LayoutObject& layout_object = layer_.GetLayoutObject();
531 // The LayoutView is special since its overflow clipping rect may be larger 503 // The LayoutView is special since its overflow clipping rect may be larger
532 // than its box rect (crbug.com/492871). 504 // than its box rect (crbug.com/492871).
533 LayoutRect layer_bounds_with_visual_overflow = 505 LayoutRect layer_bounds_with_visual_overflow =
534 layout_object.IsLayoutView() 506 layout_object.IsLayoutView()
535 ? ToLayoutView(layout_object).ViewRect() 507 ? ToLayoutView(layout_object).ViewRect()
536 : ToLayoutBox(layout_object).VisualOverflowRect(); 508 : ToLayoutBox(layout_object).VisualOverflowRect();
537 ToLayoutBox(layout_object) 509 ToLayoutBox(layout_object)
538 .FlipForWritingMode( 510 .FlipForWritingMode(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 DCHECK(!use_geometry_mapper_); 604 DCHECK(!use_geometry_mapper_);
633 ClipRectsContext context(root_layer, kPaintingClipRects, 605 ClipRectsContext context(root_layer, kPaintingClipRects,
634 kIgnorePlatformOverlayScrollbarSize, 606 kIgnorePlatformOverlayScrollbarSize,
635 subpixel_accumulation); 607 subpixel_accumulation);
636 if (respect_overflow_clip == kIgnoreOverflowClip) 608 if (respect_overflow_clip == kIgnoreOverflowClip)
637 context.SetIgnoreOverflowClip(); 609 context.SetIgnoreOverflowClip();
638 return GetClipRects(context); 610 return GetClipRects(context);
639 } 611 }
640 612
641 } // namespace blink 613 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698