blob: 4cb5bc79635c8b2f7aef83c4ce40c937dbd8db21 [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
Pekka Paalanenb79b6352012-06-12 17:42:24 +0300125 ret = eglChooseConfig(display->egl.dpy, config_attribs,
126 &display->egl.conf, 1, &n);
127 assert(ret && n == 1);
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500128
129 display->egl.ctx = eglCreateContext(display->egl.dpy,
130 display->egl.conf,
Kristian Høgsberg1a11fac2011-01-14 20:39:21 -0500131 EGL_NO_CONTEXT, context_attribs);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100132 assert(display->egl.ctx);
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500133
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100134}
135
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200136static void
137fini_egl(struct display *display)
138{
139 /* Required, otherwise segfault in egl_dri2.c: dri2_make_current()
140 * on eglReleaseThread(). */
141 eglMakeCurrent(display->egl.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
142 EGL_NO_CONTEXT);
143
144 eglTerminate(display->egl.dpy);
145 eglReleaseThread();
146}
147
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100148static GLuint
149create_shader(struct window *window, const char *source, GLenum shader_type)
150{
151 GLuint shader;
152 GLint status;
153
154 shader = glCreateShader(shader_type);
155 assert(shader != 0);
156
157 glShaderSource(shader, 1, (const char **) &source, NULL);
158 glCompileShader(shader);
159
160 glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
161 if (!status) {
162 char log[1000];
163 GLsizei len;
164 glGetShaderInfoLog(shader, 1000, &len, log);
165 fprintf(stderr, "Error: compiling %s: %*s\n",
166 shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment",
167 len, log);
168 exit(1);
169 }
170
171 return shader;
172}
173
174static void
175init_gl(struct window *window)
176{
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100177 GLuint frag, vert;
178 GLint status;
179
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100180 glViewport(0, 0, window->geometry.width, window->geometry.height);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100181
182 frag = create_shader(window, frag_shader_text, GL_FRAGMENT_SHADER);
183 vert = create_shader(window, vert_shader_text, GL_VERTEX_SHADER);
184
185 window->gl.program = glCreateProgram();
186 glAttachShader(window->gl.program, frag);
187 glAttachShader(window->gl.program, vert);
188 glLinkProgram(window->gl.program);
189
190 glGetProgramiv(window->gl.program, GL_LINK_STATUS, &status);
191 if (!status) {
192 char log[1000];
193 GLsizei len;
194 glGetProgramInfoLog(window->gl.program, 1000, &len, log);
195 fprintf(stderr, "Error: linking:\n%*s\n", len, log);
196 exit(1);
197 }
198
199 glUseProgram(window->gl.program);
200
201 window->gl.pos = 0;
202 window->gl.pos = 1;
203
204 glBindAttribLocation(window->gl.program, window->gl.pos, "pos");
205 glBindAttribLocation(window->gl.program, window->gl.col, "color");
206 glLinkProgram(window->gl.program);
207
208 window->gl.rotation_uniform =
209 glGetUniformLocation(window->gl.program, "rotation");
210}
211
212static void
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300213handle_ping(void *data, struct wl_shell_surface *shell_surface,
214 uint32_t serial)
215{
216 wl_shell_surface_pong(shell_surface, serial);
217}
218
219static void
220handle_configure(void *data, struct wl_shell_surface *shell_surface,
221 uint32_t edges, int32_t width, int32_t height)
222{
223 struct window *window = data;
224
225 window->geometry.width = width;
226 window->geometry.height = height;
227 window->configured = 1;
228}
229
230static void
231handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
232{
233}
234
235static const struct wl_shell_surface_listener shell_surface_listener = {
236 handle_ping,
237 handle_configure,
238 handle_popup_done
239};
240
241static void
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100242create_surface(struct window *window)
243{
244 struct display *display = window->display;
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500245 EGLBoolean ret;
Benjamin Franzke65e50512011-05-31 11:36:31 +0200246
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500247 window->surface = wl_compositor_create_surface(display->compositor);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200248 window->shell_surface = wl_shell_get_shell_surface(display->shell,
249 window->surface);
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300250
251 wl_shell_surface_add_listener(window->shell_surface,
252 &shell_surface_listener, window);
253
254 if (window->fullscreen) {
255 window->configured = 0;
256 wl_shell_surface_set_fullscreen(window->shell_surface,
257 WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
258 0, NULL);
259
260 while (!window->configured)
261 wl_display_iterate(display->display, display->mask);
262 }
263 else
264 wl_shell_surface_set_toplevel(window->shell_surface);
265
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500266 window->native =
Kristian Høgsberg91342c62011-04-14 14:44:58 -0400267 wl_egl_window_create(window->surface,
Kristian Høgsbergbfb8e612011-02-07 10:30:38 -0500268 window->geometry.width,
Kristian Høgsbergf389cac2011-08-31 16:21:38 -0400269 window->geometry.height);
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500270 window->egl_surface =
271 eglCreateWindowSurface(display->egl.dpy,
272 display->egl.conf,
Kristian Høgsberg8e81df42012-01-11 14:24:46 -0500273 window->native, NULL);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100274
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500275 ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface,
276 window->egl_surface, window->display->egl.ctx);
277 assert(ret == EGL_TRUE);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100278}
279
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200280static void
281destroy_surface(struct window *window)
282{
283 wl_egl_window_destroy(window->native);
284
285 wl_shell_surface_destroy(window->shell_surface);
286 wl_surface_destroy(window->surface);
287
288 if (window->callback)
289 wl_callback_destroy(window->callback);
290}
291
Kristian Høgsberg33418202011-08-16 23:01:28 -0400292static const struct wl_callback_listener frame_listener;
293
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100294static void
Kristian Høgsberg33418202011-08-16 23:01:28 -0400295redraw(void *data, struct wl_callback *callback, uint32_t time)
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100296{
297 struct window *window = data;
298 static const GLfloat verts[3][2] = {
299 { -0.5, -0.5 },
300 { 0.5, -0.5 },
301 { 0, 0.5 }
302 };
303 static const GLfloat colors[3][3] = {
304 { 1, 0, 0 },
305 { 0, 1, 0 },
306 { 0, 0, 1 }
307 };
308 GLfloat angle;
309 GLfloat rotation[4][4] = {
310 { 1, 0, 0, 0 },
311 { 0, 1, 0, 0 },
312 { 0, 0, 1, 0 },
313 { 0, 0, 0, 1 }
314 };
315 static const int32_t speed_div = 5;
316 static uint32_t start_time = 0;
317
318 if (start_time == 0)
319 start_time = time;
320
321 angle = ((time-start_time) / speed_div) % 360 * M_PI / 180.0;
322 rotation[0][0] = cos(angle);
323 rotation[0][2] = sin(angle);
324 rotation[2][0] = -sin(angle);
325 rotation[2][2] = cos(angle);
326
327 glUniformMatrix4fv(window->gl.rotation_uniform, 1, GL_FALSE,
328 (GLfloat *) rotation);
329
330 glClearColor(0.0, 0.0, 0.0, 0.5);
331 glClear(GL_COLOR_BUFFER_BIT);
332
333 glVertexAttribPointer(window->gl.pos, 2, GL_FLOAT, GL_FALSE, 0, verts);
334 glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors);
335 glEnableVertexAttribArray(window->gl.pos);
336 glEnableVertexAttribArray(window->gl.col);
337
338 glDrawArrays(GL_TRIANGLES, 0, 3);
339
340 glDisableVertexAttribArray(window->gl.pos);
341 glDisableVertexAttribArray(window->gl.col);
342
343 glFlush();
344
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500345 eglSwapBuffers(window->display->egl.dpy, window->egl_surface);
Kristian Høgsberg33418202011-08-16 23:01:28 -0400346 if (callback)
347 wl_callback_destroy(callback);
348
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200349 window->callback = wl_surface_frame(window->surface);
350 wl_callback_add_listener(window->callback, &frame_listener, window);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100351}
352
Kristian Høgsberg33418202011-08-16 23:01:28 -0400353static const struct wl_callback_listener frame_listener = {
354 redraw
355};
356
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100357static void
Daniel Stone37816df2012-05-16 18:45:18 +0100358pointer_handle_enter(void *data, struct wl_pointer *pointer,
359 uint32_t serial, struct wl_surface *surface,
360 wl_fixed_t sx, wl_fixed_t sy)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300361{
362 struct display *display = data;
363
364 if (display->window->fullscreen)
Daniel Stone37816df2012-05-16 18:45:18 +0100365 wl_pointer_attach(pointer, serial, NULL, 0, 0);
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300366}
367
368static void
Daniel Stone37816df2012-05-16 18:45:18 +0100369pointer_handle_leave(void *data, struct wl_pointer *pointer,
370 uint32_t serial, struct wl_surface *surface)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300371{
372}
373
374static void
Daniel Stone37816df2012-05-16 18:45:18 +0100375pointer_handle_motion(void *data, struct wl_pointer *pointer,
376 uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300377{
378}
379
380static void
Daniel Stone37816df2012-05-16 18:45:18 +0100381pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
382 uint32_t serial, uint32_t time, uint32_t button,
383 uint32_t state)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300384{
385}
386
387static void
Daniel Stone37816df2012-05-16 18:45:18 +0100388pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
Daniel Stone2fce4022012-05-30 16:32:00 +0100389 uint32_t time, uint32_t axis, wl_fixed_t value)
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300390{
391}
392
Daniel Stone37816df2012-05-16 18:45:18 +0100393static const struct wl_pointer_listener pointer_listener = {
394 pointer_handle_enter,
395 pointer_handle_leave,
396 pointer_handle_motion,
397 pointer_handle_button,
398 pointer_handle_axis,
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300399};
400
401static void
Daniel Stone37816df2012-05-16 18:45:18 +0100402seat_handle_capabilities(void *data, struct wl_seat *seat,
403 enum wl_seat_capability caps)
404{
Kristian Høgsbergb84108d2012-05-16 16:16:19 -0400405 struct display *d = data;
Daniel Stone37816df2012-05-16 18:45:18 +0100406
Kristian Høgsbergb84108d2012-05-16 16:16:19 -0400407 if ((caps & WL_SEAT_CAPABILITY_POINTER) && !d->pointer) {
408 d->pointer = wl_seat_get_pointer(seat);
409 wl_pointer_add_listener(d->pointer, &pointer_listener, d);
410 } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && d->pointer) {
411 wl_pointer_destroy(d->pointer);
412 d->pointer = NULL;
Daniel Stone37816df2012-05-16 18:45:18 +0100413 }
414}
415
416static const struct wl_seat_listener seat_listener = {
417 seat_handle_capabilities,
418};
419
420static void
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100421display_handle_global(struct wl_display *display, uint32_t id,
422 const char *interface, uint32_t version, void *data)
423{
424 struct display *d = data;
425
Kristian Høgsberg8357cd62011-05-13 13:24:56 -0400426 if (strcmp(interface, "wl_compositor") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -0400427 d->compositor =
428 wl_display_bind(display, id, &wl_compositor_interface);
Kristian Høgsberg7a5c9792011-06-18 06:12:54 -0400429 } else if (strcmp(interface, "wl_shell") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -0400430 d->shell = wl_display_bind(display, id, &wl_shell_interface);
Daniel Stone37816df2012-05-16 18:45:18 +0100431 } else if (strcmp(interface, "wl_seat") == 0) {
Kristian Høgsbergb84108d2012-05-16 16:16:19 -0400432 d->seat = wl_display_bind(d->display, id, &wl_seat_interface);
433 wl_seat_add_listener(d->seat, &seat_listener, d);
Kristian Høgsberg8357cd62011-05-13 13:24:56 -0400434 }
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100435}
436
437static int
438event_mask_update(uint32_t mask, void *data)
439{
440 struct display *d = data;
441
442 d->mask = mask;
443
444 return 0;
445}
446
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200447static int running = 1;
448
449static void
450signal_int(int signum)
451{
452 running = 0;
453}
454
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100455int
456main(int argc, char **argv)
457{
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200458 struct sigaction sigint;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100459 struct display display = { 0 };
460 struct window window = { 0 };
Kristian Høgsberg3593f812012-05-10 20:40:51 -0400461 int alpha_size, i;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100462
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100463 window.display = &display;
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300464 display.window = &window;
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100465 window.geometry.width = 250;
466 window.geometry.height = 250;
467
Kristian Høgsberg3593f812012-05-10 20:40:51 -0400468 alpha_size = 1;
469 for (i = 1; i < argc; i++) {
470 if (strcmp("-f", argv[i]) == 0)
471 window.fullscreen = 1;
472 if (strcmp("-o", argv[i]) == 0)
473 alpha_size = 0;
474 }
Ander Conselvan de Oliveirad51624f2012-05-02 16:42:23 +0300475
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100476 display.display = wl_display_connect(NULL);
477 assert(display.display);
478
479 wl_display_add_global_listener(display.display,
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500480 display_handle_global, &display);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100481
Benjamin Franzke65e50512011-05-31 11:36:31 +0200482 wl_display_get_fd(display.display, event_mask_update, &display);
Kristian Høgsberg33418202011-08-16 23:01:28 -0400483 wl_display_iterate(display.display, WL_DISPLAY_READABLE);
Benjamin Franzke65e50512011-05-31 11:36:31 +0200484
Kristian Høgsberg3593f812012-05-10 20:40:51 -0400485 if (window.fullscreen)
486 alpha_size = 0;
487
488 init_egl(&display, alpha_size);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100489 create_surface(&window);
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500490 init_gl(&window);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100491
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200492 sigint.sa_handler = signal_int;
493 sigemptyset(&sigint.sa_mask);
494 sigint.sa_flags = SA_RESETHAND;
495 sigaction(SIGINT, &sigint, NULL);
496
Kristian Høgsberg33418202011-08-16 23:01:28 -0400497 redraw(&window, NULL, 0);
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100498
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200499 while (running)
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100500 wl_display_iterate(display.display, display.mask);
Kristian Høgsberga495a5e2011-02-04 15:31:33 -0500501
Pekka Paalanen88e60fc2011-12-13 12:09:09 +0200502 fprintf(stderr, "simple-egl exiting\n");
503
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200504 destroy_surface(&window);
505 fini_egl(&display);
506
507 if (display.shell)
508 wl_shell_destroy(display.shell);
509
510 if (display.compositor)
511 wl_compositor_destroy(display.compositor);
512
Pekka Paalanenfb850c42011-12-15 10:07:52 +0200513 wl_display_flush(display.display);
Kristian Høgsbergfcfc83f2012-02-28 14:29:19 -0500514 wl_display_disconnect(display.display);
Pekka Paalanen2c2c1062011-12-13 14:50:25 +0200515
Benjamin Franzkeaabdce02011-01-15 00:40:17 +0100516 return 0;
517}