mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-10-12 10:28:08 +00:00
[host] dxgi: re-mapping is required to sync memory changes properly
This commit is contained in:
@@ -186,25 +186,6 @@ bool DXGI::Initialize(CaptureOptions * options)
|
||||
DeInitialize();
|
||||
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;
|
||||
return true;
|
||||
@@ -212,9 +193,6 @@ bool DXGI::Initialize(CaptureOptions * options)
|
||||
|
||||
void DXGI::DeInitialize()
|
||||
{
|
||||
if (m_eventQuery)
|
||||
m_eventQuery.Release();
|
||||
|
||||
if (m_releaseFrame)
|
||||
{
|
||||
m_releaseFrame = false;
|
||||
@@ -303,6 +281,7 @@ GrabStatus DXGI::GrabFrame(FrameInfo & frame)
|
||||
{
|
||||
m_releaseFrame = false;
|
||||
status = m_dup->ReleaseFrame();
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case S_OK:
|
||||
@@ -325,8 +304,8 @@ GrabStatus DXGI::GrabFrame(FrameInfo & frame)
|
||||
continue;
|
||||
|
||||
// send the last frame again if we timeout to prevent the client stalling on restart
|
||||
frame.width = m_desc.Width;
|
||||
frame.height = m_desc.Height;
|
||||
frame.width = m_width;
|
||||
frame.height = m_height;
|
||||
frame.pitch = m_mapping.RowPitch;
|
||||
frame.stride = m_mapping.RowPitch / 4;
|
||||
|
||||
@@ -445,22 +424,32 @@ GrabStatus DXGI::GrabFrame(FrameInfo & frame)
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
|
||||
src->GetDesc(&m_desc);
|
||||
m_deviceContext->CopyResource(m_texture, src);
|
||||
m_deviceContext->End(m_eventQuery);
|
||||
src.Release();
|
||||
src.Release();
|
||||
|
||||
m_width = m_desc.Width;
|
||||
m_height = m_desc.Height;
|
||||
if (m_surfaceMapped)
|
||||
{
|
||||
m_deviceContext->Unmap(m_texture, 0);
|
||||
m_surfaceMapped = false;
|
||||
}
|
||||
|
||||
frame.width = m_desc.Width;
|
||||
frame.height = m_desc.Height;
|
||||
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 GRAB_STATUS_ERROR;
|
||||
}
|
||||
m_surfaceMapped = true;
|
||||
|
||||
frame.width = m_width;
|
||||
frame.height = m_height;
|
||||
frame.pitch = m_mapping.RowPitch;
|
||||
frame.stride = m_mapping.RowPitch / 4;
|
||||
unsigned int size = m_height * m_mapping.RowPitch;
|
||||
|
||||
// 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);
|
||||
|
||||
return GRAB_STATUS_OK;
|
||||
|
Reference in New Issue
Block a user