Title: [193897] trunk/Source/WebCore
Revision
193897
Author
zandober...@gmail.com
Date
2015-12-10 02:23:06 -0800 (Thu, 10 Dec 2015)

Log Message

[TexMap] Clean up BitmapTexturePool
https://bugs.webkit.org/show_bug.cgi?id=152073

Reviewed by Daniel Bates.

Move BitmapTexturePoolEntry class under the BitmapTexturePool class, renaming
it to simply Entry and keeping it private. Have the constructor take in an
rvalue reference to the RefPtr<BitmapTexture> object. Remove the static
compareTimeLastUsed() function and use a lambda directly in its place.

Remove the default BitmapTexturePool constructor, which isn't used anywhere.
Have the constructor and some methods accept or return RefPtr objects, possibly
via rvalue references. Clean up the header file by removing a few unnecessary
header includes and using forward declarations where possible.

In the BitmapTexturePool implementation file, mark the two const variables as
static. The ::acquireTexture() method now uses the std::find_if() algorithm
to find a fitting Entry object in the Vector. The same method is also moved
upwards so we follow the order of declaration in the header. ::createTexture()
inlines the return of the new _expression_ into the adoptRef() call in the return
statement.

TextureMapperGL constructor is updated to pass a copied RefPtr object into the
BitmapTexturePool constructor.

* platform/graphics/texmap/BitmapTexturePool.cpp:
(WebCore::BitmapTexturePool::BitmapTexturePool):
(WebCore::BitmapTexturePool::acquireTexture):
(WebCore::BitmapTexturePool::releaseUnusedTexturesTimerFired):
(WebCore::BitmapTexturePool::createTexture):
* platform/graphics/texmap/BitmapTexturePool.h:
(WebCore::BitmapTexturePool::Entry::Entry):
(WebCore::BitmapTexturePool::Entry::markUsed):
(WebCore::BitmapTexturePoolEntry::BitmapTexturePoolEntry): Deleted.
(WebCore::BitmapTexturePoolEntry::markUsed): Deleted.
(WebCore::BitmapTexturePoolEntry::compareTimeLastUsed): Deleted.
* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGL::TextureMapperGL):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (193896 => 193897)


--- trunk/Source/WebCore/ChangeLog	2015-12-10 10:15:36 UTC (rev 193896)
+++ trunk/Source/WebCore/ChangeLog	2015-12-10 10:23:06 UTC (rev 193897)
@@ -1,3 +1,44 @@
+2015-12-10  Zan Dobersek  <zdober...@igalia.com>
+
+        [TexMap] Clean up BitmapTexturePool
+        https://bugs.webkit.org/show_bug.cgi?id=152073
+
+        Reviewed by Daniel Bates.
+
+        Move BitmapTexturePoolEntry class under the BitmapTexturePool class, renaming
+        it to simply Entry and keeping it private. Have the constructor take in an
+        rvalue reference to the RefPtr<BitmapTexture> object. Remove the static
+        compareTimeLastUsed() function and use a lambda directly in its place.
+
+        Remove the default BitmapTexturePool constructor, which isn't used anywhere.
+        Have the constructor and some methods accept or return RefPtr objects, possibly
+        via rvalue references. Clean up the header file by removing a few unnecessary
+        header includes and using forward declarations where possible.
+
+        In the BitmapTexturePool implementation file, mark the two const variables as
+        static. The ::acquireTexture() method now uses the std::find_if() algorithm
+        to find a fitting Entry object in the Vector. The same method is also moved
+        upwards so we follow the order of declaration in the header. ::createTexture()
+        inlines the return of the new _expression_ into the adoptRef() call in the return
+        statement.
+
+        TextureMapperGL constructor is updated to pass a copied RefPtr object into the
+        BitmapTexturePool constructor.
+
+        * platform/graphics/texmap/BitmapTexturePool.cpp:
+        (WebCore::BitmapTexturePool::BitmapTexturePool):
+        (WebCore::BitmapTexturePool::acquireTexture):
+        (WebCore::BitmapTexturePool::releaseUnusedTexturesTimerFired):
+        (WebCore::BitmapTexturePool::createTexture):
+        * platform/graphics/texmap/BitmapTexturePool.h:
+        (WebCore::BitmapTexturePool::Entry::Entry):
+        (WebCore::BitmapTexturePool::Entry::markUsed):
+        (WebCore::BitmapTexturePoolEntry::BitmapTexturePoolEntry): Deleted.
+        (WebCore::BitmapTexturePoolEntry::markUsed): Deleted.
+        (WebCore::BitmapTexturePoolEntry::compareTimeLastUsed): Deleted.
+        * platform/graphics/texmap/TextureMapperGL.cpp:
+        (WebCore::TextureMapperGL::TextureMapperGL):
+
 2015-12-10  Michael Catanzaro  <mcatanz...@igalia.com>
 
         [GTK] RenderThemeGtk::platformActiveSelectionBackgroundColor, et. al. should not clobber state of cached GtkStyleContexts

Modified: trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.cpp (193896 => 193897)


--- trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.cpp	2015-12-10 10:15:36 UTC (rev 193896)
+++ trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.cpp	2015-12-10 10:23:06 UTC (rev 193897)
@@ -29,27 +29,36 @@
 
 #if USE(TEXTURE_MAPPER_GL)
 #include "BitmapTextureGL.h"
-#include "GLContext.h"
 #endif
 
 namespace WebCore {
 
-const double s_releaseUnusedSecondsTolerance = 3;
-const double s_releaseUnusedTexturesTimerInterval = 0.5;
+static const double s_releaseUnusedSecondsTolerance = 3;
+static const double s_releaseUnusedTexturesTimerInterval = 0.5;
 
-BitmapTexturePool::BitmapTexturePool()
-    : m_releaseUnusedTexturesTimer(*this, &BitmapTexturePool::releaseUnusedTexturesTimerFired)
-{
-}
-
 #if USE(TEXTURE_MAPPER_GL)
-BitmapTexturePool::BitmapTexturePool(PassRefPtr<GraphicsContext3D> context)
-    : m_context3D(context)
+BitmapTexturePool::BitmapTexturePool(RefPtr<GraphicsContext3D>&& context3D)
+    : m_context3D(WTF::move(context3D))
     , m_releaseUnusedTexturesTimer(*this, &BitmapTexturePool::releaseUnusedTexturesTimerFired)
 {
 }
 #endif
 
+RefPtr<BitmapTexture> BitmapTexturePool::acquireTexture(const IntSize& size)
+{
+    Entry* selectedEntry = std::find_if(m_textures.begin(), m_textures.end(),
+        [&size](Entry& entry) { return entry.m_texture->refCount() == 1 && entry.m_texture->size() == size; });
+
+    if (selectedEntry == m_textures.end()) {
+        m_textures.append(Entry(createTexture()));
+        selectedEntry = &m_textures.last();
+    }
+
+    scheduleReleaseUnusedTextures();
+    selectedEntry->markIsInUse();
+    return selectedEntry->m_texture.copyRef();
+}
+
 void BitmapTexturePool::scheduleReleaseUnusedTextures()
 {
     if (m_releaseUnusedTexturesTimer.isActive())
@@ -64,46 +73,22 @@
         return;
 
     // Delete entries, which have been unused in s_releaseUnusedSecondsTolerance.
-    std::sort(m_textures.begin(), m_textures.end(), BitmapTexturePoolEntry::compareTimeLastUsed);
+    std::sort(m_textures.begin(), m_textures.end(),
+        [](const Entry& a, const Entry& b) { return a.m_lastUsedTime > b.m_lastUsedTime; });
 
     double minUsedTime = monotonicallyIncreasingTime() - s_releaseUnusedSecondsTolerance;
     for (size_t i = 0; i < m_textures.size(); ++i) {
-        if (m_textures[i].m_timeLastUsed < minUsedTime) {
+        if (m_textures[i].m_lastUsedTime < minUsedTime) {
             m_textures.remove(i, m_textures.size() - i);
             break;
         }
     }
 }
 
-PassRefPtr<BitmapTexture> BitmapTexturePool::acquireTexture(const IntSize& size)
+RefPtr<BitmapTexture> BitmapTexturePool::createTexture()
 {
-    BitmapTexturePoolEntry* selectedEntry = 0;
-    for (auto& entry : m_textures) {
-        // 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 (entry.m_texture->size() == size) {
-            selectedEntry = &entry;
-            break;
-        }
-    }
-
-    if (!selectedEntry) {
-        m_textures.append(BitmapTexturePoolEntry(createTexture()));
-        selectedEntry = &m_textures.last();
-    }
-
-    scheduleReleaseUnusedTextures();
-    selectedEntry->markUsed();
-    return selectedEntry->m_texture;
-}
-
-PassRefPtr<BitmapTexture> BitmapTexturePool::createTexture()
-{
 #if USE(TEXTURE_MAPPER_GL)
-    BitmapTextureGL* texture = new BitmapTextureGL(m_context3D);
-    return adoptRef(texture);
+    return adoptRef(new BitmapTextureGL(m_context3D));
 #else
     return nullptr;
 #endif

Modified: trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.h (193896 => 193897)


--- trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.h	2015-12-10 10:15:36 UTC (rev 193896)
+++ trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.h	2015-12-10 10:23:06 UTC (rev 193897)
@@ -28,8 +28,6 @@
 #define BitmapTexturePool_h
 
 #include "BitmapTexture.h"
-#include "IntRect.h"
-#include "IntSize.h"
 #include "Timer.h"
 #include <wtf/CurrentTime.h>
 
@@ -39,46 +37,43 @@
 
 namespace WebCore {
 
-class TextureMapper;
+class GraphicsContext3D;
+class IntSize;
 
-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();
 #if USE(TEXTURE_MAPPER_GL)
-    explicit BitmapTexturePool(PassRefPtr<GraphicsContext3D>);
+    explicit BitmapTexturePool(RefPtr<GraphicsContext3D>&&);
 #endif
 
-    PassRefPtr<BitmapTexture> acquireTexture(const IntSize&);
+    RefPtr<BitmapTexture> acquireTexture(const IntSize&);
 
 private:
+    struct Entry {
+        explicit Entry(RefPtr<BitmapTexture>&& texture)
+            : m_texture(WTF::move(texture))
+        { }
+
+        void markIsInUse() { m_lastUsedTime = monotonicallyIncreasingTime(); }
+
+        RefPtr<BitmapTexture> m_texture;
+        double m_lastUsedTime;
+    };
+
     void scheduleReleaseUnusedTextures();
     void releaseUnusedTexturesTimerFired();
-    PassRefPtr<BitmapTexture> createTexture();
+    RefPtr<BitmapTexture> createTexture();
 
 #if USE(TEXTURE_MAPPER_GL)
     RefPtr<GraphicsContext3D> m_context3D;
 #endif
 
-    Vector<BitmapTexturePoolEntry> m_textures;
+    Vector<Entry> m_textures;
     Timer m_releaseUnusedTexturesTimer;
 };
 
-}
+} // namespace WebCore
 
 #endif // BitmapTexturePool_h

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp (193896 => 193897)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp	2015-12-10 10:15:36 UTC (rev 193896)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp	2015-12-10 10:23:06 UTC (rev 193897)
@@ -238,7 +238,7 @@
     m_context3D = GraphicsContext3D::createForCurrentGLContext();
     m_data = new TextureMapperGLData(m_context3D.get());
 #if USE(TEXTURE_MAPPER_GL)
-    m_texturePool = std::make_unique<BitmapTexturePool>(m_context3D);
+    m_texturePool = std::make_unique<BitmapTexturePool>(m_context3D.copyRef());
 #endif
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to