[host] dxgi: fix support for non 24-bit BGR formats

This commit is contained in:
Geoffrey McRae 2023-11-07 13:15:27 +11:00
parent 5f613b09d6
commit 561c45bcb9
2 changed files with 51 additions and 49 deletions

View File

@ -140,16 +140,15 @@ static void d3d11_free(void)
this = NULL;
}
static int scaleForBGR(int x)
{
return x * 3 / 4;
}
static void copyFrameFull(Texture * tex, ID3D11Texture2D * src)
static bool d3d11_copyFrame(Texture * tex, ID3D11Texture2D * src)
{
struct D3D11TexImpl * teximpl = TEXIMPL(*tex);
ID3D11Texture2D * dst = *teximpl->cpu;
INTERLOCKED_SECTION(dxgi->deviceContextLock,
{
tex->copyTime = microtime();
if (tex->texDamageCount < 0)
ID3D11DeviceContext_CopyResource(*dxgi->deviceContext,
(ID3D11Resource *)dst, (ID3D11Resource *)src);
@ -160,26 +159,26 @@ static void copyFrameFull(Texture * tex, ID3D11Texture2D * src)
FrameDamageRect * rect = tex->texDamageRects + i;
D3D11_BOX box =
{
.left = scaleForBGR(rect->x),
.left = rect->x,
.top = rect->y,
.front = 0,
.back = 1,
.right = scaleForBGR(rect->x + rect->width),
.right = rect->x + rect->width,
.bottom = rect->y + rect->height,
};
if (dxgi->outputFormat == CAPTURE_FMT_BGR)
{
box.left = box.left * 3 / 4;
box.right = box.right * 3 / 4;
}
ID3D11DeviceContext_CopySubresourceRegion(*dxgi->deviceContext,
(ID3D11Resource *)dst, 0, box.left, box.top, 0,
(ID3D11Resource *)src, 0, &box);
}
}
}
static bool d3d11_copyFrame(Texture * tex, ID3D11Texture2D * src)
{
INTERLOCKED_SECTION(dxgi->deviceContextLock,
{
tex->copyTime = microtime();
copyFrameFull(tex, src);
ID3D11DeviceContext_Flush(*dxgi->deviceContext);
});
return true;

View File

@ -1295,11 +1295,6 @@ 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);
@ -1319,13 +1314,15 @@ static CaptureResult dxgi_getFrame(FrameBuffer * frame, int frameIndex)
tex->damageRectsCount * sizeof(*tex->damageRects));
damage->count += tex->damageRectsCount;
if (this->outputFormat == CAPTURE_FMT_BGR)
{
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);
int scaledX = originalX * 3 / 4;
rect.x = scaledX;
rect.width = scaleForBGR(originalX + rect.width) - scaledX;
rect.width = ((originalX + rect.width) * 3 / 4) - scaledX;
scaledDamageRects[i] = rect;
}
@ -1333,6 +1330,12 @@ static CaptureResult dxgi_getFrame(FrameBuffer * frame, int frameIndex)
rectsBufferToFramebuffer(scaledDamageRects, damage->count, this->bpp, frame,
this->pitch, this->dataHeight, tex->map, this->pitch);
}
else
{
rectsBufferToFramebuffer(damage->rects, damage->count, this->bpp, frame,
this->pitch, this->dataHeight, tex->map, this->pitch);
}
}
for (int i = 0; i < LGMP_Q_FRAME_LEN; ++i)
{