Skip to content

Commit

Permalink
[host] DXGI: implement damage-aware RGB24 copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyene committed Nov 6, 2023
1 parent 1aba6d2 commit 18e913b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 7 additions & 2 deletions host/platform/Windows/capture/DXGI/src/d3d11.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down
19 changes: 18 additions & 1 deletion host/platform/Windows/capture/DXGI/src/dxgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down

0 comments on commit 18e913b

Please sign in to comment.