- Revision
- 151624
- Author
- [email protected]
- Date
- 2013-06-16 16:32:22 -0700 (Sun, 16 Jun 2013)
Log Message
Fixed backgrounds in composited layers not repainted on scrolling
https://bugs.webkit.org/show_bug.cgi?id=117684
Source/WebCore:
Reviewed by Tim Horton.
FrameView is aware that "slow-repaint objects" (i.e. renderers with
background-attachment:fixed) require a slow-scrolling path. However,
it was ignorant of the fact that such objects could be painting into
compositing layers; it simply dirtied the main tiles, and nothing else.
Fix by having FrameView track the slow-repaints objects explicitly, as we
do for position:fixed, and repaint each of them on scrolling.
Test: compositing/repaint/fixed-background-scroll.html
* page/FrameView.cpp:
(WebCore::FrameView::FrameView): No need to initialize m_slowRepaintObjectCount,
which is now an OwnPtr<RenderObjectSet>.
(WebCore::FrameView::useSlowRepaints): Use hasSlowRepaintObjects() now.
(WebCore::FrameView::addSlowRepaintObject): Now adds the object to a set,
allocating the set if necessary.
(WebCore::FrameView::removeSlowRepaintObject): Remove the object from the set,
and deallocate the set if empty.
(WebCore::FrameView::scrollContentsSlowPath): Call repaintSlowRepaintObjects();
this is the change that fixes the bug for always-composited implementations (e.g.
tile cache). This is a conservative change; we still invalidate the tile cache
as well. This could be optimized later.
(WebCore::FrameView::repaintSlowRepaintObjects): Repaint each object in the set.
Their appropriate compositing ancestor will be repainted.
(WebCore::FrameView::scrollPositionChangedViaPlatformWidget): Call
repaintSlowRepaintObjects() so that fixed backgrounds in composited layers are
correctly repainted; this fixes the bug for WebKit1.
* page/FrameView.h: Replace m_slowRepaintObjectCount with a HashSet of
RenderObjects.
(WebCore::FrameView::hasSlowRepaintObject): Takes a RenderObject* now.
(WebCore::FrameView::hasSlowRepaintObjects): Ditto.
* rendering/RenderObject.cpp:
(WebCore::RenderObject::styleWillChange): Pass the RenderObject.
(WebCore::RenderObject::willBeDestroyed): Assert that this RenderObject
has been removed from FrameView's set of slow-repaint objects already, if
the document is not being destroyed.
(WebCore::RenderObject::willBeRemovedFromTree): Pass the RenderObject.
LayoutTests:
Reviewed by Tim Horton.
Test that verifies that a composited layer with a fixed background is repainted
on scrolling.
* compositing/repaint/fixed-background-scroll-expected.txt: Added.
* compositing/repaint/fixed-background-scroll.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (151623 => 151624)
--- trunk/LayoutTests/ChangeLog 2013-06-16 17:24:40 UTC (rev 151623)
+++ trunk/LayoutTests/ChangeLog 2013-06-16 23:32:22 UTC (rev 151624)
@@ -1,3 +1,16 @@
+2013-06-16 Simon Fraser <[email protected]>
+
+ Fixed backgrounds in composited layers not repainted on scrolling
+ https://bugs.webkit.org/show_bug.cgi?id=117684
+
+ Reviewed by Tim Horton.
+
+ Test that verifies that a composited layer with a fixed background is repainted
+ on scrolling.
+
+ * compositing/repaint/fixed-background-scroll-expected.txt: Added.
+ * compositing/repaint/fixed-background-scroll.html: Added.
+
2013-06-15 Simon Fraser <[email protected]>
Fixed background images behave strangely with webkit transitions
Added: trunk/LayoutTests/compositing/repaint/fixed-background-scroll-expected.txt (0 => 151624)
--- trunk/LayoutTests/compositing/repaint/fixed-background-scroll-expected.txt (rev 0)
+++ trunk/LayoutTests/compositing/repaint/fixed-background-scroll-expected.txt 2013-06-16 23:32:22 UTC (rev 151624)
@@ -0,0 +1,20 @@
+(GraphicsLayer
+ (bounds 785.00 2021.00)
+ (children 1
+ (GraphicsLayer
+ (bounds 785.00 2021.00)
+ (contentsOpaque 1)
+ (children 1
+ (GraphicsLayer
+ (position -4.00 96.00)
+ (bounds 428.00 428.00)
+ (drawsContent 1)
+ (repaint rects
+ (rect 0.00 0.00 428.00 428.00)
+ )
+ )
+ )
+ )
+ )
+)
+
Added: trunk/LayoutTests/compositing/repaint/fixed-background-scroll.html (0 => 151624)
--- trunk/LayoutTests/compositing/repaint/fixed-background-scroll.html (rev 0)
+++ trunk/LayoutTests/compositing/repaint/fixed-background-scroll.html 2013-06-16 23:32:22 UTC (rev 151624)
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+ <style>
+ body {
+ height: 2000px;
+ }
+ .box {
+ position: absolute;
+ top: 110px;
+ left: 10px;
+ width: 400px;
+ height: 400px;
+ background-image: url('../resources/alpha-blocks.png');
+ background-attachment: fixed;
+ background-size: 200px 200px;
+ box-shadow: 0 0 10px black;
+ }
+
+ .composited {
+ -webkit-transform: translateZ(0);
+ }
+ </style>
+ <script>
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+
+ function test()
+ {
+ window.setTimeout(function() {
+ document.body.offsetTop;
+ if (window.internals)
+ window.internals.startTrackingRepaints(document);
+
+ window.scrollTo(0, 100);
+
+ if (window.internals)
+ document.getElementById('repaintRects').textContent = window.internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_REPAINT_RECTS);
+
+ if (window.testRunner)
+ testRunner.notifyDone();
+ }, 0);
+ }
+ window.addEventListener('load', test, false);
+ </script>
+</head>
+<body>
+
+ <div id="box" class="composited box"></div>
+ <pre id="repaintRects"></pre>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (151623 => 151624)
--- trunk/Source/WebCore/ChangeLog 2013-06-16 17:24:40 UTC (rev 151623)
+++ trunk/Source/WebCore/ChangeLog 2013-06-16 23:32:22 UTC (rev 151624)
@@ -1,3 +1,48 @@
+2013-06-16 Simon Fraser <[email protected]>
+
+ Fixed backgrounds in composited layers not repainted on scrolling
+ https://bugs.webkit.org/show_bug.cgi?id=117684
+
+ Reviewed by Tim Horton.
+
+ FrameView is aware that "slow-repaint objects" (i.e. renderers with
+ background-attachment:fixed) require a slow-scrolling path. However,
+ it was ignorant of the fact that such objects could be painting into
+ compositing layers; it simply dirtied the main tiles, and nothing else.
+
+ Fix by having FrameView track the slow-repaints objects explicitly, as we
+ do for position:fixed, and repaint each of them on scrolling.
+
+ Test: compositing/repaint/fixed-background-scroll.html
+
+ * page/FrameView.cpp:
+ (WebCore::FrameView::FrameView): No need to initialize m_slowRepaintObjectCount,
+ which is now an OwnPtr<RenderObjectSet>.
+ (WebCore::FrameView::useSlowRepaints): Use hasSlowRepaintObjects() now.
+ (WebCore::FrameView::addSlowRepaintObject): Now adds the object to a set,
+ allocating the set if necessary.
+ (WebCore::FrameView::removeSlowRepaintObject): Remove the object from the set,
+ and deallocate the set if empty.
+ (WebCore::FrameView::scrollContentsSlowPath): Call repaintSlowRepaintObjects();
+ this is the change that fixes the bug for always-composited implementations (e.g.
+ tile cache). This is a conservative change; we still invalidate the tile cache
+ as well. This could be optimized later.
+ (WebCore::FrameView::repaintSlowRepaintObjects): Repaint each object in the set.
+ Their appropriate compositing ancestor will be repainted.
+ (WebCore::FrameView::scrollPositionChangedViaPlatformWidget): Call
+ repaintSlowRepaintObjects() so that fixed backgrounds in composited layers are
+ correctly repainted; this fixes the bug for WebKit1.
+ * page/FrameView.h: Replace m_slowRepaintObjectCount with a HashSet of
+ RenderObjects.
+ (WebCore::FrameView::hasSlowRepaintObject): Takes a RenderObject* now.
+ (WebCore::FrameView::hasSlowRepaintObjects): Ditto.
+ * rendering/RenderObject.cpp:
+ (WebCore::RenderObject::styleWillChange): Pass the RenderObject.
+ (WebCore::RenderObject::willBeDestroyed): Assert that this RenderObject
+ has been removed from FrameView's set of slow-repaint objects already, if
+ the document is not being destroyed.
+ (WebCore::RenderObject::willBeRemovedFromTree): Pass the RenderObject.
+
2013-06-15 Simon Fraser <[email protected]>
Painting of fixed background images is wrong in composited layers
Modified: trunk/Source/WebCore/page/FrameView.cpp (151623 => 151624)
--- trunk/Source/WebCore/page/FrameView.cpp 2013-06-16 17:24:40 UTC (rev 151623)
+++ trunk/Source/WebCore/page/FrameView.cpp 2013-06-16 23:32:22 UTC (rev 151624)
@@ -172,7 +172,6 @@
FrameView::FrameView(Frame* frame)
: m_frame(frame)
, m_canHaveScrollbars(true)
- , m_slowRepaintObjectCount(0)
, m_layoutTimer(this, &FrameView::layoutTimerFired)
, m_layoutRoot(0)
, m_inSynchronousPostLayout(false)
@@ -1482,7 +1481,7 @@
bool FrameView::useSlowRepaints(bool considerOverlap) const
{
- bool mustBeSlow = m_slowRepaintObjectCount > 0 || (platformWidget() && hasViewportConstrainedObjects());
+ bool mustBeSlow = hasSlowRepaintObjects() || (platformWidget() && hasViewportConstrainedObjects());
// FIXME: WidgetMac.mm makes the assumption that useSlowRepaints ==
// m_contentIsOpaque, so don't take the fast path for composited layers
@@ -1534,9 +1533,16 @@
updateCanBlitOnScrollRecursively();
}
-void FrameView::addSlowRepaintObject()
+void FrameView::addSlowRepaintObject(RenderObject* o)
{
- if (!m_slowRepaintObjectCount++) {
+ bool hadSlowRepaintObjects = hasSlowRepaintObjects();
+
+ if (!m_slowRepaintObjects)
+ m_slowRepaintObjects = adoptPtr(new RenderObjectSet);
+
+ m_slowRepaintObjects->add(o);
+
+ if (!hadSlowRepaintObjects) {
updateCanBlitOnScrollRecursively();
if (Page* page = m_frame->page()) {
@@ -1546,11 +1552,14 @@
}
}
-void FrameView::removeSlowRepaintObject()
+void FrameView::removeSlowRepaintObject(RenderObject* o)
{
- ASSERT(m_slowRepaintObjectCount > 0);
- m_slowRepaintObjectCount--;
- if (!m_slowRepaintObjectCount) {
+ ASSERT(m_slowRepaintObjects);
+ ASSERT(m_slowRepaintObjects->contains(o));
+
+ m_slowRepaintObjects->remove(o);
+ if (m_slowRepaintObjects->isEmpty()) {
+ m_slowRepaintObjects = nullptr;
updateCanBlitOnScrollRecursively();
if (Page* page = m_frame->page()) {
@@ -1734,6 +1743,9 @@
ASSERT(renderView());
renderView()->layer()->setBackingNeedsRepaintInRect(updateRect);
}
+
+ repaintSlowRepaintObjects();
+
if (RenderPart* frameRenderer = m_frame->ownerRenderer()) {
if (isEnclosedInCompositingLayer()) {
LayoutRect rect(frameRenderer->borderLeft() + frameRenderer->paddingLeft(),
@@ -1748,6 +1760,20 @@
ScrollView::scrollContentsSlowPath(updateRect);
}
+void FrameView::repaintSlowRepaintObjects()
+{
+ if (!m_slowRepaintObjects)
+ return;
+
+ // Renderers with fixed backgrounds may be in compositing layers, so we need to explicitly
+ // repaint them after scrolling.
+ RenderObjectSet::const_iterator end = m_slowRepaintObjects->end();
+ for (RenderObjectSet::const_iterator it = m_slowRepaintObjects->begin(); it != end; ++it) {
+ RenderObject* renderer = *it;
+ renderer->repaint();
+ }
+}
+
// Note that this gets called at painting time.
void FrameView::setIsOverlapped(bool isOverlapped)
{
@@ -1951,11 +1977,11 @@
}
}
-
void FrameView::scrollPositionChangedViaPlatformWidget()
{
repaintFixedElementsAfterScrolling();
updateFixedElementsAfterScrolling();
+ repaintSlowRepaintObjects();
scrollPositionChanged();
}
@@ -1972,6 +1998,7 @@
#endif
}
+// FIXME: this function is misnamed; its primary purpose is to update RenderLayer positions.
void FrameView::repaintFixedElementsAfterScrolling()
{
// For fixed position elements, update widget positions and compositing layers after scrolling,
Modified: trunk/Source/WebCore/page/FrameView.h (151623 => 151624)
--- trunk/Source/WebCore/page/FrameView.h 2013-06-16 17:24:40 UTC (rev 151623)
+++ trunk/Source/WebCore/page/FrameView.h 2013-06-16 23:32:22 UTC (rev 151624)
@@ -212,9 +212,10 @@
bool isOverlappedIncludingAncestors() const;
void setContentIsOpaque(bool);
- void addSlowRepaintObject();
- void removeSlowRepaintObject();
- bool hasSlowRepaintObjects() const { return m_slowRepaintObjectCount; }
+ void addSlowRepaintObject(RenderObject*);
+ void removeSlowRepaintObject(RenderObject*);
+ bool hasSlowRepaintObject(RenderObject* o) const { return m_slowRepaintObjects && m_slowRepaintObjects->contains(o); }
+ bool hasSlowRepaintObjects() const { return m_slowRepaintObjects && m_slowRepaintObjects->size(); }
// Includes fixed- and sticky-position objects.
typedef HashSet<RenderObject*> ViewportConstrainedObjectSet;
@@ -435,6 +436,8 @@
protected:
virtual bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect);
virtual void scrollContentsSlowPath(const IntRect& updateRect);
+
+ void repaintSlowRepaintObjects();
virtual bool isVerticalDocument() const;
virtual bool isFlippedDocument() const;
@@ -540,13 +543,15 @@
OwnPtr<RenderObjectSet> m_widgetUpdateSet;
RefPtr<Frame> m_frame;
+ OwnPtr<RenderObjectSet> m_slowRepaintObjects;
+
bool m_doFullRepaint;
bool m_canHaveScrollbars;
bool m_cannotBlitToWindow;
bool m_isOverlapped;
bool m_contentIsOpaque;
- unsigned m_slowRepaintObjectCount;
+
int m_borderX;
int m_borderY;
Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (151623 => 151624)
--- trunk/Source/WebCore/rendering/RenderObject.cpp 2013-06-16 17:24:40 UTC (rev 151623)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp 2013-06-16 23:32:22 UTC (rev 151624)
@@ -1973,10 +1973,10 @@
#endif
if (oldStyleSlowScroll != newStyleSlowScroll) {
if (oldStyleSlowScroll)
- frameView->removeSlowRepaintObject();
+ frameView->removeSlowRepaintObject(this);
if (newStyleSlowScroll)
- frameView->addSlowRepaintObject();
+ frameView->addSlowRepaintObject(this);
}
}
}
@@ -2443,6 +2443,8 @@
animation()->cancelAnimations(this);
+ ASSERT(documentBeingDestroyed() || !frame()->view()->hasSlowRepaintObject(this));
+
// For accessibility management, notify the parent of the imminent change to its child set.
// We do it now, before remove(), while the parent pointer is still available.
if (AXObjectCache* cache = document()->existingAXObjectCache())
@@ -2523,7 +2525,7 @@
if (FrameView* frameView = view()->frameView()) {
bool repaintFixedBackgroundsOnScroll = shouldRepaintFixedBackgroundsOnScroll(frameView);
if (repaintFixedBackgroundsOnScroll && m_style && m_style->hasFixedBackgroundImage())
- frameView->removeSlowRepaintObject();
+ frameView->removeSlowRepaintObject(this);
}
}