Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RenderLayerRepainter.cpp
1 /*
2  * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3  *
4  * Portions are Copyright (C) 1998 Netscape Communications Corporation.
5  *
6  * Other contributors:
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>
14  *
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.
19  *
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.
24  *
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
28  *
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.
42  */
43
44 #include "config.h"
45 #include "core/rendering/RenderLayerRepainter.h"
46
47 #include "core/rendering/FilterEffectRenderer.h"
48 #include "core/rendering/RenderLayer.h"
49 #include "core/rendering/RenderView.h"
50 #include "core/rendering/compositing/CompositedLayerMapping.h"
51
52 namespace blink {
53
54 RenderLayerRepainter::RenderLayerRepainter(RenderLayerModelObject& renderer)
55     : m_renderer(renderer)
56 {
57 }
58
59 void RenderLayerRepainter::computePaintInvalidationRectsIncludingNonCompositingDescendants()
60 {
61     // FIXME: boundsRectForPaintInvalidation() has to walk up the parent chain
62     // for every layer to compute the rects. We should make this more efficient.
63     // FIXME: it's wrong to call this when layout is not up-to-date, which we do.
64     m_renderer.setPreviousPaintInvalidationRect(m_renderer.boundsRectForPaintInvalidation(m_renderer.containerForPaintInvalidation()));
65     // FIXME: We are only updating the paint invalidation bounds but not
66     // the positionFromPaintInvalidationContainer. This means that we may
67     // forcing a full invaliation of the new position. Is this really correct?
68
69     for (RenderLayer* layer = m_renderer.layer()->firstChild(); layer; layer = layer->nextSibling()) {
70         if (layer->compositingState() != PaintsIntoOwnBacking && layer->compositingState() != PaintsIntoGroupedBacking)
71             layer->paintInvalidator().computePaintInvalidationRectsIncludingNonCompositingDescendants();
72     }
73 }
74
75 // Since we're only painting non-composited layers, we know that they all share the same repaintContainer.
76 void RenderLayerRepainter::paintInvalidationIncludingNonCompositingDescendants()
77 {
78     repaintIncludingNonCompositingDescendantsInternal(m_renderer.containerForPaintInvalidation());
79 }
80
81 void RenderLayerRepainter::repaintIncludingNonCompositingDescendantsInternal(const RenderLayerModelObject* repaintContainer)
82 {
83     m_renderer.invalidatePaintUsingContainer(repaintContainer, m_renderer.previousPaintInvalidationRect(), InvalidationLayer);
84
85     // Disable for reading compositingState() below.
86     DisableCompositingQueryAsserts disabler;
87
88     for (RenderLayer* curr = m_renderer.layer()->firstChild(); curr; curr = curr->nextSibling()) {
89         if (curr->compositingState() != PaintsIntoOwnBacking && curr->compositingState() != PaintsIntoGroupedBacking)
90             curr->paintInvalidator().repaintIncludingNonCompositingDescendantsInternal(repaintContainer);
91     }
92 }
93
94 LayoutRect RenderLayerRepainter::repaintRectIncludingNonCompositingDescendants() const
95 {
96     LayoutRect repaintRect = m_renderer.previousPaintInvalidationRect();
97
98     for (RenderLayer* child = m_renderer.layer()->firstChild(); child; child = child->nextSibling()) {
99         // Don't include repaint rects for composited child layers; they will paint themselves and have a different origin.
100         if (child->compositingState() == PaintsIntoOwnBacking || child->compositingState() == PaintsIntoGroupedBacking)
101             continue;
102
103         repaintRect.unite(child->paintInvalidator().repaintRectIncludingNonCompositingDescendants());
104     }
105     return repaintRect;
106 }
107
108 void RenderLayerRepainter::setBackingNeedsRepaintInRect(const LayoutRect& r)
109 {
110     // https://bugs.webkit.org/show_bug.cgi?id=61159 describes an unreproducible crash here,
111     // so assert but check that the layer is composited.
112     ASSERT(m_renderer.compositingState() != NotComposited);
113     if (m_renderer.compositingState() == NotComposited) {
114         // If we're trying to repaint the placeholder document layer, propagate the
115         // repaint to the native view system.
116         LayoutRect absRect(r);
117         LayoutPoint delta;
118         m_renderer.layer()->convertToLayerCoords(m_renderer.layer()->root(), delta);
119         absRect.moveBy(delta);
120
121         if (absRect.isEmpty())
122             return;
123
124         RenderView* view = m_renderer.view();
125         if (view)
126             view->invalidatePaintForRectangle(absRect);
127         return;
128     }
129     // FIXME: generalize accessors to backing GraphicsLayers so that this code is squasphing-agnostic.
130     if (m_renderer.layer()->groupedMapping()) {
131         LayoutRect repaintRect = r;
132         repaintRect.move(m_renderer.layer()->subpixelAccumulation());
133         if (GraphicsLayer* squashingLayer = m_renderer.layer()->groupedMapping()->squashingLayer())
134             squashingLayer->setNeedsDisplayInRect(pixelSnappedIntRect(repaintRect));
135     } else {
136         m_renderer.layer()->compositedLayerMapping()->setContentsNeedDisplayInRect(r);
137     }
138 }
139
140 void RenderLayerRepainter::setFilterBackendNeedsRepaintingInRect(const LayoutRect& rect)
141 {
142     if (rect.isEmpty())
143         return;
144     LayoutRect rectForRepaint = rect;
145     m_renderer.style()->filterOutsets().expandRect(rectForRepaint);
146
147     ASSERT(m_renderer.layer()->filterInfo());
148
149     RenderLayer* parentLayer = enclosingFilterRepaintLayer();
150     ASSERT(parentLayer);
151     FloatQuad repaintQuad(rectForRepaint);
152     LayoutRect parentLayerRect = m_renderer.localToContainerQuad(repaintQuad, parentLayer->renderer()).enclosingBoundingBox();
153
154     if (parentLayerRect.isEmpty())
155         return;
156
157     if (parentLayer->hasCompositedLayerMapping()) {
158         parentLayer->paintInvalidator().setBackingNeedsRepaintInRect(parentLayerRect);
159         return;
160     }
161
162     if (parentLayer->paintsWithFilters()) {
163         parentLayer->paintInvalidator().setFilterBackendNeedsRepaintingInRect(parentLayerRect);
164         return;
165     }
166
167     if (parentLayer->isRootLayer()) {
168         RenderView* view = toRenderView(parentLayer->renderer());
169         view->invalidatePaintForRectangle(parentLayerRect);
170         return;
171     }
172
173     ASSERT_NOT_REACHED();
174 }
175
176 RenderLayer* RenderLayerRepainter::enclosingFilterRepaintLayer() const
177 {
178     for (const RenderLayer* curr = m_renderer.layer(); curr; curr = curr->parent()) {
179         if ((curr != m_renderer.layer() && curr->requiresFullLayerImageForFilters()) || curr->compositingState() == PaintsIntoOwnBacking || curr->isRootLayer())
180             return const_cast<RenderLayer*>(curr);
181     }
182     return 0;
183 }
184
185 } // namespace blink