Bug 1478815 part 3 - Add a DualTextureClientLock for texture clients used for component alpha. r=nical

This commit adds a RAII class for the common operation of attempting
to lock one or two TextureClients and then maybe constructing a
DrawTargetDual from them.

MozReview-Commit-ID: ECQkDSgpyuL

--HG--
extra : rebase_source : abad14bfee32ea2fd1626069f8229487d1f05015
This commit is contained in:
Ryan Hunt 2018-08-01 12:46:35 -05:00
Родитель 74645824fc
Коммит a5f58a4250
1 изменённых файлов: 74 добавлений и 0 удалений

Просмотреть файл

@ -829,6 +829,80 @@ private:
bool mSucceeded;
};
// Automatically locks and unlocks two texture clients, and exposes them as a
// a single draw target dual. Since texture locking is fallible, Succeeded()
// must be checked on the guard object before proceeding.
class MOZ_RAII DualTextureClientAutoLock
{
public:
DualTextureClientAutoLock(TextureClient* aTexture, TextureClient* aTextureOnWhite, OpenMode aMode)
: mTarget(nullptr)
, mTexture(aTexture)
, mTextureOnWhite(aTextureOnWhite)
{
if (!mTexture->Lock(aMode)) {
return;
}
mTarget = mTexture->BorrowDrawTarget();
if (!mTarget) {
mTexture->Unlock();
return;
}
if (!mTextureOnWhite) {
return;
}
if (!mTextureOnWhite->Lock(aMode)) {
mTarget = nullptr;
mTexture->Unlock();
return;
}
RefPtr<gfx::DrawTarget> targetOnWhite = mTextureOnWhite->BorrowDrawTarget();
if (!targetOnWhite) {
mTarget = nullptr;
mTexture->Unlock();
mTextureOnWhite->Unlock();
return;
}
mTarget = gfx::Factory::CreateDualDrawTarget(mTarget, targetOnWhite);
if (!mTarget) {
mTarget = nullptr;
mTexture->Unlock();
mTextureOnWhite->Unlock();
}
}
~DualTextureClientAutoLock()
{
if (Succeeded()) {
mTarget = nullptr;
mTexture->Unlock();
if (mTextureOnWhite) {
mTextureOnWhite->Unlock();
}
}
}
bool Succeeded() const { return !!mTarget; }
operator gfx::DrawTarget*() const { return mTarget; }
gfx::DrawTarget* operator->() const { return mTarget; }
RefPtr<gfx::DrawTarget> mTarget;
private:
RefPtr<TextureClient> mTexture;
RefPtr<TextureClient> mTextureOnWhite;
};
class KeepAlive
{
public: