[chromium] Use WebGraphicsContext3D in rate limiting logic inside compositor
authorjamesr@google.com <jamesr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jun 2012 23:12:28 +0000 (23:12 +0000)
committerjamesr@google.com <jamesr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jun 2012 23:12:28 +0000 (23:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=86259

Reviewed by Adrienne Walker.

This refactors the compositor's rate limiting implementation to use the Platform API's WebGraphicsContext3D
directly instead of WebCore::GraphicsContext3D to cut down on the number of spurious WebCore dependencies in the
compositor.  The one change in contract is that the caller to CCLayerTreeHost::startRateLimit() now has to call
CCLayerTreeHost::stopRateLimit() before allowing the referenced context to go away since CCLayerTreeHost no
longer retains a reference, but this was always happening already.

* platform/graphics/chromium/Canvas2DLayerChromium.cpp:
(WebCore::Canvas2DLayerChromium::~Canvas2DLayerChromium):
(WebCore::Canvas2DLayerChromium::setNeedsDisplayRect):
* platform/graphics/chromium/RateLimiter.cpp:
(WebCore::RateLimiter::create):
(WebCore::RateLimiter::RateLimiter):
(WebCore::RateLimiter::start):
(WebCore::RateLimiter::rateLimitContext):
* platform/graphics/chromium/RateLimiter.h:
(WebKit):
(RateLimiter):
* platform/graphics/chromium/TextureLayerChromium.cpp:
(WebCore::TextureLayerChromium::~TextureLayerChromium):
(WebCore::TextureLayerChromium::setRateLimitContext):
(WebCore::TextureLayerChromium::setNeedsDisplayRect):
* platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
(WebCore::CCLayerTreeHost::startRateLimiter):
(WebCore::CCLayerTreeHost::stopRateLimiter):
(WebCore::CCLayerTreeHost::rateLimit):
(WebCore):
* platform/graphics/chromium/cc/CCLayerTreeHost.h:
(CCLayerTreeHost):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/RateLimiter.cpp
Source/WebCore/platform/graphics/chromium/RateLimiter.h
Source/WebCore/platform/graphics/chromium/TextureLayerChromium.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h

index 3cb8c493c41c3ce7dc44dad3a99d9f01ebf61b9c..cde10730d06881642b3ce7b310fce4cd301509e1 100644 (file)
@@ -1,3 +1,39 @@
+2012-06-11  James Robinson  <jamesr@chromium.org>
+
+        [chromium] Use WebGraphicsContext3D in rate limiting logic inside compositor
+        https://bugs.webkit.org/show_bug.cgi?id=86259
+
+        Reviewed by Adrienne Walker.
+
+        This refactors the compositor's rate limiting implementation to use the Platform API's WebGraphicsContext3D
+        directly instead of WebCore::GraphicsContext3D to cut down on the number of spurious WebCore dependencies in the
+        compositor.  The one change in contract is that the caller to CCLayerTreeHost::startRateLimit() now has to call
+        CCLayerTreeHost::stopRateLimit() before allowing the referenced context to go away since CCLayerTreeHost no
+        longer retains a reference, but this was always happening already.
+
+        * platform/graphics/chromium/Canvas2DLayerChromium.cpp:
+        (WebCore::Canvas2DLayerChromium::~Canvas2DLayerChromium):
+        (WebCore::Canvas2DLayerChromium::setNeedsDisplayRect):
+        * platform/graphics/chromium/RateLimiter.cpp:
+        (WebCore::RateLimiter::create):
+        (WebCore::RateLimiter::RateLimiter):
+        (WebCore::RateLimiter::start):
+        (WebCore::RateLimiter::rateLimitContext):
+        * platform/graphics/chromium/RateLimiter.h:
+        (WebKit):
+        (RateLimiter):
+        * platform/graphics/chromium/TextureLayerChromium.cpp:
+        (WebCore::TextureLayerChromium::~TextureLayerChromium):
+        (WebCore::TextureLayerChromium::setRateLimitContext):
+        (WebCore::TextureLayerChromium::setNeedsDisplayRect):
+        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
+        (WebCore::CCLayerTreeHost::startRateLimiter):
+        (WebCore::CCLayerTreeHost::stopRateLimiter):
+        (WebCore::CCLayerTreeHost::rateLimit):
+        (WebCore):
+        * platform/graphics/chromium/cc/CCLayerTreeHost.h:
+        (CCLayerTreeHost):
+
 2012-06-11  Dana Jansens  <danakj@chromium.org>
 
         [chromium] Separate CCVideoDrawQuad and from the layer tree and video provider by removing ManagedTexture and WebVideoFrame pointers from the quad
index fdadf93b43bd40e6f94a3c7fa00010c7fbb258f9..232f04719811c6db12d81f527de8d05252bd3d2b 100644 (file)
 #if USE(ACCELERATED_COMPOSITING)
 
 #include "RateLimiter.h"
-
-#include "Extensions3DChromium.h"
-#include "GraphicsContext3D.h"
 #include "TraceEvent.h"
+#include <public/WebGraphicsContext3D.h>
 
 namespace WebCore {
 
-PassRefPtr<RateLimiter> RateLimiter::create(GraphicsContext3D* context, RateLimiterClient *client)
+PassRefPtr<RateLimiter> RateLimiter::create(WebKit::WebGraphicsContext3D* context, RateLimiterClient *client)
 {
     return adoptRef(new RateLimiter(context, client));
 }
 
-RateLimiter::RateLimiter(GraphicsContext3D* context, RateLimiterClient *client)
+RateLimiter::RateLimiter(WebKit::WebGraphicsContext3D* context, RateLimiterClient *client)
     : m_context(context)
     , m_timer(this, &RateLimiter::rateLimitContext)
     , m_client(client)
 {
     ASSERT(context);
-    ASSERT(context->getExtensions());
-    m_contextSupportsRateLimitingExtension = context->getExtensions()->supports("GL_CHROMIUM_rate_limit_offscreen_context");
 }
 
 RateLimiter::~RateLimiter()
@@ -56,7 +52,7 @@ RateLimiter::~RateLimiter()
 
 void RateLimiter::start()
 {
-    if (m_contextSupportsRateLimitingExtension && !m_timer.isActive())
+    if (!m_timer.isActive())
         m_timer.startOneShot(0);
 }
 
@@ -67,12 +63,10 @@ void RateLimiter::stop()
 
 void RateLimiter::rateLimitContext(Timer<RateLimiter>*)
 {
-    TRACE_EVENT("RateLimiter::rateLimitContext", this, 0);
-
-    Extensions3DChromium* extensions = static_cast<Extensions3DChromium*>(m_context->getExtensions());
+    TRACE_EVENT0("cc", "RateLimiter::rateLimitContext");
 
     m_client->rateLimit();
-    extensions->rateLimitOffscreenContextCHROMIUM();
+    m_context->rateLimitOffscreenContextCHROMIUM();
 }
 
 }
index 68e04455e694d9ba76fe0309519807adc4f13d7b..b786b90d4900797eef9aeee04e0aa7e35cc22fdf 100644 (file)
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 
-namespace WebCore {
+namespace WebKit {
+class WebGraphicsContext3D;
+}
 
-class GraphicsContext3D;
+namespace WebCore {
 
 class RateLimiterClient {
 public:
@@ -44,16 +46,16 @@ public:
 // A class containing a timer, which calls rateLimitCHROMIUM on expiry
 class RateLimiter : public RefCounted<RateLimiter> {
 public:
-    static PassRefPtr<RateLimiter> create(GraphicsContext3D*, RateLimiterClient*);
+    static PassRefPtr<RateLimiter> create(WebKit::WebGraphicsContext3D*, RateLimiterClient*);
     ~RateLimiter();
 
     void start();
     void stop();
 
 private:
-    RateLimiter(GraphicsContext3D*, RateLimiterClient*);
-    RefPtr<GraphicsContext3D> m_context;
-    bool m_contextSupportsRateLimitingExtension;
+    RateLimiter(WebKit::WebGraphicsContext3D*, RateLimiterClient*);
+
+    WebKit::WebGraphicsContext3D* m_context;
     Timer<RateLimiter> m_timer;
     void rateLimitContext(Timer<RateLimiter>*);
     RateLimiterClient *m_client;
index 63ed244b03a238f9837e106ceefa89b78adb49ca..3b12870a2d07b846b4f41a9ca9d5f36733254a32 100644 (file)
@@ -30,6 +30,7 @@
 #include "TextureLayerChromium.h"
 
 #include "Extensions3D.h"
+#include "GraphicsContext3DPrivate.h"
 #include "cc/CCLayerTreeHost.h"
 #include "cc/CCTextureLayerImpl.h"
 
@@ -58,7 +59,7 @@ TextureLayerChromium::~TextureLayerChromium()
         if (m_textureId)
             layerTreeHost()->acquireLayerTextures();
         if (m_rateLimitContext && m_client)
-            layerTreeHost()->stopRateLimiter(m_client->context());
+            layerTreeHost()->stopRateLimiter(GraphicsContext3DPrivate::extractWebGraphicsContext3D(m_client->context()));
     }
 }
 
@@ -88,7 +89,7 @@ void TextureLayerChromium::setPremultipliedAlpha(bool premultipliedAlpha)
 void TextureLayerChromium::setRateLimitContext(bool rateLimit)
 {
     if (!rateLimit && m_rateLimitContext && m_client && layerTreeHost())
-        layerTreeHost()->stopRateLimiter(m_client->context());
+        layerTreeHost()->stopRateLimiter(GraphicsContext3DPrivate::extractWebGraphicsContext3D(m_client->context()));
 
     m_rateLimitContext = rateLimit;
 }
@@ -114,7 +115,7 @@ void TextureLayerChromium::setNeedsDisplayRect(const FloatRect& dirtyRect)
     LayerChromium::setNeedsDisplayRect(dirtyRect);
 
     if (m_rateLimitContext && m_client && layerTreeHost())
-        layerTreeHost()->startRateLimiter(m_client->context());
+        layerTreeHost()->startRateLimiter(GraphicsContext3DPrivate::extractWebGraphicsContext3D(m_client->context()));
 }
 
 void TextureLayerChromium::setLayerTreeHost(CCLayerTreeHost* host)
index 0a0154c3efe3e03ba5048f1b684a25a8441b4fdb..f4f482bea67c76b6be15045e17fe1f961787bf61 100644 (file)
@@ -633,10 +633,11 @@ void CCLayerTreeHost::applyScrollAndScale(const CCScrollAndScaleSet& info)
     m_client->applyScrollAndScale(scrollDelta, info.pageScaleDelta);
 }
 
-void CCLayerTreeHost::startRateLimiter(GraphicsContext3D* context)
+void CCLayerTreeHost::startRateLimiter(WebKit::WebGraphicsContext3D* context)
 {
     if (m_animating)
         return;
+
     ASSERT(context);
     RateLimiterMap::iterator it = m_rateLimiters.find(context);
     if (it != m_rateLimiters.end())
@@ -648,14 +649,7 @@ void CCLayerTreeHost::startRateLimiter(GraphicsContext3D* context)
     }
 }
 
-void CCLayerTreeHost::rateLimit()
-{
-    // Force a no-op command on the compositor context, so that any ratelimiting commands will wait for the compositing
-    // context, and therefore for the SwapBuffers.
-    m_proxy->forceSerializeOnSwapBuffers();
-}
-
-void CCLayerTreeHost::stopRateLimiter(GraphicsContext3D* context)
+void CCLayerTreeHost::stopRateLimiter(WebKit::WebGraphicsContext3D* context)
 {
     RateLimiterMap::iterator it = m_rateLimiters.find(context);
     if (it != m_rateLimiters.end()) {
@@ -664,6 +658,13 @@ void CCLayerTreeHost::stopRateLimiter(GraphicsContext3D* context)
     }
 }
 
+void CCLayerTreeHost::rateLimit()
+{
+    // Force a no-op command on the compositor context, so that any ratelimiting commands will wait for the compositing
+    // context, and therefore for the SwapBuffers.
+    m_proxy->forceSerializeOnSwapBuffers();
+}
+
 bool CCLayerTreeHost::bufferedUpdates()
 {
     return m_settings.maxPartialTextureUpdates != numeric_limits<size_t>::max();
index 481d3ce61e9e929279a050d31ca4ef88e72b2762..3c3ae03f66c8ef457a831ce62dc1d84fcfc341e2 100644 (file)
@@ -242,8 +242,9 @@ public:
     void startPageScaleAnimation(const IntSize& targetPosition, bool useAnchor, float scale, double durationSec);
 
     void applyScrollAndScale(const CCScrollAndScaleSet&);
-    void startRateLimiter(GraphicsContext3D*);
-    void stopRateLimiter(GraphicsContext3D*);
+
+    void startRateLimiter(WebKit::WebGraphicsContext3D*);
+    void stopRateLimiter(WebKit::WebGraphicsContext3D*);
 
     // RateLimitClient implementation
     virtual void rateLimit() OVERRIDE;
@@ -304,7 +305,7 @@ private:
     size_t m_memoryAllocationBytes;
     bool m_memoryAllocationIsForDisplay;
 
-    typedef HashMap<GraphicsContext3D*, RefPtr<RateLimiter> > RateLimiterMap;
+    typedef HashMap<WebKit::WebGraphicsContext3D*, RefPtr<RateLimiter> > RateLimiterMap;
     RateLimiterMap m_rateLimiters;
 
     float m_pageScaleFactor;