- Revision
- 106840
- Author
- jam...@google.com
- Date
- 2012-02-06 13:17:49 -0800 (Mon, 06 Feb 2012)
Log Message
Source/WebCore: Support detaching TextureManager from ManagedTexture
https://bugs.webkit.org/show_bug.cgi?id=77655
Reviewed by Kenneth Russell.
Initial patch by Alok Priyadarshi.
TextureManager now holds references to the textures it manages.
This allows TextureManager to inform managed textures when it gets deleted
so that the texture that outlive the TextureManager can handle the situation gracefully.
Unit test in TextureManagerTest.cpp
* platform/graphics/chromium/ManagedTexture.cpp:
(WebCore::ManagedTexture::ManagedTexture):
(WebCore::ManagedTexture::~ManagedTexture):
(WebCore):
(WebCore::ManagedTexture::managerWillDie):
(WebCore::ManagedTexture::isValid):
(WebCore::ManagedTexture::reserve):
(WebCore::ManagedTexture::unreserve):
(WebCore::ManagedTexture::steal):
(WebCore::ManagedTexture::reset):
* platform/graphics/chromium/ManagedTexture.h:
(WebCore::ManagedTexture::manager):
(ManagedTexture):
(WebCore::ManagedTexture::isReserved):
* platform/graphics/chromium/TextureManager.cpp:
(WebCore::TextureManager::~TextureManager):
(WebCore):
(WebCore::TextureManager::setPreferredMemoryLimitBytes):
(WebCore::TextureManager::registerTexture):
(WebCore::TextureManager::unregisterTexture):
* platform/graphics/chromium/TextureManager.h:
(WebCore):
(TextureManager):
Source/WebKit/chromium: [chromium] Support detaching TextureManager from ManagedTexture
https://bugs.webkit.org/show_bug.cgi?id=77655
Adds unit test for destroying a TextureManager while ManagedTextures are still alive referring to it.
Reviewed by Kenneth Russell.
* tests/TextureManagerTest.cpp:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (106839 => 106840)
--- trunk/Source/WebCore/ChangeLog 2012-02-06 21:05:22 UTC (rev 106839)
+++ trunk/Source/WebCore/ChangeLog 2012-02-06 21:17:49 UTC (rev 106840)
@@ -1,3 +1,41 @@
+2012-02-06 James Robinson <jam...@chromium.org>
+
+ Support detaching TextureManager from ManagedTexture
+ https://bugs.webkit.org/show_bug.cgi?id=77655
+
+ Reviewed by Kenneth Russell.
+ Initial patch by Alok Priyadarshi.
+
+ TextureManager now holds references to the textures it manages.
+ This allows TextureManager to inform managed textures when it gets deleted
+ so that the texture that outlive the TextureManager can handle the situation gracefully.
+
+ Unit test in TextureManagerTest.cpp
+
+ * platform/graphics/chromium/ManagedTexture.cpp:
+ (WebCore::ManagedTexture::ManagedTexture):
+ (WebCore::ManagedTexture::~ManagedTexture):
+ (WebCore):
+ (WebCore::ManagedTexture::managerWillDie):
+ (WebCore::ManagedTexture::isValid):
+ (WebCore::ManagedTexture::reserve):
+ (WebCore::ManagedTexture::unreserve):
+ (WebCore::ManagedTexture::steal):
+ (WebCore::ManagedTexture::reset):
+ * platform/graphics/chromium/ManagedTexture.h:
+ (WebCore::ManagedTexture::manager):
+ (ManagedTexture):
+ (WebCore::ManagedTexture::isReserved):
+ * platform/graphics/chromium/TextureManager.cpp:
+ (WebCore::TextureManager::~TextureManager):
+ (WebCore):
+ (WebCore::TextureManager::setPreferredMemoryLimitBytes):
+ (WebCore::TextureManager::registerTexture):
+ (WebCore::TextureManager::unregisterTexture):
+ * platform/graphics/chromium/TextureManager.h:
+ (WebCore):
+ (TextureManager):
+
2012-02-06 Anders Carlsson <ander...@apple.com>
Wheel event handler count not updated when adding handlers to the window
Modified: trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp (106839 => 106840)
--- trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp 2012-02-06 21:05:22 UTC (rev 106839)
+++ trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp 2012-02-06 21:17:49 UTC (rev 106840)
@@ -39,6 +39,7 @@
, m_format(0)
, m_textureId(0)
{
+ m_textureManager->registerTexture(this);
}
ManagedTexture::ManagedTexture(TextureManager* manager, TextureToken token, IntSize size, unsigned format, unsigned textureId)
@@ -48,21 +49,28 @@
, m_format(format)
, m_textureId(textureId)
{
+ m_textureManager->registerTexture(this);
}
ManagedTexture::~ManagedTexture()
{
+ if (!m_textureManager)
+ return;
+ m_textureManager->unregisterTexture(this);
if (m_token)
m_textureManager->releaseToken(m_token);
}
bool ManagedTexture::isValid(const IntSize& size, unsigned format)
{
- return m_token && size == m_size && format == m_format && m_textureManager->hasTexture(m_token);
+ return m_token && size == m_size && format == m_format && m_textureManager && m_textureManager->hasTexture(m_token);
}
bool ManagedTexture::reserve(const IntSize& size, unsigned format)
{
+ if (!m_textureManager)
+ return false;
+
if (!m_token)
m_token = m_textureManager->getToken();
@@ -83,7 +91,7 @@
void ManagedTexture::unreserve()
{
- if (!m_token)
+ if (!m_token || !m_textureManager)
return;
m_textureManager->unprotectTexture(m_token);
Modified: trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.h (106839 => 106840)
--- trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.h 2012-02-06 21:05:22 UTC (rev 106839)
+++ trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.h 2012-02-06 21:17:49 UTC (rev 106840)
@@ -46,13 +46,14 @@
}
~ManagedTexture();
+ void clearManager() { m_textureManager = 0; }
+
bool isValid(const IntSize&, unsigned format);
bool reserve(const IntSize&, unsigned format);
void unreserve();
bool isReserved()
{
- ASSERT(m_textureManager);
- return m_textureManager->isProtected(m_token);
+ return m_textureManager && m_textureManager->isProtected(m_token);
}
void allocate(TextureAllocator*);
Modified: trunk/Source/WebCore/platform/graphics/chromium/TextureManager.cpp (106839 => 106840)
--- trunk/Source/WebCore/platform/graphics/chromium/TextureManager.cpp 2012-02-06 21:05:22 UTC (rev 106839)
+++ trunk/Source/WebCore/platform/graphics/chromium/TextureManager.cpp 2012-02-06 21:17:49 UTC (rev 106840)
@@ -29,6 +29,7 @@
#include "TextureManager.h"
#include "LayerRendererChromium.h"
+#include "ManagedTexture.h"
using namespace std;
@@ -103,6 +104,12 @@
{
}
+TextureManager::~TextureManager()
+{
+ for (HashSet<ManagedTexture*>::iterator it = m_registeredTextures.begin(); it != m_registeredTextures.end(); ++it)
+ (*it)->clearManager();
+}
+
void TextureManager::setMaxMemoryLimitBytes(size_t memoryLimitBytes)
{
reduceMemoryToLimit(memoryLimitBytes);
@@ -115,6 +122,22 @@
m_preferredMemoryLimitBytes = memoryLimitBytes;
}
+void TextureManager::registerTexture(ManagedTexture* texture)
+{
+ ASSERT(texture);
+ ASSERT(!m_registeredTextures.contains(texture));
+
+ m_registeredTextures.add(texture);
+}
+
+void TextureManager::unregisterTexture(ManagedTexture* texture)
+{
+ ASSERT(texture);
+ ASSERT(m_registeredTextures.contains(texture));
+
+ m_registeredTextures.remove(texture);
+}
+
TextureToken TextureManager::getToken()
{
return m_nextToken++;
Modified: trunk/Source/WebCore/platform/graphics/chromium/TextureManager.h (106839 => 106840)
--- trunk/Source/WebCore/platform/graphics/chromium/TextureManager.h 2012-02-06 21:05:22 UTC (rev 106839)
+++ trunk/Source/WebCore/platform/graphics/chromium/TextureManager.h 2012-02-06 21:17:49 UTC (rev 106840)
@@ -31,10 +31,13 @@
#include <wtf/FastAllocBase.h>
#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
#include <wtf/ListHashSet.h>
+#include <wtf/Vector.h>
namespace WebCore {
+class ManagedTexture;
typedef int TextureToken;
class TextureAllocator {
@@ -53,6 +56,7 @@
{
return adoptPtr(new TextureManager(maxMemoryLimitBytes, preferredMemoryLimitBytes, maxTextureSize));
}
+ ~TextureManager();
// Absolute maximum limit for texture allocations for this instance.
static size_t highLimitBytes(const IntSize& viewportSize);
@@ -68,6 +72,9 @@
void setPreferredMemoryLimitBytes(size_t);
size_t preferredMemoryLimitBytes() { return m_preferredMemoryLimitBytes; }
+ void registerTexture(ManagedTexture*);
+ void unregisterTexture(ManagedTexture*);
+
TextureToken getToken();
void releaseToken(TextureToken);
bool hasTexture(TextureToken);
@@ -104,6 +111,8 @@
void removeTexture(TextureToken, TextureInfo);
unsigned replaceTexture(TextureToken, TextureInfo);
+ HashSet<ManagedTexture*> m_registeredTextures;
+
typedef HashMap<TextureToken, TextureInfo> TextureMap;
TextureMap m_textures;
ListHashSet<TextureToken> m_textureLRUSet;
Modified: trunk/Source/WebKit/chromium/ChangeLog (106839 => 106840)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-02-06 21:05:22 UTC (rev 106839)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-02-06 21:17:49 UTC (rev 106840)
@@ -1,3 +1,14 @@
+2012-02-03 James Robinson <jam...@chromium.org>
+
+ [chromium] Support detaching TextureManager from ManagedTexture
+ https://bugs.webkit.org/show_bug.cgi?id=77655
+
+ Adds unit test for destroying a TextureManager while ManagedTextures are still alive referring to it.
+
+ Reviewed by Kenneth Russell.
+
+ * tests/TextureManagerTest.cpp:
+
2012-02-06 Matthew Delaney <mdela...@apple.com>
toDataURL() uses stale data after putImageData()
Modified: trunk/Source/WebKit/chromium/tests/TextureManagerTest.cpp (106839 => 106840)
--- trunk/Source/WebKit/chromium/tests/TextureManagerTest.cpp 2012-02-06 21:05:22 UTC (rev 106839)
+++ trunk/Source/WebKit/chromium/tests/TextureManagerTest.cpp 2012-02-06 21:17:49 UTC (rev 106840)
@@ -24,6 +24,7 @@
#include "config.h"
+#include "ManagedTexture.h"
#include "TextureManager.h"
#include <gtest/gtest.h>
@@ -243,4 +244,24 @@
EXPECT_EQ(texturesMemorySize(preferredTextures), textureManager->preferredMemoryLimitBytes());
}
+TEST_F(TextureManagerTest, textureManagerDestroyedBeforeManagedTexture)
+{
+ OwnPtr<TextureManager> textureManager = createTextureManager(1, 1);
+ OwnPtr<ManagedTexture> managedTexture = ManagedTexture::create(textureManager.get());
+
+ IntSize size(50, 50);
+ unsigned format = GraphicsContext3D::RGBA;
+
+ // Texture is initially invalid, but we should be able to reserve.
+ EXPECT_FALSE(managedTexture->isValid(size, format));
+ EXPECT_TRUE(managedTexture->reserve(size, format));
+ EXPECT_TRUE(managedTexture->isValid(size, format));
+
+ textureManager.clear();
+
+ // Deleting the manager should invalidate the texture and reservation attempts should fail.
+ EXPECT_FALSE(managedTexture->isValid(size, format));
+ EXPECT_FALSE(managedTexture->reserve(size, format));
+}
+
} // namespace