REGRESSION (r238090): Toggling visibility on the <html> element can result in a blank...
[WebKit-https.git] / Source / WebCore / rendering / RenderLayerBacking.h
index 2a0cb54..71ba37f 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef RenderLayerBacking_h
-#define RenderLayerBacking_h
+#pragma once
 
 #include "FloatPoint.h"
 #include "FloatPoint3D.h"
 #include "GraphicsLayer.h"
 #include "GraphicsLayerClient.h"
 #include "RenderLayer.h"
+#include "RenderLayerCompositor.h"
 #include "ScrollingCoordinator.h"
 
 namespace WebCore {
 
 class KeyframeList;
+class PaintedContentsInfo;
 class RenderLayerCompositor;
 class TiledBacking;
 class TransformationMatrix;
@@ -59,20 +60,17 @@ public:
     explicit RenderLayerBacking(RenderLayer&);
     ~RenderLayerBacking();
 
-#if PLATFORM(IOS)
+#if PLATFORM(IOS_FAMILY)
     void layerWillBeDestroyed();
 #endif
 
+    // Do cleanup while layer->backing() is still valid.
+    void willBeDestroyed();
+
     RenderLayer& owningLayer() const { return m_owningLayer; }
 
-    enum UpdateAfterLayoutFlag {
-        CompositingChildrenOnly = 1 << 0,
-        NeedsFullRepaint = 1 << 1,
-        IsUpdateRoot = 1 << 2
-    };
-    typedef unsigned UpdateAfterLayoutFlags;
-    void updateAfterLayout(UpdateAfterLayoutFlags);
-    
+    void updateConfigurationAfterStyleChange();
+
     // Returns true if layer configuration changed.
     bool updateConfiguration();
 
@@ -85,11 +83,13 @@ public:
     // Update contents and clipping structure.
     void updateDrawsContent();
     
+    void updateAfterLayout(bool needsFullRepaint);
+    
     GraphicsLayer* graphicsLayer() const { return m_graphicsLayer.get(); }
 
     // Layer to clip children
-    bool hasClippingLayer() const { return (m_childContainmentLayer && !m_usingTiledCacheLayer); }
-    GraphicsLayer* clippingLayer() const { return !m_usingTiledCacheLayer ? m_childContainmentLayer.get() : nullptr; }
+    bool hasClippingLayer() const { return (m_childContainmentLayer && !m_isFrameLayerWithTiledBacking); }
+    GraphicsLayer* clippingLayer() const { return !m_isFrameLayerWithTiledBacking ? m_childContainmentLayer.get() : nullptr; }
 
     // Layer to get clipped by ancestor
     bool hasAncestorClippingLayer() const { return m_ancestorClippingLayer != nullptr; }
@@ -100,42 +100,55 @@ public:
     GraphicsLayer* foregroundLayer() const { return m_foregroundLayer.get(); }
     GraphicsLayer* backgroundLayer() const { return m_backgroundLayer.get(); }
     bool backgroundLayerPaintsFixedRootBackground() const { return m_backgroundLayerPaintsFixedRootBackground; }
-    
-    bool hasScrollingLayer() const { return m_scrollingLayer != nullptr; }
-    GraphicsLayer* scrollingLayer() const { return m_scrollingLayer.get(); }
-    GraphicsLayer* scrollingContentsLayer() const { return m_scrollingContentsLayer.get(); }
 
-    void detachFromScrollingCoordinator(LayerScrollCoordinationRoles);
-    
-    ScrollingNodeID scrollingNodeIDForRole(LayerScrollCoordinationRole role) const
+    bool requiresBackgroundLayer() const { return m_requiresBackgroundLayer; }
+    void setRequiresBackgroundLayer(bool);
+
+    bool hasScrollingLayer() const { return m_scrollContainerLayer != nullptr; }
+    GraphicsLayer* scrollContainerLayer() const { return m_scrollContainerLayer.get(); }
+    GraphicsLayer* scrolledContentsLayer() const { return m_scrolledContentsLayer.get(); }
+
+    OptionSet<ScrollCoordinationRole> coordinatedScrollingRoles() const;
+
+    void detachFromScrollingCoordinator(OptionSet<ScrollCoordinationRole>);
+
+    ScrollingNodeID scrollingNodeIDForRole(ScrollCoordinationRole role) const
     {
         switch (role) {
-        case Scrolling:
+        case ScrollCoordinationRole::Scrolling:
             return m_scrollingNodeID;
-        case ViewportConstrained:
+        case ScrollCoordinationRole::FrameHosting:
+            return m_frameHostingNodeID;
+        case ScrollCoordinationRole::ViewportConstrained:
             return m_viewportConstrainedNodeID;
         }
         return 0;
     }
-    
-    void setScrollingNodeIDForRole(ScrollingNodeID nodeID, LayerScrollCoordinationRole role)
+
+    void setScrollingNodeIDForRole(ScrollingNodeID nodeID, ScrollCoordinationRole role)
     {
         switch (role) {
-        case Scrolling:
+        case ScrollCoordinationRole::Scrolling:
             m_scrollingNodeID = nodeID;
             break;
-        case ViewportConstrained:
+        case ScrollCoordinationRole::FrameHosting:
+            m_frameHostingNodeID = nodeID;
+            break;
+        case ScrollCoordinationRole::ViewportConstrained:
             m_viewportConstrainedNodeID = nodeID;
             setIsScrollCoordinatedWithViewportConstrainedRole(nodeID);
             break;
         }
     }
-    
-    ScrollingNodeID scrollingNodeIDForChildren() const { return m_scrollingNodeID ? m_scrollingNodeID : m_viewportConstrainedNodeID; }
+
+    ScrollingNodeID scrollingNodeIDForChildren() const
+    {
+        return m_frameHostingNodeID ? m_frameHostingNodeID : (m_scrollingNodeID ? m_scrollingNodeID : m_viewportConstrainedNodeID);
+    }
 
     void setIsScrollCoordinatedWithViewportConstrainedRole(bool);
 
-    bool hasMaskLayer() const { return m_maskLayer != 0; }
+    bool hasMaskLayer() const { return m_maskLayer; }
     bool hasChildClippingMaskLayer() const { return m_childClippingMaskLayer != nullptr; }
 
     GraphicsLayer* parentForSublayers() const;
@@ -169,58 +182,67 @@ public:
 
     bool startAnimation(double timeOffset, const Animation* anim, const KeyframeList& keyframes);
     void animationPaused(double timeOffset, const String& name);
+    void animationSeeked(double timeOffset, const String& name);
     void animationFinished(const String& name);
 
-    void suspendAnimations(double time = 0);
+    void suspendAnimations(MonotonicTime = MonotonicTime());
     void resumeAnimations();
 
     LayoutRect compositedBounds() const;
-    void setCompositedBounds(const LayoutRect&);
-    void updateCompositedBounds();
+    // Returns true if changed.
+    bool setCompositedBounds(const LayoutRect&);
+    // Returns true if changed.
+    bool updateCompositedBounds();
     
     void updateAfterWidgetResize();
     void positionOverflowControlsLayers();
-    bool hasUnpositionedOverflowControlsLayers() const;
+    
+    bool isFrameLayerWithTiledBacking() const { return m_isFrameLayerWithTiledBacking; }
 
-    bool usingTiledBacking() const { return m_usingTiledCacheLayer; }
     WEBCORE_EXPORT TiledBacking* tiledBacking() const;
     void adjustTiledBackingCoverage();
     void setTiledBackingHasMargins(bool hasExtendedBackgroundOnLeftAndRight, bool hasExtendedBackgroundOnTopAndBottom);
     
     void updateDebugIndicators(bool showBorder, bool showRepaintCounter);
+    bool paintsSubpixelAntialiasedText() const { return m_paintsSubpixelAntialiasedText; }
 
     // GraphicsLayerClient interface
-    virtual void tiledBackingUsageChanged(const GraphicsLayer*, bool /*usingTiledBacking*/) override;
-    virtual void notifyAnimationStarted(const GraphicsLayer*, const String& animationKey, double startTime) override;
-    virtual void notifyFlushRequired(const GraphicsLayer*) override;
-    virtual void notifyFlushBeforeDisplayRefresh(const GraphicsLayer*) override;
+    void tiledBackingUsageChanged(const GraphicsLayer*, bool /*usingTiledBacking*/) override;
+    void notifyAnimationStarted(const GraphicsLayer*, const String& animationKey, MonotonicTime startTime) override;
+    void notifyFlushRequired(const GraphicsLayer*) override;
+    void notifyFlushBeforeDisplayRefresh(const GraphicsLayer*) override;
 
-    virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const FloatRect& clip) override;
+    void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const FloatRect& clip, GraphicsLayerPaintBehavior) override;
 
-    virtual float deviceScaleFactor() const override;
-    virtual float contentsScaleMultiplierForNewTiles(const GraphicsLayer*) const override;
+    float deviceScaleFactor() const override;
+    float contentsScaleMultiplierForNewTiles(const GraphicsLayer*) const override;
 
-    virtual bool paintsOpaquelyAtNonIntegralScales(const GraphicsLayer*) const override;
+    bool paintsOpaquelyAtNonIntegralScales(const GraphicsLayer*) const override;
 
-    virtual float pageScaleFactor() const override;
-    virtual float zoomedOutPageScaleFactor() const override;
-    virtual void didCommitChangesForLayer(const GraphicsLayer*) const override;
-    virtual bool getCurrentTransform(const GraphicsLayer*, TransformationMatrix&) const override;
+    float pageScaleFactor() const override;
+    float zoomedOutPageScaleFactor() const override;
 
-    virtual bool isTrackingRepaints() const override;
-    virtual bool shouldSkipLayerInDump(const GraphicsLayer*, LayerTreeAsTextBehavior) const override;
-    virtual bool shouldDumpPropertyForLayer(const GraphicsLayer*, const char* propertyName) const override;
+    void didChangePlatformLayerForLayer(const GraphicsLayer*) override;
+    bool getCurrentTransform(const GraphicsLayer*, TransformationMatrix&) const override;
 
-    virtual bool shouldAggressivelyRetainTiles(const GraphicsLayer*) const override;
-    virtual bool shouldTemporarilyRetainTileCohorts(const GraphicsLayer*) const override;
-    virtual bool needsPixelAligment() const override { return !m_isMainFrameRenderViewLayer; }
+    bool isTrackingRepaints() const override;
+    bool shouldSkipLayerInDump(const GraphicsLayer*, LayerTreeAsTextBehavior) const override;
+    bool shouldDumpPropertyForLayer(const GraphicsLayer*, const char* propertyName, LayerTreeAsTextBehavior) const override;
 
-#if PLATFORM(IOS)
-    virtual bool needsIOSDumpRenderTreeMainFrameRenderViewLayerIsAlwaysOpaqueHack(const GraphicsLayer&) const override;
+    bool shouldAggressivelyRetainTiles(const GraphicsLayer*) const override;
+    bool shouldTemporarilyRetainTileCohorts(const GraphicsLayer*) const override;
+    bool useGiantTiles() const override;
+    void logFilledVisibleFreshTile(unsigned) override;
+    bool needsPixelAligment() const override { return !m_isMainFrameRenderViewLayer; }
+
+    LayoutSize subpixelOffsetFromRenderer() const { return m_subpixelOffsetFromRenderer; }
+
+#if PLATFORM(IOS_FAMILY)
+    bool needsIOSDumpRenderTreeMainFrameRenderViewLayerIsAlwaysOpaqueHack(const GraphicsLayer&) const override;
 #endif
 
 #ifndef NDEBUG
-    virtual void verifyNotPainting() override;
+    void verifyNotPainting() override;
 #endif
 
     WEBCORE_EXPORT LayoutRect contentsBox() const;
@@ -239,11 +261,18 @@ public:
 
     // Return an estimate of the backing store area (in pixels) allocated by this object's GraphicsLayers.
     WEBCORE_EXPORT double backingStoreMemoryEstimate() const;
+    
+    // For testing only.
+    WEBCORE_EXPORT void setUsesDisplayListDrawing(bool);
+    WEBCORE_EXPORT String displayListAsText(DisplayList::AsTextFlags) const;
 
-    LayoutSize devicePixelFractionFromRenderer() const { return m_devicePixelFractionFromRenderer; }
+    WEBCORE_EXPORT void setIsTrackingDisplayListReplay(bool);
+    WEBCORE_EXPORT String replayDisplayListAsText(DisplayList::AsTextFlags) const;
 
 private:
-    FloatRect backgroundBoxForPainting() const;
+    friend class PaintedContentsInfo;
+
+    FloatRect backgroundBoxForSimpleContainerPainting() const;
 
     void createPrimaryGraphicsLayer();
     void destroyGraphicsLayers();
@@ -252,9 +281,10 @@ private:
 
     LayoutRect compositedBoundsIncludingMargin() const;
     
-    std::unique_ptr<GraphicsLayer> createGraphicsLayer(const String&, GraphicsLayer::Type = GraphicsLayer::Type::Normal);
+    Ref<GraphicsLayer> createGraphicsLayer(const String&, GraphicsLayer::Type = GraphicsLayer::Type::Normal);
 
     RenderLayerModelObject& renderer() const { return m_owningLayer.renderer(); }
+    RenderBox* renderBox() const { return m_owningLayer.renderBox(); }
     RenderLayerCompositor& compositor() const { return m_owningLayer.compositor(); }
 
     void updateInternalHierarchy();
@@ -268,7 +298,10 @@ private:
     bool requiresVerticalScrollbarLayer() const;
     bool requiresScrollCornerLayer() const;
     bool updateScrollingLayers(bool scrollingLayers);
-    void updateDrawsContent(bool isSimpleContainer);
+    
+    void updateScrollOffset(ScrollOffset);
+    void setLocationOfScrolledContents(ScrollOffset, ScrollingLayerPositionAction);
+
     void updateChildClippingStrategy(bool needsDescendantsClippingLayer);
 
     void updateMaskingLayerGeometry();
@@ -297,75 +330,83 @@ private:
 
     // Return the opacity value that this layer should use for compositing.
     float compositingOpacity(float rendererOpacity) const;
-    
+    Color rendererBackgroundColor() const;
+
     bool isMainFrameRenderViewLayer() const;
     
     bool paintsBoxDecorations() const;
-    bool paintsChildren() const;
+    bool paintsContent(RenderLayer::PaintedContentRequest&) const;
+
+    void updateDrawsContent(PaintedContentsInfo&);
 
     // Returns true if this compositing layer has no visible content.
-    bool isSimpleContainerCompositingLayer() const;
+    bool isSimpleContainerCompositingLayer(PaintedContentsInfo&) const;
     // Returns true if this layer has content that needs to be rendered by painting into the backing store.
-    bool containsPaintedContent(bool isSimpleContainer) const;
+    bool containsPaintedContent(PaintedContentsInfo&) const;
     // Returns true if the RenderLayer just contains an image that we can composite directly.
     bool isDirectlyCompositedImage() const;
-    void updateImageContents();
+    void updateImageContents(PaintedContentsInfo&);
 
-    Color rendererBackgroundColor() const;
-    void updateDirectlyCompositedBackgroundColor(bool isSimpleContainer, bool& didUpdateContentsRect);
-    void updateDirectlyCompositedBackgroundImage(bool isSimpleContainer, bool& didUpdateContentsRect);
-    void updateDirectlyCompositedContents(bool isSimpleContainer, bool& didUpdateContentsRect);
+    void updateDirectlyCompositedBoxDecorations(PaintedContentsInfo&, bool& didUpdateContentsRect);
+    void updateDirectlyCompositedBackgroundColor(PaintedContentsInfo&, bool& didUpdateContentsRect);
+    void updateDirectlyCompositedBackgroundImage(PaintedContentsInfo&, bool& didUpdateContentsRect);
 
     void resetContentsRect();
 
-    bool isPaintDestinationForDescendantLayers() const;
+    bool isPaintDestinationForDescendantLayers(RenderLayer::PaintedContentRequest&) const;
+    bool hasVisibleNonCompositedDescendants() const;
 
     bool shouldClipCompositedBounds() const;
 
-    bool hasTiledBackingFlatteningLayer() const { return (m_childContainmentLayer && m_usingTiledCacheLayer); }
-    GraphicsLayer* tileCacheFlatteningLayer() const { return m_usingTiledCacheLayer ? m_childContainmentLayer.get() : nullptr; }
+    bool hasTiledBackingFlatteningLayer() const { return (m_childContainmentLayer && m_isFrameLayerWithTiledBacking); }
+    GraphicsLayer* tileCacheFlatteningLayer() const { return m_isFrameLayerWithTiledBacking ? m_childContainmentLayer.get() : nullptr; }
 
-    void paintIntoLayer(const GraphicsLayer*, GraphicsContext*, const IntRect& paintDirtyRect, PaintBehavior, GraphicsLayerPaintingPhase);
-
-    // Helper function for updateGeometry.
-    void adjustAncestorCompositingBoundsForFlowThread(LayoutRect& ancestorCompositingBounds, const RenderLayer* compositingAncestor) const;
+    void paintIntoLayer(const GraphicsLayer*, GraphicsContext&, const IntRect& paintDirtyRect, OptionSet<PaintBehavior>, GraphicsLayerPaintingPhase);
 
     static CSSPropertyID graphicsLayerToCSSProperty(AnimatedPropertyID);
     static AnimatedPropertyID cssToGraphicsLayerProperty(CSSPropertyID);
 
-    RenderLayer& m_owningLayer;
+    bool canIssueSetNeedsDisplay() const { return !paintsIntoWindow() && !paintsIntoCompositedAncestor(); }
+    LayoutRect computeParentGraphicsLayerRect(RenderLayer* compositedAncestor, LayoutSize& ancestorClippingLayerOffset) const;
+    LayoutRect computePrimaryGraphicsLayerRect(const LayoutRect& parentGraphicsLayerRect) const;
 
-    std::unique_ptr<GraphicsLayer> m_ancestorClippingLayer; // Only used if we are clipped by an ancestor which is not a stacking context.
-    std::unique_ptr<GraphicsLayer> m_contentsContainmentLayer; // Only used if we have a background layer; takes the transform.
-    std::unique_ptr<GraphicsLayer> m_graphicsLayer;
-    std::unique_ptr<GraphicsLayer> m_foregroundLayer; // Only used in cases where we need to draw the foreground separately.
-    std::unique_ptr<GraphicsLayer> m_backgroundLayer; // Only used in cases where we need to draw the background separately.
-    std::unique_ptr<GraphicsLayer> m_childContainmentLayer; // Only used if we have clipping on a stacking context with compositing children, or if the layer has a tile cache.
-    std::unique_ptr<GraphicsLayer> m_maskLayer; // Only used if we have a mask and/or clip-path.
-    std::unique_ptr<GraphicsLayer> m_childClippingMaskLayer; // Only used if we have to clip child layers or accelerated contents with border radius or clip-path.
+    RenderLayer& m_owningLayer;
 
-    std::unique_ptr<GraphicsLayer> m_layerForHorizontalScrollbar;
-    std::unique_ptr<GraphicsLayer> m_layerForVerticalScrollbar;
-    std::unique_ptr<GraphicsLayer> m_layerForScrollCorner;
+    RefPtr<GraphicsLayer> m_ancestorClippingLayer; // Only used if we are clipped by an ancestor which is not a stacking context.
+    RefPtr<GraphicsLayer> m_contentsContainmentLayer; // Only used if we have a background layer; takes the transform.
+    RefPtr<GraphicsLayer> m_graphicsLayer;
+    RefPtr<GraphicsLayer> m_foregroundLayer; // Only used in cases where we need to draw the foreground separately.
+    RefPtr<GraphicsLayer> m_backgroundLayer; // Only used in cases where we need to draw the background separately.
+    RefPtr<GraphicsLayer> m_childContainmentLayer; // Only used if we have clipping on a stacking context with compositing children, or if the layer has a tile cache.
+    RefPtr<GraphicsLayer> m_maskLayer; // Only used if we have a mask and/or clip-path.
+    RefPtr<GraphicsLayer> m_childClippingMaskLayer; // Only used if we have to clip child layers or accelerated contents with border radius or clip-path.
 
-    std::unique_ptr<GraphicsLayer> m_scrollingLayer; // Only used if the layer is using composited scrolling.
-    std::unique_ptr<GraphicsLayer> m_scrollingContentsLayer; // Only used if the layer is using composited scrolling.
+    RefPtr<GraphicsLayer> m_layerForHorizontalScrollbar;
+    RefPtr<GraphicsLayer> m_layerForVerticalScrollbar;
+    RefPtr<GraphicsLayer> m_layerForScrollCorner;
 
-    ScrollingNodeID m_viewportConstrainedNodeID;
-    ScrollingNodeID m_scrollingNodeID;
+    RefPtr<GraphicsLayer> m_scrollContainerLayer; // Only used if the layer is using composited scrolling.
+    RefPtr<GraphicsLayer> m_scrolledContentsLayer; // Only used if the layer is using composited scrolling.
 
     LayoutRect m_compositedBounds;
-    LayoutSize m_devicePixelFractionFromRenderer;
-
-    bool m_artificiallyInflatedBounds; // bounds had to be made non-zero to make transform-origin work
-    bool m_isMainFrameRenderViewLayer;
-    bool m_usingTiledCacheLayer;
-    bool m_requiresOwnBackingStore;
-    bool m_canCompositeFilters;
+    LayoutSize m_subpixelOffsetFromRenderer; // This is the subpixel distance between the primary graphics layer and the associated renderer's bounds.
+    LayoutSize m_compositedBoundsOffsetFromGraphicsLayer; // This is the subpixel distance between the primary graphics layer and the render layer bounds.
+
+    ScrollingNodeID m_viewportConstrainedNodeID { 0 };
+    ScrollingNodeID m_scrollingNodeID { 0 };
+    ScrollingNodeID m_frameHostingNodeID { 0 };
+
+    bool m_artificiallyInflatedBounds { false }; // bounds had to be made non-zero to make transform-origin work
+    bool m_isMainFrameRenderViewLayer { false };
+    bool m_isFrameLayerWithTiledBacking { false };
+    bool m_requiresOwnBackingStore { true };
+    bool m_canCompositeFilters { false };
 #if ENABLE(FILTERS_LEVEL_2)
-    bool m_canCompositeBackdropFilters;
+    bool m_canCompositeBackdropFilters { false };
 #endif
-    bool m_backgroundLayerPaintsFixedRootBackground;
+    bool m_backgroundLayerPaintsFixedRootBackground { false };
+    bool m_requiresBackgroundLayer { false };
+    bool m_paintsSubpixelAntialiasedText { false }; // This is for logging only.
 };
 
 enum CanvasCompositingStrategy {
@@ -375,6 +416,6 @@ enum CanvasCompositingStrategy {
 };
 CanvasCompositingStrategy canvasCompositingStrategy(const RenderObject&);
 
-} // namespace WebCore
+WTF::TextStream& operator<<(WTF::TextStream&, const RenderLayerBacking&);
 
-#endif // RenderLayerBacking_h
+} // namespace WebCore