Title: [128344] trunk/Source
Revision
128344
Author
commit-qu...@webkit.org
Date
2012-09-12 11:49:25 -0700 (Wed, 12 Sep 2012)

Log Message

[chromium] Evict textures through the texture manager instead of the resource provider
https://bugs.webkit.org/show_bug.cgi?id=96463

Patch by Christopher Cameron <ccame...@chromium.org> on 2012-09-12
Reviewed by James Robinson.

Source/WebCore:

When deleting contents textures' resources on the impl thread, do the
deletion through the CCPrioritizedTextureManager instead of the
CCResourceProvider.

This requires traversing the backings list on the impl thread while
the main thread is running, so remove the one remaining traversal of
the backings list by the main thread. This traversal happens when
unlinking textures that were evicted by the impl thread, so explicitly
send the list of evicted backings from the impl thread to the main thread.

Unify all resource deletion paths in the CCPrioritizedTextureManager.
Always perform the sequence of eviction (deleting the GL resource) and
then destruction of evicted backings (deleting the objects).  Also,
use the same function (evictBackingsToReduceMemory) to reduce memory
consumption both during commit and when done by the impl thread in response
to a request by the GPU memory manager.

Note that destroying only some of the resources at a time during texture
eviction (as opposed all resources) is still not supported because the
texture upload queues cannot be only-partially invalidated yet.

Updated tests to take this behavior into account.

* platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
(WebCore::CCLayerTreeHost::reduceContentsTexturesMemoryOnImplThread):
(WebCore):
(WebCore::CCLayerTreeHost::getEvictedContentTexturesBackings):
(WebCore::CCLayerTreeHost::unlinkEvictedContentTexturesBackings):
(WebCore::CCLayerTreeHost::deleteEvictedContentTexturesBackings):
* platform/graphics/chromium/cc/CCLayerTreeHost.h:
(CCLayerTreeHost):
* platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
(WebCore::CCLayerTreeHostImpl::releaseContentsTextures):
(WebCore::CCLayerTreeHostImpl::setContentsTexturesPurged):
(WebCore):
* platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
(CCLayerTreeHostImplClient):
(CCLayerTreeHostImpl):
* platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp:
(WebCore::CCPrioritizedTextureManager::~CCPrioritizedTextureManager):
(WebCore::CCPrioritizedTextureManager::acquireBackingTextureIfNeeded):
(WebCore::CCPrioritizedTextureManager::evictBackingsToReduceMemory):
(WebCore::CCPrioritizedTextureManager::reduceMemory):
(WebCore::CCPrioritizedTextureManager::clearAllMemory):
(WebCore::CCPrioritizedTextureManager::reduceMemoryOnImplThread):
(WebCore::CCPrioritizedTextureManager::getEvictedBackings):
(WebCore::CCPrioritizedTextureManager::unlinkEvictedBackings):
(WebCore):
(WebCore::CCPrioritizedTextureManager::deleteEvictedBackings):
(WebCore::CCPrioritizedTextureManager::evictBackingResource):
* platform/graphics/chromium/cc/CCPrioritizedTextureManager.h:
(CCPrioritizedTextureManager):
* platform/graphics/chromium/cc/CCSingleThreadProxy.cpp:
(WebCore::CCSingleThreadProxy::releaseContentsTexturesOnImplThread):
(WebCore):
(WebCore::CCSingleThreadProxy::commitAndComposite):
* platform/graphics/chromium/cc/CCSingleThreadProxy.h:
* platform/graphics/chromium/cc/CCThreadProxy.cpp:
(WebCore::CCThreadProxy::releaseContentsTexturesOnImplThread):
(WebCore):
(WebCore::CCThreadProxy::scheduledActionBeginFrame):
(WebCore::CCThreadProxy::beginFrame):
(WebCore::CCThreadProxy::beginFrameCompleteOnImplThread):
(WebCore::CCThreadProxy::layerTreeHostClosedOnImplThread):
(WebCore::CCThreadProxy::recreateContextOnImplThread):
* platform/graphics/chromium/cc/CCThreadProxy.h:
(BeginFrameAndCommitState):
(CCThreadProxy):

Source/WebKit/chromium:

Update layer tree host impl test to include the extra interface functions
added to CCLayerTreeHostImplClient.

* tests/CCLayerTreeHostImplTest.cpp:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (128343 => 128344)


--- trunk/Source/WebCore/ChangeLog	2012-09-12 18:24:39 UTC (rev 128343)
+++ trunk/Source/WebCore/ChangeLog	2012-09-12 18:49:25 UTC (rev 128344)
@@ -1,3 +1,79 @@
+2012-09-12  Christopher Cameron  <ccame...@chromium.org>
+
+        [chromium] Evict textures through the texture manager instead of the resource provider
+        https://bugs.webkit.org/show_bug.cgi?id=96463
+
+        Reviewed by James Robinson.
+
+        When deleting contents textures' resources on the impl thread, do the
+        deletion through the CCPrioritizedTextureManager instead of the
+        CCResourceProvider.
+
+        This requires traversing the backings list on the impl thread while
+        the main thread is running, so remove the one remaining traversal of
+        the backings list by the main thread. This traversal happens when
+        unlinking textures that were evicted by the impl thread, so explicitly
+        send the list of evicted backings from the impl thread to the main thread.
+
+        Unify all resource deletion paths in the CCPrioritizedTextureManager.
+        Always perform the sequence of eviction (deleting the GL resource) and
+        then destruction of evicted backings (deleting the objects).  Also,
+        use the same function (evictBackingsToReduceMemory) to reduce memory
+        consumption both during commit and when done by the impl thread in response
+        to a request by the GPU memory manager.
+
+        Note that destroying only some of the resources at a time during texture
+        eviction (as opposed all resources) is still not supported because the
+        texture upload queues cannot be only-partially invalidated yet.
+
+        Updated tests to take this behavior into account.
+
+        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
+        (WebCore::CCLayerTreeHost::reduceContentsTexturesMemoryOnImplThread):
+        (WebCore):
+        (WebCore::CCLayerTreeHost::getEvictedContentTexturesBackings):
+        (WebCore::CCLayerTreeHost::unlinkEvictedContentTexturesBackings):
+        (WebCore::CCLayerTreeHost::deleteEvictedContentTexturesBackings):
+        * platform/graphics/chromium/cc/CCLayerTreeHost.h:
+        (CCLayerTreeHost):
+        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
+        (WebCore::CCLayerTreeHostImpl::releaseContentsTextures):
+        (WebCore::CCLayerTreeHostImpl::setContentsTexturesPurged):
+        (WebCore):
+        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
+        (CCLayerTreeHostImplClient):
+        (CCLayerTreeHostImpl):
+        * platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp:
+        (WebCore::CCPrioritizedTextureManager::~CCPrioritizedTextureManager):
+        (WebCore::CCPrioritizedTextureManager::acquireBackingTextureIfNeeded):
+        (WebCore::CCPrioritizedTextureManager::evictBackingsToReduceMemory):
+        (WebCore::CCPrioritizedTextureManager::reduceMemory):
+        (WebCore::CCPrioritizedTextureManager::clearAllMemory):
+        (WebCore::CCPrioritizedTextureManager::reduceMemoryOnImplThread):
+        (WebCore::CCPrioritizedTextureManager::getEvictedBackings):
+        (WebCore::CCPrioritizedTextureManager::unlinkEvictedBackings):
+        (WebCore):
+        (WebCore::CCPrioritizedTextureManager::deleteEvictedBackings):
+        (WebCore::CCPrioritizedTextureManager::evictBackingResource):
+        * platform/graphics/chromium/cc/CCPrioritizedTextureManager.h:
+        (CCPrioritizedTextureManager):
+        * platform/graphics/chromium/cc/CCSingleThreadProxy.cpp:
+        (WebCore::CCSingleThreadProxy::releaseContentsTexturesOnImplThread):
+        (WebCore):
+        (WebCore::CCSingleThreadProxy::commitAndComposite):
+        * platform/graphics/chromium/cc/CCSingleThreadProxy.h:
+        * platform/graphics/chromium/cc/CCThreadProxy.cpp:
+        (WebCore::CCThreadProxy::releaseContentsTexturesOnImplThread):
+        (WebCore):
+        (WebCore::CCThreadProxy::scheduledActionBeginFrame):
+        (WebCore::CCThreadProxy::beginFrame):
+        (WebCore::CCThreadProxy::beginFrameCompleteOnImplThread):
+        (WebCore::CCThreadProxy::layerTreeHostClosedOnImplThread):
+        (WebCore::CCThreadProxy::recreateContextOnImplThread):
+        * platform/graphics/chromium/cc/CCThreadProxy.h:
+        (BeginFrameAndCommitState):
+        (CCThreadProxy):
+
 2012-09-12  Mike Fenton  <mifen...@rim.com>
 
         [BlackBerry] Add custom messages for input type validation.

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp (128343 => 128344)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp	2012-09-12 18:24:39 UTC (rev 128343)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp	2012-09-12 18:49:25 UTC (rev 128344)
@@ -414,18 +414,33 @@
     m_proxy->setVisible(visible);
 }
 
-void CCLayerTreeHost::unlinkAllContentTextures()
+void CCLayerTreeHost::reduceContentsTexturesMemoryOnImplThread(size_t limitBytes, CCResourceProvider* resourceProvider)
 {
+    ASSERT(CCProxy::isImplThread());
+    ASSERT(m_contentsTextureManager.get());
+    m_contentsTextureManager->reduceMemoryOnImplThread(limitBytes, resourceProvider);
+}
+
+void CCLayerTreeHost::getEvictedContentTexturesBackings(CCPrioritizedTextureManager::BackingVector& evictedBackings)
+{
+    ASSERT(CCProxy::isImplThread());
+    evictedBackings.clear();
+    if (m_rendererInitialized)
+        m_contentsTextureManager->getEvictedBackings(evictedBackings);
+}
+
+void CCLayerTreeHost::unlinkEvictedContentTexturesBackings(const CCPrioritizedTextureManager::BackingVector& evictedBackings)
+{
     ASSERT(CCProxy::isMainThread());
     ASSERT(m_contentsTextureManager.get());
-    m_contentsTextureManager->unlinkAllBackings();
+    m_contentsTextureManager->unlinkEvictedBackings(evictedBackings);
 }
 
-void CCLayerTreeHost::deleteUnlinkedTextures()
+bool CCLayerTreeHost::deleteEvictedContentTexturesBackings()
 {
     ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
     ASSERT(m_contentsTextureManager.get());
-    m_contentsTextureManager->deleteAllUnlinkedBackings();
+    return m_contentsTextureManager->deleteEvictedBackings();
 }
 
 void CCLayerTreeHost::startPageScaleAnimation(const IntSize& targetPosition, bool useAnchor, float scale, double durationSec)

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h (128343 => 128344)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h	2012-09-12 18:24:39 UTC (rev 128343)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h	2012-09-12 18:49:25 UTC (rev 128344)
@@ -211,8 +211,19 @@
 
     CCPrioritizedTextureManager* contentsTextureManager() const;
 
-    void unlinkAllContentTextures();
-    void deleteUnlinkedTextures();
+    // Delete contents textures' backing resources until they use only bytesLimit bytes. This may
+    // be called on the impl thread while the main thread is running.
+    void reduceContentsTexturesMemoryOnImplThread(size_t bytesLimit, CCResourceProvider*);
+    // Retrieve the list of all contents textures' backings that have been evicted, to pass to the
+    // main thread to unlink them from their owning textures.
+    void getEvictedContentTexturesBackings(CCPrioritizedTextureManager::BackingVector&);
+    // Unlink the list of contents textures' backings from their owning textures on the main thread
+    // before updating layers.
+    void unlinkEvictedContentTexturesBackings(const CCPrioritizedTextureManager::BackingVector&);
+    // Deletes all evicted backings, unlinking them from their owning textures if needed.
+    // Returns true if this function had to unlink any backings from their owning texture when
+    // destroying them. If this was the case, the impl layer tree may contain invalid resources.
+    bool deleteEvictedContentTexturesBackings();
 
     bool visible() const { return m_visible; }
     void setVisible(bool);

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp (128343 => 128344)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp	2012-09-12 18:24:39 UTC (rev 128343)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp	2012-09-12 18:49:25 UTC (rev 128344)
@@ -521,8 +521,8 @@
 {
     if (m_contentsTexturesPurged)
         return;
-    m_resourceProvider->deleteOwnedResources(CCRenderer::ContentPool);
-    m_contentsTexturesPurged = true;
+    m_client->releaseContentsTexturesOnImplThread();
+    setContentsTexturesPurged();
     m_client->setNeedsCommitOnImplThread();
     m_client->onCanDrawStateChanged(canDraw());
 }
@@ -733,6 +733,12 @@
     return m_renderer;
 }
 
+void CCLayerTreeHostImpl::setContentsTexturesPurged()
+{
+    m_contentsTexturesPurged = true;
+    m_client->onCanDrawStateChanged(canDraw());
+}
+
 void CCLayerTreeHostImpl::resetContentsTexturesPurged()
 {
     m_contentsTexturesPurged = false;

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h (128343 => 128344)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h	2012-09-12 18:24:39 UTC (rev 128343)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h	2012-09-12 18:49:25 UTC (rev 128344)
@@ -60,6 +60,7 @@
     virtual void setNeedsRedrawOnImplThread() = 0;
     virtual void setNeedsCommitOnImplThread() = 0;
     virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) = 0;
+    virtual void releaseContentsTexturesOnImplThread() = 0;
 };
 
 // CCLayerTreeHostImpl owns the CCLayerImpl tree as well as associated rendering state
@@ -157,6 +158,7 @@
     void setSourceFrameNumber(int frameNumber) { m_sourceFrameNumber = frameNumber; }
 
     bool contentsTexturesPurged() const { return m_contentsTexturesPurged; }
+    void setContentsTexturesPurged();
     void resetContentsTexturesPurged();
     size_t memoryAllocationLimitBytes() const { return m_memoryAllocationLimitBytes; }
 

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp (128343 => 128344)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp	2012-09-12 18:24:39 UTC (rev 128343)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.cpp	2012-09-12 18:49:25 UTC (rev 128344)
@@ -51,10 +51,10 @@
     while (m_textures.size() > 0)
         unregisterTexture(*m_textures.begin());
 
-    // Each remaining backing is a leaked opengl texture. We don't have the resourceProvider
-    // to delete the textures at this time so clearMemory() needs to be called before this.
-    while (m_backings.size() > 0)
-        destroyBacking(*m_backings.begin(), 0);
+    deleteEvictedBackings();
+
+    // Each remaining backing is a leaked opengl texture. There should be none.
+    ASSERT(m_backings.isEmpty());
 }
 
 void CCPrioritizedTextureManager::prioritizeTextures()
@@ -211,7 +211,7 @@
 
     // Otherwise reduce memory and just allocate a new backing texures.
     if (!backing) {
-        reduceMemory(m_memoryAvailableBytes - texture->bytes(), resourceProvider);
+        evictBackingsToReduceMemory(m_memoryAvailableBytes - texture->bytes(), RespectManagerPriorityCutoff, resourceProvider);
         backing = createBacking(texture->size(), texture->format(), resourceProvider);
     }
 
@@ -226,18 +226,20 @@
     backing->updatePriority();
 }
 
-void CCPrioritizedTextureManager::reduceMemory(size_t limitBytes, CCResourceProvider* resourceProvider)
+void CCPrioritizedTextureManager::evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy evictionPolicy, CCResourceProvider* resourceProvider)
 {
-    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
+    ASSERT(CCProxy::isImplThread());
     if (memoryUseBytes() <= limitBytes)
         return;
+
     // Destroy backings until we are below the limit,
     // or until all backings remaining are above the cutoff.
     while (memoryUseBytes() > limitBytes && m_backings.size() > 0) {
-        BackingSet::iterator it = m_backings.begin();
-        if ((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePriorityCutoffAtLastPriorityUpdate())
-            break;
-        destroyBacking((*it), resourceProvider);
+        CCPrioritizedTexture::Backing* backing = *m_backings.begin();
+        if (evictionPolicy == RespectManagerPriorityCutoff)
+            if (backing->hadOwnerAtLastPriorityUpdate() && backing->wasAbovePriorityCutoffAtLastPriorityUpdate())
+                break;
+        evictBackingResource(backing, resourceProvider);
     }
 }
 
@@ -248,7 +250,7 @@
     // Make sure that the backings list is up to date and sorted before traversing it.
     updateBackingsPriorities();
 
-    reduceMemory(m_memoryAvailableBytes, resourceProvider);
+    evictBackingsToReduceMemory(m_memoryAvailableBytes, RespectManagerPriorityCutoff, resourceProvider);
     ASSERT(memoryUseBytes() <= maxMemoryLimitBytes());
 
     // We currently collect backings from deleted textures for later recycling.
@@ -263,44 +265,66 @@
         wastedMemory += (*it)->bytes();
     }
     size_t tenPercentOfMemory = m_memoryAvailableBytes / 10;
-    if (wastedMemory <= tenPercentOfMemory)
-        return;
-    reduceMemory(memoryUseBytes() - (wastedMemory - tenPercentOfMemory), resourceProvider);
+    if (wastedMemory > tenPercentOfMemory)
+        evictBackingsToReduceMemory(memoryUseBytes() - (wastedMemory - tenPercentOfMemory), RespectManagerPriorityCutoff, resourceProvider);
+
+    deleteEvictedBackings();
 }
 
 void CCPrioritizedTextureManager::clearAllMemory(CCResourceProvider* resourceProvider)
 {
     ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
     ASSERT(resourceProvider);
-    // Unlink and destroy all backing textures.
-    while (m_backings.size() > 0) {
-        BackingSet::iterator it = m_backings.begin();
-        if ((*it)->owner())
-            (*it)->owner()->unlink();
-        destroyBacking((*it), resourceProvider);
-    }
+    evictBackingsToReduceMemory(0, DoNotRespectManagerPriorityCutoff, resourceProvider);
+    deleteEvictedBackings();
 }
 
-void CCPrioritizedTextureManager::unlinkAllBackings()
+void CCPrioritizedTextureManager::reduceMemoryOnImplThread(size_t limitBytes, CCResourceProvider* resourceProvider)
 {
-    ASSERT(CCProxy::isMainThread());
-    for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); ++it)
-        if ((*it)->owner())
-            (*it)->owner()->unlink();
+    ASSERT(CCProxy::isImplThread());
+    ASSERT(resourceProvider);
+
+    evictBackingsToReduceMemory(limitBytes, DoNotRespectManagerPriorityCutoff, resourceProvider);
+
+    // Deleting just some (not all) resources is not supported yet because we do not clear
+    // only the deleted resources from the texture upload queues (rather, we clear all uploads).
+    // Make sure that if we evict all resources.
+    ASSERT(m_backings.isEmpty());
 }
 
-void CCPrioritizedTextureManager::deleteAllUnlinkedBackings()
+void CCPrioritizedTextureManager::getEvictedBackings(BackingVector& evictedBackings)
 {
-    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
-    BackingVector backingsToDelete;
-    for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); ++it)
-        if (!(*it)->owner())
-            backingsToDelete.append((*it));
+    ASSERT(CCProxy::isImplThread());
+    evictedBackings.clear();
+    evictedBackings.append(m_evictedBackings);
+}
 
-    for (BackingVector::iterator it = backingsToDelete.begin(); it != backingsToDelete.end(); ++it)
-        destroyBacking((*it), 0);
+void CCPrioritizedTextureManager::unlinkEvictedBackings(const BackingVector& evictedBackings)
+{
+    ASSERT(CCProxy::isMainThread());
+    for (BackingVector::const_iterator it = evictedBackings.begin(); it != evictedBackings.end(); ++it) {
+        CCPrioritizedTexture::Backing* backing = (*it);
+        if (backing->owner())
+            backing->owner()->unlink();
+    }
 }
 
+bool CCPrioritizedTextureManager::deleteEvictedBackings()
+{
+    ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()));
+    bool linkedEvictedBackingsExisted = false;
+    for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_evictedBackings.end(); ++it) {
+        CCPrioritizedTexture::Backing* backing = (*it);
+        if (backing->owner()) {
+            linkedEvictedBackingsExisted = true;
+            backing->owner()->unlink();
+        }
+        delete backing;
+    }
+    m_evictedBackings.clear();
+    return linkedEvictedBackingsExisted;
+}
+
 void CCPrioritizedTextureManager::registerTexture(CCPrioritizedTexture* texture)
 {
     ASSERT(CCProxy::isMainThread());
@@ -347,22 +371,18 @@
     return backing;
 }
 
-void CCPrioritizedTextureManager::destroyBacking(CCPrioritizedTexture::Backing* backing, CCResourceProvider* resourceProvider)
+void CCPrioritizedTextureManager::evictBackingResource(CCPrioritizedTexture::Backing* backing, CCResourceProvider* resourceProvider)
 {
-    ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
+    ASSERT(CCProxy::isImplThread());
     ASSERT(backing);
-    ASSERT(!backing->owner() || !backing->owner()->isAbovePriorityCutoff());
-    ASSERT(!backing->owner() || !backing->owner()->isSelfManaged());
+    ASSERT(resourceProvider);
     ASSERT(m_backings.find(backing) != m_backings.end());
 
-    if (resourceProvider)
-        resourceProvider->deleteResource(backing->id());
-    if (backing->owner())
-        backing->owner()->unlink();
+    resourceProvider->deleteResource(backing->id());
+    backing->setId(0);
     m_memoryUseBytes -= backing->bytes();
     m_backings.remove(backing);
-
-    delete backing;
+    m_evictedBackings.append(backing);
 }
 
 #if !ASSERT_DISABLED

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.h (128343 => 128344)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.h	2012-09-12 18:24:39 UTC (rev 128343)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCPrioritizedTextureManager.h	2012-09-12 18:49:25 UTC (rev 128344)
@@ -53,6 +53,8 @@
     }
     ~CCPrioritizedTextureManager();
 
+    typedef Vector<CCPrioritizedTexture::Backing*> BackingVector;
+
     // FIXME (http://crbug.com/137094): This 64MB default is a straggler from the
     // old texture manager and is just to give us a default memory allocation before
     // we get a callback from the GPU memory manager. We should probaby either:
@@ -74,12 +76,18 @@
     void prioritizeTextures();
     void clearPriorities();
 
+    void reduceMemoryOnImplThread(size_t limitBytes, CCResourceProvider*);
+    void getEvictedBackings(BackingVector& evictedBackings);
+    void unlinkEvictedBackings(const BackingVector& evictedBackings);
+    // Deletes all evicted backings, unlinking them from their owning textures if needed.
+    // Returns true if this function to unlinked any backings from their owning texture while
+    // destroying them.
+    bool deleteEvictedBackings();
+
     bool requestLate(CCPrioritizedTexture*);
 
     void reduceMemory(CCResourceProvider*);
     void clearAllMemory(CCResourceProvider*);
-    void unlinkAllBackings();
-    void deleteAllUnlinkedBackings();
 
     void acquireBackingTextureIfNeeded(CCPrioritizedTexture*, CCResourceProvider*);
 
@@ -90,6 +98,11 @@
 private:
     friend class CCPrioritizedTextureTest;
 
+    enum EvictionPriorityPolicy {
+        RespectManagerPriorityCutoff,
+        DoNotRespectManagerPriorityCutoff,
+    };
+
     // Compare textures. Highest priority first.
     static inline bool compareTextures(CCPrioritizedTexture* a, CCPrioritizedTexture* b)
     {
@@ -116,9 +129,9 @@
     CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, int pool);
 
     void updateBackingsPriorities();
-    void reduceMemory(size_t limit, CCResourceProvider*);
+    void evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy, CCResourceProvider*);
     CCPrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, CCResourceProvider*);
-    void destroyBacking(CCPrioritizedTexture::Backing*, CCResourceProvider*);
+    void evictBackingResource(CCPrioritizedTexture::Backing*, CCResourceProvider*);
 
 #if !ASSERT_DISABLED
     void assertInvariants();
@@ -134,10 +147,10 @@
     typedef HashSet<CCPrioritizedTexture*> TextureSet;
     typedef ListHashSet<CCPrioritizedTexture::Backing*> BackingSet;
     typedef Vector<CCPrioritizedTexture*> TextureVector;
-    typedef Vector<CCPrioritizedTexture::Backing*> BackingVector;
 
     TextureSet m_textures;
     BackingSet m_backings;
+    BackingVector m_evictedBackings;
 
     TextureVector m_tempTextureVector;
     BackingVector m_tempBackingVector;

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp (128343 => 128344)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp	2012-09-12 18:24:39 UTC (rev 128343)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp	2012-09-12 18:49:25 UTC (rev 128344)
@@ -275,6 +275,12 @@
     m_layerTreeHost->setAnimationEvents(events, wallClockTime);
 }
 
+void CCSingleThreadProxy::releaseContentsTexturesOnImplThread()
+{
+    ASSERT(isImplThread());
+    m_layerTreeHost->reduceContentsTexturesMemoryOnImplThread(0, m_layerTreeHostImpl->resourceProvider());
+}
+
 // Called by the legacy scheduling path (e.g. where render_widget does the scheduling)
 void CCSingleThreadProxy::compositeImmediately()
 {
@@ -300,16 +306,24 @@
     if (!m_layerTreeHost->initializeRendererIfNeeded())
         return false;
 
-    if (m_layerTreeHostImpl->contentsTexturesPurged()) {
-        m_layerTreeHost->unlinkAllContentTextures();
+    // Unlink any texture backings that were deleted
+    CCPrioritizedTextureManager::BackingVector evictedContentsTexturesBackings;
+    {
+        DebugScopedSetImplThread implThread;
+        m_layerTreeHost->getEvictedContentTexturesBackings(evictedContentsTexturesBackings);
+    }
+    m_layerTreeHost->unlinkEvictedContentTexturesBackings(evictedContentsTexturesBackings);
+    {
         DebugScopedSetImplThreadAndMainThreadBlocked implAndMainBlocked;
-        m_layerTreeHost->deleteUnlinkedTextures();
+        m_layerTreeHost->deleteEvictedContentTexturesBackings();
     }
 
     CCTextureUpdateQueue queue;
     m_layerTreeHost->updateLayers(queue, m_layerTreeHostImpl->memoryAllocationLimitBytes());
-    m_layerTreeHostImpl->resetContentsTexturesPurged();
 
+    if (m_layerTreeHostImpl->contentsTexturesPurged())
+        m_layerTreeHostImpl->resetContentsTexturesPurged();
+
     m_layerTreeHost->willCommit();
     doCommit(queue);
     bool result = doComposite();

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.h (128343 => 128344)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.h	2012-09-12 18:24:39 UTC (rev 128343)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.h	2012-09-12 18:49:25 UTC (rev 128344)
@@ -72,6 +72,7 @@
     virtual void setNeedsRedrawOnImplThread() OVERRIDE { m_layerTreeHost->scheduleComposite(); }
     virtual void setNeedsCommitOnImplThread() OVERRIDE { m_layerTreeHost->scheduleComposite(); }
     virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) OVERRIDE;
+    virtual void releaseContentsTexturesOnImplThread() OVERRIDE;
 
     // Called by the legacy path where RenderWidget does the scheduling.
     void compositeImmediately();

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp (128343 => 128344)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp	2012-09-12 18:24:39 UTC (rev 128343)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp	2012-09-12 18:49:25 UTC (rev 128344)
@@ -374,6 +374,16 @@
     m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadProxy::setAnimationEvents, events, wallClockTime));
 }
 
+void CCThreadProxy::releaseContentsTexturesOnImplThread()
+{
+    ASSERT(isImplThread());
+    m_layerTreeHost->reduceContentsTexturesMemoryOnImplThread(0, m_layerTreeHostImpl->resourceProvider());
+    // Make sure that we get a new commit before drawing again.
+    m_resetContentsTexturesPurgedAfterCommitOnImplThread = false;
+    // The texture upload queue may reference textures that were just purged, so clear it.
+    m_currentTextureUpdateControllerOnImplThread.clear();
+}
+
 void CCThreadProxy::setNeedsRedraw()
 {
     ASSERT(isMainThread());
@@ -476,8 +486,8 @@
     m_pendingBeginFrameRequest = adoptPtr(new BeginFrameAndCommitState());
     m_pendingBeginFrameRequest->monotonicFrameBeginTime = monotonicallyIncreasingTime();
     m_pendingBeginFrameRequest->scrollInfo = m_layerTreeHostImpl->processScrollDeltas();
-    m_pendingBeginFrameRequest->contentsTexturesWereDeleted = m_layerTreeHostImpl->contentsTexturesPurged();
     m_pendingBeginFrameRequest->memoryAllocationLimitBytes = m_layerTreeHostImpl->memoryAllocationLimitBytes();
+    m_layerTreeHost->getEvictedContentTexturesBackings(m_pendingBeginFrameRequest->evictedContentsTexturesBackings);
 
     m_mainThreadProxy->postTask(createCCThreadTask(this, &CCThreadProxy::beginFrame));
 
@@ -548,8 +558,7 @@
         return;
     }
 
-    if (request->contentsTexturesWereDeleted)
-        m_layerTreeHost->unlinkAllContentTextures();
+    m_layerTreeHost->unlinkEvictedContentTexturesBackings(request->evictedContentsTexturesBackings);
 
     OwnPtr<CCTextureUpdateQueue> queue = adoptPtr(new CCTextureUpdateQueue);
     m_layerTreeHost->updateLayers(*(queue.get()), request->memoryAllocationLimitBytes);
@@ -579,7 +588,7 @@
         DebugScopedSetMainThreadBlocked mainThreadBlocked;
 
         CCCompletionEvent completion;
-        CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::beginFrameCompleteOnImplThread, &completion, queue.release(), request->contentsTexturesWereDeleted));
+        CCProxy::implThread()->postTask(createCCThreadTask(this, &CCThreadProxy::beginFrameCompleteOnImplThread, &completion, queue.release()));
         completion.wait();
     }
 
@@ -587,7 +596,7 @@
     m_layerTreeHost->didBeginFrame();
 }
 
-void CCThreadProxy::beginFrameCompleteOnImplThread(CCCompletionEvent* completion, PassOwnPtr<CCTextureUpdateQueue> queue, bool contentsTexturesWereDeleted)
+void CCThreadProxy::beginFrameCompleteOnImplThread(CCCompletionEvent* completion, PassOwnPtr<CCTextureUpdateQueue> queue)
 {
     TRACE_EVENT0("cc", "CCThreadProxy::beginFrameCompleteOnImplThread");
     ASSERT(!m_commitCompletionEventOnImplThread);
@@ -601,19 +610,20 @@
         return;
     }
 
-    if (contentsTexturesWereDeleted) {
-        ASSERT(m_layerTreeHostImpl->contentsTexturesPurged());
-        // We unlinked all textures on the main thread, delete them now.
-        m_layerTreeHost->deleteUnlinkedTextures();
-        // Mark that we can start drawing again when this commit is complete.
-        m_resetContentsTexturesPurgedAfterCommitOnImplThread = true;
-    } else if (m_layerTreeHostImpl->contentsTexturesPurged()) {
-        // We purged the content textures on the impl thread between the time we
-        // posted the beginFrame task and now, meaning we have a bunch of
-        // uploads that are now invalid. Clear the uploads (they all go to
-        // content textures), and kick another commit to fill them again.
+    // If we unlinked evicted textures on the main thread, delete them now.
+    if (m_layerTreeHost->deleteEvictedContentTexturesBackings()) {
+
+        // Deleting the evicted textures' backings resulted in some textures in the
+        // layer tree being invalidated (unliked from their backings). The upload queue
+        // may contain references to these textures, so clear the queue and kick off
+        // another commit to fill them again.
         queue->clearUploads();
         setNeedsCommitOnImplThread();
+    } else {
+        // The layer tree does not reference evicted textures, so mark that we
+        // can draw this tree once this commit is complete.
+        if (m_layerTreeHostImpl->contentsTexturesPurged())
+            m_resetContentsTexturesPurgedAfterCommitOnImplThread = true;
     }
 
     m_currentTextureUpdateControllerOnImplThread = CCTextureUpdateController::create(CCProxy::implThread(), queue, m_layerTreeHostImpl->resourceProvider(), m_layerTreeHostImpl->renderer()->textureCopier(), m_layerTreeHostImpl->renderer()->textureUploader());
@@ -902,8 +912,7 @@
 {
     TRACE_EVENT0("cc", "CCThreadProxy::layerTreeHostClosedOnImplThread");
     ASSERT(isImplThread());
-    if (!m_layerTreeHostImpl->contentsTexturesPurged())
-        m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
+    m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
     m_inputHandlerOnImplThread.clear();
     m_layerTreeHostImpl.clear();
     m_schedulerOnImplThread.clear();
@@ -925,8 +934,7 @@
 {
     TRACE_EVENT0("cc", "CCThreadProxy::recreateContextOnImplThread");
     ASSERT(isImplThread());
-    if (!m_layerTreeHostImpl->contentsTexturesPurged())
-        m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
+    m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider());
     *recreateSucceeded = m_layerTreeHostImpl->initializeRenderer(adoptPtr(contextPtr), textureUploader);
     if (*recreateSucceeded) {
         *capabilities = m_layerTreeHostImpl->rendererCapabilities();

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.h (128343 => 128344)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.h	2012-09-12 18:24:39 UTC (rev 128343)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.h	2012-09-12 18:49:25 UTC (rev 128344)
@@ -81,6 +81,7 @@
     virtual void setNeedsRedrawOnImplThread() OVERRIDE;
     virtual void setNeedsCommitOnImplThread() OVERRIDE;
     virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) OVERRIDE;
+    virtual void releaseContentsTexturesOnImplThread() OVERRIDE;
 
     // CCSchedulerClient implementation
     virtual bool hasMoreResourceUpdates() const OVERRIDE;
@@ -106,7 +107,7 @@
 
         double monotonicFrameBeginTime;
         OwnPtr<CCScrollAndScaleSet> scrollInfo;
-        bool contentsTexturesWereDeleted;
+        CCPrioritizedTextureManager::BackingVector evictedContentsTexturesBackings;
         size_t memoryAllocationLimitBytes;
     };
     OwnPtr<BeginFrameAndCommitState> m_pendingBeginFrameRequest;
@@ -127,7 +128,7 @@
         IntRect rect;
     };
     void forceBeginFrameOnImplThread(CCCompletionEvent*);
-    void beginFrameCompleteOnImplThread(CCCompletionEvent*, PassOwnPtr<CCTextureUpdateQueue>, bool contentsTexturesWereDeleted);
+    void beginFrameCompleteOnImplThread(CCCompletionEvent*, PassOwnPtr<CCTextureUpdateQueue>);
     void beginFrameAbortedOnImplThread();
     void requestReadbackOnImplThread(ReadbackRequest*);
     void requestStartPageScaleAnimationOnImplThread(IntSize targetPosition, bool useAnchor, float scale, double durationSec);

Modified: trunk/Source/WebKit/chromium/ChangeLog (128343 => 128344)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-09-12 18:24:39 UTC (rev 128343)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-09-12 18:49:25 UTC (rev 128344)
@@ -1,3 +1,15 @@
+2012-09-12  Christopher Cameron  <ccame...@chromium.org>
+
+        [chromium] Evict textures through the texture manager instead of the resource provider
+        https://bugs.webkit.org/show_bug.cgi?id=96463
+
+        Reviewed by James Robinson.
+
+        Update layer tree host impl test to include the extra interface functions
+        added to CCLayerTreeHostImplClient.
+
+        * tests/CCLayerTreeHostImplTest.cpp:
+
 2012-09-12  Ilya Tikhonovsky  <loi...@chromium.org>
 
         Web Inspector: NMI move String* instrumentation to wtf.

Modified: trunk/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp (128343 => 128344)


--- trunk/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp	2012-09-12 18:24:39 UTC (rev 128343)
+++ trunk/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp	2012-09-12 18:49:25 UTC (rev 128344)
@@ -89,6 +89,7 @@
     virtual void setNeedsRedrawOnImplThread() OVERRIDE { m_didRequestRedraw = true; }
     virtual void setNeedsCommitOnImplThread() OVERRIDE { m_didRequestCommit = true; }
     virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) OVERRIDE { }
+    virtual void releaseContentsTexturesOnImplThread() OVERRIDE { }
 
     PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHost(bool partialSwap, PassOwnPtr<CCGraphicsContext> graphicsContext, PassOwnPtr<CCLayerImpl> rootPtr)
     {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to