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 6cd275d5dad98a61bed0772402a97426b28b276b
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Dec 2 14:33:27 2026 -0600
ecore_evas: add a canvas on a DRM render node that gives out frames
A compositor with no monitor, such as a remote desktop session, wants
to draw with the GPU and hand the result to an encoder. The gl_drm
engine can draw on a render node with no DRM device and deliver its
frames to a callback, but ecore_evas only built the canvas that opens a
seat, looks for outputs and listens to the input devices, and the
engine header is not installed.
Add ecore_evas_gl_drm_offscreen_new(), the callback that receives the
frames, the call that gives a frame back and the one that exports its
buffer as a dmabuf. Without the export a consumer cannot reach the
pixels, so the two come together. The constructor and the callback
follow the other engines: a symbol looked up in the drm module and a
function of the "drm" interface of the canvas. The canvas has an
engine function table of its own, since the one of the drm canvas is
a single static structure its constructor edits.
The canvas has no vsync, so its ticks come from the ecore_animator
fallback of ecore_evas, which renders it from the main loop with
nothing else to call. As for any engine without tick functions of its
own, ecore_evas then forces the timer source for all the animators of
the process, and does not give it back when the canvas is freed.
The engine skips a render when it has no free buffer, and evas counts
that render as drawn: what changed is lost unless the application
damages the canvas again. The canvas asks the engine first, in
fn_prepare, and does not start a render it would lose. Evas keeps the
damage, and when the main loop is idle after the consumer released a
frame, ecore_evas re-arms the tick by itself. A resize that is waiting
for a render lets it go through, since the new surface has all its
buffers free whatever the consumer holds of the old one.
The node is opened by the canvas and closed after its evas is gone,
and only a DRM render node is accepted. The engine tells nodes apart
by descriptor and takes one node per process, so the canvases of a
process share one descriptor, compared by device number.
The public frame wraps the one of the engine so that it can outlive the
canvas: giving it back, or exporting it, needs nothing else. The
dmabuf structure is public, as Ecore_X_Icon and Evas_Native_Surface
are, rather than one accessor per field to call in turn on a frame that
may be released in between.
Creating the canvas by name is left out. A name selects an engine,
and the engine of this canvas is the existing "gl_drm", which means
the canvas of a device.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
---
src/lib/ecore_evas/Ecore_Evas.h | 233 +++++++++++++
src/lib/ecore_evas/ecore_evas.c | 86 +++++
src/lib/ecore_evas/ecore_evas_drm.h | 13 +
.../ecore_evas/engines/drm/ecore_evas_drm.c | 375 +++++++++++++++++++++
4 files changed, 707 insertions(+)
diff --git a/src/lib/ecore_evas/Ecore_Evas.h b/src/lib/ecore_evas/Ecore_Evas.h
index e66a5edd9c..88cca613c0 100644
--- a/src/lib/ecore_evas/Ecore_Evas.h
+++ b/src/lib/ecore_evas/Ecore_Evas.h
@@ -1674,6 +1674,239 @@ EAPI Ecore_Evas *ecore_evas_drm_new(const char *device, unsigned int parent,
*/
EAPI Ecore_Evas *ecore_evas_gl_drm_new(const char *device, unsigned int parent, int x, int y, int w, int h); /** @since 1.12 */
+#ifdef EFL_BETA_API_SUPPORT
+
+/**
+ * @typedef Ecore_Evas_Gl_Drm_Frame
+ * @brief A finished frame of a canvas made by
+ * 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
+ * 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.
+ *
+ * @since 1.30
+ */
+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 ee The canvas that drew the frame.
+ * @param frame The frame. Give it back with
+ * ecore_evas_gl_drm_frame_release(), now or later.
+ * @param damage What changed since the frame given to this callback before,
+ * in canvas coordinates with the origin at the top left. It covers
+ * the whole canvas for the first frame and after a resize, and may
+ * cover more than what changed. It is only valid during the call.
+ * @param damage_count The number of rectangles in @p damage.
+ *
+ * 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()
+ * @since 1.30
+ */
+typedef void (*Ecore_Evas_Gl_Drm_Frame_Cb)(void *data, Ecore_Evas *ee,
+ Ecore_Evas_Gl_Drm_Frame *frame,
+ const Eina_Rectangle *damage,
+ unsigned int damage_count);
+
+/**
+ * @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.
+ *
+ * @param render_node The DRM node to draw on, such as
+ * <tt>/dev/dri/renderD128</tt>. It is required: no default is
+ * chosen.
+ * @param w The width of the canvas, in pixels, at least 1.
+ * @param h The height of the canvas, in pixels, at least 1.
+ * @return The new canvas, or @c NULL if it could not be made: no node
+ * given, the node cannot be opened, is not a DRM render node (a
+ * primary node, such as <tt>/dev/dri/card0</tt>, is refused) or
+ * cannot be drawn on (software GL is refused), the gl_drm engine
+ * is not available, or a canvas already draws on another node.
+ *
+ * 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
+ * hidden or, as for any canvas, while nothing changed.
+ *
+ * The node is opened here and closed once the canvas is freed. A process
+ * can have several of these canvases on the same node, which they share;
+ * it cannot have canvases on two nodes, and the engine refuses it next to
+ * the canvas of ecore_evas_gl_drm_new().
+ *
+ * The frames are XRGB8888 and their rows run from the top to the bottom.
+ * The canvas has no screen, pointer or rotation: ecore_evas_rotation_set()
+ * and ecore_evas_fullscreen_set() log an error and do nothing, the screen
+ * geometry is the canvas, the screen dpi is not reported,
+ * ecore_evas_pointer_warp() fails and ecore_evas_data_get(ee, "device")
+ * is @c NULL.
+ *
+ * The canvas does not render while the consumer holds as many frames as
+ * 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.
+ *
+ * @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
+ * functions such as one made by ecore_evas_buffer_new(), the process uses
+ * ECORE_ANIMATOR_SOURCE_TIMER for its Ecore_Animator, even if the source
+ * was set to ECORE_ANIMATOR_SOURCE_CUSTOM before, and the source is not
+ * given back when the canvas is freed. A canvas of ecore_evas_drm_new() in
+ * the same process then no longer drives the Ecore_Animator by its vsync,
+ * 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()
+ * @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().
+ *
+ * @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.
+ *
+ * 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.
+ *
+ * @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);
+
+/**
+ * @brief Gives a frame back to the canvas that drew it.
+ *
+ * @param frame The frame. It is invalid after this call.
+ *
+ * It must be called exactly once for each frame given to the callback,
+ * from the main loop, and before ecore_evas_shutdown(). It may be called
+ * from the callback or later, and also after the canvas was freed or
+ * resized, when the buffer of the frame is already gone.
+ *
+ * A render that was held back for want of a buffer starts when the main
+ * loop next goes idle. Call it from a callback of the main loop, a timer,
+ * a job, an event or a file descriptor handler, and not from an Ecore_Idler:
+ * while idlers run the loop does not go idle again, and the render waits
+ * for the next wake up.
+ *
+ * @since 1.30
+ */
+EAPI void ecore_evas_gl_drm_frame_release(Ecore_Evas_Gl_Drm_Frame *frame);
+
+/**
+ * @brief Gets the size of a frame.
+ *
+ * @param frame The frame.
+ * @param w The width in pixels, or @c NULL.
+ * @param h The height in pixels, or @c NULL.
+ *
+ * It is the size of the canvas when the frame was drawn, and stays valid
+ * if the canvas was resized or freed since.
+ *
+ * @since 1.30
+ */
+EAPI void ecore_evas_gl_drm_frame_size_get(const Ecore_Evas_Gl_Drm_Frame *frame, int *w, int *h);
+
+/**
+ * @brief Gets the identifier of the buffer that holds a frame.
+ *
+ * @param frame The 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.
+ *
+ * @since 1.30
+ */
+EAPI uint64_t ecore_evas_gl_drm_frame_buffer_id_get(const Ecore_Evas_Gl_Drm_Frame *frame);
+
+/**
+ * @typedef Ecore_Evas_Gl_Drm_Dmabuf
+ * @brief How the buffer of a frame is laid out as a dmabuf.
+ *
+ * Filled by ecore_evas_gl_drm_frame_dmabuf_get(). Of its @c plane_count
+ * first planes, @c fd, @c stride and @c offset are those of a dmabuf
+ * import, such as EGL_EXT_image_dma_buf_import or
+ * GBM_BO_IMPORT_FD_MODIFIER; the other planes have a @c fd of -1.
+ *
+ * @since 1.30
+ */
+typedef struct _Ecore_Evas_Gl_Drm_Dmabuf Ecore_Evas_Gl_Drm_Dmabuf;
+
+struct _Ecore_Evas_Gl_Drm_Dmabuf
+{
+ uint64_t modifier; /**< The DRM format modifier of every plane. */
+ int fd[4]; /**< The descriptor of each plane. The caller owns them and closes them. */
+ unsigned int stride[4]; /**< The bytes between two rows of each plane. */
+ unsigned int offset[4]; /**< The bytes from the start of the dmabuf to each plane. */
+ unsigned int format; /**< A DRM fourcc. */
+ int w; /**< The width in pixels. */
+ int h; /**< The height in pixels. */
+ unsigned int plane_count; /**< The number of planes. */
+};
+
+/**
+ * @brief Exports the buffer of a frame as a dmabuf.
+ *
+ * @param frame The frame.
+ * @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.
+ *
+ * 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
+ * asked the driver for, and not the invalid modifier gbm reports for a
+ * buffer made without any. An importer can use it as it is.
+ *
+ * Each call makes new descriptors, which the caller closes. They stay
+ * valid after the frame is released and after the canvas is resized or
+ * freed; only what they hold belongs to the frame until it is released,
+ * and the canvas draws in it again after that. Importing is not free, so a
+ * consumer should key what it imports on ecore_evas_gl_drm_frame_buffer_id_get()
+ * and export a buffer once, not for every frame.
+ *
+ * The GPU may still be drawing when the frame is given, and no fence goes
+ * with it. A consumer that imports the dmabuf into a GPU API waits by
+ * doing so. A consumer that maps it, with mmap(), brackets every read with
+ * the ioctl @c DMA_BUF_IOCTL_SYNC of <tt>linux/dma-buf.h</tt>, start and end.
+ * A consumer that needs a fence can get one from the dmabuf with the ioctl
+ * @c DMA_BUF_IOCTL_EXPORT_SYNC_FILE (Linux 6.0). If the canvas ever gives
+ * a fence, it will be through a call of its own and not through this
+ * structure.
+ *
+ * @since 1.30
+ */
+EAPI Eina_Bool ecore_evas_gl_drm_frame_dmabuf_get(const Ecore_Evas_Gl_Drm_Frame *frame,
+ Ecore_Evas_Gl_Drm_Dmabuf *dmabuf);
+
+#endif
+
/**
* @brief Creates a new @c Ecore_Evas canvas bound to the Evas
* @b buffer engine
diff --git a/src/lib/ecore_evas/ecore_evas.c b/src/lib/ecore_evas/ecore_evas.c
index 2d173f2933..2bf5b3225a 100644
--- a/src/lib/ecore_evas/ecore_evas.c
+++ b/src/lib/ecore_evas/ecore_evas.c
@@ -30,6 +30,7 @@
#include "Ecore_Evas.h"
#include "ecore_evas_private.h"
#include "ecore_evas_x11.h"
+#include "ecore_evas_drm.h"
#include "ecore_evas_wayland.h"
#include "ecore_evas_cocoa.h"
#include "ecore_evas_extn.h"
@@ -4635,6 +4636,91 @@ ecore_evas_gl_drm_new(const char *disp_name, unsigned int parent,
}
+EAPI Ecore_Evas *
+ecore_evas_gl_drm_offscreen_new(const char *render_node, int w, int h)
+{
+ Ecore_Evas *ee;
+ Ecore_Evas *(*new)(const char *, int, int);
+ Eina_Module *m;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(render_node, NULL);
+
+ m = _ecore_evas_engine_load("drm");
+ EINA_SAFETY_ON_NULL_RETURN_VAL(m, NULL);
+
+ new = eina_module_symbol_get(m, "ecore_evas_gl_drm_offscreen_new_internal");
+ EINA_SAFETY_ON_NULL_RETURN_VAL(new, NULL);
+
+ ee = new(render_node, w, h);
+ if (!ee) return NULL;
+
+ if (!_ecore_evas_cursors_init(ee))
+ {
+ ecore_evas_free(ee);
+ return NULL;
+ }
+ return ee;
+}
+
+EAPI void
+ecore_evas_gl_drm_frame_callback_set(Ecore_Evas *ee,
+ Ecore_Evas_Gl_Drm_Frame_Cb 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))
+ {
+ 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);
+}
+
+EAPI void
+ecore_evas_gl_drm_frame_release(Ecore_Evas_Gl_Drm_Frame *frame)
+{
+ EINA_SAFETY_ON_NULL_RETURN(frame);
+
+ frame->release(frame);
+}
+
+EAPI void
+ecore_evas_gl_drm_frame_size_get(const Ecore_Evas_Gl_Drm_Frame *frame, int *w, int *h)
+{
+ if (w) *w = 0;
+ if (h) *h = 0;
+ EINA_SAFETY_ON_NULL_RETURN(frame);
+
+ if (w) *w = frame->w;
+ if (h) *h = frame->h;
+}
+
+EAPI uint64_t
+ecore_evas_gl_drm_frame_buffer_id_get(const Ecore_Evas_Gl_Drm_Frame *frame)
+{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(frame, 0);
+
+ return frame->buffer_id;
+}
+
+EAPI Eina_Bool
+ecore_evas_gl_drm_frame_dmabuf_get(const Ecore_Evas_Gl_Drm_Frame *frame,
+ Ecore_Evas_Gl_Drm_Dmabuf *dmabuf)
+{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(frame, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(dmabuf, EINA_FALSE);
+
+ return frame->dmabuf_get(frame, dmabuf);
+}
+
EAPI Ecore_Evas *
ecore_evas_software_gdi_new(Ecore_Win32_Window *parent,
int x,
diff --git a/src/lib/ecore_evas/ecore_evas_drm.h b/src/lib/ecore_evas/ecore_evas_drm.h
index 63ef7bed0c..157347873d 100644
--- a/src/lib/ecore_evas/ecore_evas_drm.h
+++ b/src/lib/ecore_evas/ecore_evas_drm.h
@@ -3,12 +3,25 @@
#define EFL_INTERNAL_UNSTABLE
# include "Evas_Internal.h"
+# include "Ecore_Evas.h"
typedef struct _Ecore_Evas_Interface_Drm Ecore_Evas_Interface_Drm;
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);
+};
+
+/* What the library reads of a frame; the module that made it puts it
+ * first in what it allocates. */
+struct _Ecore_Evas_Gl_Drm_Frame
+{
+ void (*release)(Ecore_Evas_Gl_Drm_Frame *frame);
+ Eina_Bool (*dmabuf_get)(const Ecore_Evas_Gl_Drm_Frame *frame, Ecore_Evas_Gl_Drm_Dmabuf *dmabuf);
+ uint64_t buffer_id;
+ int w, h;
};
#endif
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 a1ece1305a..b5517c8a0f 100644
--- a/src/modules/ecore_evas/engines/drm/ecore_evas_drm.c
+++ b/src/modules/ecore_evas/engines/drm/ecore_evas_drm.c
@@ -22,6 +22,10 @@
#ifdef BUILD_ECORE_EVAS_GL_DRM
# include <Evas_Engine_GL_Drm.h>
# include <dlfcn.h>
+# include <errno.h>
+# include <fcntl.h>
+# include <sys/stat.h>
+# include <unistd.h>
#endif
#ifdef _WIN32
@@ -1175,3 +1179,374 @@ ecore_evas_gl_drm_new_internal(const char *device, unsigned int parent EINA_UNUS
return _ecore_evas_new_internal(device, x, y, w, h, EINA_TRUE);
}
#endif
+
+#ifdef BUILD_ECORE_EVAS_GL_DRM
+
+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;
+
+struct _Ecore_Evas_Gl_Drm_Offscreen_Data
+{
+ Evas_Engine_Info_GL_Drm *info;
+ Ecore_Evas_Gl_Drm_Frame_Cb frame_func;
+ const void *frame_data;
+ /* 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
+ * callback in use: it covers the canvas */
+ Eina_Bool damage_whole : 1;
+};
+
+/* Made for each frame the engine delivers, and freed when the consumer
+ * gives it back, whether or not the canvas is still there. */
+struct _Ecore_Evas_Gl_Drm_Offscreen_Frame
+{
+ Ecore_Evas_Gl_Drm_Frame base;
+ 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);
+ Eina_Bool (*engine_dmabuf_get)(const Evas_Engine_GL_Drm_Frame *frame,
+ Evas_Engine_GL_Drm_Dmabuf *dmabuf);
+};
+
+/* The engine draws on one node per process, and tells nodes apart by
+ * descriptor: the canvases share one descriptor for the node. */
+static struct
+{
+ dev_t rdev;
+ int fd;
+ unsigned int refs;
+} _offscreen_node = { 0, -1, 0 };
+
+static int
+_offscreen_node_ref(const char *path)
+{
+ struct stat st;
+ int fd;
+
+ fd = open(path, O_RDWR | O_CLOEXEC);
+ if (fd < 0)
+ {
+ ERR("Could not open %s: %s", path, strerror(errno));
+ return -1;
+ }
+
+ if (fstat(fd, &st) < 0)
+ {
+ ERR("Could not stat %s: %s", path, strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ if ((!S_ISCHR(st.st_mode)) || (drmGetNodeTypeFromFd(fd) != DRM_NODE_RENDER))
+ {
+ ERR("%s is not a DRM render node", path);
+ close(fd);
+ return -1;
+ }
+
+ if (!_offscreen_node.refs)
+ {
+ _offscreen_node.rdev = st.st_rdev;
+ _offscreen_node.fd = fd;
+ }
+ else
+ {
+ close(fd);
+ if (st.st_rdev != _offscreen_node.rdev)
+ {
+ ERR("A canvas already draws on another node than %s", path);
+ return -1;
+ }
+ }
+
+ _offscreen_node.refs++;
+ return _offscreen_node.fd;
+}
+
+static void
+_offscreen_node_unref(void)
+{
+ if (--_offscreen_node.refs) return;
+
+ close(_offscreen_node.fd);
+ _offscreen_node.fd = -1;
+}
+
+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;
+
+ frame->engine_release(frame->engine_frame);
+ free(frame);
+}
+
+static Eina_Bool
+_offscreen_frame_dmabuf_get(const Ecore_Evas_Gl_Drm_Frame *exported,
+ Ecore_Evas_Gl_Drm_Dmabuf *dmabuf)
+{
+ const Ecore_Evas_Gl_Drm_Offscreen_Frame *frame =
+ (const Ecore_Evas_Gl_Drm_Offscreen_Frame *)exported;
+ Evas_Engine_GL_Drm_Dmabuf engine_dmabuf;
+ int i;
+
+ if (!frame->engine_dmabuf_get(frame->engine_frame, &engine_dmabuf))
+ return EINA_FALSE;
+
+ dmabuf->modifier = engine_dmabuf.modifier;
+ dmabuf->format = engine_dmabuf.format;
+ dmabuf->w = engine_dmabuf.w;
+ dmabuf->h = engine_dmabuf.h;
+ dmabuf->plane_count = engine_dmabuf.plane_count;
+ for (i = 0; i < 4; i++)
+ {
+ dmabuf->fd[i] = engine_dmabuf.fd[i];
+ dmabuf->stride[i] = engine_dmabuf.stride[i];
+ dmabuf->offset[i] = engine_dmabuf.offset[i];
+ }
+
+ return EINA_TRUE;
+}
+
+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_Frame *frame;
+ Eina_Rectangle whole;
+
+ /* Before anything can fail: fn_prepare must see the size of the surface
+ * that drew this frame. */
+ odata->frame_w = engine_frame->w;
+ odata->frame_h = engine_frame->h;
+
+ frame = malloc(sizeof(Ecore_Evas_Gl_Drm_Offscreen_Frame));
+ if (!frame)
+ {
+ ERR("Could not allocate a frame");
+ odata->info->func.frame_release(engine_frame);
+ odata->damage_whole = EINA_TRUE;
+ return;
+ }
+
+ frame->base.release = _offscreen_frame_release;
+ frame->base.dmabuf_get = _offscreen_frame_dmabuf_get;
+ frame->base.buffer_id = engine_frame->id;
+ frame->base.w = engine_frame->w;
+ frame->base.h = engine_frame->h;
+ frame->engine_frame = engine_frame;
+ frame->engine_release = odata->info->func.frame_release;
+ frame->engine_dmabuf_get = odata->info->func.frame_dmabuf_get;
+
+ if (odata->damage_whole)
+ {
+ EINA_RECTANGLE_SET(&whole, 0, 0, engine_frame->w, engine_frame->h);
+ damage = &whole;
+ damage_count = 1;
+ odata->damage_whole = EINA_FALSE;
+ }
+
+ odata->frame_func((void *)odata->frame_data, ee, &frame->base,
+ damage, damage_count);
+}
+
+static void
+_offscreen_frame_callback_set(Ecore_Evas *ee, Ecore_Evas_Gl_Drm_Frame_Cb func,
+ const void *data)
+{
+ Ecore_Evas_Gl_Drm_Offscreen_Data *odata = ee->engine.data;
+
+ odata->frame_func = func;
+ odata->frame_data = data;
+ odata->damage_whole = EINA_TRUE;
+ odata->info->frame.func = func ? _offscreen_frame_cb : NULL;
+ odata->info->frame.data = ""
+}
+
+/* Renders only when the engine has a buffer to draw in, so that no render
+ * is skipped and what changed meanwhile stays to be drawn: evas keeps the
+ * damage of a render that did not start, and renders again when the main
+ * loop is idle after the consumer released a frame. */
+static Eina_Bool
+_offscreen_prepare(Ecore_Evas *ee)
+{
+ Ecore_Evas_Gl_Drm_Offscreen_Data *odata = ee->engine.data;
+
+ /* The engine learns of a resize with the render that follows it, and the
+ * surface it makes then has all its buffers free, whatever the consumer
+ * holds of the old one. */
+ if ((ee->w != odata->frame_w) || (ee->h != odata->frame_h)) return EINA_TRUE;
+
+ return odata->info->func.frame_buffer_available(odata->info);
+}
+
+static void
+_offscreen_free(Ecore_Evas *ee)
+{
+ free(ee->engine.data);
+ ee->engine.data = ""
+ _offscreen_node_unref();
+}
+
+static void
+_offscreen_show(Ecore_Evas *ee)
+{
+ if (ee->visible) return;
+
+ ee->should_be_visible = 1;
+ ee->visible = 1;
+ evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
+ if (ee->func.fn_show) ee->func.fn_show(ee);
+}
+
+static void
+_offscreen_hide(Ecore_Evas *ee)
+{
+ if (!ee->visible) return;
+
+ ee->visible = 0;
+ ee->should_be_visible = 0;
+ if (ee->func.fn_hide) ee->func.fn_hide(ee);
+}
+
+static void
+_offscreen_rotation_set(Ecore_Evas *ee, int rotation, int resize EINA_UNUSED)
+{
+ if (ee->rotation == rotation) return;
+
+ ERR("A canvas with no DRM device cannot be rotated");
+}
+
+static void
+_offscreen_fullscreen_set(Ecore_Evas *ee EINA_UNUSED, Eina_Bool on)
+{
+ if (on) ERR("A canvas with no screen cannot be fullscreen");
+}
+
+static void
+_offscreen_screen_geometry_get(const Ecore_Evas *ee, int *x, int *y, int *w, int *h)
+{
+ if (x) *x = ee->x;
+ if (y) *y = ee->y;
+ if (w) *w = ee->w;
+ if (h) *h = ee->h;
+}
+
+static void
+_offscreen_pointer_xy_get(const Ecore_Evas *ee, Evas_Coord *x, Evas_Coord *y)
+{
+ evas_pointer_canvas_xy_get(ee->evas, x, y);
+}
+
+static const Ecore_Evas_Engine_Func _ecore_evas_gl_drm_offscreen_engine_func =
+{
+ .fn_free = _offscreen_free,
+ .fn_move = _drm_move,
+ .fn_resize = _drm_resize,
+ .fn_move_resize = _drm_move_resize,
+ .fn_rotation_set = _offscreen_rotation_set,
+ .fn_show = _offscreen_show,
+ .fn_hide = _offscreen_hide,
+ .fn_title_set = _drm_title_set,
+ .fn_name_class_set = _drm_name_class_set,
+ .fn_size_min_set = _drm_size_min_set,
+ .fn_size_max_set = _drm_size_max_set,
+ .fn_size_base_set = _drm_size_base_set,
+ .fn_size_step_set = _drm_size_step_set,
+ .fn_fullscreen_set = _offscreen_fullscreen_set,
+ .fn_ignore_events_set = _drm_ignore_events_set,
+ .fn_aspect_set = _drm_aspect_set,
+ .fn_screen_geometry_get = _offscreen_screen_geometry_get,
+ .fn_pointer_xy_get = _offscreen_pointer_xy_get,
+ .fn_prepare = _offscreen_prepare,
+};
+
+EMODAPI Ecore_Evas *
+ecore_evas_gl_drm_offscreen_new_internal(const char *render_node, int w, int h)
+{
+ Ecore_Evas *ee;
+ Ecore_Evas_Interface_Drm *iface;
+ Ecore_Evas_Gl_Drm_Offscreen_Data *odata;
+ Evas_Engine_Info_GL_Drm *einfo;
+ int method, fd;
+
+ method = evas_render_method_lookup("gl_drm");
+ if (!method)
+ {
+ ERR("Evas engine 'gl_drm' is unavailable");
+ return NULL;
+ }
+
+ if (w < 1) w = 1;
+ if (h < 1) h = 1;
+
+ fd = _offscreen_node_ref(render_node);
+ if (fd < 0) return NULL;
+
+ ee = calloc(1, sizeof(Ecore_Evas));
+ odata = calloc(1, sizeof(Ecore_Evas_Gl_Drm_Offscreen_Data));
+ if ((!ee) || (!odata))
+ {
+ free(odata);
+ free(ee);
+ _offscreen_node_unref();
+ return NULL;
+ }
+
+ ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
+
+ ee->driver = "gl_drm";
+ ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_evas_gl_drm_offscreen_engine_func;
+ ee->engine.data = ""
+
+ 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;
+ ee->engine.ifaces = eina_list_append(ee->engine.ifaces, iface);
+
+ ee->w = ee->req.w = w;
+ ee->h = ee->req.h = h;
+
+ ee->prop.max.w = 32767;
+ ee->prop.max.h = 32767;
+ ee->prop.layer = 4;
+
+ if (!ecore_evas_evas_new(ee, w, h))
+ {
+ ERR("Can not create a Canvas.");
+ goto eng_err;
+ }
+
+ evas_output_method_set(ee->evas, method);
+
+ einfo = (Evas_Engine_Info_GL_Drm *)evas_engine_info_get(ee->evas);
+ if (!einfo)
+ {
+ ERR("evas_engine_info_get() for engine '%s' failed", ee->driver);
+ goto eng_err;
+ }
+
+ einfo->info.fd = fd;
+ einfo->info.format = DRM_FORMAT_XRGB8888;
+ if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo))
+ {
+ ERR("evas_engine_info_set() for engine '%s' failed", ee->driver);
+ goto eng_err;
+ }
+ odata->info = einfo;
+
+ _ecore_evas_register(ee);
+ return ee;
+
+eng_err:
+ ecore_evas_free(ee);
+ return NULL;
+}
+
+#endif
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.