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

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

Issue 2393673004: reflow comments in core/layout/compositing,core/observer (Closed)
Patch Set: comments (heh!) Created 4 years, 2 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) 2009, 2010, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2009, 2010, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 155 }
156 156
157 static inline bool isAcceleratedContents(LayoutObject* layoutObject) { 157 static inline bool isAcceleratedContents(LayoutObject* layoutObject) {
158 return isAcceleratedCanvas(layoutObject) || 158 return isAcceleratedCanvas(layoutObject) ||
159 (layoutObject->isEmbeddedObject() && 159 (layoutObject->isEmbeddedObject() &&
160 toLayoutEmbeddedObject(layoutObject) 160 toLayoutEmbeddedObject(layoutObject)
161 ->requiresAcceleratedCompositing()) || 161 ->requiresAcceleratedCompositing()) ||
162 layoutObject->isVideo(); 162 layoutObject->isVideo();
163 } 163 }
164 164
165 // Get the scrolling coordinator in a way that works inside CompositedLayerMappi ng's destructor. 165 // Get the scrolling coordinator in a way that works inside
166 // CompositedLayerMapping's destructor.
166 static ScrollingCoordinator* scrollingCoordinatorFromLayer(PaintLayer& layer) { 167 static ScrollingCoordinator* scrollingCoordinatorFromLayer(PaintLayer& layer) {
167 Page* page = layer.layoutObject()->frame()->page(); 168 Page* page = layer.layoutObject()->frame()->page();
168 return (!page) ? nullptr : page->scrollingCoordinator(); 169 return (!page) ? nullptr : page->scrollingCoordinator();
169 } 170 }
170 171
171 CompositedLayerMapping::CompositedLayerMapping(PaintLayer& layer) 172 CompositedLayerMapping::CompositedLayerMapping(PaintLayer& layer)
172 : m_owningLayer(layer), 173 : m_owningLayer(layer),
173 m_contentOffsetInCompositingLayerDirty(false), 174 m_contentOffsetInCompositingLayerDirty(false),
174 m_pendingUpdateScope(GraphicsLayerUpdateNone), 175 m_pendingUpdateScope(GraphicsLayerUpdateNone),
175 m_isMainFrameLayoutViewLayer(false), 176 m_isMainFrameLayoutViewLayer(false),
176 m_backgroundLayerPaintsFixedRootBackground(false), 177 m_backgroundLayerPaintsFixedRootBackground(false),
177 m_scrollingContentsAreEmpty(false), 178 m_scrollingContentsAreEmpty(false),
178 m_backgroundPaintsOntoScrollingContentsLayer(false) { 179 m_backgroundPaintsOntoScrollingContentsLayer(false) {
179 if (layer.isRootLayer() && layoutObject()->frame()->isMainFrame()) 180 if (layer.isRootLayer() && layoutObject()->frame()->isMainFrame())
180 m_isMainFrameLayoutViewLayer = true; 181 m_isMainFrameLayoutViewLayer = true;
181 182
182 createPrimaryGraphicsLayer(); 183 createPrimaryGraphicsLayer();
183 } 184 }
184 185
185 CompositedLayerMapping::~CompositedLayerMapping() { 186 CompositedLayerMapping::~CompositedLayerMapping() {
186 // Hits in compositing/squashing/squash-onto-nephew.html. 187 // Hits in compositing/squashing/squash-onto-nephew.html.
187 DisableCompositingQueryAsserts disabler; 188 DisableCompositingQueryAsserts disabler;
188 189
189 // Do not leave the destroyed pointer dangling on any Layers that painted to t his mapping's squashing layer. 190 // Do not leave the destroyed pointer dangling on any Layers that painted to
191 // this mapping's squashing layer.
190 for (size_t i = 0; i < m_squashedLayers.size(); ++i) { 192 for (size_t i = 0; i < m_squashedLayers.size(); ++i) {
191 PaintLayer* oldSquashedLayer = m_squashedLayers[i].paintLayer; 193 PaintLayer* oldSquashedLayer = m_squashedLayers[i].paintLayer;
192 // Assert on incorrect mappings between layers and groups 194 // Assert on incorrect mappings between layers and groups
193 ASSERT(oldSquashedLayer->groupedMapping() == this); 195 ASSERT(oldSquashedLayer->groupedMapping() == this);
194 if (oldSquashedLayer->groupedMapping() == this) { 196 if (oldSquashedLayer->groupedMapping() == this) {
195 oldSquashedLayer->setGroupedMapping( 197 oldSquashedLayer->setGroupedMapping(
196 0, PaintLayer::DoNotInvalidateLayerAndRemoveFromMapping); 198 0, PaintLayer::DoNotInvalidateLayerAndRemoveFromMapping);
197 oldSquashedLayer->setLostGroupedMapping(true); 199 oldSquashedLayer->setLostGroupedMapping(true);
198 } 200 }
199 } 201 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 254
253 m_scrollingLayer = nullptr; 255 m_scrollingLayer = nullptr;
254 m_scrollingContentsLayer = nullptr; 256 m_scrollingContentsLayer = nullptr;
255 } 257 }
256 258
257 void CompositedLayerMapping::updateOpacity(const ComputedStyle& style) { 259 void CompositedLayerMapping::updateOpacity(const ComputedStyle& style) {
258 m_graphicsLayer->setOpacity(compositingOpacity(style.opacity())); 260 m_graphicsLayer->setOpacity(compositingOpacity(style.opacity()));
259 } 261 }
260 262
261 void CompositedLayerMapping::updateTransform(const ComputedStyle& style) { 263 void CompositedLayerMapping::updateTransform(const ComputedStyle& style) {
262 // FIXME: This could use m_owningLayer.transform(), but that currently has tra nsform-origin 264 // FIXME: This could use m_owningLayer.transform(), but that currently has
263 // baked into it, and we don't want that. 265 // transform-origin baked into it, and we don't want that.
264 TransformationMatrix t; 266 TransformationMatrix t;
265 if (m_owningLayer.hasTransformRelatedProperty()) { 267 if (m_owningLayer.hasTransformRelatedProperty()) {
266 style.applyTransform( 268 style.applyTransform(
267 t, LayoutSize(toLayoutBox(layoutObject())->pixelSnappedSize()), 269 t, LayoutSize(toLayoutBox(layoutObject())->pixelSnappedSize()),
268 ComputedStyle::ExcludeTransformOrigin, ComputedStyle::IncludeMotionPath, 270 ComputedStyle::ExcludeTransformOrigin, ComputedStyle::IncludeMotionPath,
269 ComputedStyle::IncludeIndependentTransformProperties); 271 ComputedStyle::IncludeIndependentTransformProperties);
270 makeMatrixRenderable(t, compositor()->hasAcceleratedCompositing()); 272 makeMatrixRenderable(t, compositor()->hasAcceleratedCompositing());
271 } 273 }
272 274
273 m_graphicsLayer->setTransform(t); 275 m_graphicsLayer->setTransform(t);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 339
338 // non stacking context layers should never isolate 340 // non stacking context layers should never isolate
339 ASSERT(m_owningLayer.stackingNode()->isStackingContext() || !isolate); 341 ASSERT(m_owningLayer.stackingNode()->isStackingContext() || !isolate);
340 342
341 m_graphicsLayer->setIsRootForIsolatedGroup(isolate); 343 m_graphicsLayer->setIsRootForIsolatedGroup(isolate);
342 } 344 }
343 345
344 void CompositedLayerMapping:: 346 void CompositedLayerMapping::
345 updateBackgroundPaintsOntoScrollingContentsLayer() { 347 updateBackgroundPaintsOntoScrollingContentsLayer() {
346 // We can only paint the background onto the scrolling contents layer if 348 // We can only paint the background onto the scrolling contents layer if
347 // it would be visually correct and we are using composited scrolling meaning we 349 // it would be visually correct and we are using composited scrolling meaning
348 // have a scrolling contents layer to paint it into. 350 // we have a scrolling contents layer to paint it into.
349 bool shouldPaintOntoScrollingContentsLayer = 351 bool shouldPaintOntoScrollingContentsLayer =
350 m_owningLayer.canPaintBackgroundOntoScrollingContentsLayer() && 352 m_owningLayer.canPaintBackgroundOntoScrollingContentsLayer() &&
351 m_owningLayer.getScrollableArea()->usesCompositedScrolling(); 353 m_owningLayer.getScrollableArea()->usesCompositedScrolling();
352 if (shouldPaintOntoScrollingContentsLayer != 354 if (shouldPaintOntoScrollingContentsLayer !=
353 backgroundPaintsOntoScrollingContentsLayer()) { 355 backgroundPaintsOntoScrollingContentsLayer()) {
354 m_backgroundPaintsOntoScrollingContentsLayer = 356 m_backgroundPaintsOntoScrollingContentsLayer =
355 shouldPaintOntoScrollingContentsLayer; 357 shouldPaintOntoScrollingContentsLayer;
356 // If the background is no longer painted onto the scrolling contents 358 // If the background is no longer painted onto the scrolling contents layer
357 // layer the scrolling contents layer needs to be updated. If it is 359 // the scrolling contents layer needs to be updated. If it is going to be
358 // going to be painted onto the scrolling contents layer this update 360 // painted onto the scrolling contents layer this update will be triggered
359 // will be triggered by LayoutBoxModelObject::setBackingNeedsPaintInvalidati onInRect 361 // by LayoutBoxModelObject::setBackingNeedsPaintInvalidationInRect
360 if (hasScrollingLayer() && !shouldPaintOntoScrollingContentsLayer) 362 if (hasScrollingLayer() && !shouldPaintOntoScrollingContentsLayer)
361 m_scrollingContentsLayer->setNeedsDisplay(); 363 m_scrollingContentsLayer->setNeedsDisplay();
362 } 364 }
363 } 365 }
364 366
365 void CompositedLayerMapping::updateContentsOpaque() { 367 void CompositedLayerMapping::updateContentsOpaque() {
366 if (isAcceleratedCanvas(layoutObject())) { 368 if (isAcceleratedCanvas(layoutObject())) {
367 // Determine whether the rendering context's external texture layer is opaqu e. 369 // Determine whether the rendering context's external texture layer is
370 // opaque.
368 CanvasRenderingContext* context = 371 CanvasRenderingContext* context =
369 toHTMLCanvasElement(layoutObject()->node())->renderingContext(); 372 toHTMLCanvasElement(layoutObject()->node())->renderingContext();
370 if (!context->creationAttributes().alpha()) 373 if (!context->creationAttributes().alpha())
371 m_graphicsLayer->setContentsOpaque(true); 374 m_graphicsLayer->setContentsOpaque(true);
372 else if (WebLayer* layer = context->platformLayer()) 375 else if (WebLayer* layer = context->platformLayer())
373 m_graphicsLayer->setContentsOpaque( 376 m_graphicsLayer->setContentsOpaque(
374 !Color(layer->backgroundColor()).hasAlpha()); 377 !Color(layer->backgroundColor()).hasAlpha());
375 else 378 else
376 m_graphicsLayer->setContentsOpaque(false); 379 m_graphicsLayer->setContentsOpaque(false);
377 } else if (m_backgroundLayer) { 380 } else if (m_backgroundLayer) {
378 m_graphicsLayer->setContentsOpaque(false); 381 m_graphicsLayer->setContentsOpaque(false);
379 m_backgroundLayer->setContentsOpaque( 382 m_backgroundLayer->setContentsOpaque(
380 m_owningLayer.backgroundIsKnownToBeOpaqueInRect(compositedBounds())); 383 m_owningLayer.backgroundIsKnownToBeOpaqueInRect(compositedBounds()));
381 } else { 384 } else {
382 // For non-root layers, background is painted by the scrolling contents laye r if all backgrounds 385 // For non-root layers, background is painted by the scrolling contents
383 // are background attachment local, otherwise background is painted by the p rimary graphics layer. 386 // layer if all backgrounds are background attachment local, otherwise
387 // background is painted by the primary graphics layer.
384 if (hasScrollingLayer() && m_backgroundPaintsOntoScrollingContentsLayer) { 388 if (hasScrollingLayer() && m_backgroundPaintsOntoScrollingContentsLayer) {
385 // Backgrounds painted onto the foreground are clipped by the padding box rect. 389 // Backgrounds painted onto the foreground are clipped by the padding box
386 // TODO(flackr): This should actually check the entire overflow rect withi n the 390 // rect.
387 // scrolling contents layer but since we currently only trigger this for s olid 391 // TODO(flackr): This should actually check the entire overflow rect
388 // color backgrounds the answer will be the same. 392 // within the scrolling contents layer but since we currently only trigger
393 // this for solid color backgrounds the answer will be the same.
389 m_scrollingContentsLayer->setContentsOpaque( 394 m_scrollingContentsLayer->setContentsOpaque(
390 m_owningLayer.backgroundIsKnownToBeOpaqueInRect( 395 m_owningLayer.backgroundIsKnownToBeOpaqueInRect(
391 toLayoutBox(layoutObject())->paddingBoxRect())); 396 toLayoutBox(layoutObject())->paddingBoxRect()));
392 397
393 // When we paint the background onto the scrolling contents layer we are g oing 398 // When we paint the background onto the scrolling contents layer we are
394 // to leave a hole in the m_graphicsLayer where the background is so it is 399 // going to leave a hole in the m_graphicsLayer where the background is so
395 // not opaque. 400 // it is not opaque.
396 m_graphicsLayer->setContentsOpaque(false); 401 m_graphicsLayer->setContentsOpaque(false);
397 } else { 402 } else {
398 if (hasScrollingLayer()) 403 if (hasScrollingLayer())
399 m_scrollingContentsLayer->setContentsOpaque(false); 404 m_scrollingContentsLayer->setContentsOpaque(false);
400 m_graphicsLayer->setContentsOpaque( 405 m_graphicsLayer->setContentsOpaque(
401 m_owningLayer.backgroundIsKnownToBeOpaqueInRect(compositedBounds())); 406 m_owningLayer.backgroundIsKnownToBeOpaqueInRect(compositedBounds()));
402 } 407 }
403 } 408 }
404 } 409 }
405 410
406 void CompositedLayerMapping::updateCompositedBounds() { 411 void CompositedLayerMapping::updateCompositedBounds() {
407 ASSERT(m_owningLayer.compositor()->lifecycle().state() == 412 ASSERT(m_owningLayer.compositor()->lifecycle().state() ==
408 DocumentLifecycle::InCompositingUpdate); 413 DocumentLifecycle::InCompositingUpdate);
409 // FIXME: if this is really needed for performance, it would be better to stor e it on Layer. 414 // FIXME: if this is really needed for performance, it would be better to
415 // store it on Layer.
410 m_compositedBounds = m_owningLayer.boundingBoxForCompositing(); 416 m_compositedBounds = m_owningLayer.boundingBoxForCompositing();
411 m_contentOffsetInCompositingLayerDirty = true; 417 m_contentOffsetInCompositingLayerDirty = true;
412 } 418 }
413 419
414 void CompositedLayerMapping::updateAfterPartResize() { 420 void CompositedLayerMapping::updateAfterPartResize() {
415 if (layoutObject()->isLayoutPart()) { 421 if (layoutObject()->isLayoutPart()) {
416 if (PaintLayerCompositor* innerCompositor = 422 if (PaintLayerCompositor* innerCompositor =
417 PaintLayerCompositor::frameContentsCompositor( 423 PaintLayerCompositor::frameContentsCompositor(
418 toLayoutPart(layoutObject()))) { 424 toLayoutPart(layoutObject()))) {
419 innerCompositor->frameViewDidChangeSize(); 425 innerCompositor->frameViewDidChangeSize();
420 // We can floor this point because our frameviews are always aligned to pi xel boundaries. 426 // We can floor this point because our frameviews are always aligned to
427 // pixel boundaries.
421 ASSERT(m_compositedBounds.location() == 428 ASSERT(m_compositedBounds.location() ==
422 flooredIntPoint(m_compositedBounds.location())); 429 flooredIntPoint(m_compositedBounds.location()));
423 innerCompositor->frameViewDidChangeLocation( 430 innerCompositor->frameViewDidChangeLocation(
424 flooredIntPoint(contentsBox().location())); 431 flooredIntPoint(contentsBox().location()));
425 } 432 }
426 } 433 }
427 } 434 }
428 435
429 void CompositedLayerMapping::updateCompositingReasons() { 436 void CompositedLayerMapping::updateCompositingReasons() {
430 // All other layers owned by this mapping will have the same compositing reaso n 437 // All other layers owned by this mapping will have the same compositing
431 // for their lifetime, so they are initialized only when created. 438 // reason for their lifetime, so they are initialized only when created.
432 m_graphicsLayer->setCompositingReasons(m_owningLayer.getCompositingReasons()); 439 m_graphicsLayer->setCompositingReasons(m_owningLayer.getCompositingReasons());
433 m_graphicsLayer->setSquashingDisallowedReasons( 440 m_graphicsLayer->setSquashingDisallowedReasons(
434 m_owningLayer.getSquashingDisallowedReasons()); 441 m_owningLayer.getSquashingDisallowedReasons());
435 } 442 }
436 443
437 bool CompositedLayerMapping:: 444 bool CompositedLayerMapping::
438 owningLayerClippedByLayerNotAboveCompositedAncestor( 445 owningLayerClippedByLayerNotAboveCompositedAncestor(
439 const PaintLayer* scrollParent) { 446 const PaintLayer* scrollParent) {
440 if (!m_owningLayer.parent()) 447 if (!m_owningLayer.parent())
441 return false; 448 return false;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 const PaintLayer* scrollParent = m_owningLayer.scrollParent(); 482 const PaintLayer* scrollParent = m_owningLayer.scrollParent();
476 if (scrollParent && !scrollParent->needsCompositedScrolling()) 483 if (scrollParent && !scrollParent->needsCompositedScrolling())
477 return nullptr; 484 return nullptr;
478 return scrollParent; 485 return scrollParent;
479 } 486 }
480 487
481 bool CompositedLayerMapping::updateGraphicsLayerConfiguration() { 488 bool CompositedLayerMapping::updateGraphicsLayerConfiguration() {
482 ASSERT(m_owningLayer.compositor()->lifecycle().state() == 489 ASSERT(m_owningLayer.compositor()->lifecycle().state() ==
483 DocumentLifecycle::InCompositingUpdate); 490 DocumentLifecycle::InCompositingUpdate);
484 491
485 // Note carefully: here we assume that the compositing state of all descendant s have been updated already, 492 // Note carefully: here we assume that the compositing state of all
486 // so it is legitimate to compute and cache the composited bounds for this lay er. 493 // descendants have been updated already, so it is legitimate to compute and
494 // cache the composited bounds for this layer.
487 updateCompositedBounds(); 495 updateCompositedBounds();
488 496
489 PaintLayerCompositor* compositor = this->compositor(); 497 PaintLayerCompositor* compositor = this->compositor();
490 LayoutObject* layoutObject = this->layoutObject(); 498 LayoutObject* layoutObject = this->layoutObject();
491 const ComputedStyle& style = layoutObject->styleRef(); 499 const ComputedStyle& style = layoutObject->styleRef();
492 500
493 bool layerConfigChanged = false; 501 bool layerConfigChanged = false;
494 setBackgroundLayerPaintsFixedRootBackground( 502 setBackgroundLayerPaintsFixedRootBackground(
495 compositor->needsFixedRootBackgroundLayer(&m_owningLayer)); 503 compositor->needsFixedRootBackgroundLayer(&m_owningLayer));
496 504
(...skipping 13 matching lines...) Expand all
510 needsDescendantsClippingLayer = false; 518 needsDescendantsClippingLayer = false;
511 519
512 // We disable clipping on ancestor layers of the root scroller to give it 520 // We disable clipping on ancestor layers of the root scroller to give it
513 // the same behavior w.r.t top controls as the real root layer. See the 521 // the same behavior w.r.t top controls as the real root layer. See the
514 // RootScrollerController class for more details. 522 // RootScrollerController class for more details.
515 if (m_owningLayer.hasRootScrollerAsDescendant()) 523 if (m_owningLayer.hasRootScrollerAsDescendant())
516 needsDescendantsClippingLayer = false; 524 needsDescendantsClippingLayer = false;
517 525
518 const PaintLayer* scrollParent = this->scrollParent(); 526 const PaintLayer* scrollParent = this->scrollParent();
519 527
520 // This is required because compositing layers are parented according to the z -order hierarchy, yet 528 // This is required because compositing layers are parented according to the
521 // clipping goes down the layoutObject hierarchy. Thus, a PaintLayer can be cl ipped by a 529 // z-order hierarchy, yet clipping goes down the layoutObject hierarchy. Thus,
522 // PaintLayer that is an ancestor in the layoutObject hierarchy, but a sibling in the z-order 530 // a PaintLayer can be clipped by a PaintLayer that is an ancestor in the
523 // hierarchy. Further, that sibling need not be composited at all. In such sce narios, an ancestor 531 // layoutObject hierarchy, but a sibling in the z-order hierarchy. Further,
532 // that sibling need not be composited at all. In such scenarios, an ancestor
524 // clipping layer is necessary to apply the composited clip for this layer. 533 // clipping layer is necessary to apply the composited clip for this layer.
525 bool needsAncestorClip = 534 bool needsAncestorClip =
526 owningLayerClippedByLayerNotAboveCompositedAncestor(scrollParent) && 535 owningLayerClippedByLayerNotAboveCompositedAncestor(scrollParent) &&
527 !m_owningLayer.clippingContainer() 536 !m_owningLayer.clippingContainer()
528 ->enclosingLayer() 537 ->enclosingLayer()
529 ->hasRootScrollerAsDescendant(); 538 ->hasRootScrollerAsDescendant();
530 539
531 if (updateClippingLayers(needsAncestorClip, needsDescendantsClippingLayer)) 540 if (updateClippingLayers(needsAncestorClip, needsDescendantsClippingLayer))
532 layerConfigChanged = true; 541 layerConfigChanged = true;
533 542
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 // that's plugged into another GraphicsLayer that is part of the hierarchy. 574 // that's plugged into another GraphicsLayer that is part of the hierarchy.
566 // It has no parent or child GraphicsLayer. For that reason, we process it 575 // It has no parent or child GraphicsLayer. For that reason, we process it
567 // here, after the hierarchy has been updated. 576 // here, after the hierarchy has been updated.
568 bool maskLayerChanged = updateMaskLayer(layoutObject->hasMask()); 577 bool maskLayerChanged = updateMaskLayer(layoutObject->hasMask());
569 if (maskLayerChanged) 578 if (maskLayerChanged)
570 m_graphicsLayer->setMaskLayer(m_maskLayer.get()); 579 m_graphicsLayer->setMaskLayer(m_maskLayer.get());
571 580
572 bool hasChildClippingLayer = 581 bool hasChildClippingLayer =
573 compositor->clipsCompositingDescendants(&m_owningLayer) && 582 compositor->clipsCompositingDescendants(&m_owningLayer) &&
574 (hasClippingLayer() || hasScrollingLayer()); 583 (hasClippingLayer() || hasScrollingLayer());
575 // If we have a border radius or clip path on a scrolling layer, we need a cli pping mask to properly 584 // If we have a border radius or clip path on a scrolling layer, we need a
576 // clip the scrolled contents, even if there are no composited descendants. 585 // clipping mask to properly clip the scrolled contents, even if there are no
586 // composited descendants.
577 bool hasClipPath = style.clipPath(); 587 bool hasClipPath = style.clipPath();
578 bool needsChildClippingMask = 588 bool needsChildClippingMask =
579 (hasClipPath || style.hasBorderRadius()) && 589 (hasClipPath || style.hasBorderRadius()) &&
580 (hasChildClippingLayer || isAcceleratedContents(layoutObject) || 590 (hasChildClippingLayer || isAcceleratedContents(layoutObject) ||
581 hasScrollingLayer()); 591 hasScrollingLayer());
582 592
583 GraphicsLayer* layerToApplyChildClippingMask = nullptr; 593 GraphicsLayer* layerToApplyChildClippingMask = nullptr;
584 bool shouldApplyChildClippingMaskOnContents = false; 594 bool shouldApplyChildClippingMaskOnContents = false;
585 if (needsChildClippingMask) { 595 if (needsChildClippingMask) {
586 if (hasClipPath) { 596 if (hasClipPath) {
587 // Clip path clips the entire subtree, including scrollbars. It must be at tached directly onto 597 // Clip path clips the entire subtree, including scrollbars. It must be
588 // the main m_graphicsLayer. 598 // attached directly onto the main m_graphicsLayer.
589 layerToApplyChildClippingMask = m_graphicsLayer.get(); 599 layerToApplyChildClippingMask = m_graphicsLayer.get();
590 } else if (hasClippingLayer()) { 600 } else if (hasClippingLayer()) {
591 layerToApplyChildClippingMask = clippingLayer(); 601 layerToApplyChildClippingMask = clippingLayer();
592 } else if (hasScrollingLayer()) { 602 } else if (hasScrollingLayer()) {
593 layerToApplyChildClippingMask = scrollingLayer(); 603 layerToApplyChildClippingMask = scrollingLayer();
594 } else if (isAcceleratedContents(layoutObject)) { 604 } else if (isAcceleratedContents(layoutObject)) {
595 shouldApplyChildClippingMaskOnContents = true; 605 shouldApplyChildClippingMaskOnContents = true;
596 } 606 }
597 } 607 }
598 608
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 offsetFromCompositedAncestor = 718 offsetFromCompositedAncestor =
709 computeOffsetFromCompositedAncestor(&m_owningLayer, compositedAncestor); 719 computeOffsetFromCompositedAncestor(&m_owningLayer, compositedAncestor);
710 snappedOffsetFromCompositedAncestor = 720 snappedOffsetFromCompositedAncestor =
711 IntPoint(offsetFromCompositedAncestor.x().round(), 721 IntPoint(offsetFromCompositedAncestor.x().round(),
712 offsetFromCompositedAncestor.y().round()); 722 offsetFromCompositedAncestor.y().round());
713 723
714 LayoutSize subpixelAccumulation = 724 LayoutSize subpixelAccumulation =
715 offsetFromCompositedAncestor - snappedOffsetFromCompositedAncestor; 725 offsetFromCompositedAncestor - snappedOffsetFromCompositedAncestor;
716 m_owningLayer.setSubpixelAccumulation(subpixelAccumulation); 726 m_owningLayer.setSubpixelAccumulation(subpixelAccumulation);
717 727
718 // Move the bounds by the subpixel accumulation so that it pixel-snaps relativ e to absolute pixels instead of local coordinates. 728 // Move the bounds by the subpixel accumulation so that it pixel-snaps
729 // relative to absolute pixels instead of local coordinates.
719 localRawCompositingBounds.move(subpixelAccumulation); 730 localRawCompositingBounds.move(subpixelAccumulation);
720 localBounds = pixelSnappedIntRect(localRawCompositingBounds); 731 localBounds = pixelSnappedIntRect(localRawCompositingBounds);
721 732
722 compositingBoundsRelativeToCompositedAncestor = localBounds; 733 compositingBoundsRelativeToCompositedAncestor = localBounds;
723 compositingBoundsRelativeToCompositedAncestor.moveBy( 734 compositingBoundsRelativeToCompositedAncestor.moveBy(
724 snappedOffsetFromCompositedAncestor); 735 snappedOffsetFromCompositedAncestor);
725 } 736 }
726 737
727 void CompositedLayerMapping::updateSquashingLayerGeometry( 738 void CompositedLayerMapping::updateSquashingLayerGeometry(
728 const IntPoint& graphicsLayerParentLocation, 739 const IntPoint& graphicsLayerParentLocation,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 layers[i].paintLayer->computeOffsetFromTransformedAncestor(); 780 layers[i].paintLayer->computeOffsetFromTransformedAncestor();
770 LayoutSize squashedLayerOffsetFromCompositingContainer = 781 LayoutSize squashedLayerOffsetFromCompositingContainer =
771 squashedLayerOffsetFromTransformedAncestor - 782 squashedLayerOffsetFromTransformedAncestor -
772 compositingContainerOffsetFromTransformedAncestor; 783 compositingContainerOffsetFromTransformedAncestor;
773 784
774 squashedBounds.move(squashedLayerOffsetFromCompositingContainer); 785 squashedBounds.move(squashedLayerOffsetFromCompositingContainer);
775 totalSquashBounds.unite(squashedBounds); 786 totalSquashBounds.unite(squashedBounds);
776 } 787 }
777 788
778 // The totalSquashBounds is positioned with respect to compositingContainer. 789 // The totalSquashBounds is positioned with respect to compositingContainer.
779 // But the squashingLayer needs to be positioned with respect to the graphicsL ayerParent. 790 // But the squashingLayer needs to be positioned with respect to the
780 // The conversion between compositingContainer and the graphicsLayerParent is already computed 791 // graphicsLayerParent. The conversion between compositingContainer and the
781 // as compositingContainerOffsetFromParentGraphicsLayer. 792 // graphicsLayerParent is already computed as
793 // compositingContainerOffsetFromParentGraphicsLayer.
782 totalSquashBounds.moveBy(compositingContainerOffsetFromParentGraphicsLayer); 794 totalSquashBounds.moveBy(compositingContainerOffsetFromParentGraphicsLayer);
783 const IntRect squashLayerBounds = enclosingIntRect(totalSquashBounds); 795 const IntRect squashLayerBounds = enclosingIntRect(totalSquashBounds);
784 const IntPoint squashLayerOrigin = squashLayerBounds.location(); 796 const IntPoint squashLayerOrigin = squashLayerBounds.location();
785 const LayoutSize squashLayerOriginInCompositingContainerSpace = 797 const LayoutSize squashLayerOriginInCompositingContainerSpace =
786 squashLayerOrigin - compositingContainerOffsetFromParentGraphicsLayer; 798 squashLayerOrigin - compositingContainerOffsetFromParentGraphicsLayer;
787 799
788 // Now that the squashing bounds are known, we can convert the PaintLayer pain ting offsets 800 // Now that the squashing bounds are known, we can convert the PaintLayer
789 // from compositingContainer space to the squashing layer space. 801 // painting offsets from compositingContainer space to the squashing layer
802 // space.
790 // 803 //
791 // The painting offset we want to compute for each squashed PaintLayer is esse ntially the 804 // The painting offset we want to compute for each squashed PaintLayer is
792 // position of the squashed PaintLayer described w.r.t. compositingContainer's origin. 805 // essentially the position of the squashed PaintLayer described w.r.t.
793 // So we just need to convert that point from compositingContainer space to th e squashing 806 // compositingContainer's origin. So we just need to convert that point from
794 // layer's space. This is done by subtracting squashLayerOriginInCompositingCo ntainerSpace, 807 // compositingContainer space to the squashing layer's space. This is done by
795 // but then the offset overall needs to be negated because that's the directio n that the 808 // subtracting squashLayerOriginInCompositingContainerSpace, but then the
809 // offset overall needs to be negated because that's the direction that the
796 // painting code expects the offset to be. 810 // painting code expects the offset to be.
797 for (size_t i = 0; i < layers.size(); ++i) { 811 for (size_t i = 0; i < layers.size(); ++i) {
798 const LayoutPoint squashedLayerOffsetFromTransformedAncestor = 812 const LayoutPoint squashedLayerOffsetFromTransformedAncestor =
799 layers[i].paintLayer->computeOffsetFromTransformedAncestor(); 813 layers[i].paintLayer->computeOffsetFromTransformedAncestor();
800 const LayoutSize offsetFromSquashLayerOrigin = 814 const LayoutSize offsetFromSquashLayerOrigin =
801 (squashedLayerOffsetFromTransformedAncestor - 815 (squashedLayerOffsetFromTransformedAncestor -
802 compositingContainerOffsetFromTransformedAncestor) - 816 compositingContainerOffsetFromTransformedAncestor) -
803 squashLayerOriginInCompositingContainerSpace; 817 squashLayerOriginInCompositingContainerSpace;
804 818
805 IntSize newOffsetFromLayoutObject = 819 IntSize newOffsetFromLayoutObject =
806 -IntSize(offsetFromSquashLayerOrigin.width().round(), 820 -IntSize(offsetFromSquashLayerOrigin.width().round(),
807 offsetFromSquashLayerOrigin.height().round()); 821 offsetFromSquashLayerOrigin.height().round());
808 LayoutSize subpixelAccumulation = 822 LayoutSize subpixelAccumulation =
809 offsetFromSquashLayerOrigin + newOffsetFromLayoutObject; 823 offsetFromSquashLayerOrigin + newOffsetFromLayoutObject;
810 if (layers[i].offsetFromLayoutObjectSet && 824 if (layers[i].offsetFromLayoutObjectSet &&
811 layers[i].offsetFromLayoutObject != newOffsetFromLayoutObject) { 825 layers[i].offsetFromLayoutObject != newOffsetFromLayoutObject) {
812 // It is ok to issue paint invalidation here, because all of the geometry needed to correctly invalidate paint is computed by this point. 826 // It is ok to issue paint invalidation here, because all of the geometry
827 // needed to correctly invalidate paint is computed by this point.
813 DisablePaintInvalidationStateAsserts disabler; 828 DisablePaintInvalidationStateAsserts disabler;
814 ObjectPaintInvalidator(*layers[i].paintLayer->layoutObject()) 829 ObjectPaintInvalidator(*layers[i].paintLayer->layoutObject())
815 .invalidatePaintIncludingNonCompositingDescendants(); 830 .invalidatePaintIncludingNonCompositingDescendants();
816 831
817 TRACE_LAYER_INVALIDATION(layers[i].paintLayer, 832 TRACE_LAYER_INVALIDATION(layers[i].paintLayer,
818 InspectorLayerInvalidationTrackingEvent:: 833 InspectorLayerInvalidationTrackingEvent::
819 SquashingLayerGeometryWasUpdated); 834 SquashingLayerGeometryWasUpdated);
820 layersNeedingPaintInvalidation.append(layers[i].paintLayer); 835 layersNeedingPaintInvalidation.append(layers[i].paintLayer);
821 } 836 }
822 layers[i].offsetFromLayoutObject = newOffsetFromLayoutObject; 837 layers[i].offsetFromLayoutObject = newOffsetFromLayoutObject;
(...skipping 15 matching lines...) Expand all
838 localClipRectForSquashedLayer(m_owningLayer, layers[i], layers); 853 localClipRectForSquashedLayer(m_owningLayer, layers[i], layers);
839 } 854 }
840 855
841 void CompositedLayerMapping::updateGraphicsLayerGeometry( 856 void CompositedLayerMapping::updateGraphicsLayerGeometry(
842 const PaintLayer* compositingContainer, 857 const PaintLayer* compositingContainer,
843 const PaintLayer* compositingStackingContext, 858 const PaintLayer* compositingStackingContext,
844 Vector<PaintLayer*>& layersNeedingPaintInvalidation) { 859 Vector<PaintLayer*>& layersNeedingPaintInvalidation) {
845 ASSERT(m_owningLayer.compositor()->lifecycle().state() == 860 ASSERT(m_owningLayer.compositor()->lifecycle().state() ==
846 DocumentLifecycle::InCompositingUpdate); 861 DocumentLifecycle::InCompositingUpdate);
847 862
848 // Set transform property, if it is not animating. We have to do this here bec ause the transform 863 // Set transform property, if it is not animating. We have to do this here
849 // is affected by the layer dimensions. 864 // because the transform is affected by the layer dimensions.
850 if (!layoutObject()->style()->isRunningTransformAnimationOnCompositor()) 865 if (!layoutObject()->style()->isRunningTransformAnimationOnCompositor())
851 updateTransform(layoutObject()->styleRef()); 866 updateTransform(layoutObject()->styleRef());
852 867
853 // Set opacity, if it is not animating. 868 // Set opacity, if it is not animating.
854 if (!layoutObject()->style()->isRunningOpacityAnimationOnCompositor()) 869 if (!layoutObject()->style()->isRunningOpacityAnimationOnCompositor())
855 updateOpacity(layoutObject()->styleRef()); 870 updateOpacity(layoutObject()->styleRef());
856 871
857 if (!layoutObject()->style()->isRunningFilterAnimationOnCompositor()) 872 if (!layoutObject()->style()->isRunningFilterAnimationOnCompositor())
858 updateFilters(layoutObject()->styleRef()); 873 updateFilters(layoutObject()->styleRef());
859 874
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 m_graphicsLayer->setPosition(FloatPoint(relativeCompositingBounds.location() - 963 m_graphicsLayer->setPosition(FloatPoint(relativeCompositingBounds.location() -
949 graphicsLayerParentLocation)); 964 graphicsLayerParentLocation));
950 m_graphicsLayer->setOffsetFromLayoutObject( 965 m_graphicsLayer->setOffsetFromLayoutObject(
951 toIntSize(localCompositingBounds.location())); 966 toIntSize(localCompositingBounds.location()));
952 967
953 FloatSize oldSize = m_graphicsLayer->size(); 968 FloatSize oldSize = m_graphicsLayer->size();
954 const FloatSize contentsSize(relativeCompositingBounds.size()); 969 const FloatSize contentsSize(relativeCompositingBounds.size());
955 if (oldSize != contentsSize) 970 if (oldSize != contentsSize)
956 m_graphicsLayer->setSize(contentsSize); 971 m_graphicsLayer->setSize(contentsSize);
957 972
958 // m_graphicsLayer is the corresponding GraphicsLayer for this PaintLayer and its non-compositing 973 // m_graphicsLayer is the corresponding GraphicsLayer for this PaintLayer and
959 // descendants. So, the visibility flag for m_graphicsLayer should be true if there are any 974 // its non-compositing descendants. So, the visibility flag for
960 // non-compositing visible layers. 975 // m_graphicsLayer should be true if there are any non-compositing visible
976 // layers.
961 bool contentsVisible = m_owningLayer.hasVisibleContent() || 977 bool contentsVisible = m_owningLayer.hasVisibleContent() ||
962 hasVisibleNonCompositingDescendant(&m_owningLayer); 978 hasVisibleNonCompositingDescendant(&m_owningLayer);
963 m_graphicsLayer->setContentsVisible(contentsVisible); 979 m_graphicsLayer->setContentsVisible(contentsVisible);
964 980
965 m_graphicsLayer->setBackfaceVisibility( 981 m_graphicsLayer->setBackfaceVisibility(
966 layoutObject()->style()->backfaceVisibility() == 982 layoutObject()->style()->backfaceVisibility() ==
967 BackfaceVisibilityVisible); 983 BackfaceVisibilityVisible);
968 } 984 }
969 985
970 void CompositedLayerMapping::computeGraphicsLayerParentLocation( 986 void CompositedLayerMapping::computeGraphicsLayerParentLocation(
971 const PaintLayer* compositingContainer, 987 const PaintLayer* compositingContainer,
972 const IntRect& ancestorCompositingBounds, 988 const IntRect& ancestorCompositingBounds,
973 IntPoint& graphicsLayerParentLocation) { 989 IntPoint& graphicsLayerParentLocation) {
974 if (compositingContainer && 990 if (compositingContainer &&
975 compositingContainer->compositedLayerMapping()->hasClippingLayer()) { 991 compositingContainer->compositedLayerMapping()->hasClippingLayer()) {
976 // If the compositing ancestor has a layer to clip children, we parent in th at, and therefore 992 // If the compositing ancestor has a layer to clip children, we parent in
977 // position relative to it. 993 // that, and therefore position relative to it.
978 IntRect clippingBox = 994 IntRect clippingBox =
979 clipBox(toLayoutBox(compositingContainer->layoutObject())); 995 clipBox(toLayoutBox(compositingContainer->layoutObject()));
980 graphicsLayerParentLocation = 996 graphicsLayerParentLocation =
981 clippingBox.location() + 997 clippingBox.location() +
982 roundedIntSize(compositingContainer->subpixelAccumulation()); 998 roundedIntSize(compositingContainer->subpixelAccumulation());
983 } else if (compositingContainer && 999 } else if (compositingContainer &&
984 compositingContainer->compositedLayerMapping() 1000 compositingContainer->compositedLayerMapping()
985 ->childTransformLayer()) { 1001 ->childTransformLayer()) {
986 // Similarly, if the compositing ancestor has a child transform layer, we pa rent in that, and therefore 1002 // Similarly, if the compositing ancestor has a child transform layer, we
987 // position relative to it. It's already taken into account the contents off set, so we do not need to here. 1003 // parent in that, and therefore position relative to it. It's already taken
1004 // into account the contents offset, so we do not need to here.
988 graphicsLayerParentLocation = 1005 graphicsLayerParentLocation =
989 roundedIntPoint(compositingContainer->subpixelAccumulation()); 1006 roundedIntPoint(compositingContainer->subpixelAccumulation());
990 } else if (compositingContainer) { 1007 } else if (compositingContainer) {
991 graphicsLayerParentLocation = ancestorCompositingBounds.location(); 1008 graphicsLayerParentLocation = ancestorCompositingBounds.location();
992 } else { 1009 } else {
993 graphicsLayerParentLocation = 1010 graphicsLayerParentLocation =
994 layoutObject()->view()->documentRect().location(); 1011 layoutObject()->view()->documentRect().location();
995 } 1012 }
996 1013
997 if (compositingContainer && 1014 if (compositingContainer &&
(...skipping 17 matching lines...) Expand all
1015 ClipRectsContext clipRectsContext(compositingContainer, 1032 ClipRectsContext clipRectsContext(compositingContainer,
1016 PaintingClipRectsIgnoringOverflowClip, 1033 PaintingClipRectsIgnoringOverflowClip,
1017 IgnoreOverlayScrollbarSize); 1034 IgnoreOverlayScrollbarSize);
1018 IntRect parentClipRect = pixelSnappedIntRect( 1035 IntRect parentClipRect = pixelSnappedIntRect(
1019 m_owningLayer.clipper().backgroundClipRect(clipRectsContext).rect()); 1036 m_owningLayer.clipper().backgroundClipRect(clipRectsContext).rect());
1020 ASSERT(parentClipRect != LayoutRect::infiniteIntRect()); 1037 ASSERT(parentClipRect != LayoutRect::infiniteIntRect());
1021 m_ancestorClippingLayer->setPosition( 1038 m_ancestorClippingLayer->setPosition(
1022 FloatPoint(parentClipRect.location() - graphicsLayerParentLocation)); 1039 FloatPoint(parentClipRect.location() - graphicsLayerParentLocation));
1023 m_ancestorClippingLayer->setSize(FloatSize(parentClipRect.size())); 1040 m_ancestorClippingLayer->setSize(FloatSize(parentClipRect.size()));
1024 1041
1025 // backgroundRect is relative to compositingContainer, so subtract snappedOffs etFromCompositedAncestor.X/snappedOffsetFromCompositedAncestor.Y to get back to local coords. 1042 // backgroundRect is relative to compositingContainer, so subtract
1043 // snappedOffsetFromCompositedAncestor.X/snappedOffsetFromCompositedAncestor.Y
1044 // to get back to local coords.
1026 m_ancestorClippingLayer->setOffsetFromLayoutObject( 1045 m_ancestorClippingLayer->setOffsetFromLayoutObject(
1027 parentClipRect.location() - snappedOffsetFromCompositedAncestor); 1046 parentClipRect.location() - snappedOffsetFromCompositedAncestor);
1028 1047
1029 // The primary layer is then parented in, and positioned relative to this clip ping layer. 1048 // The primary layer is then parented in, and positioned relative to this
1049 // clipping layer.
1030 graphicsLayerParentLocation = parentClipRect.location(); 1050 graphicsLayerParentLocation = parentClipRect.location();
1031 } 1051 }
1032 1052
1033 void CompositedLayerMapping::updateOverflowControlsHostLayerGeometry( 1053 void CompositedLayerMapping::updateOverflowControlsHostLayerGeometry(
1034 const PaintLayer* compositingStackingContext, 1054 const PaintLayer* compositingStackingContext,
1035 const PaintLayer* compositingContainer, 1055 const PaintLayer* compositingContainer,
1036 IntPoint graphicsLayerParentLocation) { 1056 IntPoint graphicsLayerParentLocation) {
1037 if (!m_overflowControlsHostLayer) 1057 if (!m_overflowControlsHostLayer)
1038 return; 1058 return;
1039 1059
1040 // To position and clip the scrollbars correctly, m_overflowControlsHostLayer should match our 1060 // To position and clip the scrollbars correctly, m_overflowControlsHostLayer
1041 // border box rect, which is at the origin of our LayoutObject. Its position i s computed in 1061 // should match our border box rect, which is at the origin of our
1042 // various ways depending on who its parent GraphicsLayer is going to be. 1062 // LayoutObject. Its position is computed in various ways depending on who its
1063 // parent GraphicsLayer is going to be.
1043 LayoutPoint hostLayerPosition; 1064 LayoutPoint hostLayerPosition;
1044 1065
1045 if (needsToReparentOverflowControls()) { 1066 if (needsToReparentOverflowControls()) {
1046 CompositedLayerMapping* stackingCLM = 1067 CompositedLayerMapping* stackingCLM =
1047 compositingStackingContext->compositedLayerMapping(); 1068 compositingStackingContext->compositedLayerMapping();
1048 DCHECK(stackingCLM); 1069 DCHECK(stackingCLM);
1049 1070
1050 // Either m_overflowControlsHostLayer or m_overflowControlsAncestorClippingL ayer (if it 1071 // Either m_overflowControlsHostLayer or
1051 // exists) will be a child of the main GraphicsLayer of the compositing stac king context. 1072 // m_overflowControlsAncestorClippingLayer (if it exists) will be a child of
1073 // the main GraphicsLayer of the compositing stacking context.
1052 IntSize stackingOffsetFromLayoutObject = 1074 IntSize stackingOffsetFromLayoutObject =
1053 stackingCLM->mainGraphicsLayer()->offsetFromLayoutObject(); 1075 stackingCLM->mainGraphicsLayer()->offsetFromLayoutObject();
1054 1076
1055 if (m_overflowControlsAncestorClippingLayer) { 1077 if (m_overflowControlsAncestorClippingLayer) {
1056 m_overflowControlsAncestorClippingLayer->setSize( 1078 m_overflowControlsAncestorClippingLayer->setSize(
1057 m_ancestorClippingLayer->size()); 1079 m_ancestorClippingLayer->size());
1058 m_overflowControlsAncestorClippingLayer->setOffsetFromLayoutObject( 1080 m_overflowControlsAncestorClippingLayer->setOffsetFromLayoutObject(
1059 m_ancestorClippingLayer->offsetFromLayoutObject()); 1081 m_ancestorClippingLayer->offsetFromLayoutObject());
1060 m_overflowControlsAncestorClippingLayer->setMasksToBounds(true); 1082 m_overflowControlsAncestorClippingLayer->setMasksToBounds(true);
1061 1083
1062 FloatPoint position; 1084 FloatPoint position;
1063 if (compositingStackingContext == compositingContainer) { 1085 if (compositingStackingContext == compositingContainer) {
1064 position = m_ancestorClippingLayer->position(); 1086 position = m_ancestorClippingLayer->position();
1065 } else { 1087 } else {
1066 // graphicsLayerParentLocation is the location of m_ancestorClippingLaye r 1088 // graphicsLayerParentLocation is the location of
1067 // relative to compositingContainer (including any offset from 1089 // m_ancestorClippingLayer relative to compositingContainer (including
1068 // compositingContainer's m_childContainmentLayer). 1090 // any offset from compositingContainer's m_childContainmentLayer).
1069 LayoutPoint offset = LayoutPoint(graphicsLayerParentLocation); 1091 LayoutPoint offset = LayoutPoint(graphicsLayerParentLocation);
1070 compositingContainer->convertToLayerCoords(compositingStackingContext, 1092 compositingContainer->convertToLayerCoords(compositingStackingContext,
1071 offset); 1093 offset);
1072 position = 1094 position =
1073 FloatPoint(offset) - FloatSize(stackingOffsetFromLayoutObject); 1095 FloatPoint(offset) - FloatSize(stackingOffsetFromLayoutObject);
1074 } 1096 }
1075 1097
1076 m_overflowControlsAncestorClippingLayer->setPosition(position); 1098 m_overflowControlsAncestorClippingLayer->setPosition(position);
1077 hostLayerPosition.move( 1099 hostLayerPosition.move(
1078 -m_ancestorClippingLayer->offsetFromLayoutObject()); 1100 -m_ancestorClippingLayer->offsetFromLayoutObject());
1079 } else { 1101 } else {
1080 // The controls are in the same 2D space as the compositing container, so we can map them into the space of the container. 1102 // The controls are in the same 2D space as the compositing container, so
1103 // we can map them into the space of the container.
1081 TransformState transformState(TransformState::ApplyTransformDirection, 1104 TransformState transformState(TransformState::ApplyTransformDirection,
1082 FloatPoint()); 1105 FloatPoint());
1083 m_owningLayer.layoutObject()->mapLocalToAncestor( 1106 m_owningLayer.layoutObject()->mapLocalToAncestor(
1084 compositingStackingContext->layoutObject(), transformState, 1107 compositingStackingContext->layoutObject(), transformState,
1085 ApplyContainerFlip); 1108 ApplyContainerFlip);
1086 transformState.flatten(); 1109 transformState.flatten();
1087 hostLayerPosition = LayoutPoint(transformState.lastPlanarPoint()); 1110 hostLayerPosition = LayoutPoint(transformState.lastPlanarPoint());
1088 if (PaintLayerScrollableArea* scrollableArea = 1111 if (PaintLayerScrollableArea* scrollableArea =
1089 compositingStackingContext->getScrollableArea()) 1112 compositingStackingContext->getScrollableArea())
1090 hostLayerPosition.move( 1113 hostLayerPosition.move(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 m_maskLayer->setOffsetFromLayoutObject( 1178 m_maskLayer->setOffsetFromLayoutObject(
1156 m_graphicsLayer->offsetFromLayoutObject()); 1179 m_graphicsLayer->offsetFromLayoutObject());
1157 } 1180 }
1158 1181
1159 void CompositedLayerMapping::updateTransformGeometry( 1182 void CompositedLayerMapping::updateTransformGeometry(
1160 const IntPoint& snappedOffsetFromCompositedAncestor, 1183 const IntPoint& snappedOffsetFromCompositedAncestor,
1161 const IntRect& relativeCompositingBounds) { 1184 const IntRect& relativeCompositingBounds) {
1162 if (m_owningLayer.hasTransformRelatedProperty()) { 1185 if (m_owningLayer.hasTransformRelatedProperty()) {
1163 const LayoutRect borderBox = toLayoutBox(layoutObject())->borderBoxRect(); 1186 const LayoutRect borderBox = toLayoutBox(layoutObject())->borderBoxRect();
1164 1187
1165 // Get layout bounds in the coords of compositingContainer to match relative CompositingBounds. 1188 // Get layout bounds in the coords of compositingContainer to match
1189 // relativeCompositingBounds.
1166 IntRect layerBounds = pixelSnappedIntRect( 1190 IntRect layerBounds = pixelSnappedIntRect(
1167 toLayoutPoint(m_owningLayer.subpixelAccumulation()), borderBox.size()); 1191 toLayoutPoint(m_owningLayer.subpixelAccumulation()), borderBox.size());
1168 layerBounds.moveBy(snappedOffsetFromCompositedAncestor); 1192 layerBounds.moveBy(snappedOffsetFromCompositedAncestor);
1169 1193
1170 // Update properties that depend on layer dimensions 1194 // Update properties that depend on layer dimensions
1171 FloatPoint3D transformOrigin = 1195 FloatPoint3D transformOrigin =
1172 computeTransformOrigin(IntRect(IntPoint(), layerBounds.size())); 1196 computeTransformOrigin(IntRect(IntPoint(), layerBounds.size()));
1173 1197
1174 // |transformOrigin| is in the local space of this layer. layerBounds - rela tiveCompositingBounds converts to the space of the 1198 // |transformOrigin| is in the local space of this layer.
1175 // compositing bounds relative to the composited ancestor. This does not app ly to the z direction, since the page is 2D. 1199 // layerBounds - relativeCompositingBounds converts to the space of the
1200 // compositing bounds relative to the composited ancestor. This does not
1201 // apply to the z direction, since the page is 2D.
1176 FloatPoint3D compositedTransformOrigin( 1202 FloatPoint3D compositedTransformOrigin(
1177 layerBounds.x() - relativeCompositingBounds.x() + transformOrigin.x(), 1203 layerBounds.x() - relativeCompositingBounds.x() + transformOrigin.x(),
1178 layerBounds.y() - relativeCompositingBounds.y() + transformOrigin.y(), 1204 layerBounds.y() - relativeCompositingBounds.y() + transformOrigin.y(),
1179 transformOrigin.z()); 1205 transformOrigin.z());
1180 m_graphicsLayer->setTransformOrigin(compositedTransformOrigin); 1206 m_graphicsLayer->setTransformOrigin(compositedTransformOrigin);
1181 } else { 1207 } else {
1182 FloatPoint3D compositedTransformOrigin( 1208 FloatPoint3D compositedTransformOrigin(
1183 relativeCompositingBounds.width() * 0.5f, 1209 relativeCompositingBounds.width() * 0.5f,
1184 relativeCompositingBounds.height() * 0.5f, 0.f); 1210 relativeCompositingBounds.height() * 0.5f, 0.f);
1185 m_graphicsLayer->setTransformOrigin(compositedTransformOrigin); 1211 m_graphicsLayer->setTransformOrigin(compositedTransformOrigin);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 1244
1219 IntSize scrollSize(layoutBox->scrollWidth().toInt(), 1245 IntSize scrollSize(layoutBox->scrollWidth().toInt(),
1220 layoutBox->scrollHeight().toInt()); 1246 layoutBox->scrollHeight().toInt());
1221 if (scrollSize != m_scrollingContentsLayer->size() || 1247 if (scrollSize != m_scrollingContentsLayer->size() ||
1222 overflowClipRectOffsetChanged) 1248 overflowClipRectOffsetChanged)
1223 m_scrollingContentsLayer->setNeedsDisplay(); 1249 m_scrollingContentsLayer->setNeedsDisplay();
1224 1250
1225 DoubleSize scrollingContentsOffset( 1251 DoubleSize scrollingContentsOffset(
1226 overflowClipRect.location().x() - adjustedScrollOffset.width(), 1252 overflowClipRect.location().x() - adjustedScrollOffset.width(),
1227 overflowClipRect.location().y() - adjustedScrollOffset.height()); 1253 overflowClipRect.location().y() - adjustedScrollOffset.height());
1228 // The scroll offset change is compared using floating point so that fractiona l scroll offset 1254 // The scroll offset change is compared using floating point so that
1229 // change can be propagated to compositor. 1255 // fractional scroll offset change can be propagated to compositor.
1230 if (scrollingContentsOffset != m_scrollingContentsOffset || 1256 if (scrollingContentsOffset != m_scrollingContentsOffset ||
1231 scrollSize != m_scrollingContentsLayer->size()) { 1257 scrollSize != m_scrollingContentsLayer->size()) {
1232 bool coordinatorHandlesOffset = 1258 bool coordinatorHandlesOffset =
1233 compositor()->scrollingLayerDidChange(&m_owningLayer); 1259 compositor()->scrollingLayerDidChange(&m_owningLayer);
1234 m_scrollingContentsLayer->setPosition( 1260 m_scrollingContentsLayer->setPosition(
1235 coordinatorHandlesOffset 1261 coordinatorHandlesOffset
1236 ? FloatPoint() 1262 ? FloatPoint()
1237 : FloatPoint(-toFloatSize(adjustedScrollOffset))); 1263 : FloatPoint(-toFloatSize(adjustedScrollOffset)));
1238 } 1264 }
1239 m_scrollingContentsOffset = scrollingContentsOffset; 1265 m_scrollingContentsOffset = scrollingContentsOffset;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 const FloatSize& relativeCompositingBoundsSize, 1306 const FloatSize& relativeCompositingBoundsSize,
1281 const IntRect& clippingBox) { 1307 const IntRect& clippingBox) {
1282 if (!m_foregroundLayer) 1308 if (!m_foregroundLayer)
1283 return; 1309 return;
1284 1310
1285 FloatSize foregroundSize = relativeCompositingBoundsSize; 1311 FloatSize foregroundSize = relativeCompositingBoundsSize;
1286 IntSize foregroundOffset = m_graphicsLayer->offsetFromLayoutObject(); 1312 IntSize foregroundOffset = m_graphicsLayer->offsetFromLayoutObject();
1287 m_foregroundLayer->setPosition(FloatPoint()); 1313 m_foregroundLayer->setPosition(FloatPoint());
1288 1314
1289 if (hasClippingLayer()) { 1315 if (hasClippingLayer()) {
1290 // If we have a clipping layer (which clips descendants), then the foregroun d layer is a child of it, 1316 // If we have a clipping layer (which clips descendants), then the
1291 // so that it gets correctly sorted with children. In that case, position re lative to the clipping layer. 1317 // foreground layer is a child of it, so that it gets correctly sorted with
1318 // children. In that case, position relative to the clipping layer.
1292 foregroundSize = FloatSize(clippingBox.size()); 1319 foregroundSize = FloatSize(clippingBox.size());
1293 foregroundOffset = toIntSize(clippingBox.location()); 1320 foregroundOffset = toIntSize(clippingBox.location());
1294 } else if (m_childTransformLayer) { 1321 } else if (m_childTransformLayer) {
1295 // Things are different if we have a child transform layer rather 1322 // Things are different if we have a child transform layer rather
1296 // than a clipping layer. In this case, we want to actually change 1323 // than a clipping layer. In this case, we want to actually change
1297 // the position of the layer (to compensate for our ancestor 1324 // the position of the layer (to compensate for our ancestor
1298 // compositing PaintLayer's position) rather than leave the position the 1325 // compositing PaintLayer's position) rather than leave the position the
1299 // same and use offset-from-layoutObject + size to describe a clipped 1326 // same and use offset-from-layoutObject + size to describe a clipped
1300 // "window" onto the clipped layer. 1327 // "window" onto the clipped layer.
1301 1328
1302 m_foregroundLayer->setPosition(-m_childTransformLayer->position()); 1329 m_foregroundLayer->setPosition(-m_childTransformLayer->position());
1303 } 1330 }
1304 1331
1305 if (foregroundSize != m_foregroundLayer->size()) { 1332 if (foregroundSize != m_foregroundLayer->size()) {
1306 m_foregroundLayer->setSize(foregroundSize); 1333 m_foregroundLayer->setSize(foregroundSize);
1307 m_foregroundLayer->setNeedsDisplay(); 1334 m_foregroundLayer->setNeedsDisplay();
1308 } 1335 }
1309 m_foregroundLayer->setOffsetFromLayoutObject(foregroundOffset); 1336 m_foregroundLayer->setOffsetFromLayoutObject(foregroundOffset);
1310 1337
1311 // NOTE: there is some more configuring going on in updateScrollingLayerGeomet ry(). 1338 // NOTE: there is some more configuring going on in
1339 // updateScrollingLayerGeometry().
1312 } 1340 }
1313 1341
1314 void CompositedLayerMapping::updateBackgroundLayerGeometry( 1342 void CompositedLayerMapping::updateBackgroundLayerGeometry(
1315 const FloatSize& relativeCompositingBoundsSize) { 1343 const FloatSize& relativeCompositingBoundsSize) {
1316 if (!m_backgroundLayer) 1344 if (!m_backgroundLayer)
1317 return; 1345 return;
1318 1346
1319 FloatSize backgroundSize = relativeCompositingBoundsSize; 1347 FloatSize backgroundSize = relativeCompositingBoundsSize;
1320 if (backgroundLayerPaintsFixedRootBackground()) { 1348 if (backgroundLayerPaintsFixedRootBackground()) {
1321 FrameView* frameView = toLayoutView(layoutObject())->frameView(); 1349 FrameView* frameView = toLayoutView(layoutObject())->frameView();
1322 backgroundSize = FloatSize(frameView->visibleContentRect().size()); 1350 backgroundSize = FloatSize(frameView->visibleContentRect().size());
1323 } 1351 }
1324 m_backgroundLayer->setPosition(FloatPoint()); 1352 m_backgroundLayer->setPosition(FloatPoint());
1325 if (backgroundSize != m_backgroundLayer->size()) { 1353 if (backgroundSize != m_backgroundLayer->size()) {
1326 m_backgroundLayer->setSize(backgroundSize); 1354 m_backgroundLayer->setSize(backgroundSize);
1327 m_backgroundLayer->setNeedsDisplay(); 1355 m_backgroundLayer->setNeedsDisplay();
1328 } 1356 }
1329 m_backgroundLayer->setOffsetFromLayoutObject( 1357 m_backgroundLayer->setOffsetFromLayoutObject(
1330 m_graphicsLayer->offsetFromLayoutObject()); 1358 m_graphicsLayer->offsetFromLayoutObject());
1331 } 1359 }
1332 1360
1333 void CompositedLayerMapping::registerScrollingLayers() { 1361 void CompositedLayerMapping::registerScrollingLayers() {
1334 // Register fixed position layers and their containers with the scrolling coor dinator. 1362 // Register fixed position layers and their containers with the scrolling
1363 // coordinator.
1335 ScrollingCoordinator* scrollingCoordinator = 1364 ScrollingCoordinator* scrollingCoordinator =
1336 scrollingCoordinatorFromLayer(m_owningLayer); 1365 scrollingCoordinatorFromLayer(m_owningLayer);
1337 if (!scrollingCoordinator) 1366 if (!scrollingCoordinator)
1338 return; 1367 return;
1339 1368
1340 scrollingCoordinator->updateLayerPositionConstraint(&m_owningLayer); 1369 scrollingCoordinator->updateLayerPositionConstraint(&m_owningLayer);
1341 1370
1342 // Page scale is applied as a transform on the root layout view layer. Because the scroll 1371 // Page scale is applied as a transform on the root layout view layer. Because
1343 // layer is further up in the hierarchy, we need to avoid marking the root lay out view 1372 // the scroll layer is further up in the hierarchy, we need to avoid marking
1344 // layer as a container. 1373 // the root layout view layer as a container.
1345 bool isContainer = 1374 bool isContainer =
1346 m_owningLayer.layoutObject()->style()->canContainFixedPositionObjects() && 1375 m_owningLayer.layoutObject()->style()->canContainFixedPositionObjects() &&
1347 !m_owningLayer.isRootLayer(); 1376 !m_owningLayer.isRootLayer();
1348 // FIXME: we should make certain that childForSuperLayers will never be the m_ squashingContainmentLayer here 1377 // FIXME: we should make certain that childForSuperLayers will never be the
1378 // m_squashingContainmentLayer here
1349 scrollingCoordinator->setLayerIsContainerForFixedPositionLayers( 1379 scrollingCoordinator->setLayerIsContainerForFixedPositionLayers(
1350 childForSuperlayers(), isContainer); 1380 childForSuperlayers(), isContainer);
1351 } 1381 }
1352 1382
1353 void CompositedLayerMapping::updateInternalHierarchy() { 1383 void CompositedLayerMapping::updateInternalHierarchy() {
1354 // m_foregroundLayer has to be inserted in the correct order with child layers , 1384 // m_foregroundLayer has to be inserted in the correct order with child
1355 // so it's not inserted here. 1385 // layers, so it's not inserted here.
1356 if (m_ancestorClippingLayer) 1386 if (m_ancestorClippingLayer)
1357 m_ancestorClippingLayer->removeAllChildren(); 1387 m_ancestorClippingLayer->removeAllChildren();
1358 1388
1359 m_graphicsLayer->removeFromParent(); 1389 m_graphicsLayer->removeFromParent();
1360 1390
1361 if (m_ancestorClippingLayer) 1391 if (m_ancestorClippingLayer)
1362 m_ancestorClippingLayer->addChild(m_graphicsLayer.get()); 1392 m_ancestorClippingLayer->addChild(m_graphicsLayer.get());
1363 1393
1364 // Layer to which children should be attached as we build the hierarchy. 1394 // Layer to which children should be attached as we build the hierarchy.
1365 GraphicsLayer* bottomLayer = m_graphicsLayer.get(); 1395 GraphicsLayer* bottomLayer = m_graphicsLayer.get();
1366 auto updateBottomLayer = [&bottomLayer](GraphicsLayer* layer) { 1396 auto updateBottomLayer = [&bottomLayer](GraphicsLayer* layer) {
1367 if (layer) { 1397 if (layer) {
1368 bottomLayer->addChild(layer); 1398 bottomLayer->addChild(layer);
1369 bottomLayer = layer; 1399 bottomLayer = layer;
1370 } 1400 }
1371 }; 1401 };
1372 1402
1373 updateBottomLayer(m_childTransformLayer.get()); 1403 updateBottomLayer(m_childTransformLayer.get());
1374 updateBottomLayer(m_childContainmentLayer.get()); 1404 updateBottomLayer(m_childContainmentLayer.get());
1375 updateBottomLayer(m_scrollingLayer.get()); 1405 updateBottomLayer(m_scrollingLayer.get());
1376 1406
1377 // Now constructing the subtree for the overflow controls. 1407 // Now constructing the subtree for the overflow controls.
1378 bottomLayer = m_graphicsLayer.get(); 1408 bottomLayer = m_graphicsLayer.get();
1379 // TODO(pdr): Ensure painting uses the correct GraphicsLayer when root layer s crolls is enabled. 1409 // TODO(pdr): Ensure painting uses the correct GraphicsLayer when root layer
1380 // crbug.com/638719 1410 // scrolls is enabled. crbug.com/638719
1381 if (m_isMainFrameLayoutViewLayer && 1411 if (m_isMainFrameLayoutViewLayer &&
1382 !RuntimeEnabledFeatures::slimmingPaintV2Enabled()) 1412 !RuntimeEnabledFeatures::slimmingPaintV2Enabled())
1383 bottomLayer = layoutObject() 1413 bottomLayer = layoutObject()
1384 ->frame() 1414 ->frame()
1385 ->page() 1415 ->page()
1386 ->frameHost() 1416 ->frameHost()
1387 .visualViewport() 1417 .visualViewport()
1388 .containerLayer(); 1418 .containerLayer();
1389 updateBottomLayer(m_overflowControlsAncestorClippingLayer.get()); 1419 updateBottomLayer(m_overflowControlsAncestorClippingLayer.get());
1390 updateBottomLayer(m_overflowControlsHostLayer.get()); 1420 updateBottomLayer(m_overflowControlsHostLayer.get());
1391 if (m_layerForHorizontalScrollbar) 1421 if (m_layerForHorizontalScrollbar)
1392 m_overflowControlsHostLayer->addChild(m_layerForHorizontalScrollbar.get()); 1422 m_overflowControlsHostLayer->addChild(m_layerForHorizontalScrollbar.get());
1393 if (m_layerForVerticalScrollbar) 1423 if (m_layerForVerticalScrollbar)
1394 m_overflowControlsHostLayer->addChild(m_layerForVerticalScrollbar.get()); 1424 m_overflowControlsHostLayer->addChild(m_layerForVerticalScrollbar.get());
1395 if (m_layerForScrollCorner) 1425 if (m_layerForScrollCorner)
1396 m_overflowControlsHostLayer->addChild(m_layerForScrollCorner.get()); 1426 m_overflowControlsHostLayer->addChild(m_layerForScrollCorner.get());
1397 1427
1398 // The squashing containment layer, if it exists, becomes a no-op parent. 1428 // The squashing containment layer, if it exists, becomes a no-op parent.
1399 if (m_squashingLayer) { 1429 if (m_squashingLayer) {
1400 ASSERT((m_ancestorClippingLayer && !m_squashingContainmentLayer) || 1430 ASSERT((m_ancestorClippingLayer && !m_squashingContainmentLayer) ||
1401 (!m_ancestorClippingLayer && m_squashingContainmentLayer)); 1431 (!m_ancestorClippingLayer && m_squashingContainmentLayer));
1402 1432
1403 if (m_squashingContainmentLayer) { 1433 if (m_squashingContainmentLayer) {
1404 m_squashingContainmentLayer->removeAllChildren(); 1434 m_squashingContainmentLayer->removeAllChildren();
1405 m_squashingContainmentLayer->addChild(m_graphicsLayer.get()); 1435 m_squashingContainmentLayer->addChild(m_graphicsLayer.get());
1406 m_squashingContainmentLayer->addChild(m_squashingLayer.get()); 1436 m_squashingContainmentLayer->addChild(m_squashingLayer.get());
1407 } else { 1437 } else {
1408 // The ancestor clipping layer is already set up and has m_graphicsLayer u nder it. 1438 // The ancestor clipping layer is already set up and has m_graphicsLayer
1439 // under it.
1409 m_ancestorClippingLayer->addChild(m_squashingLayer.get()); 1440 m_ancestorClippingLayer->addChild(m_squashingLayer.get());
1410 } 1441 }
1411 } 1442 }
1412 } 1443 }
1413 1444
1414 void CompositedLayerMapping::updatePaintingPhases() { 1445 void CompositedLayerMapping::updatePaintingPhases() {
1415 m_graphicsLayer->setPaintingPhase(paintingPhaseForPrimaryLayer()); 1446 m_graphicsLayer->setPaintingPhase(paintingPhaseForPrimaryLayer());
1416 if (m_scrollingContentsLayer) { 1447 if (m_scrollingContentsLayer) {
1417 GraphicsLayerPaintingPhase paintPhase = 1448 GraphicsLayerPaintingPhase paintPhase =
1418 GraphicsLayerPaintOverflowContents | GraphicsLayerPaintCompositedScroll; 1449 GraphicsLayerPaintOverflowContents | GraphicsLayerPaintCompositedScroll;
(...skipping 25 matching lines...) Expand all
1444 // Our ancestor graphics layers in this CLM (m_graphicsLayer and potentially 1475 // Our ancestor graphics layers in this CLM (m_graphicsLayer and potentially
1445 // m_ancestorClippingLayer) have pixel snapped, so if we don't adjust this 1476 // m_ancestorClippingLayer) have pixel snapped, so if we don't adjust this
1446 // offset, we'll see accumulated rounding errors due to that snapping. 1477 // offset, we'll see accumulated rounding errors due to that snapping.
1447 // 1478 //
1448 // In order to ensure that we account for this rounding, we compute 1479 // In order to ensure that we account for this rounding, we compute
1449 // contentsOffsetInCompositingLayer in a somewhat roundabout way. 1480 // contentsOffsetInCompositingLayer in a somewhat roundabout way.
1450 // 1481 //
1451 // our position = (desired position) - (inherited graphics layer offset). 1482 // our position = (desired position) - (inherited graphics layer offset).
1452 // 1483 //
1453 // Precisely, 1484 // Precisely,
1454 // Offset = snappedOffsetFromCompositedAncestor - offsetDueToAncestorGraphicsL ayers (See code below) 1485 // Offset = snappedOffsetFromCompositedAncestor -
1455 // = snappedOffsetFromCompositedAncestor - (m_graphicsLayer->position() + graphicsLayerParentLocation) 1486 // offsetDueToAncestorGraphicsLayers (See code below)
1456 // = snappedOffsetFromCompositedAncestor - (relativeCompositingBounds.loc ation() - graphicsLayerParentLocation + graphicsLayerParentLocation) (See update MainGraphicsLayerGeometry) 1487 // = snappedOffsetFromCompositedAncestor -
1457 // = snappedOffsetFromCompositedAncestor - relativeCompositingBounds.loca tion() 1488 // (m_graphicsLayer->position() + graphicsLayerParentLocation)
1458 // = snappedOffsetFromCompositedAncestor - (pixelSnappedIntRect(contentBo unds.location()) + snappedOffsetFromCompositedAncestor) (See computeBoundsOfOwni ngLayer) 1489 // = snappedOffsetFromCompositedAncestor -
1490 // (relativeCompositingBounds.location() -
1491 // graphicsLayerParentLocation +
1492 // graphicsLayerParentLocation)
1493 // (See updateMainGraphicsLayerGeometry)
1494 // = snappedOffsetFromCompositedAncestor -
1495 // relativeCompositingBounds.location()
1496 // = snappedOffsetFromCompositedAncestor -
1497 // (pixelSnappedIntRect(contentBounds.location()) +
1498 // snappedOffsetFromCompositedAncestor)
1499 // (See computeBoundsOfOwningLayer)
1459 // = -pixelSnappedIntRect(contentBounds.location()) 1500 // = -pixelSnappedIntRect(contentBounds.location())
1460 // 1501 //
1461 // As you can see, we've ended up at the same spot (-contentBounds.location()) , 1502 // As you can see, we've ended up at the same spot
1462 // but by subtracting off our ancestor graphics layers positions, we can be 1503 // (-contentBounds.location()), but by subtracting off our ancestor graphics
1463 // sure we've accounted correctly for any pixel snapping due to ancestor 1504 // layers positions, we can be sure we've accounted correctly for any pixel
1464 // graphics layers. 1505 // snapping due to ancestor graphics layers.
1465 // 1506 //
1466 // And drawing of composited children takes into account the subpixel 1507 // And drawing of composited children takes into account the subpixel
1467 // accumulation of this CLM already (through its own 1508 // accumulation of this CLM already (through its own
1468 // graphicsLayerParentLocation it appears). 1509 // graphicsLayerParentLocation it appears).
1469 FloatPoint offsetDueToAncestorGraphicsLayers = 1510 FloatPoint offsetDueToAncestorGraphicsLayers =
1470 m_graphicsLayer->position() + graphicsLayerParentLocation; 1511 m_graphicsLayer->position() + graphicsLayerParentLocation;
1471 m_contentOffsetInCompositingLayer = LayoutSize( 1512 m_contentOffsetInCompositingLayer = LayoutSize(
1472 snappedOffsetFromCompositedAncestor - offsetDueToAncestorGraphicsLayers); 1513 snappedOffsetFromCompositedAncestor - offsetDueToAncestorGraphicsLayers);
1473 m_contentOffsetInCompositingLayerDirty = false; 1514 m_contentOffsetInCompositingLayerDirty = false;
1474 } 1515 }
1475 1516
1476 void CompositedLayerMapping::updateDrawsContent() { 1517 void CompositedLayerMapping::updateDrawsContent() {
1477 bool inOverlayFullscreenVideo = false; 1518 bool inOverlayFullscreenVideo = false;
1478 if (layoutObject()->isVideo()) { 1519 if (layoutObject()->isVideo()) {
1479 HTMLVideoElement* videoElement = toHTMLVideoElement(layoutObject()->node()); 1520 HTMLVideoElement* videoElement = toHTMLVideoElement(layoutObject()->node());
1480 if (videoElement->isFullscreen() && 1521 if (videoElement->isFullscreen() &&
1481 videoElement->usesOverlayFullscreenVideo()) 1522 videoElement->usesOverlayFullscreenVideo())
1482 inOverlayFullscreenVideo = true; 1523 inOverlayFullscreenVideo = true;
1483 } 1524 }
1484 bool hasPaintedContent = 1525 bool hasPaintedContent =
1485 inOverlayFullscreenVideo ? false : containsPaintedContent(); 1526 inOverlayFullscreenVideo ? false : containsPaintedContent();
1486 m_graphicsLayer->setDrawsContent(hasPaintedContent); 1527 m_graphicsLayer->setDrawsContent(hasPaintedContent);
1487 1528
1488 if (m_scrollingLayer) { 1529 if (m_scrollingLayer) {
1489 // m_scrollingLayer never has backing store. 1530 // m_scrollingLayer never has backing store.
1490 // m_scrollingContentsLayer only needs backing store if the scrolled content s need to paint. 1531 // m_scrollingContentsLayer only needs backing store if the scrolled
1532 // contents need to paint.
1491 m_scrollingContentsAreEmpty = 1533 m_scrollingContentsAreEmpty =
1492 !m_owningLayer.hasVisibleContent() || 1534 !m_owningLayer.hasVisibleContent() ||
1493 !(layoutObject()->styleRef().hasBackground() || 1535 !(layoutObject()->styleRef().hasBackground() ||
1494 layoutObject()->hasBackdropFilter() || paintsChildren()); 1536 layoutObject()->hasBackdropFilter() || paintsChildren());
1495 m_scrollingContentsLayer->setDrawsContent(!m_scrollingContentsAreEmpty); 1537 m_scrollingContentsLayer->setDrawsContent(!m_scrollingContentsAreEmpty);
1496 } 1538 }
1497 1539
1498 if (hasPaintedContent && isAcceleratedCanvas(layoutObject())) { 1540 if (hasPaintedContent && isAcceleratedCanvas(layoutObject())) {
1499 CanvasRenderingContext* context = 1541 CanvasRenderingContext* context =
1500 toHTMLCanvasElement(layoutObject()->node())->renderingContext(); 1542 toHTMLCanvasElement(layoutObject()->node())->renderingContext();
1501 // Content layer may be null if context is lost. 1543 // Content layer may be null if context is lost.
1502 if (WebLayer* contentLayer = context->platformLayer()) { 1544 if (WebLayer* contentLayer = context->platformLayer()) {
1503 Color bgColor(Color::transparent); 1545 Color bgColor(Color::transparent);
1504 if (contentLayerSupportsDirectBackgroundComposition(layoutObject())) { 1546 if (contentLayerSupportsDirectBackgroundComposition(layoutObject())) {
1505 bgColor = layoutObjectBackgroundColor(); 1547 bgColor = layoutObjectBackgroundColor();
1506 hasPaintedContent = false; 1548 hasPaintedContent = false;
1507 } 1549 }
1508 contentLayer->setBackgroundColor(bgColor.rgb()); 1550 contentLayer->setBackgroundColor(bgColor.rgb());
1509 } 1551 }
1510 } 1552 }
1511 1553
1512 // FIXME: we could refine this to only allocate backings for one of these laye rs if possible. 1554 // FIXME: we could refine this to only allocate backings for one of these
1555 // layers if possible.
1513 if (m_foregroundLayer) 1556 if (m_foregroundLayer)
1514 m_foregroundLayer->setDrawsContent(hasPaintedContent); 1557 m_foregroundLayer->setDrawsContent(hasPaintedContent);
1515 1558
1516 if (m_backgroundLayer) 1559 if (m_backgroundLayer)
1517 m_backgroundLayer->setDrawsContent(hasPaintedContent); 1560 m_backgroundLayer->setDrawsContent(hasPaintedContent);
1518 1561
1519 if (m_maskLayer) 1562 if (m_maskLayer)
1520 m_maskLayer->setDrawsContent(true); 1563 m_maskLayer->setDrawsContent(true);
1521 1564
1522 if (m_childClippingMaskLayer) 1565 if (m_childClippingMaskLayer)
(...skipping 22 matching lines...) Expand all
1545 m_ancestorClippingLayer->setShouldFlattenTransform(false); 1588 m_ancestorClippingLayer->setShouldFlattenTransform(false);
1546 layersChanged = true; 1589 layersChanged = true;
1547 } 1590 }
1548 } else if (m_ancestorClippingLayer) { 1591 } else if (m_ancestorClippingLayer) {
1549 m_ancestorClippingLayer->removeFromParent(); 1592 m_ancestorClippingLayer->removeFromParent();
1550 m_ancestorClippingLayer = nullptr; 1593 m_ancestorClippingLayer = nullptr;
1551 layersChanged = true; 1594 layersChanged = true;
1552 } 1595 }
1553 1596
1554 if (needsDescendantClip) { 1597 if (needsDescendantClip) {
1555 // We don't need a child containment layer if we're the main frame layout vi ew 1598 // We don't need a child containment layer if we're the main frame layout
1556 // layer. It's redundant as the frame clip above us will handle this clippin g. 1599 // view layer. It's redundant as the frame clip above us will handle this
1600 // clipping.
1557 if (!m_childContainmentLayer && !m_isMainFrameLayoutViewLayer) { 1601 if (!m_childContainmentLayer && !m_isMainFrameLayoutViewLayer) {
1558 m_childContainmentLayer = 1602 m_childContainmentLayer =
1559 createGraphicsLayer(CompositingReasonLayerForDescendantClip); 1603 createGraphicsLayer(CompositingReasonLayerForDescendantClip);
1560 m_childContainmentLayer->setMasksToBounds(true); 1604 m_childContainmentLayer->setMasksToBounds(true);
1561 layersChanged = true; 1605 layersChanged = true;
1562 } 1606 }
1563 } else if (hasClippingLayer()) { 1607 } else if (hasClippingLayer()) {
1564 m_childContainmentLayer->removeFromParent(); 1608 m_childContainmentLayer->removeFromParent();
1565 m_childContainmentLayer = nullptr; 1609 m_childContainmentLayer = nullptr;
1566 layersChanged = true; 1610 layersChanged = true;
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 } 1829 }
1786 1830
1787 struct UpdateRenderingContextFunctor { 1831 struct UpdateRenderingContextFunctor {
1788 void operator()(GraphicsLayer* layer) const { 1832 void operator()(GraphicsLayer* layer) const {
1789 layer->setRenderingContext(renderingContext); 1833 layer->setRenderingContext(renderingContext);
1790 } 1834 }
1791 int renderingContext; 1835 int renderingContext;
1792 }; 1836 };
1793 1837
1794 void CompositedLayerMapping::updateRenderingContext() { 1838 void CompositedLayerMapping::updateRenderingContext() {
1795 // All layers but the squashing layer (which contains 'alien' content) should be included in this 1839 // All layers but the squashing layer (which contains 'alien' content) should
1796 // rendering context. 1840 // be included in this rendering context.
1797 int id = 0; 1841 int id = 0;
1798 1842
1799 // NB, it is illegal at this point to query an ancestor's compositing state. S ome compositing 1843 // NB, it is illegal at this point to query an ancestor's compositing state.
1800 // reasons depend on the compositing state of ancestors. So if we want a rende ring context id 1844 // Some compositing reasons depend on the compositing state of ancestors. So
1801 // for the context root, we cannot ask for the id of its associated WebLayer n ow; it may not have 1845 // if we want a rendering context id for the context root, we cannot ask for
1802 // one yet. We could do a second past after doing the compositing updates to g et these ids, 1846 // the id of its associated WebLayer now; it may not have one yet. We could do
1803 // but this would actually be harmful. We do not want to attach any semantic m eaning to 1847 // a second past after doing the compositing updates to get these ids, but
1804 // the context id other than the fact that they group a number of layers toget her for the 1848 // this would actually be harmful. We do not want to attach any semantic
1805 // sake of 3d sorting. So instead we will ask the compositor to vend us an arb itrary, but 1849 // meaning to the context id other than the fact that they group a number of
1806 // consistent id. 1850 // layers together for the sake of 3d sorting. So instead we will ask the
1851 // compositor to vend us an arbitrary, but consistent id.
1807 if (PaintLayer* root = m_owningLayer.renderingContextRoot()) { 1852 if (PaintLayer* root = m_owningLayer.renderingContextRoot()) {
1808 if (Node* node = root->layoutObject()->node()) 1853 if (Node* node = root->layoutObject()->node())
1809 id = static_cast<int>(PtrHash<Node>::hash(node)); 1854 id = static_cast<int>(PtrHash<Node>::hash(node));
1810 } 1855 }
1811 1856
1812 UpdateRenderingContextFunctor functor = {id}; 1857 UpdateRenderingContextFunctor functor = {id};
1813 ApplyToGraphicsLayers<UpdateRenderingContextFunctor>( 1858 ApplyToGraphicsLayers<UpdateRenderingContextFunctor>(
1814 this, functor, ApplyToAllGraphicsLayers); 1859 this, functor, ApplyToAllGraphicsLayers);
1815 } 1860 }
1816 1861
1817 struct UpdateShouldFlattenTransformFunctor { 1862 struct UpdateShouldFlattenTransformFunctor {
1818 void operator()(GraphicsLayer* layer) const { 1863 void operator()(GraphicsLayer* layer) const {
1819 layer->setShouldFlattenTransform(shouldFlatten); 1864 layer->setShouldFlattenTransform(shouldFlatten);
1820 } 1865 }
1821 bool shouldFlatten; 1866 bool shouldFlatten;
1822 }; 1867 };
1823 1868
1824 void CompositedLayerMapping::updateShouldFlattenTransform() { 1869 void CompositedLayerMapping::updateShouldFlattenTransform() {
1825 // All CLM-managed layers that could affect a descendant layer should update t heir 1870 // All CLM-managed layers that could affect a descendant layer should update
1826 // should-flatten-transform value (the other layers' transforms don't matter h ere). 1871 // their should-flatten-transform value (the other layers' transforms don't
1872 // matter here).
1827 UpdateShouldFlattenTransformFunctor functor = { 1873 UpdateShouldFlattenTransformFunctor functor = {
1828 !m_owningLayer.shouldPreserve3D()}; 1874 !m_owningLayer.shouldPreserve3D()};
1829 ApplyToGraphicsLayersMode mode = ApplyToLayersAffectedByPreserve3D; 1875 ApplyToGraphicsLayersMode mode = ApplyToLayersAffectedByPreserve3D;
1830 ApplyToGraphicsLayers(this, functor, mode); 1876 ApplyToGraphicsLayers(this, functor, mode);
1831 1877
1832 // Note, if we apply perspective, we have to set should flatten differently 1878 // Note, if we apply perspective, we have to set should flatten differently
1833 // so that the transform propagates to child layers correctly. 1879 // so that the transform propagates to child layers correctly.
1834 if (hasChildTransformLayer()) { 1880 if (hasChildTransformLayer()) {
1835 ApplyToGraphicsLayers( 1881 ApplyToGraphicsLayers(
1836 this, 1882 this,
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 } 2081 }
2036 2082
2037 static void updateScrollParentForGraphicsLayer( 2083 static void updateScrollParentForGraphicsLayer(
2038 GraphicsLayer* layer, 2084 GraphicsLayer* layer,
2039 GraphicsLayer* topmostLayer, 2085 GraphicsLayer* topmostLayer,
2040 const PaintLayer* scrollParent, 2086 const PaintLayer* scrollParent,
2041 ScrollingCoordinator* scrollingCoordinator) { 2087 ScrollingCoordinator* scrollingCoordinator) {
2042 if (!layer) 2088 if (!layer)
2043 return; 2089 return;
2044 2090
2045 // Only the topmost layer has a scroll parent. All other layers have a null sc roll parent. 2091 // Only the topmost layer has a scroll parent. All other layers have a null
2092 // scroll parent.
2046 if (layer != topmostLayer) 2093 if (layer != topmostLayer)
2047 scrollParent = 0; 2094 scrollParent = 0;
2048 2095
2049 scrollingCoordinator->updateScrollParentForGraphicsLayer(layer, scrollParent); 2096 scrollingCoordinator->updateScrollParentForGraphicsLayer(layer, scrollParent);
2050 } 2097 }
2051 2098
2052 void CompositedLayerMapping::updateScrollParent( 2099 void CompositedLayerMapping::updateScrollParent(
2053 const PaintLayer* scrollParent) { 2100 const PaintLayer* scrollParent) {
2054 if (ScrollingCoordinator* scrollingCoordinator = 2101 if (ScrollingCoordinator* scrollingCoordinator =
2055 scrollingCoordinatorFromLayer(m_owningLayer)) { 2102 scrollingCoordinatorFromLayer(m_owningLayer)) {
(...skipping 10 matching lines...) Expand all
2066 } 2113 }
2067 2114
2068 static void updateClipParentForGraphicsLayer( 2115 static void updateClipParentForGraphicsLayer(
2069 GraphicsLayer* layer, 2116 GraphicsLayer* layer,
2070 GraphicsLayer* topmostLayer, 2117 GraphicsLayer* topmostLayer,
2071 const PaintLayer* clipParent, 2118 const PaintLayer* clipParent,
2072 ScrollingCoordinator* scrollingCoordinator) { 2119 ScrollingCoordinator* scrollingCoordinator) {
2073 if (!layer) 2120 if (!layer)
2074 return; 2121 return;
2075 2122
2076 // Only the topmost layer has a scroll parent. All other layers have a null sc roll parent. 2123 // Only the topmost layer has a scroll parent. All other layers have a null
2124 // scroll parent.
2077 if (layer != topmostLayer) 2125 if (layer != topmostLayer)
2078 clipParent = 0; 2126 clipParent = 0;
2079 2127
2080 scrollingCoordinator->updateClipParentForGraphicsLayer(layer, clipParent); 2128 scrollingCoordinator->updateClipParentForGraphicsLayer(layer, clipParent);
2081 } 2129 }
2082 2130
2083 void CompositedLayerMapping::updateClipParent(const PaintLayer* scrollParent) { 2131 void CompositedLayerMapping::updateClipParent(const PaintLayer* scrollParent) {
2084 const PaintLayer* clipParent = nullptr; 2132 const PaintLayer* clipParent = nullptr;
2085 if (!owningLayerClippedByLayerNotAboveCompositedAncestor(scrollParent)) { 2133 if (!owningLayerClippedByLayerNotAboveCompositedAncestor(scrollParent)) {
2086 clipParent = m_owningLayer.clipParent(); 2134 clipParent = m_owningLayer.clipParent();
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 } 2291 }
2244 2292
2245 return false; 2293 return false;
2246 } 2294 }
2247 2295
2248 bool CompositedLayerMapping::containsPaintedContent() const { 2296 bool CompositedLayerMapping::containsPaintedContent() const {
2249 if (layoutObject()->isImage() && isDirectlyCompositedImage()) 2297 if (layoutObject()->isImage() && isDirectlyCompositedImage())
2250 return false; 2298 return false;
2251 2299
2252 LayoutObject* layoutObject = this->layoutObject(); 2300 LayoutObject* layoutObject = this->layoutObject();
2253 // FIXME: we could optimize cases where the image, video or canvas is known to fill the border box entirely, 2301 // FIXME: we could optimize cases where the image, video or canvas is known to
2254 // and set background color on the layer in that case, instead of allocating b acking store and painting. 2302 // fill the border box entirely, and set background color on the layer in that
2303 // case, instead of allocating backing store and painting.
2255 if (layoutObject->isVideo() && 2304 if (layoutObject->isVideo() &&
2256 toLayoutVideo(layoutObject)->shouldDisplayVideo()) 2305 toLayoutVideo(layoutObject)->shouldDisplayVideo())
2257 return m_owningLayer.hasBoxDecorationsOrBackground(); 2306 return m_owningLayer.hasBoxDecorationsOrBackground();
2258 2307
2259 if (m_owningLayer.hasVisibleBoxDecorations()) 2308 if (m_owningLayer.hasVisibleBoxDecorations())
2260 return true; 2309 return true;
2261 2310
2262 if (layoutObject->hasMask()) // masks require special treatment 2311 if (layoutObject->hasMask()) // masks require special treatment
2263 return true; 2312 return true;
2264 2313
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2349 image, LayoutObject::shouldRespectImageOrientation(imageLayoutObject)); 2398 image, LayoutObject::shouldRespectImageOrientation(imageLayoutObject));
2350 2399
2351 m_graphicsLayer->setFilterQuality(layoutObject()->style()->imageRendering() == 2400 m_graphicsLayer->setFilterQuality(layoutObject()->style()->imageRendering() ==
2352 ImageRenderingPixelated 2401 ImageRenderingPixelated
2353 ? kNone_SkFilterQuality 2402 ? kNone_SkFilterQuality
2354 : kLow_SkFilterQuality); 2403 : kLow_SkFilterQuality);
2355 2404
2356 // Prevent double-drawing: https://bugs.webkit.org/show_bug.cgi?id=58632 2405 // Prevent double-drawing: https://bugs.webkit.org/show_bug.cgi?id=58632
2357 updateDrawsContent(); 2406 updateDrawsContent();
2358 2407
2359 // Image animation is "lazy", in that it automatically stops unless someone is drawing 2408 // Image animation is "lazy", in that it automatically stops unless someone is
2360 // the image. So we have to kick the animation each time; this has the downsid e that the 2409 // drawing the image. So we have to kick the animation each time; this has the
2361 // image will keep animating, even if its layer is not visible. 2410 // downside that the image will keep animating, even if its layer is not
2411 // visible.
2362 image->startAnimation(); 2412 image->startAnimation();
2363 } 2413 }
2364 2414
2365 FloatPoint3D CompositedLayerMapping::computeTransformOrigin( 2415 FloatPoint3D CompositedLayerMapping::computeTransformOrigin(
2366 const IntRect& borderBox) const { 2416 const IntRect& borderBox) const {
2367 const ComputedStyle& style = layoutObject()->styleRef(); 2417 const ComputedStyle& style = layoutObject()->styleRef();
2368 2418
2369 FloatPoint3D origin; 2419 FloatPoint3D origin;
2370 origin.setX(floatValueForLength(style.transformOriginX(), borderBox.width())); 2420 origin.setX(floatValueForLength(style.transformOriginX(), borderBox.width()));
2371 origin.setY( 2421 origin.setY(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2422 m_overflowControlsAncestorClippingLayer 2472 m_overflowControlsAncestorClippingLayer
2423 ? m_overflowControlsAncestorClippingLayer.get() 2473 ? m_overflowControlsAncestorClippingLayer.get()
2424 : m_overflowControlsHostLayer.get(); 2474 : m_overflowControlsHostLayer.get();
2425 GraphicsLayer* parent = parentForSublayers(); 2475 GraphicsLayer* parent = parentForSublayers();
2426 bool needsOverflowControlsReattached = 2476 bool needsOverflowControlsReattached =
2427 overflowControlsContainer && 2477 overflowControlsContainer &&
2428 overflowControlsContainer->parent() == parent; 2478 overflowControlsContainer->parent() == parent;
2429 2479
2430 parent->setChildren(sublayers); 2480 parent->setChildren(sublayers);
2431 2481
2432 // If we have scrollbars, but are not using composited scrolling, then parentF orSublayers may return m_graphicsLayer. 2482 // If we have scrollbars, but are not using composited scrolling, then
2433 // In that case, the above call to setChildren has clobbered the overflow cont rols host layer, so we need to reattach it. 2483 // parentForSublayers may return m_graphicsLayer. In that case, the above
2484 // call to setChildren has clobbered the overflow controls host layer, so we
2485 // need to reattach it.
2434 if (needsOverflowControlsReattached) 2486 if (needsOverflowControlsReattached)
2435 parent->addChild(overflowControlsContainer); 2487 parent->addChild(overflowControlsContainer);
2436 } 2488 }
2437 2489
2438 GraphicsLayer* CompositedLayerMapping::childForSuperlayers() const { 2490 GraphicsLayer* CompositedLayerMapping::childForSuperlayers() const {
2439 if (m_squashingContainmentLayer) 2491 if (m_squashingContainmentLayer)
2440 return m_squashingContainmentLayer.get(); 2492 return m_squashingContainmentLayer.get();
2441 2493
2442 if (m_ancestorClippingLayer) 2494 if (m_ancestorClippingLayer)
2443 return m_ancestorClippingLayer.get(); 2495 return m_ancestorClippingLayer.get();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 IntRect r; 2543 IntRect r;
2492 PaintInvalidationReason invalidationReason; 2544 PaintInvalidationReason invalidationReason;
2493 const DisplayItemClient& client; 2545 const DisplayItemClient& client;
2494 }; 2546 };
2495 2547
2496 void CompositedLayerMapping::setContentsNeedDisplayInRect( 2548 void CompositedLayerMapping::setContentsNeedDisplayInRect(
2497 const LayoutRect& r, 2549 const LayoutRect& r,
2498 PaintInvalidationReason invalidationReason, 2550 PaintInvalidationReason invalidationReason,
2499 const DisplayItemClient& client) { 2551 const DisplayItemClient& client) {
2500 DCHECK(!m_owningLayer.layoutObject()->usesCompositedScrolling()); 2552 DCHECK(!m_owningLayer.layoutObject()->usesCompositedScrolling());
2501 // TODO(wangxianzhu): Enable the following assert after paint invalidation for spv2 is ready. 2553 // TODO(wangxianzhu): Enable the following assert after paint invalidation for
2554 // spv2 is ready.
2502 // ASSERT(!RuntimeEnabledFeatures::slimmingPaintV2Enabled()); 2555 // ASSERT(!RuntimeEnabledFeatures::slimmingPaintV2Enabled());
2503 2556
2504 SetContentsNeedsDisplayInRectFunctor functor = { 2557 SetContentsNeedsDisplayInRectFunctor functor = {
2505 enclosingIntRect(LayoutRect( 2558 enclosingIntRect(LayoutRect(
2506 r.location() + m_owningLayer.subpixelAccumulation(), r.size())), 2559 r.location() + m_owningLayer.subpixelAccumulation(), r.size())),
2507 invalidationReason, client}; 2560 invalidationReason, client};
2508 ApplyToGraphicsLayers(this, functor, ApplyToContentLayers); 2561 ApplyToGraphicsLayers(this, functor, ApplyToContentLayers);
2509 } 2562 }
2510 2563
2511 void CompositedLayerMapping::setNonScrollingContentsNeedDisplayInRect( 2564 void CompositedLayerMapping::setNonScrollingContentsNeedDisplayInRect(
2512 const LayoutRect& r, 2565 const LayoutRect& r,
2513 PaintInvalidationReason invalidationReason, 2566 PaintInvalidationReason invalidationReason,
2514 const DisplayItemClient& client) { 2567 const DisplayItemClient& client) {
2515 DCHECK(m_owningLayer.layoutObject()->usesCompositedScrolling()); 2568 DCHECK(m_owningLayer.layoutObject()->usesCompositedScrolling());
2516 // TODO(wangxianzhu): Enable the following assert after paint invalidation for spv2 is ready. 2569 // TODO(wangxianzhu): Enable the following assert after paint invalidation for
2570 // spv2 is ready.
2517 // ASSERT(!RuntimeEnabledFeatures::slimmingPaintV2Enabled()); 2571 // ASSERT(!RuntimeEnabledFeatures::slimmingPaintV2Enabled());
2518 2572
2519 SetContentsNeedsDisplayInRectFunctor functor = { 2573 SetContentsNeedsDisplayInRectFunctor functor = {
2520 enclosingIntRect(LayoutRect( 2574 enclosingIntRect(LayoutRect(
2521 r.location() + m_owningLayer.subpixelAccumulation(), r.size())), 2575 r.location() + m_owningLayer.subpixelAccumulation(), r.size())),
2522 invalidationReason, client}; 2576 invalidationReason, client};
2523 ApplyToGraphicsLayers(this, functor, ApplyToNonScrollingContentLayers); 2577 ApplyToGraphicsLayers(this, functor, ApplyToNonScrollingContentLayers);
2524 } 2578 }
2525 2579
2526 void CompositedLayerMapping::setScrollingContentsNeedDisplayInRect( 2580 void CompositedLayerMapping::setScrollingContentsNeedDisplayInRect(
2527 const LayoutRect& r, 2581 const LayoutRect& r,
2528 PaintInvalidationReason invalidationReason, 2582 PaintInvalidationReason invalidationReason,
2529 const DisplayItemClient& client) { 2583 const DisplayItemClient& client) {
2530 DCHECK(m_owningLayer.layoutObject()->usesCompositedScrolling()); 2584 DCHECK(m_owningLayer.layoutObject()->usesCompositedScrolling());
2531 // TODO(wangxianzhu): Enable the following assert after paint invalidation for spv2 is ready. 2585 // TODO(wangxianzhu): Enable the following assert after paint invalidation for
2586 // spv2 is ready.
2532 // ASSERT(!RuntimeEnabledFeatures::slimmingPaintV2Enabled()); 2587 // ASSERT(!RuntimeEnabledFeatures::slimmingPaintV2Enabled());
2533 2588
2534 SetContentsNeedsDisplayInRectFunctor functor = { 2589 SetContentsNeedsDisplayInRectFunctor functor = {
2535 enclosingIntRect(LayoutRect( 2590 enclosingIntRect(LayoutRect(
2536 r.location() + m_owningLayer.subpixelAccumulation(), r.size())), 2591 r.location() + m_owningLayer.subpixelAccumulation(), r.size())),
2537 invalidationReason, client}; 2592 invalidationReason, client};
2538 ApplyToGraphicsLayers(this, functor, ApplyToScrollingContentLayers); 2593 ApplyToGraphicsLayers(this, functor, ApplyToScrollingContentLayers);
2539 } 2594 }
2540 2595
2541 const GraphicsLayerPaintInfo* CompositedLayerMapping::containingSquashedLayer( 2596 const GraphicsLayerPaintInfo* CompositedLayerMapping::containingSquashedLayer(
(...skipping 20 matching lines...) Expand all
2562 const Vector<GraphicsLayerPaintInfo>& layers) { 2617 const Vector<GraphicsLayerPaintInfo>& layers) {
2563 const LayoutObject* clippingContainer = 2618 const LayoutObject* clippingContainer =
2564 paintInfo.paintLayer->clippingContainer(); 2619 paintInfo.paintLayer->clippingContainer();
2565 if (clippingContainer == referenceLayer.clippingContainer()) 2620 if (clippingContainer == referenceLayer.clippingContainer())
2566 return LayoutRect::infiniteIntRect(); 2621 return LayoutRect::infiniteIntRect();
2567 2622
2568 ASSERT(clippingContainer); 2623 ASSERT(clippingContainer);
2569 2624
2570 const GraphicsLayerPaintInfo* ancestorPaintInfo = 2625 const GraphicsLayerPaintInfo* ancestorPaintInfo =
2571 containingSquashedLayer(clippingContainer, layers, layers.size()); 2626 containingSquashedLayer(clippingContainer, layers, layers.size());
2572 // Must be there, otherwise CompositingLayerAssigner::canSquashIntoCurrentSqua shingOwner would have disallowed squashing. 2627 // Must be there, otherwise
2628 // CompositingLayerAssigner::canSquashIntoCurrentSquashingOwner would have
2629 // disallowed squashing.
2573 ASSERT(ancestorPaintInfo); 2630 ASSERT(ancestorPaintInfo);
2574 2631
2575 // FIXME: this is a potential performance issue. We should consider caching th ese clip rects or otherwise optimizing. 2632 // FIXME: this is a potential performance issue. We should consider caching
2633 // these clip rects or otherwise optimizing.
2576 ClipRectsContext clipRectsContext(ancestorPaintInfo->paintLayer, 2634 ClipRectsContext clipRectsContext(ancestorPaintInfo->paintLayer,
2577 UncachedClipRects); 2635 UncachedClipRects);
2578 IntRect parentClipRect = 2636 IntRect parentClipRect =
2579 pixelSnappedIntRect(paintInfo.paintLayer->clipper() 2637 pixelSnappedIntRect(paintInfo.paintLayer->clipper()
2580 .backgroundClipRect(clipRectsContext) 2638 .backgroundClipRect(clipRectsContext)
2581 .rect()); 2639 .rect());
2582 ASSERT(parentClipRect != LayoutRect::infiniteIntRect()); 2640 ASSERT(parentClipRect != LayoutRect::infiniteIntRect());
2583 2641
2584 // Convert from ancestor to local coordinates. 2642 // Convert from ancestor to local coordinates.
2585 IntSize ancestorToLocalOffset = paintInfo.offsetFromLayoutObject - 2643 IntSize ancestorToLocalOffset = paintInfo.offsetFromLayoutObject -
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2635 if (paintInfo.paintLayer->containsDirtyOverlayScrollbars()) 2693 if (paintInfo.paintLayer->containsDirtyOverlayScrollbars())
2636 PaintLayerPainter(*paintInfo.paintLayer) 2694 PaintLayerPainter(*paintInfo.paintLayer)
2637 .paintLayerContents( 2695 .paintLayerContents(
2638 context, paintingInfo, 2696 context, paintingInfo,
2639 paintLayerFlags | PaintLayerPaintingOverlayScrollbars); 2697 paintLayerFlags | PaintLayerPaintingOverlayScrollbars);
2640 } else { 2698 } else {
2641 PaintLayerPaintingInfo paintingInfo( 2699 PaintLayerPaintingInfo paintingInfo(
2642 paintInfo.paintLayer, LayoutRect(dirtyRect), GlobalPaintNormalPhase, 2700 paintInfo.paintLayer, LayoutRect(dirtyRect), GlobalPaintNormalPhase,
2643 paintInfo.paintLayer->subpixelAccumulation()); 2701 paintInfo.paintLayer->subpixelAccumulation());
2644 2702
2645 // PaintLayer::paintLayer assumes that the caller clips to the passed rect. Squashed layers need to do this clipping in software, 2703 // PaintLayer::paintLayer assumes that the caller clips to the passed rect.
2646 // since there is no graphics layer to clip them precisely. Furthermore, in some cases we squash layers that need clipping in software 2704 // Squashed layers need to do this clipping in software, since there is no
2647 // from clipping ancestors (see CompositedLayerMapping::localClipRectForSqua shedLayer()). 2705 // graphics layer to clip them precisely. Furthermore, in some cases we
2706 // squash layers that need clipping in software from clipping ancestors (see
2707 // CompositedLayerMapping::localClipRectForSquashedLayer()).
2648 // FIXME: Is it correct to clip to dirtyRect in slimming paint mode? 2708 // FIXME: Is it correct to clip to dirtyRect in slimming paint mode?
2649 // FIXME: Combine similar code here and LayerClipRecorder. 2709 // FIXME: Combine similar code here and LayerClipRecorder.
2650 dirtyRect.intersect(paintInfo.localClipRectForSquashedLayer); 2710 dirtyRect.intersect(paintInfo.localClipRectForSquashedLayer);
2651 context.getPaintController().createAndAppend<ClipDisplayItem>( 2711 context.getPaintController().createAndAppend<ClipDisplayItem>(
2652 graphicsLayer, DisplayItem::kClipLayerOverflowControls, dirtyRect); 2712 graphicsLayer, DisplayItem::kClipLayerOverflowControls, dirtyRect);
2653 2713
2654 PaintLayerPainter(*paintInfo.paintLayer) 2714 PaintLayerPainter(*paintInfo.paintLayer)
2655 .paintLayer(context, paintingInfo, paintLayerFlags); 2715 .paintLayer(context, paintingInfo, paintLayerFlags);
2656 context.getPaintController().endItem<EndClipDisplayItem>( 2716 context.getPaintController().endItem<EndClipDisplayItem>(
2657 graphicsLayer, DisplayItem::clipTypeToEndClipType( 2717 graphicsLayer, DisplayItem::clipTypeToEndClipType(
(...skipping 20 matching lines...) Expand all
2678 // headless, where we would like to record an exact area (distance = 0). 2738 // headless, where we would like to record an exact area (distance = 0).
2679 static const int kPixelDistanceToRecord = 4000; 2739 static const int kPixelDistanceToRecord = 4000;
2680 2740
2681 IntRect CompositedLayerMapping::recomputeInterestRect( 2741 IntRect CompositedLayerMapping::recomputeInterestRect(
2682 const GraphicsLayer* graphicsLayer) const { 2742 const GraphicsLayer* graphicsLayer) const {
2683 FloatRect graphicsLayerBounds(FloatPoint(), graphicsLayer->size()); 2743 FloatRect graphicsLayerBounds(FloatPoint(), graphicsLayer->size());
2684 2744
2685 IntSize offsetFromAnchorLayoutObject; 2745 IntSize offsetFromAnchorLayoutObject;
2686 const LayoutBoxModelObject* anchorLayoutObject; 2746 const LayoutBoxModelObject* anchorLayoutObject;
2687 if (graphicsLayer == m_squashingLayer.get()) { 2747 if (graphicsLayer == m_squashingLayer.get()) {
2688 // TODO(chrishtr): this is a speculative fix for crbug.com/561306. However, it should never be the case that 2748 // TODO(chrishtr): this is a speculative fix for crbug.com/561306. However,
2689 // m_squashingLayer exists yet m_squashedLayers.size() == 0. There must be a bug elsewhere. 2749 // it should never be the case that m_squashingLayer exists,
2750 // yet m_squashedLayers.size() == 0. There must be a bug elsewhere.
2690 if (m_squashedLayers.size() == 0) 2751 if (m_squashedLayers.size() == 0)
2691 return IntRect(); 2752 return IntRect();
2692 // All squashed layers have the same clip and transform space, so we can use the first squashed layer's 2753 // All squashed layers have the same clip and transform space, so we can use
2693 // layoutObject to map the squashing layer's bounds into viewport space, wit h offsetFromAnchorLayoutObject 2754 // the first squashed layer's layoutObject to map the squashing layer's
2694 // to translate squashing layer's bounds into the first squashed layer's spa ce. 2755 // bounds into viewport space, with offsetFromAnchorLayoutObject to
2756 // translate squashing layer's bounds into the first squashed layer's space.
2695 anchorLayoutObject = m_squashedLayers[0].paintLayer->layoutObject(); 2757 anchorLayoutObject = m_squashedLayers[0].paintLayer->layoutObject();
2696 offsetFromAnchorLayoutObject = m_squashedLayers[0].offsetFromLayoutObject; 2758 offsetFromAnchorLayoutObject = m_squashedLayers[0].offsetFromLayoutObject;
2697 } else { 2759 } else {
2698 ASSERT(graphicsLayer == m_graphicsLayer.get() || 2760 ASSERT(graphicsLayer == m_graphicsLayer.get() ||
2699 graphicsLayer == m_scrollingContentsLayer.get()); 2761 graphicsLayer == m_scrollingContentsLayer.get());
2700 anchorLayoutObject = m_owningLayer.layoutObject(); 2762 anchorLayoutObject = m_owningLayer.layoutObject();
2701 offsetFromAnchorLayoutObject = graphicsLayer->offsetFromLayoutObject(); 2763 offsetFromAnchorLayoutObject = graphicsLayer->offsetFromLayoutObject();
2702 adjustForCompositedScrolling(graphicsLayer, offsetFromAnchorLayoutObject); 2764 adjustForCompositedScrolling(graphicsLayer, offsetFromAnchorLayoutObject);
2703 } 2765 }
2704 2766
2705 // Start with the bounds of the graphics layer in the space of the anchor Layo utObject. 2767 // Start with the bounds of the graphics layer in the space of the anchor
2768 // LayoutObject.
2706 FloatRect graphicsLayerBoundsInObjectSpace(graphicsLayerBounds); 2769 FloatRect graphicsLayerBoundsInObjectSpace(graphicsLayerBounds);
2707 graphicsLayerBoundsInObjectSpace.move(offsetFromAnchorLayoutObject); 2770 graphicsLayerBoundsInObjectSpace.move(offsetFromAnchorLayoutObject);
2708 2771
2709 // Now map the bounds to its visible content rect in root view space, includin g applying clips along the way. 2772 // Now map the bounds to its visible content rect in root view space,
2773 // including applying clips along the way.
2710 LayoutRect graphicsLayerBoundsInRootViewSpace( 2774 LayoutRect graphicsLayerBoundsInRootViewSpace(
2711 graphicsLayerBoundsInObjectSpace); 2775 graphicsLayerBoundsInObjectSpace);
2712 LayoutView* rootView = anchorLayoutObject->view(); 2776 LayoutView* rootView = anchorLayoutObject->view();
2713 while (!rootView->frame()->ownerLayoutItem().isNull()) 2777 while (!rootView->frame()->ownerLayoutItem().isNull())
2714 rootView = 2778 rootView =
2715 LayoutAPIShim::layoutObjectFrom(rootView->frame()->ownerLayoutItem()) 2779 LayoutAPIShim::layoutObjectFrom(rootView->frame()->ownerLayoutItem())
2716 ->view(); 2780 ->view();
2717 anchorLayoutObject->mapToVisualRectInAncestorSpace( 2781 anchorLayoutObject->mapToVisualRectInAncestorSpace(
2718 rootView, graphicsLayerBoundsInRootViewSpace); 2782 rootView, graphicsLayerBoundsInRootViewSpace);
2719 FloatRect visibleContentRect(graphicsLayerBoundsInRootViewSpace); 2783 FloatRect visibleContentRect(graphicsLayerBoundsInRootViewSpace);
2720 rootView->frameView()->clipPaintRect(&visibleContentRect); 2784 rootView->frameView()->clipPaintRect(&visibleContentRect);
2721 2785
2722 IntRect enclosingGraphicsLayerBounds(enclosingIntRect(graphicsLayerBounds)); 2786 IntRect enclosingGraphicsLayerBounds(enclosingIntRect(graphicsLayerBounds));
2723 2787
2724 // Map the visible content rect from root view space to local graphics layer s pace. 2788 // Map the visible content rect from root view space to local graphics layer
2789 // space.
2725 IntRect localInterestRect; 2790 IntRect localInterestRect;
2726 // If the visible content rect is empty, then it makes no sense to map it back since there is nothing to map. 2791 // If the visible content rect is empty, then it makes no sense to map it back
2792 // since there is nothing to map.
2727 if (!visibleContentRect.isEmpty()) { 2793 if (!visibleContentRect.isEmpty()) {
2728 localInterestRect = 2794 localInterestRect =
2729 anchorLayoutObject 2795 anchorLayoutObject
2730 ->absoluteToLocalQuad(visibleContentRect, 2796 ->absoluteToLocalQuad(visibleContentRect,
2731 UseTransforms | TraverseDocumentBoundaries) 2797 UseTransforms | TraverseDocumentBoundaries)
2732 .enclosingBoundingBox(); 2798 .enclosingBoundingBox();
2733 localInterestRect.move(-offsetFromAnchorLayoutObject); 2799 localInterestRect.move(-offsetFromAnchorLayoutObject);
2734 // TODO(chrishtr): the code below is a heuristic, instead we should detect a nd return whether the mapping failed. 2800 // TODO(chrishtr): the code below is a heuristic, instead we should detect
2735 // In some cases, absoluteToLocalQuad can fail to map back to the local spac e, due to passing through 2801 // and return whether the mapping failed. In some cases,
2736 // non-invertible transforms or floating-point accuracy issues. Examples inc lude rotation near 90 degrees 2802 // absoluteToLocalQuad can fail to map back to the local space, due to
2737 // or perspective. In such cases, fall back to painting the first kPixelDist anceToRecord pixels in each direction. 2803 // passing through non-invertible transforms or floating-point accuracy
2804 // issues. Examples include rotation near 90 degrees or perspective. In such
2805 // cases, fall back to painting the first kPixelDistanceToRecord pixels in
2806 // each direction.
2738 localInterestRect.intersect(enclosingGraphicsLayerBounds); 2807 localInterestRect.intersect(enclosingGraphicsLayerBounds);
2739 } 2808 }
2740 // Expand by interest rect padding amount. 2809 // Expand by interest rect padding amount.
2741 localInterestRect.inflate(kPixelDistanceToRecord); 2810 localInterestRect.inflate(kPixelDistanceToRecord);
2742 localInterestRect.intersect(enclosingGraphicsLayerBounds); 2811 localInterestRect.intersect(enclosingGraphicsLayerBounds);
2743 return localInterestRect; 2812 return localInterestRect;
2744 } 2813 }
2745 2814
2746 static const int kMinimumDistanceBeforeRepaint = 512; 2815 static const int kMinimumDistanceBeforeRepaint = 512;
2747 2816
2748 bool CompositedLayerMapping::interestRectChangedEnoughToRepaint( 2817 bool CompositedLayerMapping::interestRectChangedEnoughToRepaint(
2749 const IntRect& previousInterestRect, 2818 const IntRect& previousInterestRect,
2750 const IntRect& newInterestRect, 2819 const IntRect& newInterestRect,
2751 const IntSize& layerSize) { 2820 const IntSize& layerSize) {
2752 if (previousInterestRect.isEmpty() && newInterestRect.isEmpty()) 2821 if (previousInterestRect.isEmpty() && newInterestRect.isEmpty())
2753 return false; 2822 return false;
2754 2823
2755 // Repaint when going from empty to not-empty, to cover cases where the layer is 2824 // Repaint when going from empty to not-empty, to cover cases where the layer
2756 // painted for the first time, or otherwise becomes visible. 2825 // is painted for the first time, or otherwise becomes visible.
2757 if (previousInterestRect.isEmpty()) 2826 if (previousInterestRect.isEmpty())
2758 return true; 2827 return true;
2759 2828
2760 // Repaint if the new interest rect includes area outside of a skirt around th e existing interest rect. 2829 // Repaint if the new interest rect includes area outside of a skirt around
2830 // the existing interest rect.
2761 IntRect expandedPreviousInterestRect(previousInterestRect); 2831 IntRect expandedPreviousInterestRect(previousInterestRect);
2762 expandedPreviousInterestRect.inflate(kMinimumDistanceBeforeRepaint); 2832 expandedPreviousInterestRect.inflate(kMinimumDistanceBeforeRepaint);
2763 if (!expandedPreviousInterestRect.contains(newInterestRect)) 2833 if (!expandedPreviousInterestRect.contains(newInterestRect))
2764 return true; 2834 return true;
2765 2835
2766 // Even if the new interest rect doesn't include enough new area to satisfy th e condition above, 2836 // Even if the new interest rect doesn't include enough new area to satisfy
2767 // repaint anyway if it touches a layer edge not touched by the existing inter est rect. 2837 // the condition above, repaint anyway if it touches a layer edge not touched
2768 // Because it's impossible to expose more area in the direction, repainting ca nnot be deferred 2838 // by the existing interest rect. Because it's impossible to expose more area
2769 // until the exposed new area satisfies the condition above. 2839 // in the direction, repainting cannot be deferred until the exposed new area
2840 // satisfies the condition above.
2770 if (newInterestRect.x() == 0 && previousInterestRect.x() != 0) 2841 if (newInterestRect.x() == 0 && previousInterestRect.x() != 0)
2771 return true; 2842 return true;
2772 if (newInterestRect.y() == 0 && previousInterestRect.y() != 0) 2843 if (newInterestRect.y() == 0 && previousInterestRect.y() != 0)
2773 return true; 2844 return true;
2774 if (newInterestRect.maxX() == layerSize.width() && 2845 if (newInterestRect.maxX() == layerSize.width() &&
2775 previousInterestRect.maxX() != layerSize.width()) 2846 previousInterestRect.maxX() != layerSize.width())
2776 return true; 2847 return true;
2777 if (newInterestRect.maxY() == layerSize.height() && 2848 if (newInterestRect.maxY() == layerSize.height() &&
2778 previousInterestRect.maxY() != layerSize.height()) 2849 previousInterestRect.maxY() != layerSize.height())
2779 return true; 2850 return true;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2815 } 2886 }
2816 2887
2817 void CompositedLayerMapping::adjustForCompositedScrolling( 2888 void CompositedLayerMapping::adjustForCompositedScrolling(
2818 const GraphicsLayer* graphicsLayer, 2889 const GraphicsLayer* graphicsLayer,
2819 IntSize& offset) const { 2890 IntSize& offset) const {
2820 if (graphicsLayer == m_scrollingContentsLayer.get() || 2891 if (graphicsLayer == m_scrollingContentsLayer.get() ||
2821 graphicsLayer == m_foregroundLayer.get()) { 2892 graphicsLayer == m_foregroundLayer.get()) {
2822 if (PaintLayerScrollableArea* scrollableArea = 2893 if (PaintLayerScrollableArea* scrollableArea =
2823 m_owningLayer.getScrollableArea()) { 2894 m_owningLayer.getScrollableArea()) {
2824 if (scrollableArea->usesCompositedScrolling()) { 2895 if (scrollableArea->usesCompositedScrolling()) {
2825 // Note: this is just the scroll offset, *not* the "adjusted scroll offs et". Scroll offset 2896 // Note: this is just the scroll offset, *not* the "adjusted scroll
2826 // does not include the origin adjustment. That is instead baked already into offsetFromLayoutObject. 2897 // offset". Scroll offset does not include the origin adjustment. That
2898 // is instead baked already into offsetFromLayoutObject.
2827 DoubleSize scrollOffset = scrollableArea->scrollOffset(); 2899 DoubleSize scrollOffset = scrollableArea->scrollOffset();
2828 offset.expand(-scrollOffset.width(), -scrollOffset.height()); 2900 offset.expand(-scrollOffset.width(), -scrollOffset.height());
2829 } 2901 }
2830 } 2902 }
2831 } 2903 }
2832 } 2904 }
2833 2905
2834 void CompositedLayerMapping::paintContents( 2906 void CompositedLayerMapping::paintContents(
2835 const GraphicsLayer* graphicsLayer, 2907 const GraphicsLayer* graphicsLayer,
2836 GraphicsContext& context, 2908 GraphicsContext& context,
2837 GraphicsLayerPaintingPhase graphicsLayerPaintingPhase, 2909 GraphicsLayerPaintingPhase graphicsLayerPaintingPhase,
2838 const IntRect& interestRect) const { 2910 const IntRect& interestRect) const {
2839 // https://code.google.com/p/chromium/issues/detail?id=343772 2911 // https://code.google.com/p/chromium/issues/detail?id=343772
2840 DisableCompositingQueryAsserts disabler; 2912 DisableCompositingQueryAsserts disabler;
2841 // Allow throttling to make sure no painting paths (e.g., 2913 // Allow throttling to make sure no painting paths (e.g.,
2842 // ContentLayerDelegate::paintContents) try to paint throttled content. 2914 // ContentLayerDelegate::paintContents) try to paint throttled content.
2843 DocumentLifecycle::AllowThrottlingScope allowThrottling( 2915 DocumentLifecycle::AllowThrottlingScope allowThrottling(
2844 m_owningLayer.layoutObject()->document().lifecycle()); 2916 m_owningLayer.layoutObject()->document().lifecycle());
2845 #if ENABLE(ASSERT) 2917 #if ENABLE(ASSERT)
2846 // FIXME: once the state machine is ready, this can be removed and we can refe r to that instead. 2918 // FIXME: once the state machine is ready, this can be removed and we can
2919 // refer to that instead.
2847 if (Page* page = layoutObject()->frame()->page()) 2920 if (Page* page = layoutObject()->frame()->page())
2848 page->setIsPainting(true); 2921 page->setIsPainting(true);
2849 #endif 2922 #endif
2850 2923
2851 TRACE_EVENT1( 2924 TRACE_EVENT1(
2852 "devtools.timeline,rail", "Paint", "data", 2925 "devtools.timeline,rail", "Paint", "data",
2853 InspectorPaintEvent::data(m_owningLayer.layoutObject(), 2926 InspectorPaintEvent::data(m_owningLayer.layoutObject(),
2854 LayoutRect(interestRect), graphicsLayer)); 2927 LayoutRect(interestRect), graphicsLayer));
2855 2928
2856 PaintLayerFlags paintLayerFlags = 0; 2929 PaintLayerFlags paintLayerFlags = 0;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2891 else 2964 else
2892 paintLayerFlags |= PaintLayerPaintingSkipRootBackground; 2965 paintLayerFlags |= PaintLayerPaintingSkipRootBackground;
2893 } 2966 }
2894 GraphicsLayerPaintInfo paintInfo; 2967 GraphicsLayerPaintInfo paintInfo;
2895 paintInfo.paintLayer = &m_owningLayer; 2968 paintInfo.paintLayer = &m_owningLayer;
2896 paintInfo.compositedBounds = compositedBounds(); 2969 paintInfo.compositedBounds = compositedBounds();
2897 paintInfo.offsetFromLayoutObject = graphicsLayer->offsetFromLayoutObject(); 2970 paintInfo.offsetFromLayoutObject = graphicsLayer->offsetFromLayoutObject();
2898 adjustForCompositedScrolling(graphicsLayer, 2971 adjustForCompositedScrolling(graphicsLayer,
2899 paintInfo.offsetFromLayoutObject); 2972 paintInfo.offsetFromLayoutObject);
2900 2973
2901 // We have to use the same root as for hit testing, because both methods can compute and cache clipRects. 2974 // We have to use the same root as for hit testing, because both methods can
2975 // compute and cache clipRects.
2902 doPaintTask(paintInfo, *graphicsLayer, paintLayerFlags, context, 2976 doPaintTask(paintInfo, *graphicsLayer, paintLayerFlags, context,
2903 interestRect); 2977 interestRect);
2904 } else if (graphicsLayer == m_squashingLayer.get()) { 2978 } else if (graphicsLayer == m_squashingLayer.get()) {
2905 for (size_t i = 0; i < m_squashedLayers.size(); ++i) 2979 for (size_t i = 0; i < m_squashedLayers.size(); ++i)
2906 doPaintTask(m_squashedLayers[i], *graphicsLayer, paintLayerFlags, context, 2980 doPaintTask(m_squashedLayers[i], *graphicsLayer, paintLayerFlags, context,
2907 interestRect); 2981 interestRect);
2908 } else if (isScrollableAreaLayer(graphicsLayer)) { 2982 } else if (isScrollableAreaLayer(graphicsLayer)) {
2909 paintScrollableArea(graphicsLayer, context, interestRect); 2983 paintScrollableArea(graphicsLayer, context, interestRect);
2910 } 2984 }
2911 InspectorInstrumentation::didPaint(m_owningLayer.layoutObject()->frame(), 2985 InspectorInstrumentation::didPaint(m_owningLayer.layoutObject()->frame(),
2912 graphicsLayer, context, 2986 graphicsLayer, context,
2913 LayoutRect(interestRect)); 2987 LayoutRect(interestRect));
2914 #if ENABLE(ASSERT) 2988 #if ENABLE(ASSERT)
2915 if (Page* page = layoutObject()->frame()->page()) 2989 if (Page* page = layoutObject()->frame()->page())
2916 page->setIsPainting(false); 2990 page->setIsPainting(false);
2917 #endif 2991 #endif
2918 } 2992 }
2919 2993
2920 void CompositedLayerMapping::paintScrollableArea( 2994 void CompositedLayerMapping::paintScrollableArea(
2921 const GraphicsLayer* graphicsLayer, 2995 const GraphicsLayer* graphicsLayer,
2922 GraphicsContext& context, 2996 GraphicsContext& context,
2923 const IntRect& interestRect) const { 2997 const IntRect& interestRect) const {
2924 // Note the composited scrollable area painted here is never associated with a frame. For 2998 // Note the composited scrollable area painted here is never associated with a
2925 // painting frame ScrollableAreas, see PaintLayerCompositor::paintContents. 2999 // frame. For painting frame ScrollableAreas, see
3000 // PaintLayerCompositor::paintContents.
2926 3001
2927 if (DrawingRecorder::useCachedDrawingIfPossible( 3002 if (DrawingRecorder::useCachedDrawingIfPossible(
2928 context, *graphicsLayer, DisplayItem::kScrollbarCompositedScrollbar)) 3003 context, *graphicsLayer, DisplayItem::kScrollbarCompositedScrollbar))
2929 return; 3004 return;
2930 3005
2931 FloatRect layerBounds(FloatPoint(), graphicsLayer->size()); 3006 FloatRect layerBounds(FloatPoint(), graphicsLayer->size());
2932 SkPictureBuilder pictureBuilder(layerBounds, nullptr, &context); 3007 SkPictureBuilder pictureBuilder(layerBounds, nullptr, &context);
2933 PaintLayerScrollableArea* scrollableArea = m_owningLayer.getScrollableArea(); 3008 PaintLayerScrollableArea* scrollableArea = m_owningLayer.getScrollableArea();
2934 if (graphicsLayer == layerForHorizontalScrollbar()) { 3009 if (graphicsLayer == layerForHorizontalScrollbar()) {
2935 paintScrollbar(scrollableArea->horizontalScrollbar(), 3010 paintScrollbar(scrollableArea->horizontalScrollbar(),
2936 pictureBuilder.context(), interestRect); 3011 pictureBuilder.context(), interestRect);
2937 } else if (graphicsLayer == layerForVerticalScrollbar()) { 3012 } else if (graphicsLayer == layerForVerticalScrollbar()) {
2938 paintScrollbar(scrollableArea->verticalScrollbar(), 3013 paintScrollbar(scrollableArea->verticalScrollbar(),
2939 pictureBuilder.context(), interestRect); 3014 pictureBuilder.context(), interestRect);
2940 } else if (graphicsLayer == layerForScrollCorner()) { 3015 } else if (graphicsLayer == layerForScrollCorner()) {
2941 // Note that scroll corners always paint into local space, whereas scrollbar s paint in the space of their containing frame. 3016 // Note that scroll corners always paint into local space, whereas
3017 // scrollbars paint in the space of their containing frame.
2942 IntPoint scrollCornerAndResizerLocation = 3018 IntPoint scrollCornerAndResizerLocation =
2943 scrollableArea->scrollCornerAndResizerRect().location(); 3019 scrollableArea->scrollCornerAndResizerRect().location();
2944 CullRect cullRect(enclosingIntRect(interestRect)); 3020 CullRect cullRect(enclosingIntRect(interestRect));
2945 ScrollableAreaPainter(*scrollableArea) 3021 ScrollableAreaPainter(*scrollableArea)
2946 .paintScrollCorner(pictureBuilder.context(), 3022 .paintScrollCorner(pictureBuilder.context(),
2947 -scrollCornerAndResizerLocation, cullRect); 3023 -scrollCornerAndResizerLocation, cullRect);
2948 ScrollableAreaPainter(*scrollableArea) 3024 ScrollableAreaPainter(*scrollableArea)
2949 .paintResizer(pictureBuilder.context(), -scrollCornerAndResizerLocation, 3025 .paintResizer(pictureBuilder.context(), -scrollCornerAndResizerLocation,
2950 cullRect); 3026 cullRect);
2951 } 3027 }
2952 // Replay the painted scrollbar content with the GraphicsLayer backing as the DisplayItemClient 3028 // Replay the painted scrollbar content with the GraphicsLayer backing as the
2953 // in order for the resulting DrawingDisplayItem to produce the correct visual Rect (i.e., the 3029 // DisplayItemClient in order for the resulting DrawingDisplayItem to produce
2954 // bounds of the involved GraphicsLayer). 3030 // the correct visualRect (i.e., the bounds of the involved GraphicsLayer).
2955 DrawingRecorder drawingRecorder(context, *graphicsLayer, 3031 DrawingRecorder drawingRecorder(context, *graphicsLayer,
2956 DisplayItem::kScrollbarCompositedScrollbar, 3032 DisplayItem::kScrollbarCompositedScrollbar,
2957 layerBounds); 3033 layerBounds);
2958 pictureBuilder.endRecording()->playback(context.canvas()); 3034 pictureBuilder.endRecording()->playback(context.canvas());
2959 } 3035 }
2960 3036
2961 bool CompositedLayerMapping::isScrollableAreaLayer( 3037 bool CompositedLayerMapping::isScrollableAreaLayer(
2962 const GraphicsLayer* graphicsLayer) const { 3038 const GraphicsLayer* graphicsLayer) const {
2963 return graphicsLayer == layerForHorizontalScrollbar() || 3039 return graphicsLayer == layerForHorizontalScrollbar() ||
2964 graphicsLayer == layerForVerticalScrollbar() || 3040 graphicsLayer == layerForVerticalScrollbar() ||
2965 graphicsLayer == layerForScrollCorner(); 3041 graphicsLayer == layerForScrollCorner();
2966 } 3042 }
2967 3043
2968 bool CompositedLayerMapping::isTrackingRasterInvalidations() const { 3044 bool CompositedLayerMapping::isTrackingRasterInvalidations() const {
2969 GraphicsLayerClient* client = compositor(); 3045 GraphicsLayerClient* client = compositor();
2970 return client ? client->isTrackingRasterInvalidations() : false; 3046 return client ? client->isTrackingRasterInvalidations() : false;
2971 } 3047 }
2972 3048
2973 #if ENABLE(ASSERT) 3049 #if ENABLE(ASSERT)
2974 void CompositedLayerMapping::verifyNotPainting() { 3050 void CompositedLayerMapping::verifyNotPainting() {
2975 ASSERT(!layoutObject()->frame()->page() || 3051 ASSERT(!layoutObject()->frame()->page() ||
2976 !layoutObject()->frame()->page()->isPainting()); 3052 !layoutObject()->frame()->page()->isPainting());
2977 } 3053 }
2978 #endif 3054 #endif
2979 3055
2980 // Only used for performance benchmark testing. Intended to be a sufficiently-un ique 3056 // Only used for performance benchmark testing. Intended to be a
2981 // element id name to allow picking out the target element for invalidation. 3057 // sufficiently-unique element id name to allow picking out the target element
3058 // for invalidation.
2982 static const char* kTestPaintInvalidationTargetName = 3059 static const char* kTestPaintInvalidationTargetName =
2983 "blinkPaintInvalidationTarget"; 3060 "blinkPaintInvalidationTarget";
2984 3061
2985 void CompositedLayerMapping::invalidateTargetElementForTesting() { 3062 void CompositedLayerMapping::invalidateTargetElementForTesting() {
2986 // The below is an artificial construct formed intentionally to focus a microb enchmark on the cost of paint with a 3063 // The below is an artificial construct formed intentionally to focus a
2987 // partial invalidation. 3064 // microbenchmark on the cost of paint with a partial invalidation.
2988 Element* targetElement = 3065 Element* targetElement =
2989 m_owningLayer.layoutObject()->document().getElementById( 3066 m_owningLayer.layoutObject()->document().getElementById(
2990 AtomicString(kTestPaintInvalidationTargetName)); 3067 AtomicString(kTestPaintInvalidationTargetName));
2991 // TODO(wkorman): If we don't find the expected target element, we could consi der walking to the first leaf node so 3068 // TODO(wkorman): If we don't find the expected target element, we could
2992 // that the partial-invalidation benchmark mode still provides some value when running on generic pages. 3069 // consider walking to the first leaf node so that the partial-invalidation
3070 // benchmark mode still provides some value when running on generic pages.
2993 if (!targetElement) 3071 if (!targetElement)
2994 return; 3072 return;
2995 LayoutObject* targetObject = targetElement->layoutObject(); 3073 LayoutObject* targetObject = targetElement->layoutObject();
2996 if (!targetObject) 3074 if (!targetObject)
2997 return; 3075 return;
2998 targetObject->enclosingLayer()->setNeedsRepaint(); 3076 targetObject->enclosingLayer()->setNeedsRepaint();
2999 // TODO(wkorman): Consider revising the below to invalidate all non-compositin g descendants as well. 3077 // TODO(wkorman): Consider revising the below to invalidate all
3078 // non-compositing descendants as well.
3000 targetObject->invalidateDisplayItemClients(PaintInvalidationForTesting); 3079 targetObject->invalidateDisplayItemClients(PaintInvalidationForTesting);
3001 } 3080 }
3002 3081
3003 void CompositedLayerMapping::notifyPaint(bool isFirstPaint, 3082 void CompositedLayerMapping::notifyPaint(bool isFirstPaint,
3004 bool textPainted, 3083 bool textPainted,
3005 bool imagePainted) { 3084 bool imagePainted) {
3006 if (PaintTiming* timing = m_owningLayer.paintTiming()) 3085 if (PaintTiming* timing = m_owningLayer.paintTiming())
3007 timing->notifyPaint(isFirstPaint, textPainted, imagePainted); 3086 timing->notifyPaint(isFirstPaint, textPainted, imagePainted);
3008 } 3087 }
3009 3088
(...skipping 20 matching lines...) Expand all
3030 } 3109 }
3031 3110
3032 bool CompositedLayerMapping::updateSquashingLayerAssignment( 3111 bool CompositedLayerMapping::updateSquashingLayerAssignment(
3033 PaintLayer* squashedLayer, 3112 PaintLayer* squashedLayer,
3034 size_t nextSquashedLayerIndex) { 3113 size_t nextSquashedLayerIndex) {
3035 GraphicsLayerPaintInfo paintInfo; 3114 GraphicsLayerPaintInfo paintInfo;
3036 paintInfo.paintLayer = squashedLayer; 3115 paintInfo.paintLayer = squashedLayer;
3037 // NOTE: composited bounds are updated elsewhere 3116 // NOTE: composited bounds are updated elsewhere
3038 // NOTE: offsetFromLayoutObject is updated elsewhere 3117 // NOTE: offsetFromLayoutObject is updated elsewhere
3039 3118
3040 // Change tracking on squashing layers: at the first sign of something changed , just invalidate the layer. 3119 // Change tracking on squashing layers: at the first sign of something
3120 // changed, just invalidate the layer.
3041 // FIXME: Perhaps we can find a tighter more clever mechanism later. 3121 // FIXME: Perhaps we can find a tighter more clever mechanism later.
3042 if (nextSquashedLayerIndex < m_squashedLayers.size()) { 3122 if (nextSquashedLayerIndex < m_squashedLayers.size()) {
3043 if (paintInfo.paintLayer == 3123 if (paintInfo.paintLayer ==
3044 m_squashedLayers[nextSquashedLayerIndex].paintLayer) 3124 m_squashedLayers[nextSquashedLayerIndex].paintLayer)
3045 return false; 3125 return false;
3046 3126
3047 // Must invalidate before adding the squashed layer to the mapping. 3127 // Must invalidate before adding the squashed layer to the mapping.
3048 compositor()->paintInvalidationOnCompositingChange(squashedLayer); 3128 compositor()->paintInvalidationOnCompositingChange(squashedLayer);
3049 3129
3050 // If the layer which was previously at |nextSquashedLayerIndex| is not earl ier in the grouped mapping, invalidate its current 3130 // If the layer which was previously at |nextSquashedLayerIndex| is not
3051 // backing now, since it will move later or be removed from the squashing la yer. 3131 // earlier in the grouped mapping, invalidate its current backing now, since
3132 // it will move later or be removed from the squashing layer.
3052 invalidateLayerIfNoPrecedingEntry(nextSquashedLayerIndex); 3133 invalidateLayerIfNoPrecedingEntry(nextSquashedLayerIndex);
3053 3134
3054 m_squashedLayers.insert(nextSquashedLayerIndex, paintInfo); 3135 m_squashedLayers.insert(nextSquashedLayerIndex, paintInfo);
3055 } else { 3136 } else {
3056 // Must invalidate before adding the squashed layer to the mapping. 3137 // Must invalidate before adding the squashed layer to the mapping.
3057 compositor()->paintInvalidationOnCompositingChange(squashedLayer); 3138 compositor()->paintInvalidationOnCompositingChange(squashedLayer);
3058 m_squashedLayers.append(paintInfo); 3139 m_squashedLayers.append(paintInfo);
3059 } 3140 }
3060 squashedLayer->setGroupedMapping( 3141 squashedLayer->setGroupedMapping(
3061 this, PaintLayer::InvalidateLayerAndRemoveFromMapping); 3142 this, PaintLayer::InvalidateLayerAndRemoveFromMapping);
(...skipping 27 matching lines...) Expand all
3089 } 3170 }
3090 3171
3091 return false; 3172 return false;
3092 } 3173 }
3093 #endif 3174 #endif
3094 3175
3095 void CompositedLayerMapping::finishAccumulatingSquashingLayers( 3176 void CompositedLayerMapping::finishAccumulatingSquashingLayers(
3096 size_t nextSquashedLayerIndex, 3177 size_t nextSquashedLayerIndex,
3097 Vector<PaintLayer*>& layersNeedingPaintInvalidation) { 3178 Vector<PaintLayer*>& layersNeedingPaintInvalidation) {
3098 if (nextSquashedLayerIndex < m_squashedLayers.size()) { 3179 if (nextSquashedLayerIndex < m_squashedLayers.size()) {
3099 // Any additional squashed Layers in the array no longer belong here, but th ey might have been 3180 // Any additional squashed Layers in the array no longer belong here, but
3100 // added already at an earlier index. Clear pointers on those that do not ap pear in the valid set 3181 // they might have been added already at an earlier index. Clear pointers on
3101 // before removing all the extra entries. 3182 // those that do not appear in the valid set before removing all the extra
3183 // entries.
3102 for (size_t i = nextSquashedLayerIndex; i < m_squashedLayers.size(); ++i) { 3184 for (size_t i = nextSquashedLayerIndex; i < m_squashedLayers.size(); ++i) {
3103 if (invalidateLayerIfNoPrecedingEntry(i)) 3185 if (invalidateLayerIfNoPrecedingEntry(i))
3104 m_squashedLayers[i].paintLayer->setGroupedMapping( 3186 m_squashedLayers[i].paintLayer->setGroupedMapping(
3105 nullptr, PaintLayer::DoNotInvalidateLayerAndRemoveFromMapping); 3187 nullptr, PaintLayer::DoNotInvalidateLayerAndRemoveFromMapping);
3106 layersNeedingPaintInvalidation.append(m_squashedLayers[i].paintLayer); 3188 layersNeedingPaintInvalidation.append(m_squashedLayers[i].paintLayer);
3107 } 3189 }
3108 3190
3109 m_squashedLayers.remove(nextSquashedLayerIndex, 3191 m_squashedLayers.remove(nextSquashedLayerIndex,
3110 m_squashedLayers.size() - nextSquashedLayerIndex); 3192 m_squashedLayers.size() - nextSquashedLayerIndex);
3111 } 3193 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3153 } else if (graphicsLayer == m_scrollingContentsLayer.get()) { 3235 } else if (graphicsLayer == m_scrollingContentsLayer.get()) {
3154 name = "Scrolling Contents Layer"; 3236 name = "Scrolling Contents Layer";
3155 } else { 3237 } else {
3156 ASSERT_NOT_REACHED(); 3238 ASSERT_NOT_REACHED();
3157 } 3239 }
3158 3240
3159 return name; 3241 return name;
3160 } 3242 }
3161 3243
3162 } // namespace blink 3244 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698