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
This commit is contained in:
JengHyun Kang 2016-01-04 08:47:43 -05:00 committed by Chris Michael
parent fe70f0c080
commit b3dc27345a
4 changed files with 114 additions and 3 deletions

View File

@ -6,6 +6,7 @@
# include <drm_fourcc.h>
# include <Ecore.h>
# include <Eeze.h>
# include <xkbcommon/xkbcommon.h>
# ifdef EAPI
# undef EAPI
@ -381,6 +382,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
*

View File

@ -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;
}

View File

@ -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");

View File

@ -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