[PATCH 3/4] compositor: only update drag surfaces during output repaint

Ander Conselvan de Oliveira ander.conselvan.de.oliveira at intel.com
Tue Apr 3 05:44:17 PDT 2012


Drag surfaces were being updated in notify_* so that the relative
distance between the drag surface and the cursor hotspot was kept.
Instead, store the offset on the input device and update on
drag_surface_configure(), that way we can update its position only
once per frame.
---
 src/compositor.c |   35 ++++++++++++++++-------------------
 src/compositor.h |    3 ++-
 2 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 3d70853..0ed57de 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1442,10 +1442,6 @@ idle_handler(void *data)
 	return 1;
 }
 
-static  void
-weston_input_update_drag_surface(struct wl_input_device *input_device,
-				 int dx, int dy);
-
 WL_EXPORT void
 notify_motion(struct wl_input_device *device, uint32_t time, int x, int y)
 {
@@ -1490,9 +1486,6 @@ notify_motion(struct wl_input_device *device, uint32_t time, int x, int y)
 			y = max_y;
 	}
 
-	weston_input_update_drag_surface(device,
-					 x - device->x, y - device->y);
-
 	device->x = x;
 	device->y = y;
 
@@ -1644,9 +1637,6 @@ notify_pointer_focus(struct wl_input_device *device,
 	struct weston_compositor *compositor = wd->compositor;
 
 	if (output) {
-		weston_input_update_drag_surface(device, x - device->x,
-						 y - device->y);
-
 		device->x = x;
 		device->y = y;
 		compositor->focus = 1;
@@ -1935,6 +1925,9 @@ bind_input_device(struct wl_client *client,
 	resource->destroy = unbind_input_device;
 }
 
+static  void
+weston_input_update_drag_surface(struct wl_input_device *input_device);
+
 static void
 device_handle_new_drag_icon(struct wl_listener *listener,
 			    struct wl_resource *resource, uint32_t time)
@@ -1944,7 +1937,7 @@ device_handle_new_drag_icon(struct wl_listener *listener,
 	device = container_of(listener, struct weston_input_device,
 			      new_drag_icon_listener);
 
-	weston_input_update_drag_surface(&device->input_device, 0, 0);
+	weston_input_update_drag_surface(&device->input_device);
 }
 
 WL_EXPORT void
@@ -2010,9 +2003,15 @@ weston_compositor_update_cursor_sprites(struct weston_compositor *compositor)
 static void
 drag_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
 {
+	struct weston_input_device *device = (struct weston_input_device *)
+		es->compositor->input_device;
+
 	weston_surface_configure(es,
 				 es->geometry.x + sx, es->geometry.y + sy,
 				 es->buffer->width, es->buffer->height);
+
+	device->drag_surf_x += sx;
+	device->drag_surf_y += sy;
 }
 
 static int
@@ -2032,6 +2031,8 @@ device_setup_new_drag_surface(struct weston_input_device *device,
 
 	weston_surface_set_position(device->drag_surface,
 				    input_device->x, input_device->y);
+	device->drag_surf_x = 0;
+	device->drag_surf_y = 0;
 
 	surface->configure = drag_surface_configure;
 
@@ -2064,8 +2065,7 @@ device_map_drag_surface(struct weston_input_device *device)
 }
 
 static  void
-weston_input_update_drag_surface(struct wl_input_device *input_device,
-				 int dx, int dy)
+weston_input_update_drag_surface(struct wl_input_device *input_device)
 {
 	int surface_changed = 0;
 	struct weston_input_device *device = (struct weston_input_device *)
@@ -2102,18 +2102,15 @@ weston_input_update_drag_surface(struct wl_input_device *input_device,
 	if (region_is_undefined(&device->drag_surface->input))
 		empty_region(&device->drag_surface->input);
 
-	if (!dx && !dy)
-		return;
-
 	weston_surface_set_position(device->drag_surface,
-				    device->drag_surface->geometry.x + dx,
-				    device->drag_surface->geometry.y + dy);
+				    device->input_device.x + device->drag_surf_x,
+				    device->input_device.y + device->drag_surf_y);
 }
 
 WL_EXPORT void
 weston_compositor_update_drag_surfaces(struct weston_compositor *compositor)
 {
-	weston_input_update_drag_surface(compositor->input_device, 0, 0);
+	weston_input_update_drag_surface(compositor->input_device);
 }
 
 static void
diff --git a/src/compositor.h b/src/compositor.h
index a0ce4df..adfae41 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -107,9 +107,10 @@ struct weston_input_device {
 	struct wl_input_device input_device;
 	struct weston_compositor *compositor;
 	struct weston_surface *sprite;
+	int32_t hotspot_x, hotspot_y;
 	struct weston_surface *drag_surface;
 	struct wl_listener drag_surface_destroy_listener;
-	int32_t hotspot_x, hotspot_y;
+	int32_t drag_surf_x, drag_surf_y;
 	struct wl_list link;
 	uint32_t modifier_state;
 	int hw_cursor;
-- 
1.7.4.1



More information about the wayland-devel mailing list