diff options
author | Eduardo Lima (Etrunko) <eduardo.lima@intel.com> | 2012-11-01 15:57:18 +0000 |
---|---|---|
committer | Eduardo de Barros Lima <eblima@gmail.com> | 2012-11-01 15:57:18 +0000 |
commit | f81697bb994e7a88cca0c6901482dc16a9dc5d7c (patch) | |
tree | 6741dd344a320f130e7bd41a51ea6c2d8dd1671e /src | |
parent | 2913da1dca06ad6c2b1c69829b3ff929b1ab75b1 (diff) |
Basic support for wayland engines
Next: Mouse/Keyboard support
Signed-off-by: Eduardo Lima (Etrunko) <eduardo.lima@intel.com>
SVN revision: 78799
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/Makefile.am | 13 | ||||
-rw-r--r-- | src/bin/engine_wayland_egl.c | 116 | ||||
-rw-r--r-- | src/bin/engine_wayland_egl.h | 8 | ||||
-rw-r--r-- | src/bin/engine_wayland_shm.c | 210 | ||||
-rw-r--r-- | src/bin/engine_wayland_shm.h | 8 | ||||
-rw-r--r-- | src/bin/main.c | 6 | ||||
-rw-r--r-- | src/bin/main.h | 6 |
7 files changed, 363 insertions, 4 deletions
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 72911c0..0cd055a 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am | |||
@@ -142,9 +142,9 @@ proxy_text_random.c | |||
142 | #filter_object_blur.c \ | 142 | #filter_object_blur.c \ |
143 | #filter_object_blur_solid.c | 143 | #filter_object_blur_solid.c |
144 | 144 | ||
145 | expedite_CFLAGS = @WIN32_CFLAGS@ | 145 | expedite_CFLAGS = @WIN32_CFLAGS@ @WAYLAND_CLIENT_CFLAGS@ @WAYLAND_EGL_CFLAGS@ |
146 | expedite_CXXFLAGS = @EXPEDITE_CXXFLAGS@ | 146 | expedite_CXXFLAGS = @EXPEDITE_CXXFLAGS@ |
147 | expedite_LDADD = @SDL_LIBS@ @x_libs@ @gdi_libs@ @ddraw_libs@ @d3d_libs@ @wince_16_libs@ @DIRECTFB_LIBS@ @XCB_LIBS@ @EVAS_LIBS@ @EINA_LIBS@ @EVIL_LIBS@ @gl_cocoa_libs@ -lm | 147 | expedite_LDADD = @SDL_LIBS@ @x_libs@ @gdi_libs@ @ddraw_libs@ @d3d_libs@ @wince_16_libs@ @DIRECTFB_LIBS@ @XCB_LIBS@ @EVAS_LIBS@ @EINA_LIBS@ @EVIL_LIBS@ @gl_cocoa_libs@ @WAYLAND_CLIENT_LIBS@ @WAYLAND_EGL_LIBS@ -lm |
148 | expedite_LDFLAGS = @lt_enable_auto_import@ | 148 | expedite_LDFLAGS = @lt_enable_auto_import@ |
149 | 149 | ||
150 | if BUILD_SOFTWARE_XLIB | 150 | if BUILD_SOFTWARE_XLIB |
@@ -222,9 +222,14 @@ expedite_SOURCES += \ | |||
222 | engine_software_16_wince.c engine_software_16_wince.h engine_software_16_wince.rc | 222 | engine_software_16_wince.c engine_software_16_wince.h engine_software_16_wince.rc |
223 | endif | 223 | endif |
224 | 224 | ||
225 | if BUILD_SOFTWARE_16_WINCE | 225 | if BUILD_WAYLAND_EGL |
226 | expedite_SOURCES += \ | 226 | expedite_SOURCES += \ |
227 | engine_software_16_wince.c engine_software_16_wince.h engine_software_16_wince.rc | 227 | engine_wayland_egl.c engine_wayland_egl.h |
228 | endif | ||
229 | |||
230 | if BUILD_WAYLAND_SHM | ||
231 | expedite_SOURCES += \ | ||
232 | engine_wayland_shm.c engine_wayland_shm.h | ||
228 | endif | 233 | endif |
229 | 234 | ||
230 | .rc.lo: | 235 | .rc.lo: |
diff --git a/src/bin/engine_wayland_egl.c b/src/bin/engine_wayland_egl.c new file mode 100644 index 0000000..4f1a188 --- /dev/null +++ b/src/bin/engine_wayland_egl.c | |||
@@ -0,0 +1,116 @@ | |||
1 | #include "main.h" | ||
2 | |||
3 | #include <string.h> | ||
4 | #include <assert.h> | ||
5 | |||
6 | #include <Evas_Engine_Wayland_Egl.h> | ||
7 | #include <wayland-client.h> | ||
8 | #include <wayland-egl.h> | ||
9 | |||
10 | /* Global struct */ | ||
11 | struct _engine_wayland_egl_display | ||
12 | { | ||
13 | struct wl_display *display; | ||
14 | struct wl_registry *registry; | ||
15 | struct wl_compositor *compositor; | ||
16 | struct wl_surface *surface; | ||
17 | struct wl_shell *shell; | ||
18 | struct wl_shell_surface *shell_surface; | ||
19 | }; | ||
20 | |||
21 | static struct _engine_wayland_egl_display wl; | ||
22 | |||
23 | /* | ||
24 | * Function prototypes | ||
25 | */ | ||
26 | /* Registry handler */ | ||
27 | static void _registry_handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version __UNUSED__); | ||
28 | static const struct wl_registry_listener _registry_listener = | ||
29 | { | ||
30 | _registry_handle_global, | ||
31 | }; | ||
32 | |||
33 | /* Shell Surface handler */ | ||
34 | static void _shell_surface_handle_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial); | ||
35 | |||
36 | static const struct wl_shell_surface_listener _shell_surface_listener = | ||
37 | { | ||
38 | _shell_surface_handle_ping, | ||
39 | }; | ||
40 | |||
41 | /* | ||
42 | * API | ||
43 | */ | ||
44 | Eina_Bool | ||
45 | engine_wayland_egl_args(const char *engine __UNUSED__, int width, int height) | ||
46 | { | ||
47 | Evas_Engine_Info_Wayland_Egl *einfo; | ||
48 | |||
49 | evas_output_method_set(evas, evas_render_method_lookup("wayland_egl")); | ||
50 | einfo = (Evas_Engine_Info_Wayland_Egl *)evas_engine_info_get(evas); | ||
51 | if (!einfo) | ||
52 | { | ||
53 | printf("Evas does not support the Wayland EGL Engine\n"); | ||
54 | return EINA_FALSE; | ||
55 | } | ||
56 | |||
57 | wl.display = wl_display_connect(NULL); | ||
58 | wl.registry = wl_display_get_registry(wl.display); | ||
59 | wl_registry_add_listener(wl.registry, &_registry_listener, NULL); | ||
60 | wl_display_roundtrip(wl.display); | ||
61 | |||
62 | assert(wl.compositor != NULL); | ||
63 | assert(wl.shell != NULL); | ||
64 | |||
65 | wl.surface = wl_compositor_create_surface(wl.compositor); | ||
66 | wl.shell_surface = wl_shell_get_shell_surface(wl.shell, wl.surface); | ||
67 | wl_shell_surface_set_title(wl.shell_surface, "Expedite Wayland EGL"); | ||
68 | wl_shell_surface_add_listener(wl.shell_surface, &_shell_surface_listener, NULL); | ||
69 | wl_shell_surface_set_toplevel(wl.shell_surface); | ||
70 | |||
71 | einfo->info.display = wl.display; | ||
72 | einfo->info.surface = wl.surface; | ||
73 | if (!evas_engine_info_set(evas, (Evas_Engine_Info *) einfo)) | ||
74 | { | ||
75 | printf("Evas can not setup the informations of the Wayland EGL Engine\n"); | ||
76 | return EINA_FALSE; | ||
77 | } | ||
78 | |||
79 | return EINA_TRUE; | ||
80 | } | ||
81 | |||
82 | void | ||
83 | engine_wayland_egl_loop(void) | ||
84 | { | ||
85 | assert(wl_display_dispatch_pending(wl.display) != -1); | ||
86 | wl_display_flush(wl.display); | ||
87 | } | ||
88 | |||
89 | void | ||
90 | engine_wayland_egl_shutdown(void) | ||
91 | { | ||
92 | wl_shell_surface_destroy(wl.shell_surface); | ||
93 | wl_surface_destroy(wl.surface); | ||
94 | wl_shell_destroy(wl.shell); | ||
95 | wl_compositor_destroy(wl.compositor); | ||
96 | wl_display_flush(wl.display); | ||
97 | wl_display_disconnect(wl.display); | ||
98 | } | ||
99 | |||
100 | /* | ||
101 | * Function implementation | ||
102 | */ | ||
103 | static void | ||
104 | _registry_handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version __UNUSED__) | ||
105 | { | ||
106 | if (!strcmp(interface, "wl_compositor")) | ||
107 | wl.compositor = wl_registry_bind(wl.registry, id, &wl_compositor_interface, 1); | ||
108 | else if (!strcmp(interface, "wl_shell")) | ||
109 | wl.shell = wl_registry_bind(wl.registry, id, &wl_shell_interface, 1); | ||
110 | } | ||
111 | |||
112 | static void | ||
113 | _shell_surface_handle_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial) | ||
114 | { | ||
115 | wl_shell_surface_pong(shell_surface, serial); | ||
116 | } | ||
diff --git a/src/bin/engine_wayland_egl.h b/src/bin/engine_wayland_egl.h new file mode 100644 index 0000000..d8e6781 --- /dev/null +++ b/src/bin/engine_wayland_egl.h | |||
@@ -0,0 +1,8 @@ | |||
1 | #ifndef ENGINE_WAYLAND_EGL_H | ||
2 | #define ENGINE_WAYLAND_EGL_H | ||
3 | |||
4 | Eina_Bool engine_wayland_egl_args(const char *engine, int width, int height); | ||
5 | void engine_wayland_egl_loop(void); | ||
6 | void engine_wayland_egl_shutdown(void); | ||
7 | |||
8 | #endif | ||
diff --git a/src/bin/engine_wayland_shm.c b/src/bin/engine_wayland_shm.c new file mode 100644 index 0000000..6c3175a --- /dev/null +++ b/src/bin/engine_wayland_shm.c | |||
@@ -0,0 +1,210 @@ | |||
1 | #include "main.h" | ||
2 | |||
3 | #include <stdio.h> | ||
4 | #include <string.h> | ||
5 | #include <assert.h> | ||
6 | #include <sys/mman.h> | ||
7 | |||
8 | #include <Evas_Engine_Wayland_Shm.h> | ||
9 | #include <wayland-client.h> | ||
10 | |||
11 | /* | ||
12 | * Global struct | ||
13 | */ | ||
14 | struct _engine_wayland_shm_display | ||
15 | { | ||
16 | struct wl_display *display; | ||
17 | struct wl_registry *registry; | ||
18 | struct wl_compositor *compositor; | ||
19 | struct wl_surface *surface; | ||
20 | struct wl_callback *frame_callback; | ||
21 | struct wl_shell *shell; | ||
22 | struct wl_shell_surface *shell_surface; | ||
23 | struct wl_shm *shm; | ||
24 | struct wl_buffer *buffer; | ||
25 | void *data; | ||
26 | int width; | ||
27 | int height; | ||
28 | }; | ||
29 | |||
30 | static struct _engine_wayland_shm_display wl; | ||
31 | |||
32 | /* | ||
33 | * Function Prototypes | ||
34 | */ | ||
35 | static void _engine_wayland_shm_create_buffer(int width, int height); | ||
36 | |||
37 | /* Registry handler */ | ||
38 | static void _registry_handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version __UNUSED__); | ||
39 | static const struct wl_registry_listener _registry_listener = | ||
40 | { | ||
41 | _registry_handle_global, | ||
42 | }; | ||
43 | |||
44 | /* Shell Surface handler */ | ||
45 | static void _shell_surface_handle_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial); | ||
46 | |||
47 | static const struct wl_shell_surface_listener _shell_surface_listener = | ||
48 | { | ||
49 | _shell_surface_handle_ping, | ||
50 | }; | ||
51 | |||
52 | /* Frame handler */ | ||
53 | static void _surface_frame_handle_complete(void *data, struct wl_callback *callback, uint32_t time __UNUSED__); | ||
54 | static const struct wl_callback_listener _surface_frame_listener = | ||
55 | { | ||
56 | _surface_frame_handle_complete, | ||
57 | }; | ||
58 | |||
59 | |||
60 | /* | ||
61 | * API | ||
62 | */ | ||
63 | Eina_Bool | ||
64 | engine_wayland_shm_args(const char *engine __UNUSED__, int width, int height) | ||
65 | { | ||
66 | Evas_Engine_Info_Wayland_Shm *einfo; | ||
67 | struct wl_region *region; | ||
68 | |||
69 | evas_output_method_set(evas, evas_render_method_lookup("wayland_shm")); | ||
70 | einfo = (Evas_Engine_Info_Wayland_Shm *)evas_engine_info_get(evas); | ||
71 | if (!einfo) | ||
72 | { | ||
73 | printf("Evas does not support the Wayland SHM Engine\n"); | ||
74 | return EINA_FALSE; | ||
75 | } | ||
76 | |||
77 | wl.display = wl_display_connect(NULL); | ||
78 | wl.registry = wl_display_get_registry(wl.display); | ||
79 | wl_registry_add_listener(wl.registry, &_registry_listener, NULL); | ||
80 | wl_display_roundtrip(wl.display); | ||
81 | |||
82 | assert(wl.compositor != NULL); | ||
83 | assert(wl.shell != NULL); | ||
84 | assert(wl.shm != NULL); | ||
85 | |||
86 | wl.surface = wl_compositor_create_surface(wl.compositor); | ||
87 | wl.shell_surface = wl_shell_get_shell_surface(wl.shell, wl.surface); | ||
88 | wl_shell_surface_set_title(wl.shell_surface, "Expedite Wayland SHM"); | ||
89 | wl_shell_surface_add_listener(wl.shell_surface, &_shell_surface_listener, NULL); | ||
90 | wl_shell_surface_set_toplevel(wl.shell_surface); | ||
91 | |||
92 | _engine_wayland_shm_create_buffer(width, height); | ||
93 | |||
94 | assert(wl.buffer != NULL); | ||
95 | assert(wl.data != NULL); | ||
96 | |||
97 | wl_surface_attach(wl.surface, wl.buffer, 0, 0); | ||
98 | |||
99 | einfo->info.dest = wl.data; | ||
100 | if (!evas_engine_info_set(evas, (Evas_Engine_Info *) einfo)) | ||
101 | { | ||
102 | printf("Evas can not setup the informations of the Wayland SHM Engine\n"); | ||
103 | return EINA_FALSE; | ||
104 | } | ||
105 | |||
106 | wl.width = width; | ||
107 | wl.height = height; | ||
108 | |||
109 | _surface_frame_handle_complete(NULL, NULL, 0); | ||
110 | |||
111 | return EINA_TRUE; | ||
112 | } | ||
113 | |||
114 | void | ||
115 | engine_wayland_shm_loop(void) | ||
116 | { | ||
117 | assert(wl_display_dispatch(wl.display) != -1); | ||
118 | } | ||
119 | |||
120 | |||
121 | void | ||
122 | engine_wayland_shm_shutdown(void) | ||
123 | { | ||
124 | if (wl.frame_callback) | ||
125 | wl_callback_destroy(wl.frame_callback); | ||
126 | |||
127 | wl_buffer_destroy(wl.buffer); | ||
128 | wl_shell_surface_destroy(wl.shell_surface); | ||
129 | wl_surface_destroy(wl.surface); | ||
130 | |||
131 | wl_shm_destroy(wl.shm); | ||
132 | wl_shell_destroy(wl.shell); | ||
133 | wl_compositor_destroy(wl.compositor); | ||
134 | wl_display_flush(wl.display); | ||
135 | wl_display_disconnect(wl.display); | ||
136 | } | ||
137 | |||
138 | /* | ||
139 | * Function implementation | ||
140 | */ | ||
141 | static void | ||
142 | _registry_handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version __UNUSED__) | ||
143 | { | ||
144 | if (!strcmp(interface, "wl_compositor")) | ||
145 | wl.compositor = wl_registry_bind(wl.registry, id, &wl_compositor_interface, 1); | ||
146 | else if (!strcmp(interface, "wl_shell")) | ||
147 | wl.shell = wl_registry_bind(wl.registry, id, &wl_shell_interface, 1); | ||
148 | else if (!strcmp(interface, "wl_shm")) | ||
149 | wl.shm = wl_registry_bind(wl.registry, id, &wl_shm_interface, 1); | ||
150 | } | ||
151 | |||
152 | static void | ||
153 | _shell_surface_handle_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial) | ||
154 | { | ||
155 | wl_shell_surface_pong(shell_surface, serial); | ||
156 | } | ||
157 | |||
158 | static void | ||
159 | _engine_wayland_shm_create_buffer(int width, int height) | ||
160 | { | ||
161 | struct wl_shm_pool *pool; | ||
162 | int fd, size, stride; | ||
163 | char tmp[PATH_MAX]; | ||
164 | |||
165 | stride = width * 4; | ||
166 | size = stride * height; | ||
167 | |||
168 | strcpy(tmp, "/tmp/expedite-wayland_shm-XXXXXX"); | ||
169 | if ((fd = mkstemp(tmp)) < 0) | ||
170 | { | ||
171 | fprintf(stderr, "Could not create temporary file.\n"); | ||
172 | return; | ||
173 | } | ||
174 | |||
175 | if (ftruncate(fd, size) < 0) | ||
176 | { | ||
177 | fprintf(stderr, "Could not truncate temporary file.\n"); | ||
178 | goto end; | ||
179 | } | ||
180 | |||
181 | wl.data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | ||
182 | if (wl.data == MAP_FAILED) | ||
183 | { | ||
184 | wl.data = NULL; | ||
185 | fprintf(stderr, "mmap failed\n"); | ||
186 | goto end; | ||
187 | } | ||
188 | |||
189 | pool = wl_shm_create_pool(wl.shm, fd, size); | ||
190 | wl.buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride, WL_SHM_FORMAT_XRGB8888); | ||
191 | wl_shm_pool_destroy(pool); | ||
192 | |||
193 | end: | ||
194 | close(fd); | ||
195 | } | ||
196 | |||
197 | static void | ||
198 | _surface_frame_handle_complete(void *data, struct wl_callback *callback, uint32_t time) | ||
199 | { | ||
200 | wl_surface_damage(wl.surface, 0, 0, wl.width, wl.height); | ||
201 | |||
202 | if (wl.frame_callback) | ||
203 | wl_callback_destroy(wl.frame_callback); | ||
204 | |||
205 | wl.frame_callback = wl_surface_frame(wl.surface); | ||
206 | wl_callback_add_listener(wl.frame_callback, &_surface_frame_listener, NULL); | ||
207 | |||
208 | wl_surface_commit(wl.surface); | ||
209 | } | ||
210 | |||
diff --git a/src/bin/engine_wayland_shm.h b/src/bin/engine_wayland_shm.h new file mode 100644 index 0000000..5e16451 --- /dev/null +++ b/src/bin/engine_wayland_shm.h | |||
@@ -0,0 +1,8 @@ | |||
1 | #ifndef ENGINE_WAYLAND_SHM_H | ||
2 | #define ENGINE_WAYLAND_SHM_H | ||
3 | |||
4 | Eina_Bool engine_wayland_shm_args(const char *engine, int width, int height); | ||
5 | void engine_wayland_shm_loop(void); | ||
6 | void engine_wayland_shm_shutdown(void); | ||
7 | |||
8 | #endif | ||
diff --git a/src/bin/main.c b/src/bin/main.c index 0b1c91b..25b274a 100644 --- a/src/bin/main.c +++ b/src/bin/main.c | |||
@@ -1186,6 +1186,12 @@ static const Expedite_Engine engines[] = { | |||
1186 | { "wince-ddraw", engine_software_16_wince_args, engine_software_16_wince_loop, engine_software_16_wince_shutdown }, | 1186 | { "wince-ddraw", engine_software_16_wince_args, engine_software_16_wince_loop, engine_software_16_wince_shutdown }, |
1187 | { "wince-gdi", engine_software_16_wince_args, engine_software_16_wince_loop, engine_software_16_wince_shutdown }, | 1187 | { "wince-gdi", engine_software_16_wince_args, engine_software_16_wince_loop, engine_software_16_wince_shutdown }, |
1188 | #endif | 1188 | #endif |
1189 | #if defined(HAVE_EVAS_WAYLAND_EGL) && defined(BUILD_WAYLAND_EGL) | ||
1190 | { "wayland-egl", engine_wayland_egl_args, engine_wayland_egl_loop, engine_wayland_egl_shutdown }, | ||
1191 | #endif | ||
1192 | #if defined(HAVE_EVAS_WAYLAND_SHM) && defined(BUILD_WAYLAND_SHM) | ||
1193 | { "wayland-shm", engine_wayland_shm_args, engine_wayland_shm_loop, engine_wayland_shm_shutdown }, | ||
1194 | #endif | ||
1189 | { NULL, NULL, NULL, NULL } | 1195 | { NULL, NULL, NULL, NULL } |
1190 | }; | 1196 | }; |
1191 | 1197 | ||
diff --git a/src/bin/main.h b/src/bin/main.h index 8b3a13b..dad9468 100644 --- a/src/bin/main.h +++ b/src/bin/main.h | |||
@@ -77,6 +77,12 @@ | |||
77 | #if HAVE_EVAS_SOFTWARE_16_WINCE | 77 | #if HAVE_EVAS_SOFTWARE_16_WINCE |
78 | #include "engine_software_16_wince.h" | 78 | #include "engine_software_16_wince.h" |
79 | #endif | 79 | #endif |
80 | #if defined(HAVE_EVAS_WAYLAND_EGL) && defined(BUILD_WAYLAND_EGL) | ||
81 | #include "engine_wayland_egl.h" | ||
82 | #endif | ||
83 | #if defined(HAVE_EVAS_WAYLAND_SHM) && defined(BUILD_WAYLAND_SHM) | ||
84 | #include "engine_wayland_shm.h" | ||
85 | #endif | ||
80 | 86 | ||
81 | #ifdef __cplusplus | 87 | #ifdef __cplusplus |
82 | extern "C" | 88 | extern "C" |