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 6115e9078a46468db2aeb1325d63c890ab342610
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Dec 2 15:25:30 2026 -0600
ecore_evas: tell the consumer of an offscreen canvas when a buffer dies
A consumer of ecore_evas_gl_drm_offscreen_new() that keeps an import
per buffer id could not tell when to drop it. The documentation gave
a rule of thumb (drop what is older than the first id seen after a
size change) that holds only for a consumer that sees every frame in
order, and nothing covered the canvas being freed.
Add Ecore_Evas_Gl_Drm_Buffer_Free_Cb, called once for each buffer that
was given to the consumer, when the engine destroys it, and set it
together with the frame callback: ecore_evas_gl_drm_frame_callback_set()
becomes ecore_evas_gl_drm_frame_callbacks_set(). The two are one
consumer, and setting them in one call leaves no window in which the
frame callback has buffers whose end nobody hears of. The API is not
released, so the rename costs nothing.
When the callbacks are replaced or removed, the consumer that leaves is
told at once of the buffers it still knows, which the canvas keeps
track of per consumer. Otherwise a consumer that is swapped while
frames are held would leak what it cached, and the next one would be
told of buffers it never saw. The canvas is not passed to the
callback: the ids are unique in the process, and during
ecore_evas_free() the canvas is being taken apart, so a pointer to it
would invite calls that crash.
The buffer id documentation loses the rule of thumb.
The Evas of the canvas is not always destroyed by ecore_evas_free(): a
reference held by anyone keeps it, and its engine, until later. The
engine and the frames therefore reach the canvas through a small
reference counted link, not through the canvas, and the consumer is
told of the buffers that remain from the free of the canvas itself, so
that the promise that it hears of all of them before the call returns
does not depend on who else holds the Evas. The interface of the
module gets version 3, since its slots changed.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
---
src/lib/ecore_evas/Ecore_Evas.h | 112 +++++--
src/lib/ecore_evas/ecore_evas.c | 16 +-
src/lib/ecore_evas/ecore_evas_drm.h | 4 +-
.../ecore_evas/engines/drm/ecore_evas_drm.c | 191 ++++++++++-
src/tests/ecore/ecore_test_ecore_evas_gl_drm.c | 356 ++++++++++++++++++++-
5 files changed, 619 insertions(+), 60 deletions(-)
diff --git a/src/lib/ecore_evas/Ecore_Evas.h b/src/lib/ecore_evas/Ecore_Evas.h
index 88cca613c0..ea92e3cb52 100644
--- a/src/lib/ecore_evas/Ecore_Evas.h
+++ b/src/lib/ecore_evas/Ecore_Evas.h
@@ -1682,7 +1682,7 @@ EAPI Ecore_Evas *ecore_evas_gl_drm_new(const char *device, unsigned int pare
* ecore_evas_gl_drm_offscreen_new().
*
* The canvas gives it to the callback set with
- * ecore_evas_gl_drm_frame_callback_set(). It stays the consumer's, and
+ * ecore_evas_gl_drm_frame_callbacks_set(). It stays the consumer's, and
* the canvas does not draw into its buffer, until the consumer gives it
* back with ecore_evas_gl_drm_frame_release(), which it must do exactly
* once. It may outlive the canvas.
@@ -1695,7 +1695,7 @@ typedef struct _Ecore_Evas_Gl_Drm_Frame Ecore_Evas_Gl_Drm_Frame;
* @brief The callback that receives the frames of a canvas made by
* ecore_evas_gl_drm_offscreen_new().
*
- * @param data The data given to ecore_evas_gl_drm_frame_callback_set().
+ * @param data The data given to ecore_evas_gl_drm_frame_callbacks_set().
* @param ee The canvas that drew the frame.
* @param frame The frame. Give it back with
* ecore_evas_gl_drm_frame_release(), now or later.
@@ -1708,7 +1708,7 @@ typedef struct _Ecore_Evas_Gl_Drm_Frame Ecore_Evas_Gl_Drm_Frame;
* The callback runs on the main loop, from inside the render. It must not
* render, resize or free the canvas.
*
- * @see ecore_evas_gl_drm_frame_callback_set()
+ * @see ecore_evas_gl_drm_frame_callbacks_set()
* @since 1.30
*/
typedef void (*Ecore_Evas_Gl_Drm_Frame_Cb)(void *data, Ecore_Evas *ee,
@@ -1716,6 +1716,48 @@ typedef void (*Ecore_Evas_Gl_Drm_Frame_Cb)(void *data, Ecore_Evas *ee,
const Eina_Rectangle *damage,
unsigned int damage_count);
+/**
+ * @brief The callback that is told when a buffer of a canvas made by
+ * ecore_evas_gl_drm_offscreen_new() is gone.
+ *
+ * @param data The data given to ecore_evas_gl_drm_frame_callbacks_set().
+ * @param buffer_id The identifier of the buffer, as
+ * ecore_evas_gl_drm_frame_buffer_id_get() gave it.
+ *
+ * The canvas has no @c Ecore_Evas parameter here: the identifiers are
+ * unique in the process, and while the canvas is being freed there is
+ * nothing left of it that a callback could use.
+ *
+ * It is called once for each buffer that was given to the frame callback
+ * of this consumer, when the buffer is destroyed, and never for another
+ * buffer. A buffer is destroyed when the canvas is resized, which the
+ * canvas does when it renders next, and when the canvas is freed. The
+ * buffers of a resize are all told before the first frame of the new size
+ * reaches the frame callback, and those of ecore_evas_free() before it
+ * returns, even if the canvas itself is only freed later because something
+ * still refers to it, in which case they come when it really is.
+ *
+ * The consumer may still hold a frame of the buffer then. The frame is
+ * still to be given back with ecore_evas_gl_drm_frame_release(), which
+ * may be done from this callback, and no more than before; but
+ * ecore_evas_gl_drm_frame_dmabuf_get() has nothing to export any more and
+ * fails. What the consumer exported before is its own and is not touched:
+ * the descriptors of ecore_evas_gl_drm_frame_dmabuf_get() are closed by
+ * their owner, whenever that is.
+ *
+ * It is also called, at the time, for the buffers that are still alive
+ * when the consumer is replaced or removed by another call of
+ * ecore_evas_gl_drm_frame_callbacks_set(), as the canvas cannot tell it of
+ * their end later.
+ *
+ * The callback runs on the main loop. It must not render, resize or free
+ * the canvas, and must not set the callbacks of the canvas.
+ *
+ * @see ecore_evas_gl_drm_frame_callbacks_set()
+ * @since 1.30
+ */
+typedef void (*Ecore_Evas_Gl_Drm_Buffer_Free_Cb)(void *data, uint64_t buffer_id);
+
/**
* @brief Creates a canvas that draws with the GPU on a DRM render node and
* gives its frames to a callback, with no display, no output and no input.
@@ -1734,7 +1776,7 @@ typedef void (*Ecore_Evas_Gl_Drm_Frame_Cb)(void *data, Ecore_Evas *ee,
* It is meant for a compositor with no monitor, such as a remote desktop
* session. The canvas is hidden: show it with ecore_evas_show(), and make
* the frames with the main loop. Set the callback that receives them with
- * ecore_evas_gl_drm_frame_callback_set(). Nothing is drawn while it is
+ * ecore_evas_gl_drm_frame_callbacks_set(). Nothing is drawn while it is
* hidden or, as for any canvas, while nothing changed.
*
* The node is opened here and closed once the canvas is freed. A process
@@ -1753,8 +1795,9 @@ typedef void (*Ecore_Evas_Gl_Drm_Frame_Cb)(void *data, Ecore_Evas *ee,
* the GPU driver gives buffers (four with Mesa). What changed meanwhile
* is kept, and drawn once a frame is released, with no call of the
* application: nothing is lost. During that time ecore_evas_render() and
- * ecore_evas_manual_render() do nothing, so a consumer must never wait
- * for a new frame before it releases one.
+ * ecore_evas_manual_render() draw nothing (the latter still runs the
+ * animators), so a consumer must never wait for a new frame before it
+ * releases one.
*
* @note It has no vsync of its own: its ticks come from an Ecore_Animator
* on the timer source. While it exists, as for any canvas without tick
@@ -1766,30 +1809,45 @@ typedef void (*Ecore_Evas_Gl_Drm_Frame_Cb)(void *data, Ecore_Evas *ee,
* though it keeps ticking its own objects. In a process that has an X11
* canvas ecore_evas leaves the source alone.
*
- * @see ecore_evas_gl_drm_frame_callback_set()
+ * @see ecore_evas_gl_drm_frame_callbacks_set()
* @since 1.30
*/
EAPI Ecore_Evas *ecore_evas_gl_drm_offscreen_new(const char *render_node, int w, int h);
/**
- * @brief Sets the callback that receives the frames of a canvas made by
- * ecore_evas_gl_drm_offscreen_new().
+ * @brief Sets the callbacks of the consumer of the frames of a canvas made
+ * by ecore_evas_gl_drm_offscreen_new().
*
* @param ee The canvas. A canvas of another engine is logged and ignored.
- * @param func The callback, or @c NULL to stop receiving frames.
- * @param data The data to give to @p func.
+ * @param frame_func The callback that receives the frames, or @c NULL to
+ * stop receiving them.
+ * @param free_func The callback that is told when a buffer is destroyed,
+ * or @c NULL for a consumer that keeps nothing per buffer.
+ * @param data The data to give to both callbacks.
*
- * While there is no callback, the frames are released as soon as they are
- * drawn. Whenever the callback is set, even to another one, the damage of
- * the first frame it gets covers the whole canvas, since it is relative to
- * the frame the callback got before. The frames the old callback still
- * holds stay valid and are released as usual.
+ * Both are set together because they are one consumer: the identifiers
+ * that @p free_func is told of are those that @p frame_func was
+ * given frames of, and of no other consumer. Without @p frame_func there is
+ * no consumer, and @p free_func is not called.
+ *
+ * While there is no frame callback, the frames are released as soon as they
+ * are drawn. Whenever the callbacks are set, even to the same ones, the
+ * damage of the first frame the new consumer gets covers the whole canvas,
+ * since it is relative to the frame the consumer got before. The frames
+ * the old consumer still holds stay valid and are released as usual.
+ *
+ * Every call is a new consumer, the same functions and data as before
+ * included: the old one is told, before this call returns, that each buffer
+ * it knew that is still alive is freed, as if it was destroyed: see
+ * #Ecore_Evas_Gl_Drm_Buffer_Free_Cb. The new one is told of the buffers it
+ * gets a frame of, including a buffer the old one knew.
*
* @since 1.30
*/
-EAPI void ecore_evas_gl_drm_frame_callback_set(Ecore_Evas *ee,
- Ecore_Evas_Gl_Drm_Frame_Cb func,
- const void *data);
+EAPI void ecore_evas_gl_drm_frame_callbacks_set(Ecore_Evas *ee,
+ Ecore_Evas_Gl_Drm_Frame_Cb frame_func,
+ Ecore_Evas_Gl_Drm_Buffer_Free_Cb free_func,
+ const void *data);
/**
* @brief Gives a frame back to the canvas that drew it.
@@ -1832,14 +1890,11 @@ EAPI void ecore_evas_gl_drm_frame_size_get(const Ecore_Evas_Gl_Drm_Frame *frame,
* @return A number, never zero, that names the buffer.
*
* The canvas draws on a few buffers in turn (four with Mesa), and the same
- * buffer always comes back with the same identifier. A resize of the
- * canvas, and freeing it, destroy every buffer: their identifiers never
- * come back, and the buffers that follow have greater ones than any given
- * before, whatever the canvas. A consumer that keeps what it derived from
- * a buffer, such as an import, can key it on the identifier. It then
- * drops what it kept for the identifiers older than the first one it sees
- * after a size change, and needs to keep few in any case, since few
- * buffers are alive at once.
+ * buffer always comes back with the same identifier, which is never used
+ * for another buffer, whatever the canvas. A consumer that keeps what it
+ * derived from a buffer, such as an import, can key it on the identifier,
+ * and drops it when its #Ecore_Evas_Gl_Drm_Buffer_Free_Cb is called for
+ * the identifier. Few buffers are alive at once.
*
* @since 1.30
*/
@@ -1877,7 +1932,8 @@ struct _Ecore_Evas_Gl_Drm_Dmabuf
* @param dmabuf Where to put how the buffer is laid out.
* @return @c EINA_TRUE on success. @c EINA_FALSE, with @p dmabuf left
* alone, if the buffer of the frame is gone because the canvas was
- * resized or freed, or if it could not be exported.
+ * resized or freed, which #Ecore_Evas_Gl_Drm_Buffer_Free_Cb tells
+ * of, or if it could not be exported.
*
* The frames are XRGB8888 (@c DRM_FORMAT_XRGB8888) in a single plane, and
* linear: @c modifier is @c DRM_FORMAT_MOD_LINEAR, which is what the canvas
diff --git a/src/lib/ecore_evas/ecore_evas.c b/src/lib/ecore_evas/ecore_evas.c
index 2bf5b3225a..4787f70c58 100644
--- a/src/lib/ecore_evas/ecore_evas.c
+++ b/src/lib/ecore_evas/ecore_evas.c
@@ -4663,25 +4663,27 @@ ecore_evas_gl_drm_offscreen_new(const char *render_node, int w, int h)
}
EAPI void
-ecore_evas_gl_drm_frame_callback_set(Ecore_Evas *ee,
- Ecore_Evas_Gl_Drm_Frame_Cb func,
- const void *data)
+ecore_evas_gl_drm_frame_callbacks_set(Ecore_Evas *ee,
+ Ecore_Evas_Gl_Drm_Frame_Cb frame_func,
+ Ecore_Evas_Gl_Drm_Buffer_Free_Cb free_func,
+ const void *data)
{
Ecore_Evas_Interface_Drm *iface;
ECORE_EVAS_CHECK(ee);
iface = (Ecore_Evas_Interface_Drm *)_ecore_evas_interface_get_internal(ee, "drm", 0);
- /* The interface of an older module is a smaller structure, and the one of
- * the canvas of a device has no function: version 2 has it. */
- if ((!iface) || (iface->base.version < 2) || (!iface->frame_callback_set))
+ /* The interface of an older module is a smaller structure, or has other
+ * functions in its slots, and the one of the canvas of a device has none:
+ * version 3 has them. */
+ if ((!iface) || (iface->base.version < 3) || (!iface->frame_callbacks_set))
{
ERR("Ecore_Evas %p (engine: %s) was not made by "
"ecore_evas_gl_drm_offscreen_new()", ee, ee->driver);
return;
}
- iface->frame_callback_set(ee, func, data);
+ iface->frame_callbacks_set(ee, frame_func, free_func, data);
}
EAPI void
diff --git a/src/lib/ecore_evas/ecore_evas_drm.h b/src/lib/ecore_evas/ecore_evas_drm.h
index 157347873d..bd8e311bf1 100644
--- a/src/lib/ecore_evas/ecore_evas_drm.h
+++ b/src/lib/ecore_evas/ecore_evas_drm.h
@@ -11,7 +11,9 @@ struct _Ecore_Evas_Interface_Drm
{
Ecore_Evas_Interface base;
/* Only a canvas made by ecore_evas_gl_drm_offscreen_new() has it */
- void (*frame_callback_set)(Ecore_Evas *ee, Ecore_Evas_Gl_Drm_Frame_Cb func, const void *data);
+ void (*frame_callbacks_set)(Ecore_Evas *ee, Ecore_Evas_Gl_Drm_Frame_Cb frame_func,
+ Ecore_Evas_Gl_Drm_Buffer_Free_Cb buffer_free_func,
+ const void *data);
};
/* What the library reads of a frame; the module that made it puts it
diff --git a/src/modules/ecore_evas/engines/drm/ecore_evas_drm.c b/src/modules/ecore_evas/engines/drm/ecore_evas_drm.c
index b5517c8a0f..20186780a3 100644
--- a/src/modules/ecore_evas/engines/drm/ecore_evas_drm.c
+++ b/src/modules/ecore_evas/engines/drm/ecore_evas_drm.c
@@ -1184,12 +1184,34 @@ ecore_evas_gl_drm_new_internal(const char *device, unsigned int parent EINA_UNUS
typedef struct _Ecore_Evas_Gl_Drm_Offscreen_Data Ecore_Evas_Gl_Drm_Offscreen_Data;
typedef struct _Ecore_Evas_Gl_Drm_Offscreen_Frame Ecore_Evas_Gl_Drm_Offscreen_Frame;
+typedef struct _Ecore_Evas_Gl_Drm_Offscreen_Link Ecore_Evas_Gl_Drm_Offscreen_Link;
+
+/* What the engine has as the data of its callbacks, and what the frames
+ * know of the canvas. The engine outlives the canvas when something still
+ * holds a reference on its Evas, and a frame held by the consumer always
+ * does: both reach the canvas here, and find that it is gone when ee is
+ * NULL. The references are the canvas and each frame. */
+struct _Ecore_Evas_Gl_Drm_Offscreen_Link
+{
+ Ecore_Evas *ee;
+ void (*engine_release)(Evas_Engine_GL_Drm_Frame *frame);
+ unsigned int refs;
+ /* The Evas did not start to be deleted: its engine is there to be
+ * told that the canvas is not */
+ Eina_Bool evas_alive : 1;
+};
struct _Ecore_Evas_Gl_Drm_Offscreen_Data
{
Evas_Engine_Info_GL_Drm *info;
+ Ecore_Evas_Gl_Drm_Offscreen_Link *link;
+ Evas *evas;
Ecore_Evas_Gl_Drm_Frame_Cb frame_func;
+ Ecore_Evas_Gl_Drm_Buffer_Free_Cb buffer_free_func;
const void *frame_data;
+ /* The buffers given to frame_func that buffer_free_func was not told
+ * the end of yet, as uint64_t */
+ Eina_Inarray *buffers_known;
/* The size of the last frame given to frame_func */
int frame_w, frame_h;
/* What the next frame holds is not relative to the last one given to the
@@ -1202,6 +1224,7 @@ struct _Ecore_Evas_Gl_Drm_Offscreen_Data
struct _Ecore_Evas_Gl_Drm_Offscreen_Frame
{
Ecore_Evas_Gl_Drm_Frame base;
+ Ecore_Evas_Gl_Drm_Offscreen_Link *link;
Evas_Engine_GL_Drm_Frame *engine_frame;
/* The info goes with the canvas, so the function is kept apart */
void (*engine_release)(Evas_Engine_GL_Drm_Frame *frame);
@@ -1273,14 +1296,32 @@ _offscreen_node_unref(void)
_offscreen_node.fd = -1;
}
+static void
+_offscreen_link_unref(Ecore_Evas_Gl_Drm_Offscreen_Link *link)
+{
+ if (--link->refs) return;
+
+ free(link);
+}
+
+static void
+_offscreen_evas_del_cb(void *data, const Efl_Event *ev EINA_UNUSED)
+{
+ Ecore_Evas_Gl_Drm_Offscreen_Link *link = data;
+
+ link->evas_alive = EINA_FALSE;
+}
+
static void
_offscreen_frame_release(Ecore_Evas_Gl_Drm_Frame *released)
{
Ecore_Evas_Gl_Drm_Offscreen_Frame *frame =
(Ecore_Evas_Gl_Drm_Offscreen_Frame *)released;
+ Ecore_Evas_Gl_Drm_Offscreen_Link *link = frame->link;
frame->engine_release(frame->engine_frame);
free(frame);
+ _offscreen_link_unref(link);
}
static Eina_Bool
@@ -1292,6 +1333,9 @@ _offscreen_frame_dmabuf_get(const Ecore_Evas_Gl_Drm_Frame *exported,
Evas_Engine_GL_Drm_Dmabuf engine_dmabuf;
int i;
+ /* The buffer may be alive, if the Evas is: the canvas was freed */
+ if (!frame->link->ee) return EINA_FALSE;
+
if (!frame->engine_dmabuf_get(frame->engine_frame, &engine_dmabuf))
return EINA_FALSE;
@@ -1310,15 +1354,93 @@ _offscreen_frame_dmabuf_get(const Ecore_Evas_Gl_Drm_Frame *exported,
return EINA_TRUE;
}
+static int
+_offscreen_buffer_find(const Ecore_Evas_Gl_Drm_Offscreen_Data *odata, uint64_t id)
+{
+ unsigned int i, count;
+
+ if (!odata->buffers_known) return -1;
+
+ count = eina_inarray_count(odata->buffers_known);
+ for (i = 0; i < count; i++)
+ {
+ if (*(uint64_t *)eina_inarray_nth(odata->buffers_known, i) == id)
+ return i;
+ }
+ return -1;
+}
+
+static Eina_Bool
+_offscreen_buffer_know(Ecore_Evas_Gl_Drm_Offscreen_Data *odata, uint64_t id)
+{
+ if (_offscreen_buffer_find(odata, id) >= 0) return EINA_TRUE;
+
+ if (!odata->buffers_known)
+ {
+ odata->buffers_known = eina_inarray_new(sizeof(uint64_t), 8);
+ if (!odata->buffers_known) return EINA_FALSE;
+ }
+
+ return eina_inarray_push(odata->buffers_known, &id) >= 0;
+}
+
+/* The engine tells of every buffer it gave to a frame, to whichever
+ * consumer the frames went to. Only the ones the current consumer got a
+ * frame of are told on. */
+static void
+_offscreen_buffer_free_cb(void *data, uint64_t id)
+{
+ Ecore_Evas_Gl_Drm_Offscreen_Link *link = data;
+ Ecore_Evas_Gl_Drm_Offscreen_Data *odata;
+ int known;
+
+ /* The consumer was told when the canvas was freed */
+ if (!link->ee) return;
+
+ odata = link->ee->engine.data;
+ known = _offscreen_buffer_find(odata, id);
+ if (known < 0) return;
+
+ eina_inarray_remove_at(odata->buffers_known, known);
+ odata->buffer_free_func((void *)odata->frame_data, id);
+}
+
+/* The consumer that goes away is not told of the end of the buffers later:
+ * it is told now, so that it has dropped all it kept for them. */
+static void
+_offscreen_buffers_forget(Ecore_Evas_Gl_Drm_Offscreen_Data *odata)
+{
+ unsigned int count;
+
+ if (!odata->buffers_known) return;
+
+ while ((count = eina_inarray_count(odata->buffers_known)))
+ {
+ uint64_t id = *(uint64_t *)eina_inarray_nth(odata->buffers_known, count - 1);
+
+ eina_inarray_pop(odata->buffers_known);
+ odata->buffer_free_func((void *)odata->frame_data, id);
+ }
+}
+
static void
_offscreen_frame_cb(void *data, Evas_Engine_GL_Drm_Frame *engine_frame,
const Eina_Rectangle *damage, unsigned int damage_count)
{
- Ecore_Evas *ee = data;
- Ecore_Evas_Gl_Drm_Offscreen_Data *odata = ee->engine.data;
+ Ecore_Evas_Gl_Drm_Offscreen_Link *link = data;
+ Ecore_Evas *ee = link->ee;
+ Ecore_Evas_Gl_Drm_Offscreen_Data *odata;
Ecore_Evas_Gl_Drm_Offscreen_Frame *frame;
Eina_Rectangle whole;
+ if (!ee)
+ {
+ link->engine_release(engine_frame);
+ return;
+ }
+
+ odata = ee->engine.data;
+
/* Before anything can fail: fn_prepare must see the size of the surface
* that drew this frame. */
odata->frame_w = engine_frame->w;
@@ -1333,6 +1455,17 @@ _offscreen_frame_cb(void *data, Evas_Engine_GL_Drm_Frame *engine_frame,
return;
}
+ if ((odata->buffer_free_func) && (!_offscreen_buffer_know(odata, engine_frame->id)))
+ {
+ ERR("Could not keep the buffer of a frame");
+ odata->info->func.frame_release(engine_frame);
+ free(frame);
+ odata->damage_whole = EINA_TRUE;
+ return;
+ }
+
+ frame->link = link;
+ link->refs++;
frame->base.release = _offscreen_frame_release;
frame->base.dmabuf_get = _offscreen_frame_dmabuf_get;
frame->base.buffer_id = engine_frame->id;
@@ -1355,16 +1488,22 @@ _offscreen_frame_cb(void *data, Evas_Engine_GL_Drm_Frame *engine_frame,
}
static void
-_offscreen_frame_callback_set(Ecore_Evas *ee, Ecore_Evas_Gl_Drm_Frame_Cb func,
- const void *data)
+_offscreen_frame_callbacks_set(Ecore_Evas *ee,
+ Ecore_Evas_Gl_Drm_Frame_Cb frame_func,
+ Ecore_Evas_Gl_Drm_Buffer_Free_Cb buffer_free_func,
+ const void *data)
{
Ecore_Evas_Gl_Drm_Offscreen_Data *odata = ee->engine.data;
- odata->frame_func = func;
+ _offscreen_buffers_forget(odata);
+
+ odata->frame_func = frame_func;
+ odata->buffer_free_func = buffer_free_func;
odata->frame_data = data;
odata->damage_whole = EINA_TRUE;
- odata->info->frame.func = func ? _offscreen_frame_cb : NULL;
- odata->info->frame.data = ""
+ odata->info->frame.func = frame_func ? _offscreen_frame_cb : NULL;
+ odata->info->frame.buffer_free = buffer_free_func ? _offscreen_buffer_free_cb : NULL;
+ odata->info->frame.data = ""
}
/* Renders only when the engine has a buffer to draw in, so that no render
@@ -1387,7 +1526,24 @@ _offscreen_prepare(Ecore_Evas *ee)
static void
_offscreen_free(Ecore_Evas *ee)
{
- free(ee->engine.data);
+ Ecore_Evas_Gl_Drm_Offscreen_Data *odata = ee->engine.data;
+
+ /* The Evas told of the buffers it destroyed, as it was freed with the
+ * canvas; if something still holds it, the buffers are told of now. */
+ odata->link->ee = NULL;
+ _offscreen_buffers_forget(odata);
+ if (odata->link->evas_alive)
+ {
+ /* It goes on without the canvas, and nothing is there to tell */
+ efl_event_callback_del(odata->evas, EFL_EVENT_DEL,
+ _offscreen_evas_del_cb, odata->link);
+ odata->info->frame.func = NULL;
+ odata->info->frame.buffer_free = NULL;
+ odata->info->frame.data = ""
+ }
+ _offscreen_link_unref(odata->link);
+ if (odata->buffers_known) eina_inarray_free(odata->buffers_known);
+ free(odata);
ee->engine.data = ""
_offscreen_node_unref();
}
@@ -1472,6 +1628,7 @@ ecore_evas_gl_drm_offscreen_new_internal(const char *render_node, int w, int h)
Ecore_Evas_Interface_Drm *iface;
Ecore_Evas_Gl_Drm_Offscreen_Data *odata;
Evas_Engine_Info_GL_Drm *einfo;
+ Ecore_Evas_Gl_Drm_Offscreen_Link *link;
int method, fd;
method = evas_render_method_lookup("gl_drm");
@@ -1489,8 +1646,10 @@ ecore_evas_gl_drm_offscreen_new_internal(const char *render_node, int w, int h)
ee = calloc(1, sizeof(Ecore_Evas));
odata = calloc(1, sizeof(Ecore_Evas_Gl_Drm_Offscreen_Data));
- if ((!ee) || (!odata))
+ link = calloc(1, sizeof(Ecore_Evas_Gl_Drm_Offscreen_Link));
+ if ((!ee) || (!odata) || (!link))
{
+ free(link);
free(odata);
free(ee);
_offscreen_node_unref();
@@ -1502,12 +1661,15 @@ ecore_evas_gl_drm_offscreen_new_internal(const char *render_node, int w, int h)
ee->driver = "gl_drm";
ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_evas_gl_drm_offscreen_engine_func;
ee->engine.data = ""
+ link->ee = ee;
+ link->refs = 1;
+ odata->link = link;
iface = _ecore_evas_drm_interface_new();
if (!iface) goto eng_err;
- /* 2 has frame_callback_set */
- iface->base.version = 2;
- iface->frame_callback_set = _offscreen_frame_callback_set;
+ /* 3 has the functions of a canvas with no device */
+ iface->base.version = 3;
+ iface->frame_callbacks_set = _offscreen_frame_callbacks_set;
ee->engine.ifaces = eina_list_append(ee->engine.ifaces, iface);
ee->w = ee->req.w = w;
@@ -1523,6 +1685,10 @@ ecore_evas_gl_drm_offscreen_new_internal(const char *render_node, int w, int h)
goto eng_err;
}
+ odata->evas = ee->evas;
+ efl_event_callback_add(ee->evas, EFL_EVENT_DEL, _offscreen_evas_del_cb, link);
+ link->evas_alive = EINA_TRUE;
+
evas_output_method_set(ee->evas, method);
einfo = (Evas_Engine_Info_GL_Drm *)evas_engine_info_get(ee->evas);
@@ -1540,6 +1706,7 @@ ecore_evas_gl_drm_offscreen_new_internal(const char *render_node, int w, int h)
goto eng_err;
}
odata->info = einfo;
+ link->engine_release = einfo->func.frame_release;
_ecore_evas_register(ee);
return ee;
diff --git a/src/tests/ecore/ecore_test_ecore_evas_gl_drm.c b/src/tests/ecore/ecore_test_ecore_evas_gl_drm.c
index 29afa151c9..d0959549c8 100644
--- a/src/tests/ecore/ecore_test_ecore_evas_gl_drm.c
+++ b/src/tests/ecore/ecore_test_ecore_evas_gl_drm.c
@@ -69,6 +69,10 @@ struct _Test_Canvas
Ecore_Evas_Gl_Drm_Frame *held[HELD_MAX];
uint64_t ids[HELD_MAX];
+ uint64_t freed[HELD_MAX];
+ uint64_t other_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;
@@ -76,6 +80,8 @@ struct _Test_Canvas
unsigned int held_count;
unsigned int id_count;
unsigned int frame_count;
+ unsigned int freed_count;
+ unsigned int other_freed_count;
unsigned int damage_count;
unsigned int quit_at;
unsigned int ticks;
@@ -84,6 +90,7 @@ struct _Test_Canvas
int frame_w, frame_h;
Eina_Bool hold : 1;
+ Eina_Bool release_in_buffer_free : 1;
Eina_Bool ticks_change : 1;
Eina_Bool damage_overflow : 1;
Eina_Bool timed_out : 1;
@@ -200,6 +207,50 @@ _frame_cb(void *data, Ecore_Evas *ee, Ecore_Evas_Gl_Drm_Frame *frame,
if (c->frame_count >= c->quit_at) ecore_main_loop_quit();
}
+/* The frames of the buffer that is announced are held, have no dmabuf any
+ * more, and may be released from here. */
+static void
+_buffer_free_cb(void *data, uint64_t id)
+{
+ Test_Canvas *c = data;
+ unsigned int i;
+
+ for (i = 0; i < c->id_count; i++)
+ {
+ if (c->ids[i] == id) break;
+ }
+ ck_assert_msg(i < c->id_count, "buffer %llu was never given",
+ (unsigned long long)id);
+
+ 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;
+
+ for (i = 0; i < c->held_count; i++)
+ {
+ Ecore_Evas_Gl_Drm_Dmabuf dmabuf;
+
+ if (ecore_evas_gl_drm_frame_buffer_id_get(c->held[i]) != id) continue;
+
+ ck_assert(!ecore_evas_gl_drm_frame_dmabuf_get(c->held[i], &dmabuf));
+ if (c->release_in_buffer_free)
+ {
+ ecore_evas_gl_drm_frame_release(c->held[i]);
+ c->held[i--] = c->held[--c->held_count];
+ }
+ }
+}
+
+/* The announcements of another consumer */
+static void
+_buffer_free_other_cb(void *data, uint64_t id)
+{
+ Test_Canvas *c = data;
+
+ ck_assert_uint_lt(c->other_freed_count, HELD_MAX);
+ c->other_freed[c->other_freed_count++] = id;
+}
+
/* Another callback, for the tests that change it */
static void
_frame_other_cb(void *data, Ecore_Evas *ee, Ecore_Evas_Gl_Drm_Frame *frame,
@@ -339,7 +390,7 @@ _canvas_open_on(Test_Canvas *c, const char *node)
if (!c->ee) return EINA_FALSE;
c->node = strdup(node);
- ecore_evas_gl_drm_frame_callback_set(c->ee, _frame_cb, c);
+ ecore_evas_gl_drm_frame_callbacks_set(c->ee, _frame_cb, _buffer_free_cb, c);
_scene_build(c);
ecore_evas_show(c->ee);
return EINA_TRUE;
@@ -1298,12 +1349,12 @@ EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_callback_unset)
_frames_wait(c, 1);
- ecore_evas_gl_drm_frame_callback_set(c->ee, NULL, NULL);
+ ecore_evas_gl_drm_frame_callbacks_set(c->ee, NULL, NULL, NULL);
/* More frames than buffers: all of them were given back */
_ticks_run(c, TICKS_BLOCKED);
ck_assert_uint_eq(c->frame_count, 1);
- ecore_evas_gl_drm_frame_callback_set(c->ee, _frame_cb, c);
+ ecore_evas_gl_drm_frame_callbacks_set(c->ee, _frame_cb, _buffer_free_cb, c);
_mover_step(c);
_frames_wait(c, 1);
ck_assert_uint_eq(c->frame_count, 2);
@@ -1325,7 +1376,7 @@ EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_other_engine)
ee = ecore_evas_buffer_new(CANVAS_W, CANVAS_H);
fail_if(ee == NULL);
- ecore_evas_gl_drm_frame_callback_set(ee, _frame_cb, NULL);
+ ecore_evas_gl_drm_frame_callbacks_set(ee, _frame_cb, NULL, NULL);
ck_assert_uint_eq(_warnings, 1);
ck_assert_ptr_nonnull(strstr(_last_log, "was not made by"));
@@ -1337,7 +1388,8 @@ EFL_END_TEST
static void
_interface_function_never_called(Ecore_Evas *ee EINA_UNUSED,
- Ecore_Evas_Gl_Drm_Frame_Cb func EINA_UNUSED,
+ Ecore_Evas_Gl_Drm_Frame_Cb frame_func EINA_UNUSED,
+ Ecore_Evas_Gl_Drm_Buffer_Free_Cb buffer_free_func EINA_UNUSED,
const void *data)
{
Eina_Bool *called = (Eina_Bool *)data;
@@ -1363,11 +1415,11 @@ EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_interface_version)
iface = calloc(1, sizeof(Ecore_Evas_Interface_Drm));
ck_assert_ptr_nonnull(iface);
iface->base.name = "drm";
- iface->base.version = 1;
- iface->frame_callback_set = _interface_function_never_called;
+ iface->base.version = 2;
+ iface->frame_callbacks_set = _interface_function_never_called;
ee->engine.ifaces = eina_list_append(ee->engine.ifaces, iface);
- ecore_evas_gl_drm_frame_callback_set(ee, _frame_cb, &called);
+ ecore_evas_gl_drm_frame_callbacks_set(ee, _frame_cb, NULL, &called);
ck_assert(!called);
ck_assert_uint_eq(_warnings, 1);
@@ -1395,7 +1447,7 @@ EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_callback_replaced)
/* A small change is a small damage, or the rest proves nothing */
ck_assert(!_damage_is_all(c));
- ecore_evas_gl_drm_frame_callback_set(c->ee, _frame_other_cb, c);
+ ecore_evas_gl_drm_frame_callbacks_set(c->ee, _frame_other_cb, _buffer_free_cb, c);
_mover_step(c);
_frames_wait(c, 1);
ck_assert_uint_eq(c->other_calls, 1);
@@ -1405,7 +1457,7 @@ EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_callback_replaced)
_frames_wait(c, 1);
ck_assert(!_damage_is_all(c));
- ecore_evas_gl_drm_frame_callback_set(c->ee, _frame_cb, c);
+ ecore_evas_gl_drm_frame_callbacks_set(c->ee, _frame_cb, _buffer_free_cb, c);
_mover_step(c);
_frames_wait(c, 1);
ck_assert(_damage_is_all(c));
@@ -1428,8 +1480,8 @@ EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_callback_unset_with_frames
old = c->held[0];
c->held_count = 0;
- ecore_evas_gl_drm_frame_callback_set(c->ee, NULL, NULL);
- ecore_evas_gl_drm_frame_callback_set(c->ee, _frame_other_cb, c);
+ ecore_evas_gl_drm_frame_callbacks_set(c->ee, NULL, NULL, NULL);
+ ecore_evas_gl_drm_frame_callbacks_set(c->ee, _frame_other_cb, _buffer_free_cb, c);
ecore_evas_gl_drm_frame_release(old);
_mover_step(c);
@@ -1468,6 +1520,278 @@ EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_hidden_throttled)
}
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++)
+ {
+ _mover_step(c);
+ _frames_wait(c, 1);
+ }
+ ck_assert_uint_ge(c->held_count, 3);
+ _held_release_all(c);
+ c->hold = EINA_FALSE;
+}
+
+/* Each buffer given is announced once, as the resize destroys it and before
+ * a frame of the new size comes, and the new ones are not announced. */
+EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_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, 3);
+ ck_assert_uint_eq(c->freed_count, 0);
+
+ ecore_evas_resize(c->ee, 160, 120);
+ _frames_wait(c, 1);
+ 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);
+ }
+ ck_assert_uint_eq(c->id_count, delivered + 1);
+ ck_assert_uint_eq(_freed_times(c, c->ids[delivered]), 0);
+
+ ecore_evas_resize(c->ee, 64, 48);
+ _frames_wait(c, 1);
+ ck_assert_uint_eq(c->freed_count, delivered + 1);
+ ck_assert_uint_eq(_freed_times(c, c->ids[delivered]), 1);
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
+/* The canvas that is freed announces what it still has before it returns,
+ * and the callback has no use for the canvas. */
+EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_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, 3);
+ ck_assert_uint_eq(c->freed_count, 0);
+
+ ecore_evas_free(c->ee);
+ c->ee = 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
+
+/* Frames held across the resize and the free: announced while held, with
+ * no dmabuf left, and released from the callback or later. */
+EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_frames_held)
+{
+ Test_Canvas *c = _canvas_new();
+
+ if (!c) return;
+
+ c->hold = EINA_TRUE;
+ _frames_wait(c, 1);
+ _mover_step(c);
+ _frames_wait(c, 1);
+ ck_assert_uint_eq(c->held_count, 2);
+
+ ecore_evas_resize(c->ee, 160, 120);
+ _frames_wait(c, 1);
+ ck_assert_uint_eq(c->freed_count, 2);
+ ck_assert_uint_eq(c->held_count, 3);
+ _held_release_all(c);
+
+ /* Released by the callback itself: not twice, not never */
+ c->release_in_buffer_free = EINA_TRUE;
+ _mover_step(c);
+ _frames_wait(c, 1);
+ _mover_step(c);
+ _frames_wait(c, 1);
+ ck_assert_uint_eq(c->held_count, 2);
+ ecore_evas_resize(c->ee, 64, 48);
+ _frames_wait(c, 1);
+ ck_assert_uint_eq(c->held_count, 1);
+
+ ecore_evas_free(c->ee);
+ c->ee = NULL;
+ ck_assert_uint_eq(c->held_count, 0);
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
+/* The canvas is freed while the frames are held, and they are released
+ * after: the announcement has come, the frame is still valid. */
+EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_then_release)
+{
+ Test_Canvas *c = _canvas_new();
+ unsigned int held;
+
+ if (!c) return;
+
+ c->hold = EINA_TRUE;
+ _frames_wait(c, 1);
+ _mover_step(c);
+ _frames_wait(c, 1);
+ held = c->held_count;
+ ck_assert_uint_eq(held, 2);
+
+ ecore_evas_free(c->ee);
+ c->ee = NULL;
+ ck_assert_uint_eq(c->freed_count, 2);
+ ck_assert_uint_eq(c->held_count, held);
+ _held_release_all(c);
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
+/* Something else holds the Evas, which then outlives the canvas: the
+ * consumer is told of every buffer before ecore_evas_free() returns all the
+ * same, and nothing of the canvas is read when the Evas goes. */
+EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_evas_referenced)
+{
+ Test_Canvas *c = _canvas_new();
+ Evas *evas;
+
+ if (!c) return;
+
+ c->hold = EINA_TRUE;
+ _frames_wait(c, 1);
+ _mover_step(c);
+ _frames_wait(c, 1);
+ ck_assert_uint_eq(c->id_count, 2);
+
+ evas = ecore_evas_get(c->ee);
+ efl_ref(evas);
+ ecore_evas_free(c->ee);
+ c->ee = NULL;
+ ck_assert_uint_eq(c->freed_count, 2);
+
+ /* The frames are the consumer's to release, whenever */
+ _held_release_all(c);
+ efl_unref(evas);
+ ck_assert_uint_eq(c->freed_count, 2);
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
+/* A consumer that replaces the other is not told of what it never got, and
+ * the old one is told at once of what it knew, only once. */
+EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_consumer_replaced)
+{
+ Test_Canvas *c = _canvas_new();
+ unsigned int known, i;
+
+ if (!c) return;
+
+ _buffers_cycle(c);
+ known = c->id_count;
+ ck_assert_uint_ge(known, 3);
+
+ ecore_evas_gl_drm_frame_callbacks_set(c->ee, _frame_other_cb,
+ _buffer_free_other_cb, c);
+ ck_assert_uint_eq(c->freed_count, known);
+ for (i = 0; i < known; i++)
+ {
+ ck_assert_uint_eq(_freed_times(c, c->ids[i]), 1);
+ }
+ ck_assert_uint_eq(c->other_freed_count, 0);
+
+ /* One frame is one buffer for the new consumer, and the end of the
+ * others is nobody's business */
+ _mover_step(c);
+ _frames_wait(c, 1);
+ ecore_evas_resize(c->ee, 160, 120);
+ _frames_wait(c, 1);
+ ck_assert_uint_eq(c->other_freed_count, 1);
+ ck_assert_uint_eq(c->freed_count, known);
+
+ ecore_evas_free(c->ee);
+ c->ee = NULL;
+ ck_assert_uint_eq(c->other_freed_count, 2);
+ ck_assert_uint_eq(c->freed_count, known);
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
+/* With no consumer left, what it knew is told at once, and the buffers are
+ * not announced to anybody until another one gets a frame. */
+EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_consumer_removed)
+{
+ Test_Canvas *c = _canvas_new();
+ unsigned int known;
+
+ if (!c) return;
+
+ _buffers_cycle(c);
+ known = c->id_count;
+
+ ecore_evas_gl_drm_frame_callbacks_set(c->ee, NULL, NULL, NULL);
+ ck_assert_uint_eq(c->freed_count, known);
+
+ ecore_evas_resize(c->ee, 160, 120);
+ _ticks_run(c, 5);
+ ecore_evas_free(c->ee);
+ c->ee = NULL;
+ ck_assert_uint_eq(c->freed_count, known);
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
+/* A consumer that keeps nothing per buffer needs no callback, and the
+ * buffers it gets are never announced. */
+EFL_START_TEST(ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_none_wanted)
+{
+ Test_Canvas *c = _canvas_new();
+
+ if (!c) return;
+
+ ecore_evas_gl_drm_frame_callbacks_set(c->ee, _frame_cb, NULL, c);
+ _buffers_cycle(c);
+ ecore_evas_resize(c->ee, 160, 120);
+ _frames_wait(c, 1);
+ ecore_evas_free(c->ee);
+ c->ee = NULL;
+ ck_assert_uint_eq(c->freed_count, 0);
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
void
ecore_test_ecore_evas_gl_drm(TCase *tc)
{
@@ -1494,6 +1818,14 @@ ecore_test_ecore_evas_gl_drm(TCase *tc)
tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_callback_replaced);
tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_callback_unset_with_frames_held);
tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_hidden_throttled);
+ tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_resize);
+ tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_canvas_free);
+ tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_frames_held);
+ tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_then_release);
+ tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_evas_referenced);
+ tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_consumer_replaced);
+ tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_consumer_removed);
+ tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_buffer_free_none_wanted);
tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_dmabuf_layout);
tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_dmabuf_pixels);
tcase_add_test(tc, ecore_test_ecore_evas_gl_drm_offscreen_dmabuf_import);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.