ecore-drm: Move Eeze Udev Watch to Drm Device

Summary: Move the Eeze udev watch to inside the ecore_drm_device. This
allows us to only create One watch to catch all output changes. No
need for more than one watch (one per output) as was done previously

@fix

Signed-off-by: Chris Michael <cp.michael@samsung.com>
This commit is contained in:
Chris Michael 2015-04-07 11:08:19 -04:00 committed by Stefan Schmidt
parent d815d9bd10
commit c7ced198e6
4 changed files with 39 additions and 53 deletions

View File

@ -24,6 +24,7 @@
#endif // ifdef _MSC_VER #endif // ifdef _MSC_VER
#include <Ecore.h> #include <Ecore.h>
#include <Eeze.h>
typedef enum _Ecore_Drm_Evdev_Capabilities typedef enum _Ecore_Drm_Evdev_Capabilities
{ {
@ -110,6 +111,8 @@ struct _Ecore_Drm_Device
struct xkb_context *xkb_ctx; struct xkb_context *xkb_ctx;
unsigned int window; unsigned int window;
Eeze_Udev_Watch *watch;
}; };
struct _Ecore_Drm_Event_Activate struct _Ecore_Drm_Event_Activate

View File

@ -87,6 +87,15 @@ _ecore_drm_device_cb_idle(void *data)
return ECORE_CALLBACK_RENEW; return ECORE_CALLBACK_RENEW;
} }
static void
_ecore_drm_device_cb_output_event(const char *device EINA_UNUSED, Eeze_Udev_Event event EINA_UNUSED, void *data, Eeze_Udev_Watch *watch EINA_UNUSED)
{
Ecore_Drm_Device *dev;
if (!(dev = data)) return;
_ecore_drm_outputs_update(dev);
}
/** /**
* @defgroup Ecore_Drm_Device_Group Device manipulation functions * @defgroup Ecore_Drm_Device_Group Device manipulation functions
* *
@ -261,6 +270,7 @@ EAPI Eina_Bool
ecore_drm_device_open(Ecore_Drm_Device *dev) ecore_drm_device_open(Ecore_Drm_Device *dev)
{ {
uint64_t caps; uint64_t caps;
int events = 0;
/* check for valid device */ /* check for valid device */
if ((!dev) || (!dev->drm.name)) return EINA_FALSE; if ((!dev) || (!dev->drm.name)) return EINA_FALSE;
@ -299,6 +309,13 @@ ecore_drm_device_open(Ecore_Drm_Device *dev)
return EINA_FALSE; return EINA_FALSE;
} }
events = (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE |
EEZE_UDEV_EVENT_CHANGE);
dev->watch =
eeze_udev_watch_add(EEZE_UDEV_TYPE_DRM, events,
_ecore_drm_device_cb_output_event, NULL);
dev->drm.hdlr = dev->drm.hdlr =
ecore_main_fd_handler_add(dev->drm.fd, ECORE_FD_READ, ecore_main_fd_handler_add(dev->drm.fd, ECORE_FD_READ,
_ecore_drm_device_cb_event, dev, NULL, NULL); _ecore_drm_device_cb_event, dev, NULL, NULL);
@ -326,6 +343,9 @@ ecore_drm_device_close(Ecore_Drm_Device *dev)
/* check for valid device */ /* check for valid device */
if (!dev) return EINA_FALSE; if (!dev) return EINA_FALSE;
/* delete udev watch */
if (dev->watch) eeze_udev_watch_del(dev->watch);
/* close xkb context */ /* close xkb context */
if (dev->xkb_ctx) xkb_context_unref(dev->xkb_ctx); if (dev->xkb_ctx) xkb_context_unref(dev->xkb_ctx);

View File

@ -24,9 +24,6 @@ static const char *conn_types[] =
EAPI int ECORE_DRM_EVENT_OUTPUT = 0; EAPI int ECORE_DRM_EVENT_OUTPUT = 0;
/* local functions */
static void _ecore_drm_output_event(const char *device, Eeze_Udev_Event event EINA_UNUSED, void *data, Eeze_Udev_Watch *watch EINA_UNUSED);
static void static void
_ecore_drm_output_edid_parse_string(const uint8_t *data, char text[]) _ecore_drm_output_edid_parse_string(const uint8_t *data, char text[])
{ {
@ -517,9 +514,6 @@ _ecore_drm_output_free(Ecore_Drm_Output *output)
/* check for valid output */ /* check for valid output */
if (!output) return; if (!output) return;
/* delete any added udev watch */
if (output->watch) eeze_udev_watch_del(output->watch);
/* delete the backlight struct */ /* delete the backlight struct */
if (output->backlight) if (output->backlight)
_ecore_drm_output_backlight_shutdown(output->backlight); _ecore_drm_output_backlight_shutdown(output->backlight);
@ -596,19 +590,18 @@ finish:
_ecore_drm_output_frame_finish(output); _ecore_drm_output_frame_finish(output);
} }
static void void
_ecore_drm_update_outputs(Ecore_Drm_Output *output) _ecore_drm_outputs_update(Ecore_Drm_Device *dev)
{ {
Ecore_Drm_Output *new_output; Ecore_Drm_Output *new_output;
drmModeConnector *connector; drmModeConnector *connector;
drmModeRes *res; drmModeRes *res;
drmModeCrtc *crtc; drmModeCrtc *crtc;
int x = 0, y = 0; int x = 0, y = 0, i;
uint32_t connected = 0, disconnects = 0; uint32_t connected = 0, disconnects = 0;
int i;
Eina_List *l; Eina_List *l;
res = drmModeGetResources(output->drm_fd); res = drmModeGetResources(dev->drm.fd);
if (!res) if (!res)
{ {
ERR("Could not get resources for drm card: %m"); ERR("Could not get resources for drm card: %m");
@ -619,7 +612,7 @@ _ecore_drm_update_outputs(Ecore_Drm_Output *output)
{ {
int connector_id = res->connectors[i]; int connector_id = res->connectors[i];
connector = drmModeGetConnector(output->drm_fd, connector_id); connector = drmModeGetConnector(dev->drm.fd, connector_id);
if (connector == NULL) if (connector == NULL)
continue; continue;
@ -631,28 +624,27 @@ _ecore_drm_update_outputs(Ecore_Drm_Output *output)
connected |= (1 << connector_id); connected |= (1 << connector_id);
if (!(output->dev->conn_allocator & (1 << connector_id))) if (!(dev->conn_allocator & (1 << connector_id)))
{ {
drmModeEncoder *enc; drmModeEncoder *enc;
int events = 0;
if (!(new_output = _ecore_drm_output_create(output->dev, res, connector, x, y))) if (!(new_output = _ecore_drm_output_create(dev, res, connector, x, y)))
{ {
drmModeFreeConnector(connector); drmModeFreeConnector(connector);
_ecore_drm_output_free(new_output); _ecore_drm_output_free(new_output);
continue; continue;
} }
new_output->drm_fd = output->dev->drm.fd; new_output->drm_fd = dev->drm.fd;
if (!(enc = drmModeGetEncoder(new_output->dev->drm.fd, connector->encoder_id))) if (!(enc = drmModeGetEncoder(dev->drm.fd, connector->encoder_id)))
{ {
drmModeFreeConnector(connector); drmModeFreeConnector(connector);
_ecore_drm_output_free(new_output); _ecore_drm_output_free(new_output);
continue; continue;
} }
if (!(crtc = drmModeGetCrtc(new_output->dev->drm.fd, enc->crtc_id))) if (!(crtc = drmModeGetCrtc(dev->drm.fd, enc->crtc_id)))
{ {
drmModeFreeEncoder(enc); drmModeFreeEncoder(enc);
drmModeFreeConnector(connector); drmModeFreeConnector(connector);
@ -665,23 +657,16 @@ _ecore_drm_update_outputs(Ecore_Drm_Output *output)
drmModeFreeCrtc(crtc); drmModeFreeCrtc(crtc);
drmModeFreeEncoder(enc); drmModeFreeEncoder(enc);
events = (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE | dev->outputs = eina_list_append(dev->outputs, new_output);
EEZE_UDEV_EVENT_CHANGE);
new_output->watch =
eeze_udev_watch_add(EEZE_UDEV_TYPE_DRM, events,
_ecore_drm_output_event, new_output);
output->dev->outputs =
eina_list_append(output->dev->outputs, new_output);
} }
drmModeFreeConnector(connector);
drmModeFreeConnector(connector);
} }
disconnects = output->dev->conn_allocator & ~connected; disconnects = dev->conn_allocator & ~connected;
if (disconnects) if (disconnects)
{ {
EINA_LIST_FOREACH(output->dev->outputs, l, new_output) EINA_LIST_FOREACH(dev->outputs, l, new_output)
{ {
if (disconnects & (1 << new_output->conn_id)) if (disconnects & (1 << new_output->conn_id))
{ {
@ -693,15 +678,6 @@ _ecore_drm_update_outputs(Ecore_Drm_Output *output)
} }
} }
static void
_ecore_drm_output_event(const char *device EINA_UNUSED, Eeze_Udev_Event event EINA_UNUSED, void *data, Eeze_Udev_Watch *watch EINA_UNUSED)
{
Ecore_Drm_Output *output;
if (!(output = data)) return;
_ecore_drm_update_outputs(output);
}
static void static void
_ecore_drm_event_output_free(void *data EINA_UNUSED, void *event) _ecore_drm_event_output_free(void *data EINA_UNUSED, void *event)
{ {
@ -796,8 +772,6 @@ ecore_drm_outputs_create(Ecore_Drm_Device *dev)
for (i = 0; i < res->count_connectors; i++) for (i = 0; i < res->count_connectors; i++)
{ {
int events = 0;
/* get the connector */ /* get the connector */
if (!(conn = drmModeGetConnector(dev->drm.fd, res->connectors[i]))) if (!(conn = drmModeGetConnector(dev->drm.fd, res->connectors[i])))
continue; continue;
@ -838,16 +812,6 @@ ecore_drm_outputs_create(Ecore_Drm_Device *dev)
drmModeFreeCrtc(crtc); drmModeFreeCrtc(crtc);
drmModeFreeEncoder(enc); drmModeFreeEncoder(enc);
events = (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE |
EEZE_UDEV_EVENT_CHANGE);
output->watch =
eeze_udev_watch_add(EEZE_UDEV_TYPE_DRM, events,
_ecore_drm_output_event, output);
if (!output->watch)
ERR("Could not create Eeze_Udev_Watch for drm output");
dev->outputs = eina_list_append(dev->outputs, output); dev->outputs = eina_list_append(dev->outputs, output);
} }

View File

@ -34,7 +34,6 @@
# include <systemd/sd-login.h> # include <systemd/sd-login.h>
# endif # endif
# include <Eeze.h>
# include <Eldbus.h> # include <Eldbus.h>
# include <Ecore_Drm.h> # include <Ecore_Drm.h>
@ -114,7 +113,6 @@ struct _Ecore_Drm_Output
unsigned int crtc_id; unsigned int crtc_id;
unsigned int conn_id; unsigned int conn_id;
drmModeCrtcPtr crtc; drmModeCrtcPtr crtc;
Eeze_Udev_Watch *watch;
int x, y, phys_width, phys_height; int x, y, phys_width, phys_height;
int drm_fd; int drm_fd;
@ -262,6 +260,7 @@ void _ecore_drm_fb_destroy(Ecore_Drm_Fb *fb);
void _ecore_drm_output_fb_release(Ecore_Drm_Output *output, Ecore_Drm_Fb *fb); void _ecore_drm_output_fb_release(Ecore_Drm_Output *output, Ecore_Drm_Fb *fb);
void _ecore_drm_output_repaint_start(Ecore_Drm_Output *output); void _ecore_drm_output_repaint_start(Ecore_Drm_Output *output);
void _ecore_drm_output_frame_finish(Ecore_Drm_Output *output); void _ecore_drm_output_frame_finish(Ecore_Drm_Output *output);
void _ecore_drm_outputs_update(Ecore_Drm_Device *dev);
Eina_Bool _ecore_drm_logind_connect(Ecore_Drm_Device *dev); Eina_Bool _ecore_drm_logind_connect(Ecore_Drm_Device *dev);
void _ecore_drm_logind_disconnect(Ecore_Drm_Device *dev); void _ecore_drm_logind_disconnect(Ecore_Drm_Device *dev);