From ea5b6b4026f9255c6c704dbaa64571e63972dc8b Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Sun, 5 Nov 2023 21:44:45 -0500 Subject: [PATCH] [host] DXGI: implement damage-aware RGB24 copy --- .../platform/Windows/capture/DXGI/src/d3d11.c | 9 +++++++-- host/platform/Windows/capture/DXGI/src/dxgi.c | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/host/platform/Windows/capture/DXGI/src/d3d11.c b/host/platform/Windows/capture/DXGI/src/d3d11.c index d931c1b9..90836c95 100644 --- a/host/platform/Windows/capture/DXGI/src/d3d11.c +++ b/host/platform/Windows/capture/DXGI/src/d3d11.c @@ -140,6 +140,11 @@ static void d3d11_free(void) this = NULL; } +static int scaleForBGR(int x) +{ + return x * 3 / 4; +} + static void copyFrameFull(Texture * tex, ID3D11Texture2D * src) { struct D3D11TexImpl * teximpl = TEXIMPL(*tex); @@ -155,11 +160,11 @@ static void copyFrameFull(Texture * tex, ID3D11Texture2D * src) FrameDamageRect * rect = tex->texDamageRects + i; D3D11_BOX box = { - .left = rect->x, + .left = scaleForBGR(rect->x), .top = rect->y, .front = 0, .back = 1, - .right = rect->x + rect->width , + .right = scaleForBGR(rect->x + rect->width), .bottom = rect->y + rect->height, }; ID3D11DeviceContext_CopySubresourceRegion(*dxgi->deviceContext, diff --git a/host/platform/Windows/capture/DXGI/src/dxgi.c b/host/platform/Windows/capture/DXGI/src/dxgi.c index a7f89507..817b331f 100644 --- a/host/platform/Windows/capture/DXGI/src/dxgi.c +++ b/host/platform/Windows/capture/DXGI/src/dxgi.c @@ -1365,6 +1365,11 @@ static CaptureResult dxgi_waitFrame(CaptureFrame * frame, const size_t maxFrameS return CAPTURE_RESULT_OK; } +static int scaleForBGR(int x) +{ + return x * 3 / 4; +} + static CaptureResult dxgi_getFrame(FrameBuffer * frame, int frameIndex) { DEBUG_ASSERT(this); @@ -1383,7 +1388,19 @@ static CaptureResult dxgi_getFrame(FrameBuffer * frame, int frameIndex) memcpy(damage->rects + damage->count, tex->damageRects, tex->damageRectsCount * sizeof(*tex->damageRects)); damage->count += tex->damageRectsCount; - rectsBufferToFramebuffer(damage->rects, damage->count, this->bpp, frame, + + FrameDamageRect scaledDamageRects[damage->count]; + for (int i = 0; i < ARRAYSIZE(scaledDamageRects); i++) { + FrameDamageRect rect = damage->rects[i]; + int originalX = rect.x; + int scaledX = scaleForBGR(originalX); + rect.x = scaledX; + rect.width = scaleForBGR(originalX + rect.width) - scaledX; + + scaledDamageRects[i] = rect; + } + + rectsBufferToFramebuffer(scaledDamageRects, damage->count, this->bpp, frame, this->pitch, this->dataHeight, tex->map, this->pitch); }