commit 4f2f9a5

Michael Forney  ·  2014-01-14 00:44:28 +0000 UTC
parent ea86c0d
wayland: Remove surface drawable

This will be replaced in future commits.
2 files changed,  +17, -385
+16, -337
  1@@ -28,59 +28,22 @@
  2 #include <stdlib.h>
  3 #include <wayland-client.h>
  4 
  5-#define BACKBUF(drawable) ((drawable)->buffers[(drawable)->front_buffer ^ 1])
  6-#define FRONTBUF(drawable) ((drawable)->buffers[(drawable)->front_buffer])
  7-
  8-struct wld_wayland_context
  9-{
 10-    struct wld_context base;
 11-    struct wl_display * display;
 12-    struct wl_event_queue * queue;
 13-    const struct wld_wayland_interface * interface;
 14-    struct wld_context * context;
 15-};
 16-
 17-struct wayland_drawable
 18-{
 19-    struct wld_drawable base;
 20-
 21-    struct wld_wayland_context * context;
 22-    struct wl_surface * surface;
 23-    struct
 24-    {
 25-        struct wl_buffer * wl;
 26-        struct wld_drawable * drawable;
 27-        bool busy;
 28-        pixman_region32_t damage;
 29-    } buffers[2];
 30-    uint8_t front_buffer;
 31-    uint32_t damage_tracking;
 32-};
 33-
 34 struct wayland_exporter
 35 {
 36     struct wld_exporter base;
 37     struct wl_buffer * buffer;
 38 };
 39 
 40-static void sync_done(void * data, struct wl_callback * callback,
 41-                      uint32_t msecs);
 42-
 43-static void buffer_release(void * data, struct wl_buffer * buffer);
 44-
 45-#define DRAWABLE_IMPLEMENTS_REGION
 46-#include "interface/drawable.h"
 47 #include "interface/exporter.h"
 48 IMPL(wayland, exporter)
 49 
 50+static void sync_done(void * data, struct wl_callback * callback,
 51+                      uint32_t msecs);
 52+
 53 const struct wl_callback_listener sync_listener = {
 54     .done = &sync_done
 55 };
 56 
 57-const struct wl_buffer_listener buffer_listener = {
 58-    .release = &buffer_release
 59-};
 60-
 61 const static struct wld_wayland_interface * interfaces[] = {
 62 #if WITH_WAYLAND_DRM
 63     [WLD_DRM] = &wayland_drm_interface,
 64@@ -92,24 +55,16 @@ const static struct wld_wayland_interface * interfaces[] = {
 65 };
 66 
 67 EXPORT
 68-struct wld_wayland_context * wld_wayland_create_context
 69+struct wld_context * wld_wayland_create_context
 70     (struct wl_display * display, enum wld_wayland_interface_id id, ...)
 71 {
 72-    struct wld_wayland_context * wayland;
 73+    struct wld_context * context;
 74+    struct wl_event_queue * queue;
 75     va_list requested_interfaces;
 76     bool interfaces_tried[ARRAY_LENGTH(interfaces)] = {0};
 77 
 78-    wayland = malloc(sizeof *wayland);
 79-
 80-    if (!wayland)
 81-        goto error0;
 82-
 83-    if (!(wayland->queue = wl_display_create_queue(display)))
 84-        goto error1;
 85-
 86-    wayland->display = display;
 87-    wayland->context = NULL;
 88-    wayland->interface = NULL;
 89+    if (!(queue = wl_display_create_queue(display)))
 90+        return NULL;
 91 
 92     va_start(requested_interfaces, id);
 93 
 94@@ -118,14 +73,8 @@ struct wld_wayland_context * wld_wayland_create_context
 95         if (interfaces_tried[id] || !interfaces[id])
 96             continue;
 97 
 98-        wayland->context
 99-            = interfaces[id]->create_context(display, wayland->queue);
100-
101-        if (wayland->context)
102-        {
103-            wayland->interface = interfaces[id];
104+        if ((context = interfaces[id]->create_context(display, queue)))
105             break;
106-        }
107 
108         interfaces_tried[id] = true;
109         id = va_arg(requested_interfaces, enum wld_wayland_interface_id);
110@@ -134,131 +83,27 @@ struct wld_wayland_context * wld_wayland_create_context
111     va_end(requested_interfaces);
112 
113     /* If the user specified WLD_ANY, try any remaining interfaces. */
114-    if (!wayland->context && id == WLD_ANY)
115+    if (!context && id == WLD_ANY)
116     {
117         for (id = 0; id < ARRAY_LENGTH(interfaces); ++id)
118         {
119             if (interfaces_tried[id] || !interfaces[id])
120                 continue;
121 
122-            wayland->context
123-                = interfaces[id]->create_context(display, wayland->queue);
124-
125-            if (wayland->context)
126-            {
127-                wayland->interface = interfaces[id];
128+            if ((context = interfaces[id]->create_context(display, queue)))
129                 break;
130-            }
131         }
132     }
133 
134-    if (!wayland->context)
135-    {
136-        DEBUG("Could not initialize any of the specified interfaces\n");
137-        goto error2;
138-    }
139-
140-    return wayland;
141-
142-  error2:
143-    wl_event_queue_destroy(wayland->queue);
144-  error1:
145-    free(wayland);
146-  error0:
147-    return NULL;
148-}
149+    wl_event_queue_destroy(queue);
150 
151-EXPORT
152-void wld_wayland_destroy_context(struct wld_wayland_context * wayland)
153-{
154-    wld_destroy_context(wayland->context);
155-    free(wayland);
156-}
157-
158-EXPORT
159-struct wld_drawable * wld_wayland_create_drawable
160-    (struct wld_wayland_context * context, struct wl_surface * surface,
161-     uint32_t width, uint32_t height, uint32_t format, uint32_t damage_flags)
162-{
163-    struct wayland_drawable * wayland;
164-    union wld_object object;
165-
166-    wayland = malloc(sizeof *wayland);
167-
168-    if (!wayland)
169-        goto error0;
170-
171-    wayland->context = context;
172-    wayland->buffers[0].drawable = wld_create_drawable(context->context,
173-                                                       width, height, format);
174-
175-    if (!wayland->buffers[0].drawable)
176-        goto error1;
177-
178-    wayland->buffers[1].drawable = wld_create_drawable(context->context,
179-                                                       width, height, format);
180-
181-    if (!wayland->buffers[1].drawable)
182-        goto error2;
183-
184-    if (!wld_export(wayland->buffers[0].drawable,
185-                    WLD_WAYLAND_OBJECT_BUFFER, &object))
186+    if (!context)
187     {
188-        goto error3;
189-    }
190-
191-    wayland->buffers[0].wl = object.ptr;
192-
193-    if (!wld_export(wayland->buffers[1].drawable,
194-                    WLD_WAYLAND_OBJECT_BUFFER, &object))
195-    {
196-        goto error3;
197-    }
198-
199-    wayland->buffers[1].wl = object.ptr;
200-
201-    wayland->buffers[0].busy = false;
202-    wayland->buffers[1].busy = false;
203-    pixman_region32_init(&wayland->buffers[0].damage);
204-    pixman_region32_init(&wayland->buffers[1].damage);
205-    wayland->front_buffer = 0;
206-    wayland->surface = surface;
207-    wayland->damage_tracking = damage_flags;
208-
209-    wayland->base.impl = &drawable_impl;
210-    wayland->base.width = width;
211-    wayland->base.height = height;
212-
213-    wl_buffer_add_listener(wayland->buffers[0].wl, &buffer_listener,
214-                           &wayland->buffers[0].busy);
215-    wl_buffer_add_listener(wayland->buffers[1].wl, &buffer_listener,
216-                           &wayland->buffers[1].busy);
217-
218-    return &wayland->base;
219-
220-  error3:
221-    wld_destroy_drawable(wayland->buffers[1].drawable);
222-  error2:
223-    wld_destroy_drawable(wayland->buffers[0].drawable);
224-  error1:
225-    free(wayland);
226-  error0:
227-    return NULL;
228-}
229-
230-EXPORT
231-void wld_wayland_drawable_set_damage_tracking(struct wld_drawable * drawable,
232-                                              uint32_t flags)
233-{
234-    struct wayland_drawable * wayland = (void *) drawable;
235-
236-    if (!wayland->damage_tracking && flags)
237-    {
238-        pixman_region32_clear(&wayland->buffers[0].damage);
239-        pixman_region32_clear(&wayland->buffers[1].damage);
240+        DEBUG("Could not initialize any of the specified interfaces\n");
241+        return NULL;
242     }
243 
244-    wayland->damage_tracking = flags;
245+    return context;
246 }
247 
248 int wayland_roundtrip(struct wl_display * display,
249@@ -324,169 +169,3 @@ void sync_done(void * data, struct wl_callback * callback, uint32_t msecs)
250     wl_callback_destroy(callback);
251 }
252 
253-void buffer_release(void * data, struct wl_buffer * buffer)
254-{
255-    bool * busy = data;
256-
257-    *busy = false;
258-}
259-
260-static void wait_for_backbuf(struct wayland_drawable * wayland)
261-{
262-    if (BACKBUF(wayland).busy)
263-    {
264-        int ret;
265-
266-        do {
267-            ret = wl_display_dispatch_queue(wayland->context->display,
268-                                            wayland->context->queue);
269-        } while (BACKBUF(wayland).busy && ret != -1);
270-    }
271-}
272-
273-static void begin(struct wayland_drawable * wayland)
274-{
275-    /* Wait for the back buffer to become available. */
276-    wait_for_backbuf(wayland);
277-
278-    /* Copy across damage from front buffer. */
279-    if (wayland->damage_tracking & WLD_WAYLAND_DAMAGE_COPY
280-        && pixman_region32_not_empty(&FRONTBUF(wayland).damage))
281-    {
282-        wld_copy_region(FRONTBUF(wayland).drawable,
283-                        BACKBUF(wayland).drawable,
284-                        &FRONTBUF(wayland).damage, 0, 0);
285-        pixman_region32_clear(&FRONTBUF(wayland).damage);
286-    }
287-}
288-
289-void drawable_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
290-                             int32_t x, int32_t y,
291-                             uint32_t width, uint32_t height)
292-{
293-    struct wayland_drawable * wayland = (void *) drawable;
294-
295-    begin(wayland);
296-    wld_fill_rectangle(BACKBUF(wayland).drawable, color, x, y, width, height);
297-
298-    if (wayland->damage_tracking)
299-    {
300-        pixman_region32_union_rect(&BACKBUF(wayland).damage,
301-                                   &BACKBUF(wayland).damage,
302-                                   x, y, width, height);
303-    }
304-}
305-
306-void drawable_fill_region(struct wld_drawable * drawable, uint32_t color,
307-                          pixman_region32_t * region)
308-{
309-    struct wayland_drawable * wayland = (void *) drawable;
310-
311-    begin(wayland);
312-    wld_fill_region(BACKBUF(wayland).drawable, color, region);
313-
314-    if (wayland->damage_tracking)
315-    {
316-        pixman_region32_union(&BACKBUF(wayland).damage,
317-                              &BACKBUF(wayland).damage, region);
318-    }
319-}
320-
321-void drawable_copy_rectangle(struct wld_drawable * src_drawable,
322-                             struct wld_drawable * dst_drawable,
323-                             int32_t src_x, int32_t src_y,
324-                             int32_t dst_x, int32_t dst_y,
325-                             uint32_t width, uint32_t height)
326-{
327-    fprintf(stderr, "wayland: Copy rectangle is not implemented\n");
328-}
329-
330-void drawable_copy_region(struct wld_drawable * src_drawable,
331-                          struct wld_drawable * dst_drawable,
332-                          pixman_region32_t * region,
333-                          int32_t dst_x, int32_t dst_y)
334-{
335-    fprintf(stderr, "wayland: Copy region is not implemented\n");
336-}
337-
338-void drawable_draw_text(struct wld_drawable * drawable,
339-                        struct font * font, uint32_t color,
340-                        int32_t x, int32_t y,
341-                        const char * text, int32_t length,
342-                        struct wld_extents * extents)
343-{
344-    struct wld_extents extents0;
345-    struct wayland_drawable * wayland = (void *) drawable;
346-
347-    if (wayland->damage_tracking && !extents)
348-        extents = &extents0;
349-
350-    begin(wayland);
351-    wld_draw_text_n(BACKBUF(wayland).drawable, &font->base, color,
352-                    x, y, text, length, extents);
353-
354-    if (wayland->damage_tracking)
355-    {
356-        pixman_region32_union_rect(&BACKBUF(wayland).damage,
357-                                   &BACKBUF(wayland).damage,
358-                                   x, y - font->base.ascent,
359-                                   extents->advance, font->base.height);
360-    }
361-}
362-
363-void drawable_write(struct wld_drawable * drawable,
364-                    const void * data, size_t size)
365-{
366-    fprintf(stderr, "wayland: Write is not implemented\n");
367-}
368-
369-pixman_image_t * drawable_map(struct wld_drawable * drawable)
370-{
371-    fprintf(stderr, "wayland: Map is not implemented\n");
372-
373-    return NULL;
374-}
375-
376-void drawable_flush(struct wld_drawable * drawable)
377-{
378-    struct wayland_drawable * wayland = (void *) drawable;
379-
380-    wait_for_backbuf(wayland);
381-
382-    wld_flush(BACKBUF(wayland).drawable);
383-
384-    if (wayland->damage_tracking & WLD_WAYLAND_DAMAGE_SUBMIT)
385-    {
386-        pixman_box32_t * box;
387-        int num_boxes;
388-
389-        box = pixman_region32_rectangles(&BACKBUF(wayland).damage, &num_boxes);
390-
391-        while (num_boxes--)
392-        {
393-            wl_surface_damage(wayland->surface, box->x1, box->y1,
394-                              box->x2 - box->x1, box->y2 - box->y1);
395-            ++box;
396-        }
397-    }
398-
399-    wl_surface_attach(wayland->surface, BACKBUF(wayland).wl, 0, 0);
400-    wl_surface_commit(wayland->surface);
401-
402-    BACKBUF(wayland).busy = true;
403-
404-    wayland->front_buffer ^= 1;
405-}
406-
407-void drawable_destroy(struct wld_drawable * drawable)
408-{
409-    struct wayland_drawable * wayland = (void *) drawable;
410-
411-    wl_buffer_destroy(wayland->buffers[0].wl);
412-    wl_buffer_destroy(wayland->buffers[1].wl);
413-    wld_destroy_drawable(wayland->buffers[0].drawable);
414-    wld_destroy_drawable(wayland->buffers[1].drawable);
415-    pixman_region32_fini(&wayland->buffers[0].damage);
416-    pixman_region32_fini(&wayland->buffers[1].damage);
417-}
418-
+1, -48
 1@@ -27,10 +27,6 @@
 2 #include <stdint.h>
 3 
 4 struct wl_display;
 5-struct wl_surface;
 6-struct wl_buffer;
 7-
 8-struct wld_wayland_context;
 9 
10 enum wld_wayland_interface_id
11 {
12@@ -53,25 +49,6 @@ enum wld_wayland_object_type
13     WLD_WAYLAND_OBJECT_BUFFER   = 0x00020000
14 };
15 
16-enum wld_wayland_damage_flags
17-{
18-    /**
19-     * Copy the damaged region from the front buffer to the back buffer after
20-     * swapping buffers.
21-     *
22-     * This allows you to think of the drawable as a single image.
23-     */
24-    WLD_WAYLAND_DAMAGE_COPY     = 1 << 0,
25-
26-    /**
27-     * Submit the damaged region to the compositor before swapping buffers.
28-     *
29-     * If this is not selected, you must manually damage the surface before
30-     * calling wld_flush.
31-     */
32-    WLD_WAYLAND_DAMAGE_SUBMIT   = 1 << 1
33-};
34-
35 /**
36  * Create a new drawing context which uses various available Wayland interfaces
37  * (such as wl_shm and wl_drm) to create buffers backed by drawables specific
38@@ -84,32 +61,8 @@ enum wld_wayland_damage_flags
39  *
40  * @see enum wld_wayland_interface_id
41  */
42-struct wld_wayland_context * wld_wayland_create_context
43+struct wld_context * wld_wayland_create_context
44     (struct wl_display * display, enum wld_wayland_interface_id id, ...);
45 
46-/**
47- * Destroy a Wayland context.
48- */
49-void wld_wayland_destroy_context(struct wld_wayland_context * context);
50-
51-/**
52- * Create a new Wayland drawable for the given surface with a particular pixel
53- * format.
54- *
55- * @param damage_flags Initial damage tracking mode.
56- *                     @see enum wld_wayland_damage_tracking_flags
57- */
58-struct wld_drawable * wld_wayland_create_drawable
59-    (struct wld_wayland_context * context, struct wl_surface * surface,
60-     uint32_t width, uint32_t height, uint32_t format, uint32_t damage_flags);
61-
62-/**
63- * Enable or disable damage tracking on the specified Wayland drawable.
64- *
65- * @see enum wld_wayland_damage_tracking_flags
66- */
67-void wld_wayland_drawable_set_damage_tracking(struct wld_drawable * drawable,
68-                                              uint32_t flags);
69-
70 #endif
71