Bug 809273 - Add AutoLockTextureHost and use it to avoid needing to manually unlock. r=nrc

This commit is contained in:
Matt Woodrow 2013-04-22 14:40:52 +12:00
parent 6a644b8e27
commit cec7cf3964
2 changed files with 28 additions and 4 deletions

View File

@ -46,7 +46,9 @@ ContentHostBase::Composite(EffectChain& aEffectChain,
{
NS_ASSERTION(aVisibleRegion, "Requires a visible region");
if (!mTextureHost || !mTextureHost->Lock()) {
AutoLockTextureHost lock(mTextureHost);
if (!mTextureHost || !lock->IsValid()) {
return;
}
@ -81,7 +83,6 @@ ContentHostBase::Composite(EffectChain& aEffectChain,
subregion.And(region, textureRect);
if (subregion.IsEmpty()) {
// Region is empty, nothing to draw
mTextureHost->Unlock();
return;
}
@ -182,8 +183,6 @@ ContentHostBase::Composite(EffectChain& aEffectChain,
if (iterOnWhite) {
iterOnWhite->EndTileIteration();
}
mTextureHost->Unlock();
}
void

View File

@ -296,6 +296,31 @@ protected:
ISurfaceAllocator* mDeAllocator;
};
class AutoLockTextureHost
{
public:
AutoLockTextureHost(TextureHost* aHost)
: mTextureHost(aHost)
, mIsValid(true)
{
if (mTextureHost) {
mIsValid = mTextureHost->Lock();
}
}
~AutoLockTextureHost()
{
if (mTextureHost && mIsValid) {
mTextureHost->Unlock();
}
}
bool IsValid() { return mIsValid; }
private:
TextureHost *mTextureHost;
bool mIsValid;
};
/**
* This can be used as an offscreen rendering target by the compositor, and