[host] dxgi: populate damage rectangles

Co-Authored-By: Quantum <quantum2048@gmail.com>
This commit is contained in:
Tudor Brindus 2021-07-10 18:41:30 -04:00 committed by Geoffrey McRae
parent 80ab4b5393
commit d7f9afb3ba

View File

@ -27,6 +27,7 @@
#include "common/event.h"
#include "common/dpi.h"
#include "common/runningavg.h"
#include "common/KVMFR.h"
#include <assert.h>
#include <stdatomic.h>
@ -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)
@ -939,6 +951,18 @@ static CaptureResult dxgi_waitFrame(CaptureFrame * frame, const size_t maxFrameS
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;
}