[chromium] Compute occlusion during paint loop
[WebKit-https.git] / Source / WebCore / platform / graphics / chromium / cc / CCLayerTreeHost.h
index e5ddbb4..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>
@@ -42,18 +45,22 @@ class GrContext;
 namespace WebCore {
 
 class CCLayerTreeHostImpl;
+class CCTextureUpdater;
 class GraphicsContext3D;
-class LayerChromium;
 class LayerPainterChromium;
+class Region;
 class TextureAllocator;
 class TextureManager;
 
 class CCLayerTreeHostClient {
 public:
-    virtual void animateAndLayout(double frameBeginTime) = 0;
-    virtual void applyScrollDelta(const IntSize&) = 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 void didRecreateGraphicsContext(bool success) = 0;
+    virtual void didCommitAndDrawFrame() = 0;
+    virtual void didCompleteSwapBuffers() = 0;
 
     // Used only in the single-threaded path.
     virtual void scheduleComposite() = 0;
@@ -66,53 +73,71 @@ 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;
 };
 
 class CCLayerTreeHost : public RefCounted<CCLayerTreeHost> {
 public:
-    static PassRefPtr<CCLayerTreeHost> create(CCLayerTreeHostClient*, PassRefPtr<LayerChromium> rootLayer, const CCSettings&);
+    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 updateAnimations(double frameBeginTime);
+    void layout();
+    void beginCommitOnImplThread(CCLayerTreeHostImpl*);
+    void finishCommitOnImplThread(CCLayerTreeHostImpl*);
     void commitComplete();
-    void commitToOnImplThread(CCLayerTreeHostImpl*);
     PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D();
     virtual PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl(CCLayerTreeHostImplClient*);
+    void didBecomeInvisibleOnImplThread(CCLayerTreeHostImpl*);
     void didRecreateGraphicsContext(bool success);
+    void didCommitAndDrawFrame() { m_client->didCommitAndDrawFrame(); }
+    void didCompleteSwapBuffers() { m_client->didCompleteSwapBuffers(); }
     void deleteContentsTexturesOnImplThread(TextureAllocator*);
 
-    // 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.
-
     CCLayerTreeHostClient* client() { return m_client; }
 
     int compositorIdentifier() const { return m_compositorIdentifier; }
@@ -131,43 +156,63 @@ public:
 
     int frameNumber() const { return m_frameNumber; }
 
-    void setZoomAnimatorTransform(const TransformationMatrix&);
-
     const LayerRendererCapabilities& layerRendererCapabilities() const;
 
     // Test-only hook
     void loseCompositorContext(int numTimes);
 
     void setNeedsAnimate();
-    void setNeedsCommitThenRedraw();
+    // virtual for testing
+    virtual void setNeedsCommit();
     void setNeedsRedraw();
 
     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);
+    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);
 
+    void setHaveWheelEventHandlers(bool);
+
     void updateLayers();
 
-    void applyScrollDeltas(const CCScrollUpdateSet&);
+    void updateCompositorResources(GraphicsContext3D*, CCTextureUpdater&);
+    void applyScrollAndScale(const CCScrollAndScaleSet&);
+    void startRateLimiter(GraphicsContext3D*);
+    void stopRateLimiter(GraphicsContext3D*);
+
+    void deleteTextureAfterCommit(PassOwnPtr<ManagedTexture>);
+
 protected:
-    CCLayerTreeHost(CCLayerTreeHostClient*, PassRefPtr<LayerChromium> rootLayer, const CCSettings&);
+    CCLayerTreeHost(CCLayerTreeHostClient*, const CCSettings&);
     bool initialize();
 
 private:
     typedef Vector<RefPtr<LayerChromium> > LayerList;
+    typedef Vector<OwnPtr<ManagedTexture> > TextureList;
+
+    enum PaintType { PaintVisible, PaintIdle };
+    static void paintContentsIfDirty(LayerChromium*, PaintType, const Region& occludedScreenSpace);
+    void paintLayerContents(const LayerList&, PaintType);
+    void paintMaskAndReplicaForRenderSurface(LayerChromium*, PaintType);
 
-    void paintLayerContents(const LayerList&);
     void updateLayers(LayerChromium*);
-    void updateCompositorResources(const LayerList&, GraphicsContext3D*, TextureAllocator*);
-    void updateCompositorResources(LayerChromium*, GraphicsContext3D*, TextureAllocator*);
+    // Pre-reserve textures for any layer marked "always reserve textures"
+    void reserveTextures();
     void clearPendingUpdate();
 
     int m_compositorIdentifier;
@@ -188,8 +233,16 @@ private:
     CCSettings m_settings;
 
     IntSize m_viewportSize;
-    TransformationMatrix m_zoomAnimatorTransform;
     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;
 };
 
 }