[chromium] Use WebGraphicsContext3D in rate limiting logic inside compositor
[WebKit.git] / Source / WebCore / platform / graphics / chromium / TextureLayerChromium.cpp
index 29cc6ba0b124c0fceeaaa03c6c05edca936dbf05..3b12870a2d07b846b4f41a9ca9d5f36733254a32 100644 (file)
 
 #include "TextureLayerChromium.h"
 
+#include "Extensions3D.h"
+#include "GraphicsContext3DPrivate.h"
+#include "cc/CCLayerTreeHost.h"
 #include "cc/CCTextureLayerImpl.h"
 
 namespace WebCore {
 
-PassRefPtr<TextureLayerChromium> TextureLayerChromium::create()
+PassRefPtr<TextureLayerChromium> TextureLayerChromium::create(TextureLayerChromiumClient* client)
 {
-    return adoptRef(new TextureLayerChromium);
+    return adoptRef(new TextureLayerChromium(client));
 }
 
-TextureLayerChromium::TextureLayerChromium()
+TextureLayerChromium::TextureLayerChromium(TextureLayerChromiumClient* client)
     : LayerChromium()
-    , m_textureId(0)
+    , m_client(client)
     , m_flipped(true)
     , m_uvRect(0, 0, 1, 1)
-    , m_ioSurfaceId(0)
+    , m_premultipliedAlpha(true)
+    , m_rateLimitContext(false)
+    , m_contextLost(false)
+    , m_textureId(0)
+{
+}
+
+TextureLayerChromium::~TextureLayerChromium()
 {
+    if (layerTreeHost()) {
+        if (m_textureId)
+            layerTreeHost()->acquireLayerTextures();
+        if (m_rateLimitContext && m_client)
+            layerTreeHost()->stopRateLimiter(GraphicsContext3DPrivate::extractWebGraphicsContext3D(m_client->context()));
+    }
 }
 
 PassOwnPtr<CCLayerImpl> TextureLayerChromium::createCCLayerImpl()
@@ -52,45 +68,87 @@ PassOwnPtr<CCLayerImpl> TextureLayerChromium::createCCLayerImpl()
     return CCTextureLayerImpl::create(m_layerId);
 }
 
-bool TextureLayerChromium::drawsContent() const
+void TextureLayerChromium::setFlipped(bool flipped)
 {
-    return (m_textureId || m_ioSurfaceId) && LayerChromium::drawsContent();
+    m_flipped = flipped;
+    setNeedsCommit();
 }
 
-void TextureLayerChromium::setTextureId(unsigned id)
+void TextureLayerChromium::setUVRect(const FloatRect& rect)
 {
-    m_textureId = id;
+    m_uvRect = rect;
     setNeedsCommit();
 }
 
-void TextureLayerChromium::setFlipped(bool flipped)
+void TextureLayerChromium::setPremultipliedAlpha(bool premultipliedAlpha)
 {
-    m_flipped = flipped;
+    m_premultipliedAlpha = premultipliedAlpha;
     setNeedsCommit();
 }
 
-void TextureLayerChromium::setUVRect(const FloatRect& rect)
+void TextureLayerChromium::setRateLimitContext(bool rateLimit)
 {
-    m_uvRect = rect;
-    setNeedsCommit();
+    if (!rateLimit && m_rateLimitContext && m_client && layerTreeHost())
+        layerTreeHost()->stopRateLimiter(GraphicsContext3DPrivate::extractWebGraphicsContext3D(m_client->context()));
+
+    m_rateLimitContext = rateLimit;
 }
 
-void TextureLayerChromium::setIOSurfaceProperties(int width, int height, uint32_t ioSurfaceId)
+void TextureLayerChromium::setTextureId(unsigned id)
 {
-    m_ioSurfaceSize = IntSize(width, height);
-    m_ioSurfaceId = ioSurfaceId;
+    if (m_textureId == id)
+        return;
+    if (m_textureId && layerTreeHost())
+        layerTreeHost()->acquireLayerTextures();
+    m_textureId = id;
     setNeedsCommit();
 }
 
+void TextureLayerChromium::willModifyTexture()
+{
+    if (layerTreeHost())
+        layerTreeHost()->acquireLayerTextures();
+}
+
+void TextureLayerChromium::setNeedsDisplayRect(const FloatRect& dirtyRect)
+{
+    LayerChromium::setNeedsDisplayRect(dirtyRect);
+
+    if (m_rateLimitContext && m_client && layerTreeHost())
+        layerTreeHost()->startRateLimiter(GraphicsContext3DPrivate::extractWebGraphicsContext3D(m_client->context()));
+}
+
+void TextureLayerChromium::setLayerTreeHost(CCLayerTreeHost* host)
+{
+    if (m_textureId && layerTreeHost() && host != layerTreeHost())
+        layerTreeHost()->acquireLayerTextures();
+    LayerChromium::setLayerTreeHost(host);
+}
+
+bool TextureLayerChromium::drawsContent() const
+{
+    return (m_client || m_textureId) && !m_contextLost && LayerChromium::drawsContent();
+}
+
+void TextureLayerChromium::update(CCTextureUpdater& updater, const CCOcclusionTracker*)
+{
+    if (m_client) {
+        m_textureId = m_client->prepareTexture(updater);
+        m_contextLost = m_client->context()->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR;
+    }
+
+    m_needsDisplay = false;
+}
+
 void TextureLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
 {
     LayerChromium::pushPropertiesTo(layer);
 
     CCTextureLayerImpl* textureLayer = static_cast<CCTextureLayerImpl*>(layer);
-    textureLayer->setTextureId(m_textureId);
     textureLayer->setFlipped(m_flipped);
     textureLayer->setUVRect(m_uvRect);
-    textureLayer->setIOSurfaceProperties(m_ioSurfaceSize, m_ioSurfaceId);
+    textureLayer->setPremultipliedAlpha(m_premultipliedAlpha);
+    textureLayer->setTextureId(m_textureId);
 }
 
 }