diff --git a/host/platform/Windows/capture/DXGI/CMakeLists.txt b/host/platform/Windows/capture/DXGI/CMakeLists.txt index d71ae2f1..2a1f8e20 100644 --- a/host/platform/Windows/capture/DXGI/CMakeLists.txt +++ b/host/platform/Windows/capture/DXGI/CMakeLists.txt @@ -11,6 +11,7 @@ target_link_libraries(capture_DXGI lg_common d3d11 dxgi + dwmapi ) target_include_directories(capture_DXGI diff --git a/host/platform/Windows/capture/DXGI/src/dxgi.c b/host/platform/Windows/capture/DXGI/src/dxgi.c index 2308b962..2a6ffbe1 100644 --- a/host/platform/Windows/capture/DXGI/src/dxgi.c +++ b/host/platform/Windows/capture/DXGI/src/dxgi.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "dxgi_extra.h" @@ -85,6 +86,7 @@ struct iface ID3D11DeviceContext * deviceContext; LG_Lock deviceContextLock; bool useAcquireLock; + bool dwmFlush; D3D_FEATURE_LEVEL featureLevel; IDXGIOutputDuplication * dup; int maxTextures; @@ -161,6 +163,13 @@ static void dxgi_initOptions(void) .type = OPTION_TYPE_BOOL, .value.x_bool = true }, + { + .module = "dxgi", + .name = "dwmFlush", + .description = "Use DwmFlush to sync the capture to the windows presentation inverval", + .type = OPTION_TYPE_BOOL, + .value.x_bool = true + }, {0} }; @@ -190,6 +199,7 @@ static bool dxgi_create(CaptureGetPointerBuffer getPointerBufferFn, CapturePostP this->maxTextures = 1; this->useAcquireLock = option_get_bool("dxgi", "useAcquireLock"); + this->dwmFlush = option_get_bool("dxgi", "dwmFlush"); this->texture = calloc(this->maxTextures, sizeof(*this->texture)); this->getPointerBufferFn = getPointerBufferFn; this->postPointerBufferFn = postPointerBufferFn; @@ -807,6 +817,13 @@ static CaptureResult dxgi_capture(void) if (result != CAPTURE_RESULT_OK) return result; + // this is a bit of a hack as it causes this thread to block until the next + // present, by doing this we can allow the mouse updates to accumulate instead + // of being called to process every single one. The only caveat is we are + // limited to the refresh rate of the monitor. + if (this->dwmFlush) + DwmFlush(); + if (this->useAcquireLock) { LOCKED({