This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch ecore-evas-gl-drm-offscreen
in repository efl.
View the commit online.
commit 72bc0335e579468e60f4ca2fb57aaa9abda7d258
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Dec 2 15:20:43 2026 -0600
evas:gl_drm: tell the consumer when a buffer is destroyed
A consumer that keeps something derived from the buffer of a frame, such
as an imported dmabuf keyed on the buffer id, has no way to know when to
drop it: the id never comes back, so the only rule available was to drop
what is older than the first id seen after a size change. That rule
cannot work for a consumer that is not given the frames in order, and
leaves what was imported for a canvas that is freed.
Add Evas_Engine_Info_GL_Drm.frame.buffer_free(). It runs once for each
buffer that was given to frame.func, when the buffer is destroyed by a
resize, a reconfiguration or the free of the canvas, and before a frame
of the new size. A buffer drawn while there was no frame.func was never
given to anyone and is not announced. The consumer may still hold a
frame of the buffer then, which has no bo and which it may release from
the callback.
The function is read when the buffer dies and not when it was given, so
the engine keeps no per-consumer state: a layer above that swaps the
consumer has to tell the old one itself.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
---
.../evas/engines/gl_drm/Evas_Engine_GL_Drm.h | 19 +-
src/modules/evas/engines/gl_drm/evas_outbuf.c | 16 +-
src/tests/evas/evas_test_gl_drm.c | 226 +++++++++++++++++++++
3 files changed, 258 insertions(+), 3 deletions(-)
diff --git a/src/modules/evas/engines/gl_drm/Evas_Engine_GL_Drm.h b/src/modules/evas/engines/gl_drm/Evas_Engine_GL_Drm.h
index 1a970dd4ea..0a88ba3f90 100644
--- a/src/modules/evas/engines/gl_drm/Evas_Engine_GL_Drm.h
+++ b/src/modules/evas/engines/gl_drm/Evas_Engine_GL_Drm.h
@@ -49,7 +49,9 @@ struct _Evas_Engine_GL_Drm_Frame
struct gbm_bo *bo;
/* Names the buffer, not the frame: the engine cycles through a few
* buffers and the same buffer always comes back with the same id, so a
- * consumer can cache what it derived from it. Never reused. */
+ * consumer can cache what it derived from it. Never reused.
+ * Evas_Engine_Info_GL_Drm.frame.buffer_free() says when the buffer is
+ * gone. */
uint64_t id;
/* The size of the buffer in pixels. Still valid when bo is NULL. */
int w, h;
@@ -130,11 +132,24 @@ struct _Evas_Engine_Info_GL_Drm
* engine has buffers is not noticed. A consumer that does not want a
* render skipped asks func.frame_buffer_available() first and renders
* only when it answers EINA_TRUE: nothing is lost then, and the
- * damage stays what changed. */
+ * damage stays what changed.
+ *
+ * buffer_free runs once for each buffer that was given to func, when
+ * the buffer is destroyed: the output is resized, reconfigured or
+ * freed. It also runs for a buffer whose frame the consumer still
+ * holds, which is still to be released; the frame has no bo then. It
+ * never runs for a buffer that was not given to func, such as one
+ * drawn while func was NULL. It runs on the main loop, from inside
+ * the resize or the free, before the engine draws a first frame of the
+ * new size, and the same restrictions as for func apply. It is
+ * looked up when the buffer is destroyed, not when it was given:
+ * the consumer that changes it, or data, is told nothing of the
+ * buffers the previous one knew. id is the one of the frame. */
struct
{
void (*func)(void *data, Evas_Engine_GL_Drm_Frame *frame,
const Eina_Rectangle *damage, unsigned int damage_count);
+ void (*buffer_free)(void *data, uint64_t id);
void *data;
} frame;
diff --git a/src/modules/evas/engines/gl_drm/evas_outbuf.c b/src/modules/evas/engines/gl_drm/evas_outbuf.c
index 3d817cb4f2..4d42bb980f 100644
--- a/src/modules/evas/engines/gl_drm/evas_outbuf.c
+++ b/src/modules/evas/engines/gl_drm/evas_outbuf.c
@@ -33,7 +33,10 @@ struct _Outbuf_Frame
{
Evas_Engine_GL_Drm_Frame frame;
struct gbm_surface *surface;
+ Evas_Engine_Info_GL_Drm *info;
Eina_Bool held : 1;
+ /* Given to Evas_Engine_Info_GL_Drm.frame.func at least once */
+ Eina_Bool delivered : 1;
};
static void
@@ -127,9 +130,17 @@ static void
_evas_outbuf_frame_bo_destroy(struct gbm_bo *bo EINA_UNUSED, void *data)
{
Outbuf_Frame *frame = data;
+ Evas_Engine_Info_GL_Drm *info = frame->info;
+ uint64_t id = frame->frame.id;
+ Eina_Bool held = frame->held;
+ Eina_Bool delivered = frame->delivered;
frame->frame.bo = NULL;
- if (!frame->held) free(frame);
+ if (!held) free(frame);
+ /* The consumer may release a frame it holds from here: it is not ours
+ * any more */
+ if ((delivered) && (info->frame.buffer_free))
+ info->frame.buffer_free(info->frame.data, id);
}
static Outbuf_Frame *
@@ -149,6 +160,7 @@ _evas_outbuf_frame_get(Outbuf *ob, struct gbm_bo *bo)
frame->frame.w = ob->w;
frame->frame.h = ob->h;
frame->surface = ob->surface;
+ frame->info = ob->info;
gbm_bo_set_user_data(bo, frame, _evas_outbuf_frame_bo_destroy);
return frame;
@@ -300,6 +312,8 @@ _evas_outbuf_frame_deliver(Outbuf *ob, Tilebuf_Rect *surface_damage)
return;
}
+ frame->delivered = EINA_TRUE;
+
count = eina_inlist_count(EINA_INLIST_GET(surface_damage));
damage = alloca(sizeof(Eina_Rectangle) * count);
EINA_INLIST_FOREACH(EINA_INLIST_GET(surface_damage), r)
diff --git a/src/tests/evas/evas_test_gl_drm.c b/src/tests/evas/evas_test_gl_drm.c
index 9122530011..4041cf21c4 100644
--- a/src/tests/evas/evas_test_gl_drm.c
+++ b/src/tests/evas/evas_test_gl_drm.c
@@ -79,6 +79,9 @@ struct _Test_Canvas
Evas_Engine_GL_Drm_Frame *held[HELD_MAX];
uint64_t ids[HELD_MAX];
+ uint64_t freed[HELD_MAX];
+ /* The frames given when each buffer of freed[] was announced */
+ unsigned int freed_at_frame[HELD_MAX];
Eina_Rectangle damage[DAMAGE_MAX];
Eina_Rectangle mover_rect;
@@ -87,12 +90,14 @@ struct _Test_Canvas
unsigned int warnings;
unsigned int damage_count;
unsigned int id_count;
+ unsigned int freed_count;
unsigned int frame_count;
unsigned int rotation;
int fd;
int w, h;
Eina_Bool hold : 1;
+ Eina_Bool release_in_buffer_free : 1;
Eina_Bool owns_fd : 1;
Eina_Bool damage_overflow : 1;
};
@@ -172,6 +177,29 @@ _frame_cb(void *data, Evas_Engine_GL_Drm_Frame *frame,
c->release(frame);
}
+static void
+_buffer_free_cb(void *data, uint64_t id)
+{
+ Test_Canvas *c = data;
+ unsigned int i;
+
+ ck_assert_uint_lt(c->freed_count, HELD_MAX);
+ c->freed_at_frame[c->freed_count] = c->frame_count;
+ c->freed[c->freed_count++] = id;
+
+ if (!c->release_in_buffer_free) return;
+
+ for (i = 0; i < c->held_count; i++)
+ {
+ if (c->held[i]->id != id) continue;
+
+ ck_assert_ptr_null(c->held[i]->bo);
+ c->release(c->held[i]);
+ c->held[i] = c->held[--c->held_count];
+ break;
+ }
+}
+
static void
_held_release_all(Test_Canvas *c)
{
@@ -235,6 +263,7 @@ _info_fill(Test_Canvas *c)
c->info->info.format = DRM_FORMAT_XRGB8888;
c->info->info.rotation = c->rotation;
c->info->frame.func = _frame_cb;
+ c->info->frame.buffer_free = _buffer_free_cb;
c->info->frame.data = ""
}
@@ -1024,6 +1053,198 @@ EFL_START_TEST(evas_test_gl_drm_resize_then_free)
}
EFL_END_TEST
+/* How many times an id was announced */
+static unsigned int
+_freed_times(const Test_Canvas *c, uint64_t id)
+{
+ unsigned int i, times = 0;
+
+ for (i = 0; i < c->freed_count; i++)
+ {
+ if (c->freed[i] == id) times++;
+ }
+ return times;
+}
+
+/* Frames held at the same time are in different buffers: holds some, and
+ * gives them back. */
+static void
+_buffers_cycle(Test_Canvas *c)
+{
+ unsigned int i;
+
+ c->hold = EINA_TRUE;
+ for (i = 0; i < 3; i++)
+ {
+ _change_and_render(c);
+ }
+ ck_assert_uint_eq(c->held_count, 3);
+ _held_release_all(c);
+ c->hold = EINA_FALSE;
+}
+
+/* Each buffer given to the consumer is announced once, as the resize
+ * destroys it and before a frame of the new size, and then never again. */
+EFL_START_TEST(evas_test_gl_drm_buffer_free_resize)
+{
+ Test_Canvas *c = _canvas_new();
+ unsigned int i, delivered, frames;
+
+ if (!c) return;
+
+ _buffers_cycle(c);
+ delivered = c->id_count;
+ frames = c->frame_count;
+ ck_assert_uint_ge(delivered, 2);
+ ck_assert_uint_eq(c->freed_count, 0);
+
+ _canvas_resize(c, 160, 120);
+ _render(c);
+ ck_assert_uint_eq(c->freed_count, delivered);
+ for (i = 0; i < delivered; i++)
+ {
+ ck_assert_uint_eq(_freed_times(c, c->ids[i]), 1);
+ ck_assert_uint_eq(c->freed_at_frame[i], frames);
+ }
+
+ /* What comes after the resize is another buffer, not announced yet */
+ ck_assert_uint_eq(c->id_count, delivered + 1);
+ ck_assert_uint_eq(_freed_times(c, c->ids[delivered]), 0);
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
+/* The canvas that is freed announces the buffers it still has. */
+EFL_START_TEST(evas_test_gl_drm_buffer_free_canvas_free)
+{
+ Test_Canvas *c = _canvas_new();
+ unsigned int i;
+
+ if (!c) return;
+
+ _buffers_cycle(c);
+ ck_assert_uint_ge(c->id_count, 2);
+ ck_assert_uint_eq(c->freed_count, 0);
+
+ evas_free(c->evas);
+ c->evas = NULL;
+ ck_assert_uint_eq(c->freed_count, c->id_count);
+ for (i = 0; i < c->id_count; i++)
+ {
+ ck_assert_uint_eq(_freed_times(c, c->ids[i]), 1);
+ }
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
+/* The announcement comes while the consumer still holds a frame of the
+ * buffer, which has no bo by then and which the consumer may release from
+ * the callback, or later. */
+EFL_START_TEST(evas_test_gl_drm_buffer_free_frames_held)
+{
+ Test_Canvas *c = _canvas_new();
+
+ if (!c) return;
+
+ c->hold = EINA_TRUE;
+ _render(c);
+ _change_and_render(c);
+ ck_assert_uint_eq(c->held_count, 2);
+
+ _canvas_resize(c, 160, 120);
+ _render(c);
+ ck_assert_uint_eq(c->freed_count, 2);
+ ck_assert_uint_eq(c->held_count, 3);
+ ck_assert_ptr_null(c->held[0]->bo);
+ ck_assert_ptr_null(c->held[1]->bo);
+ _held_release_all(c);
+
+ /* And released by the callback itself: not twice, not never. Valgrind
+ * sees what an assertion cannot. */
+ c->release_in_buffer_free = EINA_TRUE;
+ _change_and_render(c);
+ _change_and_render(c);
+ ck_assert_uint_eq(c->held_count, 2);
+ _canvas_resize(c, 64, 48);
+ _render(c);
+ ck_assert_uint_eq(c->held_count, 1);
+ evas_free(c->evas);
+ c->evas = NULL;
+ ck_assert_uint_eq(c->held_count, 0);
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
+/* A buffer drawn while no frame was wanted was never given to anyone. */
+EFL_START_TEST(evas_test_gl_drm_buffer_free_never_delivered)
+{
+ Test_Canvas *c = _canvas_new();
+ unsigned int i, delivered;
+
+ if (!c) return;
+
+ /* The frames held make the next one go to another buffer, which nobody
+ * draws in after: the engine reads the function when it has a frame. */
+ c->hold = EINA_TRUE;
+ _render(c);
+ _change_and_render(c);
+ delivered = c->id_count;
+ ck_assert_uint_eq(delivered, 2);
+ c->info->frame.func = NULL;
+ _change_and_render(c);
+ ck_assert_uint_eq(c->frame_count, 2);
+ c->info->frame.func = _frame_cb;
+
+ _canvas_resize(c, 160, 120);
+ _render(c);
+ ck_assert_uint_eq(c->freed_count, delivered);
+ for (i = 0; i < delivered; i++)
+ {
+ ck_assert_uint_eq(_freed_times(c, c->ids[i]), 1);
+ }
+
+ evas_free(c->evas);
+ c->evas = NULL;
+ ck_assert_uint_eq(c->freed_count, delivered + 1);
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
+/* The function is the one set when the buffer dies. With none the canvas
+ * goes on, and one set later is told of the buffers that die after. */
+EFL_START_TEST(evas_test_gl_drm_buffer_free_replaced)
+{
+ Test_Canvas *c = _canvas_new();
+ unsigned int delivered;
+
+ if (!c) return;
+
+ _buffers_cycle(c);
+ delivered = c->id_count;
+
+ c->info->frame.buffer_free = NULL;
+ _canvas_resize(c, 160, 120);
+ _render(c);
+ ck_assert_uint_eq(c->freed_count, 0);
+
+ c->info->frame.buffer_free = _buffer_free_cb;
+ _buffers_cycle(c);
+ ck_assert_uint_gt(c->id_count, delivered);
+ _canvas_resize(c, 64, 48);
+ _render(c);
+ /* Not the ones of the first size, whose end nobody was told of, and not
+ * the one of the last size, which is alive */
+ ck_assert_uint_eq(c->freed_count, c->id_count - delivered - 1);
+ ck_assert_uint_eq(_freed_times(c, c->ids[delivered - 1]), 0);
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
EFL_START_TEST(evas_test_gl_drm_no_card_node)
{
Test_Canvas *c;
@@ -1144,6 +1365,11 @@ evas_test_gl_drm(TCase *tc)
tcase_add_test(tc, evas_test_gl_drm_resize);
tcase_add_test(tc, evas_test_gl_drm_free_with_frame_held);
tcase_add_test(tc, evas_test_gl_drm_resize_then_free);
+ tcase_add_test(tc, evas_test_gl_drm_buffer_free_resize);
+ tcase_add_test(tc, evas_test_gl_drm_buffer_free_canvas_free);
+ tcase_add_test(tc, evas_test_gl_drm_buffer_free_frames_held);
+ tcase_add_test(tc, evas_test_gl_drm_buffer_free_never_delivered);
+ tcase_add_test(tc, evas_test_gl_drm_buffer_free_replaced);
tcase_add_test(tc, evas_test_gl_drm_no_card_node);
tcase_add_test(tc, evas_test_gl_drm_same_node);
tcase_add_test(tc, evas_test_gl_drm_rotation_refused);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.