From 6b16bb3ea18590d3977b5becb2254d8ea09b9d85 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 10 Jul 2021 19:00:04 -0400 Subject: [PATCH] [host] nvfbc: populate damage rectangles --- .../Windows/capture/NVFBC/src/nvfbc.c | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/host/platform/Windows/capture/NVFBC/src/nvfbc.c b/host/platform/Windows/capture/NVFBC/src/nvfbc.c index f40786e3..5621495e 100644 --- a/host/platform/Windows/capture/NVFBC/src/nvfbc.c +++ b/host/platform/Windows/capture/NVFBC/src/nvfbc.c @@ -28,6 +28,7 @@ #include "common/event.h" #include "common/thread.h" #include "common/dpi.h" +#include "common/KVMFR.h" #include #include #include @@ -330,6 +331,32 @@ static CaptureResult nvfbc_waitFrame(CaptureFrame * frame, frame->stride = this->grabStride; frame->rotation = CAPTURE_ROT_0; + const unsigned int h = (this->height + 127) / 128; + const unsigned int w = (this->width + 127) / 128; + + // TODO: use some algorithm to merge large regions + int rectId = 0; + for (unsigned int y = 0; y < h; ++y) + for (unsigned int x = 0; x < w; ++x) + if (this->diffMap[(y*w)+x]) + { + if (rectId >= KVMFR_MAX_DAMAGE_RECTS) + { + rectId = 0; + goto done; + } + + frame->damageRects[rectId++] = (FrameDamageRect) { + .x = x * 128, + .y = y * 128, + .width = 128, + .height = 128, + }; + } + +done: + frame->damageRectsCount = rectId; + #if 0 //NvFBC never sets bIsHDR so instead we check for any data in the alpha channel //If there is data, it's HDR. This is clearly suboptimal