[GTK][WPE] Remove UpdateAtlas
[WebKit-https.git] / Source / WebCore / platform / graphics / texmap / coordinated / CoordinatedGraphicsLayer.h
index a3f0a08..e6ca865 100644 (file)
 #ifndef CoordinatedGraphicsLayer_h
 #define CoordinatedGraphicsLayer_h
 
+#if USE(COORDINATED_GRAPHICS)
+
+#include "CoordinatedGraphicsState.h"
 #include "CoordinatedImageBacking.h"
-#include "CoordinatedLayerInfo.h"
-#include "CoordinatedTile.h"
 #include "FloatPoint3D.h"
 #include "GraphicsLayer.h"
-#include "GraphicsLayerAnimation.h"
 #include "GraphicsLayerTransform.h"
 #include "Image.h"
 #include "IntSize.h"
-#include "RunLoop.h"
+#include "NicosiaBuffer.h"
+#include "TextureMapperAnimation.h"
 #include "TiledBackingStore.h"
 #include "TiledBackingStoreClient.h"
 #include "TransformationMatrix.h"
-#if USE(GRAPHICS_SURFACE)
-#include "GraphicsSurfaceToken.h"
-#endif
 #include <wtf/text/StringHash.h>
 
-#if USE(COORDINATED_GRAPHICS)
+namespace Nicosia {
+class PaintingEngine;
+}
 
 namespace WebCore {
 class CoordinatedGraphicsLayer;
-class GraphicsLayerAnimations;
+class TextureMapperAnimations;
 
 class CoordinatedGraphicsLayerClient {
 public:
     virtual bool isFlushingLayerChanges() const = 0;
-
-    // CoordinatedTileClient
-    virtual void createTile(CoordinatedLayerID, uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) = 0;
-    virtual void updateTile(CoordinatedLayerID, uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) = 0;
-    virtual void removeTile(CoordinatedLayerID, uint32_t tileID) = 0;
-
     virtual FloatRect visibleContentsRect() const = 0;
-    virtual PassRefPtr<CoordinatedImageBacking> createImageBackingIfNeeded(Image*) = 0;
-    virtual void syncLayerState(CoordinatedLayerID, const CoordinatedLayerInfo&) = 0;
-    virtual void syncLayerChildren(CoordinatedLayerID, const Vector<CoordinatedLayerID>&) = 0;
-#if ENABLE(CSS_FILTERS)
-    virtual void syncLayerFilters(CoordinatedLayerID, const FilterOperations&) = 0;
-#endif
-#if USE(GRAPHICS_SURFACE)
-    virtual void createCanvas(CoordinatedLayerID, PlatformLayer*) = 0;
-    virtual void syncCanvas(CoordinatedLayerID, PlatformLayer*) = 0;
-    virtual void destroyCanvas(CoordinatedLayerID) = 0;
-#endif
-
-    virtual void setLayerRepaintCount(CoordinatedLayerID, int) = 0;
-
-    virtual void setLayerAnimations(CoordinatedLayerID, const GraphicsLayerAnimations&) = 0;
-
+    virtual Ref<CoordinatedImageBacking> createImageBackingIfNeeded(Image&) = 0;
     virtual void detachLayer(CoordinatedGraphicsLayer*) = 0;
-    virtual PassOwnPtr<GraphicsContext> beginContentUpdate(const IntSize&, CoordinatedSurface::Flags, uint32_t& atlasID, IntPoint&) = 0;
+    virtual Nicosia::PaintingEngine& paintingEngine() = 0;
+
+    virtual void syncLayerState(CoordinatedLayerID, CoordinatedGraphicsLayerState&) = 0;
 };
 
-class CoordinatedGraphicsLayer : public GraphicsLayer
+class WEBCORE_EXPORT CoordinatedGraphicsLayer : public GraphicsLayer
     , public TiledBackingStoreClient
-    , public CoordinatedImageBacking::Host
-    , public CoordinatedTileClient {
+    , public CoordinatedImageBacking::Host {
 public:
-    explicit CoordinatedGraphicsLayer(GraphicsLayerClient*);
+    explicit CoordinatedGraphicsLayer(Type, GraphicsLayerClient&);
     virtual ~CoordinatedGraphicsLayer();
 
+    PlatformLayerID primaryLayerID() const override { return id(); }
+
     // Reimplementations from GraphicsLayer.h.
-    virtual bool setChildren(const Vector<GraphicsLayer*>&) OVERRIDE;
-    virtual void addChild(GraphicsLayer*) OVERRIDE;
-    virtual void addChildAtIndex(GraphicsLayer*, int) OVERRIDE;
-    virtual void addChildAbove(GraphicsLayer*, GraphicsLayer*) OVERRIDE;
-    virtual void addChildBelow(GraphicsLayer*, GraphicsLayer*) OVERRIDE;
-    virtual bool replaceChild(GraphicsLayer*, GraphicsLayer*) OVERRIDE;
-    virtual void removeFromParent() OVERRIDE;
-    virtual void setPosition(const FloatPoint&) OVERRIDE;
-    virtual void setAnchorPoint(const FloatPoint3D&) OVERRIDE;
-    virtual void setSize(const FloatSize&) OVERRIDE;
-    virtual void setTransform(const TransformationMatrix&) OVERRIDE;
-    virtual void setChildrenTransform(const TransformationMatrix&) OVERRIDE;
-    virtual void setPreserves3D(bool) OVERRIDE;
-    virtual void setMasksToBounds(bool) OVERRIDE;
-    virtual void setDrawsContent(bool) OVERRIDE;
-    virtual void setContentsVisible(bool) OVERRIDE;
-    virtual void setContentsOpaque(bool) OVERRIDE;
-    virtual void setBackfaceVisibility(bool) OVERRIDE;
-    virtual void setOpacity(float) OVERRIDE;
-    virtual void setContentsRect(const IntRect&) OVERRIDE;
-    virtual void setContentsToImage(Image*) OVERRIDE;
-    virtual void setContentsToSolidColor(const Color&) OVERRIDE;
-    virtual void setShowDebugBorder(bool) OVERRIDE;
-    virtual void setShowRepaintCounter(bool) OVERRIDE;
-    virtual bool shouldDirectlyCompositeImage(Image*) const OVERRIDE;
-    virtual void setContentsToCanvas(PlatformLayer*) OVERRIDE;
-    virtual void setMaskLayer(GraphicsLayer*) OVERRIDE;
-    virtual void setReplicatedByLayer(GraphicsLayer*) OVERRIDE;
-    virtual void setNeedsDisplay() OVERRIDE;
-    virtual void setNeedsDisplayInRect(const FloatRect&) OVERRIDE;
-    virtual void setContentsNeedsDisplay() OVERRIDE;
-    virtual void deviceOrPageScaleFactorChanged() OVERRIDE;
-    virtual void flushCompositingState(const FloatRect&) OVERRIDE;
-    virtual void flushCompositingStateForThisLayerOnly() OVERRIDE;
-#if ENABLE(CSS_FILTERS)
-    virtual bool setFilters(const FilterOperations&) OVERRIDE;
-#endif
-    virtual bool addAnimation(const KeyframeValueList&, const IntSize&, const Animation*, const String&, double) OVERRIDE;
-    virtual void pauseAnimation(const String&, double) OVERRIDE;
-    virtual void removeAnimation(const String&) OVERRIDE;
-    virtual void suspendAnimations(double time) OVERRIDE;
-    virtual void resumeAnimations() OVERRIDE;
+    bool setChildren(const Vector<GraphicsLayer*>&) override;
+    void addChild(GraphicsLayer*) override;
+    void addChildAtIndex(GraphicsLayer*, int) override;
+    void addChildAbove(GraphicsLayer*, GraphicsLayer*) override;
+    void addChildBelow(GraphicsLayer*, GraphicsLayer*) override;
+    bool replaceChild(GraphicsLayer*, GraphicsLayer*) override;
+    void removeFromParent() override;
+    void setPosition(const FloatPoint&) override;
+    void setAnchorPoint(const FloatPoint3D&) override;
+    void setSize(const FloatSize&) override;
+    void setTransform(const TransformationMatrix&) override;
+    void setChildrenTransform(const TransformationMatrix&) override;
+    void setPreserves3D(bool) override;
+    void setMasksToBounds(bool) override;
+    void setDrawsContent(bool) override;
+    void setContentsVisible(bool) override;
+    void setContentsOpaque(bool) override;
+    void setBackfaceVisibility(bool) override;
+    void setOpacity(float) override;
+    void setContentsRect(const FloatRect&) override;
+    void setContentsTilePhase(const FloatSize&) override;
+    void setContentsTileSize(const FloatSize&) override;
+    void setContentsToImage(Image*) override;
+    void setContentsToSolidColor(const Color&) override;
+    void setShowDebugBorder(bool) override;
+    void setShowRepaintCounter(bool) override;
+    bool shouldDirectlyCompositeImage(Image*) const override;
+    void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) override;
+    void setMaskLayer(GraphicsLayer*) override;
+    void setReplicatedByLayer(GraphicsLayer*) override;
+    void setNeedsDisplay() override;
+    void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) override;
+    void setContentsNeedsDisplay() override;
+    void deviceOrPageScaleFactorChanged() override;
+    void flushCompositingState(const FloatRect&) override;
+    void flushCompositingStateForThisLayerOnly() override;
+    bool setFilters(const FilterOperations&) override;
+    bool addAnimation(const KeyframeValueList&, const FloatSize&, const Animation*, const String&, double) override;
+    void pauseAnimation(const String&, double) override;
+    void removeAnimation(const String&) override;
+    void suspendAnimations(MonotonicTime) override;
+    void resumeAnimations() override;
+    bool usesContentsLayer() const override { return m_platformLayer || m_compositedImage; }
+
+    void syncPendingStateChangesIncludingSubLayers();
+    void updateContentBuffersIncludingSubLayers();
 
     FloatPoint computePositionRelativeToBase();
     void computePixelAlignment(FloatPoint& position, FloatSize&, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset);
 
     void setVisibleContentRectTrajectoryVector(const FloatPoint&);
 
-    void setRootLayer(bool);
-
-    CoordinatedLayerID id() const;
+    CoordinatedLayerID id() const { return m_id; }
 
     void setFixedToViewport(bool isFixed);
 
     IntRect coverRect() const { return m_mainBackingStore ? m_mainBackingStore->mapToContents(m_mainBackingStore->coverRect()) : IntRect(); }
+    IntRect transformedVisibleRect();
 
     // TiledBackingStoreClient
-    virtual void tiledBackingStorePaintBegin() OVERRIDE;
-    virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&) OVERRIDE;
-    virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea) OVERRIDE;
-    virtual void tiledBackingStoreHasPendingTileCreation() OVERRIDE;
-    virtual IntRect tiledBackingStoreContentsRect() OVERRIDE;
-    virtual IntRect tiledBackingStoreVisibleRect() OVERRIDE;
-    virtual Color tiledBackingStoreBackgroundColor() const OVERRIDE;
-
-    // CoordinatedTileClient
-    virtual void createTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) OVERRIDE;
-    virtual void updateTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) OVERRIDE;
-    virtual void removeTile(uint32_t tileID) OVERRIDE;
-    virtual PassOwnPtr<GraphicsContext> beginContentUpdate(const IntSize&, uint32_t& atlasID, IntPoint&) OVERRIDE;
+    void tiledBackingStoreHasPendingTileCreation() override;
+    void createTile(uint32_t tileID, float) override;
+    void updateTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) override;
+    void removeTile(uint32_t tileID) override;
 
     void setCoordinator(CoordinatedGraphicsLayerClient*);
 
     void setNeedsVisibleRectAdjustment();
     void purgeBackingStores();
-    bool hasPendingVisibleChanges();
+
+    CoordinatedGraphicsLayer* findFirstDescendantWithContentsRecursively();
 
 private:
-#if USE(GRAPHICS_SURFACE)
-    enum PendingCanvasOperation {
-        None = 0x00,
-        CreateCanvas = 0x01,
-        DestroyCanvas = 0x02,
-        SyncCanvas = 0x04,
-        CreateAndSyncCanvas = CreateCanvas | SyncCanvas,
-        RecreateCanvas = CreateAndSyncCanvas | DestroyCanvas
-    };
-
-    void syncCanvas();
-    void destroyCanvasIfNeeded();
-    void createCanvasIfNeeded();
-#endif
+    bool isCoordinatedGraphicsLayer() const override { return true; }
+
+    void syncPlatformLayer();
+    void updatePlatformLayer();
 
-    virtual void setDebugBorder(const Color&, float width) OVERRIDE;
+    void setDebugBorder(const Color&, float width) override;
 
     bool fixedToViewport() const { return m_fixedToViewport; }
 
@@ -185,17 +152,15 @@ private:
     void didChangeAnimations();
     void didChangeGeometry();
     void didChangeChildren();
-#if ENABLE(CSS_FILTERS)
     void didChangeFilters();
-#endif
     void didChangeImageBacking();
+    void didUpdateTileBuffers();
 
+    void resetLayerState();
     void syncLayerState();
     void syncAnimations();
     void syncChildren();
-#if ENABLE(CSS_FILTERS)
     void syncFilters();
-#endif
     void syncImageBacking();
     void computeTransformedVisibleRect();
     void updateContentBuffers();
@@ -203,8 +168,10 @@ private:
     void createBackingStore();
     void releaseImageBackingIfNeeded();
 
+    void notifyFlushRequired();
+
     // CoordinatedImageBacking::Host
-    virtual bool imageBackingVisible() OVERRIDE;
+    bool imageBackingVisible() override;
     bool shouldHaveBackingStore() const;
     bool selfOrAncestorHasActiveTransformAnimation() const;
     bool selfOrAncestorHaveNonAffineTransforms();
@@ -213,10 +180,12 @@ private:
     void setShouldUpdateVisibleRect();
     float effectiveContentsScale();
 
-    void animationStartedTimerFired(Timer<CoordinatedGraphicsLayer>*);
+    void animationStartedTimerFired();
+
+    bool filtersCanBeComposited(const FilterOperations&) const;
 
     CoordinatedLayerID m_id;
-    CoordinatedLayerInfo m_layerInfo;
+    CoordinatedGraphicsLayerState m_layerState;
     GraphicsLayerTransform m_layerTransform;
     TransformationMatrix m_cachedInverseTransform;
     FloatSize m_pixelAlignmentOffset;
@@ -234,34 +203,37 @@ private:
     bool m_shouldSyncImageBacking: 1;
     bool m_shouldSyncAnimations: 1;
     bool m_fixedToViewport : 1;
+    bool m_movingVisibleRect : 1;
     bool m_pendingContentsScaleAdjustment : 1;
     bool m_pendingVisibleRectAdjustment : 1;
-#if USE(GRAPHICS_SURFACE)
-    bool m_isValidCanvas : 1;
-    unsigned m_pendingCanvasOperation : 3;
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    bool m_shouldSyncPlatformLayer : 1;
+    bool m_shouldUpdatePlatformLayer : 1;
 #endif
 
     CoordinatedGraphicsLayerClient* m_coordinator;
-    OwnPtr<TiledBackingStore> m_mainBackingStore;
-    OwnPtr<TiledBackingStore> m_previousBackingStore;
+    std::unique_ptr<TiledBackingStore> m_mainBackingStore;
+    std::unique_ptr<TiledBackingStore> m_previousBackingStore;
+
+    struct {
+        bool completeLayer { false };
+        Vector<FloatRect, 32> rects;
+    } m_needsDisplay;
 
     RefPtr<Image> m_compositedImage;
     NativeImagePtr m_compositedNativeImagePtr;
     RefPtr<CoordinatedImageBacking> m_coordinatedImageBacking;
 
-    PlatformLayer* m_canvasPlatformLayer;
-#if USE(GRAPHICS_SURFACE)
-    IntSize m_canvasSize;
-    GraphicsSurfaceToken m_canvasToken;
-#endif
-    Timer<CoordinatedGraphicsLayer> m_animationStartedTimer;
-    GraphicsLayerAnimations m_animations;
-    double m_lastAnimationStartTime;
+    PlatformLayer* m_platformLayer;
+    Timer m_animationStartedTimer;
+    TextureMapperAnimations m_animations;
+    MonotonicTime m_lastAnimationStartTime;
 };
 
-CoordinatedGraphicsLayer* toCoordinatedGraphicsLayer(GraphicsLayer*);
-
 } // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_GRAPHICSLAYER(WebCore::CoordinatedGraphicsLayer, isCoordinatedGraphicsLayer())
+
 #endif // USE(COORDINATED_GRAPHICS)
 
 #endif // CoordinatedGraphicsLayer_h