[client] egl: stop aliasing damage tracking layouts

Pass damage rectangle arrays and counts explicitly to the EGL mesh
updater instead of casting DesktopDamage to DamageRects.
This commit is contained in:
Geoffrey McRae
2026-08-04 10:54:45 +10:00
parent 2aaf923e48
commit ad53a5e4ee
5 changed files with 28 additions and 23 deletions

View File

@@ -169,7 +169,7 @@ bool egl_damageRender(EGL_Damage * damage, LG_RendererRotate rotate, const struc
egl_shaderUse(damage->shader);
if (data && data->count != 0)
egl_desktopRectsUpdate(damage->mesh, (const struct DamageRects *) data,
egl_desktopRectsUpdate(damage->mesh, data->rects, data->count,
damage->width, damage->height);
egl_desktopRectsRender(damage->mesh);

View File

@@ -508,7 +508,9 @@ bool egl_desktopRender(EGL_Desktop * desktop, unsigned int outputWidth,
egl_desktopRectsMatrix(desktop->matrix,
width, height, x, y, scaleX, scaleY, rotate);
egl_desktopRectsUpdate(desktop->mesh, rects, width, height);
egl_desktopRectsUpdate(desktop->mesh,
rects ? rects->rects : NULL, rects ? rects->count : -1,
width, height);
const bool hdr = desktop->hdr && !desktop->useSpice;
uint32_t hdrPeak = 0;
@@ -539,7 +541,7 @@ bool egl_desktopRender(EGL_Desktop * desktop, unsigned int outputWidth,
{
/* The filter output may have changed everywhere, but this only applies
* to the render that actually evaluated the filter. */
egl_desktopRectsUpdate(desktop->mesh, NULL, width, height);
egl_desktopRectsUpdate(desktop->mesh, NULL, -1, width, height);
*fullFrame = true;
}
}

View File

@@ -107,18 +107,18 @@ inline static void rectToVertices(GLfloat * vertex, const FrameDamageRect * rect
vertex[7] = rect->y + rect->height;
}
void egl_desktopRectsUpdate(EGL_DesktopRects * rects, const struct DamageRects * data,
int width, int height)
void egl_desktopRectsUpdate(EGL_DesktopRects * rects,
const FrameDamageRect * data, int count, int width, int height)
{
if (data && data->count == 0)
if (count == 0)
{
rects->count = 0;
return;
}
const int count = (!data || data->count < 0 ? 1 : data->count) * 8;
GLfloat vertices[count];
if (!data || data->count < 0)
const int vertexCount = (count < 0 ? 1 : count) * 8;
GLfloat vertices[vertexCount];
if (count < 0)
{
FrameDamageRect full = {
.x = 0, .y = 0, .width = width, .height = height,
@@ -128,36 +128,37 @@ void egl_desktopRectsUpdate(EGL_DesktopRects * rects, const struct DamageRects *
}
else
{
rects->count = data->count;
rects->count = count;
DEBUG_ASSERT(rects->count <= rects->maxCount);
for (int i = 0; i < rects->count; ++i)
rectToVertices(vertices + i * 8, data->rects + i);
rectToVertices(vertices + i * 8, data + i);
}
// check if the value actually changed and needs updating
if (count == rects->lastVerticesCount &&
memcmp(rects->lastVertices, vertices, sizeof(GLfloat) * count) == 0)
if (vertexCount == rects->lastVerticesCount &&
memcmp(rects->lastVertices, vertices,
sizeof(GLfloat) * vertexCount) == 0)
return;
// ensure the local storage is large enough
if (count > rects->lastVerticesSize)
if (vertexCount > rects->lastVerticesSize)
{
if (rects->lastVertices)
free(rects->lastVertices);
rects->lastVertices = malloc(sizeof(GLfloat) * count);
rects->lastVertices = malloc(sizeof(GLfloat) * vertexCount);
if (!rects->lastVertices)
{
DEBUG_ERROR("out of memory");
return;
}
rects->lastVerticesSize = count;
rects->lastVerticesSize = vertexCount;
}
// copy the last value for later comparison
rects->lastVerticesCount = count;
memcpy(rects->lastVertices, vertices, sizeof(GLfloat) * count);
rects->lastVerticesCount = vertexCount;
memcpy(rects->lastVertices, vertices, sizeof(GLfloat) * vertexCount);
egl_stateBindBuffer(GL_ARRAY_BUFFER, rects->buffers[0]);
glBufferSubData(GL_ARRAY_BUFFER, 0, rects->count * 8 * sizeof(GLfloat), vertices);

View File

@@ -48,6 +48,6 @@ void egl_screenToDesktopMatrix(double matrix[6], int frameWidth, int frameHeight
bool egl_screenToDesktop(struct FrameDamageRect * output, const double matrix[6],
const struct Rect * rect, int width, int height);
void egl_desktopRectsUpdate(EGL_DesktopRects * rects, const struct DamageRects * data,
int width, int height);
void egl_desktopRectsUpdate(EGL_DesktopRects * rects,
const FrameDamageRect * data, int count, int width, int height);
void egl_desktopRectsRender(EGL_DesktopRects * rects);

View File

@@ -906,13 +906,15 @@ bool egl_postProcessRun(EGL_PostProcess * this, EGL_Texture * tex,
}
rects = this->rects;
egl_desktopRectsUpdate(rects, NULL, desktopWidth, desktopHeight);
egl_desktopRectsUpdate(
rects, NULL, -1, desktopWidth, desktopHeight);
}
if (this->config.fullFrame)
{
rects = this->rects;
egl_desktopRectsUpdate(rects, NULL, desktopWidth, desktopHeight);
egl_desktopRectsUpdate(
rects, NULL, -1, desktopWidth, desktopHeight);
}
EGL_FilterRects filterRects = {