2017-08-09 14:24:28 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <pixman.h>
|
2018-02-12 20:29:23 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <wayland-server.h>
|
2018-02-13 22:48:46 +00:00
|
|
|
#include <wlr/types/wlr_region.h>
|
2017-08-09 14:24:28 +00:00
|
|
|
|
|
|
|
static void region_add(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
int32_t x, int32_t y, int32_t width, int32_t height) {
|
2018-02-13 22:48:46 +00:00
|
|
|
pixman_region32_t *region = wlr_region_from_resource(resource);
|
2017-08-09 14:24:28 +00:00
|
|
|
pixman_region32_union_rect(region, region, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void region_subtract(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
int32_t x, int32_t y, int32_t width, int32_t height) {
|
2018-02-13 22:48:46 +00:00
|
|
|
pixman_region32_t *region = wlr_region_from_resource(resource);
|
2017-08-09 14:24:28 +00:00
|
|
|
pixman_region32_union_rect(region, region, x, y, width, height);
|
|
|
|
|
|
|
|
pixman_region32_t rect;
|
|
|
|
pixman_region32_init_rect(&rect, x, y, width, height);
|
|
|
|
pixman_region32_subtract(region, region, &rect);
|
|
|
|
pixman_region32_fini(&rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void region_destroy(struct wl_client *client, struct wl_resource *resource) {
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
}
|
|
|
|
|
2018-02-13 22:48:46 +00:00
|
|
|
static const struct wl_region_interface region_impl = {
|
2017-08-19 07:20:28 +00:00
|
|
|
.destroy = region_destroy,
|
|
|
|
.add = region_add,
|
|
|
|
.subtract = region_subtract,
|
2017-08-09 14:24:28 +00:00
|
|
|
};
|
|
|
|
|
2018-04-25 23:11:36 +00:00
|
|
|
static void region_handle_resource_destroy(struct wl_resource *resource) {
|
2018-02-13 22:48:46 +00:00
|
|
|
pixman_region32_t *reg = wlr_region_from_resource(resource);
|
2018-04-25 23:11:36 +00:00
|
|
|
|
|
|
|
wl_list_remove(wl_resource_get_link(resource));
|
2018-04-26 16:51:06 +00:00
|
|
|
|
|
|
|
pixman_region32_fini(reg);
|
|
|
|
free(reg);
|
2017-08-09 14:24:28 +00:00
|
|
|
}
|
|
|
|
|
2018-04-26 16:51:06 +00:00
|
|
|
struct wl_resource *wlr_region_create(struct wl_client *client,
|
|
|
|
uint32_t version, uint32_t id, struct wl_list *resource_list) {
|
2017-08-09 14:24:28 +00:00
|
|
|
pixman_region32_t *region = calloc(1, sizeof(pixman_region32_t));
|
2017-08-10 09:57:58 +00:00
|
|
|
if (region == NULL) {
|
2018-04-26 16:51:06 +00:00
|
|
|
wl_client_post_no_memory(client);
|
2018-04-24 22:05:15 +00:00
|
|
|
return NULL;
|
2017-08-10 09:57:58 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 14:24:28 +00:00
|
|
|
pixman_region32_init(region);
|
2017-08-10 09:57:58 +00:00
|
|
|
|
|
|
|
struct wl_resource *region_resource = wl_resource_create(client,
|
2018-04-26 16:51:06 +00:00
|
|
|
&wl_region_interface, version, id);
|
2017-08-10 09:57:58 +00:00
|
|
|
if (region_resource == NULL) {
|
|
|
|
free(region);
|
2018-04-26 16:51:06 +00:00
|
|
|
wl_client_post_no_memory(client);
|
2018-04-24 22:05:15 +00:00
|
|
|
return NULL;
|
2017-08-10 09:57:58 +00:00
|
|
|
}
|
2018-02-13 22:48:46 +00:00
|
|
|
wl_resource_set_implementation(region_resource, ®ion_impl, region,
|
2018-04-25 23:11:36 +00:00
|
|
|
region_handle_resource_destroy);
|
2018-04-26 16:51:06 +00:00
|
|
|
|
|
|
|
struct wl_list *resource_link = wl_resource_get_link(region_resource);
|
|
|
|
if (resource_list != NULL) {
|
|
|
|
wl_list_insert(resource_list, resource_link);
|
|
|
|
} else {
|
|
|
|
wl_list_init(resource_link);
|
|
|
|
}
|
|
|
|
|
2018-04-24 22:05:15 +00:00
|
|
|
return region_resource;
|
2017-08-09 14:24:28 +00:00
|
|
|
}
|
2018-02-13 22:48:46 +00:00
|
|
|
|
|
|
|
pixman_region32_t *wlr_region_from_resource(struct wl_resource *resource) {
|
|
|
|
assert(wl_resource_instance_of(resource, &wl_region_interface,
|
|
|
|
®ion_impl));
|
|
|
|
return wl_resource_get_user_data(resource);
|
|
|
|
}
|