initializa the e_comp_screen with the new e_output api.
authorSooChan Lim <sc1.lim@samsung.com>
Sun, 5 Jun 2016 12:20:50 +0000 (21:20 +0900)
committerJuyeon Lee <juyeonne.lee@samsung.com>
Fri, 10 Jun 2016 02:14:04 +0000 (11:14 +0900)
add the new e_output apis below and e_comp_screen intializes with them.
EINTERN E_Output        * e_output_new(Ecore_Drm_Output *output);
EINTERN void              e_output_del(E_Output *eout);
EINTERN Eina_Bool         e_output_update(E_Output *eout);

Change-Id: I1f36afafc1a9d02a496fd206255bd7102f91c3b6

src/bin/e_comp_screen.c
src/bin/e_comp_screen.h
src/bin/e_output.c
src/bin/e_output.h

index 57d1baae81a676b9e2d54a0a24544c4ac3a2cb39..7559b75b183fd40fa44d0819618b8387df6e37c9 100644 (file)
@@ -185,166 +185,68 @@ _e_comp_screen_mode_screen_find(E_Output *eout, Ecore_Drm_Output *output)
    return m;
 }
 
-static Eina_Bool
-_e_comp_screen_output_exists(Ecore_Drm_Output *output, unsigned int crtc)
+static E_Comp_Screen *
+_e_comp_screen_new(void)
 {
-   /* find out if this output can go into the 'possibles' */
-   return ecore_drm_output_possible_crtc_get(output, crtc);
+   E_Comp_Screen *e_comp_screen = NULL;
+
+   e_comp_screen = E_NEW(E_Comp_Screen, 1);
+   if (!e_comp_screen) return NULL;
+
+   /* Ecore_Drm_Device list */
+   e_comp_screen->devices = ecore_drm_devices_get();
+
+   /* TODO: tdm display init */
+
+   return e_comp_screen;
 }
 
-static char *
-_e_comp_screen_output_screen_get(Ecore_Drm_Output *output)
+static void
+_e_comp_screen_del(E_Comp_Screen *e_comp_screen)
 {
-   const char *model;
-
-   model = ecore_drm_output_model_get(output);
-   if (!model) return NULL;
+   if (!e_comp_screen) return;
 
-   return strdup(model);
+   free(e_comp_screen);
 }
 
-static E_Comp_Screen *
-_e_comp_screen_init_outputs(void)
+static Eina_Bool
+_e_comp_screen_init_outputs(E_Comp_Screen *e_comp_screen)
 {
    Ecore_Drm_Device *dev;
    Ecore_Drm_Output *output;
    const Eina_List *l, *ll;
-   E_Comp_Screen *r = NULL;
-
-   r = E_NEW(E_Comp_Screen, 1);
-   if (!r) return NULL;
+   E_Output *eout = NULL;
 
-   EINA_LIST_FOREACH(ecore_drm_devices_get(), l, dev)
+   EINA_LIST_FOREACH(e_comp_screen->devices, l, dev)
      {
         EINA_LIST_FOREACH(dev->outputs, ll, output)
           {
-             E_Output *eout;
-             const Eina_List *m;
-             Ecore_Drm_Output_Mode *omode;
-             unsigned int j;
-             int priority;
-             Eina_Bool ok = EINA_FALSE;
-             Eina_Bool possible = EINA_FALSE;
-             int len = 0;
-
-             eout = E_NEW(E_Output, 1);
+             if (!output) continue;
+             eout = e_output_new(output);
              if (!eout) continue;
-
-             eout->info.name = ecore_drm_output_name_get(output);
-             printf("COMP TDM: .... out %s\n", eout->info.name);
-
-             eout->info.connected = ecore_drm_output_connected_get(output);
-             printf("COMP TDM: ...... connected %i\n", eout->info.connected);
-
-             eout->info.screen = _e_comp_screen_output_screen_get(output);
-
-             eout->info.edid = ecore_drm_output_edid_get(output);
-             if (eout->info.edid)
-               eout->id = malloc(strlen(eout->info.name) + 1 + strlen(eout->info.edid) + 1);
-             else
-               eout->id = malloc(strlen(eout->info.name) + 1 + 1);
-             if (!eout->id)
+             if(!e_output_update(eout))
                {
-                  free(eout->info.screen);
-                  free(eout->info.edid);
-                  free(eout);
-                  continue;
+                  ERR("fail to e_output_update.");
                }
-             len = strlen(eout->info.name);
-             strncpy(eout->id, eout->info.name, len + 1);
-             strncat(eout->id, "/", 1);
-             if (eout->info.edid) strncat(eout->id, eout->info.edid, strlen(eout->info.edid));
-
-             printf("COMP TDM: ...... screen: %s\n", eout->id);
-
-             ecore_drm_output_physical_size_get(output, &eout->info.size.w,
-                                                &eout->info.size.h);
-
-             EINA_LIST_FOREACH(ecore_drm_output_modes_get(output), m, omode)
-               {
-                  E_Output_Mode *rmode;
-
-                  rmode = malloc(sizeof(E_Output_Mode));
-                  if (!rmode) continue;
-
-                  rmode->w = omode->width;
-                  rmode->h = omode->height;
-                  rmode->refresh = omode->refresh;
-                  rmode->preferred = (omode->flags & DRM_MODE_TYPE_PREFERRED);
-
-                  eout->info.modes = eina_list_append(eout->info.modes, rmode);
-               }
-
-             priority = 0;
-             if (ecore_drm_output_primary_get(dev) == output)
-               priority = 100;
-             eout->config.priority = priority;
-
-             for (j = 0; j < dev->crtc_count; j++)
-               {
-                  if (dev->crtcs[j] == ecore_drm_output_crtc_id_get(output))
-                    {
-                       ok = EINA_TRUE;
-                       break;
-                    }
-               }
-
-             if (!ok)
-               {
-                  /* get possible crtcs, compare to output_crtc_id_get */
-                  for (j = 0; j < dev->crtc_count; j++)
-                    {
-                       if (_e_comp_screen_output_exists(output, dev->crtcs[j]))
-                         {
-                            ok = EINA_TRUE;
-                            possible = EINA_TRUE;
-                            break;
-                         }
-                    }
-               }
-
-             if (ok)
-               {
-                  if (!possible)
-                    {
-                       unsigned int refresh;
-
-                       ecore_drm_output_position_get(output, &eout->config.geom.x,
-                                                     &eout->config.geom.y);
-                       ecore_drm_output_crtc_size_get(output, &eout->config.geom.w,
-                                                      &eout->config.geom.h);
-
-                       ecore_drm_output_current_resolution_get(output,
-                                                               &eout->config.mode.w,
-                                                               &eout->config.mode.h,
-                                                               &refresh);
-                       eout->config.mode.refresh = refresh;
-                       eout->config.enabled =
-                          ((eout->config.mode.w != 0) && (eout->config.mode.h != 0));
+             e_comp_screen->outputs = eina_list_append(e_comp_screen->outputs, eout);
+          }
+     }
 
-                       printf("COMP TDM: '%s' %i %i %ix%i\n", eout->info.name,
-                              eout->config.geom.x, eout->config.geom.y,
-                              eout->config.geom.w, eout->config.geom.h);
+   //TODO: if there is no output connected, make the fake output which is connected.
 
-                    }
+   return EINA_TRUE;
+}
 
-                  /* TODO: are rotations possible ?? */
-               }
-             eout->plane_count = 1; // TODO: get proper value using libtdm
-             printf("COMP TDM: planes %i\n", eout->plane_count);
-             for (j = 0; j < eout->plane_count; j++)
-               {
-                  printf("COMP TDM: added plane %i\n", j);
-                  Eina_Bool pri = EINA_FALSE;
-                  if (j == 0) pri = EINA_TRUE;
-                  e_plane_new(eout, j, pri);
-               }
+static void
+_e_comp_screen_deinit_outputs(E_Comp_Screen *e_comp_screen)
+{
+   E_Output *eout;
 
-             r->outputs = eina_list_append(r->outputs, eout);
-          }
+   // free up e_outputs
+   EINA_LIST_FREE(e_comp_screen->outputs, eout)
+     {
+        e_output_del(eout);
      }
-
-   return r;
 }
 
 EINTERN void
@@ -742,10 +644,6 @@ e_comp_screen_init()
         TRACE_DS_END();
         EINA_SAFETY_ON_NULL_RETURN_VAL(comp, EINA_FALSE);
      }
-   comp->comp_type = E_PIXMAP_TYPE_WL;
-
-   dont_set_ecore_drm_keymap = getenv("NO_ECORE_DRM_KEYMAP_CACHE") ? EINA_TRUE : EINA_FALSE;
-   dont_use_xkb_cache = getenv("NO_KEYMAP_CACHE") ? EINA_TRUE : EINA_FALSE;
 
    /* set gl available if we have ecore_evas support */
    if (ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_OPENGL_DRM))
@@ -754,13 +652,6 @@ e_comp_screen_init()
    INF("GL available:%d config engine:%d screen size:%dx%d",
        e_comp_gl_get(), e_comp_config_get()->engine, scr_w, scr_h);
 
-   if (e_config->xkb.use_cache && !dont_use_xkb_cache)
-     {
-        e_main_ts("\tDRM Keymap Init");
-        _e_comp_screen_keymap_set(&ctx, &map);
-        e_main_ts("\tDRM Keymap Init Done");
-     }
-
    if ((e_comp_gl_get()) &&
        (e_comp_config_get()->engine == E_COMP_ENGINE_GL))
      {
@@ -838,18 +729,26 @@ e_comp_screen_init()
 
    ecore_evas_callback_resize_set(e_comp->ee, _e_comp_screen_cb_ee_resize);
 
-   e_main_ts("\tE_Output Init");
-   if (!e_output_init())
+   /* e_comp_screen new */
+   e_comp_screen = _e_comp_screen_new();
+   if (!e_comp_screen)
+     {
+        TRACE_DS_END();
+        EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_screen, EINA_FALSE);
+     }
+   e_comp->e_comp_screen = e_comp_screen;
+
+   e_main_ts("\tE_Outputs Init");
+   if (!_e_comp_screen_init_outputs(e_comp_screen))
      {
-        e_error_message_show(_("Enlightenment cannot initialize output!\n"));
+        e_error_message_show(_("Enlightenment cannot initialize outputs!\n"));
+        _e_comp_screen_del(e_comp_screen);
+        e_comp->e_comp_screen = NULL;
         TRACE_DS_END();
         return EINA_FALSE;
      }
    if (!E_EVENT_SCREEN_CHANGE) E_EVENT_SCREEN_CHANGE = ecore_event_type_new();
 
-   e_comp_screen = _e_comp_screen_init_outputs();
-   e_comp->e_comp_screen = e_comp_screen;
-
    // take current e_output config and apply it to the driver
    _e_comp_screen_config_maxsize(e_comp_screen);
    printf("OUTPUT: eval config...\n");
@@ -861,7 +760,7 @@ e_comp_screen_init()
    ecore_event_add(E_EVENT_SCREEN_CHANGE, NULL, NULL, NULL);
 
    e_comp_screen_e_screens_setup(e_comp_screen, -1, -1);
-   e_main_ts("\tE_Output Init Done");
+   e_main_ts("\tE_Outputs Init Done");
 
    e_main_ts("\tE_Comp_Wl Init");
    if (!e_comp_wl_init())
@@ -871,9 +770,14 @@ e_comp_screen_init()
      }
    e_main_ts("\tE_Comp_Wl Init Done");
 
+   /* canvas */
    e_main_ts("\tE_Comp_Canvas Init");
    if (!e_comp_canvas_init(w, h))
      {
+        e_error_message_show(_("Enlightenment cannot initialize outputs!\n"));
+        _e_comp_screen_deinit_outputs(e_comp->e_comp_screen);
+        _e_comp_screen_del(e_comp_screen);
+        e_comp->e_comp_screen = NULL;
         TRACE_DS_END();
         return EINA_FALSE;
      }
@@ -881,6 +785,7 @@ e_comp_screen_init()
 
    e_comp_wl->screenshooter.read_pixels = _drm_read_pixels;
 
+   /* pointer */
    ecore_evas_pointer_xy_get(e_comp->ee,
                              &e_comp_wl->ptr.x,
                              &e_comp_wl->ptr.y);
@@ -897,6 +802,17 @@ e_comp_screen_init()
      }
    e_main_ts("\tE_Pointer New Done");
 
+   /* keymap */
+   dont_set_ecore_drm_keymap = getenv("NO_ECORE_DRM_KEYMAP_CACHE") ? EINA_TRUE : EINA_FALSE;
+   dont_use_xkb_cache = getenv("NO_KEYMAP_CACHE") ? EINA_TRUE : EINA_FALSE;
+
+   if (e_config->xkb.use_cache && !dont_use_xkb_cache)
+     {
+        e_main_ts("\tDRM Keymap Init");
+        _e_comp_screen_keymap_set(&ctx, &map);
+        e_main_ts("\tDRM Keymap Init Done");
+     }
+
    /* FIXME: We need a way to trap for user changing the keymap inside of E
     *        without the event coming from X11 */
 
@@ -929,17 +845,19 @@ e_comp_screen_init()
 E_API void
 e_comp_screen_shutdown()
 {
+   if (!e_comp) return;
+   if (!e_comp->e_comp_screen) return;
+
    /* shutdown ecore_drm */
    /* ecore_drm_shutdown(); */
 
-   e_output_shutdown();
-
-   // free up screen info
-   free(e_comp->e_comp_screen);
-   e_comp->e_comp_screen = NULL;
+   _e_comp_screen_deinit_outputs(e_comp->e_comp_screen);
 
    dont_set_ecore_drm_keymap = EINA_FALSE;
    dont_use_xkb_cache = EINA_FALSE;
    E_FREE_LIST(event_handlers, ecore_event_handler_del);
 
+   /* delete e_comp_sreen */
+   _e_comp_screen_del(e_comp->e_comp_screen);
+   e_comp->e_comp_screen = NULL;
 }
index 34a8c4ac62991911244f845acb9700a665fd8c83..9499af123320d4f45091c23ad9a248f8ce8ea77a 100644 (file)
@@ -15,6 +15,8 @@ struct _E_Comp_Screen
    unsigned char  ignore_hotplug_events;
    unsigned char  ignore_acpi_events;
    Eina_List *e_screens;
+
+   const Eina_List *devices;
 };
 
 
index 9039e5b60300cc4a804c842820cc8844703ebc9f..661a9d2ae784ce041075580ea27df1aa71f2540a 100644 (file)
 #include "e.h"
 
-EINTERN Eina_Bool
-e_output_init(void)
+static char *
+_e_output_model_get(Ecore_Drm_Output *output)
 {
-   // TODO: initialization e_outputs
+   const char *model;
 
-   return EINA_TRUE;
+   model = ecore_drm_output_model_get(output);
+   if (!model) return NULL;
+
+   return strdup(model);
+}
+
+
+EINTERN E_Output *
+e_output_new(Ecore_Drm_Output *output)
+{
+   E_Output *eout = NULL;
+   int i;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(output, NULL);
+
+   eout = E_NEW(E_Output, 1);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(eout, NULL);
+
+   eout->info.name = ecore_drm_output_name_get(output);
+   printf("E_OUTPUT: .... out %s\n", eout->info.name);
+
+   eout->plane_count = 1; // TODO: get proper value using libtdm
+   printf("COMP TDM: planes %i\n", eout->plane_count);
+   for (i = 0; i < eout->plane_count; i++)
+     {
+        printf("COMP TDM: added plane %i\n", i);
+        Eina_Bool pri = EINA_FALSE;
+        if (i == 0) pri = EINA_TRUE;
+        e_plane_new(eout, i, pri);
+     }
+
+   eout->output = output;
+
+   return eout;
 }
 
 EINTERN void
-e_output_shutdown(void)
+e_output_del(E_Output *eout)
 {
-   // TODO: deinitialization e_outputs
-   E_Output *eout;
-   E_Output_Mode *m;
    E_Plane *ep;
-   Eina_List *outputs;
+   E_Output_Mode *m;
+
+   if (!eout) return;
+
+   free(eout->id);
+   free(eout->info.screen);
+   free(eout->info.name);
+   free(eout->info.edid);
+   EINA_LIST_FREE(eout->info.modes, m) free(m);
+
+   EINA_LIST_FREE(eout->planes, ep) e_plane_free(ep);
+   free(eout);
+}
+
+EINTERN Eina_Bool
+e_output_update(E_Output *eout)
+{
+   Eina_List *m = NULL;
+   Eina_List *modes = NULL;
+   Eina_Bool connected;
+   E_Comp_Screen *e_comp_screen;
 
-   if (!e_comp) return;
-   if (!e_comp->e_comp_screen) return;
+   EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp, EINA_FALSE);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp->e_comp_screen, EINA_FALSE);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(eout, EINA_FALSE);
 
-   outputs = e_comp->e_comp_screen->outputs;
+   e_comp_screen = e_comp->e_comp_screen;
 
-   // free up our output screen data
-   EINA_LIST_FREE(outputs, eout)
+   connected = ecore_drm_output_connected_get(eout->output);
+   if (connected)
      {
+        /* disconnect --> connect */
+        if (connected != eout->info.connected)
+          {
+             int len = 0;
+             char *id;
+             char *screen;
+             char *edid;
+             int phy_w, phy_h;
+             Ecore_Drm_Output_Mode *omode;
+
+             screen = _e_output_model_get(eout->output);
+             edid = ecore_drm_output_edid_get(eout->output);
+             if (eout->info.edid)
+               id = malloc(strlen(eout->info.name) + 1 + strlen(eout->info.edid) + 1);
+             else
+               id = malloc(strlen(eout->info.name) + 1 + 1);
+             if (!id)
+               {
+                  free(edid);
+                  return EINA_FALSE;
+               }
+             len = strlen(eout->info.name);
+             strncpy(id, eout->info.name, len + 1);
+             strncat(id, "/", 1);
+             if (eout->info.edid) strncat(id, edid, strlen(edid));
+
+             printf("E_OUTPUT: ...... screen: %s\n", id);
+
+             ecore_drm_output_physical_size_get(eout->output, &phy_w, &phy_h);
+
+             EINA_LIST_FOREACH(ecore_drm_output_modes_get(eout->output), m, omode)
+               {
+                  E_Output_Mode *rmode;
+
+                  rmode = malloc(sizeof(E_Output_Mode));
+                  if (!rmode) continue;
+
+                  rmode->w = omode->width;
+                  rmode->h = omode->height;
+                  rmode->refresh = omode->refresh;
+                  rmode->preferred = (omode->flags & DRM_MODE_TYPE_PREFERRED);
+
+                  modes = eina_list_append(modes, rmode);
+               }
+
+             free(eout->id);
+             free(eout->info.screen);
+             free(eout->info.edid);
+             EINA_LIST_FREE(eout->info.modes, m) free(m);
+
+             eout->id = id;
+             eout->info.screen = screen;
+             eout->info.edid = edid;
+             eout->info.modes = modes;
+             eout->info.size.w = phy_w;
+             eout->info.size.h = phy_h;
+
+             eout->info.connected = EINA_TRUE;
+
+             printf("E_OUTPUT: connected.. id: %s\n", eout->id);
+          }
+
+        /* check the crtc setting */
+        const Eina_List *l;
+        int i;
+        unsigned int refresh;
+        Ecore_Drm_Device *dev;
+
+        EINA_LIST_FOREACH(e_comp_screen->devices, l, dev)
+          {
+             if (ecore_drm_output_primary_get(dev) == eout->output)
+               eout->config.priority = 100;
+
+             for (i = 0; i < dev->crtc_count; i++)
+               {
+                  if (dev->crtcs[i] == ecore_drm_output_crtc_id_get(eout->output))
+                    {
+                       ecore_drm_output_position_get(eout->output, &eout->config.geom.x,
+                                                     &eout->config.geom.y);
+                       ecore_drm_output_crtc_size_get(eout->output, &eout->config.geom.w,
+                                                      &eout->config.geom.h);
+                       ecore_drm_output_current_resolution_get(eout->output,
+                                                               &eout->config.mode.w,
+                                                               &eout->config.mode.h,
+                                                               &refresh);
+                       eout->config.mode.refresh = refresh;
+                       eout->config.enabled =
+                           ((eout->config.mode.w != 0) && (eout->config.mode.h != 0));
+
+                       printf("E_OUTPUT: '%s' %i %i %ix%i\n", eout->info.name,
+                              eout->config.geom.x, eout->config.geom.y,
+                              eout->config.geom.w, eout->config.geom.h);
+                       break;
+                    }
+               }
+          }
+     }
+   else
+     {
+        eout->info.connected = EINA_FALSE;
+
+        /* reset eout info */
         free(eout->id);
         free(eout->info.screen);
-        free(eout->info.name);
         free(eout->info.edid);
         EINA_LIST_FREE(eout->info.modes, m) free(m);
-        EINA_LIST_FREE(eout->planes, ep) e_plane_free(ep);
-        free(eout);
+
+        eout->id = malloc(strlen(eout->info.name) + 1 + 1);
+        eout->info.size.w = 0;
+        eout->info.size.h = 0;
+
+        printf("E_OUTPUT: disconnected.. id: %s\n", eout->id);
      }
+
+   return EINA_TRUE;
 }
 
 E_API E_Output *
index c3a93e2e23a99444aee3003070727bd5291b6805..8fd468b356680f416be65f14409ba305e790f8c7 100644 (file)
@@ -7,6 +7,8 @@ typedef struct _E_Output_Mode   E_Output_Mode;
 #ifndef E_OUTPUT_H
 #define E_OUTPUT_H
 
+#include <Ecore_Drm.h>
+
 #define E_OUTPUT_TYPE (int)0xE0b11002
 
 struct _E_Output_Mode
@@ -37,13 +39,16 @@ struct _E_Output
         Eina_Bool             enabled : 1; // should this monitor be enabled?
    } config;
 
+   Ecore_Drm_Output *output;
+
    int                  plane_count;
    Eina_List           *planes;
    E_Zone              *zone;
 };
 
-EINTERN Eina_Bool         e_output_init(void);
-EINTERN void              e_output_shutdown(void);
+EINTERN E_Output        * e_output_new(Ecore_Drm_Output *output);
+EINTERN void              e_output_del(E_Output *eout);
+EINTERN Eina_Bool         e_output_update(E_Output *eout);
 E_API E_Output          * e_output_find(const char *id);
 E_API const Eina_List   * e_output_planes_get(E_Output *eout);
 E_API void                e_output_util_planes_print(void);