mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-10 08:38:20 +00:00
[host] dxgi: re-mapping is required to sync memory changes properly
This commit is contained in:
parent
0d1d49b00e
commit
1f004472cc
@ -187,34 +187,12 @@ bool DXGI::Initialize(CaptureOptions * options)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = m_deviceContext->Map(m_texture, 0, D3D11_MAP_READ, 0, &m_mapping);
|
|
||||||
if (FAILED(status))
|
|
||||||
{
|
|
||||||
DEBUG_ERROR("Failed to map the texture: %08x", (int)status);
|
|
||||||
DeInitialize();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_surfaceMapped = true;
|
|
||||||
|
|
||||||
D3D11_QUERY_DESC qd;
|
|
||||||
qd.MiscFlags = 0;
|
|
||||||
qd.Query = D3D11_QUERY_EVENT;
|
|
||||||
if (FAILED(m_device->CreateQuery(&qd, &this->m_eventQuery)))
|
|
||||||
{
|
|
||||||
DEBUG_ERROR("Failed to create event query");
|
|
||||||
DeInitialize();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_initialized = true;
|
m_initialized = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DXGI::DeInitialize()
|
void DXGI::DeInitialize()
|
||||||
{
|
{
|
||||||
if (m_eventQuery)
|
|
||||||
m_eventQuery.Release();
|
|
||||||
|
|
||||||
if (m_releaseFrame)
|
if (m_releaseFrame)
|
||||||
{
|
{
|
||||||
m_releaseFrame = false;
|
m_releaseFrame = false;
|
||||||
@ -303,6 +281,7 @@ GrabStatus DXGI::GrabFrame(FrameInfo & frame)
|
|||||||
{
|
{
|
||||||
m_releaseFrame = false;
|
m_releaseFrame = false;
|
||||||
status = m_dup->ReleaseFrame();
|
status = m_dup->ReleaseFrame();
|
||||||
|
|
||||||
switch (status)
|
switch (status)
|
||||||
{
|
{
|
||||||
case S_OK:
|
case S_OK:
|
||||||
@ -325,8 +304,8 @@ GrabStatus DXGI::GrabFrame(FrameInfo & frame)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// send the last frame again if we timeout to prevent the client stalling on restart
|
// send the last frame again if we timeout to prevent the client stalling on restart
|
||||||
frame.width = m_desc.Width;
|
frame.width = m_width;
|
||||||
frame.height = m_desc.Height;
|
frame.height = m_height;
|
||||||
frame.pitch = m_mapping.RowPitch;
|
frame.pitch = m_mapping.RowPitch;
|
||||||
frame.stride = m_mapping.RowPitch / 4;
|
frame.stride = m_mapping.RowPitch / 4;
|
||||||
|
|
||||||
@ -445,22 +424,32 @@ GrabStatus DXGI::GrabFrame(FrameInfo & frame)
|
|||||||
return GRAB_STATUS_ERROR;
|
return GRAB_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
src->GetDesc(&m_desc);
|
|
||||||
m_deviceContext->CopyResource(m_texture, src);
|
m_deviceContext->CopyResource(m_texture, src);
|
||||||
m_deviceContext->End(m_eventQuery);
|
|
||||||
src.Release();
|
src.Release();
|
||||||
|
|
||||||
m_width = m_desc.Width;
|
if (m_surfaceMapped)
|
||||||
m_height = m_desc.Height;
|
{
|
||||||
|
m_deviceContext->Unmap(m_texture, 0);
|
||||||
|
m_surfaceMapped = false;
|
||||||
|
}
|
||||||
|
|
||||||
frame.width = m_desc.Width;
|
status = m_deviceContext->Map(m_texture, 0, D3D11_MAP_READ, 0, &m_mapping);
|
||||||
frame.height = m_desc.Height;
|
if (FAILED(status))
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("Failed to map the texture: %08x", (int)status);
|
||||||
|
DeInitialize();
|
||||||
|
return GRAB_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
m_surfaceMapped = true;
|
||||||
|
|
||||||
|
frame.width = m_width;
|
||||||
|
frame.height = m_height;
|
||||||
frame.pitch = m_mapping.RowPitch;
|
frame.pitch = m_mapping.RowPitch;
|
||||||
frame.stride = m_mapping.RowPitch / 4;
|
frame.stride = m_mapping.RowPitch / 4;
|
||||||
unsigned int size = m_height * m_mapping.RowPitch;
|
unsigned int size = m_height * m_mapping.RowPitch;
|
||||||
|
|
||||||
// wait for the copy to complete before trying to perform the copy
|
// wait for the copy to complete before trying to perform the copy
|
||||||
while(S_FALSE == m_deviceContext->GetData(m_eventQuery, NULL, 0, 0)) {}
|
// while(S_FALSE == m_deviceContext->GetData(m_eventQuery, NULL, 0, 0)) {}
|
||||||
memcpySSE(frame.buffer, m_mapping.pData, size < frame.bufferSize ? size : frame.bufferSize);
|
memcpySSE(frame.buffer, m_mapping.pData, size < frame.bufferSize ? size : frame.bufferSize);
|
||||||
|
|
||||||
return GRAB_STATUS_OK;
|
return GRAB_STATUS_OK;
|
||||||
|
@ -32,7 +32,6 @@ _COM_SMARTPTR_TYPEDEF(IDXGIFactory1 , __uuidof(IDXGIFactory1 ));
|
|||||||
_COM_SMARTPTR_TYPEDEF(ID3D11Device , __uuidof(ID3D11Device ));
|
_COM_SMARTPTR_TYPEDEF(ID3D11Device , __uuidof(ID3D11Device ));
|
||||||
_COM_SMARTPTR_TYPEDEF(ID3D11DeviceContext , __uuidof(ID3D11DeviceContext ));
|
_COM_SMARTPTR_TYPEDEF(ID3D11DeviceContext , __uuidof(ID3D11DeviceContext ));
|
||||||
_COM_SMARTPTR_TYPEDEF(IDXGIDevice , __uuidof(IDXGIDevice ));
|
_COM_SMARTPTR_TYPEDEF(IDXGIDevice , __uuidof(IDXGIDevice ));
|
||||||
_COM_SMARTPTR_TYPEDEF(ID3D11Query , __uuidof(ID3D11Query ));
|
|
||||||
_COM_SMARTPTR_TYPEDEF(IDXGIOutput1 , __uuidof(IDXGIOutput1 ));
|
_COM_SMARTPTR_TYPEDEF(IDXGIOutput1 , __uuidof(IDXGIOutput1 ));
|
||||||
_COM_SMARTPTR_TYPEDEF(IDXGIOutput , __uuidof(IDXGIOutput ));
|
_COM_SMARTPTR_TYPEDEF(IDXGIOutput , __uuidof(IDXGIOutput ));
|
||||||
_COM_SMARTPTR_TYPEDEF(IDXGIAdapter1 , __uuidof(IDXGIAdapter1 ));
|
_COM_SMARTPTR_TYPEDEF(IDXGIAdapter1 , __uuidof(IDXGIAdapter1 ));
|
||||||
@ -84,8 +83,6 @@ namespace Capture
|
|||||||
IDXGIOutputDuplicationPtr m_dup;
|
IDXGIOutputDuplicationPtr m_dup;
|
||||||
bool m_releaseFrame;
|
bool m_releaseFrame;
|
||||||
ID3D11Texture2DPtr m_texture;
|
ID3D11Texture2DPtr m_texture;
|
||||||
D3D11_TEXTURE2D_DESC m_desc;
|
|
||||||
ID3D11QueryPtr m_eventQuery;
|
|
||||||
D3D11_MAPPED_SUBRESOURCE m_mapping;
|
D3D11_MAPPED_SUBRESOURCE m_mapping;
|
||||||
bool m_surfaceMapped;
|
bool m_surfaceMapped;
|
||||||
BYTE * m_pointer;
|
BYTE * m_pointer;
|
||||||
|
Loading…
Reference in New Issue
Block a user