[chromium] Set texture limits as multiples of viewport size instead of hardcoded...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2011 11:05:02 +0000 (11:05 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2011 11:05:02 +0000 (11:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=72202

Patch by Eric Penner <epenner@google.com> on 2011-12-06
Reviewed by James Robinson.

Source/WebCore:

* platform/graphics/chromium/LayerRendererChromium.cpp:
(WebCore::LayerRendererChromium::drawLayers): added viewport param
(WebCore::LayerRendererChromium::initializeSharedObjects): ditto
* platform/graphics/chromium/TextureManager.cpp:
(WebCore::TextureManager::highLimitBytes): calculated based on viewport
(WebCore::TextureManager::reclaimLimitBytes): ditto
(WebCore::TextureManager::lowLimitBytes): ditto
(WebCore::TextureManager::TextureManager): added viewport param
(WebCore::TextureManager::setMaxMemoryLimitBytes): changed name
(WebCore::TextureManager::setPreferredMemoryLimitBytes): added function
(WebCore::TextureManager::requestTexture): added viewport param
* platform/graphics/chromium/TextureManager.h: ditto
(WebCore::TextureManager::create): ditto
* platform/graphics/chromium/cc/CCLayerTreeHost.cpp: ditto
(WebCore::CCLayerTreeHost::initialize): ditto
(WebCore::CCLayerTreeHost::beginCommitOnImplThread): ditto
(WebCore::CCLayerTreeHost::setViewport): ditto
(WebCore::CCLayerTreeHost::setVisible): ditto
(WebCore::CCLayerTreeHost::didBecomeInvisibleOnImplThread): ditto

Source/WebKit/chromium:

* tests/TiledLayerChromiumTest.cpp:
(WTF::TEST):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
Source/WebCore/platform/graphics/chromium/TextureManager.cpp
Source/WebCore/platform/graphics/chromium/TextureManager.h
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp

index f27dd55..b4807ab 100644 (file)
@@ -1,3 +1,30 @@
+2011-12-06  Eric Penner  <epenner@google.com>
+
+        [chromium] Set texture limits as multiples of viewport size instead of hardcoded values
+        https://bugs.webkit.org/show_bug.cgi?id=72202
+
+        Reviewed by James Robinson.
+
+        * platform/graphics/chromium/LayerRendererChromium.cpp: 
+        (WebCore::LayerRendererChromium::drawLayers): added viewport param
+        (WebCore::LayerRendererChromium::initializeSharedObjects): ditto 
+        * platform/graphics/chromium/TextureManager.cpp: 
+        (WebCore::TextureManager::highLimitBytes): calculated based on viewport
+        (WebCore::TextureManager::reclaimLimitBytes): ditto
+        (WebCore::TextureManager::lowLimitBytes): ditto
+        (WebCore::TextureManager::TextureManager): added viewport param
+        (WebCore::TextureManager::setMaxMemoryLimitBytes): changed name
+        (WebCore::TextureManager::setPreferredMemoryLimitBytes): added function
+        (WebCore::TextureManager::requestTexture): added viewport param
+        * platform/graphics/chromium/TextureManager.h: ditto
+        (WebCore::TextureManager::create): ditto
+        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp: ditto
+        (WebCore::CCLayerTreeHost::initialize): ditto
+        (WebCore::CCLayerTreeHost::beginCommitOnImplThread): ditto
+        (WebCore::CCLayerTreeHost::setViewport): ditto
+        (WebCore::CCLayerTreeHost::setVisible): ditto
+        (WebCore::CCLayerTreeHost::didBecomeInvisibleOnImplThread): ditto
+
 2011-12-06  Huang Dongsung  <luxtella@company100.net>
 
         [TexMap][QT] Draw the borders of media and webgl elements in TexMap.
index a335e50..f73d77c 100644 (file)
@@ -331,13 +331,18 @@ void LayerRendererChromium::drawLayers()
         return;
 
     size_t contentsMemoryUseBytes = m_contentsTextureAllocator->currentMemoryUseBytes();
-    m_renderSurfaceTextureManager->setMemoryLimitBytes(TextureManager::highLimitBytes() - contentsMemoryUseBytes);
+    size_t maxLimit = TextureManager::highLimitBytes(viewportSize());
+    size_t reclaimLimit = TextureManager::reclaimLimitBytes(viewportSize());
+
+    m_renderSurfaceTextureManager->setMaxMemoryLimitBytes(maxLimit - contentsMemoryUseBytes);
+
     drawLayersInternal();
 
-    if (TextureManager::reclaimLimitBytes() > contentsMemoryUseBytes)
-        m_renderSurfaceTextureManager->reduceMemoryToLimit(TextureManager::reclaimLimitBytes() - contentsMemoryUseBytes);
+    if (reclaimLimit > contentsMemoryUseBytes)
+        m_renderSurfaceTextureManager->setPreferredMemoryLimitBytes(reclaimLimit - contentsMemoryUseBytes);
     else
-        m_renderSurfaceTextureManager->reduceMemoryToLimit(0);
+        m_renderSurfaceTextureManager->setPreferredMemoryLimitBytes(0);
+
     m_renderSurfaceTextureManager->deleteEvictedTextures(m_renderSurfaceTextureAllocator.get());
 
     if (settings().compositeOffscreen)
@@ -745,7 +750,9 @@ bool LayerRendererChromium::initializeSharedObjects()
 
     GLC(m_context.get(), m_context->flush());
 
-    m_renderSurfaceTextureManager = TextureManager::create(TextureManager::highLimitBytes(), m_capabilities.maxTextureSize);
+    m_renderSurfaceTextureManager = TextureManager::create(TextureManager::highLimitBytes(viewportSize()),
+                                                           TextureManager::reclaimLimitBytes(viewportSize()),
+                                                           m_capabilities.maxTextureSize);
     m_contentsTextureAllocator = TrackingTextureAllocator::create(m_context.get());
     m_renderSurfaceTextureAllocator = TrackingTextureAllocator::create(m_context.get());
     if (m_capabilities.usingTextureUsageHint)
index 3795be4..d66b06a 100644 (file)
 
 #include "LayerRendererChromium.h"
 
+using namespace std;
+
 namespace WebCore {
 
-size_t TextureManager::highLimitBytes()
+
+namespace {
+size_t memoryLimitBytes(size_t viewportMultiplier, const IntSize& viewportSize, size_t minMegabytes, size_t maxMegabytes)
+{
+    if (viewportSize.isEmpty())
+        return minMegabytes * 1024 * 1024;
+    return max(minMegabytes * 1024 * 1024, min(maxMegabytes * 1024 * 1024, viewportMultiplier * TextureManager::memoryUseBytes(viewportSize, GraphicsContext3D::RGBA)));
+}
+}
+
+size_t TextureManager::highLimitBytes(const IntSize& viewportSize)
 {
-    return 128 * 1024 * 1024;
+    size_t viewportMultiplier, minMegabytes, maxMegabytes;
+    viewportMultiplier = 8;
+#if OS(ANDROID)
+    minMegabytes = 24;
+    maxMegabytes = 32;
+#else
+    minMegabytes = 64;
+    maxMegabytes = 128;
+#endif
+    return memoryLimitBytes(viewportMultiplier, viewportSize, minMegabytes, maxMegabytes);
 }
 
-size_t TextureManager::reclaimLimitBytes()
+size_t TextureManager::reclaimLimitBytes(const IntSize& viewportSize)
 {
-    return 64 * 1024 * 1024;
+    size_t viewportMultiplier, minMegabytes, maxMegabytes;
+    viewportMultiplier = 4;
+#if OS(ANDROID)
+    minMegabytes = 9;
+    maxMegabytes = 32;
+#else
+    minMegabytes = 32;
+    maxMegabytes = 64;
+#endif
+    return memoryLimitBytes(viewportMultiplier, viewportSize, minMegabytes, maxMegabytes);
 }
 
-size_t TextureManager::lowLimitBytes()
+size_t TextureManager::lowLimitBytes(const IntSize& viewportSize)
 {
-    return 3 * 1024 * 1024;
+    size_t viewportMultiplier, minMegabytes, maxMegabytes;
+    viewportMultiplier = 1;
+    minMegabytes = 2;
+    maxMegabytes = 3;
+    return memoryLimitBytes(viewportMultiplier, viewportSize, minMegabytes, maxMegabytes);
 }
 
 size_t TextureManager::memoryUseBytes(const IntSize& size, GC3Denum textureFormat)
@@ -60,19 +94,26 @@ size_t TextureManager::memoryUseBytes(const IntSize& size, GC3Denum textureForma
 }
 
 
-TextureManager::TextureManager(size_t memoryLimitBytes, int maxTextureSize)
-    : m_memoryLimitBytes(memoryLimitBytes)
+TextureManager::TextureManager(size_t maxMemoryLimitBytes, size_t preferredMemoryLimitBytes, int maxTextureSize)
+    : m_maxMemoryLimitBytes(maxMemoryLimitBytes)
+    , m_preferredMemoryLimitBytes(preferredMemoryLimitBytes)
     , m_memoryUseBytes(0)
     , m_maxTextureSize(maxTextureSize)
     , m_nextToken(1)
 {
 }
 
-void TextureManager::setMemoryLimitBytes(size_t memoryLimitBytes)
+void TextureManager::setMaxMemoryLimitBytes(size_t memoryLimitBytes)
 {
     reduceMemoryToLimit(memoryLimitBytes);
     ASSERT(currentMemoryUseBytes() <= memoryLimitBytes);
-    m_memoryLimitBytes = memoryLimitBytes;
+    m_maxMemoryLimitBytes = memoryLimitBytes;
+}
+
+void TextureManager::setPreferredMemoryLimitBytes(size_t memoryLimitBytes)
+{
+    reduceMemoryToLimit(memoryLimitBytes);
+    m_preferredMemoryLimitBytes = memoryLimitBytes;
 }
 
 TextureToken TextureManager::getToken()
@@ -243,11 +284,11 @@ bool TextureManager::requestTexture(TextureToken token, IntSize size, unsigned f
     }
 
     size_t memoryRequiredBytes = memoryUseBytes(size, format);
-    if (memoryRequiredBytes > m_memoryLimitBytes)
+    if (memoryRequiredBytes > m_maxMemoryLimitBytes)
         return false;
 
-    reduceMemoryToLimit(m_memoryLimitBytes - memoryRequiredBytes);
-    if (m_memoryUseBytes + memoryRequiredBytes > m_memoryLimitBytes)
+    reduceMemoryToLimit(m_maxMemoryLimitBytes - memoryRequiredBytes);
+    if (m_memoryUseBytes + memoryRequiredBytes > m_maxMemoryLimitBytes)
         return false;
 
     TextureInfo info;
@@ -260,7 +301,7 @@ bool TextureManager::requestTexture(TextureToken token, IntSize size, unsigned f
 #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()) {
+    if (m_memoryUseBytes + memoryRequiredBytes > m_preferredMemoryLimitBytes) {
         textureId = replaceTexture(token, info);
         if (textureId)
             return true;
index b191f7b..c6c21ad 100644 (file)
@@ -49,21 +49,22 @@ protected:
 class TextureManager {
     WTF_MAKE_NONCOPYABLE(TextureManager);
 public:
-    static PassOwnPtr<TextureManager> create(size_t memoryLimitBytes, int maxTextureSize)
+    static PassOwnPtr<TextureManager> create(size_t maxMemoryLimitBytes, size_t preferredMemoryLimitBytes, int maxTextureSize)
     {
-        return adoptPtr(new TextureManager(memoryLimitBytes, maxTextureSize));
+        return adoptPtr(new TextureManager(maxMemoryLimitBytes, preferredMemoryLimitBytes, 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();
+    static size_t highLimitBytes(const IntSize& viewportSize);
+    // Preferred texture size limit given the viewport size.
+    static size_t reclaimLimitBytes(const IntSize& viewportSize);
     // The maximum texture memory usage when asked to release textures.
-    static size_t lowLimitBytes();
+    static size_t lowLimitBytes(const IntSize& viewport);
 
     static size_t memoryUseBytes(const IntSize&, GC3Denum format);
 
-    void setMemoryLimitBytes(size_t);
+    void setMaxMemoryLimitBytes(size_t);
+    void setPreferredMemoryLimitBytes(size_t);
 
     TextureToken getToken();
     void releaseToken(TextureToken);
@@ -85,7 +86,7 @@ public:
     size_t currentMemoryUseBytes() const { return m_memoryUseBytes; }
 
 private:
-    TextureManager(size_t memoryLimitBytes, int maxTextureSize);
+    TextureManager(size_t maxMemoryLimitBytes, size_t preferredMemoryLimitBytes, int maxTextureSize);
 
     struct TextureInfo {
         IntSize size;
@@ -105,7 +106,8 @@ private:
     TextureMap m_textures;
     ListHashSet<TextureToken> m_textureLRUSet;
 
-    size_t m_memoryLimitBytes;
+    size_t m_maxMemoryLimitBytes;
+    size_t m_preferredMemoryLimitBytes;
     size_t m_memoryUseBytes;
     int m_maxTextureSize;
     TextureToken m_nextToken;
index db1809e..27c1704 100644 (file)
@@ -93,7 +93,9 @@ bool CCLayerTreeHost::initialize()
     // Update m_settings based on capabilities that we got back from the renderer.
     m_settings.acceleratePainting = m_proxy->layerRendererCapabilities().usingAcceleratedPainting;
 
-    m_contentsTextureManager = TextureManager::create(TextureManager::highLimitBytes(), m_proxy->layerRendererCapabilities().maxTextureSize);
+    m_contentsTextureManager = TextureManager::create(TextureManager::highLimitBytes(viewportSize()),
+                                                      TextureManager::reclaimLimitBytes(viewportSize()),
+                                                      m_proxy->layerRendererCapabilities().maxTextureSize);
     return true;
 }
 
@@ -126,7 +128,7 @@ void CCLayerTreeHost::beginCommitOnImplThread(CCLayerTreeHostImpl* hostImpl)
     ASSERT(CCProxy::isImplThread());
     TRACE_EVENT("CCLayerTreeHost::commitTo", this, 0);
 
-    contentsTextureManager()->reduceMemoryToLimit(TextureManager::reclaimLimitBytes());
+    contentsTextureManager()->reduceMemoryToLimit(TextureManager::reclaimLimitBytes(viewportSize()));
     contentsTextureManager()->deleteEvictedTextures(hostImpl->contentsTextureAllocator());
 }
 
@@ -233,6 +235,8 @@ void CCLayerTreeHost::setNeedsRedraw()
 
 void CCLayerTreeHost::setViewport(const IntSize& viewportSize)
 {
+    contentsTextureManager()->setMaxMemoryLimitBytes(TextureManager::highLimitBytes(viewportSize));
+    contentsTextureManager()->setPreferredMemoryLimitBytes(TextureManager::reclaimLimitBytes(viewportSize));
     m_viewportSize = viewportSize;
     setNeedsCommit();
 }
@@ -263,7 +267,7 @@ void CCLayerTreeHost::setVisible(bool visible)
 
     m_visible = visible;
     if (!visible) {
-        m_contentsTextureManager->reduceMemoryToLimit(TextureManager::lowLimitBytes());
+        m_contentsTextureManager->reduceMemoryToLimit(TextureManager::lowLimitBytes(viewportSize()));
         m_contentsTextureManager->unprotectAllTextures();
     }
 
@@ -279,7 +283,7 @@ void CCLayerTreeHost::didBecomeInvisibleOnImplThread(CCLayerTreeHostImpl* hostIm
     if (m_proxy->layerRendererCapabilities().contextHasCachedFrontBuffer)
         contentsTextureManager()->evictAndDeleteAllTextures(hostImpl->contentsTextureAllocator());
     else {
-        contentsTextureManager()->reduceMemoryToLimit(TextureManager::reclaimLimitBytes());
+        contentsTextureManager()->reduceMemoryToLimit(TextureManager::reclaimLimitBytes(viewportSize()));
         contentsTextureManager()->deleteEvictedTextures(hostImpl->contentsTextureAllocator());
     }
 }
index c14583a..3c1247b 100644 (file)
@@ -1,3 +1,13 @@
+2011-12-06  Eric Penner  <epenner@google.com>
+
+        [chromium] Set texture limits as multiples of viewport size instead of hardcoded values
+        https://bugs.webkit.org/show_bug.cgi?id=72202
+
+        Reviewed by James Robinson.
+
+        * tests/TiledLayerChromiumTest.cpp:
+        (WTF::TEST):
+
 2011-12-06  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r102043.
index a918f7d..63aa456 100644 (file)
@@ -114,7 +114,7 @@ private:
 
 TEST(TiledLayerChromiumTest, pushDirtyTiles)
 {
-    OwnPtr<TextureManager> textureManager = TextureManager::create(4*1024*1024, 1024);
+    OwnPtr<TextureManager> textureManager = TextureManager::create(4*1024*1024, 2*1024*1024, 1024);
     RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(textureManager.get()));
     DebugScopedSetImplThread implThread;
     RefPtr<FakeCCTiledLayerImpl> layerImpl = adoptRef(new FakeCCTiledLayerImpl(0));