From fcac52c3d0395cb45df220eff89531da1e42d2d4 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Fri, 21 Oct 2022 14:41:52 +0900 Subject: [PATCH 01/16] Use DS_ASSERT macro instead of assert() Change-Id: Iecf32f4173556f50c913c50d58338062ae1daf24 --- examples/libinput-backend.c | 2 ++ src/addon.c | 6 +++--- src/allocator/shm.c | 4 ++-- src/backend/libinput/backend.c | 3 ++- src/backend/libinput/input.c | 3 ++- src/backend/wayland/backend.c | 3 ++- src/backend/wayland/output.c | 3 ++- src/backend/wayland/seat.c | 9 ++++----- src/buffer.c | 20 ++++++++++---------- src/client_buffer/shm_client_buffer.c | 6 +++--- src/data_device/data_offer.c | 5 +++-- src/data_device/data_source.c | 4 ++-- src/data_device/data_source_client.c | 10 +++++----- src/data_device/drag.c | 7 ++++--- src/output.c | 5 +++-- src/region.c | 6 +++--- src/seat/seat.c | 4 ++-- src/seat/seat_pointer.c | 6 +++--- src/shell_surface.c | 6 +++--- src/surface/subsurface.c | 6 +++--- src/surface/surface.c | 19 +++++++++---------- src/swapchain.c | 9 +++++---- src/xdg_shell/xdg_surface.c | 8 ++++---- src/xdg_shell/xdg_toplevel.c | 6 +++--- src/xdg_shell_v6/xdg_surface_v6.c | 8 ++++---- src/xdg_shell_v6/xdg_toplevel_v6.c | 4 ++-- 26 files changed, 90 insertions(+), 82 deletions(-) diff --git a/examples/libinput-backend.c b/examples/libinput-backend.c index 592fbc3..19a21af 100644 --- a/examples/libinput-backend.c +++ b/examples/libinput-backend.c @@ -9,6 +9,8 @@ #include #include +#include "util.h" + #define UNUSED __attribute__((unused)) struct keyboard_device diff --git a/src/addon.c b/src/addon.c index e1858ff..0deac7a 100644 --- a/src/addon.c +++ b/src/addon.c @@ -1,5 +1,6 @@ #include +#include "util.h" #include "addon.h" void @@ -25,11 +26,10 @@ ds_addon_init(struct ds_addon *addon, struct ds_addon_set *set, { struct ds_addon *iter; - assert(owner && impl); + DS_ASSERT(owner && impl); wl_list_for_each(iter, &set->addons, link) { - if (iter->owner == addon->owner && iter->impl == addon->impl) - assert(0 && "Can't have two addons of the same type with the same owner"); + DS_ASSERT(iter->owner == addon->owner && iter->impl == addon->impl); } wl_list_insert(&set->addons, &addon->link); diff --git a/src/allocator/shm.c b/src/allocator/shm.c index 96a0210..36f3709 100644 --- a/src/allocator/shm.c +++ b/src/allocator/shm.c @@ -47,7 +47,7 @@ ds_shm_allocator_create(void) static struct ds_shm_allocator * shm_allocator_from_allocator(struct ds_allocator *ds_allocator) { - assert(ds_allocator->iface == &shm_allocator_iface); + DS_ASSERT(ds_allocator->iface == &shm_allocator_iface); return (struct ds_shm_allocator *)ds_allocator; } @@ -66,7 +66,7 @@ static const struct ds_buffer_interface shm_buffer_interface; static struct ds_shm_buffer * shm_buffer_from_buffer(struct ds_buffer *buffer) { - assert(buffer->iface == &shm_buffer_interface); + DS_ASSERT(buffer->iface == &shm_buffer_interface); return (struct ds_shm_buffer *)buffer; } diff --git a/src/backend/libinput/backend.c b/src/backend/libinput/backend.c index 22c07e0..8b0c8fd 100644 --- a/src/backend/libinput/backend.c +++ b/src/backend/libinput/backend.c @@ -8,6 +8,7 @@ #include "libds/log.h" +#include "util.h" #include "backend.h" static const struct ds_backend_interface libinput_backend_interface; @@ -44,7 +45,7 @@ ds_libinput_backend_create(struct wl_display *display) WL_EXPORT struct ds_libinput_backend * libinput_backend_from_backend(struct ds_backend *backend) { - assert(backend->iface == &libinput_backend_interface); + DS_ASSERT(backend->iface == &libinput_backend_interface); return (struct ds_libinput_backend *)backend; } diff --git a/src/backend/libinput/input.c b/src/backend/libinput/input.c index b6e943f..89ea635 100644 --- a/src/backend/libinput/input.c +++ b/src/backend/libinput/input.c @@ -1,6 +1,7 @@ #include #include "libds/log.h" +#include "util.h" #include "backend.h" static const struct ds_input_device_interface input_device_iface; @@ -14,7 +15,7 @@ ds_input_device_is_libinput(struct ds_input_device *ds_dev) static struct ds_libinput_input_device * get_libinput_input_device_from_input_device(struct ds_input_device *ds_dev) { - assert(ds_input_device_is_libinput(ds_dev)); + DS_ASSERT(ds_input_device_is_libinput(ds_dev)); return (struct ds_libinput_input_device *)ds_dev; } diff --git a/src/backend/wayland/backend.c b/src/backend/wayland/backend.c index 300cb36..4c8c9c8 100644 --- a/src/backend/wayland/backend.c +++ b/src/backend/wayland/backend.c @@ -9,6 +9,7 @@ #include "libds/output.h" #include "xdg-shell-client-protocol.h" +#include "util.h" #include "backend.h" static const struct ds_backend_interface wl_backend_interface; @@ -78,7 +79,7 @@ err_server: struct ds_wl_backend * wl_backend_from_backend(struct ds_backend *backend) { - assert(backend->iface == &wl_backend_interface); + DS_ASSERT(backend->iface == &wl_backend_interface); return (struct ds_wl_backend *)backend; } diff --git a/src/backend/wayland/output.c b/src/backend/wayland/output.c index 50fd7c8..285f1ac 100644 --- a/src/backend/wayland/output.c +++ b/src/backend/wayland/output.c @@ -7,6 +7,7 @@ #include "libds/output.h" #include "xdg-shell-client-protocol.h" +#include "util.h" #include "output.h" #include "backend.h" @@ -163,7 +164,7 @@ static void output_update_cursor(struct ds_wl_output *output) static struct ds_wl_output * wl_output_from_output(struct ds_output *ds_output) { - assert(ds_output->iface == &wl_output_iface); + DS_ASSERT(ds_output->iface == &wl_output_iface); return (struct ds_wl_output *)ds_output; } diff --git a/src/backend/wayland/seat.c b/src/backend/wayland/seat.c index bec12ad..8376ebf 100644 --- a/src/backend/wayland/seat.c +++ b/src/backend/wayland/seat.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -196,7 +195,7 @@ ds_input_device_is_wl(struct ds_input_device *ds_dev) static struct ds_wl_input_device * get_wl_input_device_from_input_device(struct ds_input_device *ds_dev) { - assert(ds_input_device_is_wl(ds_dev)); + DS_ASSERT(ds_input_device_is_wl(ds_dev)); return (struct ds_wl_input_device *)ds_dev; } @@ -246,7 +245,7 @@ static const struct ds_pointer_interface pointer_iface; static struct ds_wl_pointer * get_wl_pointer_from_pointer(struct ds_pointer *ds_pointer) { - assert(ds_pointer->iface == &pointer_iface); + DS_ASSERT(ds_pointer->iface == &pointer_iface); return (struct ds_wl_pointer *)ds_pointer; } @@ -427,7 +426,7 @@ static const struct ds_keyboard_interface keyboard_iface; static struct ds_wl_keyboard * get_wl_keyboard_from_keyboard(struct ds_keyboard *ds_keyboard) { - assert(ds_keyboard->iface == &keyboard_iface); + DS_ASSERT(ds_keyboard->iface == &keyboard_iface); return (struct ds_wl_keyboard *)ds_keyboard; } @@ -615,7 +614,7 @@ static const struct ds_touch_interface touch_iface; static struct ds_wl_touch * get_wl_touch_from_touch(struct ds_touch *ds_touch) { - assert(ds_touch->iface == &touch_iface); + DS_ASSERT(ds_touch->iface == &touch_iface); return (struct ds_wl_touch *)ds_touch; } diff --git a/src/buffer.c b/src/buffer.c index 4571679..6d0650b 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1,9 +1,9 @@ -#include #include #include "libds/log.h" #include "libds/interfaces/buffer.h" +#include "util.h" #include "buffer.h" #include "client_buffer.h" @@ -32,7 +32,7 @@ ds_buffer_from_resource(struct wl_resource *resource) struct ds_buffer *buffer; const struct ds_buffer_resource_interface *iface; - assert(resource && ds_resource_is_buffer(resource)); + DS_ASSERT(resource && ds_resource_is_buffer(resource)); if (wl_shm_buffer_get(resource) != NULL) { struct ds_shm_client_buffer *shm_client_buffer = @@ -66,7 +66,7 @@ ds_buffer_from_resource(struct wl_resource *resource) WL_EXPORT void ds_buffer_drop(struct ds_buffer *buffer) { - assert(!buffer->dropped); + DS_ASSERT(!buffer->dropped); buffer->dropped = true; ds_dbg("Buffer(%p) dropped: n_locks(%zu)", buffer, buffer->n_locks); buffer_consider_destroy(buffer); @@ -83,7 +83,7 @@ ds_buffer_lock(struct ds_buffer *buffer) WL_EXPORT void ds_buffer_unlock(struct ds_buffer *buffer) { - assert(buffer->n_locks > 0); + DS_ASSERT(buffer->n_locks > 0); buffer->n_locks--; ds_dbg("Buffer(%p) n_locks(%zu)", buffer, buffer->n_locks); @@ -97,7 +97,7 @@ WL_EXPORT bool ds_buffer_begin_data_ptr_access(struct ds_buffer *buffer, uint32_t flags, void **data, uint32_t *format, size_t *stride) { - assert(!buffer->accessing_data_ptr); + DS_ASSERT(!buffer->accessing_data_ptr); if (!buffer->iface->begin_data_ptr_access) return false; if (!buffer->iface->begin_data_ptr_access(buffer, @@ -110,7 +110,7 @@ ds_buffer_begin_data_ptr_access(struct ds_buffer *buffer, uint32_t flags, WL_EXPORT void ds_buffer_end_data_ptr_access(struct ds_buffer *buffer) { - assert(buffer->accessing_data_ptr); + DS_ASSERT(buffer->accessing_data_ptr); buffer->iface->end_data_ptr_access(buffer); buffer->accessing_data_ptr = false; } @@ -153,9 +153,9 @@ ds_buffer_register_resource_interface( { const struct ds_buffer_resource_interface **iface_ptr; - assert(iface); - assert(iface->is_instance); - assert(iface->from_resource); + DS_ASSERT(iface); + DS_ASSERT(iface->is_instance); + DS_ASSERT(iface->from_resource); wl_array_for_each(iface_ptr, &buffer_resource_interfaces) { if (*iface_ptr == iface) { @@ -189,7 +189,7 @@ buffer_consider_destroy(struct ds_buffer *buffer) if (!buffer->dropped || buffer->n_locks > 0) return; - assert(!buffer->accessing_data_ptr); + DS_ASSERT(!buffer->accessing_data_ptr); wl_signal_emit(&buffer->events.destroy, NULL); buffer->iface->destroy(buffer); diff --git a/src/client_buffer/shm_client_buffer.c b/src/client_buffer/shm_client_buffer.c index 73d97ea..0b31b7f 100644 --- a/src/client_buffer/shm_client_buffer.c +++ b/src/client_buffer/shm_client_buffer.c @@ -1,10 +1,10 @@ -#include #include #include #include "libds/log.h" +#include "util.h" #include "pixel_format.h" #include "buffer.h" #include "client_buffer.h" @@ -52,7 +52,7 @@ static const struct ds_buffer_interface shm_client_buffer_iface; static struct ds_shm_client_buffer * shm_client_buffer_from_buffer(struct ds_buffer *buffer) { - assert(buffer->iface == &shm_client_buffer_iface); + DS_ASSERT(buffer->iface == &shm_client_buffer_iface); return (struct ds_shm_client_buffer *)buffer; } @@ -140,7 +140,7 @@ shm_client_buffer_create(struct wl_resource *resource) int32_t height; shm_buffer = wl_shm_buffer_get(resource); - assert(shm_buffer); + DS_ASSERT(shm_buffer); width = wl_shm_buffer_get_width(shm_buffer); height = wl_shm_buffer_get_height(shm_buffer); diff --git a/src/data_device/data_offer.c b/src/data_device/data_offer.c index e12f5ef..fc17b66 100644 --- a/src/data_device/data_offer.c +++ b/src/data_device/data_offer.c @@ -3,6 +3,7 @@ #include #include "libds/log.h" +#include "util.h" #include "data_device_private.h" static const struct wl_data_offer_interface data_offer_iface; @@ -58,7 +59,7 @@ create_data_offer(struct wl_resource *device_resource, wl_list_insert(&data_device->drag_offers, &offer->link); break; default: - assert(0 && "cannot reach here"); + DS_ASSERT_NOT_REACHED(); break; } @@ -86,7 +87,7 @@ data_offer_update_action(struct ds_data_offer *offer) { uint32_t action; - assert(offer->type == DS_DATA_OFFER_DRAG); + DS_ASSERT(offer->type == DS_DATA_OFFER_DRAG); action = data_offer_choose_action(offer); if (offer->source->current_dnd_action == action) diff --git a/src/data_device/data_source.c b/src/data_device/data_source.c index f18472a..6a18e3b 100644 --- a/src/data_device/data_source.c +++ b/src/data_device/data_source.c @@ -1,13 +1,13 @@ -#include #include +#include "util.h" #include "data_device_private.h" void ds_data_source_init(struct ds_data_source *source, const struct ds_data_source_interface *iface) { - assert(iface->send); + DS_ASSERT(iface->send); source->iface = iface; source->actions = -1; diff --git a/src/data_device/data_source_client.c b/src/data_device/data_source_client.c index 60aafeb..b647e27 100644 --- a/src/data_device/data_source_client.c +++ b/src/data_device/data_source_client.c @@ -1,7 +1,7 @@ -#include #include #include "libds/log.h" +#include "util.h" #include "data_device_private.h" static const struct wl_data_source_interface wl_data_source_iface; @@ -169,7 +169,7 @@ static const struct wl_data_source_interface wl_data_source_iface = { static struct ds_data_source_client * data_source_client_from_data_source(struct ds_data_source *ds_source) { - assert(ds_source->iface->accept == data_source_client_iface_accept); + DS_ASSERT(ds_source->iface->accept == data_source_client_iface_accept); return (struct ds_data_source_client *)ds_source; } @@ -211,7 +211,7 @@ data_source_client_iface_dnd_drop(struct ds_data_source *ds_source) struct ds_data_source_client *source; source = data_source_client_from_data_source(ds_source); - assert(wl_resource_get_version(source->resource) >= + DS_ASSERT(wl_resource_get_version(source->resource) >= WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION); wl_data_source_send_dnd_drop_performed(source->resource); } @@ -222,7 +222,7 @@ data_source_client_iface_dnd_finish(struct ds_data_source *ds_source) struct ds_data_source_client *source; source = data_source_client_from_data_source(ds_source); - assert(wl_resource_get_version(source->resource) >= + DS_ASSERT(wl_resource_get_version(source->resource) >= WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION); wl_data_source_send_dnd_finished(source->resource); } @@ -234,7 +234,7 @@ data_source_client_iface_dnd_action(struct ds_data_source *ds_source, struct ds_data_source_client *source; source = data_source_client_from_data_source(ds_source); - assert(wl_resource_get_version(source->resource) >= + DS_ASSERT(wl_resource_get_version(source->resource) >= WL_DATA_SOURCE_ACTION_SINCE_VERSION); wl_data_source_send_action(source->resource, action); } diff --git a/src/data_device/drag.c b/src/data_device/drag.c index c13acb4..1500682 100644 --- a/src/data_device/drag.c +++ b/src/data_device/drag.c @@ -1,5 +1,6 @@ -#include #include + +#include "util.h" #include "data_device_private.h" static const struct ds_pointer_grab_interface drag_pointer_grab_iface; @@ -501,7 +502,7 @@ static const struct ds_keyboard_grab_interface drag_keyboard_grab_iface = { static void drag_start(struct ds_drag *drag, uint32_t serial) { - assert(!drag->started); + DS_ASSERT(!drag->started); drag->started = true; ds_seat_keyboard_start_grab(drag->seat, &drag->keyboard_grab); @@ -531,7 +532,7 @@ drag_drop(struct ds_drag *drag, uint32_t time) struct ds_data_device *data_device; struct wl_resource *resource; - assert(drag->focused_client); + DS_ASSERT(drag->focused_client); drag->dropped = true; diff --git a/src/output.c b/src/output.c index 1e34c86..de48b37 100644 --- a/src/output.c +++ b/src/output.c @@ -1,10 +1,11 @@ -#include #include #include "libds/log.h" #include "libds/output.h" #include "libds/interfaces/output.h" +#include "util.h" + #define OUTPUT_VERSION 3 static void output_handle_display_destroy(struct wl_listener *listener, @@ -28,7 +29,7 @@ WL_EXPORT void ds_output_init(struct ds_output *output, struct ds_backend *backend, const struct ds_output_interface *iface, struct wl_display *display) { - assert(iface->commit); + DS_ASSERT(iface->commit); output->backend = backend; output->iface = iface; diff --git a/src/region.c b/src/region.c index 52e62c7..61b0117 100644 --- a/src/region.c +++ b/src/region.c @@ -1,10 +1,10 @@ -#include #include #include #include #include "libds/log.h" +#include "util.h" #include "region.h" static const struct wl_region_interface region_impl; @@ -39,7 +39,7 @@ ds_region_add(struct wl_client *client, uint32_t version, uint32_t id) pixman_region32_t * ds_region_from_resource(struct wl_resource *resource) { - assert(wl_resource_instance_of(resource, &wl_region_interface, + DS_ASSERT(wl_resource_instance_of(resource, &wl_region_interface, ®ion_impl)); return wl_resource_get_user_data(resource); } @@ -107,7 +107,7 @@ ds_region_transform(pixman_region32_t *dst, pixman_region32_t *src, break; default: ds_err("Unknown transform value(%d)", transform); - assert(0 && "Cannot reach here"); + DS_ASSERT_NOT_REACHED(); break; } } diff --git a/src/seat/seat.c b/src/seat/seat.c index 7fd884a..ca9c2e9 100644 --- a/src/seat/seat.c +++ b/src/seat/seat.c @@ -1,12 +1,12 @@ #include "config.h" -#include #define _POSIX_C_SOURCE 200809L #include #include #include #include "libds/log.h" +#include "util.h" #include "data_device.h" #include "seat_private.h" @@ -162,7 +162,7 @@ ds_seat_client_for_wl_client(struct ds_seat *seat, struct wl_client *wl_client) WL_EXPORT struct ds_seat_client * ds_seat_client_from_resource(struct wl_resource *resource) { - assert(wl_resource_instance_of(resource, &wl_seat_interface, &seat_impl)); + DS_ASSERT(wl_resource_instance_of(resource, &wl_seat_interface, &seat_impl)); return wl_resource_get_user_data(resource); } diff --git a/src/seat/seat_pointer.c b/src/seat/seat_pointer.c index f8fb169..fc18769 100644 --- a/src/seat/seat_pointer.c +++ b/src/seat/seat_pointer.c @@ -1,8 +1,8 @@ -#include #include #include #include +#include "util.h" #include "seat_private.h" static const struct ds_pointer_grab_interface default_pointer_grab_iface; @@ -36,7 +36,7 @@ ds_seat_pointer_notify_enter(struct ds_seat *seat, struct ds_surface *surface, { struct ds_seat_pointer_grab *grab = seat->pointer.grab; - assert(surface); + DS_ASSERT(surface); grab->iface->enter(grab, surface, sx, sy); } @@ -237,7 +237,7 @@ ds_seat_pointer_send_axis(struct ds_seat *seat, uint32_t time_msec, return; if (pointer->sent_axis_source) { - assert(pointer->cached_axis_source == source); + DS_ASSERT(pointer->cached_axis_source == source); } else { pointer->sent_axis_source = true; diff --git a/src/shell_surface.c b/src/shell_surface.c index 73c498b..18e0056 100644 --- a/src/shell_surface.c +++ b/src/shell_surface.c @@ -1,9 +1,9 @@ -#include #include #include #include "libds/log.h" +#include "util.h" #include "shell.h" static const struct wl_shell_surface_interface shell_surface_impl; @@ -151,7 +151,7 @@ unmap_shell_surface(struct ds_shell_surface *shell_surface) // TODO break; case DS_SHELL_SURFACE_ROLE_NONE: - assert(false && "not reached"); + DS_ASSERT_NOT_REACHED(); } wl_list_for_each_safe(configure, tmp, &shell_surface->configure_list, link) @@ -324,7 +324,7 @@ shell_surface_configure_destroy(struct ds_shell_surface_configure *configure) static void create_shell_surface_toplevel(struct ds_shell_surface *shell_surface) { - assert(shell_surface->toplevel == NULL); + DS_ASSERT(shell_surface->toplevel == NULL); shell_surface->toplevel = calloc(1, sizeof *shell_surface->toplevel); if (!shell_surface->toplevel) { diff --git a/src/surface/subsurface.c b/src/surface/subsurface.c index 080513f..eafa38a 100644 --- a/src/surface/subsurface.c +++ b/src/surface/subsurface.c @@ -1,9 +1,9 @@ -#include #include #include "libds/log.h" #include "libds/surface.h" +#include "util.h" #include "surface-private.h" static const struct wl_subsurface_interface subsurface_impl; @@ -79,7 +79,7 @@ ds_surface_is_subsurface(struct ds_surface *surface) WL_EXPORT struct ds_subsurface * ds_subsurface_from_resource(struct wl_resource *resource) { - assert(wl_resource_instance_of(resource, &wl_subsurface_interface, + DS_ASSERT(wl_resource_instance_of(resource, &wl_subsurface_interface, &subsurface_impl)); return wl_resource_get_user_data(resource); } @@ -87,7 +87,7 @@ ds_subsurface_from_resource(struct wl_resource *resource) struct ds_subsurface * ds_subsurface_from_ds_surface(struct ds_surface *surface) { - assert(ds_surface_is_subsurface(surface)); + DS_ASSERT(ds_surface_is_subsurface(surface)); return (struct ds_subsurface *)surface->role_data; } diff --git a/src/surface/surface.c b/src/surface/surface.c index 4c5a853..f4f86f6 100644 --- a/src/surface/surface.c +++ b/src/surface/surface.c @@ -1,4 +1,3 @@ -#include #include #include "libds/log.h" @@ -73,7 +72,7 @@ ds_surface_send_frame_done(struct ds_surface *surface, WL_EXPORT struct ds_surface * ds_surface_from_resource(struct wl_resource *resource) { - assert(wl_resource_instance_of(resource, &wl_surface_interface, + DS_ASSERT(wl_resource_instance_of(resource, &wl_surface_interface, &surface_impl)); return wl_resource_get_user_data(resource); } @@ -83,7 +82,7 @@ ds_surface_set_role(struct ds_surface *surface, const struct ds_surface_role *role, void *role_data, struct wl_resource *error_resource, uint32_t error_code) { - assert(role != NULL); + DS_ASSERT(role != NULL); if (surface->role != NULL && surface->role != role) { ds_err("Cannot assign role %s to ds_surface(%p) " @@ -155,7 +154,7 @@ ds_surface_take_viewport(struct ds_surface *surface) WL_EXPORT void ds_surface_viewport_release(struct ds_surface_viewport *vp_handle) { - assert(vp_handle->taken == true); + DS_ASSERT(vp_handle->taken == true); vp_handle->taken = false; } @@ -165,8 +164,8 @@ ds_surface_viewport_set_source(struct ds_surface_viewport *vp_handle, { struct ds_surface *surface; - assert(vp_handle->taken == true); - assert(x >= 0 && y >= 0 && width > 0 && height > 0); + DS_ASSERT(vp_handle->taken == true); + DS_ASSERT(x >= 0 && y >= 0 && width > 0 && height > 0); surface = wl_container_of(vp_handle, surface, viewport_handle); surface->pending.committed |= DS_SURFACE_STATE_VIEWPORT; @@ -182,7 +181,7 @@ ds_surface_viewport_unset_source(struct ds_surface_viewport *vp_handle) { struct ds_surface *surface; - assert(vp_handle->taken == true); + DS_ASSERT(vp_handle->taken == true); surface = wl_container_of(vp_handle, surface, viewport_handle); surface->pending.committed |= DS_SURFACE_STATE_VIEWPORT; @@ -195,8 +194,8 @@ ds_surface_viewport_set_destination(struct ds_surface_viewport *vp_handle, { struct ds_surface *surface; - assert(vp_handle->taken == true); - assert(width > 0 && height > 0); + DS_ASSERT(vp_handle->taken == true); + DS_ASSERT(width > 0 && height > 0); surface = wl_container_of(vp_handle, surface, viewport_handle); surface->pending.committed |= DS_SURFACE_STATE_VIEWPORT; @@ -210,7 +209,7 @@ ds_surface_viewport_unset_destination(struct ds_surface_viewport *vp_handle) { struct ds_surface *surface; - assert(vp_handle->taken == true); + DS_ASSERT(vp_handle->taken == true); surface = wl_container_of(vp_handle, surface, viewport_handle); surface->pending.committed |= DS_SURFACE_STATE_VIEWPORT; diff --git a/src/swapchain.c b/src/swapchain.c index 78a2ece..be2af23 100644 --- a/src/swapchain.c +++ b/src/swapchain.c @@ -1,10 +1,11 @@ -#include #include #include #include "libds/log.h" #include "libds/allocator.h" +#include "util.h" + #define DS_SWAPCHAIN_CAP 4 struct ds_swapchain_slot @@ -120,7 +121,7 @@ ds_swapchain_set_buffer_submitted(struct ds_swapchain *swapchain, struct ds_swapchain_slot *slot; size_t i; - assert(buffer); + DS_ASSERT(buffer); if (!swapchain_has_buffer(swapchain, buffer)) return; @@ -175,8 +176,8 @@ static struct ds_buffer * swapchain_slot_acquire(struct ds_swapchain *swapchain, struct ds_swapchain_slot *slot, int *age) { - assert(!slot->acquired); - assert(slot->buffer); + DS_ASSERT(!slot->acquired); + DS_ASSERT(slot->buffer); slot->acquired = true; diff --git a/src/xdg_shell/xdg_surface.c b/src/xdg_shell/xdg_surface.c index 35ca7a7..1b566a5 100644 --- a/src/xdg_shell/xdg_surface.c +++ b/src/xdg_shell/xdg_surface.c @@ -1,8 +1,8 @@ -#include #include #include "libds/log.h" +#include "util.h" #include "xdg_shell.h" static const struct xdg_surface_interface xdg_surface_impl; @@ -130,7 +130,7 @@ unmap_xdg_surface(struct ds_xdg_surface *surface) // TODO break; case DS_XDG_SURFACE_ROLE_NONE: - assert(false && "not reached"); + DS_ASSERT_NOT_REACHED(); } wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) @@ -402,7 +402,7 @@ xdg_surface_handle_ack_configure(struct wl_client *client, case DS_XDG_SURFACE_ROLE_POPUP: break; default: - assert(0 && "not reached"); + DS_ASSERT_NOT_REACHED(); break; } @@ -472,7 +472,7 @@ surface_send_configure(void *user_data) switch (surface->role) { case DS_XDG_SURFACE_ROLE_NONE: - assert(0 && "not reached"); + DS_ASSERT_NOT_REACHED(); break; case DS_XDG_SURFACE_ROLE_TOPLEVEL: send_xdg_toplevel_configure(surface, configure); diff --git a/src/xdg_shell/xdg_toplevel.c b/src/xdg_shell/xdg_toplevel.c index cd24bbc..56bba06 100644 --- a/src/xdg_shell/xdg_toplevel.c +++ b/src/xdg_shell/xdg_toplevel.c @@ -1,7 +1,7 @@ -#include #include #include +#include "util.h" #include "xdg_shell.h" static const struct ds_surface_role xdg_toplevel_surface_role = @@ -17,7 +17,7 @@ static void xdg_toplevel_handle_resource_destroy(struct wl_resource *resource); WL_EXPORT uint32_t ds_xdg_toplevel_set_activated(struct ds_xdg_surface *surface, bool activated) { - assert(surface->role == DS_XDG_SURFACE_ROLE_TOPLEVEL); + DS_ASSERT(surface->role == DS_XDG_SURFACE_ROLE_TOPLEVEL); surface->toplevel->scheduled.activated = activated; return ds_xdg_surface_schedule_configure(surface); @@ -37,7 +37,7 @@ create_xdg_toplevel(struct ds_xdg_surface *surface, uint32_t id) return; } - assert(surface->toplevel == NULL); + DS_ASSERT(surface->toplevel == NULL); surface->toplevel = calloc(1, sizeof *surface->toplevel); if (!surface->toplevel) { diff --git a/src/xdg_shell_v6/xdg_surface_v6.c b/src/xdg_shell_v6/xdg_surface_v6.c index 487ad45..d098172 100644 --- a/src/xdg_shell_v6/xdg_surface_v6.c +++ b/src/xdg_shell_v6/xdg_surface_v6.c @@ -1,8 +1,8 @@ -#include #include #include "libds/log.h" +#include "util.h" #include "xdg_shell_v6.h" static const struct zxdg_surface_v6_interface xdg_surface_v6_impl; @@ -130,7 +130,7 @@ unmap_xdg_surface_v6(struct ds_xdg_surface_v6 *surface) // TODO break; case DS_XDG_SURFACE_V6_ROLE_NONE: - assert(false && "not reached"); + DS_ASSERT_NOT_REACHED(); } wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) @@ -408,7 +408,7 @@ xdg_surface_v6_handle_ack_configure(struct wl_client *client, case DS_XDG_SURFACE_V6_ROLE_POPUP: break; default: - assert(0 && "not reached"); + DS_ASSERT_NOT_REACHED(); break; } @@ -478,7 +478,7 @@ surface_send_configure(void *user_data) switch (surface->role) { case DS_XDG_SURFACE_V6_ROLE_NONE: - assert(0 && "not reached"); + DS_ASSERT_NOT_REACHED(); break; case DS_XDG_SURFACE_V6_ROLE_TOPLEVEL: send_xdg_toplevel_v6_configure(surface, configure); diff --git a/src/xdg_shell_v6/xdg_toplevel_v6.c b/src/xdg_shell_v6/xdg_toplevel_v6.c index 463b65a..91b12a0 100644 --- a/src/xdg_shell_v6/xdg_toplevel_v6.c +++ b/src/xdg_shell_v6/xdg_toplevel_v6.c @@ -1,7 +1,7 @@ -#include #include #include +#include "util.h" #include "xdg_shell_v6.h" static const struct ds_surface_role xdg_toplevel_v6_surface_role = @@ -28,7 +28,7 @@ create_xdg_toplevel_v6(struct ds_xdg_surface_v6 *surface, uint32_t id) return; } - assert(surface->toplevel == NULL); + DS_ASSERT(surface->toplevel == NULL); surface->toplevel = calloc(1, sizeof *surface->toplevel); if (!surface->toplevel) { -- 2.7.4 From 3f64520f23e39096b2cd82134791d233e6ab0719 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Mon, 24 Oct 2022 08:43:16 +0900 Subject: [PATCH 02/16] Replace MIN macro with DS_MIN Change-Id: I03566bf438710b36387c27bbb547bb7bf0ee1c7f --- src/backend/wayland/seat.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/backend/wayland/seat.c b/src/backend/wayland/seat.c index 8376ebf..8b9085e 100644 --- a/src/backend/wayland/seat.c +++ b/src/backend/wayland/seat.c @@ -13,12 +13,6 @@ #include "util.h" #include "backend.h" -#ifdef MIN -# undef MIN -#endif - -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - static const struct wl_seat_listener seat_listener; static const struct wl_callback_listener seat_callback_listener; @@ -35,6 +29,7 @@ struct ds_wl_seat * create_wl_seat(struct ds_wl_backend *backend, uint32_t id, uint32_t available_version) { + const uint32_t seat_version = 5; struct ds_wl_seat *seat; seat = calloc(1, sizeof *seat); @@ -42,7 +37,7 @@ create_wl_seat(struct ds_wl_backend *backend, uint32_t id, return NULL; seat->backend = backend; - seat->version = MIN(available_version, 5); + seat->version = DS_MIN(available_version, seat_version); seat->wl_seat = wl_registry_bind(backend->server.registry, id, &wl_seat_interface, seat->version); -- 2.7.4 From a324c5a65690fa434e454738ccb9c1e01b2f1710 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Mon, 24 Oct 2022 08:51:33 +0900 Subject: [PATCH 03/16] surface: Use DS_FLAG_* macros Change-Id: I67d3134e36c70aa7b490dd7f7c4d23438789118e --- src/surface/surface.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/surface/surface.c b/src/surface/surface.c index f4f86f6..a80c1ac 100644 --- a/src/surface/surface.c +++ b/src/surface/surface.c @@ -168,7 +168,7 @@ ds_surface_viewport_set_source(struct ds_surface_viewport *vp_handle, DS_ASSERT(x >= 0 && y >= 0 && width > 0 && height > 0); surface = wl_container_of(vp_handle, surface, viewport_handle); - surface->pending.committed |= DS_SURFACE_STATE_VIEWPORT; + DS_FLAG_SET(surface->pending.committed, DS_SURFACE_STATE_VIEWPORT); surface->pending.viewport.has_src = true; surface->pending.viewport.src.x = x; surface->pending.viewport.src.y = y; @@ -184,7 +184,7 @@ ds_surface_viewport_unset_source(struct ds_surface_viewport *vp_handle) DS_ASSERT(vp_handle->taken == true); surface = wl_container_of(vp_handle, surface, viewport_handle); - surface->pending.committed |= DS_SURFACE_STATE_VIEWPORT; + DS_FLAG_SET(surface->pending.committed, DS_SURFACE_STATE_VIEWPORT); surface->pending.viewport.has_src = false; } @@ -198,7 +198,7 @@ ds_surface_viewport_set_destination(struct ds_surface_viewport *vp_handle, DS_ASSERT(width > 0 && height > 0); surface = wl_container_of(vp_handle, surface, viewport_handle); - surface->pending.committed |= DS_SURFACE_STATE_VIEWPORT; + DS_FLAG_SET(surface->pending.committed, DS_SURFACE_STATE_VIEWPORT); surface->pending.viewport.has_dst = true; surface->pending.viewport.dst_width = width; surface->pending.viewport.dst_height = height; @@ -212,7 +212,7 @@ ds_surface_viewport_unset_destination(struct ds_surface_viewport *vp_handle) DS_ASSERT(vp_handle->taken == true); surface = wl_container_of(vp_handle, surface, viewport_handle); - surface->pending.committed |= DS_SURFACE_STATE_VIEWPORT; + DS_FLAG_SET(surface->pending.committed, DS_SURFACE_STATE_VIEWPORT); surface->pending.viewport.has_dst = false; } @@ -331,7 +331,7 @@ surface_handle_attach(struct wl_client *client, } surface = wl_resource_get_user_data(resource); - surface->pending.committed |= DS_SURFACE_STATE_BUFFER; + DS_FLAG_SET(surface->pending.committed, DS_SURFACE_STATE_BUFFER); surface->pending.dx = dx; surface->pending.dy = dy; @@ -358,7 +358,7 @@ surface_handle_damage(struct wl_client *client, if (width < 0 || height < 0) return; - surface->pending.committed |= DS_SURFACE_STATE_SURFACE_DAMAGE; + DS_FLAG_SET(surface->pending.committed, DS_SURFACE_STATE_SURFACE_DAMAGE); pixman_region32_union_rect(&surface->pending.surface_damage, &surface->pending.surface_damage, x, y, width, height); @@ -394,7 +394,8 @@ surface_handle_frame(struct wl_client *client, wl_list_insert(surface->pending.frame_callback_list.prev, wl_resource_get_link(callback_resource)); - surface->pending.committed |= DS_SURFACE_STATE_FRAME_CALLBACK_LIST; + DS_FLAG_SET(surface->pending.committed, + DS_SURFACE_STATE_FRAME_CALLBACK_LIST); } static void @@ -408,7 +409,7 @@ surface_handle_set_opaque_region(struct wl_client *client, ds_dbg("ds_surface(%p) set opaque region", surface); - surface->pending.committed |= DS_SURFACE_STATE_OPAQUE_REGION; + DS_FLAG_SET(surface->pending.committed, DS_SURFACE_STATE_OPAQUE_REGION); if (region_resource) { region = ds_region_from_resource(region_resource); pixman_region32_copy(&surface->pending.opaque, region); @@ -429,7 +430,7 @@ surface_handle_set_input_region(struct wl_client *client, ds_dbg("ds_surface(%p) set input region", surface); - surface->pending.committed |= DS_SURFACE_STATE_INPUT_REGION; + DS_FLAG_SET(surface->pending.committed, DS_SURFACE_STATE_INPUT_REGION); if (region_resource) { region = ds_region_from_resource(region_resource); pixman_region32_copy(&surface->pending.input, region); @@ -478,7 +479,7 @@ surface_handle_set_buffer_transform(struct wl_client *client, return; } - surface->pending.committed |= DS_SURFACE_STATE_TRANSFORM; + DS_FLAG_SET(surface->pending.committed, DS_SURFACE_STATE_TRANSFORM); surface->pending.transform = transform; } @@ -500,7 +501,7 @@ surface_handle_set_buffer_scale(struct wl_client *client, return; } - surface->pending.committed |= DS_SURFACE_STATE_SCALE; + DS_FLAG_SET(surface->pending.committed, DS_SURFACE_STATE_SCALE); surface->pending.scale = scale; } @@ -522,7 +523,7 @@ surface_handle_damage_buffer(struct wl_client *client, return; } - surface->pending.committed |= DS_SURFACE_STATE_BUFFER_DAMAGE; + DS_FLAG_SET(surface->pending.committed, DS_SURFACE_STATE_BUFFER_DAMAGE); pixman_region32_union_rect(&surface->pending.buffer_damage, &surface->pending.buffer_damage, x, y, width, height); @@ -609,13 +610,13 @@ surface_state_move(struct ds_surface_state *state, struct ds_surface_state *next state->buffer_width = next->buffer_width; state->buffer_height = next->buffer_height; - if (next->committed & DS_SURFACE_STATE_SCALE) + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_SCALE)) state->scale = next->scale; - if (next->committed & DS_SURFACE_STATE_TRANSFORM) + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_TRANSFORM)) state->transform = next->transform; - if (next->committed & DS_SURFACE_STATE_BUFFER) { + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_BUFFER)) { state->dx = next->dx; state->dy = next->dy; next->dx = next->dy = 0; @@ -635,30 +636,30 @@ surface_state_move(struct ds_surface_state *state, struct ds_surface_state *next state->dx = state->dy = 0; } - if (next->committed & DS_SURFACE_STATE_SURFACE_DAMAGE) { + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_SURFACE_DAMAGE)) { pixman_region32_copy(&state->surface_damage, &next->surface_damage); pixman_region32_clear(&next->surface_damage); } else pixman_region32_clear(&state->surface_damage); - if (next->committed & DS_SURFACE_STATE_BUFFER_DAMAGE) { + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_BUFFER_DAMAGE)) { pixman_region32_copy(&state->buffer_damage, &next->buffer_damage); pixman_region32_clear(&next->buffer_damage); } else pixman_region32_clear(&state->buffer_damage); - if (next->committed & DS_SURFACE_STATE_OPAQUE_REGION) + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_OPAQUE_REGION)) pixman_region32_copy(&state->opaque, &next->opaque); - if (next->committed & DS_SURFACE_STATE_INPUT_REGION) + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_INPUT_REGION)) pixman_region32_copy(&state->input, &next->input); - if (next->committed & DS_SURFACE_STATE_VIEWPORT) + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_VIEWPORT)) memcpy(&state->viewport, &next->viewport, sizeof(state->viewport)); - if (next->committed & DS_SURFACE_STATE_FRAME_CALLBACK_LIST) { + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_FRAME_CALLBACK_LIST)) { wl_list_insert_list(&state->frame_callback_list, &next->frame_callback_list); wl_list_init(&next->frame_callback_list); @@ -705,7 +706,7 @@ surface_finalize_pending(struct ds_surface *surface) { struct ds_surface_state *pending = &surface->pending; - if ((pending->committed & DS_SURFACE_STATE_BUFFER)) { + if (DS_FLAG_IS_SET(pending->committed, DS_SURFACE_STATE_BUFFER)) { if (pending->buffer) { ds_buffer_get_size(pending->buffer, &pending->buffer_width, &pending->buffer_height); @@ -839,7 +840,7 @@ surface_commit_state(struct ds_surface *surface, struct ds_surface_state *next) surface_state_move(&surface->current, next); // FIXME no need? - if (surface->current.committed & DS_SURFACE_STATE_BUFFER) + if (DS_FLAG_IS_SET(surface->current.committed, DS_SURFACE_STATE_BUFFER)) surface_update_buffer(surface); if (surface->role && surface->role->commit) -- 2.7.4 From 4f24dfb2ffd2477bf37b78ef4ddf321bde1c8643 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Mon, 24 Oct 2022 10:41:57 +0900 Subject: [PATCH 04/16] Create wl_resource with minimum version The version of wl_resource has to be the minimum among the versions for which both compositor and client support. Change-Id: I16e310e8f5aaec570b1dc1a956b05fd115facd58 --- src/compositor.c | 3 ++- src/data_device/manager.c | 3 ++- src/output.c | 3 ++- src/presentation.c | 2 +- src/seat/seat.c | 3 ++- src/shell.c | 5 +++-- src/subcompositor.c | 4 +++- src/xdg_shell/xdg_shell.c | 5 +++-- src/xdg_shell_v6/xdg_shell_v6.c | 5 +++-- 9 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/compositor.c b/src/compositor.c index 64b9a99..4b90405 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -3,6 +3,7 @@ #include "libds/log.h" +#include "util.h" #include "subcompositor.h" #include "surface.h" #include "region.h" @@ -120,7 +121,7 @@ static void compositor_bind(struct wl_client *client, void *data, struct wl_resource *resource; resource = wl_resource_create(client, &wl_compositor_interface, - version, id); + DS_MIN((int)version, COMPOSITOR_VERSION), id); if (resource == NULL) { wl_client_post_no_memory(client); return; diff --git a/src/data_device/manager.c b/src/data_device/manager.c index 79ccc7f..b30d33e 100644 --- a/src/data_device/manager.c +++ b/src/data_device/manager.c @@ -2,6 +2,7 @@ #include #include "libds/log.h" +#include "util.h" #include "data_device_private.h" #define DATA_DEVICE_MANAGER_VERSION 3 @@ -102,7 +103,7 @@ data_device_manager_bind(struct wl_client *client, void *data, struct wl_resource *resource; resource = wl_resource_create(client, &wl_data_device_manager_interface, - version, id); + DS_MIN((int)version, DATA_DEVICE_MANAGER_VERSION), id); if (!resource) { wl_client_post_no_memory(client); return; diff --git a/src/output.c b/src/output.c index de48b37..8876a3d 100644 --- a/src/output.c +++ b/src/output.c @@ -345,7 +345,8 @@ output_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) struct ds_output *output = data; struct wl_resource *resource; - resource = wl_resource_create(client, &wl_output_interface, version, id); + resource = wl_resource_create(client, &wl_output_interface, + DS_MIN((int)version, OUTPUT_VERSION), id); if (!resource) { wl_client_post_no_memory(client); return; diff --git a/src/presentation.c b/src/presentation.c index 54d10d9..0e0580e 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -91,7 +91,7 @@ presentation_bind(struct wl_client *client, void *data, struct wl_resource *resource; resource = wl_resource_create(client, &wp_presentation_interface, - version, id); + DS_MIN((int)version, PRESENTATION_VERSION), id); if (!resource) { wl_client_post_no_memory(client); return; diff --git a/src/seat/seat.c b/src/seat/seat.c index ca9c2e9..58ac3ec 100644 --- a/src/seat/seat.c +++ b/src/seat/seat.c @@ -400,7 +400,8 @@ seat_handle_bind(struct wl_client *wl_client, void *data, uint32_t version, struct ds_seat_client *seat_client; struct wl_resource *resource; - resource = wl_resource_create(wl_client, &wl_seat_interface, version, id); + resource = wl_resource_create(wl_client, &wl_seat_interface, + DS_MIN((int)version, SEAT_VERSION), id); if (!resource) { wl_client_post_no_memory(wl_client); return; diff --git a/src/shell.c b/src/shell.c index e9b42b4..a757233 100644 --- a/src/shell.c +++ b/src/shell.c @@ -5,6 +5,7 @@ #include "libds/log.h" #include "libds/shell.h" +#include "util.h" #include "shell.h" #define WL_SHELL_VERSION 1 @@ -158,8 +159,8 @@ shell_bind(struct wl_client *wl_client, void *data, uint32_t version, wl_list_init(&client->shell_surfaces); - client->resource = - wl_resource_create(wl_client, &wl_shell_interface, version, id); + client->resource = wl_resource_create(wl_client, &wl_shell_interface, + DS_MIN((int)version, WL_SHELL_VERSION), id); if (client->resource == NULL) { free(client); wl_client_post_no_memory(wl_client); diff --git a/src/subcompositor.c b/src/subcompositor.c index 9e821b3..077a715 100644 --- a/src/subcompositor.c +++ b/src/subcompositor.c @@ -1,5 +1,6 @@ #include "libds/log.h" +#include "util.h" #include "subcompositor.h" #include "surface.h" @@ -90,7 +91,8 @@ subcompositor_bind(struct wl_client *client, void *data, struct ds_subcompositor *subcomp = data; struct wl_resource *resource; - resource = wl_resource_create(client, &wl_subcompositor_interface, 1, id); + resource = wl_resource_create(client, &wl_subcompositor_interface, + DS_MIN((int)version, SUBCOMPOSITOR_VERSION), id); if (resource == NULL) { wl_client_post_no_memory(client); return; diff --git a/src/xdg_shell/xdg_shell.c b/src/xdg_shell/xdg_shell.c index 57096ea..3d48efb 100644 --- a/src/xdg_shell/xdg_shell.c +++ b/src/xdg_shell/xdg_shell.c @@ -5,6 +5,7 @@ #include "libds/log.h" #include "libds/xdg_shell.h" +#include "util.h" #include "xdg_shell.h" #define XDG_WM_BASE_VERSION 2 @@ -200,8 +201,8 @@ xdg_shell_bind(struct wl_client *wl_client, void *data, uint32_t version, wl_list_init(&client->surfaces); - client->resource = - wl_resource_create(wl_client, &xdg_wm_base_interface, version, id); + client->resource = wl_resource_create(wl_client, &xdg_wm_base_interface, + DS_MIN((int)version, XDG_WM_BASE_VERSION), id); if (client->resource == NULL) { free(client); wl_client_post_no_memory(wl_client); diff --git a/src/xdg_shell_v6/xdg_shell_v6.c b/src/xdg_shell_v6/xdg_shell_v6.c index af8b81c..0f94fae 100644 --- a/src/xdg_shell_v6/xdg_shell_v6.c +++ b/src/xdg_shell_v6/xdg_shell_v6.c @@ -5,6 +5,7 @@ #include "libds/log.h" #include "libds/xdg_shell_v6.h" +#include "util.h" #include "xdg_shell_v6.h" #define XDG_SHELL_V6_BASE_VERSION 1 @@ -200,8 +201,8 @@ xdg_shell_v6_bind(struct wl_client *wl_client, void *data, uint32_t version, wl_list_init(&client->surfaces); - client->resource = - wl_resource_create(wl_client, &zxdg_shell_v6_interface, version, id); + client->resource = wl_resource_create(wl_client, &zxdg_shell_v6_interface, + DS_MIN((int)version, XDG_SHELL_V6_BASE_VERSION), id); if (client->resource == NULL) { free(client); wl_client_post_no_memory(wl_client); -- 2.7.4 From 680391c2951225f347cbc2f373d7007ed2efa30c Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Thu, 27 Oct 2022 15:00:37 +0900 Subject: [PATCH 05/16] Rename event types for consistency The event type names should be prefixed with `ds_{submodule}_event_`. Change-Id: I72dd9ee5df04042dd061a9c5a0641a6c120dca22 --- examples/input-device-test.c | 6 +++--- examples/libinput-backend.c | 12 ++++++------ examples/tinyds.c | 12 ++++++------ include/libds/data_device.h | 10 +++++----- include/libds/interfaces/keyboard.h | 2 +- include/libds/keyboard.h | 2 +- include/libds/pointer.h | 6 +++--- include/libds/seat.h | 4 ++-- include/libds/touch.h | 6 +++--- src/backend/libinput/keyboard.c | 2 +- src/backend/libinput/pointer.c | 6 +++--- src/backend/libinput/touch.c | 6 +++--- src/backend/wayland/seat.c | 14 +++++++------- src/data_device/data_device.c | 4 ++-- src/data_device/data_offer.c | 2 +- src/data_device/drag.c | 4 ++-- src/keyboard.c | 6 +++--- src/seat/seat_keyboard.c | 2 +- src/seat/seat_pointer.c | 2 +- 19 files changed, 54 insertions(+), 54 deletions(-) diff --git a/examples/input-device-test.c b/examples/input-device-test.c index 62fe8b0..c71426d 100644 --- a/examples/input-device-test.c +++ b/examples/input-device-test.c @@ -165,7 +165,7 @@ pointer_handle_device_destroy(struct wl_listener *listener, void *data) static void pointer_handle_motion_absolute(struct wl_listener *listener, void *data) { - struct ds_event_pointer_motion_absolute *event = data; + struct ds_pointer_event_motion_absolute *event = data; ds_inf("Pointer device(%p): motion absolute (%f, %f) time(%d ms)", event->device, event->x, event->y, event->time_msec); @@ -174,7 +174,7 @@ pointer_handle_motion_absolute(struct wl_listener *listener, void *data) static void pointer_handle_button(struct wl_listener *listener, void *data) { - struct ds_event_pointer_button *event = data; + struct ds_pointer_event_button *event = data; ds_inf("Pointer Device(%p): button(%d) state(%d) time(%d ms)", event->device, event->button, event->state, event->time_msec); @@ -255,7 +255,7 @@ keyboard_handle_modifiers(struct wl_listener *listener, void *data) static void keyboard_handle_key(struct wl_listener *listener, void *data) { - struct ds_event_keyboard_key *event = data; + struct ds_keyboard_event_key *event = data; struct keyboard_device *keyboard; struct xkb_state *xkb_state; const xkb_keysym_t *syms; diff --git a/examples/libinput-backend.c b/examples/libinput-backend.c index 19a21af..02b257f 100644 --- a/examples/libinput-backend.c +++ b/examples/libinput-backend.c @@ -141,7 +141,7 @@ keyboard_handle_device_destroy(struct wl_listener *listener, void *data) static void keyboard_handle_key(struct wl_listener *listener, void *data) { - struct ds_event_keyboard_key *event = data; + struct ds_keyboard_event_key *event = data; struct keyboard_device *keyboard; keyboard = wl_container_of(listener, keyboard, key); @@ -191,7 +191,7 @@ pointer_handle_device_destroy(struct wl_listener *listener, void *data) static void pointer_handle_motion(struct wl_listener *listener, void *data) { - struct ds_event_pointer_motion *event = data; + struct ds_pointer_event_motion *event = data; struct pointer_device *pointer; pointer = wl_container_of(listener, pointer, motion); @@ -204,7 +204,7 @@ pointer_handle_motion(struct wl_listener *listener, void *data) static void pointer_handle_button(struct wl_listener *listener, void *data) { - struct ds_event_pointer_button *event = data; + struct ds_pointer_event_button *event = data; struct pointer_device *pointer; pointer = wl_container_of(listener, pointer, button); @@ -256,7 +256,7 @@ touch_handle_device_destroy(struct wl_listener *listener, void *data) static void touch_handle_down(struct wl_listener *listener, void *data) { - struct ds_event_touch_down *event = data; + struct ds_touch_event_down *event = data; struct touch_device *touch; touch = wl_container_of(listener, touch, down); @@ -268,7 +268,7 @@ touch_handle_down(struct wl_listener *listener, void *data) static void touch_handle_up(struct wl_listener *listener, void *data) { - struct ds_event_touch_up *event = data; + struct ds_touch_event_up *event = data; struct touch_device *touch; touch = wl_container_of(listener, touch, up); @@ -280,7 +280,7 @@ touch_handle_up(struct wl_listener *listener, void *data) static void touch_handle_motion(struct wl_listener *listener, void *data) { - struct ds_event_touch_motion *event = data; + struct ds_touch_event_motion *event = data; struct touch_device *touch; touch = wl_container_of(listener, touch, motion); diff --git a/examples/tinyds.c b/examples/tinyds.c index 32087e6..fa0a854 100644 --- a/examples/tinyds.c +++ b/examples/tinyds.c @@ -462,7 +462,7 @@ server_handle_new_xdg_surface(struct wl_listener *listener, void *data) static void server_handle_request_set_selection(struct wl_listener *listener, void *data) { - struct ds_event_request_set_selection *event = data; + struct ds_data_device_manager_event_request_set_selection *event = data; ds_seat_set_selection(event->seat, event->source, event->serial); } @@ -470,7 +470,7 @@ server_handle_request_set_selection(struct wl_listener *listener, void *data) static void server_handle_request_start_drag(struct wl_listener *listener, void *data) { - struct ds_event_request_start_drag *event = data; + struct ds_data_device_manager_event_request_start_drag *event = data; ds_drag_start_pointer_drag(event->drag, event->serial); } @@ -478,7 +478,7 @@ server_handle_request_start_drag(struct wl_listener *listener, void *data) static void server_handle_request_data_offer_receive(struct wl_listener *listener, void *data) { - struct ds_event_request_data_offer_receive *event = data; + struct ds_data_device_manager_event_request_data_offer_receive *event = data; ds_data_offer_send(event->offer, event->mime_type, event->fd); } @@ -871,7 +871,7 @@ static void keyboard_handle_key(struct wl_listener *listener, void *data) { struct tinyds_keyboard *kbd; - struct ds_event_keyboard_key *event = data; + struct ds_keyboard_event_key *event = data; struct ds_keyboard *ds_keyboard; struct xkb_state *xkb_state; const xkb_keysym_t *syms; @@ -992,7 +992,7 @@ static void pointer_handle_motion_absolute(struct wl_listener *listener, void *data) { struct tinyds_pointer *pointer; - struct ds_event_pointer_motion_absolute *event = data; + struct ds_pointer_event_motion_absolute *event = data; struct tinyds_view *view; double sx, sy; @@ -1030,7 +1030,7 @@ static void pointer_handle_button(struct wl_listener *listener, void *data) { struct tinyds_pointer *pointer; - struct ds_event_pointer_button *event = data; + struct ds_pointer_event_button *event = data; struct tinyds_view *view; pointer = wl_container_of(listener, pointer, button); diff --git a/include/libds/data_device.h b/include/libds/data_device.h index a34b4c4..917f051 100644 --- a/include/libds/data_device.h +++ b/include/libds/data_device.h @@ -37,14 +37,14 @@ struct ds_drag; struct ds_touch_point; -struct ds_event_request_set_selection +struct ds_data_device_manager_event_request_set_selection { struct ds_seat *seat; struct ds_data_source *source; uint32_t serial; }; -struct ds_event_request_start_drag +struct ds_data_device_manager_event_request_start_drag { struct ds_seat *seat; struct ds_surface *origin; @@ -52,20 +52,20 @@ struct ds_event_request_start_drag uint32_t serial; }; -struct ds_event_request_data_offer_receive +struct ds_data_device_manager_event_request_data_offer_receive { struct ds_data_offer *offer; const char *mime_type; int32_t fd; }; -struct ds_event_drag_motion { +struct ds_drag_event_motion { struct ds_drag *drag; uint32_t time; double sx, sy; }; -struct ds_event_drag_drop { +struct ds_drag_event_drop { struct ds_drag *drag; uint32_t time; }; diff --git a/include/libds/interfaces/keyboard.h b/include/libds/interfaces/keyboard.h index 85a20a5..720098d 100644 --- a/include/libds/interfaces/keyboard.h +++ b/include/libds/interfaces/keyboard.h @@ -59,7 +59,7 @@ void ds_keyboard_init(struct ds_keyboard *keyboard, void ds_keyboard_destroy(struct ds_keyboard *keyboard); void ds_keyboard_notify_key(struct ds_keyboard *keyboard, - struct ds_event_keyboard_key *event); + struct ds_keyboard_event_key *event); void ds_keyboard_notify_modifiers(struct ds_keyboard *keyboard, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, diff --git a/include/libds/keyboard.h b/include/libds/keyboard.h index 80165e6..b02369f 100644 --- a/include/libds/keyboard.h +++ b/include/libds/keyboard.h @@ -30,7 +30,7 @@ struct ds_keyboard_modifiers xkb_mod_mask_t group; }; -struct ds_event_keyboard_key +struct ds_keyboard_event_key { uint32_t time_msec; uint32_t keycode; diff --git a/include/libds/pointer.h b/include/libds/pointer.h index 99545df..f347571 100644 --- a/include/libds/pointer.h +++ b/include/libds/pointer.h @@ -7,7 +7,7 @@ struct ds_pointer; -struct ds_event_pointer_motion_absolute +struct ds_pointer_event_motion_absolute { struct ds_input_device *device; uint32_t time_msec; @@ -15,14 +15,14 @@ struct ds_event_pointer_motion_absolute double x, y; }; -struct ds_event_pointer_motion +struct ds_pointer_event_motion { struct ds_input_device *device; uint32_t time_msec; double delta_x, delta_y; }; -struct ds_event_pointer_button +struct ds_pointer_event_button { struct ds_input_device *device; uint32_t time_msec; diff --git a/include/libds/seat.h b/include/libds/seat.h index 42626b6..1237696 100644 --- a/include/libds/seat.h +++ b/include/libds/seat.h @@ -31,14 +31,14 @@ enum ds_axis_source DS_AXIS_SOURCE_WHEEL_TILT, }; -struct ds_event_seat_pointer_focus_change +struct ds_seat_pointer_event_focus_change { struct ds_seat *seat; struct ds_surface *old_surface, *new_surface; double sx, sy; }; -struct ds_event_seat_keyboard_focus_change +struct ds_seat_keyboard_event_focus_change { struct ds_seat *seat; struct ds_surface *old_surface, *new_surface; diff --git a/include/libds/touch.h b/include/libds/touch.h index 4b69b90..986dca8 100644 --- a/include/libds/touch.h +++ b/include/libds/touch.h @@ -7,7 +7,7 @@ struct ds_touch; -struct ds_event_touch_down +struct ds_touch_event_down { struct ds_input_device *device; uint32_t time_msec; @@ -16,14 +16,14 @@ struct ds_event_touch_down double x, y; }; -struct ds_event_touch_up +struct ds_touch_event_up { struct ds_input_device *device; uint32_t time_msec; uint32_t id; }; -struct ds_event_touch_motion +struct ds_touch_event_motion { struct ds_input_device *device; uint32_t time_msec; diff --git a/src/backend/libinput/keyboard.c b/src/backend/libinput/keyboard.c index 9376f11..b93138c 100644 --- a/src/backend/libinput/keyboard.c +++ b/src/backend/libinput/keyboard.c @@ -9,7 +9,7 @@ handle_keyboard_key(struct libinput_event *event, uint32_t key; enum libinput_key_state li_state; enum wl_keyboard_key_state state = WL_KEYBOARD_KEY_STATE_PRESSED; - struct ds_event_keyboard_key ds_event = {0}; + struct ds_keyboard_event_key ds_event = {0}; kbevent = libinput_event_get_keyboard_event(event); diff --git a/src/backend/libinput/pointer.c b/src/backend/libinput/pointer.c index efdbaa7..7ea13ea 100644 --- a/src/backend/libinput/pointer.c +++ b/src/backend/libinput/pointer.c @@ -7,7 +7,7 @@ handle_pointer_motion(struct libinput_event *event, { struct libinput_event_pointer *pevent; double delta_x, delta_y; - struct ds_event_pointer_motion ds_event = { 0 }; + struct ds_pointer_event_motion ds_event = { 0 }; pevent = libinput_event_get_pointer_event(event); @@ -31,7 +31,7 @@ handle_pointer_motion_abs(struct libinput_event *event, { struct libinput_event_pointer *pevent; double x, y; - struct ds_event_pointer_motion_absolute ds_event = { 0 }; + struct ds_pointer_event_motion_absolute ds_event = { 0 }; pevent = libinput_event_get_pointer_event(event); @@ -56,7 +56,7 @@ handle_pointer_button(struct libinput_event *event, uint32_t button; enum libinput_button_state li_state = LIBINPUT_BUTTON_STATE_PRESSED; enum ds_button_state state = DS_BUTTON_PRESSED; - struct ds_event_pointer_button ds_event = { 0 }; + struct ds_pointer_event_button ds_event = { 0 }; pevent = libinput_event_get_pointer_event(event); diff --git a/src/backend/libinput/touch.c b/src/backend/libinput/touch.c index fd94c0b..c6b16a1 100644 --- a/src/backend/libinput/touch.c +++ b/src/backend/libinput/touch.c @@ -8,7 +8,7 @@ handle_touch_down(struct libinput_event *event, struct libinput_event_touch *tevent; uint32_t touch_id; double x, y; - struct ds_event_touch_down ds_event = { 0 }; + struct ds_touch_event_down ds_event = { 0 }; tevent = libinput_event_get_touch_event(event); @@ -34,7 +34,7 @@ handle_touch_up(struct libinput_event *event, { struct libinput_event_touch *tevent; uint32_t touch_id; - struct ds_event_touch_up ds_event = { 0 }; + struct ds_touch_event_up ds_event = { 0 }; tevent = libinput_event_get_touch_event(event); @@ -57,7 +57,7 @@ handle_touch_motion(struct libinput_event *event, struct libinput_event_touch *tevent; uint32_t touch_id; double x, y; - struct ds_event_touch_motion ds_event = { 0 }; + struct ds_touch_event_motion ds_event = { 0 }; tevent = libinput_event_get_touch_event(event); diff --git a/src/backend/wayland/seat.c b/src/backend/wayland/seat.c index 8b9085e..8d5836b 100644 --- a/src/backend/wayland/seat.c +++ b/src/backend/wayland/seat.c @@ -315,7 +315,7 @@ pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, ds_output = &seat->output->base; // FIXME take size size of a output into account - struct ds_event_pointer_motion_absolute event = { + struct ds_pointer_event_motion_absolute event = { .device = seat->pointer_dev, .time_msec = time, .x = wl_fixed_to_double(sx) / ds_output->width, @@ -335,7 +335,7 @@ pointer_handle_button(void *data, struct wl_pointer *wl_pointer, if (!seat->output) return; - struct ds_event_pointer_button event = { + struct ds_pointer_event_button event = { .device = seat->pointer_dev, .button = button, .state = state, @@ -494,7 +494,7 @@ keyboard_handle_enter(void *data, struct wl_keyboard *wl_keyboard, time = get_current_time_msec(); wl_array_for_each(keycode_ptr, keys) { - struct ds_event_keyboard_key event = { + struct ds_keyboard_event_key event = { .keycode = *keycode_ptr, .state = WL_KEYBOARD_KEY_STATE_PRESSED, .time_msec = time, @@ -526,7 +526,7 @@ keyboard_handle_leave(void *data, struct wl_keyboard *wl_keyboard, for (size_t i = 0; i < num_keycodes; i++) { keycode = pressed[i]; - struct ds_event_keyboard_key event = { + struct ds_keyboard_event_key event = { .keycode = keycode, .state = WL_KEYBOARD_KEY_STATE_RELEASED, .time_msec = time, @@ -545,7 +545,7 @@ keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard, ds_dbg("wl_keyboard: key"); - struct ds_event_keyboard_key event = { + struct ds_keyboard_event_key event = { .keycode = key, .state = state, .time_msec = time, @@ -639,7 +639,7 @@ touch_handle_down(void *data, struct wl_touch *wl_touch, ds_dbg("wl_touch: down"); - struct ds_event_touch_down event = { + struct ds_touch_event_down event = { .device = seat->touch_dev, .id = id, .x = fixed_x, @@ -657,7 +657,7 @@ touch_handle_up(void *data, struct wl_touch *wl_touch, ds_dbg("wl_touch: up"); - struct ds_event_touch_up event = { + struct ds_touch_event_up event = { .device = seat->touch_dev, .id = id, }; diff --git a/src/data_device/data_device.c b/src/data_device/data_device.c index 345958c..6902404 100644 --- a/src/data_device/data_device.c +++ b/src/data_device/data_device.c @@ -301,7 +301,7 @@ data_device_handle_start_drag(struct wl_client *client, if (source_client) source_client->finalized = true; - struct ds_event_request_start_drag event = { + struct ds_data_device_manager_event_request_start_drag event = { .seat = data_device->seat, .drag = drag, .origin = ds_surface_from_resource(origin_resource), @@ -329,7 +329,7 @@ data_device_handle_set_selection(struct wl_client *client, source->finalized = true; } - struct ds_event_request_set_selection event = { + struct ds_data_device_manager_event_request_set_selection event = { .seat = data_device->seat, .source = &source->base, .serial = serial, diff --git a/src/data_device/data_offer.c b/src/data_device/data_offer.c index fc17b66..3be7829 100644 --- a/src/data_device/data_offer.c +++ b/src/data_device/data_offer.c @@ -178,7 +178,7 @@ data_offer_handle_receive(struct wl_client *client, if (!offer) return; - struct ds_event_request_data_offer_receive event = { + struct ds_data_device_manager_event_request_data_offer_receive event = { .offer = offer, .mime_type = mime_type, .fd = fd, diff --git a/src/data_device/drag.c b/src/data_device/drag.c index 1500682..cd7cddf 100644 --- a/src/data_device/drag.c +++ b/src/data_device/drag.c @@ -326,7 +326,7 @@ drag_pointer_grab_iface_motion(struct ds_seat_pointer_grab *grab, if (data_device) data_device_send_drag_motion(data_device, time, sx, sy); - struct ds_event_drag_motion event = { + struct ds_drag_event_motion event = { .drag = drag, .time = time, .sx = sx, @@ -546,7 +546,7 @@ drag_drop(struct ds_drag *drag, uint32_t time) if (drag->source) ds_data_source_dnd_drop(drag->source); - struct ds_event_drag_drop event = { + struct ds_drag_event_drop event = { .drag = drag, .time = time, }; diff --git a/src/keyboard.c b/src/keyboard.c index 30668c4..550d72f 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -11,7 +11,7 @@ static bool keyboard_modifier_update(struct ds_keyboard *keyboard); static void keyboard_key_update(struct ds_keyboard *keyboard, - struct ds_event_keyboard_key *event); + struct ds_keyboard_event_key *event); static void keyboard_led_update(struct ds_keyboard *keyboard); WL_EXPORT bool @@ -157,7 +157,7 @@ ds_keyboard_get_xkb_state(struct ds_keyboard *keyboard) WL_EXPORT void ds_keyboard_notify_key(struct ds_keyboard *keyboard, - struct ds_event_keyboard_key *event) + struct ds_keyboard_event_key *event) { uint32_t keycode; enum xkb_key_direction dir; @@ -333,7 +333,7 @@ keyboard_modifier_update(struct ds_keyboard *keyboard) } static void keyboard_key_update(struct ds_keyboard *keyboard, - struct ds_event_keyboard_key *event) + struct ds_keyboard_event_key *event) { // TODO } diff --git a/src/seat/seat_keyboard.c b/src/seat/seat_keyboard.c index 85cf672..302e887 100644 --- a/src/seat/seat_keyboard.c +++ b/src/seat/seat_keyboard.c @@ -643,7 +643,7 @@ static void seat_keyboard_emit_focus_change(struct ds_seat_keyboard *keyboard, struct ds_surface *old_surface, struct ds_surface *new_surface) { - struct ds_event_seat_keyboard_focus_change event = { + struct ds_seat_keyboard_event_focus_change event = { .seat = keyboard->seat, .old_surface = old_surface, .new_surface = new_surface, diff --git a/src/seat/seat_pointer.c b/src/seat/seat_pointer.c index fc18769..ce6bd0d 100644 --- a/src/seat/seat_pointer.c +++ b/src/seat/seat_pointer.c @@ -504,7 +504,7 @@ seat_pointer_emit_focus_change(struct ds_seat_pointer *pointer, struct ds_surface *old_surface, struct ds_surface *new_surface, double sx, double sy) { - struct ds_event_seat_pointer_focus_change event = { + struct ds_seat_pointer_event_focus_change event = { .seat = pointer->seat, .new_surface = new_surface, .old_surface = old_surface, -- 2.7.4 From ee73c65a6d2a9ae3fe9626526e24650cc202bf69 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Thu, 8 Dec 2022 18:20:04 +0900 Subject: [PATCH 06/16] Add defs.h to export helper macros We need to export helper macros and definitions for libds-tizen. Change-Id: I14d8e064980a56f98e9f107473638b42b2e5eb4d --- include/libds/util/defs.h | 78 +++++++++++++++++++++++++++++++++++++++++++++++ src/util.h | 74 +------------------------------------------- 2 files changed, 79 insertions(+), 73 deletions(-) create mode 100644 include/libds/util/defs.h diff --git a/include/libds/util/defs.h b/include/libds/util/defs.h new file mode 100644 index 0000000..7ad735e --- /dev/null +++ b/include/libds/util/defs.h @@ -0,0 +1,78 @@ +#ifndef LIBDS_UTIL_DEFS_H +#define LIBDS_UTIL_DEFS_H + +#include + +#ifndef DS_LIKELY +#ifdef __GNUC__ +#define DS_LIKELY(x) (__builtin_expect(!!(x),1)) +#define DS_UNLIKELY(x) (__builtin_expect(!!(x),0)) +#else +#define DS_LIKELY(x) (x) +#define DS_UNLIKELY(x) (x) +#endif +#endif + +#define DS_RETURN_IF_FAIL(expr) \ + do { \ + if (DS_UNLIKELY(!(expr))) { \ + ds_err("'%s' failed at %s:%u %s()\n", \ + #expr, __FILE__, __LINE__, __func__); \ + return; \ + } \ + } while (false) + +#define DS_RETURN_VAL_IF_FAIL(expr, val) \ + do { \ + if (DS_UNLIKELY(!(expr))) { \ + ds_err("'%s' failed at %s:%u %s()\n", \ + #expr, __FILE__, __LINE__, __func__); \ + return (val); \ + } \ + } while (false) + +#define DS_ASSERT(expr) \ + do { \ + if (DS_UNLIKELY(!(expr))) { \ + ds_err("'%s' failed at %s:%u %s()\n", \ + #expr, __FILE__, __LINE__, __func__); \ + abort(); \ + } \ + } while (false) + +#define DS_ASSERT_NOT_REACHED() \ + do { \ + ds_err("Code should not be reached at %s:%u %s()\n", \ + __FILE__, __LINE__, __func__); \ + abort(); \ + } while (false) + +#define DS_FLAG_MASK(field, mask, flag) (((field) & (mask)) == (flag)) +#define DS_FLAG_IS_SET(field, flag) DS_FLAG_MASK(field, flag, flag) + +#define DS_FLAG_SET(field, flag) ((field) |= (flag)) +#define DS_FLAG_CLEAR(field, flag) ((field) &= ~(__typeof__(field))(flag)) +#define DS_FLAG_UPDATE(field, flag, val) ((val) ? \ + DS_FLAG_SET((field), (flag)) : DS_FLAG_CLEAR((field), (flag))) + +#define DS_MIN(a, b) \ +({ \ + __typeof__(a) _min_a = (a); \ + __typeof__(b) _min_b = (b); \ + DS_LIKELY(_min_a <= _min_b) ? _min_a : _min_b; \ +}) + +#define DS_MAX(a, b) \ +({ \ + __typeof__(a) _max_a = (a); \ + __typeof__(b) _max_b = (b); \ + DS_LIKELY(_max_a >= _max_b) ? _max_a : _max_b; \ +}) + +#define DS_SWAP(a, b) \ +({ \ + __typeof__(a) _t = (a); \ + (a) = b; (b) = _t; \ +}) + +#endif diff --git a/src/util.h b/src/util.h index f821c35..26a63eb 100644 --- a/src/util.h +++ b/src/util.h @@ -6,79 +6,7 @@ #include #include -#include "libds/log.h" - -#ifndef DS_LIKELY -#ifdef __GNUC__ -#define DS_LIKELY(x) (__builtin_expect(!!(x),1)) -#define DS_UNLIKELY(x) (__builtin_expect(!!(x),0)) -#else -#define DS_LIKELY(x) (x) -#define DS_UNLIKELY(x) (x) -#endif -#endif - -#define DS_RETURN_IF_FAIL(expr) \ - do { \ - if (DS_UNLIKELY(!(expr))) { \ - ds_err("'%s' failed at %s:%u %s()\n", \ - #expr, __FILE__, __LINE__, __func__); \ - return; \ - } \ - } while (false) - -#define DS_RETURN_VAL_IF_FAIL(expr, val) \ - do { \ - if (DS_UNLIKELY(!(expr))) { \ - ds_err("'%s' failed at %s:%u %s()\n", \ - #expr, __FILE__, __LINE__, __func__); \ - return (val); \ - } \ - } while (false) - -#define DS_ASSERT(expr) \ - do { \ - if (DS_UNLIKELY(!(expr))) { \ - ds_err("'%s' failed at %s:%u %s()\n", \ - #expr, __FILE__, __LINE__, __func__); \ - abort(); \ - } \ - } while (false) - -#define DS_ASSERT_NOT_REACHED() \ - do { \ - ds_err("Code should not be reached at %s:%u %s()\n", \ - __FILE__, __LINE__, __func__); \ - abort(); \ - } while (false) - -#define DS_FLAG_MASK(field, mask, flag) (((field) & (mask)) == (flag)) -#define DS_FLAG_IS_SET(field, flag) DS_FLAG_MASK(field, flag, flag) - -#define DS_FLAG_SET(field, flag) ((field) |= (flag)) -#define DS_FLAG_CLEAR(field, flag) ((field) &= ~(__typeof__(field))(flag)) -#define DS_FLAG_UPDATE(field, flag, val) ((val) ? \ - DS_FLAG_SET((field), (flag)) : DS_FLAG_CLEAR((field), (flag))) - -#define DS_MIN(a, b) \ -({ \ - __typeof__(a) _min_a = (a); \ - __typeof__(b) _min_b = (b); \ - DS_LIKELY(_min_a <= _min_b) ? _min_a : _min_b; \ -}) - -#define DS_MAX(a, b) \ -({ \ - __typeof__(a) _max_a = (a); \ - __typeof__(b) _max_b = (b); \ - DS_LIKELY(_max_a >= _max_b) ? _max_a : _max_b; \ -}) - -#define DS_SWAP(a, b) \ -({ \ - __typeof__(a) _t = (a); \ - (a) = b; (b) = _t; \ -}) +#include "libds/util/defs.h" int64_t timespec_to_msec(const struct timespec *a); -- 2.7.4 From 7063d22fc5a35c6df33ebc9d923b6ceb534d2587 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Thu, 29 Dec 2022 15:57:47 +0900 Subject: [PATCH 07/16] compositor: Put compositor implementation into a directory This patch renames and puts all related compositor implementation into one directoy. Change-Id: I819e0e6f9e4c574a3e03ab7f2b452dd7fa9b5cec --- src/{ => compositor}/compositor.c | 16 ++++--------- .../compositor_private.h} | 26 ++++++++++++++++++++-- src/{ => compositor}/subcompositor.c | 12 ++++------ src/{surface => compositor}/subsurface.c | 24 ++++++++------------ src/{surface => compositor}/surface.c | 16 +++++-------- src/meson.build | 8 +++---- src/subcompositor.h | 18 --------------- src/surface.h | 3 --- 8 files changed, 51 insertions(+), 72 deletions(-) rename src/{ => compositor}/compositor.c (91%) rename src/{surface/surface-private.h => compositor/compositor_private.h} (80%) rename src/{ => compositor}/subcompositor.c (91%) rename src/{surface => compositor}/subsurface.c (97%) rename src/{surface => compositor}/surface.c (98%) delete mode 100644 src/subcompositor.h diff --git a/src/compositor.c b/src/compositor/compositor.c similarity index 91% rename from src/compositor.c rename to src/compositor/compositor.c index 4b90405..5b2bf5a 100644 --- a/src/compositor.c +++ b/src/compositor/compositor.c @@ -1,12 +1,5 @@ -#include -#include - -#include "libds/log.h" - -#include "util.h" -#include "subcompositor.h" -#include "surface.h" #include "region.h" +#include "compositor_private.h" #define COMPOSITOR_VERSION 4 @@ -46,7 +39,7 @@ ds_compositor_create(struct wl_display *display) goto err_global; } - if (!ds_subcompositor_init(&compositor->subcompositor, display)) { + if (!subcompositor_init(&compositor->subcompositor, display)) { ds_err("Could not initialize subcompositor"); goto err_subcomp; } @@ -91,8 +84,7 @@ compositor_handle_create_surface(struct wl_client *client, struct ds_surface *surface; compositor = wl_resource_get_user_data(resource); - surface = ds_surface_create(client, - wl_resource_get_version(resource), id); + surface = create_surface(client, wl_resource_get_version(resource), id); if (!surface) { ds_err("Could not create ds_surface"); return; @@ -143,6 +135,6 @@ compositor_handle_display_destroy(struct wl_listener *listener, void *data) wl_signal_emit(&compositor->events.destroy, compositor); wl_list_remove(&compositor->display_destroy.link); - ds_subcompositor_finish(&compositor->subcompositor); + subcompositor_finish(&compositor->subcompositor); free(compositor); } diff --git a/src/surface/surface-private.h b/src/compositor/compositor_private.h similarity index 80% rename from src/surface/surface-private.h rename to src/compositor/compositor_private.h index 25f224f..3020939 100644 --- a/src/surface/surface-private.h +++ b/src/compositor/compositor_private.h @@ -2,14 +2,18 @@ #define DS_SURFACE_PRIVATE_H #include +#include #include #include +#include "libds/log.h" +#include "libds/util/defs.h" #include "libds/util/box.h" #include "addon.h" #include "buffer.h" #include "surface.h" +#include "util.h" enum ds_surface_state_field { @@ -24,6 +28,11 @@ enum ds_surface_state_field DS_SURFACE_STATE_VIEWPORT = 1 << 8, }; +struct ds_subcompositor +{ + struct wl_global *global; +}; + struct ds_surface_state { enum ds_surface_state_field committed; @@ -118,13 +127,26 @@ struct ds_subsurface bool mapped; }; +bool subcompositor_init(struct ds_subcompositor *subcomp, + struct wl_display *display); + +void subcompositor_finish(struct ds_subcompositor *subcomp); + +struct ds_surface * +create_surface(struct wl_client *client, uint32_t version, uint32_t id); + struct ds_surface * ds_surface_get_root_surface(struct ds_surface *surface); struct ds_subsurface * -ds_subsurface_from_ds_surface(struct ds_surface *surface); +create_subsurface(struct wl_resource *subcomp_resource, + struct ds_surface *surface, struct ds_surface *parent, + uint32_t version, uint32_t id); + +struct ds_subsurface * +subsurface_from_ds_surface(struct ds_surface *surface); struct ds_surface * -ds_subsurface_get_parent(struct ds_subsurface *subsurface); +subsurface_get_parent(struct ds_subsurface *subsurface); #endif diff --git a/src/subcompositor.c b/src/compositor/subcompositor.c similarity index 91% rename from src/subcompositor.c rename to src/compositor/subcompositor.c index 077a715..35a62a9 100644 --- a/src/subcompositor.c +++ b/src/compositor/subcompositor.c @@ -1,8 +1,4 @@ -#include "libds/log.h" - -#include "util.h" -#include "subcompositor.h" -#include "surface.h" +#include "compositor_private.h" #define SUBCOMPOSITOR_VERSION 1 @@ -10,7 +6,7 @@ static void subcompositor_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id); bool -ds_subcompositor_init(struct ds_subcompositor *subcomp, +subcompositor_init(struct ds_subcompositor *subcomp, struct wl_display *display) { subcomp->global = wl_global_create(display, &wl_subcompositor_interface, @@ -24,7 +20,7 @@ ds_subcompositor_init(struct ds_subcompositor *subcomp, } void -ds_subcompositor_finish(struct ds_subcompositor *subcomp) +subcompositor_finish(struct ds_subcompositor *subcomp) { wl_global_destroy(subcomp->global); } @@ -74,7 +70,7 @@ subcompositor_handle_get_subsurface(struct wl_client *client, return; } - ds_subsurface_create(resource, surface, parent, + create_subsurface(resource, surface, parent, wl_resource_get_version(resource), id); } diff --git a/src/surface/subsurface.c b/src/compositor/subsurface.c similarity index 97% rename from src/surface/subsurface.c rename to src/compositor/subsurface.c index eafa38a..719bb4c 100644 --- a/src/surface/subsurface.c +++ b/src/compositor/subsurface.c @@ -1,10 +1,4 @@ -#include - -#include "libds/log.h" -#include "libds/surface.h" - -#include "util.h" -#include "surface-private.h" +#include "compositor_private.h" static const struct wl_subsurface_interface subsurface_impl; static const struct ds_surface_role subsurface_role; @@ -22,7 +16,7 @@ static struct ds_subsurface *subsurface_find_sibling(struct ds_subsurface *subsu struct ds_surface *surface); struct ds_subsurface * -ds_subsurface_create(struct wl_resource *subcomp_resource, +create_subsurface(struct wl_resource *subcomp_resource, struct ds_surface *surface, struct ds_surface *parent, uint32_t version, uint32_t id) { @@ -84,17 +78,17 @@ ds_subsurface_from_resource(struct wl_resource *resource) return wl_resource_get_user_data(resource); } -struct ds_subsurface * -ds_subsurface_from_ds_surface(struct ds_surface *surface) +struct ds_surface * +subsurface_get_parent(struct ds_subsurface *subsurface) { - DS_ASSERT(ds_surface_is_subsurface(surface)); - return (struct ds_subsurface *)surface->role_data; + return subsurface->parent; } -struct ds_surface * -ds_subsurface_get_parent(struct ds_subsurface *subsurface) +struct ds_subsurface * +subsurface_from_ds_surface(struct ds_surface *surface) { - return subsurface->parent; + DS_ASSERT(ds_surface_is_subsurface(surface)); + return (struct ds_subsurface *)surface->role_data; } static const struct ds_surface_role subsurface_role = diff --git a/src/surface/surface.c b/src/compositor/surface.c similarity index 98% rename from src/surface/surface.c rename to src/compositor/surface.c index a80c1ac..9e58548 100644 --- a/src/surface/surface.c +++ b/src/compositor/surface.c @@ -1,11 +1,7 @@ #include -#include "libds/log.h" -#include "libds/surface.h" - #include "region.h" -#include "util.h" -#include "surface-private.h" +#include "compositor_private.h" #define CALLBACK_VERSION 1 @@ -217,7 +213,7 @@ ds_surface_viewport_unset_destination(struct ds_surface_viewport *vp_handle) } struct ds_surface * -ds_surface_create(struct wl_client *client, uint32_t version, uint32_t id) +create_surface(struct wl_client *client, uint32_t version, uint32_t id) { struct ds_surface *surface; @@ -263,11 +259,11 @@ ds_surface_is_ancestor_of(struct ds_surface *surface, while (target_surface && ds_surface_is_subsurface(target_surface)) { - target_subsurface = ds_subsurface_from_ds_surface(target_surface); + target_subsurface = subsurface_from_ds_surface(target_surface); if (!target_subsurface) break; - parent_surface = ds_subsurface_get_parent(target_subsurface); + parent_surface = subsurface_get_parent(target_subsurface); if (surface == parent_surface) return true; @@ -283,11 +279,11 @@ ds_surface_get_root_surface(struct ds_surface *surface) struct ds_subsurface *subsurface; while (ds_surface_is_subsurface(surface)) { - subsurface = ds_subsurface_from_ds_surface(surface); + subsurface = subsurface_from_ds_surface(surface); if (!subsurface) break; - surface = ds_subsurface_get_parent(subsurface); + surface = subsurface_get_parent(subsurface); if (!surface) return NULL; } diff --git a/src/meson.build b/src/meson.build index 7b962a2..4328b75 100644 --- a/src/meson.build +++ b/src/meson.build @@ -5,14 +5,14 @@ libds_files = [ 'allocator.c', 'swapchain.c', 'output.c', - 'compositor.c', - 'subcompositor.c', 'region.c', 'util/time.c', 'util/shm.c', 'util/box.c', - 'surface/surface.c', - 'surface/subsurface.c', + 'compositor/compositor.c', + 'compositor/subcompositor.c', + 'compositor/surface.c', + 'compositor/subsurface.c', 'client_buffer/shm_client_buffer.c', 'xdg_shell/xdg_shell.c', 'xdg_shell/xdg_surface.c', diff --git a/src/subcompositor.h b/src/subcompositor.h deleted file mode 100644 index 71265d0..0000000 --- a/src/subcompositor.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef DS_SUBCOMPOSITOR_H -#define DS_SUBCOMPOSITOR_H - -#include - -struct ds_subcompositor -{ - struct wl_global *global; -}; - -bool -ds_subcompositor_init(struct ds_subcompositor *subcomp, - struct wl_display *display); - -void -ds_subcompositor_finish(struct ds_subcompositor *subcomp); - -#endif diff --git a/src/surface.h b/src/surface.h index a797bd0..31e21e7 100644 --- a/src/surface.h +++ b/src/surface.h @@ -5,9 +5,6 @@ #include "libds/surface.h" -struct ds_surface * -ds_surface_create(struct wl_client *client, uint32_t version, uint32_t id); - bool ds_surface_has_buffer(struct ds_surface *surface); -- 2.7.4 From 88abf3f4fba3c65be02cd5c7b63aec446d1bf7ed Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Thu, 29 Dec 2022 16:16:41 +0900 Subject: [PATCH 08/16] input_device: Put input_device impelmentation into a directoy Change-Id: I4880c9821045ba4ffc5480f756295459048e8939 --- include/libds/interfaces/keyboard.h | 2 -- include/libds/interfaces/pointer.h | 2 -- include/libds/interfaces/touch.h | 2 -- src/{ => input_device}/input_device.c | 8 +++--- src/input_device/input_device_private.h | 8 ++++++ src/{ => input_device}/keyboard.c | 36 ++++++++++++------------- src/{ => input_device}/pointer.c | 48 ++++++++++++++++----------------- src/{ => input_device}/touch.c | 48 ++++++++++++++++----------------- src/meson.build | 8 +++--- 9 files changed, 83 insertions(+), 79 deletions(-) rename src/{ => input_device}/input_device.c (93%) create mode 100644 src/input_device/input_device_private.h rename src/{ => input_device}/keyboard.c (99%) rename src/{ => input_device}/pointer.c (96%) rename src/{ => input_device}/touch.c (96%) diff --git a/include/libds/interfaces/keyboard.h b/include/libds/interfaces/keyboard.h index 720098d..32f5e4d 100644 --- a/include/libds/interfaces/keyboard.h +++ b/include/libds/interfaces/keyboard.h @@ -56,8 +56,6 @@ struct ds_keyboard void ds_keyboard_init(struct ds_keyboard *keyboard, const struct ds_keyboard_interface *iface); -void ds_keyboard_destroy(struct ds_keyboard *keyboard); - void ds_keyboard_notify_key(struct ds_keyboard *keyboard, struct ds_keyboard_event_key *event); diff --git a/include/libds/interfaces/pointer.h b/include/libds/interfaces/pointer.h index 84b0e23..262c8d3 100644 --- a/include/libds/interfaces/pointer.h +++ b/include/libds/interfaces/pointer.h @@ -25,6 +25,4 @@ struct ds_pointer void ds_pointer_init(struct ds_pointer *pointer, const struct ds_pointer_interface *iface); -void ds_pointer_destroy(struct ds_pointer *pointer); - #endif diff --git a/include/libds/interfaces/touch.h b/include/libds/interfaces/touch.h index 25ff4e6..b2731dd 100644 --- a/include/libds/interfaces/touch.h +++ b/include/libds/interfaces/touch.h @@ -25,6 +25,4 @@ struct ds_touch void ds_touch_init(struct ds_touch *touch, const struct ds_touch_interface *iface); -void ds_touch_destroy(struct ds_touch *touch); - #endif diff --git a/src/input_device.c b/src/input_device/input_device.c similarity index 93% rename from src/input_device.c rename to src/input_device/input_device.c index 534bced..da1994d 100644 --- a/src/input_device.c +++ b/src/input_device/input_device.c @@ -9,6 +9,8 @@ #include "libds/interfaces/keyboard.h" #include "libds/interfaces/touch.h" +#include "input_device_private.h" + WL_EXPORT enum ds_input_device_type ds_input_device_get_type(struct ds_input_device *dev) { @@ -82,13 +84,13 @@ ds_input_device_destroy(struct ds_input_device *dev) if (dev->_device) { switch (dev->type) { case DS_INPUT_DEVICE_POINTER: - ds_pointer_destroy(dev->pointer); + pointer_destroy(dev->pointer); break; case DS_INPUT_DEVICE_KEYBOARD: - ds_keyboard_destroy(dev->keyboard); + keyboard_destroy(dev->keyboard); break; case DS_INPUT_DEVICE_TOUCH: - ds_touch_destroy(dev->touch); + touch_destroy(dev->touch); break; default: ds_err("Warning: leaking memory %p %p %d", diff --git a/src/input_device/input_device_private.h b/src/input_device/input_device_private.h new file mode 100644 index 0000000..4113228 --- /dev/null +++ b/src/input_device/input_device_private.h @@ -0,0 +1,8 @@ +#ifndef DS_INPUT_DEVICE_PRIVATE_H +#define DS_INPUT_DEVICE_PRIVATE_H + +void keyboard_destroy(struct ds_keyboard *keyboard); +void pointer_destroy(struct ds_pointer *pointer); +void touch_destroy(struct ds_touch *touch); + +#endif \ No newline at end of file diff --git a/src/keyboard.c b/src/input_device/keyboard.c similarity index 99% rename from src/keyboard.c rename to src/input_device/keyboard.c index 550d72f..193844d 100644 --- a/src/keyboard.c +++ b/src/input_device/keyboard.c @@ -257,24 +257,6 @@ ds_keyboard_init(struct ds_keyboard *keyboard, wl_signal_init(&keyboard->events.repeat_info); } -void -ds_keyboard_destroy(struct ds_keyboard *keyboard) -{ - wl_signal_emit(&keyboard->events.destroy, keyboard); - - if (keyboard->keymap) { - close(keyboard->keymap_fd); - free(keyboard->keymap_string); - xkb_state_unref(keyboard->xkb_state); - xkb_keymap_unref(keyboard->keymap); - } - - if (keyboard->iface && keyboard->iface->destroy) - keyboard->iface->destroy(keyboard); - else - free(keyboard); -} - bool ds_keyboard_get_keymap_fd(struct ds_keyboard *keyboard, int *keymap_fd, size_t *keymap_size) @@ -302,6 +284,24 @@ ds_keyboard_get_repeat_info(struct ds_keyboard *keyboard, int32_t *rate, *delay = keyboard->repeat_info.delay; } +void +keyboard_destroy(struct ds_keyboard *keyboard) +{ + wl_signal_emit(&keyboard->events.destroy, keyboard); + + if (keyboard->keymap) { + close(keyboard->keymap_fd); + free(keyboard->keymap_string); + xkb_state_unref(keyboard->xkb_state); + xkb_keymap_unref(keyboard->keymap); + } + + if (keyboard->iface && keyboard->iface->destroy) + keyboard->iface->destroy(keyboard); + else + free(keyboard); +} + static bool keyboard_modifier_update(struct ds_keyboard *keyboard) { diff --git a/src/pointer.c b/src/input_device/pointer.c similarity index 96% rename from src/pointer.c rename to src/input_device/pointer.c index 5c5cbda..227466c 100644 --- a/src/pointer.c +++ b/src/input_device/pointer.c @@ -2,30 +2,6 @@ #include #include "libds/interfaces/pointer.h" -void -ds_pointer_init(struct ds_pointer *pointer, - const struct ds_pointer_interface *iface) -{ - pointer->iface = iface; - - wl_signal_init(&pointer->events.motion); - wl_signal_init(&pointer->events.motion_absolute); - wl_signal_init(&pointer->events.button); - wl_signal_init(&pointer->events.frame); -} - -void -ds_pointer_destroy(struct ds_pointer *pointer) -{ - if (!pointer) - return; - - if (pointer->iface && pointer->iface->destroy) - pointer->iface->destroy(pointer); - else - free(pointer); -} - WL_EXPORT void ds_pointer_add_motion_listener(struct ds_pointer *pointer, struct wl_listener *listener) @@ -53,3 +29,27 @@ ds_pointer_add_frame_listener(struct ds_pointer *pointer, { wl_signal_add(&pointer->events.frame, listener); } + +void +ds_pointer_init(struct ds_pointer *pointer, + const struct ds_pointer_interface *iface) +{ + pointer->iface = iface; + + wl_signal_init(&pointer->events.motion); + wl_signal_init(&pointer->events.motion_absolute); + wl_signal_init(&pointer->events.button); + wl_signal_init(&pointer->events.frame); +} + +void +pointer_destroy(struct ds_pointer *pointer) +{ + if (!pointer) + return; + + if (pointer->iface && pointer->iface->destroy) + pointer->iface->destroy(pointer); + else + free(pointer); +} \ No newline at end of file diff --git a/src/touch.c b/src/input_device/touch.c similarity index 96% rename from src/touch.c rename to src/input_device/touch.c index 72a3660..8ffe5a5 100644 --- a/src/touch.c +++ b/src/input_device/touch.c @@ -2,30 +2,6 @@ #include #include "libds/interfaces/touch.h" -void -ds_touch_init(struct ds_touch *touch, - const struct ds_touch_interface *iface) -{ - touch->iface = iface; - - wl_signal_init(&touch->events.down); - wl_signal_init(&touch->events.up); - wl_signal_init(&touch->events.motion); - wl_signal_init(&touch->events.frame); -} - -void -ds_touch_destroy(struct ds_touch *touch) -{ - if (!touch) - return; - - if (touch->iface && touch->iface->destroy) - touch->iface->destroy(touch); - else - free(touch); -} - WL_EXPORT void ds_touch_add_down_listener(struct ds_touch *touch, struct wl_listener *listener) @@ -53,3 +29,27 @@ ds_touch_add_frame_listener(struct ds_touch *touch, { wl_signal_add(&touch->events.frame, listener); } + +void +ds_touch_init(struct ds_touch *touch, + const struct ds_touch_interface *iface) +{ + touch->iface = iface; + + wl_signal_init(&touch->events.down); + wl_signal_init(&touch->events.up); + wl_signal_init(&touch->events.motion); + wl_signal_init(&touch->events.frame); +} + +void +touch_destroy(struct ds_touch *touch) +{ + if (!touch) + return; + + if (touch->iface && touch->iface->destroy) + touch->iface->destroy(touch); + else + free(touch); +} \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 4328b75..59043e3 100644 --- a/src/meson.build +++ b/src/meson.build @@ -19,10 +19,10 @@ libds_files = [ 'xdg_shell/xdg_toplevel.c', 'pixel_format.c', 'backend.c', - 'input_device.c', - 'pointer.c', - 'keyboard.c', - 'touch.c', + 'input_device/input_device.c', + 'input_device/pointer.c', + 'input_device/keyboard.c', + 'input_device/touch.c', 'seat/seat.c', 'seat/seat_pointer.c', 'seat/seat_keyboard.c', -- 2.7.4 From 6f33a6efa8f73b1842814177f2b4033e3cf05b6e Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Thu, 29 Dec 2022 16:21:55 +0900 Subject: [PATCH 09/16] input_device: Remove unused include Change-Id: Id761447c4eaa675df8b1e1a3bdfd210fec7f008e --- src/input_device/input_device.c | 3 --- src/input_device/input_device_private.h | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/input_device/input_device.c b/src/input_device/input_device.c index da1994d..d609ef6 100644 --- a/src/input_device/input_device.c +++ b/src/input_device/input_device.c @@ -5,9 +5,6 @@ #include "libds/log.h" #include "libds/interfaces/input_device.h" -#include "libds/interfaces/pointer.h" -#include "libds/interfaces/keyboard.h" -#include "libds/interfaces/touch.h" #include "input_device_private.h" diff --git a/src/input_device/input_device_private.h b/src/input_device/input_device_private.h index 4113228..6bd98b1 100644 --- a/src/input_device/input_device_private.h +++ b/src/input_device/input_device_private.h @@ -1,6 +1,10 @@ #ifndef DS_INPUT_DEVICE_PRIVATE_H #define DS_INPUT_DEVICE_PRIVATE_H +struct ds_keyboard; +struct ds_pointer; +struct ds_touch; + void keyboard_destroy(struct ds_keyboard *keyboard); void pointer_destroy(struct ds_pointer *pointer); void touch_destroy(struct ds_touch *touch); -- 2.7.4 From d950979548ccd94e03bf4ad4c0250b389258f286 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Mon, 20 Mar 2023 13:47:51 +0900 Subject: [PATCH 10/16] util: Fix mismatched declaration of prototype Change-Id: I845c684ea869bfda3a9d57409fc827c99f81677a --- src/util/shm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/shm.c b/src/util/shm.c index 4c94b79..7e6c370 100644 --- a/src/util/shm.c +++ b/src/util/shm.c @@ -115,7 +115,7 @@ create_tmpfile_cloexec(char *tmpname) * XDG_RUNTIME_DIR. */ int -allocate_shm_file(off_t size) +allocate_shm_file(size_t size) { static const char template[] = "/weston-shared-XXXXXX"; const char *path; -- 2.7.4 From 3d217ce3e056491693d739d7a6dc805050b79ef0 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Mon, 20 Mar 2023 13:48:36 +0900 Subject: [PATCH 11/16] Fix build error by -Werror=shadow The global variable of buffer seemed to have been accidently inserted by the commit, 4304a4d4. This removes this unused variable. Change-Id: I98118f54d38912a0e54758c4caeaaab5cb48f3b1 --- src/client_buffer/shm_client_buffer.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client_buffer/shm_client_buffer.c b/src/client_buffer/shm_client_buffer.c index 0b31b7f..a4a0b22 100644 --- a/src/client_buffer/shm_client_buffer.c +++ b/src/client_buffer/shm_client_buffer.c @@ -111,7 +111,6 @@ shm_client_buffer_get_resource(struct ds_buffer *ds_buffer) return buffer->resource; } -struct ds_shm_client_buffer *buffer; static const struct ds_buffer_interface shm_client_buffer_iface = { .destroy = shm_client_buffer_destroy, -- 2.7.4 From 97e09c72831d654e163bd9690b195dddb1291476 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Thu, 11 May 2023 14:46:27 +0900 Subject: [PATCH 12/16] drag: Fix wrong error check That was a mistake made by commit 3f83416b. Change-Id: I2431b9f9a0d5dd6ba1eddb1635d9c8e172c6ec82 --- src/data_device/drag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data_device/drag.c b/src/data_device/drag.c index cd7cddf..be4689d 100644 --- a/src/data_device/drag.c +++ b/src/data_device/drag.c @@ -580,7 +580,7 @@ drag_enter(struct ds_drag *drag, struct ds_surface *surface, if (!data_device) return; - if (data_device_send_drag_enter(data_device, drag->source, + if (!data_device_send_drag_enter(data_device, drag->source, surface_resource, sx, sy)) { return; } -- 2.7.4 From 1b4382bf9a3963ea53a0cf83862c2ee02b00c1af Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 22 Feb 2023 14:10:00 +0900 Subject: [PATCH 13/16] Expose ds_surface as ABI Change-Id: I43ee7c7423915ead7ac0b0f924436e9e84ac9c48 --- include/libds/types/ds_surface.h | 91 +++++++++++++++++++++++++++++++++++++ {src => include/libds/util}/addon.h | 4 +- src/addon.c | 2 +- src/compositor/compositor_private.h | 84 +--------------------------------- 4 files changed, 96 insertions(+), 85 deletions(-) create mode 100644 include/libds/types/ds_surface.h rename {src => include/libds/util}/addon.h (92%) diff --git a/include/libds/types/ds_surface.h b/include/libds/types/ds_surface.h new file mode 100644 index 0000000..1447a2e --- /dev/null +++ b/include/libds/types/ds_surface.h @@ -0,0 +1,91 @@ +#ifndef LIBDS_TYPES_DS_SURFACE_H +#define LIBDS_TYPES_DS_SURFACE_H + +#include +#include + +#include +#include +#include +#include + +enum ds_surface_state_field +{ + DS_SURFACE_STATE_BUFFER = 1 << 0, + DS_SURFACE_STATE_SURFACE_DAMAGE = 1 << 1, + DS_SURFACE_STATE_BUFFER_DAMAGE = 1 << 2, + DS_SURFACE_STATE_OPAQUE_REGION = 1 << 3, + DS_SURFACE_STATE_INPUT_REGION = 1 << 4, + DS_SURFACE_STATE_TRANSFORM = 1 << 5, + DS_SURFACE_STATE_SCALE = 1 << 6, + DS_SURFACE_STATE_FRAME_CALLBACK_LIST = 1 << 7, + DS_SURFACE_STATE_VIEWPORT = 1 << 8, +}; + +struct ds_surface_state +{ + enum ds_surface_state_field committed; + + struct ds_buffer *buffer; + int32_t dx, dy; + pixman_region32_t surface_damage, buffer_damage; + pixman_region32_t opaque, input; + enum wl_output_transform transform; + int32_t scale; + struct wl_list frame_callback_list; + + int width, height; + int buffer_width, buffer_height; + + struct wl_list subsurfaces_below; + struct wl_list subsurfaces_above; + + /** + * The viewport is applied after the surface transform and scale. + * + * If has_src is true, the surface content is cropped to the provided + * rectangle. If has_dst is true, the surface content is scaled to the + * provided rectangle. + */ + struct { + bool has_src, has_dst; + // In coordinates alter scale/transform are applied, but before the + // destination rectangle is applied + struct ds_fbox src; + int dst_width, dst_height; + } viewport; +}; + +struct ds_surface_viewport +{ + bool taken; +}; + +struct ds_surface +{ + struct wl_resource *resource; + + struct ds_buffer *buffer; + + pixman_region32_t buffer_damage; + pixman_region32_t opaque_region; + pixman_region32_t input_region; + + struct ds_surface_state current, pending; + struct ds_surface_viewport viewport_handle; + + const struct ds_surface_role *role; + void *role_data; + + int sx, sy; + + struct { + struct wl_signal commit; + struct wl_signal new_subsurface; + struct wl_signal destroy; + } events; + + struct ds_addon_set addons; +}; + +#endif diff --git a/src/addon.h b/include/libds/util/addon.h similarity index 92% rename from src/addon.h rename to include/libds/util/addon.h index 2e7b0e1..7a5c798 100644 --- a/src/addon.h +++ b/include/libds/util/addon.h @@ -1,5 +1,5 @@ -#ifndef DS_ADDON_H -#define DS_ADDON_H +#ifndef LIBDS_UTIL_ADDON_H +#define LIBDS_UTIL_ADDON_H #include diff --git a/src/addon.c b/src/addon.c index 0deac7a..0d23a24 100644 --- a/src/addon.c +++ b/src/addon.c @@ -1,7 +1,7 @@ #include +#include "libds/util/addon.h" #include "util.h" -#include "addon.h" void ds_addon_set_init(struct ds_addon_set *set) diff --git a/src/compositor/compositor_private.h b/src/compositor/compositor_private.h index 3020939..1860be3 100644 --- a/src/compositor/compositor_private.h +++ b/src/compositor/compositor_private.h @@ -4,101 +4,21 @@ #include #include -#include #include #include "libds/log.h" #include "libds/util/defs.h" #include "libds/util/box.h" -#include "addon.h" -#include "buffer.h" +#include "libds/util/addon.h" +#include "libds/types/ds_surface.h" #include "surface.h" #include "util.h" -enum ds_surface_state_field -{ - DS_SURFACE_STATE_BUFFER = 1 << 0, - DS_SURFACE_STATE_SURFACE_DAMAGE = 1 << 1, - DS_SURFACE_STATE_BUFFER_DAMAGE = 1 << 2, - DS_SURFACE_STATE_OPAQUE_REGION = 1 << 3, - DS_SURFACE_STATE_INPUT_REGION = 1 << 4, - DS_SURFACE_STATE_TRANSFORM = 1 << 5, - DS_SURFACE_STATE_SCALE = 1 << 6, - DS_SURFACE_STATE_FRAME_CALLBACK_LIST = 1 << 7, - DS_SURFACE_STATE_VIEWPORT = 1 << 8, -}; - struct ds_subcompositor { struct wl_global *global; }; -struct ds_surface_state -{ - enum ds_surface_state_field committed; - - struct ds_buffer *buffer; - int32_t dx, dy; - pixman_region32_t surface_damage, buffer_damage; - pixman_region32_t opaque, input; - enum wl_output_transform transform; - int32_t scale; - struct wl_list frame_callback_list; - - int width, height; - int buffer_width, buffer_height; - - struct wl_list subsurfaces_below; - struct wl_list subsurfaces_above; - - /** - * The viewport is applied after the surface transform and scale. - * - * If has_src is true, the surface content is cropped to the provided - * rectangle. If has_dst is true, the surface content is scaled to the - * provided rectangle. - */ - struct { - bool has_src, has_dst; - // In coordinates alter scale/transform are applied, but before the - // destination rectangle is applied - struct ds_fbox src; - int dst_width, dst_height; - } viewport; -}; - -struct ds_surface_viewport -{ - bool taken; -}; - -struct ds_surface -{ - struct wl_resource *resource; - - struct ds_buffer *buffer; - - pixman_region32_t buffer_damage; - pixman_region32_t opaque_region; - pixman_region32_t input_region; - - struct ds_surface_state current, pending; - struct ds_surface_viewport viewport_handle; - - const struct ds_surface_role *role; - void *role_data; - - int sx, sy; - - struct { - struct wl_signal commit; - struct wl_signal new_subsurface; - struct wl_signal destroy; - } events; - - struct ds_addon_set addons; -}; - struct ds_subsurface_parent_state { int32_t x, y; -- 2.7.4 From 696eebccddc7591086560319d2d3b670a1eceeb8 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 22 Feb 2023 09:52:38 +0900 Subject: [PATCH 14/16] subsurface: Add cached states This makes subsurface work with cached states depending on the sync mode. Change-Id: I186de52c6c4bc20329e61e7ec2a85185dedfd6c8 --- src/compositor/compositor_private.h | 19 ++- src/compositor/subsurface.c | 81 +++++++++- src/compositor/surface.c | 287 +++++++++++++++++++----------------- 3 files changed, 252 insertions(+), 135 deletions(-) diff --git a/src/compositor/compositor_private.h b/src/compositor/compositor_private.h index 1860be3..d8cf53b 100644 --- a/src/compositor/compositor_private.h +++ b/src/compositor/compositor_private.h @@ -7,7 +7,6 @@ #include #include "libds/log.h" -#include "libds/util/defs.h" #include "libds/util/box.h" #include "libds/util/addon.h" #include "libds/types/ds_surface.h" @@ -42,6 +41,9 @@ struct ds_subsurface struct wl_listener parent_destroy; } listener; + struct ds_surface_state cached; + bool has_cache; + bool synchronized; bool reordered; bool mapped; @@ -55,6 +57,16 @@ void subcompositor_finish(struct ds_subcompositor *subcomp); struct ds_surface * create_surface(struct wl_client *client, uint32_t version, uint32_t id); +void surface_state_move(struct ds_surface_state *state, + struct ds_surface_state *next); + +void surface_commit_state(struct ds_surface *surface, + struct ds_surface_state *next); + +void surface_state_init(struct ds_surface_state *state); + +void surface_state_finish(struct ds_surface_state *state); + struct ds_surface * ds_surface_get_root_surface(struct ds_surface *surface); @@ -69,4 +81,9 @@ subsurface_from_ds_surface(struct ds_surface *surface); struct ds_surface * subsurface_get_parent(struct ds_subsurface *subsurface); +void subsurface_commit(struct ds_subsurface *subsurface); + +void subsurface_parent_commit(struct ds_subsurface *subsurface, + bool synchronized); + #endif diff --git a/src/compositor/subsurface.c b/src/compositor/subsurface.c index 719bb4c..d21a2a4 100644 --- a/src/compositor/subsurface.c +++ b/src/compositor/subsurface.c @@ -14,6 +14,8 @@ static void subsurface_link_parent(struct ds_subsurface *subsurface, static void subsurface_unlink_parent(struct ds_subsurface *subsurface); static struct ds_subsurface *subsurface_find_sibling(struct ds_subsurface *subsurface, struct ds_surface *surface); +static bool subsurface_is_synchronized(struct ds_subsurface *subsurface); +static void subsurface_synchronized_commit(struct ds_subsurface *subsurface); struct ds_subsurface * create_subsurface(struct wl_resource *subcomp_resource, @@ -70,6 +72,47 @@ ds_surface_is_subsurface(struct ds_surface *surface) return ds_surface_get_role(surface) == &subsurface_role; } +void +subsurface_commit(struct ds_subsurface *subsurface) +{ + struct ds_surface *surface = subsurface->surface; + struct ds_subsurface *child; + + if (subsurface_is_synchronized(subsurface)) { + surface_state_move(&subsurface->cached, &surface->pending); + subsurface->has_cache = true; + } + else { + if (subsurface->has_cache) { + surface_state_move(&subsurface->cached, &surface->pending); + surface_commit_state(surface, &subsurface->cached); + subsurface->has_cache = false; + } + else { + surface_commit_state(surface, &surface->pending); + } + + wl_list_for_each(child, &surface->current.subsurfaces_below, current.link) + subsurface_parent_commit(child, false); + wl_list_for_each(child, &surface->current.subsurfaces_above, current.link) + subsurface_parent_commit(child, false); + } +} + +void +subsurface_parent_commit(struct ds_subsurface *subsurface, bool synchronized) +{ + if (subsurface->current.x != subsurface->pending.x || + subsurface->current.y != subsurface->pending.y) { + subsurface->current.x = subsurface->pending.x; + subsurface->current.y = subsurface->pending.y; + } + + if (synchronized || subsurface->synchronized) { + subsurface_synchronized_commit(subsurface); + } +} + WL_EXPORT struct ds_subsurface * ds_subsurface_from_resource(struct wl_resource *resource) { @@ -212,7 +255,8 @@ subsurface_handle_set_desync(struct wl_client *client, if (subsurface->synchronized) { subsurface->synchronized = false; - // TODO: flush + if (!subsurface_is_synchronized(subsurface)) + subsurface_synchronized_commit(subsurface); } } @@ -237,6 +281,7 @@ subsurface_destroy(struct ds_subsurface *subsurface) if (subsurface->surface) subsurface_unlink_surface(subsurface); + surface_state_finish(&subsurface->cached); wl_resource_set_user_data(subsurface->resource, NULL); free(subsurface); @@ -336,3 +381,37 @@ subsurface_find_sibling(struct ds_subsurface *subsurface, struct ds_surface *sur return NULL; } + +static bool +subsurface_is_synchronized(struct ds_subsurface *subsurface) +{ + struct ds_subsurface *iter = subsurface; + + do { + if (iter->synchronized) + return true; + + if (!iter->parent) + break; + } while ((iter = subsurface_from_ds_surface(iter->parent))); + + return false; +} + +static void +subsurface_synchronized_commit(struct ds_subsurface *subsurface) +{ + struct ds_surface *surface = subsurface->surface; + struct ds_subsurface *child; + + if (subsurface->has_cache) { + surface_state_move(&subsurface->cached, &surface->pending); + surface_commit_state(surface, &subsurface->cached); + subsurface->has_cache = false; + } + + wl_list_for_each(child, &surface->current.subsurfaces_below, current.link) + subsurface_parent_commit(child, true); + wl_list_for_each(child, &surface->current.subsurfaces_above, current.link) + subsurface_parent_commit(child, true); +} diff --git a/src/compositor/surface.c b/src/compositor/surface.c index 9e58548..7ab9b29 100644 --- a/src/compositor/surface.c +++ b/src/compositor/surface.c @@ -8,15 +8,12 @@ static const struct wl_surface_interface surface_impl; static void surface_handle_resource_destroy(struct wl_resource *resource); -static void surface_state_init(struct ds_surface_state *state); -static void surface_state_finish(struct ds_surface_state *state); -static void surface_state_move(struct ds_surface_state *state, - struct ds_surface_state *next); static void surface_finalize_pending(struct ds_surface *surface); -static void surface_commit_state(struct ds_surface *surface, - struct ds_surface_state *next); static bool surface_for_each(struct ds_surface *surface, int x, int y, ds_surface_for_each_func_t iterator, void *data); +static void surface_update_damage(pixman_region32_t *buffer_damage, + struct ds_surface_state *current, struct ds_surface_state *pending); +static void surface_update_buffer(struct ds_surface *surface); WL_EXPORT void ds_surface_add_destroy_listener(struct ds_surface *surface, @@ -303,6 +300,147 @@ ds_surface_get_wl_resource(struct ds_surface *surface) return surface->resource; } +void +surface_state_move(struct ds_surface_state *state, struct ds_surface_state *next) +{ + state->width = next->width; + state->height = next->height; + state->buffer_width = next->buffer_width; + state->buffer_height = next->buffer_height; + + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_SCALE)) + state->scale = next->scale; + + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_TRANSFORM)) + state->transform = next->transform; + + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_BUFFER)) { + state->dx = next->dx; + state->dy = next->dy; + next->dx = next->dy = 0; + + if (state->buffer) { + ds_buffer_unlock(state->buffer); + state->buffer = NULL; + } + + if (next->buffer) { + state->buffer = ds_buffer_lock(next->buffer); + ds_buffer_unlock(next->buffer); + next->buffer = NULL; + } + } + else { + state->dx = state->dy = 0; + } + + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_SURFACE_DAMAGE)) { + pixman_region32_copy(&state->surface_damage, &next->surface_damage); + pixman_region32_clear(&next->surface_damage); + } + else + pixman_region32_clear(&state->surface_damage); + + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_BUFFER_DAMAGE)) { + pixman_region32_copy(&state->buffer_damage, &next->buffer_damage); + pixman_region32_clear(&next->buffer_damage); + } + else + pixman_region32_clear(&state->buffer_damage); + + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_OPAQUE_REGION)) + pixman_region32_copy(&state->opaque, &next->opaque); + + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_INPUT_REGION)) + pixman_region32_copy(&state->input, &next->input); + + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_VIEWPORT)) + memcpy(&state->viewport, &next->viewport, sizeof(state->viewport)); + + if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_FRAME_CALLBACK_LIST)) { + wl_list_insert_list(&state->frame_callback_list, + &next->frame_callback_list); + wl_list_init(&next->frame_callback_list); + } + + // FIXME + // state->committed |= next->committed; ?? + state->committed = next->committed; + next->committed = 0; +} + +void +surface_commit_state(struct ds_surface *surface, struct ds_surface_state *next) +{ + struct ds_subsurface *subsurface; + + surface_finalize_pending(surface); + + surface->sx += next->dx; + surface->sy += next->dy; + surface_update_damage(&surface->buffer_damage, &surface->current, next); + + surface_state_move(&surface->current, next); + + // FIXME no need? + if (DS_FLAG_IS_SET(surface->current.committed, DS_SURFACE_STATE_BUFFER)) + surface_update_buffer(surface); + + + wl_list_for_each_reverse(subsurface, &surface->pending.subsurfaces_above, + pending.link) { + wl_list_remove(&subsurface->current.link); + wl_list_insert(&surface->current.subsurfaces_above, + &subsurface->current.link); + } + wl_list_for_each_reverse(subsurface, &surface->pending.subsurfaces_below, + pending.link) { + wl_list_remove(&subsurface->current.link); + wl_list_insert(&surface->current.subsurfaces_below, + &subsurface->current.link); + } + + if (surface->role && surface->role->commit) + surface->role->commit(surface); + + wl_signal_emit(&surface->events.commit, surface); +} + +void +surface_state_init(struct ds_surface_state *state) +{ + state->scale = 1; + state->transform = WL_OUTPUT_TRANSFORM_NORMAL; + + wl_list_init(&state->subsurfaces_above); + wl_list_init(&state->subsurfaces_below); + + wl_list_init(&state->frame_callback_list); + + pixman_region32_init(&state->surface_damage); + pixman_region32_init(&state->buffer_damage); + pixman_region32_init(&state->opaque); + pixman_region32_init_rect(&state->input, + INT32_MIN, INT32_MIN, UINT32_MAX, UINT32_MAX); +} + +void +surface_state_finish(struct ds_surface_state *state) +{ + struct wl_resource *resource, *tmp; + + if (state->buffer) + ds_buffer_unlock(state->buffer); + + wl_resource_for_each_safe(resource, tmp, &state->frame_callback_list) + wl_resource_destroy(resource); + + pixman_region32_fini(&state->surface_damage); + pixman_region32_fini(&state->buffer_damage); + pixman_region32_fini(&state->opaque); + pixman_region32_fini(&state->input); +} + static void surface_handle_destroy(struct wl_client *client, struct wl_resource *resource) { @@ -442,18 +580,24 @@ static void surface_handle_commit(struct wl_client *client, struct wl_resource *resource) { struct ds_surface *surface; + struct ds_subsurface *subsurface, *child; surface = wl_resource_get_user_data(resource); ds_dbg("ds_surface(%p) commit", surface); - // TODO handle subsurface - - surface_finalize_pending(surface); + if (ds_surface_is_subsurface(surface)) { + subsurface = subsurface_from_ds_surface(surface); + subsurface_commit(subsurface); + return; + } surface_commit_state(surface, &surface->pending); - // TODO handle subsurfaces of a given surface + wl_list_for_each(child, &surface->current.subsurfaces_below, current.link) + subsurface_parent_commit(child, false); + wl_list_for_each(child, &surface->current.subsurfaces_above, current.link) + subsurface_parent_commit(child, false); } static void @@ -564,110 +708,6 @@ surface_handle_resource_destroy(struct wl_resource *resource) } static void -surface_state_init(struct ds_surface_state *state) -{ - state->scale = 1; - state->transform = WL_OUTPUT_TRANSFORM_NORMAL; - - wl_list_init(&state->subsurfaces_above); - wl_list_init(&state->subsurfaces_below); - - wl_list_init(&state->frame_callback_list); - - pixman_region32_init(&state->surface_damage); - pixman_region32_init(&state->buffer_damage); - pixman_region32_init(&state->opaque); - pixman_region32_init_rect(&state->input, - INT32_MIN, INT32_MIN, UINT32_MAX, UINT32_MAX); -} - -static void -surface_state_finish(struct ds_surface_state *state) -{ - struct wl_resource *resource, *tmp; - - if (state->buffer) - ds_buffer_unlock(state->buffer); - - wl_resource_for_each_safe(resource, tmp, &state->frame_callback_list) - wl_resource_destroy(resource); - - pixman_region32_fini(&state->surface_damage); - pixman_region32_fini(&state->buffer_damage); - pixman_region32_fini(&state->opaque); - pixman_region32_fini(&state->input); -} - -static void -surface_state_move(struct ds_surface_state *state, struct ds_surface_state *next) -{ - state->width = next->width; - state->height = next->height; - state->buffer_width = next->buffer_width; - state->buffer_height = next->buffer_height; - - if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_SCALE)) - state->scale = next->scale; - - if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_TRANSFORM)) - state->transform = next->transform; - - if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_BUFFER)) { - state->dx = next->dx; - state->dy = next->dy; - next->dx = next->dy = 0; - - if (state->buffer) { - ds_buffer_unlock(state->buffer); - state->buffer = NULL; - } - - if (next->buffer) { - state->buffer = ds_buffer_lock(next->buffer); - ds_buffer_unlock(next->buffer); - next->buffer = NULL; - } - } - else { - state->dx = state->dy = 0; - } - - if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_SURFACE_DAMAGE)) { - pixman_region32_copy(&state->surface_damage, &next->surface_damage); - pixman_region32_clear(&next->surface_damage); - } - else - pixman_region32_clear(&state->surface_damage); - - if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_BUFFER_DAMAGE)) { - pixman_region32_copy(&state->buffer_damage, &next->buffer_damage); - pixman_region32_clear(&next->buffer_damage); - } - else - pixman_region32_clear(&state->buffer_damage); - - if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_OPAQUE_REGION)) - pixman_region32_copy(&state->opaque, &next->opaque); - - if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_INPUT_REGION)) - pixman_region32_copy(&state->input, &next->input); - - if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_VIEWPORT)) - memcpy(&state->viewport, &next->viewport, sizeof(state->viewport)); - - if (DS_FLAG_IS_SET(next->committed, DS_SURFACE_STATE_FRAME_CALLBACK_LIST)) { - wl_list_insert_list(&state->frame_callback_list, - &next->frame_callback_list); - wl_list_init(&next->frame_callback_list); - } - - // FIXME - // state->committed |= next->committed; ?? - state->committed = next->committed; - next->committed = 0; -} - -static void surface_state_viewport_src_size(struct ds_surface_state *state, int *out_width, int *out_height) { @@ -826,25 +866,6 @@ surface_update_buffer(struct ds_surface *surface) } } -static void -surface_commit_state(struct ds_surface *surface, struct ds_surface_state *next) -{ - surface->sx += next->dx; - surface->sy += next->dy; - surface_update_damage(&surface->buffer_damage, &surface->current, next); - - surface_state_move(&surface->current, next); - - // FIXME no need? - if (DS_FLAG_IS_SET(surface->current.committed, DS_SURFACE_STATE_BUFFER)) - surface_update_buffer(surface); - - if (surface->role && surface->role->commit) - surface->role->commit(surface); - - wl_signal_emit(&surface->events.commit, surface); -} - static bool surface_for_each(struct ds_surface *surface, int x, int y, ds_surface_for_each_func_t iterator, void *data) -- 2.7.4 From 98ebe2feee9e2c475bcfba9a98e86d2108b98fcd Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Fri, 28 Apr 2023 14:06:33 +0900 Subject: [PATCH 15/16] subsurface: Destroy after destruction of parent surface A subsurface will be destroyed after its parent surface because the subsurface becomes inert when its parent is destroyed. Thus, we can make sure that a subsurface always has a valid parent. Change-Id: I50ac03e9e3e7bd4373a2f028d89697d597016889 --- src/compositor/subsurface.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/compositor/subsurface.c b/src/compositor/subsurface.c index d21a2a4..b3bc455 100644 --- a/src/compositor/subsurface.c +++ b/src/compositor/subsurface.c @@ -318,7 +318,7 @@ subsurface_handle_parent_destroy(struct wl_listener *listener, subsurface = wl_container_of(listener, subsurface, listener.parent_destroy); - subsurface_unlink_parent(subsurface); + subsurface_destroy(subsurface); } static void @@ -390,9 +390,6 @@ subsurface_is_synchronized(struct ds_subsurface *subsurface) do { if (iter->synchronized) return true; - - if (!iter->parent) - break; } while ((iter = subsurface_from_ds_surface(iter->parent))); return false; -- 2.7.4 From cbc74401075237210066d0becba41d7227a18a25 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 22 Feb 2023 14:35:35 +0900 Subject: [PATCH 16/16] Expose ds_subsurface as ABI Change-Id: I57a13628ea72393ec0b4d89442ee20bc9b5751b0 --- include/libds/types/ds_subsurface.h | 40 +++++++++++++++++++++++++++++++++++++ src/compositor/compositor_private.h | 32 +---------------------------- 2 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 include/libds/types/ds_subsurface.h diff --git a/include/libds/types/ds_subsurface.h b/include/libds/types/ds_subsurface.h new file mode 100644 index 0000000..b50b962 --- /dev/null +++ b/include/libds/types/ds_subsurface.h @@ -0,0 +1,40 @@ +#ifndef LIBDS_TYPES_DS_SUBSURFACE_H +#define LIBDS_TYPES_DS_SUBSURFACE_H + +#include + +#include +#include + +struct ds_subsurface_parent_state +{ + int32_t x, y; + struct wl_list link; +}; + +struct ds_subsurface +{ + struct wl_resource *resource; + struct ds_surface *surface; + struct ds_surface *parent; + + struct ds_subsurface_parent_state current, pending; + + struct { + struct wl_signal destroy; + } events; + + struct { + struct wl_listener surface_destroy; + struct wl_listener parent_destroy; + } listener; + + struct ds_surface_state cached; + bool has_cache; + + bool synchronized; + bool reordered; + bool mapped; +}; + +#endif diff --git a/src/compositor/compositor_private.h b/src/compositor/compositor_private.h index d8cf53b..1663014 100644 --- a/src/compositor/compositor_private.h +++ b/src/compositor/compositor_private.h @@ -10,6 +10,7 @@ #include "libds/util/box.h" #include "libds/util/addon.h" #include "libds/types/ds_surface.h" +#include "libds/types/ds_subsurface.h" #include "surface.h" #include "util.h" @@ -18,37 +19,6 @@ struct ds_subcompositor struct wl_global *global; }; -struct ds_subsurface_parent_state -{ - int32_t x, y; - struct wl_list link; -}; - -struct ds_subsurface -{ - struct wl_resource *resource; - struct ds_surface *surface; - struct ds_surface *parent; - - struct ds_subsurface_parent_state current, pending; - - struct { - struct wl_signal destroy; - } events; - - struct { - struct wl_listener surface_destroy; - struct wl_listener parent_destroy; - } listener; - - struct ds_surface_state cached; - bool has_cache; - - bool synchronized; - bool reordered; - bool mapped; -}; - bool subcompositor_init(struct ds_subcompositor *subcomp, struct wl_display *display); -- 2.7.4