Jump to content

  • Log In with Google      Sign In   
  • Create Account

Screen Capture with DXGI


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 majiac   Members   -  Reputation: 105

Like
0Likes
Like

Posted 22 April 2013 - 06:55 PM

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.



Sponsor:

#2 eppo   Crossbones+   -  Reputation: 2458

Like
1Likes
Like

Posted 23 April 2013 - 12:21 PM

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.


Edited by eppo, 23 April 2013 - 12:34 PM.


#3 majiac   Members   -  Reputation: 105

Like
0Likes
Like

Posted 23 April 2013 - 04:09 PM

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?



#4 eppo   Crossbones+   -  Reputation: 2458

Like
0Likes
Like

Posted 24 April 2013 - 02:46 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS