[host] DXGI: implement damage-aware RGB24 copy

This commit is contained in:
Tudor Brindus 2023-11-05 21:44:45 -05:00 committed by Geoffrey McRae
parent 6329779893
commit ea5b6b4026
2 changed files with 25 additions and 3 deletions

View file

@ -140,6 +140,11 @@ static void d3d11_free(void)
this = NULL; this = NULL;
} }
static int scaleForBGR(int x)
{
return x * 3 / 4;
}
static void copyFrameFull(Texture * tex, ID3D11Texture2D * src) static void copyFrameFull(Texture * tex, ID3D11Texture2D * src)
{ {
struct D3D11TexImpl * teximpl = TEXIMPL(*tex); struct D3D11TexImpl * teximpl = TEXIMPL(*tex);
@ -155,11 +160,11 @@ static void copyFrameFull(Texture * tex, ID3D11Texture2D * src)
FrameDamageRect * rect = tex->texDamageRects + i; FrameDamageRect * rect = tex->texDamageRects + i;
D3D11_BOX box = D3D11_BOX box =
{ {
.left = rect->x, .left = scaleForBGR(rect->x),
.top = rect->y, .top = rect->y,
.front = 0, .front = 0,
.back = 1, .back = 1,
.right = rect->x + rect->width , .right = scaleForBGR(rect->x + rect->width),
.bottom = rect->y + rect->height, .bottom = rect->y + rect->height,
}; };
ID3D11DeviceContext_CopySubresourceRegion(*dxgi->deviceContext, ID3D11DeviceContext_CopySubresourceRegion(*dxgi->deviceContext,

View file

@ -1365,6 +1365,11 @@ static CaptureResult dxgi_waitFrame(CaptureFrame * frame, const size_t maxFrameS
return CAPTURE_RESULT_OK; return CAPTURE_RESULT_OK;
} }
static int scaleForBGR(int x)
{
return x * 3 / 4;
}
static CaptureResult dxgi_getFrame(FrameBuffer * frame, int frameIndex) static CaptureResult dxgi_getFrame(FrameBuffer * frame, int frameIndex)
{ {
DEBUG_ASSERT(this); DEBUG_ASSERT(this);
@ -1383,7 +1388,19 @@ static CaptureResult dxgi_getFrame(FrameBuffer * frame, int frameIndex)
memcpy(damage->rects + damage->count, tex->damageRects, memcpy(damage->rects + damage->count, tex->damageRects,
tex->damageRectsCount * sizeof(*tex->damageRects)); tex->damageRectsCount * sizeof(*tex->damageRects));
damage->count += tex->damageRectsCount; 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); this->pitch, this->dataHeight, tex->map, this->pitch);
} }