[chromium] Move contents texture manager from LayerRendererChromium to CCLayerTreeHost
authorjamesr@google.com <jamesr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Sep 2011 20:30:12 +0000 (20:30 +0000)
committerjamesr@google.com <jamesr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Sep 2011 20:30:12 +0000 (20:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67440

Reviewed by Kenneth Russell.

This moves the contents TextureManager over to the CCLayerTreeHost, where it belongs, and adds in a commit path
to make sure that textures are deleted even if the page is not visible.  This move also removed the need for
LayerRendererChromium's CCLayerTreeHost pointer, so I removed that as well.  That meant moving the
layerTreeAsText() logic over to the CCLayerImpl side, which is where it really belonged anyway.

Covered by existing compositing/ tests and
platform/chromium/compositor/lost-compositor-context-with-rendersurface.html

* platform/graphics/chromium/LayerRendererChromium.cpp:
(WebCore::LayerRendererChromium::releaseRenderSurfaceTextures):
(WebCore::LayerRendererChromium::drawLayers):
(WebCore::LayerRendererChromium::initializeSharedObjects):
(WebCore::LayerRendererChromium::cleanupSharedObjects):
* platform/graphics/chromium/LayerRendererChromium.h:
(WebCore::LayerRendererChromium::setContentsTextureMemoryUseBytes):
* platform/graphics/chromium/TextureManager.cpp:
(WebCore::TextureManager::highLimitBytes):
(WebCore::TextureManager::reclaimLimitBytes):
(WebCore::TextureManager::lowLimitBytes):
* platform/graphics/chromium/TextureManager.h:
* platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
(WebCore::CCLayerTreeHost::initialize):
(WebCore::CCLayerTreeHost::~CCLayerTreeHost):
(WebCore::CCLayerTreeHost::deleteContentsTextures):
(WebCore::CCLayerTreeHost::commitTo):
(WebCore::CCLayerTreeHost::setVisible):
(WebCore::CCLayerTreeHost::contentsTextureManager):
* platform/graphics/chromium/cc/CCLayerTreeHost.h:
* platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
(WebCore::CCLayerTreeHostImpl::setVisible):
* platform/graphics/chromium/cc/CCProxy.h:
* platform/graphics/chromium/cc/CCSingleThreadProxy.cpp:
(WebCore::CCSingleThreadProxy::setNeedsCommit):
(WebCore::CCSingleThreadProxy::stop):
* platform/graphics/chromium/cc/CCSingleThreadProxy.h:
* platform/graphics/chromium/cc/CCThreadProxy.cpp:
(WebCore::CCThreadProxy::setNeedsCommit):
(WebCore::CCThreadProxy::setNeedsCommitOnCCThread):
(WebCore::CCThreadProxy::layerTreeHostClosedOnCCThread):
* platform/graphics/chromium/cc/CCThreadProxy.h:

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

40 files changed:
LayoutTests/platform/chromium/compositing/lost-compositor-context-with-rendersurface-expected.png [new file with mode: 0644]
LayoutTests/platform/chromium/compositing/lost-compositor-context-with-rendersurface-expected.txt [new file with mode: 0644]
LayoutTests/platform/chromium/compositing/lost-compositor-context-with-rendersurface.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/CanvasLayerChromium.h
Source/WebCore/platform/graphics/chromium/ContentLayerChromium.h
Source/WebCore/platform/graphics/chromium/ImageLayerChromium.h
Source/WebCore/platform/graphics/chromium/LayerChromium.cpp
Source/WebCore/platform/graphics/chromium/LayerChromium.h
Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h
Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp
Source/WebCore/platform/graphics/chromium/PluginLayerChromium.h
Source/WebCore/platform/graphics/chromium/RenderSurfaceChromium.cpp
Source/WebCore/platform/graphics/chromium/RenderSurfaceChromium.h
Source/WebCore/platform/graphics/chromium/TextureManager.cpp
Source/WebCore/platform/graphics/chromium/TextureManager.h
Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp
Source/WebCore/platform/graphics/chromium/TiledLayerChromium.h
Source/WebCore/platform/graphics/chromium/VideoLayerChromium.h
Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.h
Source/WebCore/platform/graphics/chromium/cc/CCCanvasLayerImpl.cpp
Source/WebCore/platform/graphics/chromium/cc/CCCanvasLayerImpl.h
Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.h
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h
Source/WebCore/platform/graphics/chromium/cc/CCPluginLayerImpl.cpp
Source/WebCore/platform/graphics/chromium/cc/CCPluginLayerImpl.h
Source/WebCore/platform/graphics/chromium/cc/CCProxy.h
Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp
Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.h
Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp
Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.h
Source/WebCore/platform/graphics/chromium/cc/CCTiledLayerImpl.cpp
Source/WebCore/platform/graphics/chromium/cc/CCTiledLayerImpl.h
Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.cpp
Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.h

diff --git a/LayoutTests/platform/chromium/compositing/lost-compositor-context-with-rendersurface-expected.png b/LayoutTests/platform/chromium/compositing/lost-compositor-context-with-rendersurface-expected.png
new file mode 100644 (file)
index 0000000..99e495b
Binary files /dev/null and b/LayoutTests/platform/chromium/compositing/lost-compositor-context-with-rendersurface-expected.png differ
diff --git a/LayoutTests/platform/chromium/compositing/lost-compositor-context-with-rendersurface-expected.txt b/LayoutTests/platform/chromium/compositing/lost-compositor-context-with-rendersurface-expected.txt
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/LayoutTests/platform/chromium/compositing/lost-compositor-context-with-rendersurface.html b/LayoutTests/platform/chromium/compositing/lost-compositor-context-with-rendersurface.html
new file mode 100644 (file)
index 0000000..704da13
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <style type="text/css" media="screen">
+    .red {
+        background-color: red;
+    }
+
+    .green {
+        background-color: green;
+    }
+
+    div {
+      height: 100px;
+      width: 100px;
+    }
+
+    .composited {
+      -webkit-transform: translateZ(0);
+    }
+
+    .renderSurface {
+      opacity: 0.5;
+    }
+  </style>
+</head>
+<body>
+  <!-- In the pixel results, one green squares should be visible. -->
+  <div class="red renderSurface">
+    <div id="target" class="red composited"></div>
+  </div>
+  <p>
+  <script>
+  if (window.layoutTestController) {
+    layoutTestController.dumpAsText(true);  // This is only useful as a pixel test.
+    layoutTestController.display();
+    layoutTestController.loseCompositorContext(1);
+  }
+  var target = document.getElementById("target");
+  target.classList.remove("red");
+  target.classList.add("green");
+  </script>
+</body>
+</html>
index 1e6c7e0..464f2f0 100644 (file)
@@ -1,3 +1,51 @@
+2011-09-12  James Robinson  <jamesr@chromium.org>
+
+        [chromium] Move contents texture manager from LayerRendererChromium to CCLayerTreeHost
+        https://bugs.webkit.org/show_bug.cgi?id=67440
+
+        Reviewed by Kenneth Russell.
+
+        This moves the contents TextureManager over to the CCLayerTreeHost, where it belongs, and adds in a commit path
+        to make sure that textures are deleted even if the page is not visible.  This move also removed the need for
+        LayerRendererChromium's CCLayerTreeHost pointer, so I removed that as well.  That meant moving the
+        layerTreeAsText() logic over to the CCLayerImpl side, which is where it really belonged anyway.
+
+        Covered by existing compositing/ tests and
+        platform/chromium/compositor/lost-compositor-context-with-rendersurface.html
+
+        * platform/graphics/chromium/LayerRendererChromium.cpp:
+        (WebCore::LayerRendererChromium::releaseRenderSurfaceTextures):
+        (WebCore::LayerRendererChromium::drawLayers):
+        (WebCore::LayerRendererChromium::initializeSharedObjects):
+        (WebCore::LayerRendererChromium::cleanupSharedObjects):
+        * platform/graphics/chromium/LayerRendererChromium.h:
+        (WebCore::LayerRendererChromium::setContentsTextureMemoryUseBytes):
+        * platform/graphics/chromium/TextureManager.cpp:
+        (WebCore::TextureManager::highLimitBytes):
+        (WebCore::TextureManager::reclaimLimitBytes):
+        (WebCore::TextureManager::lowLimitBytes):
+        * platform/graphics/chromium/TextureManager.h:
+        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
+        (WebCore::CCLayerTreeHost::initialize):
+        (WebCore::CCLayerTreeHost::~CCLayerTreeHost):
+        (WebCore::CCLayerTreeHost::deleteContentsTextures):
+        (WebCore::CCLayerTreeHost::commitTo):
+        (WebCore::CCLayerTreeHost::setVisible):
+        (WebCore::CCLayerTreeHost::contentsTextureManager):
+        * platform/graphics/chromium/cc/CCLayerTreeHost.h:
+        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
+        (WebCore::CCLayerTreeHostImpl::setVisible):
+        * platform/graphics/chromium/cc/CCProxy.h:
+        * platform/graphics/chromium/cc/CCSingleThreadProxy.cpp:
+        (WebCore::CCSingleThreadProxy::setNeedsCommit):
+        (WebCore::CCSingleThreadProxy::stop):
+        * platform/graphics/chromium/cc/CCSingleThreadProxy.h:
+        * platform/graphics/chromium/cc/CCThreadProxy.cpp:
+        (WebCore::CCThreadProxy::setNeedsCommit):
+        (WebCore::CCThreadProxy::setNeedsCommitOnCCThread):
+        (WebCore::CCThreadProxy::layerTreeHostClosedOnCCThread):
+        * platform/graphics/chromium/cc/CCThreadProxy.h:
+
 2011-09-12  Chris Rogers  <crogers@google.com>
 
         DelayNode delay buffer is not correctly wrapping around
index ea26dfe..4c2e440 100644 (file)
@@ -52,8 +52,6 @@ public:
 protected:
     explicit CanvasLayerChromium(GraphicsLayerChromium* owner);
 
-    virtual const char* layerTypeAsString() const { return "CanvasLayer"; }
-
     bool m_hasAlpha;
     bool m_premultipliedAlpha;
     unsigned m_textureId;
index bac41f9..9409ae1 100644 (file)
@@ -54,8 +54,6 @@ public:
 private:
     explicit ContentLayerChromium(GraphicsLayerChromium* owner);
 
-    virtual const char* layerTypeAsString() const { return "ContentLayer"; }
-
     virtual void cleanupResources();
     virtual bool drawsContent() const;
     virtual void createTextureUpdater(const CCLayerTreeHost*);
index d697913..4afe05d 100644 (file)
@@ -57,9 +57,6 @@ public:
 
     void setContents(Image* image);
 
-protected:
-    virtual const char* layerTypeAsString() const { return "ImageLayer"; }
-
 private:
     ImageLayerChromium(GraphicsLayerChromium* owner);
 
index bcd4d77..a0d3465 100644 (file)
@@ -376,48 +376,6 @@ void LayerChromium::drawTexturedQuad(GraphicsContext3D* context, const Transform
     GLC(context, context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0));
 }
 
-String LayerChromium::layerTreeAsText() const
-{
-    TextStream ts;
-    dumpLayer(ts, 0);
-    return ts.release();
-}
-
-static void writeIndent(TextStream& ts, int indent)
-{
-    for (int i = 0; i != indent; ++i)
-        ts << "  ";
-}
-
-void LayerChromium::dumpLayer(TextStream& ts, int indent) const
-{
-    writeIndent(ts, indent);
-    ts << layerTypeAsString() << "(" << m_name << ")\n";
-    dumpLayerProperties(ts, indent+2);
-    if (m_replicaLayer) {
-        writeIndent(ts, indent+2);
-        ts << "Replica:\n";
-        m_replicaLayer->dumpLayer(ts, indent+3);
-    }
-    if (m_maskLayer) {
-        writeIndent(ts, indent+2);
-        ts << "Mask:\n";
-        m_maskLayer->dumpLayer(ts, indent+3);
-    }
-    for (size_t i = 0; i < m_children.size(); ++i)
-        m_children[i]->dumpLayer(ts, indent+1);
-}
-
-void LayerChromium::dumpLayerProperties(TextStream& ts, int indent) const
-{
-    writeIndent(ts, indent);
-    ts << "id: " << id() << " drawsContent: " << drawsContent() << " bounds " << m_bounds.width() << "x" << m_bounds.height() << " usesLayerScissor: " << usesLayerScissor()
-        << " scissorRect: (" << m_scissorRect.x() << ", " << m_scissorRect.y() << ", " << m_scissorRect.width() << ", " << m_scissorRect.height() << ")"
-        << " visibleLayerRect: (" << m_visibleLayerRect.x() << ", " << m_visibleLayerRect.y() << ", " << m_visibleLayerRect.width() << ", " << m_visibleLayerRect.height() << ")"
-        << "\n";
-
-}
-
 PassRefPtr<CCLayerImpl> LayerChromium::createCCLayerImpl()
 {
     return CCLayerImpl::create(m_layerId);
index 8d30d7d..7f6ffa7 100644 (file)
@@ -172,7 +172,6 @@ public:
     void setBorderColor(const Color&);
 
     void drawDebugBorder();
-    String layerTreeAsText() const;
 
     void setBorderWidth(float);
 
@@ -220,11 +219,6 @@ protected:
 
     static void toGLMatrix(float*, const TransformationMatrix&);
 
-    void dumpLayer(TextStream&, int indent) const;
-
-    virtual const char* layerTypeAsString() const { return "LayerChromium"; }
-    virtual void dumpLayerProperties(TextStream&, int indent) const;
-
     FloatRect m_dirtyRect;
     bool m_contentsDirty;
 
index 5d5e4c5..c728169 100644 (file)
@@ -70,20 +70,6 @@ using namespace std;
 
 namespace WebCore {
 
-// FIXME: Make this limit adjustable and give it a useful value.
-
-// Absolute maximum limit for texture allocations for this instance.
-static size_t textureMemoryHighLimitBytes = 128 * 1024 * 1024;
-// Preferred texture size limit. Can be exceeded if needed.
-static size_t textureMemoryReclaimLimitBytes = 64 * 1024 * 1024;
-// The maximum texture memory usage when asked to release textures.
-static size_t textureMemoryLowLimitBytes = 3 * 1024 * 1024;
-
-size_t LayerRendererChromium::textureMemoryReclaimLimit()
-{
-    return textureMemoryReclaimLimitBytes;
-}
-
 namespace {
 
 static TransformationMatrix orthoMatrix(float left, float right, float bottom, float top)
@@ -143,24 +129,22 @@ bool contextSupportsAcceleratedPainting(GraphicsContext3D* context)
 
 } // anonymous namespace
 
-PassRefPtr<LayerRendererChromium> LayerRendererChromium::create(CCLayerTreeHost* owner, CCLayerTreeHostImpl* ownerImpl, PassRefPtr<GraphicsContext3D> context)
+PassRefPtr<LayerRendererChromium> LayerRendererChromium::create(CCLayerTreeHostImpl* owner, PassRefPtr<GraphicsContext3D> context)
 {
 #if USE(SKIA)
     if (owner->settings().acceleratePainting && !contextSupportsAcceleratedPainting(context.get()))
         return 0;
 #endif
-    RefPtr<LayerRendererChromium> layerRenderer(adoptRef(new LayerRendererChromium(owner, ownerImpl, context)));
+    RefPtr<LayerRendererChromium> layerRenderer(adoptRef(new LayerRendererChromium(owner, context)));
     if (!layerRenderer->initialize())
         return 0;
 
     return layerRenderer.release();
 }
 
-LayerRendererChromium::LayerRendererChromium(CCLayerTreeHost* owner,
-                                             CCLayerTreeHostImpl* ownerImpl,
+LayerRendererChromium::LayerRendererChromium(CCLayerTreeHostImpl* owner,
                                              PassRefPtr<GraphicsContext3D> context)
     : m_owner(owner)
-    , m_ownerImpl(ownerImpl)
     , m_currentRenderSurface(0)
     , m_offscreenFramebufferId(0)
     , m_zoomAnimatorScale(1)
@@ -210,8 +194,8 @@ void LayerRendererChromium::clearRenderSurfacesOnCCLayerImplRecursive(CCLayerImp
 
 void LayerRendererChromium::close()
 {
-    if (rootLayerImpl())
-        clearRenderSurfacesOnCCLayerImplRecursive(rootLayerImpl());
+    if (rootLayer())
+        clearRenderSurfacesOnCCLayerImplRecursive(rootLayer());
 }
 
 GraphicsContext3D* LayerRendererChromium::context()
@@ -226,18 +210,9 @@ void LayerRendererChromium::debugGLCall(GraphicsContext3D* context, const char*
         LOG_ERROR("GL command failed: File: %s\n\tLine %d\n\tcommand: %s, error %x\n", file, line, command, static_cast<int>(error));
 }
 
-void LayerRendererChromium::releaseTextures()
+void LayerRendererChromium::releaseRenderSurfaceTextures()
 {
-    // Reduces texture memory usage to textureMemoryLowLimitBytes by deleting non root layer
-    // textures.
-    m_owner->nonCompositedContentHost()->protectVisibleTileTextures();
-    m_contentsTextureManager->reduceMemoryToLimit(textureMemoryLowLimitBytes);
-    m_contentsTextureManager->unprotectAllTextures();
-    m_contentsTextureManager->deleteEvictedTextures(m_context.get());
-    // Evict all RenderSurface textures.
-    m_renderSurfaceTextureManager->unprotectAllTextures();
-    m_renderSurfaceTextureManager->reduceMemoryToLimit(0);
-    m_renderSurfaceTextureManager->deleteEvictedTextures(m_context.get());
+    m_renderSurfaceTextureManager->evictAndDeleteAllTextures(m_context.get());
 }
 
 void LayerRendererChromium::viewportChanged()
@@ -257,18 +232,16 @@ void LayerRendererChromium::drawLayers()
     // RenderWidget.
     m_headsUpDisplay->onFrameBegin(currentTime());
 
-    if (!rootLayerImpl())
+    if (!rootLayer())
         return;
     // FIXME: No need to walk the tree here. This could be passed via draw.
-    rootLayerImpl()->setLayerRendererRecursive(this);
+    rootLayer()->setLayerRendererRecursive(this);
 
-    m_renderSurfaceTextureManager->setMemoryLimitBytes(textureMemoryHighLimitBytes - m_contentsTextureManager->currentMemoryUseBytes());
+    m_renderSurfaceTextureManager->setMemoryLimitBytes(TextureManager::highLimitBytes() - m_contentsTextureMemoryUseBytes);
     drawLayersInternal();
 
-    m_contentsTextureManager->unprotectAllTextures();
-
-    if (textureMemoryReclaimLimitBytes > m_contentsTextureManager->currentMemoryUseBytes())
-        m_renderSurfaceTextureManager->reduceMemoryToLimit(textureMemoryReclaimLimitBytes - m_contentsTextureManager->currentMemoryUseBytes());
+    if (TextureManager::reclaimLimitBytes() > m_contentsTextureMemoryUseBytes)
+        m_renderSurfaceTextureManager->reduceMemoryToLimit(TextureManager::reclaimLimitBytes() - m_contentsTextureMemoryUseBytes);
     else
         m_renderSurfaceTextureManager->reduceMemoryToLimit(0);
     m_renderSurfaceTextureManager->deleteEvictedTextures(m_context.get());
@@ -283,7 +256,7 @@ void LayerRendererChromium::drawLayersInternal()
         return;
 
     TRACE_EVENT("LayerRendererChromium::drawLayers", this, 0);
-    CCLayerImpl* rootDrawLayer = rootLayerImpl();
+    CCLayerImpl* rootDrawLayer = rootLayer();
     makeContextCurrent();
 
     if (!rootDrawLayer->renderSurface())
@@ -447,7 +420,7 @@ bool LayerRendererChromium::isLayerVisible(LayerChromium* layer, const Transform
 
 ManagedTexture* LayerRendererChromium::getOffscreenLayerTexture()
 {
-    return settings().compositeOffscreen && rootLayerImpl() ? rootLayerImpl()->renderSurface()->contentsTexture() : 0;
+    return settings().compositeOffscreen && rootLayer() ? rootLayer()->renderSurface()->contentsTexture() : 0;
 }
 
 void LayerRendererChromium::copyOffscreenTextureToDisplay()
@@ -603,12 +576,7 @@ bool LayerRendererChromium::initializeSharedObjects()
 
     GLC(m_context.get(), m_context->flush());
 
-    m_contentsTextureManager = TextureManager::create(textureMemoryHighLimitBytes, m_capabilities.maxTextureSize);
-    m_renderSurfaceTextureManager = TextureManager::create(textureMemoryHighLimitBytes, m_capabilities.maxTextureSize);
-#ifndef NDEBUG
-    m_contentsTextureManager->setAssociatedContextDebugOnly(m_context.get());
-    m_renderSurfaceTextureManager->setAssociatedContextDebugOnly(m_context.get());
-#endif
+    m_renderSurfaceTextureManager = TextureManager::create(TextureManager::highLimitBytes(), m_capabilities.maxTextureSize);
     return true;
 }
 
@@ -817,29 +785,22 @@ void LayerRendererChromium::cleanupSharedObjects()
     if (m_offscreenFramebufferId)
         GLC(m_context.get(), m_context->deleteFramebuffer(m_offscreenFramebufferId));
 
-    // Clear tilers before the texture manager, as they have references to textures.
-    m_contentsTextureManager->unprotectAllTextures();
-    m_contentsTextureManager->reduceMemoryToLimit(0);
-    m_contentsTextureManager->deleteEvictedTextures(m_context.get());
-    m_contentsTextureManager.clear();
-    m_renderSurfaceTextureManager->unprotectAllTextures();
-    m_renderSurfaceTextureManager->reduceMemoryToLimit(0);
-    m_renderSurfaceTextureManager->deleteEvictedTextures(m_context.get());
-    m_renderSurfaceTextureManager.clear();
+    ASSERT(!m_contentsTextureMemoryUseBytes);
+    releaseRenderSurfaceTextures();
 }
 
 String LayerRendererChromium::layerTreeAsText() const
 {
     TextStream ts;
     if (rootLayer()) {
-        ts << rootLayer()->platformLayer()->layerTreeAsText();
+        ts << rootLayer()->layerTreeAsText();
         ts << "RenderSurfaces:\n";
-        dumpRenderSurfaces(ts, 1, rootLayer()->platformLayer());
+        dumpRenderSurfaces(ts, 1, rootLayer());
     }
     return ts.release();
 }
 
-void LayerRendererChromium::dumpRenderSurfaces(TextStream& ts, int indent, const LayerChromium* layer) const
+void LayerRendererChromium::dumpRenderSurfaces(TextStream& ts, int indent, const CCLayerImpl* layer) const
 {
     if (layer->renderSurface())
         layer->renderSurface()->dumpSurface(ts, indent);
index afbe22d..5d804ad 100644 (file)
@@ -74,7 +74,7 @@ class NonCompositedContentHost;
 // Class that handles drawing of composited render layers using GL.
 class LayerRendererChromium : public RefCounted<LayerRendererChromium> {
 public:
-    static PassRefPtr<LayerRendererChromium> create(CCLayerTreeHost*, CCLayerTreeHostImpl*, PassRefPtr<GraphicsContext3D>);
+    static PassRefPtr<LayerRendererChromium> create(CCLayerTreeHostImpl*, PassRefPtr<GraphicsContext3D>);
 
     // Must be called in order to allow the LayerRendererChromium to destruct
     void close();
@@ -84,19 +84,13 @@ public:
     const CCSettings& settings() const { return m_owner->settings(); }
     const LayerRendererCapabilities& capabilities() const { return m_capabilities; }
 
-    CCLayerTreeHost* owner() { return m_owner; }
-    const CCLayerTreeHost* owner() const { return m_owner; }
-
-    GraphicsLayer* rootLayer() { return m_owner->rootLayer(); }
-    const GraphicsLayer* rootLayer() const { return m_owner->rootLayer(); }
-
-    CCLayerImpl* rootLayerImpl() { return m_ownerImpl->rootLayer(); }
-    const CCLayerImpl* rootLayerImpl() const { return m_ownerImpl->rootLayer(); }
+    CCLayerImpl* rootLayer() { return m_owner->rootLayer(); }
+    const CCLayerImpl* rootLayer() const { return m_owner->rootLayer(); }
 
     GraphicsContext3D* context();
     bool contextSupportsMapSub() const { return m_capabilities.usingMapSub; }
 
-    const IntSize& viewportSize() { return m_ownerImpl->viewportSize(); }
+    const IntSize& viewportSize() { return m_owner->viewportSize(); }
     int viewportWidth() { return viewportSize().width(); }
     int viewportHeight() { return viewportSize().height(); }
 
@@ -139,7 +133,6 @@ public:
 
     void getFramebufferPixels(void *pixels, const IntRect& rect);
 
-    TextureManager* contentsTextureManager() const { return m_contentsTextureManager.get(); }
     TextureManager* renderSurfaceTextureManager() const { return m_renderSurfaceTextureManager.get(); }
 
     CCHeadsUpDisplay* headsUpDisplay() { return m_headsUpDisplay.get(); }
@@ -150,17 +143,16 @@ public:
 
     bool isContextLost();
 
-    void releaseTextures();
+    void releaseRenderSurfaceTextures();
 
     GC3Denum bestTextureFormat();
 
     typedef Vector<RefPtr<CCLayerImpl> > CCLayerList;
 
-    // FIXME: Remove this when the contents texture manager has moved to CCLayerTreeHost.
-    static size_t textureMemoryReclaimLimit();
+    void setContentsTextureMemoryUseBytes(size_t contentsTextureMemoryUseBytes) { m_contentsTextureMemoryUseBytes = contentsTextureMemoryUseBytes; }
 
 private:
-    LayerRendererChromium(CCLayerTreeHost*, CCLayerTreeHostImpl*, PassRefPtr<GraphicsContext3D>);
+    LayerRendererChromium(CCLayerTreeHostImpl*, PassRefPtr<GraphicsContext3D>);
     bool initialize();
 
     void drawLayersInternal();
@@ -179,17 +171,14 @@ private:
 
     static bool compareLayerZ(const RefPtr<CCLayerImpl>&, const RefPtr<CCLayerImpl>&);
 
-    void dumpRenderSurfaces(TextStream&, int indent, const LayerChromium*) const;
+    void dumpRenderSurfaces(TextStream&, int indent, const CCLayerImpl*) const;
 
     bool initializeSharedObjects();
     void cleanupSharedObjects();
 
     void clearRenderSurfacesOnCCLayerImplRecursive(CCLayerImpl*);
 
-    // FIXME: Remove CCLayerTreeHost field
-    CCLayerTreeHost* m_owner;
-
-    CCLayerTreeHostImpl* m_ownerImpl;
+    CCLayerTreeHostImpl* m_owner;
 
     LayerRendererCapabilities m_capabilities;
 
@@ -220,7 +209,7 @@ private:
     OwnPtr<CCVideoLayerImpl::RGBAProgram> m_videoLayerRGBAProgram;
     OwnPtr<CCVideoLayerImpl::YUVProgram> m_videoLayerYUVProgram;
 
-    OwnPtr<TextureManager> m_contentsTextureManager;
+    size_t m_contentsTextureMemoryUseBytes;
     OwnPtr<TextureManager> m_renderSurfaceTextureManager;
 
     OwnPtr<CCHeadsUpDisplay> m_headsUpDisplay;
index 790c70f..f1f818b 100644 (file)
@@ -83,7 +83,6 @@ void ManagedTexture::unreserve()
 void ManagedTexture::bindTexture(GraphicsContext3D* context)
 {
     ASSERT(m_textureManager->hasTexture(m_token));
-    ASSERT(context == m_textureManager->associatedContextDebugOnly());
     if (!m_textureId)
         m_textureId = m_textureManager->allocateTexture(context, m_token);
     context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
@@ -92,7 +91,6 @@ void ManagedTexture::bindTexture(GraphicsContext3D* context)
 void ManagedTexture::framebufferTexture2D(GraphicsContext3D* context)
 {
     ASSERT(m_textureManager->hasTexture(m_token));
-    ASSERT(context == m_textureManager->associatedContextDebugOnly());
     if (!m_textureId)
         m_textureId = m_textureManager->allocateTexture(context, m_token);
     context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_textureId, 0);
index 852dc2e..d1cfc80 100644 (file)
@@ -46,9 +46,6 @@ public:
 
     virtual void pushPropertiesTo(CCLayerImpl*);
 
-protected:
-    virtual const char* layerTypeAsString() const { return "PluginLayer"; }
-
 private:
     explicit PluginLayerChromium(GraphicsLayerChromium* owner);
     unsigned m_textureId;
index a5fd74b..73f3ab2 100644 (file)
@@ -59,27 +59,5 @@ FloatRect RenderSurfaceChromium::drawableContentRect() const
     return drawableContentRect;
 }
 
-String RenderSurfaceChromium::name() const
-{
-    return String::format("RenderSurface(id=%d,owner=%s)", m_owningLayer->id(), m_owningLayer->name().utf8().data());
-}
-
-static void writeIndent(TextStream& ts, int indent)
-{
-    for (int i = 0; i != indent; ++i)
-        ts << "  ";
-}
-
-void RenderSurfaceChromium::dumpSurface(TextStream& ts, int indent) const
-{
-    writeIndent(ts, indent);
-    ts << name() << "\n";
-
-    writeIndent(ts, indent+1);
-    ts << "contentRect: (" << m_contentRect.x() << ", " << m_contentRect.y() << ", " << m_contentRect.width() << ", " << m_contentRect.height()
-        << " scissorRect: (" << m_scissorRect.x() << ", " << m_scissorRect.y() << ", " << m_scissorRect.width() << ", " << m_scissorRect.height() << ")"
-        << "\n";
-}
-
 }
 #endif // USE(ACCELERATED_COMPOSITING)
index 4a062c5..8c2fb69 100644 (file)
@@ -54,9 +54,6 @@ public:
     void cleanupResources();
     void draw(const IntRect& targetSurfaceRect);
 
-    String name() const;
-    void dumpSurface(TextStream&, int indent) const;
-
     // Returns the rect that encloses the RenderSurface including any reflection.
     FloatRect drawableContentRect() const;
 
index 8fa0651..9a068dc 100644 (file)
@@ -44,6 +44,21 @@ static size_t memoryUseBytes(IntSize size, GC3Denum textureFormat)
     return size.width() * size.height() * componentsPerPixel * bytesPerComponent;
 }
 
+size_t TextureManager::highLimitBytes()
+{
+    return 128 * 1024 * 1024;
+}
+
+size_t TextureManager::reclaimLimitBytes()
+{
+    return 64 * 1024 * 1024;
+}
+
+size_t TextureManager::lowLimitBytes()
+{
+    return 3 * 1024 * 1024;
+}
+
 TextureManager::TextureManager(size_t memoryLimitBytes, int maxTextureSize)
     : m_memoryLimitBytes(memoryLimitBytes)
     , m_memoryUseBytes(0)
@@ -139,12 +154,24 @@ void TextureManager::addTexture(TextureToken token, TextureInfo info)
 
 void TextureManager::deleteEvictedTextures(GraphicsContext3D* context)
 {
-    ASSERT(context == m_associatedContextDebugOnly);
-    for (size_t i = 0; i < m_evictedTextureIds.size(); ++i) {
-        if (m_evictedTextureIds[i])
-            GLC(context, context->deleteTexture(m_evictedTextureIds[i]));
+    if (context) {
+        for (size_t i = 0; i < m_evictedTextures.size(); ++i) {
+            if (m_evictedTextures[i].textureId) {
+#ifndef NDEBUG
+                ASSERT(m_evictedTextures[i].allocatingContext == context);
+#endif
+                GLC(context, context->deleteTexture(m_evictedTextures[i].textureId));
+            }
+        }
     }
-    m_evictedTextureIds.clear();
+    m_evictedTextures.clear();
+}
+
+void TextureManager::evictAndDeleteAllTextures(GraphicsContext3D* context)
+{
+    unprotectAllTextures();
+    reduceMemoryToLimit(0);
+    deleteEvictedTextures(context);
 }
 
 void TextureManager::removeTexture(TextureToken token, TextureInfo info)
@@ -155,12 +182,16 @@ void TextureManager::removeTexture(TextureToken token, TextureInfo info)
     m_textures.remove(token);
     ASSERT(m_textureLRUSet.contains(token));
     m_textureLRUSet.remove(token);
-    m_evictedTextureIds.append(info.textureId);
+    EvictionEntry entry;
+    entry.textureId = info.textureId;
+#ifndef NDEBUG
+    entry.allocatingContext = info.allocatingContext;
+#endif
+    m_evictedTextures.append(entry);
 }
 
 unsigned TextureManager::allocateTexture(GraphicsContext3D* context, TextureToken token)
 {
-    ASSERT(context == m_associatedContextDebugOnly);
     TextureMap::iterator it = m_textures.find(token);
     ASSERT(it != m_textures.end());
     TextureInfo* info = &it.get()->second;
@@ -177,6 +208,9 @@ unsigned TextureManager::allocateTexture(GraphicsContext3D* context, TextureToke
     GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
     GLC(context, context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, info->format, info->size.width(), info->size.height(), 0, info->format, GraphicsContext3D::UNSIGNED_BYTE));
     info->textureId = textureId;
+#ifndef NDEBUG
+    info->allocatingContext = context;
+#endif
     return textureId;
 }
 
@@ -204,6 +238,9 @@ bool TextureManager::requestTexture(TextureToken token, IntSize size, unsigned f
     info.format = format;
     info.textureId = 0;
     info.isProtected = true;
+#ifndef NDEBUG
+    info.allocatingContext = 0;
+#endif
     addTexture(token, info);
     return true;
 }
index 12ad208..2105c57 100644 (file)
@@ -45,6 +45,13 @@ public:
         return adoptPtr(new TextureManager(memoryLimitBytes, maxTextureSize));
     }
 
+    // Absolute maximum limit for texture allocations for this instance.
+    static size_t highLimitBytes();
+    // Preferred texture size limit. Can be exceeded if needed.
+    static size_t reclaimLimitBytes();
+    // The maximum texture memory usage when asked to release textures.
+    static size_t lowLimitBytes();
+
     void setMemoryLimitBytes(size_t);
 
     TextureToken getToken();
@@ -61,14 +68,11 @@ public:
     unsigned allocateTexture(GraphicsContext3D*, TextureToken);
     void deleteEvictedTextures(GraphicsContext3D*);
 
+    void evictAndDeleteAllTextures(GraphicsContext3D*);
+
     void reduceMemoryToLimit(size_t);
     size_t currentMemoryUseBytes() const { return m_memoryUseBytes; }
 
-#ifndef NDEBUG
-    void setAssociatedContextDebugOnly(GraphicsContext3D* context) { m_associatedContextDebugOnly = context; }
-    GraphicsContext3D* associatedContextDebugOnly() const { return m_associatedContextDebugOnly; }
-#endif
-
 private:
     TextureManager(size_t memoryLimitBytes, int maxTextureSize);
 
@@ -77,6 +81,9 @@ private:
         GC3Denum format;
         unsigned textureId;
         bool isProtected;
+#ifndef NDEBUG
+        GraphicsContext3D* allocatingContext;
+#endif
     };
 
     void addTexture(TextureToken, TextureInfo);
@@ -91,11 +98,14 @@ private:
     int m_maxTextureSize;
     TextureToken m_nextToken;
 
+    struct EvictionEntry {
+        unsigned textureId;
 #ifndef NDEBUG
-    GraphicsContext3D* m_associatedContextDebugOnly;
+        GraphicsContext3D* allocatingContext;
 #endif
+    };
 
-    Vector<unsigned> m_evictedTextureIds;
+    Vector<EvictionEntry> m_evictedTextures;
 };
 
 }
index ddeffe7..6bd2821 100644 (file)
@@ -265,19 +265,6 @@ void TiledLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
     }
 }
 
-static void writeIndent(TextStream& ts, int indent)
-{
-    for (int i = 0; i != indent; ++i)
-        ts << "  ";
-}
-
-void TiledLayerChromium::dumpLayerProperties(TextStream& ts, int indent) const
-{
-    LayerChromium::dumpLayerProperties(ts, indent);
-    writeIndent(ts, indent);
-    ts << "skipsDraw: " << (!m_tiler || m_skipsDraw) << "\n";
-}
-
 TextureManager* TiledLayerChromium::textureManager() const
 {
     if (!layerTreeHost())
index 5856918..6926e3d 100644 (file)
@@ -74,8 +74,6 @@ protected:
 private:
     virtual PassRefPtr<CCLayerImpl> createCCLayerImpl();
 
-    virtual void dumpLayerProperties(TextStream&, int indent) const;
-
     virtual void setLayerTreeHost(CCLayerTreeHost*);
 
     void createTilerIfNeeded();
index 7b156fb..9f79032 100644 (file)
@@ -63,7 +63,6 @@ public:
 
 protected:
     virtual void cleanupResources();
-    virtual const char* layerTypeAsString() const { return "VideoLayer"; }
 
 private:
     struct Texture {
index 862fa88..21550df 100644 (file)
@@ -57,9 +57,6 @@ public:
     void setContext(const GraphicsContext3D* context);
     GraphicsContext3D* context() { return m_context; }
 
-protected:
-    virtual const char* layerTypeAsString() const { return "WebGLLayer"; }
-
 private:
     explicit WebGLLayerChromium(GraphicsLayerChromium* owner);
     friend class WebGLLayerChromiumRateLimitTask;
index 8cc223e..aab01d2 100644 (file)
@@ -48,6 +48,11 @@ CCCanvasLayerImpl::~CCCanvasLayerImpl()
 {
 }
 
+const char* CCCanvasLayerImpl::layerTypeAsString() const
+{
+    return "CanvasLayer";
+}
+
 void CCCanvasLayerImpl::draw()
 {
     ASSERT(CCProxy::isImplThread());
index d85eba8..5d45f5e 100644 (file)
@@ -52,6 +52,8 @@ public:
 private:
     explicit CCCanvasLayerImpl(int);
 
+    virtual const char* layerTypeAsString() const;
+
     unsigned m_textureId;
     bool m_hasAlpha;
     bool m_premultipliedAlpha;
index 300f471..2ce1126 100644 (file)
@@ -85,6 +85,11 @@ CCLayerImpl::~CCLayerImpl()
 {
 }
 
+const char* CCLayerImpl::layerTypeAsString() const
+{
+    return "LayerChromium";
+}
+
 void CCLayerImpl::addChild(PassRefPtr<CCLayerImpl> child)
 {
     child->setParent(this);
@@ -227,6 +232,33 @@ void sortLayers(Vector<RefPtr<CCLayerImpl> >::iterator first, Vector<RefPtr<CCLa
     layerSorter->sort(first, end);
 }
 
+String CCLayerImpl::layerTreeAsText() const
+{
+    TextStream ts;
+    dumpLayer(ts, 0);
+    return ts.release();
 }
 
+void CCLayerImpl::dumpLayer(TextStream& ts, int indent) const
+{
+    writeIndent(ts, indent);
+    ts << layerTypeAsString() << "(" << m_name << ")\n";
+    dumpLayerProperties(ts, indent+2);
+    if (m_replicaLayer) {
+        writeIndent(ts, indent+2);
+        ts << "Replica:\n";
+        m_replicaLayer->dumpLayer(ts, indent+3);
+    }
+    if (m_maskLayer) {
+        writeIndent(ts, indent+2);
+        ts << "Mask:\n";
+        m_maskLayer->dumpLayer(ts, indent+3);
+    }
+    for (size_t i = 0; i < m_children.size(); ++i)
+        m_children[i]->dumpLayer(ts, indent+1);
+}
+
+}
+
+
 #endif // USE(ACCELERATED_COMPOSITING)
index c7dc469..909e2f7 100644 (file)
@@ -165,11 +165,12 @@ public:
     const IntRect& drawableContentRect() const { return m_drawableContentRect; }
     void setDrawableContentRect(const IntRect& rect) { m_drawableContentRect = rect; }
 
-    virtual void dumpLayerProperties(TextStream&, int indent) const;
+    String layerTreeAsText() const;
 
 protected:
     explicit CCLayerImpl(int);
 
+    virtual void dumpLayerProperties(TextStream&, int indent) const;
     static void writeIndent(TextStream&, int indent);
 
 private:
@@ -177,6 +178,10 @@ private:
     friend class TreeSynchronizer;
     void clearChildList(); // Warning: This does not preserve tree structure invariants and so is only exposed to the tree synchronizer.
 
+    virtual const char* layerTypeAsString() const;
+
+    void dumpLayer(TextStream&, int indent) const;
+
     // Properties internal to CCLayerImpl
     CCLayerImpl* m_parent;
     Vector<RefPtr<CCLayerImpl> > m_children;
index ee0dd43..7b8cb41 100644 (file)
@@ -69,7 +69,7 @@ bool CCLayerTreeHost::initialize()
         m_proxy = CCSingleThreadProxy::create(this);
     m_proxy->start();
 
-    if (!m_proxy->initializeLayerRenderer(this))
+    if (!m_proxy->initializeLayerRenderer())
         return false;
 
     // Update m_settings based on capabilities that we got back from the renderer.
@@ -86,14 +86,25 @@ bool CCLayerTreeHost::initialize()
     // We changed the root layer. Tell the proxy a commit is needed.
     m_proxy->setNeedsCommitAndRedraw();
 
+    m_contentsTextureManager = TextureManager::create(TextureManager::highLimitBytes(), m_proxy->layerRendererCapabilities().maxTextureSize);
     return true;
 }
 
 CCLayerTreeHost::~CCLayerTreeHost()
 {
+    ASSERT(CCProxy::isMainThread());
     TRACE_EVENT("CCLayerTreeHost::~CCLayerTreeHost", this, 0);
     m_proxy->stop();
     m_proxy.clear();
+    m_updateList.clear();
+    ASSERT(!m_contentsTextureManager->currentMemoryUseBytes());
+    m_contentsTextureManager.clear();
+}
+
+void CCLayerTreeHost::deleteContentsTextures(GraphicsContext3D* context)
+{
+    ASSERT(CCProxy::isImplThread());
+    m_contentsTextureManager->evictAndDeleteAllTextures(context);
 }
 
 void CCLayerTreeHost::animateAndLayout(double frameBeginTime)
@@ -109,7 +120,7 @@ void CCLayerTreeHost::commitTo(CCLayerTreeHostImpl* hostImpl)
     TRACE_EVENT("CCLayerTreeHost::commitTo", this, 0);
     hostImpl->setSourceFrameNumber(frameNumber());
 
-    contentsTextureManager()->reduceMemoryToLimit(hostImpl->layerRenderer()->textureMemoryReclaimLimit());
+    contentsTextureManager()->reduceMemoryToLimit(TextureManager::reclaimLimitBytes());
     contentsTextureManager()->deleteEvictedTextures(hostImpl->context());
 
     updateCompositorResources(m_updateList, hostImpl->context());
@@ -119,6 +130,9 @@ void CCLayerTreeHost::commitTo(CCLayerTreeHostImpl* hostImpl)
     hostImpl->setZoomAnimatorScale(m_zoomAnimatorScale);
     hostImpl->setViewport(viewportSize());
 
+    hostImpl->layerRenderer()->setContentsTextureMemoryUseBytes(m_contentsTextureManager->currentMemoryUseBytes());
+    m_contentsTextureManager->unprotectAllTextures();
+
     // Synchronize trees, if one exists at all...
     if (rootLayer())
         hostImpl->setRootLayer(TreeSynchronizer::synchronizeTrees(rootLayer()->platformLayer(), hostImpl->rootLayer()));
@@ -145,6 +159,8 @@ PassOwnPtr<CCLayerTreeHostImpl> CCLayerTreeHost::createLayerTreeHostImpl()
 
 void CCLayerTreeHost::didRecreateGraphicsContext(bool success)
 {
+    m_contentsTextureManager->evictAndDeleteAllTextures(0);
+
     if (rootLayer())
         rootLayer()->platformLayer()->cleanupResourcesRecursive();
     m_client->didRecreateGraphicsContext(success);
@@ -259,7 +275,14 @@ void CCLayerTreeHost::setViewport(const IntSize& viewportSize, const IntSize& co
 void CCLayerTreeHost::setVisible(bool visible)
 {
     m_visible = visible;
-    m_proxy->setNeedsCommitAndRedraw();
+    if (visible)
+        m_proxy->setNeedsCommitAndRedraw();
+    else {
+        m_nonCompositedContentHost->protectVisibleTileTextures();
+        m_contentsTextureManager->reduceMemoryToLimit(TextureManager::lowLimitBytes());
+        m_contentsTextureManager->unprotectAllTextures();
+        m_proxy->setNeedsCommit();
+    }
 }
 
 void CCLayerTreeHost::loseCompositorContext(int numTimes)
@@ -269,7 +292,7 @@ void CCLayerTreeHost::loseCompositorContext(int numTimes)
 
 TextureManager* CCLayerTreeHost::contentsTextureManager() const
 {
-    return m_proxy->contentsTextureManager();
+    return m_contentsTextureManager.get();
 }
 
 #if !USE(THREADED_COMPOSITING)
index ed98c2e..c713f03 100644 (file)
@@ -157,6 +157,8 @@ public:
 
     void updateLayers();
 
+    void deleteContentsTextures(GraphicsContext3D*);
+
 protected:
     CCLayerTreeHost(CCLayerTreeHostClient*, const CCSettings&);
 
@@ -184,6 +186,7 @@ private:
 
     OwnPtr<GraphicsLayer> m_rootLayer;
     OwnPtr<NonCompositedContentHost> m_nonCompositedContentHost;
+    OwnPtr<TextureManager> m_contentsTextureManager;
 
     LayerList m_updateList;
 
index 7082d65..bec7c02 100644 (file)
@@ -74,7 +74,7 @@ void CCLayerTreeHostImpl::drawLayers()
 {
     TRACE_EVENT("CCLayerTreeHostImpl::drawLayers", this, 0);
     ASSERT(m_layerRenderer);
-    if (m_layerRenderer->owner()->rootLayer())
+    if (m_layerRenderer->rootLayer())
         m_layerRenderer->drawLayers();
 
     ++m_frameNumber;
@@ -116,31 +116,27 @@ void CCLayerTreeHostImpl::setRootLayer(PassRefPtr<CCLayerImpl> layer)
 void CCLayerTreeHostImpl::setVisible(bool visible)
 {
     if (m_layerRenderer && !visible)
-        m_layerRenderer->releaseTextures();
+        m_layerRenderer->releaseRenderSurfaceTextures();
 }
 
-bool CCLayerTreeHostImpl::initializeLayerRenderer(CCLayerTreeHost* implHack, PassRefPtr<GraphicsContext3D> context)
+bool CCLayerTreeHostImpl::initializeLayerRenderer(PassRefPtr<GraphicsContext3D> context)
 {
-    // If m_layerRenderer exists, then we are recovering from a lost context
-    bool recreatingRenderer = m_layerRenderer;
-
-    // First time layerRenderer creation
     RefPtr<LayerRendererChromium> layerRenderer;
-    if (!recreatingRenderer)
-        layerRenderer = LayerRendererChromium::create(implHack, this, context);
-    else
-        layerRenderer = LayerRendererChromium::create(m_layerRenderer->owner(), this, context);
-
+    layerRenderer = LayerRendererChromium::create(this, context);
 
     // If creation failed, and we had asked for accelerated painting, disable accelerated painting
     // and try creating the renderer again.
     if (!layerRenderer && m_settings.acceleratePainting) {
         m_settings.acceleratePainting = false;
 
-        if (!recreatingRenderer)
-            layerRenderer = LayerRendererChromium::create(implHack, this, context);
-        else
-            layerRenderer = LayerRendererChromium::create(m_layerRenderer->owner(), this, context);
+        layerRenderer = LayerRendererChromium::create(this, context);
+    }
+
+    // If we had a previous layer renderer, then its context must have been lost along with all of its resources.
+    // Let the old layer renderer known its resources are gone.
+    if (m_layerRenderer) {
+        m_layerRenderer->setContentsTextureMemoryUseBytes(0);
+        m_layerRenderer->close();
     }
 
     m_layerRenderer = layerRenderer;
index 052f260..dff9680 100644 (file)
@@ -56,7 +56,7 @@ public:
     void finishAllRendering();
     int frameNumber() const { return m_frameNumber; }
 
-    bool initializeLayerRenderer(CCLayerTreeHost* ownerHack, PassRefPtr<GraphicsContext3D>);
+    bool initializeLayerRenderer(PassRefPtr<GraphicsContext3D>);
     bool isContextLost();
     LayerRendererChromium* layerRenderer() { return m_layerRenderer.get(); }
     const LayerRendererCapabilities& layerRendererCapabilities() const;
@@ -77,6 +77,7 @@ public:
     const IntSize& viewportSize() const { return m_viewportSize; }
     void setZoomAnimatorScale(double);
 
+    const CCSettings& settings() const { return m_settings; }
 protected:
     explicit CCLayerTreeHostImpl(const CCSettings&);
     int m_sourceFrameNumber;
index 0f165be..0250010 100644 (file)
@@ -46,6 +46,11 @@ CCPluginLayerImpl::~CCPluginLayerImpl()
 {
 }
 
+const char* CCPluginLayerImpl::layerTypeAsString() const
+{
+    return "PluginLayer";
+}
+
 void CCPluginLayerImpl::draw()
 {
     ASSERT(CCProxy::isImplThread());
index 9b4c536..cacc22f 100644 (file)
@@ -51,6 +51,8 @@ public:
 private:
     explicit CCPluginLayerImpl(int);
 
+    virtual const char* layerTypeAsString() const;
+
     unsigned m_textureId;
 };
 
index aae6694..f5e418b 100644 (file)
@@ -58,10 +58,11 @@ public:
 
     virtual bool isStarted() const = 0;
 
-    virtual bool initializeLayerRenderer(CCLayerTreeHost* ownerHack) = 0;
+    virtual bool initializeLayerRenderer() = 0;
 
     virtual const LayerRendererCapabilities& layerRendererCapabilities() const = 0;
 
+    virtual void setNeedsCommit() = 0;
     virtual void setNeedsCommitAndRedraw() = 0;
     virtual void setNeedsRedraw() = 0;
 
@@ -80,9 +81,6 @@ public:
     // Temporary hack while render_widget still does scheduling for CCLayerTreeHostMainThreadI
     virtual GraphicsContext3D* context() = 0;
 
-    // Temporary hack while LayerChromiums hold references to LayerRendererChromiums
-    virtual TextureManager* contentsTextureManager() = 0;
-
 protected:
     CCProxy() { }
     friend class ScopedSetImplThread;
index 0af330d..2d27d72 100644 (file)
@@ -121,8 +121,9 @@ bool CCSingleThreadProxy::isStarted() const
     return m_layerTreeHostImpl;
 }
 
-bool CCSingleThreadProxy::initializeLayerRenderer(CCLayerTreeHost* ownerHack)
+bool CCSingleThreadProxy::initializeLayerRenderer()
 {
+    ASSERT(isMainThread());
     RefPtr<GraphicsContext3D> context = m_layerTreeHost->createLayerTreeHostContext3D();
     if (!context)
         return false;
@@ -130,7 +131,7 @@ bool CCSingleThreadProxy::initializeLayerRenderer(CCLayerTreeHost* ownerHack)
 
     {
         ScopedSetImplThread impl;
-        return m_layerTreeHostImpl->initializeLayerRenderer(ownerHack, context);
+        return m_layerTreeHostImpl->initializeLayerRenderer(context);
     }
 }
 
@@ -146,6 +147,18 @@ void CCSingleThreadProxy::loseCompositorContext(int numTimes)
     m_timesRecreateShouldFail = numTimes - 1;
 }
 
+void CCSingleThreadProxy::setNeedsCommit()
+{
+    ASSERT(isMainThread());
+    // Commit immediately
+    {
+        ScopedSetImplThread impl;
+        m_layerTreeHostImpl->beginCommit();
+        m_layerTreeHost->commitTo(m_layerTreeHostImpl.get());
+        m_layerTreeHostImpl->commitComplete();
+    }
+}
+
 void CCSingleThreadProxy::setNeedsCommitAndRedraw()
 {
     ASSERT(isMainThread());
@@ -170,16 +183,12 @@ void CCSingleThreadProxy::stop()
     ASSERT(isMainThread());
     {
         ScopedSetImplThread impl;
+        m_layerTreeHost->deleteContentsTextures(m_layerTreeHostImpl->context());
         m_layerTreeHostImpl.clear();
     }
     m_layerTreeHost = 0;
 }
 
-TextureManager* CCSingleThreadProxy::contentsTextureManager()
-{
-    return m_layerTreeHostImpl->layerRenderer()->contentsTextureManager();
-}
-
 #if !USE(THREADED_COMPOSITING)
 // Called by the legacy scheduling path (e.g. where render_widget does the scheduling)
 void CCSingleThreadProxy::compositeImmediately()
@@ -197,6 +206,7 @@ void CCSingleThreadProxy::compositeImmediately()
 
 bool CCSingleThreadProxy::recreateContextIfNeeded()
 {
+    ASSERT(isMainThread());
     if (!m_graphicsContextLost)
         return true;
     RefPtr<GraphicsContext3D> context;
@@ -207,7 +217,7 @@ bool CCSingleThreadProxy::recreateContextIfNeeded()
 
     if (context) {
         ASSERT(context->hasOneRef());
-        if (m_layerTreeHostImpl->initializeLayerRenderer(0, context)) {
+        if (m_layerTreeHostImpl->initializeLayerRenderer(context)) {
             m_layerTreeHost->didRecreateGraphicsContext(true);
             m_graphicsContextLost = false;
             return true;
index 765b859..bbbe5f5 100644 (file)
@@ -44,17 +44,15 @@ public:
     virtual GraphicsContext3D* context();
     virtual void finishAllRendering();
     virtual bool isStarted() const;
-    virtual bool initializeLayerRenderer(CCLayerTreeHost* ownerHack);
+    virtual bool initializeLayerRenderer();
     virtual const LayerRendererCapabilities& layerRendererCapabilities() const;
     virtual void loseCompositorContext(int numTimes);
+    virtual void setNeedsCommit();
     virtual void setNeedsCommitAndRedraw();
     virtual void setNeedsRedraw();
     virtual void start();
     virtual void stop();
 
-    // Temporary hack while LayerChromiums hold references to LayerRendererChromiums
-    virtual TextureManager* contentsTextureManager();
-
     // Special case functions.
 #if !USE(THREADED_COMPOSITING)
     void compositeImmediately();
index 1a88384..12b5b36 100644 (file)
@@ -98,7 +98,7 @@ bool CCThreadProxy::isStarted() const
     return m_layerTreeHostImpl;
 }
 
-bool CCThreadProxy::initializeLayerRenderer(CCLayerTreeHost* ownerHack)
+bool CCThreadProxy::initializeLayerRenderer()
 {
     RefPtr<GraphicsContext3D> context = m_layerTreeHost->createLayerTreeHostContext3D();
     if (!context)
@@ -115,8 +115,7 @@ bool CCThreadProxy::initializeLayerRenderer(CCLayerTreeHost* ownerHack)
     bool initializeSucceeded;
     LayerRendererCapabilities capabilities;
     ccThread->postTask(createCCThreadTask(this, &CCThreadProxy::initializeLayerRendererOnCCThread,
-                                          AllowCrossThreadAccess(ownerHack), AllowCrossThreadAccess(contextPtr),
-                                          AllowCrossThreadAccess(&completion), AllowCrossThreadAccess(&initializeSucceeded), AllowCrossThreadAccess(&capabilities)));
+                                          AllowCrossThreadAccess(contextPtr), AllowCrossThreadAccess(&completion), AllowCrossThreadAccess(&initializeSucceeded), AllowCrossThreadAccess(&capabilities)));
     completion.wait();
 
     if (initializeSucceeded)
@@ -134,6 +133,17 @@ void CCThreadProxy::loseCompositorContext(int numTimes)
     ASSERT_NOT_REACHED();
 }
 
+void CCThreadProxy::setNeedsCommit()
+{
+    ASSERT(isMainThread());
+    if (m_commitPending)
+        return;
+
+    TRACE_EVENT("CCThreadProxy::setNeedsCommit", this, 0);
+    m_commitPending = true;
+    ccThread->postTask(createCCThreadTask(this, &CCThreadProxy::setNeedsCommitOnCCThread));
+}
+
 void CCThreadProxy::setNeedsCommitAndRedraw()
 {
     ASSERT(isMainThread());
@@ -172,12 +182,6 @@ void CCThreadProxy::stop()
     m_layerTreeHost = 0;
 }
 
-TextureManager* CCThreadProxy::contentsTextureManager()
-{
-    ASSERT_NOT_REACHED();
-    return 0;
-}
-
 void CCThreadProxy::beginFrameAndCommitOnCCThread()
 {
     TRACE_EVENT("CCThreadProxy::beginFrameAndCommitOnCCThread", this, 0);
@@ -229,6 +233,15 @@ void CCThreadProxy::drawLayersOnCCThread()
         m_layerTreeHostImpl->drawLayers();
 }
 
+void CCThreadProxy::setNeedsCommitOnCCThread()
+{
+    TRACE_EVENT("CCThreadProxy::setNeedsCommitOnCCThread", this, 0);
+    ASSERT(isImplThread());
+    ASSERT(m_layerTreeHostImpl);
+    // FIXME: Not yet implemented, see https://bugs.webkit.org/show_bug.cgi?id=67417
+    ASSERT_NOT_REACHED();
+}
+
 void CCThreadProxy::setNeedsCommitAndRedrawOnCCThread()
 {
     TRACE_EVENT("CCThreadProxy::setNeedsCommitAndRedrawOnCCThread", this, 0);
@@ -251,12 +264,12 @@ void CCThreadProxy::initializeImplOnCCThread(CCCompletionEvent* completion)
     completion->signal();
 }
 
-void CCThreadProxy::initializeLayerRendererOnCCThread(CCLayerTreeHost* ownerHack, GraphicsContext3D* contextPtr, CCCompletionEvent* completion, bool* initializeSucceeded, LayerRendererCapabilities* capabilities)
+void CCThreadProxy::initializeLayerRendererOnCCThread(GraphicsContext3D* contextPtr, CCCompletionEvent* completion, bool* initializeSucceeded, LayerRendererCapabilities* capabilities)
 {
     TRACE_EVENT("CCThreadProxy::initializeLayerRendererOnCCThread", this, 0);
     ASSERT(isImplThread());
     RefPtr<GraphicsContext3D> context(adoptRef(contextPtr));
-    *initializeSucceeded = m_layerTreeHostImpl->initializeLayerRenderer(ownerHack, context);
+    *initializeSucceeded = m_layerTreeHostImpl->initializeLayerRenderer(context);
     if (*initializeSucceeded)
         *capabilities = m_layerTreeHostImpl->layerRendererCapabilities();
     completion->signal();
@@ -266,6 +279,7 @@ void CCThreadProxy::layerTreeHostClosedOnCCThread(CCCompletionEvent* completion)
 {
     TRACE_EVENT("CCThreadProxy::layerTreeHostClosedOnCCThread", this, 0);
     ASSERT(isImplThread());
+    m_layerTreeHost->deleteContentsTextures(m_layerTreeHostImpl->context());
     m_layerTreeHostImpl.clear();
     completion->signal();
 }
index 24e1fe1..2467724 100644 (file)
@@ -45,17 +45,15 @@ public:
     virtual GraphicsContext3D* context();
     virtual void finishAllRendering();
     virtual bool isStarted() const;
-    virtual bool initializeLayerRenderer(CCLayerTreeHost* ownerHack);
+    virtual bool initializeLayerRenderer();
     virtual const LayerRendererCapabilities& layerRendererCapabilities() const;
     virtual void loseCompositorContext(int numTimes);
+    virtual void setNeedsCommit();
     virtual void setNeedsCommitAndRedraw();
     virtual void setNeedsRedraw();
     virtual void start();
     virtual void stop();
 
-    // Temporary hack while LayerChromiums hold references to LayerRendererChromiums
-    virtual TextureManager* contentsTextureManager();
-
 private:
     explicit CCThreadProxy(CCLayerTreeHost*);
 
@@ -67,7 +65,8 @@ private:
     void commitOnCCThread(CCCompletionEvent*);
     void drawLayersOnCCThread();
     void initializeImplOnCCThread(CCCompletionEvent*);
-    void initializeLayerRendererOnCCThread(CCLayerTreeHost*, GraphicsContext3D*, CCCompletionEvent*, bool* initializeSucceeded, LayerRendererCapabilities*);
+    void initializeLayerRendererOnCCThread(GraphicsContext3D*, CCCompletionEvent*, bool* initializeSucceeded, LayerRendererCapabilities*);
+    void setNeedsCommitOnCCThread();
     void setNeedsCommitAndRedrawOnCCThread();
     void setNeedsRedrawOnCCThread();
     void layerTreeHostClosedOnCCThread(CCCompletionEvent*);
index 1a75834..d466c87 100644 (file)
@@ -60,6 +60,11 @@ CCTiledLayerImpl::~CCTiledLayerImpl()
 {
 }
 
+const char* CCTiledLayerImpl::layerTypeAsString() const
+{
+    return "TiledLayer";
+}
+
 void CCTiledLayerImpl::bindContentsTexture()
 {
     // This function is only valid for single texture layers, e.g. masks.
@@ -75,8 +80,9 @@ void CCTiledLayerImpl::bindContentsTexture()
 
 void CCTiledLayerImpl::dumpLayerProperties(TextStream& ts, int indent) const
 {
-    writeIndent(ts, indent);
     CCLayerImpl::dumpLayerProperties(ts, indent);
+    writeIndent(ts, indent);
+    ts << "skipsDraw: " << (!m_tiler || m_skipsDraw) << "\n";
 }
 
 DrawableTile* CCTiledLayerImpl::tileAt(int i, int j) const
index ceec5f2..8b6e8c5 100644 (file)
@@ -67,6 +67,8 @@ public:
 private:
     explicit CCTiledLayerImpl(int id);
 
+    virtual const char* layerTypeAsString() const;
+
     // Draw all tiles that intersect with the content rect.
     void draw(LayerRendererChromium*, const IntRect& contentRect, const TransformationMatrix&, float opacity);
 
index 293db42..d16914d 100644 (file)
@@ -69,6 +69,11 @@ CCVideoLayerImpl::~CCVideoLayerImpl()
     cleanupResources();
 }
 
+const char* CCVideoLayerImpl::layerTypeAsString() const
+{
+    return "VideoLayer";
+}
+
 void CCVideoLayerImpl::setTexture(size_t index, Platform3DObject textureId, const IntSize& size, const IntSize& visibleSize)
 {
     ASSERT(index < 3);
index bd16376..b6c11c2 100644 (file)
@@ -58,6 +58,8 @@ public:
 private:
     explicit CCVideoLayerImpl(int);
 
+    virtual const char* layerTypeAsString() const;
+
     struct Texture {
         Platform3DObject id;
         IntSize size;