stefan pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=c7ced198e623dff7690b857e9702267b71633605

commit c7ced198e623dff7690b857e9702267b71633605
Author: Chris Michael <cp.mich...@samsung.com>
Date:   Tue Apr 7 11:08:19 2015 -0400

    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.mich...@samsung.com>
---
 src/lib/ecore_drm/Ecore_Drm.h         |  3 ++
 src/lib/ecore_drm/ecore_drm_device.c  | 20 +++++++++++
 src/lib/ecore_drm/ecore_drm_output.c  | 66 ++++++++---------------------------
 src/lib/ecore_drm/ecore_drm_private.h |  3 +-
 4 files changed, 39 insertions(+), 53 deletions(-)

diff --git a/src/lib/ecore_drm/Ecore_Drm.h b/src/lib/ecore_drm/Ecore_Drm.h
index 5c4dd8b..e5357d5 100644
--- a/src/lib/ecore_drm/Ecore_Drm.h
+++ b/src/lib/ecore_drm/Ecore_Drm.h
@@ -24,6 +24,7 @@
 #endif // ifdef _MSC_VER
 
 #include <Ecore.h>
+#include <Eeze.h>
 
 typedef enum _Ecore_Drm_Evdev_Capabilities
 {
@@ -110,6 +111,8 @@ struct _Ecore_Drm_Device
    struct xkb_context *xkb_ctx;
 
    unsigned int window;
+
+   Eeze_Udev_Watch *watch;
 };
 
 struct _Ecore_Drm_Event_Activate
diff --git a/src/lib/ecore_drm/ecore_drm_device.c 
b/src/lib/ecore_drm/ecore_drm_device.c
index 917a02b..69a8e1c 100644
--- a/src/lib/ecore_drm/ecore_drm_device.c
+++ b/src/lib/ecore_drm/ecore_drm_device.c
@@ -87,6 +87,15 @@ _ecore_drm_device_cb_idle(void *data)
    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
  * 
@@ -261,6 +270,7 @@ EAPI Eina_Bool
 ecore_drm_device_open(Ecore_Drm_Device *dev)
 {
    uint64_t caps;
+   int events = 0;
 
    /* check for valid device */
    if ((!dev) || (!dev->drm.name)) return EINA_FALSE;
@@ -299,6 +309,13 @@ ecore_drm_device_open(Ecore_Drm_Device *dev)
         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 = 
      ecore_main_fd_handler_add(dev->drm.fd, ECORE_FD_READ, 
                                _ecore_drm_device_cb_event, dev, NULL, NULL);
@@ -326,6 +343,9 @@ ecore_drm_device_close(Ecore_Drm_Device *dev)
    /* check for valid device */
    if (!dev) return EINA_FALSE;
 
+   /* delete udev watch */
+   if (dev->watch) eeze_udev_watch_del(dev->watch);
+
    /* close xkb context */
    if (dev->xkb_ctx) xkb_context_unref(dev->xkb_ctx);
 
diff --git a/src/lib/ecore_drm/ecore_drm_output.c 
b/src/lib/ecore_drm/ecore_drm_output.c
index fc2cd5e..dc87374 100644
--- a/src/lib/ecore_drm/ecore_drm_output.c
+++ b/src/lib/ecore_drm/ecore_drm_output.c
@@ -24,9 +24,6 @@ static const char *conn_types[] =
 
 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 
 _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 */
    if (!output) return;
 
-   /* delete any added udev watch */
-   if (output->watch) eeze_udev_watch_del(output->watch);
-
    /* delete the backlight struct */
    if (output->backlight) 
      _ecore_drm_output_backlight_shutdown(output->backlight);
@@ -596,19 +590,18 @@ finish:
    _ecore_drm_output_frame_finish(output);
 }
 
-static void
-_ecore_drm_update_outputs(Ecore_Drm_Output *output)
+void
+_ecore_drm_outputs_update(Ecore_Drm_Device *dev)
 {
    Ecore_Drm_Output *new_output;
    drmModeConnector *connector;
    drmModeRes *res;
    drmModeCrtc *crtc;
-   int x = 0, y = 0;
+   int x = 0, y = 0, i;
    uint32_t connected = 0, disconnects = 0;
-   int i;
    Eina_List *l;
 
-   res = drmModeGetResources(output->drm_fd);
+   res = drmModeGetResources(dev->drm.fd);
    if (!res)
      {
         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];
 
-        connector = drmModeGetConnector(output->drm_fd, connector_id);
+        connector = drmModeGetConnector(dev->drm.fd, connector_id);
         if (connector == NULL)
           continue;
 
@@ -631,28 +624,27 @@ _ecore_drm_update_outputs(Ecore_Drm_Output *output)
 
         connected |= (1 << connector_id);
 
-        if (!(output->dev->conn_allocator & (1 << connector_id)))
+        if (!(dev->conn_allocator & (1 << connector_id)))
           {
              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);
                   _ecore_drm_output_free(new_output);
                   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);
                   _ecore_drm_output_free(new_output);
                   continue;
                }
 
-             if (!(crtc = drmModeGetCrtc(new_output->dev->drm.fd, 
enc->crtc_id)))
+             if (!(crtc = drmModeGetCrtc(dev->drm.fd, enc->crtc_id)))
                {
                   drmModeFreeEncoder(enc);
                   drmModeFreeConnector(connector);
@@ -665,23 +657,16 @@ _ecore_drm_update_outputs(Ecore_Drm_Output *output)
              drmModeFreeCrtc(crtc);
              drmModeFreeEncoder(enc);
 
-             events = (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE | 
-                       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);
+             dev->outputs = eina_list_append(dev->outputs, new_output);
           }
-          drmModeFreeConnector(connector);
+
+        drmModeFreeConnector(connector);
      }
 
-   disconnects = output->dev->conn_allocator & ~connected;
+   disconnects = dev->conn_allocator & ~connected;
    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))
                {
@@ -694,15 +679,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
 _ecore_drm_event_output_free(void *data EINA_UNUSED, void *event)
 {
    Ecore_Drm_Event_Output *e = event;
@@ -796,8 +772,6 @@ ecore_drm_outputs_create(Ecore_Drm_Device *dev)
 
    for (i = 0; i < res->count_connectors; i++)
      {
-        int events = 0;
-
         /* get the connector */
         if (!(conn = drmModeGetConnector(dev->drm.fd, res->connectors[i])))
           continue;
@@ -838,16 +812,6 @@ ecore_drm_outputs_create(Ecore_Drm_Device *dev)
              drmModeFreeCrtc(crtc);
              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);
           }
 
diff --git a/src/lib/ecore_drm/ecore_drm_private.h 
b/src/lib/ecore_drm/ecore_drm_private.h
index 7b8e4f1..2d20255 100644
--- a/src/lib/ecore_drm/ecore_drm_private.h
+++ b/src/lib/ecore_drm/ecore_drm_private.h
@@ -34,7 +34,6 @@
 #  include <systemd/sd-login.h>
 # endif
 
-# include <Eeze.h>
 # include <Eldbus.h>
 # include <Ecore_Drm.h>
 
@@ -114,7 +113,6 @@ struct _Ecore_Drm_Output
    unsigned int crtc_id;
    unsigned int conn_id;
    drmModeCrtcPtr crtc;
-   Eeze_Udev_Watch *watch;
 
    int x, y, phys_width, phys_height;
    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_repaint_start(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);
 void _ecore_drm_logind_disconnect(Ecore_Drm_Device *dev);

-- 


Reply via email to