[client] lgmp: snapshot and validate frame layouts

This commit is contained in:
Geoffrey McRae
2026-08-24 12:37:00 +10:00
parent abf98c0267
commit ef8636cbeb
4 changed files with 253 additions and 81 deletions

View File

@@ -1382,6 +1382,7 @@ int main_frameThread(void * unused)
{
uint64_t frameSerial = 0;
uint32_t formatVersion = 0;
LG_TransportFrameFormat acceptedFormat = {};
LG_RendererFormat rendererFormat;
uint64_t sourceGeneration = 0;
@@ -1454,6 +1455,30 @@ int main_frameThread(void * unused)
primaryWorkerFailed();
break;
}
if (!lgTransport_validateFrameFormat(format, frame.flags, NULL))
{
videoPayloadRelease();
DEBUG_ERROR(
"Transport returned an invalid frame layout: type=%d "
"data=%ux%u frame=%ux%u stride=%u pitch=%u flags=%#x",
format->type, format->dataWidth, format->dataHeight,
format->frameWidth, format->frameHeight,
format->stride, format->pitch, frame.flags);
g_state.videoOps->frame->releaseFrame(g_state.transport.handle, &frame);
primaryWorkerFailed();
break;
}
if (!sourceChanged && g_state.formatValid &&
format->version == formatVersion &&
!lgTransport_frameLayoutMatches(format, &acceptedFormat))
{
videoPayloadRelease();
DEBUG_ERROR(
"Transport changed the frame layout without changing its version");
g_state.videoOps->frame->releaseFrame(g_state.transport.handle, &frame);
primaryWorkerFailed();
break;
}
const bool formatChanged = sourceChanged ||
!g_state.formatValid || format->version != formatVersion;
bool rendererSupportsNativeHDR = false;
@@ -1581,10 +1606,11 @@ int main_frameThread(void * unused)
for (uint32_t i = 0; !invalidDamage && i < damageCount; ++i)
{
const FrameDamageRect * rect = &frame.damageRects[i];
invalidDamage = rect->x > format->frameWidth ||
rect->y > format->frameHeight ||
invalidDamage = !rect->width || !rect->height ||
rect->x > format->frameWidth ||
rect->y > format->dataHeight ||
rect->width > format->frameWidth - rect->x ||
rect->height > format->frameHeight - rect->y;
rect->height > format->dataHeight - rect->y;
}
if (invalidDamage)
{
@@ -1630,6 +1656,7 @@ int main_frameThread(void * unused)
{
g_state.formatValid = true;
formatVersion = format->version;
memcpy(&acceptedFormat, format, sizeof(acceptedFormat));
#ifdef ENABLE_TESTS
atomic_store_explicit(&l_testFrameType, format->type,
memory_order_release);