mirror of
https://gitlab.freedesktop.org/wayland/weston
synced 2024-10-01 19:38:34 +00:00
libweston: Add and use weston_coord_surface_add/sub helpers
We already have these for global coordinates, now we have them for surface coordinates too. In addition to removing some unsightly unadorned coordinate usage, this also adds appropriate coordinate space id checks at runtime. Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
parent
cec0ab7d23
commit
720421c193
|
@ -167,6 +167,19 @@ weston_coord_global_add(struct weston_coord_global a,
|
|||
return (struct weston_coord_global){ .c = weston_coord_add(a.c, b.c) };
|
||||
}
|
||||
|
||||
static inline struct weston_coord_surface __attribute__ ((warn_unused_result))
|
||||
weston_coord_surface_add(struct weston_coord_surface a,
|
||||
struct weston_coord_surface b)
|
||||
{
|
||||
assert(a.coordinate_space_id &&
|
||||
a.coordinate_space_id == b.coordinate_space_id);
|
||||
|
||||
return (struct weston_coord_surface){
|
||||
.c = weston_coord_add(a.c, b.c),
|
||||
.coordinate_space_id = a.coordinate_space_id,
|
||||
};
|
||||
}
|
||||
|
||||
static inline struct weston_coord __attribute__ ((warn_unused_result))
|
||||
weston_coord_sub(struct weston_coord a, struct weston_coord b)
|
||||
{
|
||||
|
@ -180,6 +193,19 @@ weston_coord_global_sub(struct weston_coord_global a,
|
|||
return (struct weston_coord_global){ .c = weston_coord_sub(a.c, b.c) };
|
||||
}
|
||||
|
||||
static inline struct weston_coord_surface __attribute__ ((warn_unused_result))
|
||||
weston_coord_surface_sub(struct weston_coord_surface a,
|
||||
struct weston_coord_surface b)
|
||||
{
|
||||
assert(a.coordinate_space_id &&
|
||||
a.coordinate_space_id == b.coordinate_space_id);
|
||||
|
||||
return (struct weston_coord_surface){
|
||||
.c = weston_coord_sub(a.c, b.c),
|
||||
.coordinate_space_id = a.coordinate_space_id,
|
||||
};
|
||||
}
|
||||
|
||||
static inline struct weston_coord __attribute__ ((warn_unused_result))
|
||||
weston_coord_truncate(struct weston_coord in)
|
||||
{
|
||||
|
|
|
@ -4816,8 +4816,8 @@ weston_subsurface_commit_to_cache(struct weston_subsurface *sub)
|
|||
sub->cached.protection_mode = surface->pending.protection_mode;
|
||||
assert(surface->pending.acquire_fence_fd == -1);
|
||||
assert(surface->pending.buffer_release_ref.buffer_release == NULL);
|
||||
sub->cached.buf_offset.c = weston_coord_add(sub->cached.buf_offset.c,
|
||||
surface->pending.buf_offset.c);
|
||||
sub->cached.buf_offset = weston_coord_surface_add(sub->cached.buf_offset,
|
||||
surface->pending.buf_offset);
|
||||
|
||||
sub->cached.buffer_viewport.buffer =
|
||||
surface->pending.buffer_viewport.buffer;
|
||||
|
@ -4958,8 +4958,9 @@ subsurface_committed(struct weston_surface *surface,
|
|||
continue;
|
||||
}
|
||||
|
||||
new_origin.coordinate_space_id = view->geometry.parent->surface;
|
||||
tmp = weston_view_get_pos_offset_rel(view);
|
||||
tmp.c = weston_coord_add(tmp.c, new_origin.c);
|
||||
tmp = weston_coord_surface_add(tmp, new_origin);
|
||||
weston_view_set_rel_position(view, tmp);
|
||||
}
|
||||
/* No need to check parent mappedness, because if parent is not
|
||||
|
|
|
@ -435,9 +435,7 @@ drag_surface_configure(struct weston_drag *drag,
|
|||
drag->icon->is_mapped = true;
|
||||
}
|
||||
|
||||
assert(drag->offset.coordinate_space_id &&
|
||||
drag->offset.coordinate_space_id == new_origin.coordinate_space_id);
|
||||
drag->offset.c = weston_coord_add(drag->offset.c, new_origin.c);
|
||||
drag->offset = weston_coord_surface_add(drag->offset, new_origin);
|
||||
|
||||
/* init to 0 for avoiding a compile warning */
|
||||
pos.c = weston_coord(0, 0);
|
||||
|
|
|
@ -3215,7 +3215,7 @@ tablet_tool_cursor_surface_committed(struct weston_surface *es,
|
|||
|
||||
assert(es == tool->sprite->surface);
|
||||
|
||||
tool->hotspot.c = weston_coord_sub(tool->hotspot.c, new_origin.c);
|
||||
tool->hotspot = weston_coord_surface_sub(tool->hotspot, new_origin);
|
||||
hotspot_inv = weston_coord_surface_invert(tool->hotspot);
|
||||
weston_view_set_position_with_offset(tool->sprite,
|
||||
tool->pos, hotspot_inv);
|
||||
|
@ -3510,8 +3510,8 @@ pointer_cursor_surface_committed(struct weston_surface *es,
|
|||
|
||||
assert(es == pointer->sprite->surface);
|
||||
|
||||
pointer->hotspot.c = weston_coord_sub(pointer->hotspot.c,
|
||||
new_origin.c);
|
||||
pointer->hotspot = weston_coord_surface_sub(pointer->hotspot,
|
||||
new_origin);
|
||||
hotspot_inv = weston_coord_surface_invert(pointer->hotspot);
|
||||
weston_view_set_position_with_offset(pointer->sprite,
|
||||
pointer->pos, hotspot_inv);
|
||||
|
|
Loading…
Reference in a new issue