commit c71dc18
Michael Forney
·
2014-10-19 02:03:32 +0000 UTC
parent 7fe3933
wayland: Remove wayland-drm and wayland-shm headers Add a wayland_impl struct.
8 files changed,
+86,
-137
M
Makefile
+0,
-2
1@@ -63,13 +63,11 @@ ifeq ($(ENABLE_WAYLAND),1)
2
3 ifneq ($(findstring shm,$(WAYLAND_INTERFACES)),)
4 WLD_SOURCES += wayland-shm.c
5- WLD_HEADERS += wayland-shm.h
6 WLD_CPPFLAGS += -DWITH_WAYLAND_SHM=1
7 endif
8
9 ifneq ($(findstring drm,$(WAYLAND_INTERFACES)),)
10 WLD_SOURCES += wayland-drm.c protocol/wayland-drm-protocol.c
11- WLD_HEADERS += wayland-drm.h
12 WLD_CPPFLAGS += -DWITH_WAYLAND_DRM=1
13 endif
14 endif
R wayland-shm.h =>
interface/wayland.h
+16,
-23
1@@ -1,6 +1,6 @@
2-/* wld: wayland-shm.h
3+/* wld: interface/wayland.h
4 *
5- * Copyright (c) 2013, 2014 Michael Forney
6+ * Copyright (c) 2014 Michael Forney
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10@@ -21,28 +21,21 @@
11 * SOFTWARE.
12 */
13
14-#ifndef WLD_WAYLAND_SHM_H
15-#define WLD_WAYLAND_SHM_H
16-
17-#include <stdbool.h>
18-#include <stdint.h>
19-
20-struct wl_display;
21-struct wl_event_queue;
22+#ifndef WAYLAND_IMPL_NAME
23+# error you must define WAYLAND_IMPL_NAME before including interface/wayland.h
24+#endif
25
26-/**
27- * Create a new WLD context which creates Wayland buffers through the wl_shm
28- * interface, backed by Pixman images.
29- */
30-struct wld_context * wld_wayland_shm_create_context
31+static struct wayland_context * wayland_create_context
32 (struct wl_display * display, struct wl_event_queue * queue);
33+static bool wayland_has_format(struct wld_context * context, uint32_t format);
34
35-/**
36- * Check if the wl_shm global has the specified pixel format.
37- *
38- * @see enum wld_format
39- */
40-bool wld_wayland_shm_has_format(struct wld_context * context, uint32_t format);
41-
42-#endif
43+#define EXPAND(f, x) f(x)
44+#define VAR(name) name ## _wayland_impl
45+const struct wayland_impl EXPAND(VAR, WAYLAND_IMPL_NAME) = {
46+ .create_context = &wayland_create_context,
47+ .has_format = &wayland_has_format,
48+ //.create_surface = &wayland_create_surface,
49+};
50+#undef VAR
51+#undef EXPAND
52
+7,
-16
1@@ -21,7 +21,6 @@
2 * SOFTWARE.
3 */
4
5-#include "wayland-drm.h"
6 #include "wayland.h"
7 #include "drm.h"
8 #include "protocol/wayland-drm-client-protocol.h"
9@@ -35,8 +34,6 @@
10 #include <fcntl.h>
11 #include <xf86drm.h>
12
13-#include <stdio.h>
14-
15 struct drm_context
16 {
17 struct wayland_context base;
18@@ -49,7 +46,9 @@ struct drm_context
19 bool authenticated;
20 };
21
22+#define WAYLAND_IMPL_NAME drm
23 #include "interface/context.h"
24+#include "interface/wayland.h"
25 IMPL(drm_context, wld_context)
26
27 static void registry_global(void * data, struct wl_registry * registry,
28@@ -64,10 +63,6 @@ static void drm_authenticated(void * data, struct wl_drm * wl);
29 static void drm_capabilities(void * data, struct wl_drm * wl,
30 uint32_t capabilities);
31
32-const struct wld_wayland_interface wayland_drm_interface = {
33- .create_context = &wld_wayland_drm_create_context,
34-};
35-
36 const static struct wl_registry_listener registry_listener = {
37 .global = ®istry_global,
38 .global_remove = ®istry_global_remove
39@@ -80,9 +75,8 @@ const static struct wl_drm_listener drm_listener = {
40 .capabilities = &drm_capabilities
41 };
42
43-EXPORT
44-struct wld_context * wld_wayland_drm_create_context(struct wl_display * display,
45- struct wl_event_queue * queue)
46+struct wayland_context * wayland_create_context(struct wl_display * display,
47+ struct wl_event_queue * queue)
48 {
49 struct drm_context * context;
50
51@@ -90,8 +84,6 @@ struct wld_context * wld_wayland_drm_create_context(struct wl_display * display,
52 goto error0;
53
54 context_initialize(&context->base.base, &wld_context_impl);
55- context->base.display = display;
56- context->base.queue = queue;
57 context->wl = NULL;
58 context->fd = -1;
59 context->capabilities = 0;
60@@ -144,7 +136,7 @@ struct wld_context * wld_wayland_drm_create_context(struct wl_display * display,
61 goto error4;
62 }
63
64- return &context->base.base;
65+ return &context->base;
66
67 error4:
68 close(context->fd);
69@@ -159,8 +151,7 @@ struct wld_context * wld_wayland_drm_create_context(struct wl_display * display,
70 return NULL;
71 }
72
73-EXPORT
74-bool wld_wayland_drm_has_format(struct wld_context * base, uint32_t format)
75+bool wayland_has_format(struct wld_context * base, uint32_t format)
76 {
77 struct drm_context * context = drm_context(base);
78 uint32_t * supported_format;
79@@ -198,7 +189,7 @@ struct buffer * context_create_buffer(struct wld_context * base,
80 union wld_object object;
81 struct wl_buffer * wl;
82
83- if (!wld_wayland_drm_has_format(base, format))
84+ if (!wayland_has_format(base, format))
85 goto error0;
86
87 buffer = context->driver_context->impl->create_buffer
+0,
-53
1@@ -1,53 +0,0 @@
2-/* wld: wayland-drm.h
3- *
4- * Copyright (c) 2013, 2014 Michael Forney
5- *
6- * Permission is hereby granted, free of charge, to any person obtaining a copy
7- * of this software and associated documentation files (the "Software"), to deal
8- * in the Software without restriction, including without limitation the rights
9- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10- * copies of the Software, and to permit persons to whom the Software is
11- * furnished to do so, subject to the following conditions:
12- *
13- * The above copyright notice and this permission notice shall be included in
14- * all copies or substantial portions of the Software.
15- *
16- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22- * SOFTWARE.
23- */
24-
25-#ifndef WLD_WAYLAND_DRM_H
26-#define WLD_WAYLAND_DRM_H
27-
28-#include <stdbool.h>
29-#include <stdint.h>
30-
31-struct wl_display;
32-struct wl_event_queue;
33-
34-/**
35- * Create a new WLD context which creates Wayland buffers through the wl_drm
36- * interface, backed by hardware specific buffer implementations.
37- */
38-struct wld_context * wld_wayland_drm_create_context
39- (struct wl_display * display, struct wl_event_queue * queue);
40-
41-/**
42- * Check if the wl_drm global has the specified pixel format.
43- *
44- * @see enum wld_format
45- */
46-bool wld_wayland_drm_has_format(struct wld_context * context, uint32_t format);
47-
48-/**
49- * Get the opened file descriptor for the DRM device.
50- */
51-int wld_wayland_drm_get_fd(struct wld_context * context);
52-
53-#endif
54-
+10,
-8
1@@ -31,25 +31,27 @@ struct wl_display;
2 struct wl_event_queue;
3 struct wl_buffer;
4
5-struct wld_wayland_interface
6-{
7- struct wld_context * (* create_context)(struct wl_display * display,
8- struct wl_event_queue * queue);
9-};
10-
11 struct wayland_context
12 {
13 struct wld_context base;
14+ const struct wayland_impl * impl;
15 struct wl_display * display;
16 struct wl_event_queue * queue;
17 };
18
19+struct wayland_impl
20+{
21+ struct wayland_context * (* create_context)(struct wl_display * display,
22+ struct wl_event_queue * queue);
23+ bool (* has_format)(struct wld_context * context, uint32_t format);
24+};
25+
26 #if WITH_WAYLAND_DRM
27-extern const struct wld_wayland_interface wayland_drm_interface;
28+extern const struct wayland_impl drm_wayland_impl;
29 #endif
30
31 #if WITH_WAYLAND_SHM
32-extern const struct wld_wayland_interface wayland_shm_interface;
33+extern const struct wayland_impl shm_wayland_impl;
34 #endif
35
36 bool wayland_buffer_add_exporter(struct buffer * buffer, struct wl_buffer * wl);
+11,
-14
1@@ -23,7 +23,6 @@
2
3 #define _GNU_SOURCE /* Required for mkostemp */
4
5-#include "wayland-shm.h"
6 #include "wayland.h"
7 #include "wayland-private.h"
8 #include "wld-private.h"
9@@ -50,8 +49,10 @@ struct shm_buffer
10 int fd;
11 };
12
13+#define WAYLAND_IMPL_NAME shm
14 #include "interface/context.h"
15 #include "interface/buffer.h"
16+#include "interface/wayland.h"
17 IMPL(shm_context, wld_context)
18 IMPL(shm_buffer, wld_buffer)
19
20@@ -63,10 +64,6 @@ static void registry_global_remove(void * data, struct wl_registry * registry,
21
22 static void shm_format(void * data, struct wl_shm * wl, uint32_t format);
23
24-const struct wld_wayland_interface wayland_shm_interface = {
25- .create_context = &wld_wayland_shm_create_context,
26-};
27-
28 const static struct wl_registry_listener registry_listener = {
29 .global = ®istry_global,
30 .global_remove = ®istry_global_remove
31@@ -89,9 +86,8 @@ static inline uint32_t format_wld_to_shm(uint32_t format)
32 }
33 }
34
35-EXPORT
36-struct wld_context * wld_wayland_shm_create_context
37- (struct wl_display * display, struct wl_event_queue * queue)
38+struct wayland_context * wayland_create_context(struct wl_display * display,
39+ struct wl_event_queue * queue)
40 {
41 struct shm_context * context;
42
43@@ -99,8 +95,6 @@ struct wld_context * wld_wayland_shm_create_context
44 goto error0;
45
46 context_initialize(&context->base.base, &wld_context_impl);
47- context->base.display = display;
48- context->base.queue = queue;
49 context->wl = NULL;
50 wl_array_init(&context->formats);
51
52@@ -127,7 +121,7 @@ struct wld_context * wld_wayland_shm_create_context
53 /* Wait for SHM formats. */
54 wl_display_roundtrip_queue(display, queue);
55
56- return &context->base.base;
57+ return &context->base;
58
59 error2:
60 wl_registry_destroy(context->registry);
61@@ -138,15 +132,15 @@ struct wld_context * wld_wayland_shm_create_context
62 return NULL;
63 }
64
65-EXPORT
66-bool wld_shm_has_format(struct wld_context * base, uint32_t format)
67+bool wayland_has_format(struct wld_context * base, uint32_t format)
68 {
69 struct shm_context * context = shm_context(base);
70 uint32_t * supported_format;
71+ uint32_t shm_format = format_wld_to_shm(format);
72
73 wl_array_for_each(supported_format, &context->formats)
74 {
75- if (*supported_format == format)
76+ if (*supported_format == shm_format)
77 return true;
78 }
79
80@@ -171,6 +165,9 @@ struct buffer * context_create_buffer(struct wld_context * base,
81 struct wl_shm_pool * pool;
82 struct wl_buffer * wl;
83
84+ if (!wayland_has_format(base, format))
85+ goto error0;
86+
87 if (!(buffer = malloc(sizeof *buffer)))
88 goto error0;
89
+34,
-21
1@@ -67,13 +67,13 @@ static const struct wl_callback_listener sync_listener = {
2
3 static void buffer_release(void * data, struct wl_buffer * buffer);
4
5-const static struct wld_wayland_interface * interfaces[] = {
6+const static struct wayland_impl * impls[] = {
7 #if WITH_WAYLAND_DRM
8- [WLD_DRM] = &wayland_drm_interface,
9+ [WLD_DRM] = &drm_wayland_impl,
10 #endif
11
12 #if WITH_WAYLAND_SHM
13- [WLD_SHM] = &wayland_shm_interface
14+ [WLD_SHM] = &shm_wayland_impl,
15 #endif
16 };
17
18@@ -93,10 +93,10 @@ EXPORT
19 struct wld_context * wld_wayland_create_context
20 (struct wl_display * display, enum wld_wayland_interface_id id, ...)
21 {
22- struct wld_context * context = NULL;
23+ struct wayland_context * context = NULL;
24 struct wl_event_queue * queue;
25- va_list requested_interfaces;
26- bool interfaces_tried[ARRAY_LENGTH(interfaces)] = {0};
27+ va_list requested_impls;
28+ bool impls_tried[ARRAY_LENGTH(impls)] = {0};
29 const char * interface_string;
30
31 if (!(queue = wl_display_create_queue(display)))
32@@ -106,8 +106,8 @@ struct wld_context * wld_wayland_create_context
33 {
34 id = interface_id(interface_string);
35
36- if ((context = interfaces[id]->create_context(display, queue)))
37- return context;
38+ if ((context = impls[id]->create_context(display, queue)))
39+ return &context->base;
40
41 fprintf(stderr, "Could not create context for Wayland interface '%s'\n",
42 interface_string);
43@@ -115,42 +115,47 @@ struct wld_context * wld_wayland_create_context
44 return NULL;
45 }
46
47- va_start(requested_interfaces, id);
48+ va_start(requested_impls, id);
49
50 while (id >= 0)
51 {
52- if (interfaces_tried[id] || !interfaces[id])
53+ if (impls_tried[id] || !impls[id])
54 continue;
55
56- if ((context = interfaces[id]->create_context(display, queue)))
57- break;
58+ if ((context = impls[id]->create_context(display, queue)))
59+ goto done;
60
61- interfaces_tried[id] = true;
62- id = va_arg(requested_interfaces, enum wld_wayland_interface_id);
63+ impls_tried[id] = true;
64+ id = va_arg(requested_impls, enum wld_wayland_interface_id);
65 }
66
67- va_end(requested_interfaces);
68+ va_end(requested_impls);
69
70- /* If the user specified WLD_ANY, try any remaining interfaces. */
71+ /* If the user specified WLD_ANY, try any remaining implementations. */
72 if (!context && id == WLD_ANY)
73 {
74- for (id = 0; id < ARRAY_LENGTH(interfaces); ++id)
75+ for (id = 0; id < ARRAY_LENGTH(impls); ++id)
76 {
77- if (interfaces_tried[id] || !interfaces[id])
78+ if (impls_tried[id] || !impls[id])
79 continue;
80
81- if ((context = interfaces[id]->create_context(display, queue)))
82+ if ((context = impls[id]->create_context(display, queue)))
83 break;
84 }
85 }
86
87 if (!context)
88 {
89- DEBUG("Could not initialize any of the specified interfaces\n");
90+ DEBUG("Could not initialize any of the specified implementations\n");
91 return NULL;
92 }
93
94- return context;
95+ done:
96+ context->impl = impls[id];
97+ context->display = display;
98+ context->queue = queue;
99+
100+ return &context->base;
101 }
102
103 EXPORT
104@@ -183,6 +188,14 @@ struct wld_surface * wld_wayland_create_surface(struct wld_context * context,
105 return NULL;
106 }
107
108+EXPORT
109+bool wld_wayland_has_format(struct wld_context * base, uint32_t format)
110+{
111+ struct wayland_context * context = (void *) base;
112+
113+ return context->impl->has_format(base, format);
114+}
115+
116 static bool buffer_export(struct wld_exporter * exporter,
117 struct wld_buffer * buffer,
118 uint32_t type, union wld_object * object)
+8,
-0
1@@ -24,6 +24,7 @@
2 #ifndef WLD_WAYLAND_H
3 #define WLD_WAYLAND_H
4
5+#include <stdbool.h>
6 #include <stdint.h>
7
8 struct wl_display;
9@@ -72,5 +73,12 @@ struct wld_surface * wld_wayland_create_surface(struct wld_context * context,
10 uint32_t format, uint32_t flags,
11 struct wl_surface * surface);
12
13+/**
14+ * Check if the wayland implementation supports a particular pixel format.
15+ *
16+ * @see enum wld_format
17+ */
18+bool wld_wayland_has_format(struct wld_context * context, uint32_t format);
19+
20 #endif
21