[chromium] Compute occlusion during paint loop
[WebKit-https.git] / Source / WebCore / platform / graphics / chromium / cc / CCLayerTreeHost.h
index c713f03..f58203d 100644 (file)
 
 #include "GraphicsTypes3D.h"
 #include "IntRect.h"
+#include "LayerChromium.h"
+#include "RateLimiter.h"
+#include "TransformationMatrix.h"
+#include "cc/CCLayerTreeHostCommon.h"
 #include "cc/CCProxy.h"
 
+#include <wtf/HashMap.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
@@ -40,25 +45,26 @@ class GrContext;
 namespace WebCore {
 
 class CCLayerTreeHostImpl;
-class CCThread;
+class CCTextureUpdater;
 class GraphicsContext3D;
-class LayerChromium;
 class LayerPainterChromium;
-class LayerRendererChromium;
-class GraphicsLayer;
-class NonCompositedContentHost;
+class Region;
+class TextureAllocator;
 class TextureManager;
 
 class CCLayerTreeHostClient {
 public:
-    virtual void animateAndLayout(double frameBeginTime) = 0;
-    virtual PassOwnPtr<CCThread> createCompositorThread() = 0;
+    virtual void updateAnimations(double frameBeginTime) = 0;
+    virtual void layout() = 0;
+    virtual void applyScrollAndScale(const IntSize& scrollDelta, float pageScale) = 0;
     virtual PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D() = 0;
-    virtual PassOwnPtr<LayerPainterChromium> createRootLayerPainter() = 0;
     virtual void didRecreateGraphicsContext(bool success) = 0;
-#if !USE(THREADED_COMPOSITING)
+    virtual void didCommitAndDrawFrame() = 0;
+    virtual void didCompleteSwapBuffers() = 0;
+
+    // Used only in the single-threaded path.
     virtual void scheduleComposite() = 0;
-#endif
+
 protected:
     virtual ~CCLayerTreeHostClient() { }
 };
@@ -67,28 +73,46 @@ struct CCSettings {
     CCSettings()
             : acceleratePainting(false)
             , compositeOffscreen(false)
-            , enableCompositorThread(false)
             , showFPSCounter(false)
-            , showPlatformLayerTree(false) { }
+            , showPlatformLayerTree(false)
+            , refreshRate(0)
+            , perTilePainting(false)
+            , partialSwapEnabled(false)
+            , partialTextureUpdates(true) { }
 
     bool acceleratePainting;
     bool compositeOffscreen;
-    bool enableCompositorThread;
     bool showFPSCounter;
     bool showPlatformLayerTree;
+    double refreshRate;
+    bool perTilePainting;
+    bool partialSwapEnabled;
+    bool partialTextureUpdates;
 };
 
 // Provides information on an Impl's rendering capabilities back to the CCLayerTreeHost
 struct LayerRendererCapabilities {
     LayerRendererCapabilities()
         : bestTextureFormat(0)
+        , contextHasCachedFrontBuffer(false)
+        , usingPartialSwap(false)
         , usingMapSub(false)
         , usingAcceleratedPainting(false)
+        , usingSetVisibility(false)
+        , usingSwapCompleteCallback(false)
+        , usingTextureUsageHint(false)
+        , usingTextureStorageExtension(false)
         , maxTextureSize(0) { }
 
     GC3Denum bestTextureFormat;
+    bool contextHasCachedFrontBuffer;
+    bool usingPartialSwap;
     bool usingMapSub;
     bool usingAcceleratedPainting;
+    bool usingSetVisibility;
+    bool usingSwapCompleteCallback;
+    bool usingTextureUsageHint;
+    bool usingTextureStorageExtension;
     int maxTextureSize;
 };
 
@@ -97,26 +121,29 @@ public:
     static PassRefPtr<CCLayerTreeHost> create(CCLayerTreeHostClient*, const CCSettings&);
     virtual ~CCLayerTreeHost();
 
+    // Returns true if any CCLayerTreeHost is alive.
+    static bool anyLayerTreeHostInstanceExists();
+
     // CCLayerTreeHost interface to CCProxy.
-    void animateAndLayout(double frameBeginTime);
-    void commitTo(CCLayerTreeHostImpl*);
-    PassOwnPtr<CCThread> createCompositorThread();
+    void updateAnimations(double frameBeginTime);
+    void layout();
+    void beginCommitOnImplThread(CCLayerTreeHostImpl*);
+    void finishCommitOnImplThread(CCLayerTreeHostImpl*);
+    void commitComplete();
     PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D();
-    PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl();
+    virtual PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl(CCLayerTreeHostImplClient*);
+    void didBecomeInvisibleOnImplThread(CCLayerTreeHostImpl*);
     void didRecreateGraphicsContext(bool success);
-#if !USE(THREADED_COMPOSITING)
-    void scheduleComposite();
-#endif
-
-    // CCLayerTreeHost interface to WebView.
-    bool animating() const { return m_animating; }
-    void setAnimating(bool animating) { m_animating = animating; } // Can be removed when non-threaded scheduling moves inside.
+    void didCommitAndDrawFrame() { m_client->didCommitAndDrawFrame(); }
+    void didCompleteSwapBuffers() { m_client->didCompleteSwapBuffers(); }
+    void deleteContentsTexturesOnImplThread(TextureAllocator*);
 
     CCLayerTreeHostClient* client() { return m_client; }
 
-#if !USE(THREADED_COMPOSITING)
+    int compositorIdentifier() const { return m_compositorIdentifier; }
+
+    // Only used when compositing on the main thread.
     void composite();
-#endif
 
     GraphicsContext3D* context();
 
@@ -129,52 +156,66 @@ public:
 
     int frameNumber() const { return m_frameNumber; }
 
-    void invalidateRootLayerRect(const IntRect& dirtyRect);
-    void setZoomAnimatorScale(double);
-
     const LayerRendererCapabilities& layerRendererCapabilities() const;
 
     // Test-only hook
     void loseCompositorContext(int numTimes);
 
-    void setNeedsCommitAndRedraw();
+    void setNeedsAnimate();
+    // virtual for testing
+    virtual void setNeedsCommit();
     void setNeedsRedraw();
 
-    void setRootLayer(GraphicsLayer*);
-    GraphicsLayer* rootLayer() { return m_rootLayer.get(); }
-    const GraphicsLayer* rootLayer() const { return m_rootLayer.get(); }
+    LayerChromium* rootLayer() { return m_rootLayer.get(); }
+    const LayerChromium* rootLayer() const { return m_rootLayer.get(); }
+    void setRootLayer(PassRefPtr<LayerChromium>);
 
     const CCSettings& settings() const { return m_settings; }
 
-    void setViewport(const IntSize& viewportSize, const IntSize& contentsSize, const IntPoint& scrollPosition);
+    void setViewportSize(const IntSize&);
 
     const IntSize& viewportSize() const { return m_viewportSize; }
+
+    void setPageScale(float);
+    float pageScale() const { return m_pageScale; }
+
+    void setPageScaleFactorLimits(float minScale, float maxScale);
+
     TextureManager* contentsTextureManager() const;
 
+    bool visible() const { return m_visible; }
     void setVisible(bool);
 
-    NonCompositedContentHost* nonCompositedContentHost() const { return m_nonCompositedContentHost.get(); }
+    void setHaveWheelEventHandlers(bool);
 
     void updateLayers();
 
-    void deleteContentsTextures(GraphicsContext3D*);
+    void updateCompositorResources(GraphicsContext3D*, CCTextureUpdater&);
+    void applyScrollAndScale(const CCScrollAndScaleSet&);
+    void startRateLimiter(GraphicsContext3D*);
+    void stopRateLimiter(GraphicsContext3D*);
+
+    void deleteTextureAfterCommit(PassOwnPtr<ManagedTexture>);
 
 protected:
     CCLayerTreeHost(CCLayerTreeHostClient*, const CCSettings&);
+    bool initialize();
 
 private:
     typedef Vector<RefPtr<LayerChromium> > LayerList;
+    typedef Vector<OwnPtr<ManagedTexture> > TextureList;
 
-    void paintLayerContents(const LayerList&);
-    void updateLayers(LayerChromium*);
-    void updateCompositorResources(const LayerList&, GraphicsContext3D*);
-    void updateCompositorResources(LayerChromium*, GraphicsContext3D*);
-
-    void clearRenderSurfacesRecursive(LayerChromium*);
+    enum PaintType { PaintVisible, PaintIdle };
+    static void paintContentsIfDirty(LayerChromium*, PaintType, const Region& occludedScreenSpace);
+    void paintLayerContents(const LayerList&, PaintType);
+    void paintMaskAndReplicaForRenderSurface(LayerChromium*, PaintType);
 
-    bool initialize();
+    void updateLayers(LayerChromium*);
+    // Pre-reserve textures for any layer marked "always reserve textures"
+    void reserveTextures();
+    void clearPendingUpdate();
 
-    PassRefPtr<LayerRendererChromium> createLayerRenderer();
+    int m_compositorIdentifier;
 
     bool m_animating;
 
@@ -184,8 +225,7 @@ private:
 
     OwnPtr<CCProxy> m_proxy;
 
-    OwnPtr<GraphicsLayer> m_rootLayer;
-    OwnPtr<NonCompositedContentHost> m_nonCompositedContentHost;
+    RefPtr<LayerChromium> m_rootLayer;
     OwnPtr<TextureManager> m_contentsTextureManager;
 
     LayerList m_updateList;
@@ -193,8 +233,16 @@ private:
     CCSettings m_settings;
 
     IntSize m_viewportSize;
-    double m_zoomAnimatorScale;
     bool m_visible;
+    bool m_haveWheelEventHandlers;
+    typedef HashMap<GraphicsContext3D*, RefPtr<RateLimiter> > RateLimiterMap;
+    RateLimiterMap m_rateLimiters;
+
+    float m_pageScale;
+    float m_minPageScale, m_maxPageScale;
+    bool m_triggerIdlePaints;
+
+    TextureList m_deleteTextureAfterCommitList;
 };
 
 }