commit b5c8fd0
Michael Forney
·
2013-06-21 07:28:03 +0000 UTC
parent 49e0968
surface: Make swc_surface_new because surfaces are created dynamically
3 files changed,
+30,
-24
+1,
-2
1@@ -222,7 +222,7 @@ static void create_surface(struct wl_client * client,
2 struct swc_surface * surface;
3 struct swc_output * output;
4
5- surface = malloc(sizeof *surface);
6+ surface = swc_surface_new(client, id);
7
8 if (!surface)
9 {
10@@ -245,7 +245,6 @@ static void create_surface(struct wl_client * client,
11 }
12 };
13
14- swc_surface_initialize(surface, client, id);
15 wl_signal_add(&surface->event_signal,
16 &surface->compositor_state.event_listener);
17 wl_resource_add_destroy_listener(surface->resource,
+28,
-18
1@@ -2,6 +2,7 @@
2 #include "event.h"
3 #include "region.h"
4
5+#include <stdlib.h>
6 #include <stdio.h>
7
8 static pixman_box32_t infinite_extents = {
9@@ -20,12 +21,6 @@ static void state_initialize(struct swc_surface_state * state)
10 wl_list_init(&state->frame_callbacks);
11 }
12
13-static void destroy_surface_resource(struct wl_resource * resource)
14-{
15- struct swc_surface * surface = resource->data;
16-
17- swc_surface_finish(surface);
18-}
19
20 static void destroy(struct wl_client * client, struct wl_resource * resource)
21 {
22@@ -173,18 +168,23 @@ struct wl_surface_interface surface_implementation = {
23 .commit = &commit,
24 };
25
26-bool swc_surface_initialize(struct swc_surface * surface,
27- struct wl_client * client, uint32_t id)
28+/**
29+ * Construct a new surface, adding it to the given client as id.
30+ *
31+ * The surface will be free'd automatically when it's resource is destroyed.
32+ *
33+ * @return The newly allocated surface.
34+ */
35+struct swc_surface * swc_surface_new(struct wl_client * client, uint32_t id)
36 {
37- state_initialize(&surface->state);
38- state_initialize(&surface->pending.state);
39+ struct swc_surface * surface;
40
41- surface->resource = wl_client_add_object(client, &wl_surface_interface,
42- &surface_implementation, id, surface);
43- wl_resource_set_destructor(surface->resource, &destroy_surface_resource);
44+ surface = malloc(sizeof *surface);
45
46- wl_signal_init(&surface->event_signal);
47+ if (!surface)
48+ return NULL;
49
50+ /* Initialize the surface. */
51 surface->output_mask = 0;
52 surface->geometry.x = 0;
53 surface->geometry.y = 0;
54@@ -193,11 +193,21 @@ bool swc_surface_initialize(struct swc_surface * surface,
55 surface->border.width = 0;
56 surface->border.color = 0x000000;
57
58- return true;
59-}
60+ state_initialize(&surface->state);
61+ state_initialize(&surface->pending.state);
62
63-void swc_surface_finish(struct swc_surface * surface)
64-{
65+ /* The input region should be intersected with the surface's geometry,
66+ * which at this point is empty. */
67+ pixman_region32_clear(&surface->state.input);
68+
69+ wl_signal_init(&surface->event_signal);
70+
71+ /* Add the surface to the client. */
72+ surface->resource
73+ = wl_client_add_object(client, &wl_surface_interface,
74+ &surface_implementation, id, surface);
75+
76+ return surface;
77 }
78
79 void swc_surface_send_frame_callbacks(struct swc_surface * surface,
+1,
-4
1@@ -62,10 +62,7 @@ struct swc_surface
2 struct wl_list link;
3 };
4
5-bool swc_surface_initialize(struct swc_surface * surface,
6- struct wl_client * client, uint32_t id);
7-
8-void swc_surface_finish(struct swc_surface * surface);
9+struct swc_surface * swc_surface_new(struct wl_client * client, uint32_t id);
10
11 void swc_surface_send_frame_callbacks(struct swc_surface * surface,
12 uint32_t time);