[gtk/wip/baedert/nodeeditor: 10/11] GdkWaylandDevice: Don't recreate the default cursor every frame
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/nodeeditor: 10/11] GdkWaylandDevice: Don't recreate the default cursor every frame
- Date: Mon, 22 Apr 2019 11:51:11 +0000 (UTC)
commit 16bf64f709f3970812e38fad2646e91f20fcb385
Author: Timm Bäder <mail baedert org>
Date: Mon Apr 22 11:31:12 2019 +0200
GdkWaylandDevice: Don't recreate the default cursor every frame
Save the information whether the cursor in use is the default one, and
don't create a new cursor object in that case.
We previously created a new cursor object every frame just to compare it
to the current cursor in use and then throw it away.
gdk/wayland/gdkdevice-wayland.c | 46 +++++++++++++++++++++++++----------------
1 file changed, 28 insertions(+), 18 deletions(-)
---
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index f740e42c18..b98abcfff8 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -103,6 +103,7 @@ struct _GdkWaylandPointerData {
uint32_t grab_time;
struct wl_surface *pointer_surface;
+ guint cursor_is_default: 1;
GdkCursor *cursor;
guint cursor_timeout_id;
guint cursor_image_index;
@@ -486,9 +487,9 @@ gdk_wayland_device_update_surface_cursor (GdkDevice *device)
}
static void
-gdk_wayland_device_set_surface_cursor (GdkDevice *device,
- GdkSurface *surface,
- GdkCursor *cursor)
+gdk_wayland_device_set_surface_cursor (GdkDevice *device,
+ GdkSurface *surface,
+ GdkCursor *cursor)
{
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device));
GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
@@ -499,26 +500,35 @@ gdk_wayland_device_set_surface_cursor (GdkDevice *device,
if (seat->grab_cursor)
cursor = seat->grab_cursor;
- if (cursor == NULL)
- cursor = gdk_cursor_new_from_name ("default", NULL);
- else
- cursor = g_object_ref (cursor);
-
if (pointer->cursor != NULL &&
+ cursor != NULL &&
gdk_cursor_equal (cursor, pointer->cursor))
- {
- g_object_unref (cursor);
- return;
- }
-
- gdk_wayland_pointer_stop_cursor_animation (pointer);
+ return;
- if (pointer->cursor)
- g_object_unref (pointer->cursor);
+ if (cursor == NULL)
+ {
+ if (!pointer->cursor_is_default)
+ {
+ g_clear_object (&pointer->cursor);
+ pointer->cursor = gdk_cursor_new_from_name ("default", NULL);
+ pointer->cursor_is_default = TRUE;
- pointer->cursor = cursor;
+ gdk_wayland_pointer_stop_cursor_animation (pointer);
+ gdk_wayland_device_update_surface_cursor (device);
+ }
+ else
+ {
+ /* Nothing to do, we'already using the default cursor */
+ }
+ }
+ else
+ {
+ g_set_object (&pointer->cursor, cursor);
+ pointer->cursor_is_default = FALSE;
- gdk_wayland_device_update_surface_cursor (device);
+ gdk_wayland_pointer_stop_cursor_animation (pointer);
+ gdk_wayland_device_update_surface_cursor (device);
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]