aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ecore_drm
diff options
context:
space:
mode:
authorJengHyun Kang <jhyuni.kang@samsung.com>2016-01-04 08:47:43 -0500
committerChris Michael <cpmichael@osg.samsung.com>2016-01-04 08:47:58 -0500
commitb3dc27345a59dc21b115fe55bb15e7af092eacbe (patch)
tree8f66f5941ab4efd09eaadb2cfca12825f09da55a /src/lib/ecore_drm
parentedje: enhance circular dependency error message of edje calculation (diff)
downloadefl-b3dc27345a59dc21b115fe55bb15e7af092eacbe.tar.gz
ecore-drm: Add a new API for keymap cache
Summary: Originally, each keyboard devices could have their own keymap. The one keyboard's keymap could different with others. But for this, Ecore_Drm compile a new keymap when a keyboard is connected. But this is a burden for some people who doesn't manage keymap for each keyboard. They want to maintain only one keymap for system. So, I added cached context/keymap and just ref/unref for each keyboard device. People who want to different keymap for each keyboard just do not set cached context/keymap. Then Ecore_Drm maintain keymaps about each keyboard devices. Test Plan: Connect a keyboard device and watch flow of ioctl. Originally Ecore_Drm opened xkb data and compile keymap, but after patch, that ioctl is disppeared. @feature Reviewers: raster, devilhorns, ManMower Reviewed By: devilhorns, ManMower Subscribers: cedric, input.hacker, ohduna, jpeg Differential Revision: https://phab.enlightenment.org/D3503
Diffstat (limited to 'src/lib/ecore_drm')
-rw-r--r--src/lib/ecore_drm/Ecore_Drm.h27
-rw-r--r--src/lib/ecore_drm/ecore_drm_device.c80
-rw-r--r--src/lib/ecore_drm/ecore_drm_evdev.c2
-rw-r--r--src/lib/ecore_drm/ecore_drm_private.h8
4 files changed, 114 insertions, 3 deletions
diff --git a/src/lib/ecore_drm/Ecore_Drm.h b/src/lib/ecore_drm/Ecore_Drm.h
index 1f110efd28..5c50f1022d 100644
--- a/src/lib/ecore_drm/Ecore_Drm.h
+++ b/src/lib/ecore_drm/Ecore_Drm.h
@@ -6,6 +6,7 @@
# include <drm_fourcc.h>
# include <Ecore.h>
# include <Eeze.h>
+# include <xkbcommon/xkbcommon.h>
# ifdef EAPI
# undef EAPI
@@ -382,6 +383,32 @@ EAPI Eina_Bool ecore_drm_device_software_setup(Ecore_Drm_Device *dev);
EAPI Eina_Bool ecore_drm_device_pointer_left_handed_set(Ecore_Drm_Device *dev, Eina_Bool left_handed);
/**
+ * Setup a cached context to use same context for each devices
+ *
+ * This function will setup a cached context to use same context for each devices
+ * This function will be called before initialize Ecore_Drm.
+ *
+ * @param ctx struct xkb_context used in libxkbcommon
+ *
+ * @ingroup Ecore_Drm_Device_Group
+ * @since 1.17
+ */
+EAPI void ecore_drm_device_keyboard_cached_context_set(struct xkb_context *ctx);
+
+/**
+ * Setup a cached keymap to use same keymap for each devices
+ *
+ * This function will setup a cached keymap to use same keymap for each devices
+ * This function will be called before initialize Ecore_Drm.
+ *
+ * @param map struct xkb_keymap used in libxkbcommon
+ *
+ * @ingroup Ecore_Drm_Device_Group
+ * @since 1.17
+ */
+EAPI void ecore_drm_device_keyboard_cached_keymap_set(struct xkb_keymap *map);
+
+/**
* Find an Ecore_Drm_Output at the given coordinates
*
* This function will loop all the existing outputs in Ecore_Drm_Device and
diff --git a/src/lib/ecore_drm/ecore_drm_device.c b/src/lib/ecore_drm/ecore_drm_device.c
index f0c0cfe470..d3eb91f68d 100644
--- a/src/lib/ecore_drm/ecore_drm_device.c
+++ b/src/lib/ecore_drm/ecore_drm_device.c
@@ -107,6 +107,58 @@ _ecore_drm_device_cb_output_event(const char *device EINA_UNUSED, Eeze_Udev_Even
_ecore_drm_outputs_update(dev);
}
+struct xkb_context *
+_ecore_drm_device_cached_context_get(enum xkb_context_flags flags)
+{
+ if (!cached_context)
+ return xkb_context_new(flags);
+ else
+ return xkb_context_ref(cached_context);
+}
+
+struct xkb_keymap *
+_ecore_drm_device_cached_keymap_get(struct xkb_context *ctx,
+ const struct xkb_rule_names *names,
+ enum xkb_keymap_compile_flags flags)
+{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, NULL);
+
+ if (!cached_keymap)
+ return xkb_map_new_from_names(ctx, names, flags);
+ else
+ return xkb_map_ref(cached_keymap);
+}
+
+void
+_ecore_drm_device_cached_context_update(struct xkb_context *ctx)
+{
+ Eina_List *l;
+ Ecore_Drm_Device *dev;
+
+ EINA_LIST_FOREACH(drm_devices, l, dev)
+ {
+ xkb_context_unref(dev->xkb_ctx);
+ dev->xkb_ctx = xkb_context_ref(ctx);
+ }
+}
+
+void
+_ecore_drm_device_cached_keymap_update(struct xkb_keymap *map)
+{
+ Eina_List *l, *l2, *l3;
+ Ecore_Drm_Device *dev;
+ Ecore_Drm_Seat *seat;
+ Ecore_Drm_Evdev *edev;
+
+ EINA_LIST_FOREACH(drm_devices, l, dev)
+ EINA_LIST_FOREACH(dev->seats, l2, seat)
+ EINA_LIST_FOREACH(seat->devices, l3, edev)
+ {
+ xkb_keymap_unref(edev->xkb.keymap);
+ edev->xkb.keymap = xkb_keymap_ref(map);
+ }
+}
+
/**
* @defgroup Ecore_Drm_Device_Group Device manipulation functions
*
@@ -308,7 +360,7 @@ ecore_drm_device_open(Ecore_Drm_Device *dev)
}
/* try to create xkb context */
- if (!(dev->xkb_ctx = xkb_context_new(0)))
+ if (!(dev->xkb_ctx = _ecore_drm_device_cached_context_get(0)))
{
ERR("Failed to create xkb context: %m");
return EINA_FALSE;
@@ -590,3 +642,29 @@ ecore_drm_device_pointer_left_handed_set(Ecore_Drm_Device *dev, Eina_Bool left_h
}
return EINA_TRUE;
}
+
+EAPI void
+ecore_drm_device_keyboard_cached_context_set(struct xkb_context *ctx)
+{
+ EINA_SAFETY_ON_NULL_RETURN(ctx);
+
+ if (cached_context == ctx) return;
+
+ if (cached_context)
+ _ecore_drm_device_cached_context_update(ctx);
+
+ cached_context = ctx;
+}
+
+EAPI void
+ecore_drm_device_keyboard_cached_keymap_set(struct xkb_keymap *map)
+{
+ EINA_SAFETY_ON_NULL_RETURN(map);
+
+ if (cached_keymap == map) return;
+
+ if (cached_keymap)
+ _ecore_drm_device_cached_keymap_update(map);
+
+ cached_keymap = map;
+}
diff --git a/src/lib/ecore_drm/ecore_drm_evdev.c b/src/lib/ecore_drm/ecore_drm_evdev.c
index a57c7e84df..1f21dd6b76 100644
--- a/src/lib/ecore_drm/ecore_drm_evdev.c
+++ b/src/lib/ecore_drm/ecore_drm_evdev.c
@@ -116,7 +116,7 @@ _device_keyboard_setup(Ecore_Drm_Evdev *edev)
if (!input->dev->xkb_ctx) return;
/* create keymap from xkb context */
- edev->xkb.keymap = xkb_map_new_from_names(input->dev->xkb_ctx, NULL, 0);
+ edev->xkb.keymap = _ecore_drm_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
if (!edev->xkb.keymap)
{
ERR("Failed to create keymap: %m");
diff --git a/src/lib/ecore_drm/ecore_drm_private.h b/src/lib/ecore_drm/ecore_drm_private.h
index 6d30dee56b..c3ba84c14b 100644
--- a/src/lib/ecore_drm/ecore_drm_private.h
+++ b/src/lib/ecore_drm/ecore_drm_private.h
@@ -24,7 +24,6 @@
# include <linux/major.h>
# include <linux/input.h>
# include <libinput.h>
-# include <xkbcommon/xkbcommon.h>
# ifdef HAVE_SYSTEMD
# include <systemd/sd-login.h>
@@ -69,6 +68,8 @@
# endif
extern int _ecore_drm_log_dom;
+struct xkb_keymap *cached_keymap;
+struct xkb_context *cached_context;
# define EVDEV_MAX_SLOTS 32
@@ -294,4 +295,9 @@ Eina_Bool _ecore_drm_dbus_session_release(void);
void _ecore_drm_inputs_init(void);
void _ecore_drm_inputs_shutdown(void);
+
+struct xkb_context *_ecore_drm_device_cached_context_get(enum xkb_context_flags flags);
+struct xkb_keymap *_ecore_drm_device_cached_keymap_get(struct xkb_context *ctx,
+ const struct xkb_rule_names *names,
+ enum xkb_keymap_compile_flags flags);
#endif