evas/drm: Make use of ecore_drm for opening DRM device

We use this functionality already from ecore_drm. The evas version does
not even use udev to acquire the device which means we could not support
hotplugging. The only missing feature was the capability check for
DUMB_BUFFER which I added to ecore_drm now.

This is the second iteration of this patch. Thsi time also taking expedite
runs of he evas drm engine in account.
This commit is contained in:
Stefan Schmidt 2014-07-10 10:05:59 +02:00
parent b9da47eccf
commit 18989020d7
4 changed files with 46 additions and 106 deletions

View File

@ -1225,9 +1225,11 @@ modules_evas_engines_drm_module_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
-I$(top_srcdir)/src/lib/evas/cserve2 \
-I$(top_srcdir)/src/modules/evas/engines/drm \
@EVAS_CFLAGS@ \
@ECORE_DRM_CFLAGS@ \
@evas_engine_drm_cflags@
modules_evas_engines_drm_module_la_LIBADD = \
@USE_EVAS_LIBS@ \
@ECORE_DRM_LIBS@ \
@evas_engine_drm_libs@
modules_evas_engines_drm_module_la_DEPENDENCIES = @USE_EVAS_INTERNAL_LIBS@
modules_evas_engines_drm_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@

View File

@ -7,85 +7,6 @@
* pass any 'user data' to the signal handlers :( */
static Evas_Engine_Info_Drm *siginfo;
static char *
_evas_drm_card_driver_get(const char *dev)
{
struct stat st;
int maj, min;
char *path, path_link[PATH_MAX + 1] = "";
char *drv;
if (stat(dev, &st) < 0) return NULL;
if (!S_ISCHR(st.st_mode)) return NULL;
maj = major(st.st_rdev);
min = minor(st.st_rdev);
asprintf(&path, "/sys/dev/char/%d:%d/device/driver", maj, min);
if (readlink(path, path_link, sizeof(path_link) - 1) < 0)
{
free(path);
return NULL;
}
free(path);
if (!(drv = strrchr(path_link, '/'))) return NULL;
return strdup(drv + strlen("/"));
}
static int
_evas_drm_card_open(int card)
{
char dev[32], *driver;
int fd = -1;
uint64_t dumb;
sprintf(dev, DRM_DEV_NAME, DRM_DIR_NAME, card);
driver = _evas_drm_card_driver_get(dev);
DBG("Drm Device Driver: %s", driver);
if ((fd = drmOpen(driver, NULL)) < 0)
{
CRI("Could not open drm device %s: %m", dev);
return -1;
}
/* if ((fd = open(dev, (O_RDWR | O_CLOEXEC))) < 0) */
/* { */
/* CRI("Could not open drm device %s: %m", dev); */
/* return -1; */
/* } */
/* drmVersionPtr ver; */
/* if ((ver = drmGetVersion(fd))) */
/* { */
/* DBG("Drm Driver Name: %s", ver->name); */
/* drmFreeVersion(ver); */
/* } */
/* check for dumb buffer support
*
* NB: This checks that we can at least support software rendering */
if ((drmGetCap(fd, DRM_CAP_DUMB_BUFFER, &dumb) < 0) || (!dumb))
{
CRI("Drm Device %s does not support software rendering", dev);
/* close the card */
close(fd);
/* return failure */
return -1;
}
DBG("Opened Drm Card %s: %d", dev, fd);
/* return opened card */
return fd;
}
static int
_evas_drm_tty_open(Evas_Engine_Info_Drm *info)
{
@ -387,26 +308,15 @@ _evas_drm_outbuf_planes_setup(Outbuf *ob, drmModePlaneResPtr pres)
return EINA_TRUE;
}
Eina_Bool
evas_drm_init(Evas_Engine_Info_Drm *info, int card)
Eina_Bool
evas_drm_init(Evas_Engine_Info_Drm *info)
{
/* check for valid engine info */
if (!info) return EINA_FALSE;
setvbuf(stdout, NULL, _IONBF, 0);
/* check if we already opened the card */
if (info->info.fd < 0)
{
/* try to open the drm card */
if ((info->info.fd = _evas_drm_card_open(card)) < 0)
return EINA_FALSE;
/* set flag to indicate that evas opened the card and we should
* be the one to close it */
info->info.own_fd = EINA_TRUE;
}
/* check if we already opened the tty */
if (info->info.tty < 0)
{
@ -431,8 +341,6 @@ evas_drm_init(Evas_Engine_Info_Drm *info, int card)
if ((info->info.tty >= 0) && (info->info.own_tty))
close(info->info.tty);
/* FIXME: Close card also ?? */
return EINA_FALSE;
}
@ -452,13 +360,6 @@ evas_drm_shutdown(Evas_Engine_Info_Drm *info)
info->info.tty = -1;
}
/* check if we already opened the card. if so, close it */
if ((info->info.fd >= 0) && (info->info.own_fd))
{
close(info->info.fd);
info->info.fd = -1;
}
return EINA_TRUE;
}

View File

@ -1,7 +1,9 @@
#include "evas_engine.h"
#include <Ecore_Drm.h>
/* local structures */
typedef struct _Render_Engine Render_Engine;
static Ecore_Drm_Device *drm_dev = NULL;
struct _Render_Engine
{
@ -29,8 +31,25 @@ _output_setup(Evas_Engine_Info_Drm *info, int w, int h)
/* if we have no drm device, get one */
if (info->info.fd < 0)
{
/* try to init drm (this includes openening the card & tty) */
if (!evas_drm_init(info, 0))
if (!ecore_drm_init())
return NULL;
/* try getting the default drm device */
if (!(drm_dev = ecore_drm_device_find(NULL, NULL)))
goto on_error;
/* check if we already opened the drm device with ecore_evas */
if (info->info.fd < 0)
{
/* try to open the drm ourselfs (most likely because we get called from expedite) */
if (!ecore_drm_device_open(drm_dev))
goto on_error;
info->info.own_fd = EINA_TRUE;
info->info.fd = ecore_drm_device_fd_get(drm_dev);
}
/* try to init drm (this includes openening tty) */
/* FIXME replace with ecore_drm_tty */
if (!evas_drm_init(info))
goto on_error;
}
@ -60,7 +79,16 @@ _output_setup(Evas_Engine_Info_Drm *info, int w, int h)
on_error:
if (re) evas_render_engine_software_generic_clean(&re->generic);
/* shutdown drm card & tty */
/* check if we already opened the card. if so, close it */
if ((info->info.fd >= 0) && (info->info.own_fd))
{
ecore_drm_device_close(drm_dev);
info->info.fd = -1;
ecore_drm_device_free(drm_dev);
}
/* shutdown tty */
/* FIXME use ecore_drm_tty */
evas_drm_shutdown(info);
free(re);
@ -170,6 +198,15 @@ eng_output_free(void *data)
{
Render_Engine *re = data;
/* check if we already opened the card. if so, close it */
if ((re->info->info.fd >= 0) && (re->info->info.own_fd))
{
ecore_drm_device_close(drm_dev);
re->info->info.fd = -1;
ecore_drm_device_free(drm_dev);
}
/* FIXME use ecore_drm_tty */
evas_drm_shutdown(re->info);
evas_render_engine_software_generic_clean(&re->generic);
free(re);

View File

@ -128,7 +128,7 @@ void evas_outbuf_update_region_push(Outbuf *ob, RGBA_Image *update, int x, int y
void evas_outbuf_update_region_free(Outbuf *ob, RGBA_Image *update);
void evas_outbuf_flush(Outbuf *ob, Tilebuf_Rect *rects, Evas_Render_Mode render_mode);
Eina_Bool evas_drm_init(Evas_Engine_Info_Drm *info, int card);
Eina_Bool evas_drm_init(Evas_Engine_Info_Drm *info);
Eina_Bool evas_drm_shutdown(Evas_Engine_Info_Drm *info);
Eina_Bool evas_drm_outbuf_setup(Outbuf *ob);