cogl/onscreen: Pass damage regions unflipped

The other similar API all operate with the assumptions that (0,0) is at
the top left, so lets make damage regions behave this way too. Add a
helper to flip the rectangles, to make it a bit more convenient. It'll
be used in more places in a follow up.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4103>
This commit is contained in:
Jonas Ådahl
2024-10-21 21:07:24 +02:00
committed by Marge Bot
parent fffd4e6c52
commit 5deef6accb
3 changed files with 28 additions and 3 deletions

View File

@@ -80,3 +80,23 @@ _cogl_util_one_at_a_time_mix (unsigned int hash)
return hash;
}
static inline void
cogl_rectangles_to_flipped_array (const int *rectangles,
int n_rectangles,
int height,
int *rectangles_array)
{
int i;
for (i = 0; i < n_rectangles; i++)
{
const int *rect = rectangles + 4 * i;
int *flip_rect = rectangles_array + 4 * i;
flip_rect[0] = rect[0];
flip_rect[1] = height - rect[1] - rect[3];
flip_rect[2] = rect[2];
flip_rect[3] = rect[3];
}
}

View File

@@ -256,15 +256,21 @@ cogl_onscreen_egl_queue_damage_region (CoglOnscreen *onscreen,
CoglContext *context = cogl_framebuffer_get_context (framebuffer);
CoglRenderer *renderer = context->display->renderer;
CoglRendererEGL *egl_renderer = renderer->winsys;
int *egl_rectangles;
g_return_if_fail (n_rectangles > 0);
if (!egl_renderer->pf_eglSetDamageRegion)
return;
egl_rectangles = g_alloca (n_rectangles * sizeof (int) * 4);
cogl_rectangles_to_flipped_array (rectangles, n_rectangles,
cogl_framebuffer_get_height (framebuffer),
egl_rectangles);
if (egl_renderer->pf_eglSetDamageRegion (egl_renderer->edpy,
priv->egl_surface,
rectangles,
egl_rectangles,
n_rectangles) == EGL_FALSE)
g_warning ("Error reported by eglSetDamageRegion");
}