Skip to content

Commit

Permalink
Fix for WGC screen capture going stale and not recreating when physic…
Browse files Browse the repository at this point in the history
…ally turning monitor off and on again.
  • Loading branch information
sskodje committed Dec 13, 2022
1 parent 7d6f194 commit f507282
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions ScreenRecorderLibNative/WindowsGraphicsCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ HRESULT WindowsGraphicsCapture::RecreateFramePool(_Inout_ GRAPHICS_FRAME_DATA *p
newFramePoolSize.Height += 100;
}
m_framePool.Recreate(direct3DDevice, winrt::DirectXPixelFormat::B8G8R8A8UIntNormalized, 1, newFramePoolSize);
LOG_TRACE(L"Recreated WGC Frame Pool size [%d,%d]", newFramePoolSize.Width, newFramePoolSize.Height);
}
catch (winrt::hresult_error const &ex)
{
Expand All @@ -421,11 +422,10 @@ HRESULT WindowsGraphicsCapture::RecreateFramePool(_Inout_ GRAPHICS_FRAME_DATA *p

HRESULT WindowsGraphicsCapture::ProcessRecordingTimeout(_Inout_ GRAPHICS_FRAME_DATA *pData)
{
HRESULT hr = DXGI_ERROR_WAIT_TIMEOUT;
if (m_RecordingSource->Type == RecordingSourceType::Window) {
if (!IsWindow(m_RecordingSource->SourceWindow)) {
//The window is gone, gracefully abort.
hr = E_ABORT;
return E_ABORT;
}
else if (IsIconic(m_RecordingSource->SourceWindow)) {
//IsIconic means the window is minimized, and not rendered, so a blank placeholder texture is used instead.
Expand All @@ -441,7 +441,7 @@ HRESULT WindowsGraphicsCapture::ProcessRecordingTimeout(_Inout_ GRAPHICS_FRAME_D
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.Usage = D3D11_USAGE_DEFAULT;
RETURN_ON_BAD_HR(hr = m_Device->CreateTexture2D(&desc, nullptr, &pData->Frame));
RETURN_ON_BAD_HR(m_Device->CreateTexture2D(&desc, nullptr, &pData->Frame));
}
else {
D3D11_TEXTURE2D_DESC desc;
Expand All @@ -451,18 +451,17 @@ HRESULT WindowsGraphicsCapture::ProcessRecordingTimeout(_Inout_ GRAPHICS_FRAME_D
pData->ContentSize = windowSize;
m_TextureManager->BlankTexture(pData->Frame, RECT{ 0,0,windowSize.cx,windowSize.cy }, 0, 0);
QueryPerformanceCounter(&pData->Timestamp);
hr = S_OK;
}
else if (IsRecordingSessionStale()) {
//The session has stopped producing frames for a while, so it should be restarted.
StopCapture();
StartCapture(*m_RecordingSource);
LOG_INFO("Restarted Windows Graphics Capture");
QueryPerformanceCounter(&m_LastCaptureSessionRestart);
hr = DXGI_ERROR_WAIT_TIMEOUT;
return S_OK;
}
}
return hr;
if (IsRecordingSessionStale()) {
//The session has stopped producing frames for a while, so it should be restarted.
StopCapture();
StartCapture(*m_RecordingSource);
LOG_INFO("Restarted Windows Graphics Capture");
QueryPerformanceCounter(&m_LastCaptureSessionRestart);
}
return DXGI_ERROR_WAIT_TIMEOUT;
}

/// <summary>
Expand Down

0 comments on commit f507282

Please sign in to comment.