Skip to content
Permalink
Browse files
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:

Canonical link: https://commits.webkit.org/94765@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@106840 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
jamesr committed Feb 6, 2012
1 parent 51e04e6 commit 3b6c582cfa3afbae90419dde144640a6ada35555
Showing 7 changed files with 115 additions and 4 deletions.
@@ -1,3 +1,41 @@
2012-02-06 James Robinson <jamesr@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 <andersca@apple.com>

Wheel event handler count not updated when adding handlers to the window
@@ -39,6 +39,7 @@ ManagedTexture::ManagedTexture(TextureManager* manager)
, 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 @@ ManagedTexture::ManagedTexture(TextureManager* manager, TextureToken token, IntS
, 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 @@ bool ManagedTexture::reserve(const IntSize& size, unsigned format)

void ManagedTexture::unreserve()
{
if (!m_token)
if (!m_token || !m_textureManager)
return;

m_textureManager->unprotectTexture(m_token);
@@ -46,13 +46,14 @@ class ManagedTexture {
}
~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*);
@@ -29,6 +29,7 @@
#include "TextureManager.h"

#include "LayerRendererChromium.h"
#include "ManagedTexture.h"

using namespace std;

@@ -103,6 +104,12 @@ TextureManager::TextureManager(size_t maxMemoryLimitBytes, size_t preferredMemor
{
}

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 @@ void TextureManager::setPreferredMemoryLimitBytes(size_t memoryLimitBytes)
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++;
@@ -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 @@ class TextureManager {
{
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 @@ class TextureManager {
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 @@ class TextureManager {
void removeTexture(TextureToken, TextureInfo);
unsigned replaceTexture(TextureToken, TextureInfo);

HashSet<ManagedTexture*> m_registeredTextures;

typedef HashMap<TextureToken, TextureInfo> TextureMap;
TextureMap m_textures;
ListHashSet<TextureToken> m_textureLRUSet;
@@ -1,3 +1,14 @@
2012-02-03 James Robinson <jamesr@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 <mdelaney@apple.com>

toDataURL() uses stale data after putImageData()
@@ -24,6 +24,7 @@

#include "config.h"

#include "ManagedTexture.h"
#include "TextureManager.h"

#include <gtest/gtest.h>
@@ -243,4 +244,24 @@ TEST_F(TextureManagerTest, setPreferredMemoryLimitBytes)
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

0 comments on commit 3b6c582

Please sign in to comment.