Title: [101854] trunk/Source/WebCore
Revision
101854
Author
[email protected]
Date
2011-12-02 14:30:08 -0800 (Fri, 02 Dec 2011)

Log Message

[chromium] Recycle tile-sized textures during commit to prevent reallocations
https://bugs.webkit.org/show_bug.cgi?id=70645

Patch by Grace Kloba <[email protected]> on 2011-12-02
Reviewed by James Robinson.

Currently texture request is capped by the high limit while we reclaim the
textures in each commit. This triggers new tiles always allocated when scrolling.
The proposal is to recycle the texture during request if the total used memory
is about to exceed the reclaim limit.

* platform/graphics/chromium/ManagedTexture.cpp:
(WebCore::ManagedTexture::reserve):
* platform/graphics/chromium/TextureManager.cpp:
(WebCore::TextureManager::setMemoryLimitBytes):
(WebCore::TextureManager::replaceTexture):
(WebCore::TextureManager::requestTexture):
* platform/graphics/chromium/TextureManager.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (101853 => 101854)


--- trunk/Source/WebCore/ChangeLog	2011-12-02 22:26:56 UTC (rev 101853)
+++ trunk/Source/WebCore/ChangeLog	2011-12-02 22:30:08 UTC (rev 101854)
@@ -1,3 +1,23 @@
+2011-12-02  Grace Kloba  <[email protected]>
+
+        [chromium] Recycle tile-sized textures during commit to prevent reallocations
+        https://bugs.webkit.org/show_bug.cgi?id=70645
+
+        Reviewed by James Robinson.
+
+        Currently texture request is capped by the high limit while we reclaim the
+        textures in each commit. This triggers new tiles always allocated when scrolling.
+        The proposal is to recycle the texture during request if the total used memory
+        is about to exceed the reclaim limit.
+
+        * platform/graphics/chromium/ManagedTexture.cpp:
+        (WebCore::ManagedTexture::reserve):
+        * platform/graphics/chromium/TextureManager.cpp:
+        (WebCore::TextureManager::setMemoryLimitBytes):
+        (WebCore::TextureManager::replaceTexture):
+        (WebCore::TextureManager::requestTexture):
+        * platform/graphics/chromium/TextureManager.h:
+
 2011-12-02  Kent Tamura  <[email protected]>
 
         [Chromium] Show placeholder even if the element is focused

Modified: trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp (101853 => 101854)


--- trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp	2011-12-02 22:26:56 UTC (rev 101853)
+++ trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp	2011-12-02 22:30:08 UTC (rev 101854)
@@ -62,7 +62,7 @@
         m_textureManager->protectTexture(m_token);
     else {
         m_textureId = 0;
-        reserved = m_textureManager->requestTexture(m_token, size, format);
+        reserved = m_textureManager->requestTexture(m_token, size, format, m_textureId);
         if (reserved) {
             m_size = size;
             m_format = format;

Modified: trunk/Source/WebCore/platform/graphics/chromium/TextureManager.cpp (101853 => 101854)


--- trunk/Source/WebCore/platform/graphics/chromium/TextureManager.cpp	2011-12-02 22:26:56 UTC (rev 101853)
+++ trunk/Source/WebCore/platform/graphics/chromium/TextureManager.cpp	2011-12-02 22:30:08 UTC (rev 101854)
@@ -71,7 +71,7 @@
 void TextureManager::setMemoryLimitBytes(size_t memoryLimitBytes)
 {
     reduceMemoryToLimit(memoryLimitBytes);
-    ASSERT(currentMemoryUseBytes() < memoryLimitBytes);
+    ASSERT(currentMemoryUseBytes() <= memoryLimitBytes);
     m_memoryLimitBytes = memoryLimitBytes;
 }
 
@@ -141,6 +141,30 @@
     }
 }
 
+unsigned TextureManager::replaceTexture(TextureToken newToken, TextureInfo newInfo)
+{
+    for (ListHashSet<TextureToken>::iterator lruIt = m_textureLRUSet.begin(); lruIt != m_textureLRUSet.end(); ++lruIt) {
+        TextureToken token = *lruIt;
+        TextureInfo info = m_textures.get(token);
+        if (info.isProtected)
+            continue;
+        if (!info.textureId)
+            continue;
+        if (newInfo.size != info.size || newInfo.format != info.format)
+            continue;
+        newInfo.textureId = info.textureId;
+#ifndef NDEBUG
+        newInfo.allocator = info.allocator;
+#endif
+        m_textures.remove(token);
+        m_textureLRUSet.remove(token);
+        m_textures.set(newToken, newInfo);
+        m_textureLRUSet.add(newToken);
+        return info.textureId;
+    }
+    return 0;
+}
+
 void TextureManager::addTexture(TextureToken token, TextureInfo info)
 {
     ASSERT(!m_textureLRUSet.contains(token));
@@ -205,8 +229,10 @@
     return textureId;
 }
 
-bool TextureManager::requestTexture(TextureToken token, IntSize size, unsigned format)
+bool TextureManager::requestTexture(TextureToken token, IntSize size, unsigned format, unsigned& textureId)
 {
+    textureId = 0;
+
     if (size.width() > m_maxTextureSize || size.height() > m_maxTextureSize)
         return false;
 
@@ -232,6 +258,13 @@
 #ifndef NDEBUG
     info.allocator = 0;
 #endif
+    // Avoid churning by reusing the texture if it is about to be reclaimed and
+    // it has the same size and format as the requesting texture.
+    if (m_memoryUseBytes + memoryRequiredBytes > reclaimLimitBytes()) {
+        textureId = replaceTexture(token, info);
+        if (textureId)
+            return true;
+    }
     addTexture(token, info);
     return true;
 }

Modified: trunk/Source/WebCore/platform/graphics/chromium/TextureManager.h (101853 => 101854)


--- trunk/Source/WebCore/platform/graphics/chromium/TextureManager.h	2011-12-02 22:26:56 UTC (rev 101853)
+++ trunk/Source/WebCore/platform/graphics/chromium/TextureManager.h	2011-12-02 22:30:08 UTC (rev 101854)
@@ -69,7 +69,7 @@
     void releaseToken(TextureToken);
     bool hasTexture(TextureToken);
 
-    bool requestTexture(TextureToken, IntSize, GC3Denum textureFormat);
+    bool requestTexture(TextureToken, IntSize, GC3Denum textureFormat, unsigned& textureId);
 
     void protectTexture(TextureToken);
     void unprotectTexture(TextureToken);
@@ -99,6 +99,7 @@
 
     void addTexture(TextureToken, TextureInfo);
     void removeTexture(TextureToken, TextureInfo);
+    unsigned replaceTexture(TextureToken, TextureInfo);
 
     typedef HashMap<TextureToken, TextureInfo> TextureMap;
     TextureMap m_textures;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to