[iOS WK2] background-attachment:fixed behaves very poorly
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 May 2014 19:32:37 +0000 (19:32 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 May 2014 19:32:37 +0000 (19:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=132881
<rdar://problem/16789526>

Reviewed by Beth Dakin.

Source/WebCore:

Remove the old ENABLE_FAST_MOBILE_SCROLLING code, and add a setting that
controls whether fixed backgrounds paint relative to the document, which
is enabled for iOS (WK1 and WK2). This setting is consulted when we repaint
fixed backgrounds on scrolling, when we paint them, and when we decide to make
a layer for fixed backgrounds.

* page/Settings.cpp:
* page/Settings.in:
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::calculateBackgroundImageGeometry):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::styleWillChange):
(WebCore::RenderElement::willBeRemovedFromTree):
(WebCore::shouldRepaintFixedBackgroundsOnScroll): Deleted.
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::needsFixedRootBackgroundLayer):

Source/WTF:

Remove ENABLE_FAST_MOBILE_SCROLLING. Ports can use the fixedBackgroundsPaintRelativeToDocument
setting now.

* wtf/FeatureDefines.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@168726 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/FeatureDefines.h
Source/WebCore/ChangeLog
Source/WebCore/page/Settings.cpp
Source/WebCore/page/Settings.in
Source/WebCore/rendering/RenderBoxModelObject.cpp
Source/WebCore/rendering/RenderElement.cpp
Source/WebCore/rendering/RenderLayerCompositor.cpp

index b85b748..361d388 100644 (file)
@@ -1,3 +1,16 @@
+2014-05-13  Simon Fraser  <simon.fraser@apple.com>
+
+        [iOS WK2] background-attachment:fixed behaves very poorly
+        https://bugs.webkit.org/show_bug.cgi?id=132881
+        <rdar://problem/16789526>
+
+        Reviewed by Beth Dakin.
+        
+        Remove ENABLE_FAST_MOBILE_SCROLLING. Ports can use the fixedBackgroundsPaintRelativeToDocument
+        setting now.
+
+        * wtf/FeatureDefines.h:
+
 2014-05-08  Alexey Proskuryakov  <ap@apple.com>
 
         Automatically zip document bundles used via File API
index d0b38a5..9a4eebd 100644 (file)
 #define ENABLE_ENCRYPTED_MEDIA_V2 0
 #endif
 
-#if !defined(ENABLE_FAST_MOBILE_SCROLLING)
-#define ENABLE_FAST_MOBILE_SCROLLING 0
-#endif
-
 #if !defined(ENABLE_FILTERS)
 #define ENABLE_FILTERS 0
 #endif
index 6328894..a7101a0 100644 (file)
@@ -1,3 +1,28 @@
+2014-05-13  Simon Fraser  <simon.fraser@apple.com>
+
+        [iOS WK2] background-attachment:fixed behaves very poorly
+        https://bugs.webkit.org/show_bug.cgi?id=132881
+        <rdar://problem/16789526>
+
+        Reviewed by Beth Dakin.
+
+        Remove the old ENABLE_FAST_MOBILE_SCROLLING code, and add a setting that
+        controls whether fixed backgrounds paint relative to the document, which
+        is enabled for iOS (WK1 and WK2). This setting is consulted when we repaint
+        fixed backgrounds on scrolling, when we paint them, and when we decide to make
+        a layer for fixed backgrounds.
+        
+        * page/Settings.cpp:
+        * page/Settings.in:
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::calculateBackgroundImageGeometry):
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::styleWillChange):
+        (WebCore::RenderElement::willBeRemovedFromTree):
+        (WebCore::shouldRepaintFixedBackgroundsOnScroll): Deleted.
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::needsFixedRootBackgroundLayer):
+
 2014-05-13  Zalan Bujtas  <zalan@apple.com>
 
         REGRESSSION(r168528) Subpixel rendering: Selection rect is not positioned properly when SVG text is selected.
index 6c03449..514a5a1 100644 (file)
@@ -122,12 +122,14 @@ static EditingBehaviorType editingBehaviorTypeForPlatform()
 
 #if PLATFORM(IOS)
 static const bool defaultFixedPositionCreatesStackingContext = true;
+static const bool defaultFixedBackgroundsPaintRelativeToDocument = true;
 static const bool defaultAcceleratedCompositingForFixedPositionEnabled = true;
 static const bool defaultMediaPlaybackAllowsInline = false;
 static const bool defaultMediaPlaybackRequiresUserGesture = true;
 static const bool defaultShouldRespectImageOrientation = true;
 #else
 static const bool defaultFixedPositionCreatesStackingContext = false;
+static const bool defaultFixedBackgroundsPaintRelativeToDocument = false;
 static const bool defaultAcceleratedCompositingForFixedPositionEnabled = false;
 static const bool defaultMediaPlaybackAllowsInline = true;
 static const bool defaultMediaPlaybackRequiresUserGesture = false;
index d1dc8e6..2202e01 100644 (file)
@@ -187,6 +187,7 @@ selectTrailingWhitespaceEnabled initial=defaultSelectTrailingWhitespaceEnabled
 
 selectionIncludesAltImageText initial=true
 useLegacyBackgroundSizeShorthandBehavior initial=false
+fixedBackgroundsPaintRelativeToDocument initial=defaultFixedBackgroundsPaintRelativeToDocument
 
 minimumZoomFontSize type=float, initial=15, conditional=IOS_TEXT_AUTOSIZING
 
index ec47c88..57f63b7 100644 (file)
@@ -1082,17 +1082,6 @@ void RenderBoxModelObject::calculateBackgroundImageGeometry(const RenderLayerMod
     // destRect will be adjusted later if the background is non-repeating.
     // FIXME: transforms spec says that fixed backgrounds behave like scroll inside transforms. https://bugs.webkit.org/show_bug.cgi?id=15679
     bool fixedAttachment = fillLayer->attachment() == FixedBackgroundAttachment;
-    
-#if ENABLE(FAST_MOBILE_SCROLLING)
-    if (view().frameView().canBlitOnScroll()) {
-        // As a side effect of an optimization to blit on scroll, we do not honor the CSS
-        // property "background-attachment: fixed" because it may result in rendering
-        // artifacts. Note, these artifacts only appear if we are blitting on scroll of
-        // a page that has fixed background images.
-        fixedAttachment = false;
-    }
-#endif
-
     if (!fixedAttachment) {
         geometry.setDestRect(paintRect);
 
@@ -1127,12 +1116,17 @@ void RenderBoxModelObject::calculateBackgroundImageGeometry(const RenderLayerMod
     } else {
         geometry.setHasNonLocalGeometry();
 
-        LayoutRect viewportRect = view().viewRect();
-        if (fixedBackgroundPaintsInLocalCoordinates())
-            viewportRect.setLocation(LayoutPoint());
-        else
-            viewportRect.setLocation(toLayoutPoint(view().frameView().scrollOffsetForFixedPosition()));
-
+        LayoutRect viewportRect;
+        if (frame().settings().fixedBackgroundsPaintRelativeToDocument())
+            viewportRect = view().unscaledDocumentRect();
+        else {
+            viewportRect = view().viewRect();
+            if (fixedBackgroundPaintsInLocalCoordinates())
+                viewportRect.setLocation(LayoutPoint());
+            else
+                viewportRect.setLocation(toLayoutPoint(view().frameView().scrollOffsetForFixedPosition()));
+        }
+        
         if (paintContainer)
             viewportRect.moveBy(LayoutPoint(-paintContainer->localToAbsolute(FloatPoint())));
 
index c376bae..99b6f73 100644 (file)
@@ -57,6 +57,7 @@
 #include "RenderTheme.h"
 #include "RenderView.h"
 #include "SVGRenderSupport.h"
+#include "Settings.h"
 #include "StyleResolver.h"
 #include <wtf/MathExtras.h>
 #include <wtf/StackStats.h>
@@ -793,19 +794,6 @@ void RenderElement::propagateStyleToAnonymousChildren(StylePropagationType propa
     }
 }
 
-// On low-powered/mobile devices, preventing blitting on a scroll can cause noticeable delays
-// when scrolling a page with a fixed background image. As an optimization, assuming there are
-// no fixed positoned elements on the page, we can acclerate scrolling (via blitting) if we
-// ignore the CSS property "background-attachment: fixed".
-static bool shouldRepaintFixedBackgroundsOnScroll()
-{
-#if ENABLE(FAST_MOBILE_SCROLLING)
-    return false;
-#else
-    return true;
-#endif
-}
-
 static inline bool rendererHasBackground(const RenderElement* renderer)
 {
     return renderer && renderer->hasBackground();
@@ -879,27 +867,31 @@ void RenderElement::styleWillChange(StyleDifference diff, const RenderStyle& new
         s_noLongerAffectsParentBlock = false;
     }
 
-    bool repaintFixedBackgroundsOnScroll = shouldRepaintFixedBackgroundsOnScroll();
-
-    bool newStyleSlowScroll = repaintFixedBackgroundsOnScroll && newStyle.hasFixedBackgroundImage();
-    bool oldStyleSlowScroll = oldStyle && repaintFixedBackgroundsOnScroll && m_style->hasFixedBackgroundImage();
-    bool drawsRootBackground = isRoot() || (isBody() && !rendererHasBackground(document().documentElement()->renderer()));
-    if (drawsRootBackground && repaintFixedBackgroundsOnScroll) {
-        if (view().compositor().supportsFixedRootBackgroundCompositing()) {
-            if (newStyleSlowScroll && newStyle.hasEntirelyFixedBackground())
-                newStyleSlowScroll = false;
-
-            if (oldStyleSlowScroll && m_style->hasEntirelyFixedBackground())
-                oldStyleSlowScroll = false;
+    bool newStyleUsesFixedBackgrounds = newStyle.hasFixedBackgroundImage();
+    bool oldStyleUsesFixedBackgrounds = m_style->hasFixedBackgroundImage();
+    if (newStyleUsesFixedBackgrounds || oldStyleUsesFixedBackgrounds) {
+        bool repaintFixedBackgroundsOnScroll = !frame().settings().fixedBackgroundsPaintRelativeToDocument();
+
+        bool newStyleSlowScroll = repaintFixedBackgroundsOnScroll && newStyleUsesFixedBackgrounds;
+        bool oldStyleSlowScroll = oldStyle && repaintFixedBackgroundsOnScroll && oldStyleUsesFixedBackgrounds;
+        bool drawsRootBackground = isRoot() || (isBody() && !rendererHasBackground(document().documentElement()->renderer()));
+        if (drawsRootBackground && repaintFixedBackgroundsOnScroll) {
+            if (view().compositor().supportsFixedRootBackgroundCompositing()) {
+                if (newStyleSlowScroll && newStyle.hasEntirelyFixedBackground())
+                    newStyleSlowScroll = false;
+
+                if (oldStyleSlowScroll && m_style->hasEntirelyFixedBackground())
+                    oldStyleSlowScroll = false;
+            }
         }
-    }
 
-    if (oldStyleSlowScroll != newStyleSlowScroll) {
-        if (oldStyleSlowScroll)
-            view().frameView().removeSlowRepaintObject(this);
+        if (oldStyleSlowScroll != newStyleSlowScroll) {
+            if (oldStyleSlowScroll)
+                view().frameView().removeSlowRepaintObject(this);
 
-        if (newStyleSlowScroll)
-            view().frameView().addSlowRepaintObject(this);
+            if (newStyleSlowScroll)
+                view().frameView().addSlowRepaintObject(this);
+        }
     }
 
     if (isRoot() || isBody())
@@ -1002,8 +994,7 @@ void RenderElement::willBeRemovedFromTree()
         removeLayers(layer);
     }
 
-    bool repaintFixedBackgroundsOnScroll = shouldRepaintFixedBackgroundsOnScroll();
-    if (repaintFixedBackgroundsOnScroll && m_style->hasFixedBackgroundImage())
+    if (m_style->hasFixedBackgroundImage() && !frame().settings().fixedBackgroundsPaintRelativeToDocument())
         view().frameView().removeSlowRepaintObject(this);
 
     if (isOutOfFlowPositioned() && parent()->childrenInline())
index 4f308ec..ee67d72 100644 (file)
@@ -2720,6 +2720,9 @@ bool RenderLayerCompositor::needsFixedRootBackgroundLayer(const RenderLayer& lay
     if (&layer != m_renderView.layer())
         return false;
 
+    if (m_renderView.frameView().frame().settings().fixedBackgroundsPaintRelativeToDocument())
+        return false;
+
     return supportsFixedRootBackgroundCompositing() && m_renderView.rootBackgroundIsEntirelyFixed();
 }