mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 1195527 - Part 2: Add D3D11 video TextureClient recycler. r=jrmuizel
This commit is contained in:
parent
d07dcdfcf6
commit
4c2bc925a5
@ -44,6 +44,7 @@ using layers::ImageContainer;
|
||||
using layers::D3D9SurfaceImage;
|
||||
using layers::D3D9RecycleAllocator;
|
||||
using layers::D3D11ShareHandleImage;
|
||||
using layers::D3D11RecycleAllocator;
|
||||
|
||||
class D3D9DXVA2Manager : public DXVA2Manager
|
||||
{
|
||||
@ -421,6 +422,7 @@ private:
|
||||
RefPtr<ID3D11DeviceContext> mContext;
|
||||
RefPtr<IMFDXGIDeviceManager> mDXGIDeviceManager;
|
||||
RefPtr<MFTDecoder> mTransform;
|
||||
RefPtr<D3D11RecycleAllocator> mTextureClientAllocator;
|
||||
uint32_t mWidth;
|
||||
uint32_t mHeight;
|
||||
UINT mDeviceManagerToken;
|
||||
@ -486,6 +488,10 @@ D3D11DXVA2Manager::Init(nsACString& aFailureReason)
|
||||
return hr;
|
||||
}
|
||||
|
||||
mTextureClientAllocator = new D3D11RecycleAllocator(layers::ImageBridgeChild::GetSingleton(),
|
||||
mDevice);
|
||||
mTextureClientAllocator->SetMaxPoolSize(5);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@ -527,7 +533,9 @@ D3D11DXVA2Manager::CopyToImage(IMFSample* aVideoSample,
|
||||
"Wrong format?");
|
||||
|
||||
D3D11ShareHandleImage* videoImage = static_cast<D3D11ShareHandleImage*>(image.get());
|
||||
HRESULT hr = videoImage->SetData(D3D11ShareHandleImage::Data(mDevice, gfx::IntSize(mWidth, mHeight), aRegion));
|
||||
HRESULT hr = videoImage->SetData(D3D11ShareHandleImage::Data(mTextureClientAllocator,
|
||||
gfx::IntSize(mWidth, mHeight),
|
||||
aRegion));
|
||||
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
|
||||
|
||||
hr = mTransform->Input(aVideoSample);
|
||||
|
@ -22,11 +22,9 @@ D3D11ShareHandleImage::SetData(const Data& aData)
|
||||
mPictureRect = aData.mRegion;
|
||||
mSize = aData.mSize;
|
||||
|
||||
mTextureClient = TextureClientD3D11::Create(nullptr,
|
||||
gfx::SurfaceFormat::B8G8R8A8,
|
||||
TextureFlags::DEFAULT,
|
||||
aData.mDevice,
|
||||
mSize);
|
||||
mTextureClient =
|
||||
aData.mAllocator->CreateOrRecycleClient(gfx::SurfaceFormat::B8G8R8A8,
|
||||
mSize);
|
||||
if (!mTextureClient) {
|
||||
return E_FAIL;
|
||||
}
|
||||
@ -135,5 +133,37 @@ D3D11ShareHandleImage::GetTexture() const {
|
||||
return mTextureClient->GetD3D11Texture();
|
||||
}
|
||||
|
||||
already_AddRefed<TextureClient>
|
||||
D3D11RecycleAllocator::Allocate(gfx::SurfaceFormat aFormat,
|
||||
gfx::IntSize aSize,
|
||||
BackendSelector aSelector,
|
||||
TextureFlags aTextureFlags,
|
||||
TextureAllocationFlags aAllocFlags)
|
||||
{
|
||||
return TextureClientD3D11::Create(mSurfaceAllocator,
|
||||
aFormat,
|
||||
TextureFlags::DEFAULT,
|
||||
mDevice,
|
||||
aSize);
|
||||
}
|
||||
|
||||
already_AddRefed<TextureClientD3D11>
|
||||
D3D11RecycleAllocator::CreateOrRecycleClient(gfx::SurfaceFormat aFormat,
|
||||
const gfx::IntSize& aSize)
|
||||
{
|
||||
RefPtr<TextureClient> textureClient =
|
||||
CreateOrRecycle(aFormat,
|
||||
aSize,
|
||||
BackendSelector::Content,
|
||||
layers::TextureFlags::DEFAULT);
|
||||
if (!textureClient) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<TextureClientD3D11> textureD3D11 = static_cast<TextureClientD3D11*>(textureClient.get());
|
||||
return textureD3D11.forget();
|
||||
}
|
||||
|
||||
|
||||
} // namespace layers
|
||||
} // namespace mozilla
|
||||
|
@ -12,10 +12,35 @@
|
||||
#include "d3d11.h"
|
||||
#include "mozilla/layers/TextureClient.h"
|
||||
#include "mozilla/layers/TextureD3D11.h"
|
||||
#include "mozilla/layers/TextureClientRecycleAllocator.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
class D3D11RecycleAllocator : public TextureClientRecycleAllocator
|
||||
{
|
||||
public:
|
||||
explicit D3D11RecycleAllocator(ISurfaceAllocator* aAllocator,
|
||||
ID3D11Device* aDevice)
|
||||
: TextureClientRecycleAllocator(aAllocator)
|
||||
, mDevice(aDevice)
|
||||
{}
|
||||
|
||||
already_AddRefed<TextureClientD3D11>
|
||||
CreateOrRecycleClient(gfx::SurfaceFormat aFormat,
|
||||
const gfx::IntSize& aSize);
|
||||
|
||||
protected:
|
||||
virtual already_AddRefed<TextureClient>
|
||||
Allocate(gfx::SurfaceFormat aFormat,
|
||||
gfx::IntSize aSize,
|
||||
BackendSelector aSelector,
|
||||
TextureFlags aTextureFlags,
|
||||
TextureAllocationFlags aAllocFlags) override;
|
||||
|
||||
RefPtr<ID3D11Device> mDevice;
|
||||
};
|
||||
|
||||
// Image class that wraps a ID3D11Texture2D. This class copies the image
|
||||
// passed into SetData(), so that it can be accessed from other D3D devices.
|
||||
// This class also manages the synchronization of the copy, to ensure the
|
||||
@ -24,13 +49,13 @@ class D3D11ShareHandleImage : public Image {
|
||||
public:
|
||||
|
||||
struct Data {
|
||||
Data(ID3D11Device* aDevice,
|
||||
Data(D3D11RecycleAllocator* aAllocator,
|
||||
const gfx::IntSize& aSize,
|
||||
const gfx::IntRect& aRegion)
|
||||
: mDevice(aDevice)
|
||||
: mAllocator(aAllocator)
|
||||
, mSize(aSize)
|
||||
, mRegion(aRegion) {}
|
||||
RefPtr<ID3D11Device> mDevice;
|
||||
RefPtr<D3D11RecycleAllocator> mAllocator;
|
||||
gfx::IntSize mSize;
|
||||
gfx::IntRect mRegion;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user