commit a291d87

Michael Forney  ·  2013-07-19 07:52:02 +0000 UTC
parent b1a964a
Only create single buffers in wayland-{drm,shm}
7 files changed,  +65, -61
+15, -21
 1@@ -239,32 +239,26 @@ int wld_drm_get_fd(struct wld_drm_context * drm)
 2 }
 3 
 4 struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * drm,
 5-                                              struct wl_surface * surface,
 6                                               uint32_t width, uint32_t height,
 7-                                              uint32_t format)
 8+                                              enum wld_format format,
 9+                                              struct wl_buffer ** buffer)
10 {
11-    struct drm_drawable * drawable0, * drawable1;
12-    uint32_t name0, name1, pitch0, pitch1;
13-    struct wl_buffer * buffer0, * buffer1;
14+    struct drm_drawable * drawable;
15 
16-    if (!wld_drm_has_format(drm, format))
17+    if (buffer && !wld_drm_has_format(drm, format))
18         return NULL;
19 
20-    drawable0 = (void *) drm->interface->create_drawable(drm->context,
21-                                                         width, height, format);
22-    drawable1 = (void *) drm->interface->create_drawable(drm->context,
23-                                                         width, height, format);
24-
25-    buffer0 = wl_drm_create_prime_buffer(drm->wl, drawable0->fd, width, height,
26-                                         format, 0, drawable0->pitch,
27-                                         0, 0, 0, 0);
28-    buffer1 = wl_drm_create_prime_buffer(drm->wl, drawable1->fd, width, height,
29-                                         format, 0, drawable1->pitch,
30-                                         0, 0, 0, 0);
31-
32-    return wld_wayland_create_drawable_from_buffers(surface,
33-                                                    buffer0, &drawable0->base,
34-                                                    buffer1, &drawable1->base);
35+    drawable = (void *) drm->interface->create_drawable(drm->context,
36+                                                        width, height, format);
37+
38+    if (buffer)
39+    {
40+        *buffer = wl_drm_create_prime_buffer(drm->wl, drawable->fd,
41+                                             width, height, format,
42+                                             0, drawable->pitch, 0, 0, 0, 0);
43+    }
44+
45+    return &drawable->base;
46 }
47 
48 void registry_global(void * data, struct wl_registry * registry, uint32_t name,
+3, -3
 1@@ -33,7 +33,7 @@ enum wld_format;
 2 
 3 struct wl_display;
 4 struct wl_event_queue;
 5-struct wl_surface;
 6+struct wl_buffer;
 7 
 8 /**
 9  * Create a new drawable context which creates Wayland buffers through the
10@@ -64,9 +64,9 @@ int wld_drm_get_fd(struct wld_drm_context * context);
11  * Create a new DRM drawable with the specified dimensions.
12  */
13 struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * context,
14-                                              struct wl_surface * surface,
15                                               uint32_t width, uint32_t height,
16-                                              enum wld_format format);
17+                                              enum wld_format format,
18+                                              struct wl_buffer ** buffer);
19 
20 #endif
21 
+3, -2
 1@@ -31,13 +31,14 @@ enum wld_format format;
 2 
 3 struct wl_display;
 4 struct wl_event_queue;
 5+struct wl_buffer;
 6 
 7 typedef void * (* wayland_create_context_func_t)(struct wl_display * display,
 8                                                  struct wl_event_queue * queue);
 9 typedef void (* wayland_destroy_context_func_t)(void * context);
10 typedef struct wld_drawable * (* wayland_create_drawable_func_t)
11-    (void * context, struct wl_surface * surface,
12-     uint32_t width, uint32_t height, enum wld_format format);
13+    (void * context, uint32_t width, uint32_t height, enum wld_format format,
14+     struct wl_buffer ** buffer);
15 
16 struct wld_wayland_interface
17 {
+11, -18
 1@@ -152,9 +152,9 @@ bool wld_shm_has_format(struct wld_shm_context * shm, uint32_t format)
 2 }
 3 
 4 struct wld_drawable * wld_shm_create_drawable(struct wld_shm_context * shm,
 5-                                              struct wl_surface * surface,
 6                                               uint32_t width, uint32_t height,
 7-                                              uint32_t format)
 8+                                              enum wld_format format,
 9+                                              struct wl_buffer ** buffer)
10 {
11     char name[] = "/tmp/wld-XXXXXX";
12     uint32_t pitch = width * format_bytes_per_pixel(format);
13@@ -162,8 +162,7 @@ struct wld_drawable * wld_shm_create_drawable(struct wld_shm_context * shm,
14     int fd;
15     void * data;
16     struct wl_shm_pool * pool;
17-    struct wl_buffer * buffer0, * buffer1;
18-    struct wld_drawable * drawable0, * drawable1;
19+    struct wld_drawable * drawable;
20     uint32_t shm_format = wayland_format(format);
21 
22     fd = mkostemp(name, O_CLOEXEC);
23@@ -173,30 +172,24 @@ struct wld_drawable * wld_shm_create_drawable(struct wld_shm_context * shm,
24 
25     unlink(name);
26 
27-    if (ftruncate(fd, size * 2) < 0)
28+    if (ftruncate(fd, size) < 0)
29         goto error1;
30 
31-    data = mmap(NULL, size * 2, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
32+    data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
33 
34     if (data == MAP_FAILED)
35         goto error1;
36 
37-    pool = wl_shm_create_pool(shm->wl, fd, size * 2);
38-    buffer0 = wl_shm_pool_create_buffer(pool, 0, width, height, pitch,
39-                                        shm_format);
40-    buffer1 = wl_shm_pool_create_buffer(pool, size, width, height, pitch,
41+    drawable = wld_pixman_create_drawable(shm->pixman_context, width, height,
42+                                          data, pitch, format);
43+
44+    pool = wl_shm_create_pool(shm->wl, fd, size);
45+    *buffer = wl_shm_pool_create_buffer(pool, 0, width, height, pitch,
46                                         shm_format);
47     wl_shm_pool_destroy(pool);
48     close(fd);
49 
50-    drawable0 = wld_pixman_create_drawable(shm->pixman_context, width, height,
51-                                           data, pitch, format);
52-    drawable1 = wld_pixman_create_drawable(shm->pixman_context, width, height,
53-                                           data + size, pitch, format);
54-
55-    return wld_wayland_create_drawable_from_buffers(surface,
56-                                                    buffer0, drawable0,
57-                                                    buffer1, drawable1);
58+    return drawable;
59 
60   error1:
61     close(fd);
+3, -3
 1@@ -33,7 +33,7 @@ enum wld_format;
 2 
 3 struct wl_display;
 4 struct wl_event_queue;
 5-struct wl_surface;
 6+struct wl_buffer;
 7 
 8 /**
 9  * Create a new drawable context which creates Wayland buffers through the
10@@ -59,9 +59,9 @@ bool wld_shm_has_format(struct wld_shm_context * context,
11  * Create a new SHM drawable with the specified dimensions.
12  */
13 struct wld_drawable * wld_shm_create_drawable(struct wld_shm_context * context,
14-                                              struct wl_surface * surface,
15                                               uint32_t width, uint32_t height,
16-                                              enum wld_format format);
17+                                              enum wld_format format,
18+                                              struct wl_buffer ** buffer);
19 
20 #endif
21 
+27, -12
 1@@ -41,6 +41,8 @@ struct wld_wayland_context
 2 struct wayland_drawable
 3 {
 4     struct wld_drawable base;
 5+
 6+    struct wld_wayland_context * context;
 7     struct wl_surface * surface;
 8     struct
 9     {
10@@ -175,20 +177,32 @@ struct wld_drawable * wld_wayland_create_drawable
11     (struct wld_wayland_context * context, struct wl_surface * surface,
12      uint32_t width, uint32_t height, enum wld_format format)
13 {
14-    return context->interface->create_drawable(context->context, surface,
15-                                               width, height, format);
16+    struct wayland_drawable * wayland;
17+    struct wld_drawable * drawables[2];
18+    struct wl_buffer * buffers[2];
19+
20+    drawables[0] = context->interface->create_drawable
21+        (context->context, width, height, format, &buffers[0]);
22+    drawables[1] = context->interface->create_drawable
23+        (context->context, width, height, format, &buffers[1]);
24+
25+    wayland = (void *) wld_wayland_create_drawable_from_buffers
26+        (surface, buffers, drawables);
27+
28+    wayland->context = context;
29+
30+    return &wayland->base;
31 }
32 
33 struct wld_drawable * wld_wayland_create_drawable_from_buffers
34     (struct wl_surface * surface,
35-     struct wl_buffer * buffer0, struct wld_drawable * drawable0,
36-     struct wl_buffer * buffer1, struct wld_drawable * drawable1)
37+     struct wl_buffer * buffers[], struct wld_drawable * drawables[])
38 {
39     struct wayland_drawable * wayland;
40     uint32_t * data;
41 
42-    if (drawable0->width != drawable1->width
43-        || drawable0->height != drawable1->height)
44+    if (drawables[0]->width != drawables[1]->width
45+        || drawables[0]->height != drawables[1]->height)
46     {
47         DEBUG("Drawables aren't the same dimensions\n");
48         return NULL;
49@@ -199,16 +213,17 @@ struct wld_drawable * wld_wayland_create_drawable_from_buffers
50     if (!wayland)
51         return NULL;
52 
53-    wayland->buffers[0].buffer = buffer0;
54-    wayland->buffers[1].buffer = buffer1;
55-    wayland->buffers[0].drawable = drawable0;
56-    wayland->buffers[1].drawable = drawable1;
57+    wayland->context = NULL;
58+    wayland->buffers[0].buffer = buffers[0];
59+    wayland->buffers[1].buffer = buffers[1];
60+    wayland->buffers[0].drawable = drawables[0];
61+    wayland->buffers[1].drawable = drawables[1];
62     wayland->front_buffer = 0;
63     wayland->surface = surface;
64 
65     wayland->base.interface = &wayland_draw;
66-    wayland->base.width = drawable0->width;
67-    wayland->base.height = drawable0->height;
68+    wayland->base.width = drawables[0]->width;
69+    wayland->base.height = drawables[0]->height;
70 
71     return &wayland->base;
72 }
+3, -2
 1@@ -81,13 +81,14 @@ struct wld_drawable * wld_wayland_create_drawable
 2  * Create a new Wayland drawable for the given surface, using the given buffers
 3  * and drawables as backing for the surface.
 4  *
 5+ * You must pass exactly two buffers and drawables
 6+ *
 7  * This method does not require a Wayland context to be created because buffers
 8  * and drawables are passed to it explicitly.
 9  */
10 struct wld_drawable * wld_wayland_create_drawable_from_buffers
11     (struct wl_surface * surface,
12-     struct wl_buffer * buffer0, struct wld_drawable * drawable0,
13-     struct wl_buffer * buffer1, struct wld_drawable * drawable1);
14+     struct wl_buffer * buffers[], struct wld_drawable * drawables[]);
15 
16 #endif
17