Bug 1104837: Add warnings and assertions when our assumptions about tile pools fail. r=nical

This commit is contained in:
Milan Sreckovic 2014-11-25 14:54:29 -05:00
parent 9e1fa5e6fd
commit ebc70a4c51
3 changed files with 64 additions and 1 deletions

View File

@ -475,6 +475,9 @@ TextureClient::TextureClient(TextureFlags aFlags)
, mShared(false)
, mValid(true)
, mAddedToCompositableClient(false)
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
, mPoolTracker(nullptr)
#endif
{}
TextureClient::~TextureClient()

View File

@ -37,6 +37,12 @@ class GLContext;
class SharedSurface;
}
// When defined, we track which pool the tile came from and test for
// any inconsistencies. This can be defined in release build as well.
#ifdef DEBUG
#define GFX_DEBUG_TRACK_CLIENTS_IN_POOL 1
#endif
namespace layers {
class AsyncTransactionTracker;
@ -51,6 +57,9 @@ class PTextureChild;
class TextureChild;
class BufferTextureClient;
class TextureClient;
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
class TextureClientPool;
#endif
class KeepAlive;
/**
@ -474,6 +483,12 @@ protected:
friend class RemoveTextureFromCompositableTracker;
friend void TestTextureClientSurface(TextureClient*, gfxImageSurface*);
friend void TestTextureClientYCbCr(TextureClient*, PlanarYCbCrData&);
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
public:
// Pointer to the pool this tile came from.
TextureClientPool* mPoolTracker;
#endif
};
/**

View File

@ -20,7 +20,8 @@ ShrinkCallback(nsITimer *aTimer, void *aClosure)
static_cast<TextureClientPool*>(aClosure)->ShrinkToMinimumSize();
}
TextureClientPool::TextureClientPool(gfx::SurfaceFormat aFormat, gfx::IntSize aSize,
TextureClientPool::TextureClientPool(gfx::SurfaceFormat aFormat,
gfx::IntSize aSize,
uint32_t aMaxTextureClients,
uint32_t aShrinkTimeoutMsec,
ISurfaceAllocator *aAllocator)
@ -42,6 +43,35 @@ TextureClientPool::~TextureClientPool()
mTimer->Cancel();
}
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
static bool TestClientPool(const char* what,
TextureClient* aClient,
TextureClientPool* aPool)
{
TextureClientPool* actual = aClient->mPoolTracker;
bool ok = (actual == aPool);
if (ok) {
ok = (aClient->GetFormat() == aPool->GetFormat());
}
if (!ok) {
if (actual) {
gfxCriticalError() << "Pool error(" << what << "): "
<< aPool << "-" << aPool->GetFormat() << ", "
<< actual << "-" << actual->GetFormat() << ", "
<< aClient->GetFormat();
MOZ_CRASH("Crashing with actual");
} else {
gfxCriticalError() << "Pool error(" << what << "): "
<< aPool << "-" << aPool->GetFormat() << ", nullptr, "
<< aClient->GetFormat();
MOZ_CRASH("Crashing without actual");
}
}
return ok;
}
#endif
TemporaryRef<TextureClient>
TextureClientPool::GetTextureClient()
{
@ -51,6 +81,10 @@ TextureClientPool::GetTextureClient()
mOutstandingClients++;
textureClient = mTextureClients.top();
mTextureClients.pop();
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
DebugOnly<bool> ok = TestClientPool("fetch", textureClient, this);
MOZ_ASSERT(ok);
#endif
return textureClient;
}
@ -70,6 +104,9 @@ TextureClientPool::GetTextureClient()
}
mOutstandingClients++;
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
textureClient->mPoolTracker = this;
#endif
return textureClient;
}
@ -79,6 +116,10 @@ TextureClientPool::ReturnTextureClient(TextureClient *aClient)
if (!aClient) {
return;
}
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
DebugOnly<bool> ok = TestClientPool("return", aClient, this);
MOZ_ASSERT(ok);
#endif
// Add the client to the pool:
MOZ_ASSERT(mOutstandingClients > mTextureClientsDeferred.size());
mOutstandingClients--;
@ -101,6 +142,10 @@ TextureClientPool::ReturnTextureClientDeferred(TextureClient *aClient)
if (!aClient) {
return;
}
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
DebugOnly<bool> ok = TestClientPool("defer", aClient, this);
MOZ_ASSERT(ok);
#endif
mTextureClientsDeferred.push(aClient);
ShrinkToMaximumSize();
}