1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/rendering/PaintInvalidationState.h"
8 #include "core/rendering/RenderInline.h"
9 #include "core/rendering/RenderLayer.h"
10 #include "core/rendering/RenderView.h"
11 #include "core/rendering/svg/RenderSVGModelObject.h"
12 #include "platform/Partitions.h"
16 PaintInvalidationState::PaintInvalidationState(RenderObject& renderer)
18 , m_cachedOffsetsEnabled(true)
19 , m_forceCheckForPaintInvalidation(false)
20 , m_paintInvalidationContainer(*renderer.containerForPaintInvalidation())
21 , m_renderer(renderer)
23 bool establishesPaintInvalidationContainer = &m_renderer == &m_paintInvalidationContainer;
24 if (!establishesPaintInvalidationContainer) {
25 if (!renderer.supportsPaintInvalidationStateCachedOffsets()) {
26 m_cachedOffsetsEnabled = false;
29 bool invalidationContainerSkipped;
30 RenderObject* container = renderer.container(&m_paintInvalidationContainer, &invalidationContainerSkipped);
31 if (container && !invalidationContainerSkipped) {
32 FloatPoint point = container->localToContainerPoint(FloatPoint(), &m_paintInvalidationContainer);
33 if (container->isTableRow())
34 point = FloatPoint(point.x() - toRenderBox(container)->x().toFloat(), point.y() - toRenderBox(container)->y().toFloat());
35 m_paintOffset = LayoutSize(point.x(), point.y());
37 applyClipIfNeeded(*container);
40 applyClipIfNeeded(m_renderer);
44 PaintInvalidationState::PaintInvalidationState(const PaintInvalidationState& next, RenderLayerModelObject& renderer, const RenderLayerModelObject& paintInvalidationContainer)
46 , m_cachedOffsetsEnabled(true)
47 , m_forceCheckForPaintInvalidation(next.m_forceCheckForPaintInvalidation)
48 , m_paintInvalidationContainer(paintInvalidationContainer)
49 , m_renderer(renderer)
51 // FIXME: SVG could probably benefit from a stack-based optimization like html does. crbug.com/391054
52 bool establishesPaintInvalidationContainer = &m_renderer == &m_paintInvalidationContainer;
53 bool fixed = m_renderer.isOutOfFlowPositioned() && m_renderer.style()->position() == FixedPosition;
55 if (establishesPaintInvalidationContainer) {
56 // When we hit a new paint invalidation container, we don't need to
57 // continue forcing a check for paint invalidation because movement
58 // from our parents will just move the whole invalidation container.
59 m_forceCheckForPaintInvalidation = false;
61 if (!renderer.supportsPaintInvalidationStateCachedOffsets() || !next.m_cachedOffsetsEnabled) {
62 m_cachedOffsetsEnabled = false;
64 LayoutSize offset = m_renderer.isBox() && !m_renderer.isTableRow() ? toRenderBox(renderer).locationOffset() : LayoutSize();
66 // FIXME: This doesn't work correctly with transforms.
67 FloatPoint fixedOffset = m_renderer.view()->localToAbsolute(FloatPoint(), IsFixed);
68 m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y()) + offset;
70 m_paintOffset = next.m_paintOffset + offset;
73 if (m_renderer.isOutOfFlowPositioned() && !fixed) {
74 if (RenderObject* container = m_renderer.container()) {
75 if (container->style()->hasInFlowPosition() && container->isRenderInline())
76 m_paintOffset += toRenderInline(container)->offsetForInFlowPositionedInline(toRenderBox(renderer));
80 if (m_renderer.style()->hasInFlowPosition() && renderer.hasLayer())
81 m_paintOffset += renderer.layer()->offsetForInFlowPosition();
84 m_clipped = !fixed && next.m_clipped;
86 m_clipRect = next.m_clipRect;
89 applyClipIfNeeded(renderer);
91 // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present.
94 void PaintInvalidationState::applyClipIfNeeded(const RenderObject& renderer)
96 if (!renderer.hasOverflowClip())
99 const RenderBox& box = toRenderBox(renderer);
101 // Do not clip scroll layer contents because the compositor expects the whole layer
102 // to be always invalidated in-time.
103 if (box.usesCompositedScrolling()) {
104 ASSERT(!m_clipped); // The box should establish paint invalidation container, so no m_clipped inherited.
106 LayoutRect clipRect(toPoint(m_paintOffset), box.layer()->size());
108 m_clipRect.intersect(clipRect);
110 m_clipRect = clipRect;
115 m_paintOffset -= box.scrolledContentOffset();