commit f8ab5ed

Michael Forney  ·  2013-12-17 17:02:00 +0000 UTC
parent dcc33a0
drm: Move initialization from compositor.c to swc.c
11 files changed,  +144, -174
+4, -30
 1@@ -3,6 +3,7 @@
 2 #include "compositor_surface.h"
 3 #include "cursor_surface.h"
 4 #include "data_device_manager.h"
 5+#include "drm.h"
 6 #include "internal.h"
 7 #include "output.h"
 8 #include "pointer.h"
 9@@ -15,8 +16,6 @@
10 #include <stdio.h>
11 #include <xkbcommon/xkbcommon-keysyms.h>
12 
13-static const char default_seat[] = "seat0";
14-
15 static void calculate_damage(struct swc_compositor * compositor)
16 {
17     struct swc_surface * surface;
18@@ -340,23 +339,9 @@ bool swc_compositor_initialize(struct swc_compositor * compositor,
19         .motion = &handle_motion
20     };
21 
22-    /* TODO: configurable seat */
23-    if (!swc_drm_initialize(&compositor->drm, default_seat))
24-    {
25-        printf("could not initialize drm\n");
26-        goto error0;
27-    }
28-
29-    wl_signal_add(&compositor->drm.event_signal, &compositor->drm_listener);
30-    swc_drm_add_event_sources(&compositor->drm, event_loop);
31+    wl_signal_add(&swc.drm->event_signal, &compositor->drm_listener);
32 
33-    if (!swc_renderer_initialize(&compositor->renderer, &compositor->drm))
34-    {
35-        printf("could not initialize renderer\n");
36-        goto error1;
37-    }
38-
39-    outputs = swc_drm_create_outputs(&compositor->drm);
40+    outputs = swc_drm_create_outputs();
41 
42     if (outputs)
43     {
44@@ -367,7 +352,7 @@ bool swc_compositor_initialize(struct swc_compositor * compositor,
45     else
46     {
47         printf("could not create outputs\n");
48-        goto error2;
49+        return false;
50     }
51 
52     pixman_region32_init(&compositor->damage);
53@@ -387,13 +372,6 @@ bool swc_compositor_initialize(struct swc_compositor * compositor,
54 
55 
56     return true;
57-
58-  error2:
59-    swc_renderer_finalize(&compositor->renderer);
60-  error1:
61-    swc_drm_finish(&compositor->drm);
62-  error0:
63-    return false;
64 }
65 
66 void swc_compositor_finish(struct swc_compositor * compositor)
67@@ -405,8 +383,6 @@ void swc_compositor_finish(struct swc_compositor * compositor)
68         swc_output_finish(output);
69         free(output);
70     }
71-
72-    swc_drm_finish(&compositor->drm);
73 }
74 
75 void swc_compositor_add_globals(struct swc_compositor * compositor,
76@@ -417,8 +393,6 @@ void swc_compositor_add_globals(struct swc_compositor * compositor,
77     wl_global_create(display, &wl_compositor_interface, 3, compositor,
78                      &bind_compositor);
79 
80-    swc_drm_add_globals(&compositor->drm, display);
81-
82     wl_list_for_each(output, &compositor->outputs, link)
83     {
84         swc_output_add_globals(output, display);
+0, -2
 1@@ -1,7 +1,6 @@
 2 #ifndef SWC_COMPOSITOR_H
 3 #define SWC_COMPOSITOR_H
 4 
 5-#include "drm.h"
 6 #include "pointer.h"
 7 #include "renderer.h"
 8 
 9@@ -11,7 +10,6 @@ struct swc_compositor
10 {
11     struct wl_display * display;
12 
13-    struct swc_drm drm;
14     struct swc_renderer renderer;
15 
16     struct wl_list outputs;
+93, -73
  1@@ -40,13 +40,25 @@
  2 #include <wayland-server.h>
  3 #include "protocol/wayland-drm-server-protocol.h"
  4 
  5+struct swc_drm drm_global;
  6+
  7+static struct
  8+{
  9+    uint32_t id;
 10+    char * path;
 11+
 12+    uint32_t taken_output_ids;
 13+
 14+    struct wl_global * global;
 15+    struct wl_event_source * event_source;
 16+} drm;
 17+
 18 static void authenticate(struct wl_client * client,
 19                          struct wl_resource * resource, uint32_t magic)
 20 {
 21-    struct swc_drm * drm = wl_resource_get_user_data(resource);
 22     int ret;
 23 
 24-    if ((ret = drmAuthMagic(drm->fd, magic)) == 0)
 25+    if ((ret = drmAuthMagic(swc.drm->fd, magic)) == 0)
 26         wl_drm_send_authenticated(resource);
 27     else
 28     {
 29@@ -60,11 +72,10 @@ static void create_buffer(struct wl_client * client,
 30                           uint32_t name, int32_t width, int32_t height,
 31                           uint32_t stride, uint32_t format)
 32 {
 33-    struct swc_drm * drm = wl_resource_get_user_data(resource);
 34     struct wld_drawable * drawable;
 35     struct swc_drm_buffer * buffer;
 36 
 37-    drawable = wld_drm_import_gem(drm->context, width, height, format,
 38+    drawable = wld_drm_import_gem(swc.drm->context, width, height, format,
 39                                   name, stride);
 40 
 41     if (!drawable)
 42@@ -103,11 +114,11 @@ static void create_prime_buffer(struct wl_client * client,
 43                                 int32_t offset1, int32_t stride1,
 44                                 int32_t offset2, int32_t stride2)
 45 {
 46-    struct swc_drm * drm = wl_resource_get_user_data(resource);
 47     struct wld_drawable * drawable;
 48     struct swc_drm_buffer * buffer;
 49 
 50-    drawable = wld_drm_import(drm->context, width, height, format, fd, stride0);
 51+    drawable = wld_drm_import(swc.drm->context, width, height, format,
 52+                              fd, stride0);
 53     close(fd);
 54 
 55     if (!drawable)
 56@@ -199,7 +210,7 @@ static struct udev_device * find_primary_drm_device(const char * seat)
 57     return drm_device;
 58 }
 59 
 60-static bool find_available_crtc(struct swc_drm * drm, drmModeRes * resources,
 61+static bool find_available_crtc(drmModeRes * resources,
 62                                 drmModeConnector * connector,
 63                                 uint32_t taken_crtcs, uint32_t * crtc)
 64 {
 65@@ -211,7 +222,8 @@ static bool find_available_crtc(struct swc_drm * drm, drmModeRes * resources,
 66          encoder_index < connector->count_encoders;
 67          ++encoder_index)
 68     {
 69-        encoder = drmModeGetEncoder(drm->fd, connector->encoders[encoder_index]);
 70+        encoder = drmModeGetEncoder(swc.drm->fd,
 71+                                    connector->encoders[encoder_index]);
 72         possible_crtcs = encoder->possible_crtcs;
 73         drmModeFreeEncoder(encoder);
 74 
 75@@ -232,11 +244,9 @@ static bool find_available_crtc(struct swc_drm * drm, drmModeRes * resources,
 76     return false;
 77 }
 78 
 79-static bool find_available_id(struct swc_drm * drm, uint32_t * id)
 80+static bool find_available_id(uint32_t * id)
 81 {
 82-    uint32_t index = __builtin_ffsl(~drm->taken_output_ids);
 83-
 84-    printf("drm->taken_output_ids: %u, index: %u\n", drm->taken_output_ids, index);
 85+    uint32_t index = __builtin_ffsl(~drm.taken_output_ids);
 86 
 87     if (index == 0)
 88         return false;
 89@@ -262,7 +272,7 @@ static void handle_page_flip(int fd, unsigned int sequence, unsigned int sec,
 90 
 91     /* XXX: It doesn't make sense for multiple things to be listening for page
 92      *      flips (or does it?). Maybe this should be a callback instead? */
 93-    swc_send_event(&output->drm->event_signal, SWC_DRM_PAGE_FLIP, &event_data);
 94+    swc_send_event(&swc.drm->event_signal, SWC_DRM_PAGE_FLIP, &event_data);
 95 }
 96 
 97 static drmEventContext event_context = {
 98@@ -278,14 +288,33 @@ static int handle_data(int fd, uint32_t mask, void * data)
 99     return 1;
100 }
101 
102-bool swc_drm_initialize(struct swc_drm * drm, const char * seat)
103+static void bind_drm(struct wl_client * client, void * data, uint32_t version,
104+                     uint32_t id)
105+{
106+    struct wl_resource * resource;
107+
108+    if (version >= 2)
109+        version = 2;
110+
111+    resource = wl_resource_create(client, &wl_drm_interface, version, id);
112+    wl_resource_set_implementation(resource, &drm_implementation, NULL, NULL);
113+
114+    if (version >= 2)
115+        wl_drm_send_capabilities(resource, WL_DRM_CAPABILITY_PRIME);
116+
117+    wl_drm_send_device(resource, drm.path);
118+    wl_drm_send_format(resource, WL_DRM_FORMAT_XRGB8888);
119+    wl_drm_send_format(resource, WL_DRM_FORMAT_ARGB8888);
120+}
121+
122+bool swc_drm_initialize(const char * seat_name)
123 {
124     const char * sysnum;
125     char * end;
126 
127-    wl_signal_init(&drm->event_signal);
128+    wl_signal_init(&swc.drm->event_signal);
129 
130-    struct udev_device * drm_device = find_primary_drm_device(seat);
131+    struct udev_device * drm_device = find_primary_drm_device(seat_name);
132 
133     if (!drm_device)
134     {
135@@ -295,9 +324,7 @@ bool swc_drm_initialize(struct swc_drm * drm, const char * seat)
136 
137     /* XXX: Why do we need the sysnum? */
138     sysnum = udev_device_get_sysnum(drm_device);
139-    drm->id = strtoul(sysnum, &end, 10);
140-
141-    drm->taken_output_ids = 0;
142+    drm.id = strtoul(sysnum, &end, 10);
143 
144     if (*end != '\0')
145     {
146@@ -306,74 +333,65 @@ bool swc_drm_initialize(struct swc_drm * drm, const char * seat)
147         goto error0;
148     }
149 
150-    printf("sysnum: %s\n", sysnum);
151-
152-    drm->path = strdup(udev_device_get_devnode(drm_device));
153+    drm.taken_output_ids = 0;
154+    drm.path = strdup(udev_device_get_devnode(drm_device));
155     udev_device_unref(drm_device);
156-    drm->fd = swc_launch_open_device(drm->path, O_RDWR | O_CLOEXEC);
157+    swc.drm->fd = swc_launch_open_device(drm.path, O_RDWR | O_CLOEXEC);
158 
159-    if (drm->fd == -1)
160+    if (swc.drm->fd == -1)
161     {
162-        fprintf(stderr, "Could not open %s\n", drm->path);
163+        fprintf(stderr, "Could not open %s\n", drm.path);
164         goto error1;
165     }
166 
167-    if (!(drm->context = wld_drm_create_context(drm->fd)))
168+    if (!(swc.drm->context = wld_drm_create_context(swc.drm->fd)))
169     {
170         fprintf(stderr, "Could not create WLD DRM context\n");
171         goto error2;
172     }
173 
174+    drm.global = wl_global_create(swc.display, &wl_drm_interface, 2,
175+                                  NULL, &bind_drm);
176+
177+    if (!drm.global)
178+    {
179+        ERROR("Could not create wl_drm global\n");
180+        goto error3;
181+    }
182+
183+    drm.event_source = wl_event_loop_add_fd
184+        (swc.event_loop, swc.drm->fd, WL_EVENT_READABLE, &handle_data, NULL);
185+
186+    if (!drm.event_source)
187+    {
188+        ERROR("Could not create DRM event source\n");
189+        goto error4;
190+    }
191+
192     return true;
193 
194+  error4:
195+    wl_global_destroy(drm.global);
196+  error3:
197+    wld_drm_destroy_context(swc.drm->context);
198   error2:
199-    close(drm->fd);
200+    close(swc.drm->fd);
201   error1:
202-    free(drm->path);
203+    free(drm.path);
204   error0:
205     return false;
206 }
207 
208-void swc_drm_finish(struct swc_drm * drm)
209-{
210-    wld_drm_destroy_context(drm->context);
211-    free(drm->path);
212-    close(drm->fd);
213-}
214-
215-void swc_drm_add_event_sources(struct swc_drm * drm,
216-                               struct wl_event_loop * event_loop)
217-{
218-    drm->source = wl_event_loop_add_fd(event_loop, drm->fd, WL_EVENT_READABLE,
219-                                       &handle_data, NULL);
220-}
221-
222-static void bind_drm(struct wl_client * client, void * data, uint32_t version,
223-                     uint32_t id)
224-{
225-    struct swc_drm * drm = data;
226-    struct wl_resource * resource;
227-
228-    if (version >= 2)
229-        version = 2;
230-
231-    resource = wl_resource_create(client, &wl_drm_interface, version, id);
232-    wl_resource_set_implementation(resource, &drm_implementation, drm, NULL);
233-
234-    if (version >= 2)
235-        wl_drm_send_capabilities(resource, WL_DRM_CAPABILITY_PRIME);
236-
237-    wl_drm_send_device(resource, drm->path);
238-    wl_drm_send_format(resource, WL_DRM_FORMAT_XRGB8888);
239-    wl_drm_send_format(resource, WL_DRM_FORMAT_ARGB8888);
240-}
241-
242-void swc_drm_add_globals(struct swc_drm * drm, struct wl_display * display)
243+void swc_drm_finalize()
244 {
245-    wl_global_create(display, &wl_drm_interface, 2, drm, &bind_drm);
246+    wl_event_source_remove(drm.event_source);
247+    wl_global_destroy(drm.global);
248+    wld_drm_destroy_context(swc.drm->context);
249+    free(drm.path);
250+    close(swc.drm->fd);
251 }
252 
253-struct wl_list * swc_drm_create_outputs(struct swc_drm * drm)
254+struct wl_list * swc_drm_create_outputs()
255 {
256     drmModeRes * resources;
257     drmModeConnector * connector;
258@@ -387,7 +405,7 @@ struct wl_list * swc_drm_create_outputs(struct swc_drm * drm)
259     outputs = malloc(sizeof(struct wl_list));
260     wl_list_init(outputs);
261 
262-    resources = drmModeGetResources(drm->fd);
263+    resources = drmModeGetResources(swc.drm->fd);
264     if (!resources)
265     {
266         printf("couldn't get DRM resources\n");
267@@ -400,7 +418,7 @@ struct wl_list * swc_drm_create_outputs(struct swc_drm * drm)
268     for (index = 0; index < resources->count_crtcs; ++index)
269     {
270         printf("crtc[%u]: %u\n", index, resources->crtcs[index]);
271-        crtc = drmModeGetCrtc(drm->fd, resources->crtcs[index]);
272+        crtc = drmModeGetCrtc(swc.drm->fd, resources->crtcs[index]);
273         printf("crtc, id: %u, x: %u, y: %u, width: %u, height: %u\n",
274             crtc->crtc_id, crtc->x, crtc->y, crtc->width, crtc->height);
275         drmModeFreeCrtc(crtc);
276@@ -409,14 +427,16 @@ struct wl_list * swc_drm_create_outputs(struct swc_drm * drm)
277     for (index = 0; index < resources->count_encoders; ++index)
278     {
279         printf("encoder[%u]: %u\n", index, resources->encoders[index]);
280-        drmModeEncoder * encoder = drmModeGetEncoder(drm->fd, resources->encoders[index]);
281+        drmModeEncoder * encoder = drmModeGetEncoder
282+            (swc.drm->fd, resources->encoders[index]);
283         printf("encoder, id: %u, type: %u\n", encoder->encoder_id, encoder->encoder_type);
284         drmModeFreeEncoder(encoder);
285     }
286 
287     for (index = 0; index < resources->count_connectors; ++index)
288     {
289-        connector = drmModeGetConnector(drm->fd, resources->connectors[index]);
290+        connector = drmModeGetConnector(swc.drm->fd,
291+                                        resources->connectors[index]);
292 
293         printf("connector, id: %u, type: %u, type_id: %u, connection: %u\n",
294             connector->connector_id, connector->connector_type,
295@@ -428,14 +448,14 @@ struct wl_list * swc_drm_create_outputs(struct swc_drm * drm)
296             uint32_t crtc_index;
297             uint32_t id;
298 
299-            if (!find_available_crtc(drm, resources, connector, taken_crtcs,
300+            if (!find_available_crtc(resources, connector, taken_crtcs,
301                                      &crtc_index))
302             {
303                 printf("couldn't find crtc for connector %u\n", index);
304                 continue;
305             }
306 
307-            if (!find_available_id(drm, &id))
308+            if (!find_available_id(&id))
309             {
310                 printf("no more available output IDs\n");
311                 break;
312@@ -446,7 +466,7 @@ struct wl_list * swc_drm_create_outputs(struct swc_drm * drm)
313             output->geometry.x = x;
314             output->geometry.y = 0;
315 
316-            if (!swc_output_initialize(output, drm, id,
317+            if (!swc_output_initialize(output, id,
318                                        resources->crtcs[crtc_index], connector))
319             {
320                 drmModeFreeConnector(connector);
321@@ -455,7 +475,7 @@ struct wl_list * swc_drm_create_outputs(struct swc_drm * drm)
322             }
323 
324             taken_crtcs |= 1 << crtc_index;
325-            drm->taken_output_ids |= 1 << id;
326+            drm.taken_output_ids |= 1 << id;
327 
328             wl_list_insert(outputs, &output->link);
329             x += output->geometry.width;
+3, -18
 1@@ -5,8 +5,6 @@
 2 #include <stdint.h>
 3 #include <wayland-server.h>
 4 
 5-struct wld_drm_context * context;
 6-
 7 enum swc_drm_event_type
 8 {
 9     SWC_DRM_PAGE_FLIP
10@@ -21,27 +19,14 @@ struct swc_drm_event_data
11 struct swc_drm
12 {
13     int fd;
14-    uint32_t id;
15-    char * path;
16-
17     struct wld_drm_context * context;
18-
19-    uint32_t taken_output_ids;
20-
21-    struct wl_event_source * source;
22-
23     struct wl_signal event_signal;
24 };
25 
26-bool swc_drm_initialize(struct swc_drm * drm, const char * seat);
27-void swc_drm_finish(struct swc_drm * drm);
28-
29-void swc_drm_add_event_sources(struct swc_drm * drm,
30-                               struct wl_event_loop * event_loop);
31-
32-void swc_drm_add_globals(struct swc_drm * drm, struct wl_display * display);
33+bool swc_drm_initialize(const char * seat);
34+void swc_drm_finalize();
35 
36-struct wl_list * swc_drm_create_outputs(struct swc_drm * drm);
37+struct wl_list * swc_drm_create_outputs();
38 
39 #endif
40 
+1, -0
1@@ -35,6 +35,7 @@ struct swc
2     const struct swc_seat_global * const seat;
3     const struct swc_bindings_global * const bindings;
4     struct swc_compositor * compositor;
5+    struct swc_drm * const drm;
6 };
7 
8 extern struct swc swc;
+5, -6
 1@@ -1,5 +1,6 @@
 2 #include "output.h"
 3 #include "drm.h"
 4+#include "internal.h"
 5 #include "mode.h"
 6 #include "util.h"
 7 
 8@@ -45,7 +46,7 @@ static void bind_output(struct wl_client * client, void * data,
 9         wl_output_send_done(resource);
10 }
11 
12-bool swc_output_initialize(struct swc_output * output, struct swc_drm * drm,
13+bool swc_output_initialize(struct swc_output * output,
14                            uint32_t id, uint32_t crtc_id,
15                            drmModeConnector * connector)
16 {
17@@ -54,8 +55,6 @@ bool swc_output_initialize(struct swc_output * output, struct swc_drm * drm,
18     struct swc_mode * modes;
19     uint32_t index;
20 
21-    output->drm = drm;
22-
23     printf("initializing output with id: %u\n", id);
24 
25     output->id = id;
26@@ -71,8 +70,8 @@ bool swc_output_initialize(struct swc_output * output, struct swc_drm * drm,
27     output->connector_id = connector->connector_id;
28 
29     /* Determine the current CRTC of this output. */
30-    encoder = drmModeGetEncoder(drm->fd, connector->encoder_id);
31-    current_crtc = drmModeGetCrtc(drm->fd, encoder->crtc_id);
32+    encoder = drmModeGetEncoder(swc.drm->fd, connector->encoder_id);
33+    current_crtc = drmModeGetCrtc(swc.drm->fd, encoder->crtc_id);
34     drmModeFreeEncoder(encoder);
35 
36     modes = wl_array_add(&output->modes, connector->count_modes * sizeof *modes);
37@@ -125,7 +124,7 @@ void swc_output_finish(struct swc_output * output)
38         swc_mode_finish(mode);
39     wl_array_release(&output->modes);
40 
41-    drmModeSetCrtc(output->drm->fd, crtc->crtc_id, crtc->buffer_id, crtc->x,
42+    drmModeSetCrtc(swc.drm->fd, crtc->crtc_id, crtc->buffer_id, crtc->x,
43                    crtc->y, &output->connector_id, 1, &crtc->mode);
44     drmModeFreeCrtc(crtc);
45 }
+1, -4
 1@@ -16,8 +16,6 @@ struct swc_output
 2 {
 3     uint32_t id;
 4 
 5-    struct swc_drm * drm;
 6-
 7     /* The geometry of this output */
 8     pixman_rectangle32_t geometry;
 9     uint32_t physical_width, physical_height;
10@@ -44,8 +42,7 @@ struct swc_output
11     struct wl_list link;
12 };
13 
14-bool swc_output_initialize(struct swc_output * output, struct swc_drm * drm,
15-                           uint32_t id, uint32_t crtc_id,
16+bool swc_output_initialize(struct swc_output * output, uint32_t id, uint32_t crtc_id,
17                            drmModeConnector * connector);
18 
19 void swc_output_finish(struct swc_output * output);
+9, -9
 1@@ -23,6 +23,7 @@
 2 
 3 #include "plane.h"
 4 #include "drm.h"
 5+#include "internal.h"
 6 #include "mode.h"
 7 #include "output.h"
 8 
 9@@ -43,7 +44,7 @@ static bool framebuffer_initialize(struct swc_plane * plane)
10     struct framebuffer * buffer
11         = swc_double_buffer_front(&plane->double_buffer);
12 
13-    return drmModeSetCrtc(plane->output->drm->fd, plane->output->crtc_id,
14+    return drmModeSetCrtc(swc.drm->fd, plane->output->crtc_id,
15                           buffer->fb_id, 0, 0, &plane->output->connector_id, 1,
16                           &plane->output->current_mode->info) == 0;
17 }
18@@ -58,7 +59,7 @@ static void * framebuffer_create_buffer(struct swc_plane * plane)
19     if (!(buffer = malloc(sizeof *buffer)))
20         goto error0;
21 
22-    drawable = wld_drm_create_drawable(output->drm->context,
23+    drawable = wld_drm_create_drawable(swc.drm->context,
24                                        output->geometry.width,
25                                        output->geometry.height,
26                                        WLD_FORMAT_XRGB8888);
27@@ -71,7 +72,7 @@ static void * framebuffer_create_buffer(struct swc_plane * plane)
28 
29     handle = wld_drm_get_handle(drawable);
30 
31-    if (drmModeAddFB(plane->output->drm->fd, drawable->width, drawable->height,
32+    if (drmModeAddFB(swc.drm->fd, drawable->width, drawable->height,
33                      24, 32, drawable->pitch, handle, &buffer->fb_id) != 0)
34     {
35         fprintf(stderr, "drmModeAddFB failed\n");
36@@ -94,7 +95,7 @@ static void framebuffer_destroy_buffer(struct swc_plane * plane, void * data)
37 {
38     struct framebuffer * buffer = data;
39 
40-    drmModeRmFB(plane->output->drm->fd, buffer->fb_id);
41+    drmModeRmFB(swc.drm->fd, buffer->fb_id);
42     wld_destroy_drawable(buffer->drawable);
43 }
44 
45@@ -110,7 +111,7 @@ static bool framebuffer_flip(struct swc_plane * plane)
46     struct swc_output * output = plane->output;
47     struct framebuffer * buffer = swc_double_buffer_back(&plane->double_buffer);
48 
49-    return drmModePageFlip(output->drm->fd, output->crtc_id, buffer->fb_id,
50+    return drmModePageFlip(swc.drm->fd, output->crtc_id, buffer->fb_id,
51                            DRM_MODE_PAGE_FLIP_EVENT, output) == 0;
52 }
53 
54@@ -129,7 +130,7 @@ static bool cursor_initialize(struct swc_plane * plane)
55 
56 static void * cursor_create_buffer(struct swc_plane * plane)
57 {
58-    return wld_drm_create_drawable(plane->output->drm->context, 64, 64,
59+    return wld_drm_create_drawable(swc.drm->context, 64, 64,
60                                    WLD_FORMAT_ARGB8888);
61 }
62 
63@@ -151,14 +152,13 @@ static bool cursor_flip(struct swc_plane * plane)
64         = swc_double_buffer_back(&plane->double_buffer);
65     int handle = wld_drm_get_handle(drawable);
66 
67-    return drmModeSetCursor(plane->output->drm->fd, plane->output->crtc_id,
68+    return drmModeSetCursor(swc.drm->fd, plane->output->crtc_id,
69                             handle, 64, 64) == 0;
70 }
71 
72 static bool cursor_move(struct swc_plane * plane, int32_t x, int32_t y)
73 {
74-    return drmModeMoveCursor(plane->output->drm->fd, plane->output->crtc_id,
75-                             x, y) == 0;
76+    return drmModeMoveCursor(swc.drm->fd, plane->output->crtc_id, x, y) == 0;
77 }
78 
79 const struct swc_plane_interface swc_cursor_plane = {
+3, -13
 1@@ -1,6 +1,8 @@
 2 #include "renderer.h"
 3 #include "compositor_surface.h"
 4+#include "drm.h"
 5 #include "drm_buffer.h"
 6+#include "internal.h"
 7 
 8 #include <assert.h>
 9 #include <stdio.h>
10@@ -127,18 +129,6 @@ static void repaint_surface(struct swc_renderer * renderer,
11     pixman_region32_fini(&border_damage);
12 }
13 
14-bool swc_renderer_initialize(struct swc_renderer * renderer,
15-                             struct swc_drm * drm)
16-{
17-    renderer->drm = drm;
18-
19-    return true;
20-}
21-
22-void swc_renderer_finalize(struct swc_renderer * renderer)
23-{
24-}
25-
26 void swc_renderer_set_target(struct swc_renderer * renderer,
27                              struct swc_plane * plane)
28 {
29@@ -206,7 +196,7 @@ void swc_renderer_attach(struct swc_renderer * renderer,
30                  pitch = wl_shm_buffer_get_stride(shm_buffer);
31         void * data = wl_shm_buffer_get_data(shm_buffer);
32 
33-        state->drawable = wld_drm_create_drawable(renderer->drm->context,
34+        state->drawable = wld_drm_create_drawable(swc.drm->context,
35                                                   width, height,
36                                                   wld_format(format));
37         state->src = pixman_image_create_bits_no_clear(pixman_format(format),
+0, -7
 1@@ -1,7 +1,6 @@
 2 #ifndef SWC_RENDERER_H
 3 #define SWC_RENDERER_H
 4 
 5-#include "drm.h"
 6 #include "output.h"
 7 #include "surface.h"
 8 
 9@@ -13,15 +12,9 @@ struct swc_render_target
10 
11 struct swc_renderer
12 {
13-    struct swc_drm * drm;
14     struct swc_render_target target;
15 };
16 
17-bool swc_renderer_initialize(struct swc_renderer * renderer,
18-                             struct swc_drm * drm);
19-
20-void swc_renderer_finalize(struct swc_renderer * renderer);
21-
22 void swc_renderer_set_target(struct swc_renderer * renderer,
23                              struct swc_plane * plane);
24 
+25, -12
  1@@ -25,6 +25,7 @@
  2 #include "bindings.h"
  3 #include "compositor.h"
  4 #include "data_device_manager.h"
  5+#include "drm.h"
  6 #include "internal.h"
  7 #include "keyboard.h"
  8 #include "pointer.h"
  9@@ -39,12 +40,14 @@
 10 
 11 extern const struct swc_seat_global seat_global;
 12 extern const struct swc_bindings_global bindings_global;
 13+extern struct swc_drm drm_global;
 14 static struct swc_compositor compositor;
 15 
 16 struct swc swc = {
 17     .seat = &seat_global,
 18     .bindings = &bindings_global,
 19-    .compositor = &compositor
 20+    .compositor = &compositor,
 21+    .drm = &drm_global,
 22 };
 23 
 24 static void setup_compositor()
 25@@ -83,6 +86,7 @@ bool swc_initialize(struct wl_display * display,
 26     swc.display = display;
 27     swc.event_loop = event_loop ?: wl_display_get_event_loop(display);
 28     swc.manager = manager;
 29+    const char * default_seat = "seat0";
 30 
 31     if (!(swc.udev = udev_new()))
 32     {
 33@@ -90,10 +94,16 @@ bool swc_initialize(struct wl_display * display,
 34         goto error0;
 35     }
 36 
 37+    if (!swc_drm_initialize(default_seat))
 38+    {
 39+        ERROR("Could not initialize DRM\n");
 40+        goto error1;
 41+    }
 42+
 43     if (!swc_compositor_initialize(&compositor, display, swc.event_loop))
 44     {
 45         ERROR("Could not initialize compositor\n");
 46-        goto error1;
 47+        goto error2;
 48     }
 49 
 50     swc_compositor_add_globals(&compositor, display);
 51@@ -101,32 +111,32 @@ bool swc_initialize(struct wl_display * display,
 52     if (!swc_data_device_manager_initialize())
 53     {
 54         ERROR("Could not initialize data device manager\n");
 55-        goto error2;
 56+        goto error3;
 57     }
 58 
 59     if (!swc_seat_initialize())
 60     {
 61         ERROR("Could not initialize seat\n");
 62-        goto error3;
 63+        goto error4;
 64     }
 65 
 66     if (!swc_bindings_initialize())
 67     {
 68         ERROR("Could not initialize bindings\n");
 69-        goto error4;
 70+        goto error5;
 71     }
 72 
 73     if (!swc_shell_initialize())
 74     {
 75         ERROR("Could not initialize shell\n");
 76-        goto error5;
 77+        goto error6;
 78     }
 79 
 80 #ifdef ENABLE_XWAYLAND
 81     if (!swc_xserver_initialize())
 82     {
 83         ERROR("Could not initialize xwayland\n");
 84-        goto error6;
 85+        goto error7;
 86     }
 87 #endif
 88 
 89@@ -134,16 +144,18 @@ bool swc_initialize(struct wl_display * display,
 90 
 91     return true;
 92 
 93-  error6:
 94+  error7:
 95     swc_shell_finalize();
 96-  error5:
 97+  error6:
 98     swc_bindings_finalize();
 99-  error4:
100+  error5:
101     swc_seat_finalize();
102-  error3:
103+  error4:
104     swc_data_device_manager_finalize();
105-  error2:
106+  error3:
107     swc_compositor_finish(&compositor);
108+  error2:
109+    swc_drm_finalize();
110   error1:
111     udev_unref(swc.udev);
112   error0:
113@@ -161,6 +173,7 @@ void swc_finalize()
114     swc_seat_finalize();
115     swc_data_device_manager_finalize();
116     swc_compositor_finish(&compositor);
117+    swc_drm_finalize();
118     udev_unref(swc.udev);
119 }
120