Title: [133601] trunk/Source/WebCore
Revision
133601
Author
commit-qu...@webkit.org
Date
2012-11-06 07:12:19 -0800 (Tue, 06 Nov 2012)

Log Message

[TexMap] Remove unused textures in the texture pool.
https://bugs.webkit.org/show_bug.cgi?id=100706

Patch by Huang Dongsung <luxte...@company100.net> on 2012-11-06
Reviewed by Noam Rosenthal.

Currently, we do not remove textures in the texture pool of
TextureMapper. The texture pool is destroyed when TextureMapper is
destroyed. It means the texture pool consumes texture memory until its
destruction. This patch removes textures if the textures have been not
used in 3 seconds as LayerTreeCoordinator manages UpdateAtlases.

Changing cache policy is not testable in layout tests.

* platform/graphics/texmap/TextureMapper.cpp:
(WebCore::BitmapTexturePoolEntry::BitmapTexturePoolEntry):
(WebCore::BitmapTexturePoolEntry::markUsed):
(WebCore::BitmapTexturePoolEntry::compareTimeLastUsed):
(BitmapTexturePoolEntry):
(WebCore):
(BitmapTexturePool):
(WebCore::BitmapTexturePool::BitmapTexturePool):
(WebCore::BitmapTexturePool::scheduleReleaseUnusedTextures):
(WebCore::BitmapTexturePool::releaseUnusedTexturesTimerFired):
(WebCore::BitmapTexturePool::acquireTexture):
(WebCore::TextureMapper::acquireTextureFromPool):
(WebCore::TextureMapper::TextureMapper):
(WebCore::TextureMapper::~TextureMapper):
* platform/graphics/texmap/TextureMapper.h:
(WebCore):
(TextureMapper):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (133600 => 133601)


--- trunk/Source/WebCore/ChangeLog	2012-11-06 14:45:05 UTC (rev 133600)
+++ trunk/Source/WebCore/ChangeLog	2012-11-06 15:12:19 UTC (rev 133601)
@@ -1,3 +1,36 @@
+2012-11-06  Huang Dongsung  <luxte...@company100.net>
+
+        [TexMap] Remove unused textures in the texture pool.
+        https://bugs.webkit.org/show_bug.cgi?id=100706
+
+        Reviewed by Noam Rosenthal.
+
+        Currently, we do not remove textures in the texture pool of
+        TextureMapper. The texture pool is destroyed when TextureMapper is
+        destroyed. It means the texture pool consumes texture memory until its
+        destruction. This patch removes textures if the textures have been not
+        used in 3 seconds as LayerTreeCoordinator manages UpdateAtlases.
+
+        Changing cache policy is not testable in layout tests.
+
+        * platform/graphics/texmap/TextureMapper.cpp:
+        (WebCore::BitmapTexturePoolEntry::BitmapTexturePoolEntry):
+        (WebCore::BitmapTexturePoolEntry::markUsed):
+        (WebCore::BitmapTexturePoolEntry::compareTimeLastUsed):
+        (BitmapTexturePoolEntry):
+        (WebCore):
+        (BitmapTexturePool):
+        (WebCore::BitmapTexturePool::BitmapTexturePool):
+        (WebCore::BitmapTexturePool::scheduleReleaseUnusedTextures):
+        (WebCore::BitmapTexturePool::releaseUnusedTexturesTimerFired):
+        (WebCore::BitmapTexturePool::acquireTexture):
+        (WebCore::TextureMapper::acquireTextureFromPool):
+        (WebCore::TextureMapper::TextureMapper):
+        (WebCore::TextureMapper::~TextureMapper):
+        * platform/graphics/texmap/TextureMapper.h:
+        (WebCore):
+        (TextureMapper):
+
 2012-11-02  Ilya Tikhonovsky  <loi...@chromium.org>
 
         Web Inspector: NMI instrument CachedMetadata. It uses ~300k on plus.google.com

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp (133600 => 133601)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp	2012-11-06 14:45:05 UTC (rev 133600)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp	2012-11-06 15:12:19 UTC (rev 133601)
@@ -21,33 +21,105 @@
 #include "TextureMapper.h"
 
 #include "TextureMapperImageBuffer.h"
+#include "Timer.h"
+#include <wtf/CurrentTime.h>
+#include <wtf/NonCopyingSort.h>
 
 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
 
 namespace WebCore {
 
-PassRefPtr<BitmapTexture> TextureMapper::acquireTextureFromPool(const IntSize& size)
+struct BitmapTexturePoolEntry {
+    explicit BitmapTexturePoolEntry(PassRefPtr<BitmapTexture> texture)
+        : m_texture(texture)
+    { }
+    inline void markUsed() { m_timeLastUsed = monotonicallyIncreasingTime(); }
+    static bool compareTimeLastUsed(const BitmapTexturePoolEntry& a, const BitmapTexturePoolEntry& b)
+    {
+        return a.m_timeLastUsed - b.m_timeLastUsed > 0;
+    }
+
+    RefPtr<BitmapTexture> m_texture;
+    double m_timeLastUsed;
+};
+
+class BitmapTexturePool {
+    WTF_MAKE_NONCOPYABLE(BitmapTexturePool);
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    BitmapTexturePool();
+
+    PassRefPtr<BitmapTexture> acquireTexture(const IntSize&, TextureMapper*);
+
+private:
+    void scheduleReleaseUnusedTextures();
+    void releaseUnusedTexturesTimerFired(Timer<BitmapTexturePool>*);
+
+    Vector<BitmapTexturePoolEntry> m_textures;
+    Timer<BitmapTexturePool> m_releaseUnusedTexturesTimer;
+
+    static const double s_releaseUnusedSecondsTolerance = 3;
+    static const double s_releaseUnusedTexturesTimerInterval = 0.5;
+};
+
+BitmapTexturePool::BitmapTexturePool()
+    : m_releaseUnusedTexturesTimer(this, &BitmapTexturePool::releaseUnusedTexturesTimerFired)
+{ }
+
+void BitmapTexturePool::scheduleReleaseUnusedTextures()
 {
-    RefPtr<BitmapTexture> selectedTexture;
+    if (m_releaseUnusedTexturesTimer.isActive())
+        m_releaseUnusedTexturesTimer.stop();
 
-    for (size_t i = 0; i < m_texturePool.size(); ++i) {
-        RefPtr<BitmapTexture>& texture = m_texturePool[i];
+    m_releaseUnusedTexturesTimer.startOneShot(s_releaseUnusedTexturesTimerInterval);
+}
 
-        // If the surface has only one reference (the one in m_texturePool), we can safely reuse it.
-        if (texture->refCount() > 1)
+void BitmapTexturePool::releaseUnusedTexturesTimerFired(Timer<BitmapTexturePool>*)
+{
+    if (m_textures.isEmpty())
+        return;
+
+    // Delete entries, which have been unused in s_releaseUnusedSecondsTolerance.
+    nonCopyingSort(m_textures.begin(), m_textures.end(), BitmapTexturePoolEntry::compareTimeLastUsed);
+
+    double minUsedTime = monotonicallyIncreasingTime() - s_releaseUnusedSecondsTolerance;
+    for (size_t i = 0; i < m_textures.size(); ++i) {
+        if (m_textures[i].m_timeLastUsed < minUsedTime) {
+            m_textures.remove(i, m_textures.size() - i);
+            break;
+        }
+    }
+}
+
+PassRefPtr<BitmapTexture> BitmapTexturePool::acquireTexture(const IntSize& size, TextureMapper* textureMapper)
+{
+    BitmapTexturePoolEntry* selectedEntry = 0;
+    for (size_t i = 0; i < m_textures.size(); ++i) {
+        BitmapTexturePoolEntry* entry = &m_textures[i];
+
+        // If the surface has only one reference (the one in m_textures), we can safely reuse it.
+        if (entry->m_texture->refCount() > 1)
             continue;
 
-        if (texture->canReuseWith(size)) {
-            selectedTexture = texture;
+        if (entry->m_texture->canReuseWith(size)) {
+            selectedEntry = entry;
             break;
         }
     }
 
-    if (!selectedTexture) {
-        selectedTexture = createTexture();
-        m_texturePool.append(selectedTexture);
+    if (!selectedEntry) {
+        m_textures.append(BitmapTexturePoolEntry(textureMapper->createTexture()));
+        selectedEntry = &m_textures.last();
     }
 
+    scheduleReleaseUnusedTextures();
+    selectedEntry->markUsed();
+    return selectedEntry->m_texture;
+}
+
+PassRefPtr<BitmapTexture> TextureMapper::acquireTextureFromPool(const IntSize& size)
+{
+    RefPtr<BitmapTexture> selectedTexture = m_texturePool->acquireTexture(size, this);
     selectedTexture->reset(size, BitmapTexture::SupportsAlpha);
     return selectedTexture;
 }
@@ -59,5 +131,15 @@
     return platformCreateAccelerated();
 }
 
+TextureMapper::TextureMapper(AccelerationMode accelerationMode)
+    : m_interpolationQuality(InterpolationDefault)
+    , m_textDrawingMode(TextModeFill)
+    , m_texturePool(adoptPtr(new BitmapTexturePool()))
+    , m_accelerationMode(accelerationMode)
+{ }
+
+TextureMapper::~TextureMapper()
+{ }
+
 }
 #endif

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.h (133600 => 133601)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.h	2012-11-06 14:45:05 UTC (rev 133600)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.h	2012-11-06 15:12:19 UTC (rev 133601)
@@ -47,6 +47,7 @@
 
 namespace WebCore {
 
+class BitmapTexturePool;
 class TextureMapper;
 
 // A 2D texture that can be the target of software or GL rendering.
@@ -115,7 +116,7 @@
     typedef unsigned PaintFlags;
 
     static PassOwnPtr<TextureMapper> create(AccelerationMode newMode = SoftwareMode);
-    virtual ~TextureMapper() { }
+    virtual ~TextureMapper();
 
     enum ExposedEdges {
         NoEdges = 0,
@@ -150,15 +151,10 @@
 
     virtual IntSize maxTextureSize() const { return IntSize(INT_MAX, INT_MAX); }
 
-    // A surface is released implicitly when dereferenced.
     virtual PassRefPtr<BitmapTexture> acquireTextureFromPool(const IntSize&);
 
 protected:
-    TextureMapper(AccelerationMode accelerationMode)
-        : m_interpolationQuality(InterpolationDefault)
-        , m_textDrawingMode(TextModeFill)
-        , m_accelerationMode(accelerationMode)
-    {}
+    TextureMapper(AccelerationMode);
 
 private:
 #if USE(TEXTURE_MAPPER_GL)
@@ -171,7 +167,7 @@
 #endif
     InterpolationQuality m_interpolationQuality;
     TextDrawingModeFlags m_textDrawingMode;
-    Vector<RefPtr<BitmapTexture> > m_texturePool;
+    OwnPtr<BitmapTexturePool> m_texturePool;
     GraphicsContext* m_context;
     AccelerationMode m_accelerationMode;
 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to