diff --git a/host/platform/Windows/capture/DXGI/src/dxgi.c b/host/platform/Windows/capture/DXGI/src/dxgi.c index 918e0a96..4f536910 100644 --- a/host/platform/Windows/capture/DXGI/src/dxgi.c +++ b/host/platform/Windows/capture/DXGI/src/dxgi.c @@ -27,6 +27,7 @@ #include "common/event.h" #include "common/dpi.h" #include "common/runningavg.h" +#include "common/KVMFR.h" #include #include @@ -53,6 +54,8 @@ typedef struct Texture ID3D11Texture2D * tex; D3D11_MAPPED_SUBRESOURCE map; uint64_t copyTime; + uint8_t damageRectsCount; + RECT damageRects[KVMFR_MAX_DAMAGE_RECTS]; } Texture; @@ -782,6 +785,15 @@ static CaptureResult dxgi_capture(void) tex->copyTime = microtime(); ID3D11DeviceContext_CopyResource(this->deviceContext, (ID3D11Resource *)tex->tex, (ID3D11Resource *)src); + + UINT damageRectsBufferSizeRequired; + if (IDXGIOutputDuplication_GetFrameDirtyRects(this->dup, KVMFR_MAX_DAMAGE_RECTS, + tex->damageRects, &damageRectsBufferSizeRequired) == S_OK) + tex->damageRectsCount = damageRectsBufferSizeRequired / sizeof(*tex->damageRects); + else + // Either received too many damage regions or hit another error; + // damage the full frame instead. + tex->damageRectsCount = 0; } if (copyPointer) @@ -930,14 +942,26 @@ static CaptureResult dxgi_waitFrame(CaptureFrame * frame, const size_t maxFrameS const unsigned int maxHeight = maxFrameSize / this->pitch; - frame->formatVer = tex->formatVer; - frame->width = this->width; - frame->height = maxHeight > this->height ? this->height : maxHeight; - frame->realHeight = this->height; - frame->pitch = this->pitch; - frame->stride = this->stride; - frame->format = this->format; - frame->rotation = this->rotation; + frame->formatVer = tex->formatVer; + frame->width = this->width; + frame->height = maxHeight > this->height ? this->height : maxHeight; + frame->realHeight = this->height; + frame->pitch = this->pitch; + frame->stride = this->stride; + frame->format = this->format; + frame->rotation = this->rotation; + + frame->damageRectsCount = tex->damageRectsCount; + for (int i = 0; i < tex->damageRectsCount; i++) + { + RECT damageRect = tex->damageRects[i]; + frame->damageRects[i] = (FrameDamageRect) { + .x = damageRect.left, + .y = damageRect.top, + .width = damageRect.right - damageRect.left, + .height = damageRect.bottom - damageRect.top + }; + } atomic_fetch_sub_explicit(&this->texReady, 1, memory_order_release); return CAPTURE_RESULT_OK;