зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
74645824fc
Коммит
a5f58a4250
|
@ -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:
|
||||
|
|
Загрузка…
Ссылка в новой задаче