Evren Bingøl
Evren Bingøl

Reputation: 1725

DesktopImageInSystemMemory of DXGI_OUTDUPL_DESC

I need this variable to be TRUE so that I can use MapDesktopSurface of IDXGIOutputDuplication

How do we set this to true. What previous settings can be done.

Here is a link

http://msdn.microsoft.com/en-us/library/windows/desktop/hh404622(v=vs.85).aspx

Upvotes: 3

Views: 796

Answers (1)

Adwaiit Rajjvaed
Adwaiit Rajjvaed

Reputation: 101

I faced the same problem...So this is what you need to do:

The MapDesktopSurface method will most of the times return DXGI_ERROR_UNSUPPORTED as the image is not in the system memory, but in GPU memory.

In this case, you need to transfer that image from GPU memory to System memory.

So how to do that?

  1. Create a descriptor for ID3D11Texture2D of type D3D11_TEXTURE12D_DESC.

  2. Use GetDesc on the image(ID3D11Texture2D) that you acquired using IDXGIOutputDuplication::AcquireNextFrame to fill in the descriptor.

  3. This descriptor that you get has frameDescriptor.Usage set to D3D11_USAGE_DEFAULT.

  4. You need to set the descriptor with following parameters (let others remain as it is):

    frameDescriptor.Usage = D3D11_USAGE_STAGING;
    frameDescriptor.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
    frameDescriptor.BindFlags = 0;
    frameDescriptor.MiscFlags = 0;
    frameDescriptor.MipLevels = 1;
    frameDescriptor.ArraySize = 1;
    frameDescriptor.SampleDesc.Count = 1;
    
  5. Now, create a new staging buffer (ID3D11Texture2D) using the above descriptor as follows:

    m_Device->CreateTexture2D(&frameDescriptor, NULL, &newId3d11Texture2D);
    
  6. Copy the contents of the acquired image to your staging buffer as follows:

    m_DeviceContext->CopyResource(newId3d11Texture2D, m_AcquiredDesktopImage);
    
  7. Important: Release the acquired frame using IDXGIOutputDuplication::ReleaseFrame()

  8. Now you can process this newTexture (newId3d11Texture2D) as you wish!!!!!

Map it if you want...

This should be enough for answering your query...if you want more information, you can always check out the msdn pages or ask through comments...

Upvotes: 2

Related Questions