Bug 951218 - Use RAII to unlock TextureHost. r=bjacob

This commit is contained in:
Nicolas Silva 2013-12-19 17:20:51 +01:00
parent 7426c28af4
commit 1ff99ae9e0
3 changed files with 32 additions and 31 deletions

View File

@ -40,32 +40,6 @@ ContentHostBase::GetAsTextureHost()
return mTextureHost;
}
class MOZ_STACK_CLASS AutoLockTextureHost
{
public:
AutoLockTextureHost(TextureHost* aHost)
: mHost(aHost)
{
mLockSuccess = mHost ? mHost->Lock() : true;
}
~AutoLockTextureHost()
{
if (mHost) {
mHost->Unlock();
}
}
bool IsValid()
{
return mLockSuccess;
}
private:
TextureHost* mHost;
bool mLockSuccess;
};
void
ContentHostBase::Composite(EffectChain& aEffectChain,
float aOpacity,
@ -77,12 +51,15 @@ ContentHostBase::Composite(EffectChain& aEffectChain,
{
NS_ASSERTION(aVisibleRegion, "Requires a visible region");
if (!mTextureHost) {
NS_WARNING("Missing TextureHost");
return;
}
AutoLockTextureHost lock(mTextureHost);
AutoLockTextureHost lockOnWhite(mTextureHostOnWhite);
if (!mTextureHost ||
!lock.IsValid() ||
!lockOnWhite.IsValid()) {
if (lock.Failed() || lockOnWhite.Failed()) {
return;
}

View File

@ -76,7 +76,8 @@ ImageHost::Composite(EffectChain& aEffectChain,
// Make sure the front buffer has a compositor
mFrontBuffer->SetCompositor(GetCompositor());
if (!mFrontBuffer->Lock()) {
AutoLockTextureHost autoLock(mFrontBuffer);
if (autoLock.Failed()) {
NS_WARNING("failed to lock front buffer");
return;
}
@ -153,7 +154,6 @@ ImageHost::Composite(EffectChain& aEffectChain,
rect, aClipRect,
aTransform);
}
mFrontBuffer->Unlock();
}
void

View File

@ -780,6 +780,30 @@ protected:
gfx::SurfaceFormat mFormat;
};
class MOZ_STACK_CLASS AutoLockTextureHost
{
public:
AutoLockTextureHost(TextureHost* aTexture)
: mTexture(aTexture)
{
MOZ_ASSERT(mTexture);
mLocked = aTexture->Lock();
}
~AutoLockTextureHost()
{
if (mLocked) {
mTexture->Unlock();
}
}
bool Failed() { return !mLocked; }
private:
RefPtr<TextureHost> mTexture;
bool mLocked;
};
class AutoLockDeprecatedTextureHost
{
public: