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

Unified Diff: Source/core/layout/LayoutView.cpp

Issue 1145993002: Refactor root element background painting (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: make invalidation more robust. also improve incremental invalidation for some common cases Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/layout/LayoutView.cpp
diff --git a/Source/core/layout/LayoutView.cpp b/Source/core/layout/LayoutView.cpp
index f100481a8ab8727510cb2745c1dc77de5c6c09f4..71f8f06ac67bdc4125aee779cacd12112b3299b3 100644
--- a/Source/core/layout/LayoutView.cpp
+++ b/Source/core/layout/LayoutView.cpp
@@ -195,16 +195,14 @@ bool LayoutView::shouldDoFullPaintInvalidationForNextLayout() const
return true;
if (size().height() != viewLogicalHeightForBoxSizing()) {
- if (LayoutObject* backgroundLayoutObject = this->backgroundLayoutObject()) {
- // When background-attachment is 'fixed', we treat the viewport (instead of the 'root'
- // i.e. html or body) as the background positioning area, and we should full paint invalidation
- // viewport resize if the background image is not composited and needs full paint invalidation on
- // background positioning area resize.
- if (!m_compositor || !m_compositor->needsFixedRootBackgroundLayer(layer())) {
- if (backgroundLayoutObject->style()->hasFixedBackgroundImage()
- && mustInvalidateFillLayersPaintOnHeightChange(backgroundLayoutObject->style()->backgroundLayers()))
- return true;
- }
+ // When background-attachment is 'fixed', we treat the viewport (instead of the 'root'
+ // i.e. html or body) as the background positioning area, and we should full paint invalidation
+ // viewport resize if the background image is not composited and needs full paint invalidation on
+ // background positioning area resize.
+ if (!m_compositor || !m_compositor->needsFixedRootBackgroundLayer(layer())) {
+ if (style()->hasFixedBackgroundImage()
+ && mustInvalidateFillLayersPaintOnHeightChange(style()->backgroundLayers()))
+ return true;
}
}
@@ -221,8 +219,6 @@ void LayoutView::layout()
SubtreeLayoutScope layoutScope(*this);
- LayoutRect oldLayoutOverflowRect = layoutOverflowRect();
-
// Use calcWidth/Height to get the new width/height, since this will take the full page zoom factor into account.
bool relayoutChildren = !shouldUsePrintingLayout() && (!m_frameView
|| logicalWidth() != viewLogicalWidthForBoxSizing()
@@ -254,22 +250,64 @@ void LayoutView::layout()
layoutContent();
- if (RuntimeEnabledFeatures::slimmingPaintEnabled() && layoutOverflowRect() != oldLayoutOverflowRect) {
- // The document element paints the viewport background, so we need to invalidate it when
- // layout overflow changes.
- // FIXME: Improve viewport background styling/invalidation/painting. crbug.com/475115
- if (Element* documentElement = document().documentElement()) {
- if (LayoutObject* rootObject = documentElement->layoutObject())
- rootObject->setShouldDoFullPaintInvalidation();
- }
- }
-
#if ENABLE(ASSERT)
checkLayoutState();
#endif
clearNeedsLayout();
}
+void LayoutView::styleDidChange(StyleDifference diff, const ComputedStyle* oldStyle)
+{
+ const ComputedStyle& newStyle = styleRef();
+
+ if (oldStyle && oldStyle->hasEntirelyFixedBackground() != newStyle.hasEntirelyFixedBackground())
+ compositor()->setNeedsUpdateFixedBackground();
+
+ LayoutBlockFlow::styleDidChange(diff, oldStyle);
+}
+
+PaintInvalidationReason LayoutView::invalidatePaintIfNeeded(PaintInvalidationState& paintInvalidationState, const LayoutBoxModelObject& newPaintInvalidationContainer)
+{
+ const LayoutObject* rootObject = document().documentElement() ? document().documentElement()->layoutObject() : nullptr;
+ TransformationMatrix newTransform;
+ LayoutSize newBorderBoxSize;
+ LayoutRect newPaddingBoxRect;
+ LayoutRect newContentBoxRect;
+
+ if (rootObject && rootObject->isBox()) {
+ const LayoutBox& rootBox = toLayoutBox(*rootObject);
+ if (rootBox.hasLayer()) {
+ const DeprecatedPaintLayer& rootLayer = *rootBox.layer();
+ LayoutPoint offset;
+ rootLayer.convertToLayerCoords(nullptr, offset);
+ newTransform.translate(offset.x(), offset.y());
+ newTransform.multiply(rootLayer.currentTransform());
+ }
+ newBorderBoxSize = rootBox.size();
+ newPaddingBoxRect = rootBox.paddingBoxRect();
+ newContentBoxRect = rootBox.contentBoxRect();
+ }
+
+ if (m_previousRootBackgroundPositioning.transform != newTransform)
+ setShouldDoFullPaintInvalidation(PaintInvalidationLocationChange);
+
+ const FillLayer& backgroundLayers = style()->backgroundLayers();
+ if (mustInvalidateFillLayersPaintOnWidthChange(backgroundLayers) || mustInvalidateFillLayersPaintOnHeightChange(backgroundLayers)) {
+ if (m_previousRootBackgroundPositioning.borderBoxSize != newBorderBoxSize
+ || m_previousRootBackgroundPositioning.paddingBoxRect != newPaddingBoxRect
+ || m_previousRootBackgroundPositioning.contentBoxRect != newContentBoxRect) {
+ setShouldDoFullPaintInvalidation(PaintInvalidationBorderBoxChange);
+ }
+ }
Xianzhu 2015/06/05 03:44:51 We don't allow setShouldDoFullPaintInvalidation()
+
+ m_previousRootBackgroundPositioning.transform = newTransform;
+ m_previousRootBackgroundPositioning.borderBoxSize = newBorderBoxSize;
+ m_previousRootBackgroundPositioning.paddingBoxRect = newPaddingBoxRect;
+ m_previousRootBackgroundPositioning.contentBoxRect = newContentBoxRect;
+
+ return LayoutBox::invalidatePaintIfNeeded(paintInvalidationState, newPaintInvalidationContainer);
+}
+
void LayoutView::mapLocalToContainer(const LayoutBoxModelObject* paintInvalidationContainer, TransformState& transformState, MapCoordinatesFlags mode, bool* wasFixed, const PaintInvalidationState* paintInvalidationState) const
{
ASSERT_UNUSED(wasFixed, !wasFixed || *wasFixed == static_cast<bool>(mode & IsFixed));
@@ -844,18 +882,7 @@ IntRect LayoutView::unscaledDocumentRect() const
bool LayoutView::rootBackgroundIsEntirelyFixed() const
{
- if (LayoutObject* backgroundLayoutObject = this->backgroundLayoutObject())
- return backgroundLayoutObject->style()->hasEntirelyFixedBackground();
- return false;
-}
-
-LayoutObject* LayoutView::backgroundLayoutObject() const
-{
- if (Element* documentElement = document().documentElement()) {
- if (LayoutObject* rootObject = documentElement->layoutObject())
- return rootObject->layoutObjectForRootBackground();
- }
- return 0;
+ return style()->hasEntirelyFixedBackground();
}
LayoutRect LayoutView::backgroundRect(LayoutBox* backgroundLayoutObject) const

Powered by Google App Engine
This is Rietveld 408576698