Bug 964794 - Remove extra Lock and minimize DT creation/destruction in D3D11 TextureClient. r=Bas

This commit is contained in:
Nicolas Silva 2014-01-29 17:26:42 +01:00
parent bbce6c3530
commit 298c0624fc
2 changed files with 12 additions and 8 deletions

View File

@ -146,6 +146,7 @@ TextureClientD3D11::TextureClientD3D11(gfx::SurfaceFormat aFormat, TextureFlags
: TextureClient(aFlags)
, mFormat(aFormat)
, mIsLocked(false)
, mNeedsClear(false)
{}
TextureClientD3D11::~TextureClientD3D11()
@ -159,6 +160,12 @@ TextureClientD3D11::Lock(OpenMode aMode)
}
MOZ_ASSERT(!mIsLocked, "The Texture is already locked!");
LockD3DTexture(mTexture.get());
if (mNeedsClear) {
mDrawTarget->ClearRect(Rect(0, 0, GetSize().width, GetSize().height));
mNeedsClear = false;
}
mIsLocked = true;
return true;
}
@ -169,7 +176,6 @@ TextureClientD3D11::Unlock()
MOZ_ASSERT(mIsLocked, "Unlocked called while the texture is not locked!");
if (mDrawTarget) {
mDrawTarget->Flush();
mDrawTarget = nullptr;
}
UnlockD3DTexture(mTexture.get());
mIsLocked = false;
@ -184,6 +190,8 @@ TextureClientD3D11::GetAsDrawTarget()
return mDrawTarget;
}
// The DrawTarget is created only once, and is only usable between calls
// to Lock and Unlock.
mDrawTarget = Factory::CreateDrawTargetForD3D10Texture(mTexture, mFormat);
return mDrawTarget;
}
@ -207,13 +215,8 @@ TextureClientD3D11::AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlag
return false;
}
if (aFlags & ALLOC_CLEAR_BUFFER) {
DebugOnly<bool> locked = Lock(OPEN_WRITE_ONLY);
MOZ_ASSERT(locked);
RefPtr<DrawTarget> dt = GetAsDrawTarget();
dt->ClearRect(Rect(0, 0, GetSize().width, GetSize().height));
Unlock();
}
// Defer clearing to the next time we lock to avoid an extra (expensive) lock.
mNeedsClear = aFlags & ALLOC_CLEAR_BUFFER;
return true;
}

View File

@ -66,6 +66,7 @@ protected:
RefPtr<gfx::DrawTarget> mDrawTarget;
gfx::SurfaceFormat mFormat;
bool mIsLocked;
bool mNeedsClear;
};
/**