blob: 5dd44f95e6c2216cab67958b7ae8b2c99e1f4cfd [file] [log] [blame]
Benjamin Franzkeaabdce02011-01-15 00:40:17 +01001/*
2 * Copyright © 2011 Benjamin Franzke
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010026#include <stdbool.h>
27#include <math.h>
28#include <assert.h>
Pekka Paalanen88e60fc2011-12-13 12:09:09 +020029#include <signal.h>
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010030
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010031#include <wayland-client.h>
Kristian Høgsberga495a5e2011-02-04 15:31:33 -050032#include <wayland-egl.h>
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010033
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010034#include <GLES2/gl2.h>
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010035#include <EGL/egl.h>
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010036
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +030037struct window;
Daniel Stone37816df2012-05-16 18:45:18 +010038struct seat;
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +030039
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010040struct display {
41 struct wl_display *display;
Kristian Høgsberga495a5e2011-02-04 15:31:33 -050042 struct wl_compositor *compositor;
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -040043 struct wl_shell *shell;
Kristian Høgsbergb84108d2012-05-16 16:16:19 -040044 struct wl_seat *seat;
45 struct wl_pointer *pointer;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010046 struct {
47 EGLDisplay dpy;
48 EGLContext ctx;
Kristian Høgsberga495a5e2011-02-04 15:31:33 -050049 EGLConfig conf;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010050 } egl;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010051 uint32_t mask;
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +030052 struct window *window;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010053};
54
55struct window {
56 struct display *display;
57 struct {
58 int width, height;
59 } geometry;
60 struct {
61 GLuint fbo;
62 GLuint color_rbo;
63
64 GLuint program;
65 GLuint rotation_uniform;
66
67 GLuint pos;
68 GLuint col;
69 } gl;
Kristian Høgsberga495a5e2011-02-04 15:31:33 -050070
71 struct wl_egl_window *native;
72 struct wl_surface *surface;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +020073 struct wl_shell_surface *shell_surface;
Kristian Høgsberga495a5e2011-02-04 15:31:33 -050074 EGLSurface egl_surface;
Pekka Paalanen2c2c1062011-12-13 14:50:25 +020075 struct wl_callback *callback;
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +030076 int fullscreen, configured;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010077};
78
79static const char *vert_shader_text =
80 "uniform mat4 rotation;\n"
81 "attribute vec4 pos;\n"
82 "attribute vec4 color;\n"
83 "varying vec4 v_color;\n"
84 "void main() {\n"
85 " gl_Position = rotation * pos;\n"
86 " v_color = color;\n"
87 "}\n";
88
89static const char *frag_shader_text =
Kristian Høgsberg1a11fac2011-01-14 20:39:21 -050090 "precision mediump float;\n"
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010091 "varying vec4 v_color;\n"
92 "void main() {\n"
93 " gl_FragColor = v_color;\n"
94 "}\n";
95
96static void
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +030097init_egl(struct display *display, EGLint alpha_size)
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010098{
Kristian Høgsberg1a11fac2011-01-14 20:39:21 -050099 static const EGLint context_attribs[] = {
100 EGL_CONTEXT_CLIENT_VERSION, 2,
101 EGL_NONE
102 };
103
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300104 EGLint config_attribs[] = {
Kristian Høgsberg8e81df42012-01-11 14:24:46 -0500105 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500106 EGL_RED_SIZE, 1,
107 EGL_GREEN_SIZE, 1,
108 EGL_BLUE_SIZE, 1,
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300109 EGL_ALPHA_SIZE, alpha_size,
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500110 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
111 EGL_NONE
112 };
113
114 EGLint major, minor, n;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100115 EGLBoolean ret;
116
Kristian Høgsberg91342c62011-04-14 14:44:58 -0400117 display->egl.dpy = eglGetDisplay(display->display);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100118 assert(display->egl.dpy);
119
120 ret = eglInitialize(display->egl.dpy, &major, &minor);
121 assert(ret == EGL_TRUE);
Kristian Høgsberg1a11fac2011-01-14 20:39:21 -0500122 ret = eglBindAPI(EGL_OPENGL_ES_API);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100123 assert(ret == EGL_TRUE);
124
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500125 assert(eglChooseConfig(display->egl.dpy, config_attribs,
126 &display->egl.conf, 1, &n) && n == 1);
127
128 display->egl.ctx = eglCreateContext(display->egl.dpy,
129 display->egl.conf,
Kristian Høgsberg1a11fac2011-01-14 20:39:21 -0500130 EGL_NO_CONTEXT, context_attribs);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100131 assert(display->egl.ctx);
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500132
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100133}
134
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200135static void
136fini_egl(struct display *display)
137{
138 /* Required, otherwise segfault in egl_dri2.c: dri2_make_current()
139 * on eglReleaseThread(). */
140 eglMakeCurrent(display->egl.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
141 EGL_NO_CONTEXT);
142
143 eglTerminate(display->egl.dpy);
144 eglReleaseThread();
145}
146
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100147static GLuint
148create_shader(struct window *window, const char *source, GLenum shader_type)
149{
150 GLuint shader;
151 GLint status;
152
153 shader = glCreateShader(shader_type);
154 assert(shader != 0);
155
156 glShaderSource(shader, 1, (const char **) &source, NULL);
157 glCompileShader(shader);
158
159 glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
160 if (!status) {
161 char log[1000];
162 GLsizei len;
163 glGetShaderInfoLog(shader, 1000, &len, log);
164 fprintf(stderr, "Error: compiling %s: %*s\n",
165 shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment",
166 len, log);
167 exit(1);
168 }
169
170 return shader;
171}
172
173static void
174init_gl(struct window *window)
175{
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100176 GLuint frag, vert;
177 GLint status;
178
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100179 glViewport(0, 0, window->geometry.width, window->geometry.height);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100180
181 frag = create_shader(window, frag_shader_text, GL_FRAGMENT_SHADER);
182 vert = create_shader(window, vert_shader_text, GL_VERTEX_SHADER);
183
184 window->gl.program = glCreateProgram();
185 glAttachShader(window->gl.program, frag);
186 glAttachShader(window->gl.program, vert);
187 glLinkProgram(window->gl.program);
188
189 glGetProgramiv(window->gl.program, GL_LINK_STATUS, &status);
190 if (!status) {
191 char log[1000];
192 GLsizei len;
193 glGetProgramInfoLog(window->gl.program, 1000, &len, log);
194 fprintf(stderr, "Error: linking:\n%*s\n", len, log);
195 exit(1);
196 }
197
198 glUseProgram(window->gl.program);
199
200 window->gl.pos = 0;
201 window->gl.pos = 1;
202
203 glBindAttribLocation(window->gl.program, window->gl.pos, "pos");
204 glBindAttribLocation(window->gl.program, window->gl.col, "color");
205 glLinkProgram(window->gl.program);
206
207 window->gl.rotation_uniform =
208 glGetUniformLocation(window->gl.program, "rotation");
209}
210
211static void
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300212handle_ping(void *data, struct wl_shell_surface *shell_surface,
213 uint32_t serial)
214{
215 wl_shell_surface_pong(shell_surface, serial);
216}
217
218static void
219handle_configure(void *data, struct wl_shell_surface *shell_surface,
220 uint32_t edges, int32_t width, int32_t height)
221{
222 struct window *window = data;
223
224 window->geometry.width = width;
225 window->geometry.height = height;
226 window->configured = 1;
227}
228
229static void
230handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
231{
232}
233
234static const struct wl_shell_surface_listener shell_surface_listener = {
235 handle_ping,
236 handle_configure,
237 handle_popup_done
238};
239
240static void
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100241create_surface(struct window *window)
242{
243 struct display *display = window->display;
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500244 EGLBoolean ret;
Benjamin Franzke65e50512011-05-31 11:36:31 +0200245
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500246 window->surface = wl_compositor_create_surface(display->compositor);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200247 window->shell_surface = wl_shell_get_shell_surface(display->shell,
248 window->surface);
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300249
250 wl_shell_surface_add_listener(window->shell_surface,
251 &shell_surface_listener, window);
252
253 if (window->fullscreen) {
254 window->configured = 0;
255 wl_shell_surface_set_fullscreen(window->shell_surface,
256 WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
257 0, NULL);
258
259 while (!window->configured)
260 wl_display_iterate(display->display, display->mask);
261 }
262 else
263 wl_shell_surface_set_toplevel(window->shell_surface);
264
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500265 window->native =
Kristian Høgsberg91342c62011-04-14 14:44:58 -0400266 wl_egl_window_create(window->surface,
Kristian Høgsbergbfb8e612011-02-07 10:30:38 -0500267 window->geometry.width,
Kristian Høgsbergf389cac2011-08-31 16:21:38 -0400268 window->geometry.height);
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500269 window->egl_surface =
270 eglCreateWindowSurface(display->egl.dpy,
271 display->egl.conf,
Kristian Høgsberg8e81df42012-01-11 14:24:46 -0500272 window->native, NULL);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100273
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500274 ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface,
275 window->egl_surface, window->display->egl.ctx);
276 assert(ret == EGL_TRUE);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100277}
278
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200279static void
280destroy_surface(struct window *window)
281{
282 wl_egl_window_destroy(window->native);
283
284 wl_shell_surface_destroy(window->shell_surface);
285 wl_surface_destroy(window->surface);
286
287 if (window->callback)
288 wl_callback_destroy(window->callback);
289}
290
Kristian Høgsberg33418202011-08-16 23:01:28 -0400291static const struct wl_callback_listener frame_listener;
292
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100293static void
Kristian Høgsberg33418202011-08-16 23:01:28 -0400294redraw(void *data, struct wl_callback *callback, uint32_t time)
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100295{
296 struct window *window = data;
297 static const GLfloat verts[3][2] = {
298 { -0.5, -0.5 },
299 { 0.5, -0.5 },
300 { 0, 0.5 }
301 };
302 static const GLfloat colors[3][3] = {
303 { 1, 0, 0 },
304 { 0, 1, 0 },
305 { 0, 0, 1 }
306 };
307 GLfloat angle;
308 GLfloat rotation[4][4] = {
309 { 1, 0, 0, 0 },
310 { 0, 1, 0, 0 },
311 { 0, 0, 1, 0 },
312 { 0, 0, 0, 1 }
313 };
314 static const int32_t speed_div = 5;
315 static uint32_t start_time = 0;
316
317 if (start_time == 0)
318 start_time = time;
319
320 angle = ((time-start_time) / speed_div) % 360 * M_PI / 180.0;
321 rotation[0][0] = cos(angle);
322 rotation[0][2] = sin(angle);
323 rotation[2][0] = -sin(angle);
324 rotation[2][2] = cos(angle);
325
326 glUniformMatrix4fv(window->gl.rotation_uniform, 1, GL_FALSE,
327 (GLfloat *) rotation);
328
329 glClearColor(0.0, 0.0, 0.0, 0.5);
330 glClear(GL_COLOR_BUFFER_BIT);
331
332 glVertexAttribPointer(window->gl.pos, 2, GL_FLOAT, GL_FALSE, 0, verts);
333 glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors);
334 glEnableVertexAttribArray(window->gl.pos);
335 glEnableVertexAttribArray(window->gl.col);
336
337 glDrawArrays(GL_TRIANGLES, 0, 3);
338
339 glDisableVertexAttribArray(window->gl.pos);
340 glDisableVertexAttribArray(window->gl.col);
341
342 glFlush();
343
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500344 eglSwapBuffers(window->display->egl.dpy, window->egl_surface);
Kristian Høgsberg33418202011-08-16 23:01:28 -0400345 if (callback)
346 wl_callback_destroy(callback);
347
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200348 window->callback = wl_surface_frame(window->surface);
349 wl_callback_add_listener(window->callback, &frame_listener, window);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100350}
351
Kristian Høgsberg33418202011-08-16 23:01:28 -0400352static const struct wl_callback_listener frame_listener = {
353 redraw
354};
355
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100356static void
Daniel Stone37816df2012-05-16 18:45:18 +0100357pointer_handle_enter(void *data, struct wl_pointer *pointer,
358 uint32_t serial, struct wl_surface *surface,
359 wl_fixed_t sx, wl_fixed_t sy)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300360{
361 struct display *display = data;
362
363 if (display->window->fullscreen)
Daniel Stone37816df2012-05-16 18:45:18 +0100364 wl_pointer_attach(pointer, serial, NULL, 0, 0);
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300365}
366
367static void
Daniel Stone37816df2012-05-16 18:45:18 +0100368pointer_handle_leave(void *data, struct wl_pointer *pointer,
369 uint32_t serial, struct wl_surface *surface)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300370{
371}
372
373static void
Daniel Stone37816df2012-05-16 18:45:18 +0100374pointer_handle_motion(void *data, struct wl_pointer *pointer,
375 uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300376{
377}
378
379static void
Daniel Stone37816df2012-05-16 18:45:18 +0100380pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
381 uint32_t serial, uint32_t time, uint32_t button,
382 uint32_t state)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300383{
384}
385
386static void
Daniel Stone37816df2012-05-16 18:45:18 +0100387pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
Daniel Stone2fce4022012-05-30 16:32:00 +0100388 uint32_t time, uint32_t axis, wl_fixed_t value)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300389{
390}
391
Daniel Stone37816df2012-05-16 18:45:18 +0100392static const struct wl_pointer_listener pointer_listener = {
393 pointer_handle_enter,
394 pointer_handle_leave,
395 pointer_handle_motion,
396 pointer_handle_button,
397 pointer_handle_axis,
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300398};
399
400static void
Daniel Stone37816df2012-05-16 18:45:18 +0100401seat_handle_capabilities(void *data, struct wl_seat *seat,
402 enum wl_seat_capability caps)
403{
Kristian Høgsbergb84108d2012-05-16 16:16:19 -0400404 struct display *d = data;
Daniel Stone37816df2012-05-16 18:45:18 +0100405
Kristian Høgsbergb84108d2012-05-16 16:16:19 -0400406 if ((caps & WL_SEAT_CAPABILITY_POINTER) && !d->pointer) {
407 d->pointer = wl_seat_get_pointer(seat);
408 wl_pointer_add_listener(d->pointer, &pointer_listener, d);
409 } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && d->pointer) {
410 wl_pointer_destroy(d->pointer);
411 d->pointer = NULL;
Daniel Stone37816df2012-05-16 18:45:18 +0100412 }
413}
414
415static const struct wl_seat_listener seat_listener = {
416 seat_handle_capabilities,
417};
418
419static void
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100420display_handle_global(struct wl_display *display, uint32_t id,
421 const char *interface, uint32_t version, void *data)
422{
423 struct display *d = data;
424
Kristian Høgsberg8357cd62011-05-13 13:24:56 -0400425 if (strcmp(interface, "wl_compositor") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -0400426 d->compositor =
427 wl_display_bind(display, id, &wl_compositor_interface);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400428 } else if (strcmp(interface, "wl_shell") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -0400429 d->shell = wl_display_bind(display, id, &wl_shell_interface);
Daniel Stone37816df2012-05-16 18:45:18 +0100430 } else if (strcmp(interface, "wl_seat") == 0) {
Kristian Høgsbergb84108d2012-05-16 16:16:19 -0400431 d->seat = wl_display_bind(d->display, id, &wl_seat_interface);
432 wl_seat_add_listener(d->seat, &seat_listener, d);
Kristian Høgsberg8357cd62011-05-13 13:24:56 -0400433 }
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100434}
435
436static int
437event_mask_update(uint32_t mask, void *data)
438{
439 struct display *d = data;
440
441 d->mask = mask;
442
443 return 0;
444}
445
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200446static int running = 1;
447
448static void
449signal_int(int signum)
450{
451 running = 0;
452}
453
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100454int
455main(int argc, char **argv)
456{
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200457 struct sigaction sigint;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100458 struct display display = { 0 };
459 struct window window = { 0 };
Kristian Høgsberg3593f812012-05-10 20:40:51 -0400460 int alpha_size, i;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100461
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100462 window.display = &display;
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300463 display.window = &window;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100464 window.geometry.width = 250;
465 window.geometry.height = 250;
466
Kristian Høgsberg3593f812012-05-10 20:40:51 -0400467 alpha_size = 1;
468 for (i = 1; i < argc; i++) {
469 if (strcmp("-f", argv[i]) == 0)
470 window.fullscreen = 1;
471 if (strcmp("-o", argv[i]) == 0)
472 alpha_size = 0;
473 }
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300474
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100475 display.display = wl_display_connect(NULL);
476 assert(display.display);
477
478 wl_display_add_global_listener(display.display,
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500479 display_handle_global, &display);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100480
Benjamin Franzke65e50512011-05-31 11:36:31 +0200481 wl_display_get_fd(display.display, event_mask_update, &display);
Kristian Høgsberg33418202011-08-16 23:01:28 -0400482 wl_display_iterate(display.display, WL_DISPLAY_READABLE);
Benjamin Franzke65e50512011-05-31 11:36:31 +0200483
Kristian Høgsberg3593f812012-05-10 20:40:51 -0400484 if (window.fullscreen)
485 alpha_size = 0;
486
487 init_egl(&display, alpha_size);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100488 create_surface(&window);
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500489 init_gl(&window);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100490
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200491 sigint.sa_handler = signal_int;
492 sigemptyset(&sigint.sa_mask);
493 sigint.sa_flags = SA_RESETHAND;
494 sigaction(SIGINT, &sigint, NULL);
495
Kristian Høgsberg33418202011-08-16 23:01:28 -0400496 redraw(&window, NULL, 0);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100497
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200498 while (running)
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100499 wl_display_iterate(display.display, display.mask);
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500500
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200501 fprintf(stderr, "simple-egl exiting\n");
502
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200503 destroy_surface(&window);
504 fini_egl(&display);
505
506 if (display.shell)
507 wl_shell_destroy(display.shell);
508
509 if (display.compositor)
510 wl_compositor_destroy(display.compositor);
511
Pekka Paalanenfb850c42011-12-15 10:07:52 +0200512 wl_display_flush(display.display);
Kristian Høgsbergfcfc83f2012-02-28 14:29:19 -0500513 wl_display_disconnect(display.display);
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200514
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100515 return 0;
516}