commit 117c1c7

Michael Forney  ·  2013-06-14 08:33:02 +0000 UTC
parent 4b5d2a8
Implement regions
5 files changed,  +115, -3
+1, -0
1@@ -12,6 +12,7 @@ libswc_la_SOURCES = \
2 	output.c output.h \
3 	buffer.c buffer.h \
4 	surface.c surface.h \
5+	region.c region.h \
6 	renderer.c renderer.h \
7 	seat.c seat.h \
8 	mode.c mode.h \
+11, -0
 1@@ -214,6 +214,17 @@ static void create_surface(struct wl_client * client,
 2 static void create_region(struct wl_client * client,
 3                           struct wl_resource * resource, uint32_t id)
 4 {
 5+    struct swc_region * region;
 6+
 7+    region = malloc(sizeof *region);
 8+
 9+    if (!region)
10+    {
11+        wl_resource_post_no_memory(resource);
12+        return;
13+    }
14+
15+    swc_region_initialize(region, client, id);
16 }
17 
18 struct wl_compositor_interface compositor_implementation = {
+64, -0
 1@@ -0,0 +1,64 @@
 2+#include "region.h"
 3+
 4+#include <stdlib.h>
 5+
 6+static void destroy_region_resource(struct wl_resource * resource)
 7+{
 8+    struct swc_region * region;
 9+
10+    region = resource->data;
11+    swc_region_finish(region);
12+
13+    free(region);
14+}
15+
16+static void region_destroy(struct wl_client * client,
17+                           struct wl_resource * resource)
18+{
19+    wl_resource_destroy(resource);
20+}
21+
22+static void region_add(struct wl_client * client,
23+                       struct wl_resource * resource,
24+                       int32_t x, int32_t y, int32_t width, int32_t height)
25+{
26+    struct swc_region * region = resource->data;
27+
28+    pixman_region32_union_rect(&region->region, &region->region,
29+                               x, y, width, height);
30+}
31+
32+static void region_subtract(struct wl_client * client,
33+                            struct wl_resource * resource,
34+                            int32_t x, int32_t y, int32_t width, int32_t height)
35+{
36+    struct swc_region * region = resource->data;
37+    pixman_region32_t operand;
38+
39+    pixman_region32_init_rect(&operand, x, y, width, height);
40+    pixman_region32_subtract(&region->region, &region->region, &operand);
41+}
42+
43+static const struct wl_region_interface region_implementation = {
44+    .destroy = &region_destroy,
45+    .add = &region_add,
46+    .subtract = &region_subtract
47+};
48+
49+bool swc_region_initialize(struct swc_region * region, struct wl_client * client,
50+                          uint32_t id)
51+{
52+    pixman_region32_init(&region->region);
53+
54+    region->resource = wl_client_add_object(client, &wl_region_interface,
55+                                             &region_implementation, id, region);
56+    wl_resource_set_destructor(region->resource, &destroy_region_resource);
57+
58+    return true;
59+}
60+
61+void swc_region_finish(struct swc_region * region)
62+{
63+    pixman_region32_fini(&region->region);
64+}
65+
+20, -0
 1@@ -0,0 +1,20 @@
 2+#ifndef SWC_REGION_H
 3+#define SWC_REGION_H 1
 4+
 5+#include <stdbool.h>
 6+#include <pixman.h>
 7+#include <wayland-server.h>
 8+
 9+struct swc_region
10+{
11+    struct wl_resource * resource;
12+    pixman_region32_t region;
13+};
14+
15+bool swc_region_initialize(struct swc_region * region, struct wl_client * client,
16+                           uint32_t id);
17+
18+void swc_region_finish(struct swc_region * region);
19+
20+#endif
21+
+19, -3
 1@@ -1,5 +1,6 @@
 2 #include "surface.h"
 3 #include "event.h"
 4+#include "region.h"
 5 
 6 #include <stdio.h>
 7 
 8@@ -102,17 +103,30 @@ void swc_surface_set_opaque_region(struct wl_client * client,
 9 
10     if (region_resource)
11     {
12+        struct swc_region * region = region_resource->data;
13+
14+        pixman_region32_copy(&surface->pending.state.opaque, &region->region);
15     }
16     else
17-    {
18-    }
19+        pixman_region32_clear(&surface->pending.state.opaque);
20 }
21 
22 void swc_surface_set_input_region(struct wl_client * client,
23                                   struct wl_resource * resource,
24-                                  struct wl_resource * region)
25+                                  struct wl_resource * region_resource)
26 {
27+    struct swc_surface * surface = resource->data;
28+
29     printf("surface_set_input_region\n");
30+
31+    if (region_resource)
32+    {
33+        struct swc_region * region = region_resource->data;
34+
35+        pixman_region32_copy(&surface->pending.state.input, &region->region);
36+    }
37+    else
38+        pixman_region32_clear(&surface->pending.state.input);
39 }
40 
41 void swc_surface_commit(struct wl_client * client,
42@@ -145,6 +159,8 @@ void swc_surface_commit(struct wl_client * client,
43 
44     /* Reset pending state */
45     pixman_region32_clear(&surface->pending.state.damage);
46+    pixman_region32_clear(&surface->pending.state.opaque);
47+    pixman_region32_clear(&surface->pending.state.input);
48     surface->pending.state.buffer = surface->state.buffer;
49     wl_list_init(&surface->pending.state.frame_callbacks);
50