blob: 441686f9fb85ece3eec914b0b214720cdf094818 [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;
Daniel Stone37816df2012-05-16 18:45:18 +010044 struct seat *seat;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010045 struct {
46 EGLDisplay dpy;
47 EGLContext ctx;
Kristian Høgsberga495a5e2011-02-04 15:31:33 -050048 EGLConfig conf;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010049 } egl;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010050 uint32_t mask;
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +030051 struct window *window;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010052};
53
Daniel Stone37816df2012-05-16 18:45:18 +010054struct seat {
55 struct display *display;
56 struct wl_seat *seat;
57 struct wl_pointer *pointer;
58 struct wl_keyboard *keyboard;
59 struct wl_touch *touch;
60};
61
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010062struct window {
63 struct display *display;
64 struct {
65 int width, height;
66 } geometry;
67 struct {
68 GLuint fbo;
69 GLuint color_rbo;
70
71 GLuint program;
72 GLuint rotation_uniform;
73
74 GLuint pos;
75 GLuint col;
76 } gl;
Kristian Høgsberga495a5e2011-02-04 15:31:33 -050077
78 struct wl_egl_window *native;
79 struct wl_surface *surface;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +020080 struct wl_shell_surface *shell_surface;
Kristian Høgsberga495a5e2011-02-04 15:31:33 -050081 EGLSurface egl_surface;
Pekka Paalanen2c2c1062011-12-13 14:50:25 +020082 struct wl_callback *callback;
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +030083 int fullscreen, configured;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010084};
85
86static const char *vert_shader_text =
87 "uniform mat4 rotation;\n"
88 "attribute vec4 pos;\n"
89 "attribute vec4 color;\n"
90 "varying vec4 v_color;\n"
91 "void main() {\n"
92 " gl_Position = rotation * pos;\n"
93 " v_color = color;\n"
94 "}\n";
95
96static const char *frag_shader_text =
Kristian Høgsberg1a11fac2011-01-14 20:39:21 -050097 "precision mediump float;\n"
Benjamin Franzkeaabdce02011-01-15 00:40:17 +010098 "varying vec4 v_color;\n"
99 "void main() {\n"
100 " gl_FragColor = v_color;\n"
101 "}\n";
102
103static void
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300104init_egl(struct display *display, EGLint alpha_size)
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100105{
Kristian Høgsberg1a11fac2011-01-14 20:39:21 -0500106 static const EGLint context_attribs[] = {
107 EGL_CONTEXT_CLIENT_VERSION, 2,
108 EGL_NONE
109 };
110
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300111 EGLint config_attribs[] = {
Kristian Høgsberg8e81df42012-01-11 14:24:46 -0500112 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500113 EGL_RED_SIZE, 1,
114 EGL_GREEN_SIZE, 1,
115 EGL_BLUE_SIZE, 1,
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300116 EGL_ALPHA_SIZE, alpha_size,
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500117 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
118 EGL_NONE
119 };
120
121 EGLint major, minor, n;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100122 EGLBoolean ret;
123
Kristian Høgsberg91342c62011-04-14 14:44:58 -0400124 display->egl.dpy = eglGetDisplay(display->display);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100125 assert(display->egl.dpy);
126
127 ret = eglInitialize(display->egl.dpy, &major, &minor);
128 assert(ret == EGL_TRUE);
Kristian Høgsberg1a11fac2011-01-14 20:39:21 -0500129 ret = eglBindAPI(EGL_OPENGL_ES_API);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100130 assert(ret == EGL_TRUE);
131
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500132 assert(eglChooseConfig(display->egl.dpy, config_attribs,
133 &display->egl.conf, 1, &n) && n == 1);
134
135 display->egl.ctx = eglCreateContext(display->egl.dpy,
136 display->egl.conf,
Kristian Høgsberg1a11fac2011-01-14 20:39:21 -0500137 EGL_NO_CONTEXT, context_attribs);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100138 assert(display->egl.ctx);
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500139
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100140}
141
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200142static void
143fini_egl(struct display *display)
144{
145 /* Required, otherwise segfault in egl_dri2.c: dri2_make_current()
146 * on eglReleaseThread(). */
147 eglMakeCurrent(display->egl.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
148 EGL_NO_CONTEXT);
149
150 eglTerminate(display->egl.dpy);
151 eglReleaseThread();
152}
153
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100154static GLuint
155create_shader(struct window *window, const char *source, GLenum shader_type)
156{
157 GLuint shader;
158 GLint status;
159
160 shader = glCreateShader(shader_type);
161 assert(shader != 0);
162
163 glShaderSource(shader, 1, (const char **) &source, NULL);
164 glCompileShader(shader);
165
166 glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
167 if (!status) {
168 char log[1000];
169 GLsizei len;
170 glGetShaderInfoLog(shader, 1000, &len, log);
171 fprintf(stderr, "Error: compiling %s: %*s\n",
172 shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment",
173 len, log);
174 exit(1);
175 }
176
177 return shader;
178}
179
180static void
181init_gl(struct window *window)
182{
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100183 GLuint frag, vert;
184 GLint status;
185
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100186 glViewport(0, 0, window->geometry.width, window->geometry.height);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100187
188 frag = create_shader(window, frag_shader_text, GL_FRAGMENT_SHADER);
189 vert = create_shader(window, vert_shader_text, GL_VERTEX_SHADER);
190
191 window->gl.program = glCreateProgram();
192 glAttachShader(window->gl.program, frag);
193 glAttachShader(window->gl.program, vert);
194 glLinkProgram(window->gl.program);
195
196 glGetProgramiv(window->gl.program, GL_LINK_STATUS, &status);
197 if (!status) {
198 char log[1000];
199 GLsizei len;
200 glGetProgramInfoLog(window->gl.program, 1000, &len, log);
201 fprintf(stderr, "Error: linking:\n%*s\n", len, log);
202 exit(1);
203 }
204
205 glUseProgram(window->gl.program);
206
207 window->gl.pos = 0;
208 window->gl.pos = 1;
209
210 glBindAttribLocation(window->gl.program, window->gl.pos, "pos");
211 glBindAttribLocation(window->gl.program, window->gl.col, "color");
212 glLinkProgram(window->gl.program);
213
214 window->gl.rotation_uniform =
215 glGetUniformLocation(window->gl.program, "rotation");
216}
217
218static void
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300219handle_ping(void *data, struct wl_shell_surface *shell_surface,
220 uint32_t serial)
221{
222 wl_shell_surface_pong(shell_surface, serial);
223}
224
225static void
226handle_configure(void *data, struct wl_shell_surface *shell_surface,
227 uint32_t edges, int32_t width, int32_t height)
228{
229 struct window *window = data;
230
231 window->geometry.width = width;
232 window->geometry.height = height;
233 window->configured = 1;
234}
235
236static void
237handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
238{
239}
240
241static const struct wl_shell_surface_listener shell_surface_listener = {
242 handle_ping,
243 handle_configure,
244 handle_popup_done
245};
246
247static void
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100248create_surface(struct window *window)
249{
250 struct display *display = window->display;
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500251 EGLBoolean ret;
Benjamin Franzke65e50512011-05-31 11:36:31 +0200252
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500253 window->surface = wl_compositor_create_surface(display->compositor);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200254 window->shell_surface = wl_shell_get_shell_surface(display->shell,
255 window->surface);
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300256
257 wl_shell_surface_add_listener(window->shell_surface,
258 &shell_surface_listener, window);
259
260 if (window->fullscreen) {
261 window->configured = 0;
262 wl_shell_surface_set_fullscreen(window->shell_surface,
263 WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
264 0, NULL);
265
266 while (!window->configured)
267 wl_display_iterate(display->display, display->mask);
268 }
269 else
270 wl_shell_surface_set_toplevel(window->shell_surface);
271
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500272 window->native =
Kristian Høgsberg91342c62011-04-14 14:44:58 -0400273 wl_egl_window_create(window->surface,
Kristian Høgsbergbfb8e612011-02-07 10:30:38 -0500274 window->geometry.width,
Kristian Høgsbergf389cac2011-08-31 16:21:38 -0400275 window->geometry.height);
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500276 window->egl_surface =
277 eglCreateWindowSurface(display->egl.dpy,
278 display->egl.conf,
Kristian Høgsberg8e81df42012-01-11 14:24:46 -0500279 window->native, NULL);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100280
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500281 ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface,
282 window->egl_surface, window->display->egl.ctx);
283 assert(ret == EGL_TRUE);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100284}
285
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200286static void
287destroy_surface(struct window *window)
288{
289 wl_egl_window_destroy(window->native);
290
291 wl_shell_surface_destroy(window->shell_surface);
292 wl_surface_destroy(window->surface);
293
294 if (window->callback)
295 wl_callback_destroy(window->callback);
296}
297
Kristian Høgsberg33418202011-08-16 23:01:28 -0400298static const struct wl_callback_listener frame_listener;
299
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100300static void
Kristian Høgsberg33418202011-08-16 23:01:28 -0400301redraw(void *data, struct wl_callback *callback, uint32_t time)
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100302{
303 struct window *window = data;
304 static const GLfloat verts[3][2] = {
305 { -0.5, -0.5 },
306 { 0.5, -0.5 },
307 { 0, 0.5 }
308 };
309 static const GLfloat colors[3][3] = {
310 { 1, 0, 0 },
311 { 0, 1, 0 },
312 { 0, 0, 1 }
313 };
314 GLfloat angle;
315 GLfloat rotation[4][4] = {
316 { 1, 0, 0, 0 },
317 { 0, 1, 0, 0 },
318 { 0, 0, 1, 0 },
319 { 0, 0, 0, 1 }
320 };
321 static const int32_t speed_div = 5;
322 static uint32_t start_time = 0;
323
324 if (start_time == 0)
325 start_time = time;
326
327 angle = ((time-start_time) / speed_div) % 360 * M_PI / 180.0;
328 rotation[0][0] = cos(angle);
329 rotation[0][2] = sin(angle);
330 rotation[2][0] = -sin(angle);
331 rotation[2][2] = cos(angle);
332
333 glUniformMatrix4fv(window->gl.rotation_uniform, 1, GL_FALSE,
334 (GLfloat *) rotation);
335
336 glClearColor(0.0, 0.0, 0.0, 0.5);
337 glClear(GL_COLOR_BUFFER_BIT);
338
339 glVertexAttribPointer(window->gl.pos, 2, GL_FLOAT, GL_FALSE, 0, verts);
340 glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors);
341 glEnableVertexAttribArray(window->gl.pos);
342 glEnableVertexAttribArray(window->gl.col);
343
344 glDrawArrays(GL_TRIANGLES, 0, 3);
345
346 glDisableVertexAttribArray(window->gl.pos);
347 glDisableVertexAttribArray(window->gl.col);
348
349 glFlush();
350
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500351 eglSwapBuffers(window->display->egl.dpy, window->egl_surface);
Kristian Høgsberg33418202011-08-16 23:01:28 -0400352 if (callback)
353 wl_callback_destroy(callback);
354
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200355 window->callback = wl_surface_frame(window->surface);
356 wl_callback_add_listener(window->callback, &frame_listener, window);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100357}
358
Kristian Høgsberg33418202011-08-16 23:01:28 -0400359static const struct wl_callback_listener frame_listener = {
360 redraw
361};
362
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100363static void
Daniel Stone37816df2012-05-16 18:45:18 +0100364pointer_handle_enter(void *data, struct wl_pointer *pointer,
365 uint32_t serial, struct wl_surface *surface,
366 wl_fixed_t sx, wl_fixed_t sy)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300367{
368 struct display *display = data;
369
370 if (display->window->fullscreen)
Daniel Stone37816df2012-05-16 18:45:18 +0100371 wl_pointer_attach(pointer, serial, NULL, 0, 0);
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300372}
373
374static void
Daniel Stone37816df2012-05-16 18:45:18 +0100375pointer_handle_leave(void *data, struct wl_pointer *pointer,
376 uint32_t serial, struct wl_surface *surface)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300377{
378}
379
380static void
Daniel Stone37816df2012-05-16 18:45:18 +0100381pointer_handle_motion(void *data, struct wl_pointer *pointer,
382 uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300383{
384}
385
386static void
Daniel Stone37816df2012-05-16 18:45:18 +0100387pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
388 uint32_t serial, uint32_t time, uint32_t button,
389 uint32_t state)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300390{
391}
392
393static void
Daniel Stone37816df2012-05-16 18:45:18 +0100394pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
395 uint32_t time, uint32_t axis, int32_t value)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300396{
397}
398
Daniel Stone37816df2012-05-16 18:45:18 +0100399static const struct wl_pointer_listener pointer_listener = {
400 pointer_handle_enter,
401 pointer_handle_leave,
402 pointer_handle_motion,
403 pointer_handle_button,
404 pointer_handle_axis,
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300405};
406
407static void
Daniel Stone37816df2012-05-16 18:45:18 +0100408seat_handle_capabilities(void *data, struct wl_seat *seat,
409 enum wl_seat_capability caps)
410{
411 struct seat *s = data;
412
413 if ((caps & WL_SEAT_CAPABILITY_POINTER) && !s->pointer) {
414 s->pointer = wl_seat_get_pointer(seat);
415 wl_pointer_set_user_data(s->pointer, s);
416 wl_pointer_add_listener(s->pointer, &pointer_listener, s);
417 } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && s->pointer) {
418 wl_pointer_destroy(s->pointer);
419 s->pointer = NULL;
420 }
421}
422
423static const struct wl_seat_listener seat_listener = {
424 seat_handle_capabilities,
425};
426
427static void
428bind_seat(struct display *d, uint32_t id)
429{
430 struct seat *s = calloc(1, sizeof *s);
431
432 s->display = d;
433 s->seat = wl_display_bind(d->display, id, &wl_seat_interface);
434 wl_seat_add_listener(s->seat, &seat_listener, s);
435 d->seat = s;
436}
437
438static void
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100439display_handle_global(struct wl_display *display, uint32_t id,
440 const char *interface, uint32_t version, void *data)
441{
442 struct display *d = data;
443
Kristian Høgsberg8357cd62011-05-13 13:24:56 -0400444 if (strcmp(interface, "wl_compositor") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -0400445 d->compositor =
446 wl_display_bind(display, id, &wl_compositor_interface);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400447 } else if (strcmp(interface, "wl_shell") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -0400448 d->shell = wl_display_bind(display, id, &wl_shell_interface);
Daniel Stone37816df2012-05-16 18:45:18 +0100449 } else if (strcmp(interface, "wl_seat") == 0) {
450 bind_seat(d, id);
Kristian Høgsberg8357cd62011-05-13 13:24:56 -0400451 }
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100452}
453
454static int
455event_mask_update(uint32_t mask, void *data)
456{
457 struct display *d = data;
458
459 d->mask = mask;
460
461 return 0;
462}
463
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200464static int running = 1;
465
466static void
467signal_int(int signum)
468{
469 running = 0;
470}
471
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100472int
473main(int argc, char **argv)
474{
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200475 struct sigaction sigint;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100476 struct display display = { 0 };
477 struct window window = { 0 };
Kristian Høgsberg3593f812012-05-10 20:40:51 -0400478 int alpha_size, i;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100479
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100480 window.display = &display;
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300481 display.window = &window;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100482 window.geometry.width = 250;
483 window.geometry.height = 250;
484
Kristian Høgsberg3593f812012-05-10 20:40:51 -0400485 alpha_size = 1;
486 for (i = 1; i < argc; i++) {
487 if (strcmp("-f", argv[i]) == 0)
488 window.fullscreen = 1;
489 if (strcmp("-o", argv[i]) == 0)
490 alpha_size = 0;
491 }
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300492
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100493 display.display = wl_display_connect(NULL);
494 assert(display.display);
495
496 wl_display_add_global_listener(display.display,
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500497 display_handle_global, &display);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100498
Benjamin Franzke65e50512011-05-31 11:36:31 +0200499 wl_display_get_fd(display.display, event_mask_update, &display);
Kristian Høgsberg33418202011-08-16 23:01:28 -0400500 wl_display_iterate(display.display, WL_DISPLAY_READABLE);
Benjamin Franzke65e50512011-05-31 11:36:31 +0200501
Kristian Høgsberg3593f812012-05-10 20:40:51 -0400502 if (window.fullscreen)
503 alpha_size = 0;
504
505 init_egl(&display, alpha_size);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100506 create_surface(&window);
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500507 init_gl(&window);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100508
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200509 sigint.sa_handler = signal_int;
510 sigemptyset(&sigint.sa_mask);
511 sigint.sa_flags = SA_RESETHAND;
512 sigaction(SIGINT, &sigint, NULL);
513
Kristian Høgsberg33418202011-08-16 23:01:28 -0400514 redraw(&window, NULL, 0);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100515
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200516 while (running)
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100517 wl_display_iterate(display.display, display.mask);
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500518
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200519 fprintf(stderr, "simple-egl exiting\n");
520
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200521 destroy_surface(&window);
522 fini_egl(&display);
523
524 if (display.shell)
525 wl_shell_destroy(display.shell);
526
527 if (display.compositor)
528 wl_compositor_destroy(display.compositor);
529
Pekka Paalanenfb850c42011-12-15 10:07:52 +0200530 wl_display_flush(display.display);
Kristian Høgsbergfcfc83f2012-02-28 14:29:19 -0500531 wl_display_disconnect(display.display);
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200532
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100533 return 0;
534}