From d7f9afb3ba1475f5a9a6766a297230a88c2ad78a Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Sat, 10 Jul 2021 18:41:30 -0400 Subject: [PATCH] [host] dxgi: populate damage rectangles Co-Authored-By: Quantum --- host/platform/Windows/capture/DXGI/src/dxgi.c | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) 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;