2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
4 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
7 * Robert O'Callahan <roc+@cs.cmu.edu>
8 * David Baron <dbaron@fas.harvard.edu>
9 * Christian Biesinger <cbiesinger@web.de>
10 * Randall Jesup <rjesup@wgate.com>
11 * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
12 * Josh Soref <timeless@mac.com>
13 * Boris Zbarsky <bzbarsky@mit.edu>
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 * Alternatively, the contents of this file may be used under the terms
30 * of either the Mozilla Public License Version 1.1, found at
31 * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
32 * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
33 * (the "GPL"), in which case the provisions of the MPL or the GPL are
34 * applicable instead of those above. If you wish to allow use of your
35 * version of this file only under the terms of one of those two
36 * licenses (the MPL or the GPL) and not to allow others to use your
37 * version of this file under the LGPL, indicate your decision by
38 * deletingthe provisions above and replace them with the notice and
39 * other provisions required by the MPL or the GPL, as the case may be.
40 * If you do not delete the provisions above, a recipient may use your
41 * version of this file under any of the LGPL, the MPL or the GPL.
45 #include "core/rendering/RenderLayerRepainter.h"
47 #include "core/rendering/FilterEffectRenderer.h"
48 #include "core/rendering/LayoutRectRecorder.h"
49 #include "core/rendering/RenderLayer.h"
50 #include "core/rendering/RenderView.h"
51 #include "core/rendering/compositing/CompositedLayerMapping.h"
55 RenderLayerRepainter::RenderLayerRepainter(RenderLayerModelObject* renderer)
56 : m_renderer(renderer)
57 , m_repaintStatus(NeedsNormalRepaint)
61 void RenderLayerRepainter::repaintAfterLayout(RenderGeometryMap* geometryMap, bool shouldCheckForRepaint)
63 if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
66 // FIXME: really, we're in the repaint phase here, and the following queries are legal.
67 // Until those states are fully fledged, I'll just disable the ASSERTS.
68 DisableCompositingQueryAsserts disabler;
69 if (m_renderer->layer()->hasVisibleContent()) {
70 RenderView* view = m_renderer->view();
72 // FIXME: LayoutState does not work with RenderLayers as there is not a 1-to-1
73 // mapping between them and the RenderObjects. It would be neat to enable
74 // LayoutState outside the layout() phase and use it here.
75 ASSERT(!view->layoutStateEnabled());
77 RenderLayerModelObject* repaintContainer = m_renderer->containerForRepaint();
78 LayoutRect oldRepaintRect = m_repaintRect;
79 LayoutRect oldOutlineBox = m_outlineBox;
80 computeRepaintRects(repaintContainer, geometryMap);
81 shouldCheckForRepaint &= shouldRepaintLayer();
83 // FIXME: Should ASSERT that value calculated for m_outlineBox using the cached offset is the same
84 // as the value not using the cached offset, but we can't due to https://bugs.webkit.org/show_bug.cgi?id=37048
85 if (shouldCheckForRepaint) {
86 if (view && !view->document().printing()) {
87 if (m_repaintStatus & NeedsFullRepaint) {
88 m_renderer->repaintUsingContainer(repaintContainer, pixelSnappedIntRect(oldRepaintRect));
89 if (m_repaintRect != oldRepaintRect)
90 m_renderer->repaintUsingContainer(repaintContainer, pixelSnappedIntRect(m_repaintRect));
92 m_renderer->repaintAfterLayoutIfNeeded(repaintContainer, m_renderer->selfNeedsLayout(), oldRepaintRect, oldOutlineBox, &m_repaintRect, &m_outlineBox);
100 m_repaintStatus = NeedsNormalRepaint;
104 void RenderLayerRepainter::clearRepaintRects()
106 ASSERT(!m_renderer->layer()->hasVisibleContent());
108 m_repaintRect = IntRect();
109 m_outlineBox = IntRect();
112 void RenderLayerRepainter::computeRepaintRects(const RenderLayerModelObject* repaintContainer, const RenderGeometryMap* geometryMap)
114 if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
117 m_repaintRect = m_renderer->clippedOverflowRectForRepaint(repaintContainer);
118 m_outlineBox = m_renderer->outlineBoundsForRepaint(repaintContainer, geometryMap);
121 void RenderLayerRepainter::computeRepaintRectsIncludingDescendants()
123 if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) {
124 // FIXME: We want RenderLayerRepainter to go away when
125 // repaint-after-layout is on by default so we need to figure out how to
126 // handle this update.
128 // This is a little silly as we create and immediately destroy the RAII
129 // object but it makes sure we correctly set all of the repaint flags.
130 LayoutRectRecorder recorder(*m_renderer);
133 // FIXME: computeRepaintRects() has to walk up the parent chain for every layer to compute the rects.
134 // We should make this more efficient.
135 // FIXME: it's wrong to call this when layout is not up-to-date, which we do.
136 computeRepaintRects(m_renderer->containerForRepaint());
139 for (RenderLayer* layer = m_renderer->layer()->firstChild(); layer; layer = layer->nextSibling())
140 layer->repainter().computeRepaintRectsIncludingDescendants();
143 inline bool RenderLayerRepainter::shouldRepaintLayer() const
145 if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
148 if (m_repaintStatus != NeedsFullRepaintForPositionedMovementLayout)
151 // Composited layers that were moved during a positioned movement only
152 // layout, don't need to be repainted. They just need to be recomposited.
153 return m_renderer->compositingState() != PaintsIntoOwnBacking;
156 // Since we're only painting non-composited layers, we know that they all share the same repaintContainer.
157 void RenderLayerRepainter::repaintIncludingNonCompositingDescendants(RenderLayerModelObject* repaintContainer)
159 m_renderer->repaintUsingContainer(repaintContainer, pixelSnappedIntRect(m_renderer->clippedOverflowRectForRepaint(repaintContainer)));
161 for (RenderLayer* curr = m_renderer->layer()->firstChild(); curr; curr = curr->nextSibling()) {
162 if (!curr->hasCompositedLayerMapping())
163 curr->repainter().repaintIncludingNonCompositingDescendants(repaintContainer);
167 LayoutRect RenderLayerRepainter::repaintRectIncludingNonCompositingDescendants() const
169 LayoutRect repaintRect;
170 if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
171 repaintRect = m_renderer->newRepaintRect();
173 repaintRect = m_repaintRect;
175 for (RenderLayer* child = m_renderer->layer()->firstChild(); child; child = child->nextSibling()) {
176 // Don't include repaint rects for composited child layers; they will paint themselves and have a different origin.
177 if (child->hasCompositedLayerMapping())
180 repaintRect.unite(child->repainter().repaintRectIncludingNonCompositingDescendants());
185 void RenderLayerRepainter::setBackingNeedsRepaint()
187 ASSERT(m_renderer->compositingState() != NotComposited);
189 if (m_renderer->compositingState() == PaintsIntoGroupedBacking) {
190 // FIXME: should probably setNeedsDisplayInRect for this layer's bounds only.
191 m_renderer->groupedMapping()->squashingLayer()->setNeedsDisplay();
193 m_renderer->compositedLayerMapping()->setContentsNeedDisplay();
197 void RenderLayerRepainter::setBackingNeedsRepaintInRect(const LayoutRect& r)
199 // https://bugs.webkit.org/show_bug.cgi?id=61159 describes an unreproducible crash here,
200 // so assert but check that the layer is composited.
201 ASSERT(m_renderer->compositingState() != NotComposited);
202 if (m_renderer->compositingState() == NotComposited) {
203 // If we're trying to repaint the placeholder document layer, propagate the
204 // repaint to the native view system.
205 LayoutRect absRect(r);
207 m_renderer->layer()->convertToLayerCoords(m_renderer->layer()->root(), delta);
208 absRect.moveBy(delta);
210 RenderView* view = m_renderer->view();
212 view->repaintViewRectangle(absRect);
214 if (m_renderer->compositingState() == PaintsIntoGroupedBacking) {
215 // FIXME: LayoutRect rounding to IntRect is probably not a good idea.
216 IntRect offsetRect = pixelSnappedIntRect(r);
217 if (m_renderer->hasTransform())
218 offsetRect = m_renderer->layer()->transform()->mapRect(pixelSnappedIntRect(r));
220 offsetRect.move(-m_renderer->layer()->offsetFromSquashingLayerOrigin());
221 m_renderer->groupedMapping()->squashingLayer()->setNeedsDisplayInRect(offsetRect);
223 IntRect repaintRect = pixelSnappedIntRect(r.location() + m_renderer->compositedLayerMapping()->subpixelAccumulation(), r.size());
224 m_renderer->compositedLayerMapping()->setContentsNeedDisplayInRect(repaintRect);
229 void RenderLayerRepainter::repaintIncludingDescendants()
231 m_renderer->repaint();
232 for (RenderLayer* curr = m_renderer->layer()->firstChild(); curr; curr = curr->nextSibling())
233 curr->repainter().repaintIncludingDescendants();
236 void RenderLayerRepainter::setFilterBackendNeedsRepaintingInRect(const LayoutRect& rect)
241 LayoutRect rectForRepaint = rect;
242 m_renderer->style()->filterOutsets().expandRect(rectForRepaint);
244 RenderLayerFilterInfo* filterInfo = m_renderer->layer()->filterInfo();
246 filterInfo->expandDirtySourceRect(rectForRepaint);
248 ASSERT(filterInfo->renderer());
249 if (filterInfo->renderer()->hasCustomShaderFilter()) {
250 // If we have at least one custom shader, we need to update the whole bounding box of the layer, because the
251 // shader can address any ouput pixel.
252 // Note: This is only for output rect, so there's no need to expand the dirty source rect.
253 rectForRepaint.unite(m_renderer->layer()->calculateLayerBounds(m_renderer->layer()));
256 RenderLayer* parentLayer = enclosingFilterRepaintLayer();
258 FloatQuad repaintQuad(rectForRepaint);
259 LayoutRect parentLayerRect = m_renderer->localToContainerQuad(repaintQuad, parentLayer->renderer()).enclosingBoundingBox();
261 if (parentLayer->hasCompositedLayerMapping()) {
262 parentLayer->repainter().setBackingNeedsRepaintInRect(parentLayerRect);
266 if (parentLayer->paintsWithFilters()) {
267 parentLayer->repainter().setFilterBackendNeedsRepaintingInRect(parentLayerRect);
271 if (parentLayer->isRootLayer()) {
272 RenderView* view = toRenderView(parentLayer->renderer());
273 view->repaintViewRectangle(parentLayerRect);
277 ASSERT_NOT_REACHED();
280 RenderLayer* RenderLayerRepainter::enclosingFilterRepaintLayer() const
282 for (const RenderLayer* curr = m_renderer->layer(); curr; curr = curr->parent()) {
283 if ((curr != m_renderer->layer() && curr->requiresFullLayerImageForFilters()) || curr->compositingState() == PaintsIntoOwnBacking || curr->isRootLayer())
284 return const_cast<RenderLayer*>(curr);
289 } // Namespace WebCore