diff --git a/src/lib/ecore_drm2/Ecore_Drm2.h b/src/lib/ecore_drm2/Ecore_Drm2.h index 450f1faa0c..81c3ace6a8 100644 --- a/src/lib/ecore_drm2/Ecore_Drm2.h +++ b/src/lib/ecore_drm2/Ecore_Drm2.h @@ -144,7 +144,7 @@ EAPI int ecore_drm2_shutdown(void); /** * Read and process pending Drm events * - * @param fd drm file descriptor + * @param dev drm device * @param ctx * * @return 0 on success, -1 otherwise @@ -156,7 +156,7 @@ EAPI int ecore_drm2_shutdown(void); * @ingroup Ecore_Drm_Init_Group * @since 1.19 */ -EAPI int ecore_drm2_event_handle(int fd, Ecore_Drm2_Context *drmctx); +EAPI int ecore_drm2_event_handle(Ecore_Drm2_Device *dev, Ecore_Drm2_Context *drmctx); /** * @defgroup Ecore_Drm2_Device_Group Drm device functions @@ -832,7 +832,7 @@ EAPI unsigned int ecore_drm2_output_subpixel_get(const Ecore_Drm2_Output *output /** * Create a new framebuffer object * - * @param fd + * @param dev * @param width * @param height * @param depth @@ -844,9 +844,9 @@ EAPI unsigned int ecore_drm2_output_subpixel_get(const Ecore_Drm2_Output *output * @ingroup Ecore_Drm2_Fb_Group * @since 1.18 */ -EAPI Ecore_Drm2_Fb *ecore_drm2_fb_create(int fd, int width, int height, int depth, int bpp, unsigned int format); +EAPI Ecore_Drm2_Fb *ecore_drm2_fb_create(Ecore_Drm2_Device *dev, int width, int height, int depth, int bpp, unsigned int format); -EAPI Ecore_Drm2_Fb *ecore_drm2_fb_gbm_create(int fd, int width, int height, int depth, int bpp, unsigned int format, unsigned int handle, unsigned int stride, void *bo); +EAPI Ecore_Drm2_Fb *ecore_drm2_fb_gbm_create(Ecore_Drm2_Device *dev, int width, int height, int depth, int bpp, unsigned int format, unsigned int handle, unsigned int stride, void *bo); /** * Get a framebuffer's mmap'd data @@ -971,7 +971,7 @@ EAPI void *ecore_drm2_fb_bo_get(Ecore_Drm2_Fb *fb); /** * Import a dmabuf object as a Framebuffer * - * @param fd + * @param dev * @param width * @param height * @param depth @@ -987,7 +987,7 @@ EAPI void *ecore_drm2_fb_bo_get(Ecore_Drm2_Fb *fb); * @since 1.20 * */ -EAPI Ecore_Drm2_Fb *ecore_drm2_fb_dmabuf_import(int fd, int width, int height, int depth, int bpp, unsigned int format, unsigned int strides[4], int dmabuf_fd[4], int dmabuf_fd_count); +EAPI Ecore_Drm2_Fb *ecore_drm2_fb_dmabuf_import(Ecore_Drm2_Device *dev, int width, int height, int depth, int bpp, unsigned int format, unsigned int strides[4], int dmabuf_fd[4], int dmabuf_fd_count); /** * Discard a framebuffer object @@ -1094,6 +1094,18 @@ EAPI void ecore_drm2_fb_status_handler_set(Ecore_Drm2_Fb *fb, Ecore_Drm2_Fb_Stat */ EAPI Eina_Bool ecore_drm2_output_blanktime_get(Ecore_Drm2_Output *output, int sequence, long *sec, long *usec); +/** + * Get the fd of an Ecore_Drm2_Device + * + * Query the fd of the device. + * + * @param device + * + * @since 1.20 + */ + +EAPI int ecore_drm2_device_fd_get(Ecore_Drm2_Device *device); + # endif #endif diff --git a/src/lib/ecore_drm2/ecore_drm2.c b/src/lib/ecore_drm2/ecore_drm2.c index 526ea4a523..a4ab72042d 100644 --- a/src/lib/ecore_drm2/ecore_drm2.c +++ b/src/lib/ecore_drm2/ecore_drm2.c @@ -219,16 +219,16 @@ ecore_drm2_shutdown(void) } EAPI int -ecore_drm2_event_handle(int fd, Ecore_Drm2_Context *drmctx) +ecore_drm2_event_handle(Ecore_Drm2_Device *dev, Ecore_Drm2_Context *drmctx) { drmEventContext ctx; - EINA_SAFETY_ON_TRUE_RETURN_VAL((fd < 0), -1); + EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1); memset(&ctx, 0, sizeof(ctx)); ctx.version = 2; ctx.page_flip_handler = drmctx->page_flip_handler; ctx.vblank_handler = drmctx->vblank_handler; - return sym_drmHandleEvent(fd, &ctx); + return sym_drmHandleEvent(dev->fd, &ctx); } diff --git a/src/lib/ecore_drm2/ecore_drm2_device.c b/src/lib/ecore_drm2/ecore_drm2_device.c index 3545d1a299..aa8917ce4e 100644 --- a/src/lib/ecore_drm2/ecore_drm2_device.c +++ b/src/lib/ecore_drm2/ecore_drm2_device.c @@ -885,6 +885,14 @@ ecore_drm2_device_prefer_shadow(Ecore_Drm2_Device *device) return EINA_FALSE; } +EAPI int +ecore_drm2_device_fd_get(Ecore_Drm2_Device *device) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(device, -1); + + return device->fd; +} + /* prevent crashing with old apps compiled against these functions */ EAPI void ecore_drm2_device_keyboard_cached_context_set(){}; EAPI void ecore_drm2_device_keyboard_cached_keymap_set(){}; diff --git a/src/lib/ecore_drm2/ecore_drm2_fb.c b/src/lib/ecore_drm2/ecore_drm2_fb.c index 3a13c3dbbb..85331aeaa2 100644 --- a/src/lib/ecore_drm2/ecore_drm2_fb.c +++ b/src/lib/ecore_drm2/ecore_drm2_fb.c @@ -16,7 +16,7 @@ _fb2_create(Ecore_Drm2_Fb *fb) } EAPI Ecore_Drm2_Fb * -ecore_drm2_fb_create(int fd, int width, int height, int depth, int bpp, unsigned int format) +ecore_drm2_fb_create(Ecore_Drm2_Device *dev, int width, int height, int depth, int bpp, unsigned int format) { Ecore_Drm2_Fb *fb; struct drm_mode_create_dumb carg; @@ -24,12 +24,12 @@ ecore_drm2_fb_create(int fd, int width, int height, int depth, int bpp, unsigned struct drm_mode_map_dumb marg; int ret; - EINA_SAFETY_ON_TRUE_RETURN_VAL((fd < 0), NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(dev, NULL); fb = calloc(1, sizeof(Ecore_Drm2_Fb)); if (!fb) return NULL; - fb->fd = fd; + fb->fd = dev->fd; fb->w = width; fb->h = height; fb->bpp = bpp; @@ -42,7 +42,7 @@ ecore_drm2_fb_create(int fd, int width, int height, int depth, int bpp, unsigned carg.width = width; carg.height = height; - ret = sym_drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &carg); + ret = sym_drmIoctl(dev->fd, DRM_IOCTL_MODE_CREATE_DUMB, &carg); if (ret) goto err; fb->handles[0] = carg.handle; @@ -52,7 +52,7 @@ ecore_drm2_fb_create(int fd, int width, int height, int depth, int bpp, unsigned if (!_fb2_create(fb)) { ret = - sym_drmModeAddFB(fd, width, height, depth, bpp, + sym_drmModeAddFB(dev->fd, width, height, depth, bpp, fb->strides[0], fb->handles[0], &fb->id); if (ret) { @@ -63,14 +63,14 @@ ecore_drm2_fb_create(int fd, int width, int height, int depth, int bpp, unsigned memset(&marg, 0, sizeof(struct drm_mode_map_dumb)); marg.handle = fb->handles[0]; - ret = sym_drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &marg); + ret = sym_drmIoctl(dev->fd, DRM_IOCTL_MODE_MAP_DUMB, &marg); if (ret) { ERR("Could not map framebuffer: %m"); goto map_err; } - fb->mmap = mmap(NULL, fb->sizes[0], PROT_WRITE, MAP_SHARED, fd, marg.offset); + fb->mmap = mmap(NULL, fb->sizes[0], PROT_WRITE, MAP_SHARED, dev->fd, marg.offset); if (fb->mmap == MAP_FAILED) { ERR("Could not mmap framebuffer memory: %m"); @@ -80,22 +80,22 @@ ecore_drm2_fb_create(int fd, int width, int height, int depth, int bpp, unsigned return fb; map_err: - sym_drmModeRmFB(fd, fb->id); + sym_drmModeRmFB(dev->fd, fb->id); add_err: memset(&darg, 0, sizeof(struct drm_mode_destroy_dumb)); darg.handle = fb->handles[0]; - sym_drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &darg); + sym_drmIoctl(dev->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &darg); err: free(fb); return NULL; } EAPI Ecore_Drm2_Fb * -ecore_drm2_fb_gbm_create(int fd, int width, int height, int depth, int bpp, unsigned int format, unsigned int handle, unsigned int stride, void *bo) +ecore_drm2_fb_gbm_create(Ecore_Drm2_Device *dev, int width, int height, int depth, int bpp, unsigned int format, unsigned int handle, unsigned int stride, void *bo) { Ecore_Drm2_Fb *fb; - EINA_SAFETY_ON_TRUE_RETURN_VAL((fd < 0), NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(dev, NULL); fb = calloc(1, sizeof(Ecore_Drm2_Fb)); if (!fb) return NULL; @@ -103,7 +103,7 @@ ecore_drm2_fb_gbm_create(int fd, int width, int height, int depth, int bpp, unsi fb->gbm = EINA_TRUE; fb->gbm_bo = bo; - fb->fd = fd; + fb->fd = dev->fd; fb->w = width; fb->h = height; fb->bpp = bpp; @@ -116,7 +116,7 @@ ecore_drm2_fb_gbm_create(int fd, int width, int height, int depth, int bpp, unsi if (!_fb2_create(fb)) { - if (sym_drmModeAddFB(fd, width, height, depth, bpp, + if (sym_drmModeAddFB(dev->fd, width, height, depth, bpp, fb->strides[0], fb->handles[0], &fb->id)) { ERR("Could not add framebuffer: %m"); @@ -664,20 +664,22 @@ ecore_drm2_fb_bo_get(Ecore_Drm2_Fb *fb) } EAPI Ecore_Drm2_Fb * -ecore_drm2_fb_dmabuf_import(int fd, int width, int height, int depth, int bpp, unsigned int format, unsigned int strides[4], int dmabuf_fd[4], int dmabuf_fd_count) +ecore_drm2_fb_dmabuf_import(Ecore_Drm2_Device *dev, int width, int height, int depth, int bpp, unsigned int format, unsigned int strides[4], int dmabuf_fd[4], int dmabuf_fd_count) { int i; Ecore_Drm2_Fb *fb; + EINA_SAFETY_ON_NULL_RETURN_VAL(dev, NULL); + fb = calloc(1, sizeof(Ecore_Drm2_Fb)); if (!fb) return NULL; for (i = 0; i < dmabuf_fd_count; i++) - if (sym_drmPrimeFDToHandle(fd, dmabuf_fd[i], &fb->handles[i])) + if (sym_drmPrimeFDToHandle(dev->fd, dmabuf_fd[i], &fb->handles[i])) goto fail; fb->dmabuf = EINA_TRUE; - fb->fd = fd; + fb->fd = dev->fd; fb->w = width; fb->h = height; fb->bpp = bpp; 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 35cd8d83a1..a801445492 100644 --- a/src/modules/ecore_evas/engines/drm/ecore_evas_drm.c +++ b/src/modules/ecore_evas/engines/drm/ecore_evas_drm.c @@ -48,7 +48,6 @@ typedef struct _Ecore_Evas_Engine_Drm_Data { - int fd; int cw, ch; int clockid; int x, y, w, h; @@ -156,8 +155,7 @@ _ecore_evas_drm_init(Ecore_Evas *ee, Ecore_Evas_Engine_Drm_Data *edata, const ch goto dev_err; } - edata->fd = ecore_drm2_device_open(edata->dev); - if (edata->fd < 0) + if (ecore_drm2_device_open(edata->dev) < 0) { ERR("Failed to open device"); goto open_err; @@ -597,7 +595,7 @@ _cb_drm_event(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED) ee = data; edata = ee->engine.data; - ret = ecore_drm2_event_handle(edata->fd, &edata->ctx); + ret = ecore_drm2_event_handle(edata->dev, &edata->ctx); if (ret) { WRN("drmHandleEvent failed to read an event"); @@ -907,7 +905,7 @@ _ecore_evas_new_internal(const char *device, int x, int y, int w, int h, Eina_Bo if ((num) && (!atoi(num))) einfo->info.vsync = EINA_FALSE; - einfo->info.fd = edata->fd; + einfo->info.dev = edata->dev; einfo->info.bpp = edata->bpp; einfo->info.depth = edata->depth; einfo->info.format = edata->format; @@ -925,7 +923,7 @@ _ecore_evas_new_internal(const char *device, int x, int y, int w, int h, Eina_Bo { Evas_Engine_Info_Drm *einfo = tinfo; - einfo->info.fd = edata->fd; + einfo->info.dev = edata->dev; einfo->info.bpp = edata->bpp; einfo->info.depth = edata->depth; einfo->info.format = edata->format; @@ -962,7 +960,8 @@ _ecore_evas_new_internal(const char *device, int x, int y, int w, int h, Eina_Bo edata->ctx.page_flip_handler = _cb_pageflip; edata->hdlr = - ecore_main_fd_handler_add(edata->fd, ECORE_FD_READ, _cb_drm_event, ee, + ecore_main_fd_handler_add(ecore_drm2_device_fd_get(edata->dev), + ECORE_FD_READ, _cb_drm_event, ee, NULL, NULL); canvases = eina_list_append(canvases, ee); diff --git a/src/modules/evas/engines/drm/Evas_Engine_Drm.h b/src/modules/evas/engines/drm/Evas_Engine_Drm.h index 457db625e7..2fcbc466f1 100644 --- a/src/modules/evas/engines/drm/Evas_Engine_Drm.h +++ b/src/modules/evas/engines/drm/Evas_Engine_Drm.h @@ -1,6 +1,8 @@ #ifndef _EVAS_ENGINE_DRM_H # define _EVAS_ENGINE_DRM_H +# include + typedef struct _Evas_Engine_Info_Drm { /* PRIVATE - don't mess with this baby or evas will poke its tongue out */ @@ -9,7 +11,7 @@ typedef struct _Evas_Engine_Info_Drm struct { - int fd; + Ecore_Drm2_Device *dev; int depth, bpp; unsigned int format, rotation; diff --git a/src/modules/evas/engines/drm/evas_engine.c b/src/modules/evas/engines/drm/evas_engine.c index e54b809b5a..7d01407c8f 100644 --- a/src/modules/evas/engines/drm/evas_engine.c +++ b/src/modules/evas/engines/drm/evas_engine.c @@ -5,7 +5,7 @@ typedef struct _Render_Engine { Render_Engine_Software_Generic generic; - int fd; + Ecore_Drm2_Device *dev; } Render_Engine; struct scanout_handle @@ -30,7 +30,7 @@ _render_engine_setup(Evas_Engine_Info_Drm *info, int w, int h) ob = _outbuf_setup(info, w, h); if (!ob) goto err; - re->fd = info->info.fd; + re->dev = info->info.dev; if (!evas_render_engine_software_generic_init(&re->generic, ob, _outbuf_state_get, @@ -120,7 +120,7 @@ eng_output_free(void *engine EINA_UNUSED, void *data) } static Ecore_Drm2_Fb * -drm_import_simple_dmabuf(int fd, struct dmabuf_attributes *attributes) +drm_import_simple_dmabuf(Ecore_Drm2_Device *dev, struct dmabuf_attributes *attributes) { unsigned int stride[4] = { 0 }; int dmabuf_fd[4] = { 0 }; @@ -132,7 +132,7 @@ drm_import_simple_dmabuf(int fd, struct dmabuf_attributes *attributes) dmabuf_fd[i] = attributes->fd[i]; } - return ecore_drm2_fb_dmabuf_import(fd, attributes->width, + return ecore_drm2_fb_dmabuf_import(dev, attributes->width, attributes->height, 32, 32, attributes->format, stride, dmabuf_fd, attributes->n_planes); @@ -197,7 +197,7 @@ eng_image_plane_assign(void *data, void *image, int x, int y) * sticking to this one for now */ if (n->ns.type != EVAS_NATIVE_SURFACE_WL_DMABUF) return NULL; - fb = drm_import_simple_dmabuf(re->fd, &n->ns_data.wl_surface_dmabuf.attr); + fb = drm_import_simple_dmabuf(re->dev, &n->ns_data.wl_surface_dmabuf.attr); if (!fb) return NULL; g = calloc(1, sizeof(struct scanout_handle)); diff --git a/src/modules/evas/engines/drm/evas_engine.h b/src/modules/evas/engines/drm/evas_engine.h index 09f23f9650..a14ce15b07 100644 --- a/src/modules/evas/engines/drm/evas_engine.h +++ b/src/modules/evas/engines/drm/evas_engine.h @@ -52,7 +52,8 @@ typedef struct _Outbuf_Fb struct _Outbuf { - int fd, w, h, bpp, rotation; + Ecore_Drm2_Device *dev; + int w, h, bpp, rotation; unsigned int depth, format; struct diff --git a/src/modules/evas/engines/drm/evas_outbuf.c b/src/modules/evas/engines/drm/evas_outbuf.c index d65b92107d..79f8f6f12c 100644 --- a/src/modules/evas/engines/drm/evas_outbuf.c +++ b/src/modules/evas/engines/drm/evas_outbuf.c @@ -32,7 +32,7 @@ static Eina_Bool _outbuf_fb_create(Outbuf *ob, Outbuf_Fb *ofb) { ofb->fb = - ecore_drm2_fb_create(ob->fd, ob->w, ob->h, + ecore_drm2_fb_create(ob->dev, ob->w, ob->h, ob->depth, ob->bpp, ob->format); if (!ofb->fb) return EINA_FALSE; @@ -66,7 +66,7 @@ _outbuf_setup(Evas_Engine_Info_Drm *info, int w, int h) ob->w = w; ob->h = h; - ob->fd = info->info.fd; + ob->dev = info->info.dev; ob->alpha = info->info.alpha; ob->rotation = info->info.rotation; 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 9fd4b3c0e9..5dd18545a7 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 @@ -18,7 +18,8 @@ struct _Evas_Engine_Info_GL_Drm { struct gbm_device *gbm; - int fd, bpp; + Ecore_Drm2_Device *dev; + int bpp; unsigned int rotation, depth; unsigned int format, flags; diff --git a/src/modules/evas/engines/gl_drm/evas_engine.c b/src/modules/evas/engines/gl_drm/evas_engine.c index f5109a3875..f4dbed8494 100644 --- a/src/modules/evas/engines/gl_drm/evas_engine.c +++ b/src/modules/evas/engines/gl_drm/evas_engine.c @@ -122,9 +122,11 @@ static const EVGL_Interface evgl_funcs = Eina_Bool eng_gbm_init(Evas_Engine_Info_GL_Drm *info) { + int fd; if (!info) return EINA_FALSE; - if (!(info->info.gbm = gbm_create_device(info->info.fd))) + fd = ecore_drm2_device_fd_get(info->info.dev); + if (!(info->info.gbm = gbm_create_device(fd))) { ERR("Coult not create gbm device"); return EINA_FALSE; @@ -600,7 +602,7 @@ _re_winfree(Render_Engine *re) } static Ecore_Drm2_Fb * -drm_import_simple_dmabuf(int fd, struct dmabuf_attributes *attributes) +drm_import_simple_dmabuf(Ecore_Drm2_Device *dev, struct dmabuf_attributes *attributes) { unsigned int stride[4] = { 0 }; int dmabuf_fd[4] = { 0 }; @@ -612,7 +614,7 @@ drm_import_simple_dmabuf(int fd, struct dmabuf_attributes *attributes) dmabuf_fd[i] = attributes->fd[i]; } - return ecore_drm2_fb_dmabuf_import(fd, attributes->width, + return ecore_drm2_fb_dmabuf_import(dev, attributes->width, attributes->height, 32, 32, attributes->format, stride, dmabuf_fd, attributes->n_planes); @@ -805,7 +807,7 @@ eng_image_plane_assign(void *data, void *image, int x, int y) * sticking to this one for now */ if (n->ns.type != EVAS_NATIVE_SURFACE_WL_DMABUF) return NULL; - fb = drm_import_simple_dmabuf(re->fd, &n->ns_data.wl_surface_dmabuf.attr); + fb = drm_import_simple_dmabuf(re->dev, &n->ns_data.wl_surface_dmabuf.attr); if (!fb) return NULL; @@ -958,7 +960,7 @@ eng_setup(void *engine EINA_UNUSED, void *in, unsigned int w, unsigned int h) return NULL; } - re->fd = info->info.fd; + re->dev = info->info.dev; /* try to create new outbuf */ ob = evas_outbuf_new(info, w, h, swap_mode); diff --git a/src/modules/evas/engines/gl_drm/evas_engine.h b/src/modules/evas/engines/gl_drm/evas_engine.h index 107c9387b1..1a888d2e8e 100644 --- a/src/modules/evas/engines/gl_drm/evas_engine.h +++ b/src/modules/evas/engines/gl_drm/evas_engine.h @@ -70,7 +70,7 @@ struct _Render_Engine { Render_Engine_GL_Generic generic; - int fd; + Ecore_Drm2_Device *dev; }; struct _Context_3D @@ -85,7 +85,9 @@ struct _Outbuf Evas_Engine_Info_GL_Drm *info; Evas_Engine_GL_Context *gl_context; - int fd, w, h, bpp; + Ecore_Drm2_Device *dev; + + int w, h, bpp; unsigned int rotation, depth, format; int prev_age; Render_Engine_Swap_Mode swap_mode; diff --git a/src/modules/evas/engines/gl_drm/evas_outbuf.c b/src/modules/evas/engines/gl_drm/evas_outbuf.c index f51444ccb1..0f3ea45e2f 100644 --- a/src/modules/evas/engines/gl_drm/evas_outbuf.c +++ b/src/modules/evas/engines/gl_drm/evas_outbuf.c @@ -75,7 +75,7 @@ _evas_outbuf_fb_get(Outbuf *ob, struct gbm_bo *bo) /* fb->size = fb->stride * fb->h; */ fb = - ecore_drm2_fb_gbm_create(ob->fd, w, h, ob->depth, ob->bpp, + ecore_drm2_fb_gbm_create(ob->dev, w, h, ob->depth, ob->bpp, format, hdl, stride, bo); if (!fb) { @@ -407,7 +407,7 @@ evas_outbuf_new(Evas_Engine_Info_GL_Drm *info, int w, int h, Render_Engine_Swap_ /* ob->vsync = info->info.vsync; */ ob->swap_mode = swap_mode; - ob->fd = info->info.fd; + ob->dev = info->info.dev; ob->bpp = info->info.bpp; ob->format = info->info.format; ob->priv.output = info->info.output;