mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-10 00:28:20 +00:00
[host] dxgi: fix support for non 24-bit BGR formats
This commit is contained in:
parent
5f613b09d6
commit
561c45bcb9
@ -140,46 +140,45 @@ 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;
|
||||
|
||||
if (tex->texDamageCount < 0)
|
||||
ID3D11DeviceContext_CopyResource(*dxgi->deviceContext,
|
||||
(ID3D11Resource *)dst, (ID3D11Resource *)src);
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < tex->texDamageCount; ++i)
|
||||
{
|
||||
FrameDamageRect * rect = tex->texDamageRects + i;
|
||||
D3D11_BOX box =
|
||||
{
|
||||
.left = scaleForBGR(rect->x),
|
||||
.top = rect->y,
|
||||
.front = 0,
|
||||
.back = 1,
|
||||
.right = scaleForBGR(rect->x + rect->width),
|
||||
.bottom = rect->y + rect->height,
|
||||
};
|
||||
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);
|
||||
|
||||
if (tex->texDamageCount < 0)
|
||||
ID3D11DeviceContext_CopyResource(*dxgi->deviceContext,
|
||||
(ID3D11Resource *)dst, (ID3D11Resource *)src);
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < tex->texDamageCount; ++i)
|
||||
{
|
||||
FrameDamageRect * rect = tex->texDamageRects + i;
|
||||
D3D11_BOX box =
|
||||
{
|
||||
.left = rect->x,
|
||||
.top = rect->y,
|
||||
.front = 0,
|
||||
.back = 1,
|
||||
.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);
|
||||
}
|
||||
}
|
||||
|
||||
ID3D11DeviceContext_Flush(*dxgi->deviceContext);
|
||||
});
|
||||
return true;
|
||||
|
@ -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,19 +1314,27 @@ static CaptureResult dxgi_getFrame(FrameBuffer * frame, int frameIndex)
|
||||
tex->damageRectsCount * sizeof(*tex->damageRects));
|
||||
damage->count += tex->damageRectsCount;
|
||||
|
||||
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;
|
||||
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 = originalX * 3 / 4;
|
||||
rect.x = scaledX;
|
||||
rect.width = ((originalX + rect.width) * 3 / 4) - scaledX;
|
||||
|
||||
scaledDamageRects[i] = rect;
|
||||
scaledDamageRects[i] = rect;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
rectsBufferToFramebuffer(scaledDamageRects, damage->count, this->bpp, frame,
|
||||
this->pitch, this->dataHeight, tex->map, this->pitch);
|
||||
}
|
||||
|
||||
for (int i = 0; i < LGMP_Q_FRAME_LEN; ++i)
|
||||
|
Loading…
Reference in New Issue
Block a user