Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 1 | /* |
| 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 Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 26 | #include <stdbool.h> |
| 27 | #include <math.h> |
| 28 | #include <assert.h> |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 29 | #include <signal.h> |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 30 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 31 | #include <wayland-client.h> |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 32 | #include <wayland-egl.h> |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 33 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 34 | #include <GLES2/gl2.h> |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 35 | #include <EGL/egl.h> |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 36 | |
| 37 | struct display { |
| 38 | struct wl_display *display; |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 39 | struct wl_compositor *compositor; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 40 | struct wl_shell *shell; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 41 | struct { |
| 42 | EGLDisplay dpy; |
| 43 | EGLContext ctx; |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 44 | EGLConfig conf; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 45 | } egl; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 46 | uint32_t mask; |
| 47 | }; |
| 48 | |
| 49 | struct window { |
| 50 | struct display *display; |
| 51 | struct { |
| 52 | int width, height; |
| 53 | } geometry; |
| 54 | struct { |
| 55 | GLuint fbo; |
| 56 | GLuint color_rbo; |
| 57 | |
| 58 | GLuint program; |
| 59 | GLuint rotation_uniform; |
| 60 | |
| 61 | GLuint pos; |
| 62 | GLuint col; |
| 63 | } gl; |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 64 | |
| 65 | struct wl_egl_window *native; |
| 66 | struct wl_surface *surface; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 67 | struct wl_shell_surface *shell_surface; |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 68 | EGLSurface egl_surface; |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 69 | struct wl_callback *callback; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | static const char *vert_shader_text = |
| 73 | "uniform mat4 rotation;\n" |
| 74 | "attribute vec4 pos;\n" |
| 75 | "attribute vec4 color;\n" |
| 76 | "varying vec4 v_color;\n" |
| 77 | "void main() {\n" |
| 78 | " gl_Position = rotation * pos;\n" |
| 79 | " v_color = color;\n" |
| 80 | "}\n"; |
| 81 | |
| 82 | static const char *frag_shader_text = |
Kristian Høgsberg | 1a11fac | 2011-01-14 20:39:21 -0500 | [diff] [blame] | 83 | "precision mediump float;\n" |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 84 | "varying vec4 v_color;\n" |
| 85 | "void main() {\n" |
| 86 | " gl_FragColor = v_color;\n" |
| 87 | "}\n"; |
| 88 | |
| 89 | static void |
| 90 | init_egl(struct display *display) |
| 91 | { |
Kristian Høgsberg | 1a11fac | 2011-01-14 20:39:21 -0500 | [diff] [blame] | 92 | static const EGLint context_attribs[] = { |
| 93 | EGL_CONTEXT_CLIENT_VERSION, 2, |
| 94 | EGL_NONE |
| 95 | }; |
| 96 | |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 97 | static const EGLint config_attribs[] = { |
Kristian Høgsberg | 8e81df4 | 2012-01-11 14:24:46 -0500 | [diff] [blame] | 98 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 99 | EGL_RED_SIZE, 1, |
| 100 | EGL_GREEN_SIZE, 1, |
| 101 | EGL_BLUE_SIZE, 1, |
Benjamin Franzke | 2eae9e3 | 2011-03-17 15:43:21 +0100 | [diff] [blame] | 102 | EGL_ALPHA_SIZE, 1, |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 103 | EGL_DEPTH_SIZE, 1, |
| 104 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 105 | EGL_NONE |
| 106 | }; |
| 107 | |
| 108 | EGLint major, minor, n; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 109 | EGLBoolean ret; |
| 110 | |
Kristian Høgsberg | 91342c6 | 2011-04-14 14:44:58 -0400 | [diff] [blame] | 111 | display->egl.dpy = eglGetDisplay(display->display); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 112 | assert(display->egl.dpy); |
| 113 | |
| 114 | ret = eglInitialize(display->egl.dpy, &major, &minor); |
| 115 | assert(ret == EGL_TRUE); |
Kristian Høgsberg | 1a11fac | 2011-01-14 20:39:21 -0500 | [diff] [blame] | 116 | ret = eglBindAPI(EGL_OPENGL_ES_API); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 117 | assert(ret == EGL_TRUE); |
| 118 | |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 119 | assert(eglChooseConfig(display->egl.dpy, config_attribs, |
| 120 | &display->egl.conf, 1, &n) && n == 1); |
| 121 | |
| 122 | display->egl.ctx = eglCreateContext(display->egl.dpy, |
| 123 | display->egl.conf, |
Kristian Høgsberg | 1a11fac | 2011-01-14 20:39:21 -0500 | [diff] [blame] | 124 | EGL_NO_CONTEXT, context_attribs); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 125 | assert(display->egl.ctx); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 126 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 129 | static void |
| 130 | fini_egl(struct display *display) |
| 131 | { |
| 132 | /* Required, otherwise segfault in egl_dri2.c: dri2_make_current() |
| 133 | * on eglReleaseThread(). */ |
| 134 | eglMakeCurrent(display->egl.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, |
| 135 | EGL_NO_CONTEXT); |
| 136 | |
| 137 | eglTerminate(display->egl.dpy); |
| 138 | eglReleaseThread(); |
| 139 | } |
| 140 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 141 | static GLuint |
| 142 | create_shader(struct window *window, const char *source, GLenum shader_type) |
| 143 | { |
| 144 | GLuint shader; |
| 145 | GLint status; |
| 146 | |
| 147 | shader = glCreateShader(shader_type); |
| 148 | assert(shader != 0); |
| 149 | |
| 150 | glShaderSource(shader, 1, (const char **) &source, NULL); |
| 151 | glCompileShader(shader); |
| 152 | |
| 153 | glGetShaderiv(shader, GL_COMPILE_STATUS, &status); |
| 154 | if (!status) { |
| 155 | char log[1000]; |
| 156 | GLsizei len; |
| 157 | glGetShaderInfoLog(shader, 1000, &len, log); |
| 158 | fprintf(stderr, "Error: compiling %s: %*s\n", |
| 159 | shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment", |
| 160 | len, log); |
| 161 | exit(1); |
| 162 | } |
| 163 | |
| 164 | return shader; |
| 165 | } |
| 166 | |
| 167 | static void |
| 168 | init_gl(struct window *window) |
| 169 | { |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 170 | GLuint frag, vert; |
| 171 | GLint status; |
| 172 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 173 | glViewport(0, 0, window->geometry.width, window->geometry.height); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 174 | |
| 175 | frag = create_shader(window, frag_shader_text, GL_FRAGMENT_SHADER); |
| 176 | vert = create_shader(window, vert_shader_text, GL_VERTEX_SHADER); |
| 177 | |
| 178 | window->gl.program = glCreateProgram(); |
| 179 | glAttachShader(window->gl.program, frag); |
| 180 | glAttachShader(window->gl.program, vert); |
| 181 | glLinkProgram(window->gl.program); |
| 182 | |
| 183 | glGetProgramiv(window->gl.program, GL_LINK_STATUS, &status); |
| 184 | if (!status) { |
| 185 | char log[1000]; |
| 186 | GLsizei len; |
| 187 | glGetProgramInfoLog(window->gl.program, 1000, &len, log); |
| 188 | fprintf(stderr, "Error: linking:\n%*s\n", len, log); |
| 189 | exit(1); |
| 190 | } |
| 191 | |
| 192 | glUseProgram(window->gl.program); |
| 193 | |
| 194 | window->gl.pos = 0; |
| 195 | window->gl.pos = 1; |
| 196 | |
| 197 | glBindAttribLocation(window->gl.program, window->gl.pos, "pos"); |
| 198 | glBindAttribLocation(window->gl.program, window->gl.col, "color"); |
| 199 | glLinkProgram(window->gl.program); |
| 200 | |
| 201 | window->gl.rotation_uniform = |
| 202 | glGetUniformLocation(window->gl.program, "rotation"); |
| 203 | } |
| 204 | |
| 205 | static void |
| 206 | create_surface(struct window *window) |
| 207 | { |
| 208 | struct display *display = window->display; |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 209 | EGLBoolean ret; |
Benjamin Franzke | 65e5051 | 2011-05-31 11:36:31 +0200 | [diff] [blame] | 210 | |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 211 | window->surface = wl_compositor_create_surface(display->compositor); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 212 | window->shell_surface = wl_shell_get_shell_surface(display->shell, |
| 213 | window->surface); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 214 | window->native = |
Kristian Høgsberg | 91342c6 | 2011-04-14 14:44:58 -0400 | [diff] [blame] | 215 | wl_egl_window_create(window->surface, |
Kristian Høgsberg | bfb8e61 | 2011-02-07 10:30:38 -0500 | [diff] [blame] | 216 | window->geometry.width, |
Kristian Høgsberg | f389cac | 2011-08-31 16:21:38 -0400 | [diff] [blame] | 217 | window->geometry.height); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 218 | window->egl_surface = |
| 219 | eglCreateWindowSurface(display->egl.dpy, |
| 220 | display->egl.conf, |
Kristian Høgsberg | 8e81df4 | 2012-01-11 14:24:46 -0500 | [diff] [blame] | 221 | window->native, NULL); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 222 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 223 | wl_shell_surface_set_toplevel(window->shell_surface); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 224 | |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 225 | ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface, |
| 226 | window->egl_surface, window->display->egl.ctx); |
| 227 | assert(ret == EGL_TRUE); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 228 | } |
| 229 | |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 230 | static void |
| 231 | destroy_surface(struct window *window) |
| 232 | { |
| 233 | wl_egl_window_destroy(window->native); |
| 234 | |
| 235 | wl_shell_surface_destroy(window->shell_surface); |
| 236 | wl_surface_destroy(window->surface); |
| 237 | |
| 238 | if (window->callback) |
| 239 | wl_callback_destroy(window->callback); |
| 240 | } |
| 241 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 242 | static const struct wl_callback_listener frame_listener; |
| 243 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 244 | static void |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 245 | redraw(void *data, struct wl_callback *callback, uint32_t time) |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 246 | { |
| 247 | struct window *window = data; |
| 248 | static const GLfloat verts[3][2] = { |
| 249 | { -0.5, -0.5 }, |
| 250 | { 0.5, -0.5 }, |
| 251 | { 0, 0.5 } |
| 252 | }; |
| 253 | static const GLfloat colors[3][3] = { |
| 254 | { 1, 0, 0 }, |
| 255 | { 0, 1, 0 }, |
| 256 | { 0, 0, 1 } |
| 257 | }; |
| 258 | GLfloat angle; |
| 259 | GLfloat rotation[4][4] = { |
| 260 | { 1, 0, 0, 0 }, |
| 261 | { 0, 1, 0, 0 }, |
| 262 | { 0, 0, 1, 0 }, |
| 263 | { 0, 0, 0, 1 } |
| 264 | }; |
| 265 | static const int32_t speed_div = 5; |
| 266 | static uint32_t start_time = 0; |
| 267 | |
| 268 | if (start_time == 0) |
| 269 | start_time = time; |
| 270 | |
| 271 | angle = ((time-start_time) / speed_div) % 360 * M_PI / 180.0; |
| 272 | rotation[0][0] = cos(angle); |
| 273 | rotation[0][2] = sin(angle); |
| 274 | rotation[2][0] = -sin(angle); |
| 275 | rotation[2][2] = cos(angle); |
| 276 | |
| 277 | glUniformMatrix4fv(window->gl.rotation_uniform, 1, GL_FALSE, |
| 278 | (GLfloat *) rotation); |
| 279 | |
| 280 | glClearColor(0.0, 0.0, 0.0, 0.5); |
| 281 | glClear(GL_COLOR_BUFFER_BIT); |
| 282 | |
| 283 | glVertexAttribPointer(window->gl.pos, 2, GL_FLOAT, GL_FALSE, 0, verts); |
| 284 | glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors); |
| 285 | glEnableVertexAttribArray(window->gl.pos); |
| 286 | glEnableVertexAttribArray(window->gl.col); |
| 287 | |
| 288 | glDrawArrays(GL_TRIANGLES, 0, 3); |
| 289 | |
| 290 | glDisableVertexAttribArray(window->gl.pos); |
| 291 | glDisableVertexAttribArray(window->gl.col); |
| 292 | |
| 293 | glFlush(); |
| 294 | |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 295 | eglSwapBuffers(window->display->egl.dpy, window->egl_surface); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 296 | if (callback) |
| 297 | wl_callback_destroy(callback); |
| 298 | |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 299 | window->callback = wl_surface_frame(window->surface); |
| 300 | wl_callback_add_listener(window->callback, &frame_listener, window); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 301 | } |
| 302 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 303 | static const struct wl_callback_listener frame_listener = { |
| 304 | redraw |
| 305 | }; |
| 306 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 307 | static void |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 308 | display_handle_global(struct wl_display *display, uint32_t id, |
| 309 | const char *interface, uint32_t version, void *data) |
| 310 | { |
| 311 | struct display *d = data; |
| 312 | |
Kristian Høgsberg | 8357cd6 | 2011-05-13 13:24:56 -0400 | [diff] [blame] | 313 | if (strcmp(interface, "wl_compositor") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 314 | d->compositor = |
| 315 | wl_display_bind(display, id, &wl_compositor_interface); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 316 | } else if (strcmp(interface, "wl_shell") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 317 | d->shell = wl_display_bind(display, id, &wl_shell_interface); |
Kristian Høgsberg | 8357cd6 | 2011-05-13 13:24:56 -0400 | [diff] [blame] | 318 | } |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | static int |
| 322 | event_mask_update(uint32_t mask, void *data) |
| 323 | { |
| 324 | struct display *d = data; |
| 325 | |
| 326 | d->mask = mask; |
| 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 331 | static int running = 1; |
| 332 | |
| 333 | static void |
| 334 | signal_int(int signum) |
| 335 | { |
| 336 | running = 0; |
| 337 | } |
| 338 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 339 | int |
| 340 | main(int argc, char **argv) |
| 341 | { |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 342 | struct sigaction sigint; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 343 | struct display display = { 0 }; |
| 344 | struct window window = { 0 }; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 345 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 346 | window.display = &display; |
| 347 | window.geometry.width = 250; |
| 348 | window.geometry.height = 250; |
| 349 | |
| 350 | display.display = wl_display_connect(NULL); |
| 351 | assert(display.display); |
| 352 | |
| 353 | wl_display_add_global_listener(display.display, |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 354 | display_handle_global, &display); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 355 | |
Benjamin Franzke | 65e5051 | 2011-05-31 11:36:31 +0200 | [diff] [blame] | 356 | wl_display_get_fd(display.display, event_mask_update, &display); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 357 | wl_display_iterate(display.display, WL_DISPLAY_READABLE); |
Benjamin Franzke | 65e5051 | 2011-05-31 11:36:31 +0200 | [diff] [blame] | 358 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 359 | init_egl(&display); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 360 | create_surface(&window); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 361 | init_gl(&window); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 362 | |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 363 | sigint.sa_handler = signal_int; |
| 364 | sigemptyset(&sigint.sa_mask); |
| 365 | sigint.sa_flags = SA_RESETHAND; |
| 366 | sigaction(SIGINT, &sigint, NULL); |
| 367 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 368 | redraw(&window, NULL, 0); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 369 | |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 370 | while (running) |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 371 | wl_display_iterate(display.display, display.mask); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 372 | |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 373 | fprintf(stderr, "simple-egl exiting\n"); |
| 374 | |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 375 | destroy_surface(&window); |
| 376 | fini_egl(&display); |
| 377 | |
| 378 | if (display.shell) |
| 379 | wl_shell_destroy(display.shell); |
| 380 | |
| 381 | if (display.compositor) |
| 382 | wl_compositor_destroy(display.compositor); |
| 383 | |
Pekka Paalanen | fb850c4 | 2011-12-15 10:07:52 +0200 | [diff] [blame] | 384 | wl_display_flush(display.display); |
Kristian Høgsberg | fcfc83f | 2012-02-28 14:29:19 -0500 | [diff] [blame^] | 385 | wl_display_disconnect(display.display); |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 386 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 387 | return 0; |
| 388 | } |