mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 14:57:20 +00:00
[dxgi] cleaned up retry logic
This commit is contained in:
parent
9613127162
commit
fb37174e5f
@ -361,22 +361,33 @@ GrabStatus Capture::DXGI::Capture()
|
||||
IDXGIResourcePtr res;
|
||||
|
||||
HRESULT status;
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
while (true)
|
||||
for (int retryCount = 0; retryCount < 2; ++retryCount)
|
||||
{
|
||||
GrabStatus ret = ReleaseFrame();
|
||||
if (ret != GRAB_STATUS_OK)
|
||||
return ret;
|
||||
|
||||
status = m_dup->AcquireNextFrame(1000, &frameInfo, &res);
|
||||
if (status == DXGI_ERROR_WAIT_TIMEOUT)
|
||||
return GRAB_STATUS_TIMEOUT;
|
||||
|
||||
if (FAILED(status))
|
||||
switch (status)
|
||||
{
|
||||
case S_OK:
|
||||
m_releaseFrame = true;
|
||||
break;
|
||||
|
||||
m_releaseFrame = true;
|
||||
case DXGI_ERROR_WAIT_TIMEOUT:
|
||||
return GRAB_STATUS_TIMEOUT;
|
||||
|
||||
// desktop switch, mode change, switch DWM on or off or Secure Desktop
|
||||
case DXGI_ERROR_ACCESS_LOST:
|
||||
case WAIT_ABANDONED:
|
||||
return GRAB_STATUS_REINIT;
|
||||
|
||||
default:
|
||||
// unknown failure
|
||||
DEBUG_WINERROR("AcquireNextFrame failed", status);
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
|
||||
// if we have a mouse update
|
||||
if (frameInfo.LastMouseUpdateTime.QuadPart)
|
||||
@ -464,45 +475,33 @@ GrabStatus Capture::DXGI::Capture()
|
||||
LeaveCriticalSection(&m_cursorCS);
|
||||
}
|
||||
|
||||
// if we also have frame data, break out to process it
|
||||
if (frameInfo.LastPresentTime.QuadPart != 0)
|
||||
break;
|
||||
// if we don't have frame data
|
||||
if (frameInfo.LastPresentTime.QuadPart == 0)
|
||||
{
|
||||
// if there is nothing to update, just start again
|
||||
if (!cursorUpdated)
|
||||
{
|
||||
--retryCount;
|
||||
continue;
|
||||
}
|
||||
|
||||
res = NULL;
|
||||
|
||||
// if the cursor has been updated
|
||||
if (cursorUpdated)
|
||||
return GRAB_STATUS_CURSOR;
|
||||
|
||||
// otherwise just try again
|
||||
}
|
||||
|
||||
if (SUCCEEDED(status))
|
||||
// success, break out of the retry loop
|
||||
break;
|
||||
|
||||
switch (status)
|
||||
{
|
||||
// desktop switch, mode change, switch DWM on or off or Secure Desktop
|
||||
case DXGI_ERROR_ACCESS_LOST:
|
||||
case WAIT_ABANDONED:
|
||||
return GRAB_STATUS_REINIT;
|
||||
|
||||
default:
|
||||
// unknown failure
|
||||
DEBUG_WINERROR("AcquireNextFrame failed", status);
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// retry count exceeded
|
||||
if (FAILED(status))
|
||||
// ensure we have a frame
|
||||
if (!m_releaseFrame)
|
||||
{
|
||||
DEBUG_WINERROR("Failed to acquire next frame", status);
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
|
||||
// get the texture
|
||||
res.QueryInterface(IID_PPV_ARGS(&m_ftexture));
|
||||
|
||||
if (!m_ftexture)
|
||||
{
|
||||
DEBUG_ERROR("Failed to get src ID3D11Texture2D");
|
||||
@ -565,11 +564,14 @@ GrabStatus Capture::DXGI::GrabFrameRaw(FrameInfo & frame)
|
||||
frame.pitch = m_width * 4;
|
||||
frame.stride = m_width;
|
||||
|
||||
if (frame.pitch == mapping.RowPitch)
|
||||
memcpySSE(frame.buffer, mapping.pData, frame.pitch * m_height);
|
||||
else
|
||||
for(unsigned int y = 0; y < m_height; ++y)
|
||||
memcpySSE(
|
||||
(uint32_t*)frame.buffer + (m_width * y),
|
||||
(uint8_t *)frame.buffer + (frame.pitch * y),
|
||||
(uint8_t *)mapping.pData + (mapping.RowPitch * y),
|
||||
m_width * 4
|
||||
frame.pitch
|
||||
);
|
||||
|
||||
m_deviceContext->Unmap(m_texture[0], 0);
|
||||
|
Loading…
Reference in New Issue
Block a user