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 computeRepaintRects(repaintContainer, geometryMap);
80 shouldCheckForRepaint &= shouldRepaintLayer();
82 if (shouldCheckForRepaint) {
83 if (view && !view->document().printing()) {
84 if (m_repaintStatus & NeedsFullRepaint) {
85 m_renderer->repaintUsingContainer(repaintContainer, pixelSnappedIntRect(oldRepaintRect));
86 if (m_repaintRect != oldRepaintRect)
87 m_renderer->repaintUsingContainer(repaintContainer, pixelSnappedIntRect(m_repaintRect));
89 m_renderer->repaintAfterLayoutIfNeeded(repaintContainer, m_renderer->selfNeedsLayout(), oldRepaintRect, &m_repaintRect);
97 m_repaintStatus = NeedsNormalRepaint;
101 void RenderLayerRepainter::clearRepaintRects()
103 ASSERT(!m_renderer->layer()->hasVisibleContent());
105 m_repaintRect = IntRect();
108 void RenderLayerRepainter::computeRepaintRects(const RenderLayerModelObject* repaintContainer, const RenderGeometryMap* geometryMap)
110 if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
113 m_repaintRect = m_renderer->clippedOverflowRectForRepaint(repaintContainer);
116 void RenderLayerRepainter::computeRepaintRectsIncludingDescendants()
118 if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) {
119 // FIXME: We want RenderLayerRepainter to go away when
120 // repaint-after-layout is on by default so we need to figure out how to
121 // handle this update.
123 // This is a little silly as we create and immediately destroy the RAII
124 // object but it makes sure we correctly set all of the repaint flags.
125 LayoutRectRecorder recorder(*m_renderer);
128 // FIXME: computeRepaintRects() has to walk up the parent chain for every layer to compute the rects.
129 // We should make this more efficient.
130 // FIXME: it's wrong to call this when layout is not up-to-date, which we do.
131 computeRepaintRects(m_renderer->containerForRepaint());
134 for (RenderLayer* layer = m_renderer->layer()->firstChild(); layer; layer = layer->nextSibling())
135 layer->repainter().computeRepaintRectsIncludingDescendants();
138 inline bool RenderLayerRepainter::shouldRepaintLayer() const
140 if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
143 if (m_repaintStatus != NeedsFullRepaintForPositionedMovementLayout)
146 // Composited layers that were moved during a positioned movement only
147 // layout, don't need to be repainted. They just need to be recomposited.
148 return m_renderer->compositingState() != PaintsIntoOwnBacking;
151 // Since we're only painting non-composited layers, we know that they all share the same repaintContainer.
152 void RenderLayerRepainter::repaintIncludingNonCompositingDescendants(RenderLayerModelObject* repaintContainer)
154 m_renderer->repaintUsingContainer(repaintContainer, pixelSnappedIntRect(m_renderer->clippedOverflowRectForRepaint(repaintContainer)));
156 for (RenderLayer* curr = m_renderer->layer()->firstChild(); curr; curr = curr->nextSibling()) {
157 if (!curr->hasCompositedLayerMapping())
158 curr->repainter().repaintIncludingNonCompositingDescendants(repaintContainer);
162 LayoutRect RenderLayerRepainter::repaintRectIncludingNonCompositingDescendants() const
164 LayoutRect repaintRect;
165 if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
166 repaintRect = m_renderer->newRepaintRect();
168 repaintRect = m_repaintRect;
170 for (RenderLayer* child = m_renderer->layer()->firstChild(); child; child = child->nextSibling()) {
171 // Don't include repaint rects for composited child layers; they will paint themselves and have a different origin.
172 if (child->hasCompositedLayerMapping())
175 repaintRect.unite(child->repainter().repaintRectIncludingNonCompositingDescendants());
180 void RenderLayerRepainter::setBackingNeedsRepaint()
182 ASSERT(m_renderer->compositingState() != NotComposited);
184 if (m_renderer->compositingState() == PaintsIntoGroupedBacking) {
185 // FIXME: should probably setNeedsDisplayInRect for this layer's bounds only.
186 m_renderer->groupedMapping()->squashingLayer()->setNeedsDisplay();
188 m_renderer->compositedLayerMapping()->setContentsNeedDisplay();
192 void RenderLayerRepainter::setBackingNeedsRepaintInRect(const LayoutRect& r)
194 // https://bugs.webkit.org/show_bug.cgi?id=61159 describes an unreproducible crash here,
195 // so assert but check that the layer is composited.
196 ASSERT(m_renderer->compositingState() != NotComposited);
197 if (m_renderer->compositingState() == NotComposited) {
198 // If we're trying to repaint the placeholder document layer, propagate the
199 // repaint to the native view system.
200 LayoutRect absRect(r);
202 m_renderer->layer()->convertToLayerCoords(m_renderer->layer()->root(), delta);
203 absRect.moveBy(delta);
205 RenderView* view = m_renderer->view();
207 view->repaintViewRectangle(absRect);
209 if (m_renderer->compositingState() == PaintsIntoGroupedBacking) {
210 // FIXME: LayoutRect rounding to IntRect is probably not a good idea.
211 IntRect offsetRect = pixelSnappedIntRect(r);
212 if (m_renderer->hasTransform())
213 offsetRect = m_renderer->layer()->transform()->mapRect(pixelSnappedIntRect(r));
215 offsetRect.move(-m_renderer->layer()->offsetFromSquashingLayerOrigin());
216 m_renderer->groupedMapping()->squashingLayer()->setNeedsDisplayInRect(offsetRect);
218 IntRect repaintRect = pixelSnappedIntRect(r.location() + m_renderer->compositedLayerMapping()->subpixelAccumulation(), r.size());
219 m_renderer->compositedLayerMapping()->setContentsNeedDisplayInRect(repaintRect);
224 void RenderLayerRepainter::repaintIncludingDescendants()
226 m_renderer->repaint();
227 for (RenderLayer* curr = m_renderer->layer()->firstChild(); curr; curr = curr->nextSibling())
228 curr->repainter().repaintIncludingDescendants();
231 void RenderLayerRepainter::setFilterBackendNeedsRepaintingInRect(const LayoutRect& rect)
236 LayoutRect rectForRepaint = rect;
237 m_renderer->style()->filterOutsets().expandRect(rectForRepaint);
239 RenderLayerFilterInfo* filterInfo = m_renderer->layer()->filterInfo();
241 filterInfo->expandDirtySourceRect(rectForRepaint);
243 ASSERT(filterInfo->renderer());
244 if (filterInfo->renderer()->hasCustomShaderFilter()) {
245 // If we have at least one custom shader, we need to update the whole bounding box of the layer, because the
246 // shader can address any ouput pixel.
247 // Note: This is only for output rect, so there's no need to expand the dirty source rect.
248 rectForRepaint.unite(m_renderer->layer()->calculateLayerBounds(m_renderer->layer()));
251 RenderLayer* parentLayer = enclosingFilterRepaintLayer();
253 FloatQuad repaintQuad(rectForRepaint);
254 LayoutRect parentLayerRect = m_renderer->localToContainerQuad(repaintQuad, parentLayer->renderer()).enclosingBoundingBox();
256 if (parentLayer->hasCompositedLayerMapping()) {
257 parentLayer->repainter().setBackingNeedsRepaintInRect(parentLayerRect);
261 if (parentLayer->paintsWithFilters()) {
262 parentLayer->repainter().setFilterBackendNeedsRepaintingInRect(parentLayerRect);
266 if (parentLayer->isRootLayer()) {
267 RenderView* view = toRenderView(parentLayer->renderer());
268 view->repaintViewRectangle(parentLayerRect);
272 ASSERT_NOT_REACHED();
275 RenderLayer* RenderLayerRepainter::enclosingFilterRepaintLayer() const
277 for (const RenderLayer* curr = m_renderer->layer(); curr; curr = curr->parent()) {
278 if ((curr != m_renderer->layer() && curr->requiresFullLayerImageForFilters()) || curr->compositingState() == PaintsIntoOwnBacking || curr->isRootLayer())
279 return const_cast<RenderLayer*>(curr);
284 } // Namespace WebCore