wayland: Remove overly complex cursor cache

This commit is contained in:
Jasper St. Pierre 2014-08-10 12:15:40 -04:00
parent cb60da5f6b
commit a07fc2f85d
4 changed files with 19 additions and 65 deletions

View File

@ -68,66 +68,16 @@ struct _GdkWaylandCursorClass
G_DEFINE_TYPE (GdkWaylandCursor, _gdk_wayland_cursor, GDK_TYPE_CURSOR)
struct cursor_cache_key
void
_gdk_wayland_display_init_cursors (GdkWaylandDisplay *display)
{
GdkCursorType type;
const char *name;
};
static void
add_to_cache (GdkWaylandDisplay *display, GdkWaylandCursor *cursor)
{
display->cursor_cache = g_slist_prepend (display->cursor_cache, cursor);
g_object_ref (cursor);
display->cursor_cache = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
}
static gint
cache_compare_func (gconstpointer listelem,
gconstpointer target)
{
GdkWaylandCursor *cursor = (GdkWaylandCursor *) listelem;
struct cursor_cache_key* key = (struct cursor_cache_key *) target;
if (cursor->cursor.type != key->type)
return 1; /* No match */
/* Elements marked as pixmap must be named cursors
* (since we don't store normal pixmap cursors
*/
if (key->type == GDK_CURSOR_IS_PIXMAP)
return strcmp (key->name, cursor->name);
return 0; /* Match */
}
static GdkWaylandCursor*
find_in_cache (GdkWaylandDisplay *display,
GdkCursorType type,
const char *name)
{
GSList* res;
struct cursor_cache_key key;
key.type = type;
key.name = name;
res = g_slist_find_custom (display->cursor_cache, &key, cache_compare_func);
if (res)
return (GdkWaylandCursor *) res->data;
return NULL;
}
/* Called by gdk_wayland_display_finalize to flush any cached cursors
* for a dead display.
*/
void
_gdk_wayland_display_finalize_cursors (GdkWaylandDisplay *display)
{
g_slist_foreach (display->cursor_cache, (GFunc) g_object_unref, NULL);
g_slist_free (display->cursor_cache);
g_hash_table_destroy (display->cursor_cache);
}
static gboolean
@ -156,7 +106,14 @@ void
_gdk_wayland_display_update_cursors (GdkWaylandDisplay *display,
struct wl_cursor_theme *theme)
{
g_slist_foreach (display->cursor_cache, (GFunc) set_cursor_from_theme, theme);
GHashTableIter iter;
const char *name;
GdkWaylandCursor *cursor;
g_hash_table_iter_init (&iter, display->cursor_cache);
while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &cursor))
set_cursor_from_theme (cursor, theme);
}
static void
@ -302,14 +259,9 @@ _gdk_wayland_display_get_cursor_for_name (GdkDisplay *display,
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
private = find_in_cache (wayland_display, GDK_CURSOR_IS_PIXMAP, name);
private = g_hash_table_lookup (wayland_display->cursor_cache, name);
if (private)
{
/* Cache had it, add a ref for this user */
g_object_ref (private);
return (GdkCursor*) private;
}
return GDK_CURSOR (g_object_ref (private));
private = g_object_new (GDK_TYPE_WAYLAND_CURSOR,
"cursor-type", GDK_CURSOR_IS_PIXMAP,
@ -325,8 +277,8 @@ _gdk_wayland_display_get_cursor_for_name (GdkDisplay *display,
if (!set_cursor_from_theme (private, wayland_display->cursor_theme))
return GDK_CURSOR (private);
add_to_cache (wayland_display, private);
/* Insert into cache. */
g_hash_table_insert (wayland_display->cursor_cache, private->name, g_object_ref (private));
return GDK_CURSOR (private);
}

View File

@ -232,6 +232,7 @@ _gdk_wayland_display_open (const gchar *display_name)
/* Wait until the dust has settled during init... */
wl_display_roundtrip (display_wayland->wl_display);
_gdk_wayland_display_init_cursors (display_wayland);
gdk_input_init (display);
g_signal_emit_by_name (display, "opened");

View File

@ -64,7 +64,7 @@ struct _GdkWaylandDisplay
struct wl_data_device_manager *data_device_manager;
struct wl_cursor_theme *cursor_theme;
GSList *cursor_cache;
GHashTable *cursor_cache;
GSource *event_source;

View File

@ -52,6 +52,7 @@ struct xkb_keymap *_gdk_wayland_keymap_get_xkb_keymap (GdkKeymap *keymap);
gboolean _gdk_wayland_keymap_key_is_modifier (GdkKeymap *keymap,
guint keycode);
void _gdk_wayland_display_init_cursors (GdkWaylandDisplay *display);
void _gdk_wayland_display_finalize_cursors (GdkWaylandDisplay *display);
void _gdk_wayland_display_update_cursors (GdkWaylandDisplay *display,
struct wl_cursor_theme *theme);