discomfitor pushed a commit to branch master.

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

commit bdb462e19f483fcb9541c332be5983b4db4c66c5
Author: JengHyun Kang <jhyuni.k...@samsung.com>
Date:   Tue Jan 5 13:07:27 2016 -0500

    Set cached xkb context/keymap
    
    Summary:
    Set xkb context and keymap to Ecore_Drm.
             In enlightenment (used in wayland with drm backend), keymap is 
used only one.
             So for avoid unnecessary open keymap files, set cached context and 
keymap.
             But for this, enlightenment must compile keymap before init 
ecore_drm.
             So I changed booting sequence also.
    
    Test Plan: Distinguish time between before and after during add a keyboard 
device.
    
    Reviewers: raster, devilhorns, zmike
    
    Subscribers: cedric, input.hacker, ohduna
    
    Differential Revision: https://phab.enlightenment.org/D3504
---
 config/default/e.src            |  1 +
 config/mobile/e.src             |  1 +
 config/standard/e.src           |  1 +
 config/tiling/e.src             |  1 +
 src/bin/e_comp_wl.c             |  2 +-
 src/bin/e_comp_wl_input.c       | 50 ++++++++++++++++++++++++++++++-----------
 src/bin/e_comp_wl_input.h       |  3 ++-
 src/bin/e_config.c              |  1 +
 src/bin/e_config.h              |  1 +
 src/modules/wl_drm/e_mod_main.c | 26 ++++++++++++++++++++-
 src/modules/wl_wl/e_mod_main.c  |  2 +-
 src/modules/wl_x11/e_mod_main.c |  2 +-
 12 files changed, 73 insertions(+), 18 deletions(-)

diff --git a/config/default/e.src b/config/default/e.src
index b7cb835..6c601c5 100644
--- a/config/default/e.src
+++ b/config/default/e.src
@@ -215,6 +215,7 @@ group "E_Config" struct {
   value "update.later" uchar: 0;
   value "xkb.only_label" int: 0;
   value "xkb.default_model" string: "default";
+  value "xkb.use_cache" uchar: 0;
   value "keyboard.repeat_delay" int: 400;
   value "keyboard.repeat_rate" int: 25;
   value "exe_always_single_instance" uchar: 0;
diff --git a/config/mobile/e.src b/config/mobile/e.src
index 1431dde..251632d 100644
--- a/config/mobile/e.src
+++ b/config/mobile/e.src
@@ -865,6 +865,7 @@ group "E_Config" struct {
     }
     value "xkb.only_label" int: 0;
     value "xkb.default_model" string: "default";
+    value "xkb.use_cache" uchar: 0;
     value "keyboard.repeat_delay" int: 400;
     value "keyboard.repeat_rate" int: 25;
     value "exe_always_single_instance" uchar: 1;
diff --git a/config/standard/e.src b/config/standard/e.src
index b41057c..f43f193 100644
--- a/config/standard/e.src
+++ b/config/standard/e.src
@@ -1106,6 +1106,7 @@ group "E_Config" struct {
     }
     value "xkb.only_label" int: 0;
     value "xkb.default_model" string: "default";
+    value "xkb.use_cache" uchar: 0;
     value "keyboard.repeat_delay" int: 400;
     value "keyboard.repeat_rate" int: 25;
     value "exe_always_single_instance" uchar: 0;
diff --git a/config/tiling/e.src b/config/tiling/e.src
index afeac1f..eff658c 100644
--- a/config/tiling/e.src
+++ b/config/tiling/e.src
@@ -1128,6 +1128,7 @@ group "E_Config" struct {
     }
     value "xkb.only_label" int: 0;
     value "xkb.default_model" string: "default";
+    value "xkb.use_cache" uchar: 0;
     value "keyboard.repeat_delay" int: 400;
     value "keyboard.repeat_rate" int: 25;
     value "exe_always_single_instance" uchar: 0;
diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c
index bcfb60d..454ed69 100644
--- a/src/bin/e_comp_wl.c
+++ b/src/bin/e_comp_wl.c
@@ -2655,7 +2655,7 @@ _e_comp_wl_compositor_create(void)
         if (!layout) layout = strdup("us");
 
         /* update compositor keymap */
-        e_comp_wl_input_keymap_set(rules, model, layout);
+        e_comp_wl_input_keymap_set(rules, model, layout, NULL, NULL);
      }
 #endif
    e_comp_wl->wl.client_disp = ecore_wl2_display_connect(NULL);
diff --git a/src/bin/e_comp_wl_input.c b/src/bin/e_comp_wl_input.c
index 79f75d4..3e80cb8 100644
--- a/src/bin/e_comp_wl_input.c
+++ b/src/bin/e_comp_wl_input.c
@@ -2,6 +2,9 @@
 #define E_COMP_WL
 #include "e.h"
 #include <sys/mman.h>
+#ifdef HAVE_WL_DRM
+#include <Ecore_Drm.h>
+#endif
 
 E_API int E_EVENT_TEXT_INPUT_PANEL_VISIBILITY_CHANGE = -1;
 
@@ -586,41 +589,62 @@ e_comp_wl_input_keyboard_enabled_set(Eina_Bool enabled)
 }
 
 E_API void
-e_comp_wl_input_keymap_set(const char *rules, const char *model, const char 
*layout)
+e_comp_wl_input_keymap_set(const char *rules, const char *model, const char 
*layout, struct xkb_context *dflt_ctx, struct xkb_keymap *dflt_map)
 {
    struct xkb_keymap *keymap;
    struct xkb_rule_names names;
+   Eina_Bool use_dflt_xkb = EINA_FALSE;
 
    /* DBG("COMP_WL: Keymap Set: %s %s %s", rules, model, layout); */
 
+   if (dflt_ctx && dflt_map) use_dflt_xkb = EINA_TRUE;
+
    /* assemble xkb_rule_names so we can fetch keymap */
-   memset(&names, 0, sizeof(names));
-   if (rules) names.rules = strdup(rules);
-   else names.rules = strdup("evdev");
-   if (model) names.model = strdup(model);
-   else names.model = strdup("pc105");
-   if (layout) names.layout = strdup(layout);
-   else names.layout = strdup("us");
+   if (!use_dflt_xkb)
+     {
+        memset(&names, 0, sizeof(names));
+        if (rules) names.rules = strdup(rules);
+        else names.rules = strdup("evdev");
+        if (model) names.model = strdup(model);
+        else names.model = strdup("pc105");
+        if (layout) names.layout = strdup(layout);
+        else names.layout = strdup("us");
+     }
 
    /* unreference any existing context */
    if (e_comp_wl->xkb.context)
      xkb_context_unref(e_comp_wl->xkb.context);
 
    /* create a new xkb context */
-   e_comp_wl->xkb.context = xkb_context_new(0);
+   if (use_dflt_xkb) e_comp_wl->xkb.context = dflt_ctx;
+   else e_comp_wl->xkb.context = xkb_context_new(0);
+
+#ifdef HAVE_WL_DRM
+   if (e_config->xkb.use_cache)
+     ecore_drm_device_keyboard_cached_context_set(e_comp_wl->xkb.context);
+#endif
 
    /* fetch new keymap based on names */
-   keymap = xkb_map_new_from_names(e_comp_wl->xkb.context, &names, 0);
+   if (use_dflt_xkb) keymap = dflt_map;
+   else keymap = xkb_map_new_from_names(e_comp_wl->xkb.context, &names, 0);
    if (keymap)
      {
         /* update compositor keymap */
         _e_comp_wl_input_keymap_update(keymap);
      }
 
+#ifdef HAVE_WL_DRM
+   if (e_config->xkb.use_cache)
+     ecore_drm_device_keyboard_cached_keymap_set(keymap);
+#endif
+
    /* cleanup */
-   free((char *)names.rules);
-   free((char *)names.model);
-   free((char *)names.layout);
+   if (!use_dflt_xkb)
+     {
+        free((char *)names.rules);
+        free((char *)names.model);
+        free((char *)names.layout);
+     }
 }
 
 E_API void
diff --git a/src/bin/e_comp_wl_input.h b/src/bin/e_comp_wl_input.h
index a9bc9d4..f13d0a1 100644
--- a/src/bin/e_comp_wl_input.h
+++ b/src/bin/e_comp_wl_input.h
@@ -29,7 +29,8 @@ E_API void e_comp_wl_input_pointer_enabled_set(Eina_Bool 
enabled);
 E_API void e_comp_wl_input_keyboard_enabled_set(Eina_Bool enabled);
 E_API void e_comp_wl_input_touch_enabled_set(Eina_Bool enabled);
 
-E_API void e_comp_wl_input_keymap_set(const char *rules, const char *model, 
const char *layout);
+E_API void e_comp_wl_input_keymap_set(const char *rules, const char *model, 
const char *layout,
+                                      struct xkb_context *dflt_ctx, struct 
xkb_keymap *dflt_map);
 
 # endif
 #endif
diff --git a/src/bin/e_config.c b/src/bin/e_config.c
index a24f448..7d94141 100644
--- a/src/bin/e_config.c
+++ b/src/bin/e_config.c
@@ -752,6 +752,7 @@ _e_config_edd_init(Eina_Bool old)
    E_CONFIG_VAL(D, T, xkb.only_label, INT);
    E_CONFIG_VAL(D, T, xkb.dont_touch_my_damn_keyboard, UCHAR);
    E_CONFIG_VAL(D, T, xkb.default_model, STR);
+   E_CONFIG_VAL(D, T, xkb.use_cache, UCHAR);
 
    E_CONFIG_VAL(D, T, keyboard.repeat_delay, INT);
    E_CONFIG_VAL(D, T, keyboard.repeat_rate, INT);
diff --git a/src/bin/e_config.h b/src/bin/e_config.h
index a2f9a7a..a3a65cc 100644
--- a/src/bin/e_config.h
+++ b/src/bin/e_config.h
@@ -428,6 +428,7 @@ struct _E_Config
       const char *cur_layout; // whatever the current layout is
       const char *selected_layout; // whatever teh current layout that the 
user has selected is
       const char *desklock_layout;
+      Eina_Bool use_cache;
    } xkb;
 
    struct
diff --git a/src/modules/wl_drm/e_mod_main.c b/src/modules/wl_drm/e_mod_main.c
index 7a9f6aa..9277d52 100644
--- a/src/modules/wl_drm/e_mod_main.c
+++ b/src/modules/wl_drm/e_mod_main.c
@@ -668,10 +668,32 @@ _drm_read_pixels(E_Comp_Wl_Output *output, void *pixels)
      }
 }
 
+static void
+_e_mod_drm_keymap_set(struct xkb_context *ctx, struct xkb_keymap *map)
+{
+   struct xkb_rule_names names;
+
+   ctx = xkb_context_new(0);
+   EINA_SAFETY_ON_NULL_RETURN(ctx);
+
+   memset(&names, 0, sizeof(names));
+   names.rules = strdup("evdev");
+   names.model = strdup("pc105");
+   names.layout = strdup("us");
+
+   map = xkb_map_new_from_names(ctx, &names, 0);
+   EINA_SAFETY_ON_NULL_RETURN(map);
+
+   ecore_drm_device_keyboard_cached_context_set(ctx);
+   ecore_drm_device_keyboard_cached_keymap_set(map);
+}
+
 E_API void *
 e_modapi_init(E_Module *m)
 {
    int w = 0, h = 0;
+   struct xkb_context *ctx = NULL;
+   struct xkb_keymap *map = NULL;
 
    printf("LOAD WL_DRM MODULE\n");
 
@@ -682,6 +704,8 @@ e_modapi_init(E_Module *m)
    /*      return NULL; */
    /*   } */
 
+   _e_mod_drm_keymap_set(ctx, map);
+
    if (e_comp_config_get()->engine == E_COMP_ENGINE_GL)
      {
         e_comp->ee = ecore_evas_new("gl_drm", 0, 0, 1, 1, NULL);
@@ -743,7 +767,7 @@ e_modapi_init(E_Module *m)
 
    /* FIXME: This is just for testing at the moment....
     * happens to jive with what drm does */
-   e_comp_wl_input_keymap_set(NULL, NULL, NULL);
+   e_comp_wl_input_keymap_set(NULL, NULL, NULL, ctx, map);
 
    activate_handler =
       ecore_event_handler_add(ECORE_DRM_EVENT_ACTIVATE,
diff --git a/src/modules/wl_wl/e_mod_main.c b/src/modules/wl_wl/e_mod_main.c
index 5cc0aaa..35bac19 100644
--- a/src/modules/wl_wl/e_mod_main.c
+++ b/src/modules/wl_wl/e_mod_main.c
@@ -58,7 +58,7 @@ e_modapi_init(E_Module *m)
    e_comp->pointer = e_pointer_canvas_new(e_comp->ee, EINA_TRUE);
    e_comp->pointer->color = EINA_TRUE;
 
-   e_comp_wl_input_keymap_set(NULL, NULL, NULL);
+   e_comp_wl_input_keymap_set(NULL, NULL, NULL, NULL, NULL);
    wl_wl_init();
 
    return m;
diff --git a/src/modules/wl_x11/e_mod_main.c b/src/modules/wl_x11/e_mod_main.c
index 1d8d940..c38694e 100644
--- a/src/modules/wl_x11/e_mod_main.c
+++ b/src/modules/wl_x11/e_mod_main.c
@@ -50,7 +50,7 @@ _cb_keymap_changed(void *data EINA_UNUSED, int type 
EINA_UNUSED, void *event EIN
    if (!layout) layout = strdup("us");
 
    /* update compositor keymap */
-   e_comp_wl_input_keymap_set(rules, model, layout);
+   e_comp_wl_input_keymap_set(rules, model, layout, NULL, NULL);
 
    free(rules);
    free(model);

-- 


Reply via email to