2017-08-09 16:24:28 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <pixman.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <wayland-server.h>
|
2017-08-09 16:24:28 +02: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) {
|
|
|
|
pixman_region32_t *region = wl_resource_get_user_data(resource);
|
|
|
|
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) {
|
|
|
|
pixman_region32_t *region = wl_resource_get_user_data(resource);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_region_interface region_interface = {
|
2017-08-19 09:20:28 +02:00
|
|
|
.destroy = region_destroy,
|
|
|
|
.add = region_add,
|
|
|
|
.subtract = region_subtract,
|
2017-08-09 16:24:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void destroy_region(struct wl_resource *resource) {
|
|
|
|
pixman_region32_t *reg = wl_resource_get_user_data(resource);
|
|
|
|
pixman_region32_fini(reg);
|
|
|
|
free(reg);
|
|
|
|
}
|
|
|
|
|
2017-08-10 11:57:58 +02:00
|
|
|
void wlr_region_create(struct wl_client *client, struct wl_resource *res,
|
|
|
|
uint32_t id) {
|
2017-08-09 16:24:28 +02:00
|
|
|
pixman_region32_t *region = calloc(1, sizeof(pixman_region32_t));
|
2017-08-10 11:57:58 +02:00
|
|
|
if (region == NULL) {
|
|
|
|
wl_resource_post_no_memory(res);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-09 16:24:28 +02:00
|
|
|
pixman_region32_init(region);
|
2017-08-10 11:57:58 +02:00
|
|
|
|
|
|
|
struct wl_resource *region_resource = wl_resource_create(client,
|
|
|
|
&wl_region_interface, 1, id);
|
|
|
|
if (region_resource == NULL) {
|
|
|
|
free(region);
|
|
|
|
wl_resource_post_no_memory(res);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wl_resource_set_implementation(region_resource, ®ion_interface, region,
|
|
|
|
destroy_region);
|
2017-08-09 16:24:28 +02:00
|
|
|
}
|