Skip to content

Commit

Permalink
Bug 1200595 - D3D9 TextureData implementation. r=Bas
Browse files Browse the repository at this point in the history
  • Loading branch information
nical committed Oct 19, 2015
1 parent db75ae2 commit 87dfdde
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 252 deletions.
42 changes: 19 additions & 23 deletions gfx/layers/D3D9SurfaceImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ D3D9SurfaceImage::AllocateAndCopy(D3D9RecycleAllocator* aAllocator,
// DXVA surfaces aren't created sharable, so we need to copy the surface
// to a sharable texture to that it's accessible to the layer manager's
// device.
RefPtr<SharedTextureClientD3D9> textureClient =
RefPtr<TextureClient> textureClient =
aAllocator->CreateOrRecycleClient(gfx::SurfaceFormat::B8G8R8X8, aRegion.Size());
if (!textureClient) {
return E_FAIL;
}

// Copy the image onto the texture, preforming YUV -> RGB conversion if necessary.
RefPtr<IDirect3DSurface9> textureSurface = textureClient->GetD3D9Surface();
RefPtr<IDirect3DSurface9> textureSurface = static_cast<DXGID3D9TextureData*>(
textureClient->GetInternalData())->GetD3D9Surface();
if (!textureSurface) {
return E_FAIL;
}
Expand Down Expand Up @@ -121,7 +122,7 @@ D3D9SurfaceImage::EnsureSynchronized()
const D3DSURFACE_DESC&
D3D9SurfaceImage::GetDesc() const
{
return mTextureClient->GetDesc();
return static_cast<DXGID3D9TextureData*>(mTextureClient->GetInternalData())->GetDesc();
}

gfx::IntSize
Expand All @@ -142,7 +143,9 @@ D3D9SurfaceImage::GetTextureClient(CompositableClient* aClient)
already_AddRefed<gfx::SourceSurface>
D3D9SurfaceImage::GetAsSourceSurface()
{
NS_ENSURE_TRUE(mTextureClient, nullptr);
if (!mTextureClient) {
return nullptr;
}

HRESULT hr;
RefPtr<gfx::DataSourceSurface> surface = gfx::Factory::CreateDataSourceSurface(mSize, gfx::SurfaceFormat::B8G8R8X8);
Expand All @@ -153,14 +156,15 @@ D3D9SurfaceImage::GetAsSourceSurface()
// Ensure that the texture is ready to be used.
EnsureSynchronized();

DXGID3D9TextureData* texData = static_cast<DXGID3D9TextureData*>(mTextureClient->GetInternalData());
// Readback the texture from GPU memory into system memory, so that
// we can copy it into the Cairo image. This is expensive.
RefPtr<IDirect3DSurface9> textureSurface = mTextureClient->GetD3D9Surface();
RefPtr<IDirect3DSurface9> textureSurface = texData->GetD3D9Surface();
if (!textureSurface) {
return nullptr;
}

RefPtr<IDirect3DDevice9> device = mTextureClient->GetD3D9Device();
RefPtr<IDirect3DDevice9> device = texData->GetD3D9Device();
if (!device) {
return nullptr;
}
Expand Down Expand Up @@ -208,28 +212,20 @@ D3D9RecycleAllocator::Allocate(gfx::SurfaceFormat aFormat,
TextureFlags aTextureFlags,
TextureAllocationFlags aAllocFlags)
{
return SharedTextureClientD3D9::Create(mSurfaceAllocator,
aFormat,
aTextureFlags,
mDevice,
aSize);
TextureData* data = DXGID3D9TextureData::Create(aSize, aFormat, aTextureFlags, mDevice);
if (!data) {
return nullptr;
}

return MakeAndAddRef<ClientTexture>(data, aTextureFlags, mSurfaceAllocator);
}

already_AddRefed<SharedTextureClientD3D9>
already_AddRefed<TextureClient>
D3D9RecycleAllocator::CreateOrRecycleClient(gfx::SurfaceFormat aFormat,
const gfx::IntSize& aSize)
{
RefPtr<TextureClient> textureClient =
CreateOrRecycle(aFormat,
aSize,
BackendSelector::Content,
layers::TextureFlags::DEFAULT);
if (!textureClient) {
return nullptr;
}

RefPtr<SharedTextureClientD3D9> textureD3D9 = static_cast<SharedTextureClientD3D9*>(textureClient.get());
return textureD3D9.forget();
return CreateOrRecycle(aFormat, aSize, BackendSelector::Content,
TextureFlags::DEFAULT);
}

} // namespace layers
Expand Down
6 changes: 3 additions & 3 deletions gfx/layers/D3D9SurfaceImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace mozilla {
namespace layers {

class SharedTextureClientD3D9;
class TextureClient;

class D3D9RecycleAllocator : public TextureClientRecycleAllocator
{
Expand All @@ -26,7 +26,7 @@ class D3D9RecycleAllocator : public TextureClientRecycleAllocator
, mDevice(aDevice)
{}

already_AddRefed<SharedTextureClientD3D9>
already_AddRefed<TextureClient>
CreateOrRecycleClient(gfx::SurfaceFormat aFormat,
const gfx::IntSize& aSize);

Expand Down Expand Up @@ -73,7 +73,7 @@ class D3D9SurfaceImage : public Image {

gfx::IntSize mSize;
RefPtr<IDirect3DQuery9> mQuery;
RefPtr<SharedTextureClientD3D9> mTextureClient;
RefPtr<TextureClient> mTextureClient;
bool mValid;
bool mIsFirstFrame;
};
Expand Down
5 changes: 4 additions & 1 deletion gfx/layers/client/TextureClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,10 @@ TextureClient::CreateForDrawing(CompositableForwarder* aAllocator,
aSize.height <= maxTextureSize &&
NS_IsMainThread()) {
if (gfxWindowsPlatform::GetPlatform()->GetD3D9Device()) {
texture = new TextureClientD3D9(aAllocator, aFormat, aTextureFlags);
TextureData* data = D3D9TextureData::Create(aSize, aFormat, aAllocFlags);
if (data) {
return MakeAndAddRef<ClientTexture>(data, aTextureFlags, aAllocator);
}
}
}

Expand Down
Loading

0 comments on commit 87dfdde

Please sign in to comment.