Screen Capture with DXGI

Started by
2 comments, last by eppo 10 years, 12 months ago

Hi all,

I would like to use DX10 and DXGI to capture a desktop image in Windows 7. However, when I call GetDisplaySurfaceData, I get an error DXGI_ERROR_INVALID_CALL. The code snippet is as following:


D3D10_TEXTURE2D_DESC d3d10Texture2DDesc; 
    D3D10_TEXTURE2D_DESC desc; 
    ZeroMemory( &desc, sizeof(desc) ); 
    desc.Width = 1440; 
    desc.Height = 900; 
    desc.MipLevels = 1; 
    desc.ArraySize = 1; 
    desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 
    desc.SampleDesc.Count = 1; 
    desc.Usage = D3D10_USAGE_DYNAMIC; 
    desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; 
    desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE|D3D10_CPU_ACCESS_WRITE; 
 
    ID3D10Texture2D *pD3d10Texture = NULL; 
    hr = g_pd3dDevice->CreateTexture2D( &desc, NULL, &pD3d10Texture ); 
 
    hr = pD3d10Texture->QueryInterface(__uuidof(IDXGISurface), (void**)&g_pDXGISurface); 
 
    hr = g_pOutput->GetDisplaySurfaceData(g_pDXGISurface); 

In fact, my first question above all is if it's possible to use this DXGIOutput::GetDisplaySurfaceData function to capture the desktop. In DX9 we have GetFrontBufferData, but in DX10/11 there doesn't seem to be a replacement.

Please help and any input would be greatly appreciated.

Advertisement

Are you trying to capture the entire desktop, or only a single desktop window?

GetDisplaySurfaceData() only works in full screen mode. In windowed mode DXGI can blit to a shared surface managed by the desktop windows manager, but has no access to the entire screen buffer. DXGI 1.2 under Windows 8 adds access to the desktop via a Duplication API.

To create a screen dump: Link

To read the contents of a DXGI surface into sys mem, CopyResource() the backbuffer to a surface created with CPU_READ access. Then Map() the surface to read back the texture data.

Are you trying to capture the entire desktop, or only a single desktop window?

GetDisplaySurfaceData() only works in full screen mode. In windowed mode DXGI can blit to a shared surface managed by the desktop windows manager, but has no access to the entire screen buffer. DXGI 1.2 under Windows 8 adds access to the desktop via a Duplication API.

To create a screen dump: Link

To read the contents of a DXGI surface into sys mem, CopyResource() the backbuffer to a surface created with CPU_READ access. Then Map() the surface to read back the texture data.

Hi eppo,

Thank you so much for your reply!

I'm trying to capture the entire desktop. I thought IDXGIOutput represents an adapter output and DWM is implemented using DirectX so I was hoping GetDisplaySurfaceData is able to capture the desktop like what GetFrontBufferData in DX9 does.

Thank you for pointing me to the screen dump link. I tried the BitBlt and GetFrontBufferData methods and the problem with them is the performance - BitBlt is hardware accelerated in Windows 7 but it takes lots of CPU and GetFrontBufferData is slow by design. Desktop Duplication API is only available in Windows 8. Are you aware of any other techniques that would allow me to capture a desktop screen.

GetDisplaySurfaceData() has no access to the DWM shared surface, but in a full screen mode application written in DX10/11(assuming this app is written by someone else and can be any video game for example ), would it be able to capture the output?

If you want to grab other applications' back buffers, you'll have to hook their DXGI API calls (Present() etc.). I believe programs like Fraps and Afterburner use this method.

This topic is closed to new replies.

Advertisement