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 | f389cac | 2011-08-31 16:21:38 -0400 | [diff] [blame] | 98 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_VG_ALPHA_FORMAT_PRE_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; |
Kristian Høgsberg | f389cac | 2011-08-31 16:21:38 -0400 | [diff] [blame] | 210 | static const EGLint surface_attribs[] = { |
| 211 | EGL_ALPHA_FORMAT, EGL_ALPHA_FORMAT_PRE, |
| 212 | EGL_NONE |
| 213 | }; |
Benjamin Franzke | 65e5051 | 2011-05-31 11:36:31 +0200 | [diff] [blame] | 214 | |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 215 | window->surface = wl_compositor_create_surface(display->compositor); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 216 | window->shell_surface = wl_shell_get_shell_surface(display->shell, |
| 217 | window->surface); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 218 | window->native = |
Kristian Høgsberg | 91342c6 | 2011-04-14 14:44:58 -0400 | [diff] [blame] | 219 | wl_egl_window_create(window->surface, |
Kristian Høgsberg | bfb8e61 | 2011-02-07 10:30:38 -0500 | [diff] [blame] | 220 | window->geometry.width, |
Kristian Høgsberg | f389cac | 2011-08-31 16:21:38 -0400 | [diff] [blame] | 221 | window->geometry.height); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 222 | window->egl_surface = |
| 223 | eglCreateWindowSurface(display->egl.dpy, |
| 224 | display->egl.conf, |
Kristian Høgsberg | 297d6dd | 2011-02-09 10:51:15 -0500 | [diff] [blame] | 225 | window->native, |
Kristian Høgsberg | f389cac | 2011-08-31 16:21:38 -0400 | [diff] [blame] | 226 | surface_attribs); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 227 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 228 | wl_shell_surface_set_toplevel(window->shell_surface); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 229 | |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 230 | ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface, |
| 231 | window->egl_surface, window->display->egl.ctx); |
| 232 | assert(ret == EGL_TRUE); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 233 | } |
| 234 | |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 235 | static void |
| 236 | destroy_surface(struct window *window) |
| 237 | { |
| 238 | wl_egl_window_destroy(window->native); |
| 239 | |
| 240 | wl_shell_surface_destroy(window->shell_surface); |
| 241 | wl_surface_destroy(window->surface); |
| 242 | |
| 243 | if (window->callback) |
| 244 | wl_callback_destroy(window->callback); |
| 245 | } |
| 246 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 247 | static const struct wl_callback_listener frame_listener; |
| 248 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 249 | static void |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 250 | redraw(void *data, struct wl_callback *callback, uint32_t time) |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 251 | { |
| 252 | struct window *window = data; |
| 253 | static const GLfloat verts[3][2] = { |
| 254 | { -0.5, -0.5 }, |
| 255 | { 0.5, -0.5 }, |
| 256 | { 0, 0.5 } |
| 257 | }; |
| 258 | static const GLfloat colors[3][3] = { |
| 259 | { 1, 0, 0 }, |
| 260 | { 0, 1, 0 }, |
| 261 | { 0, 0, 1 } |
| 262 | }; |
| 263 | GLfloat angle; |
| 264 | GLfloat rotation[4][4] = { |
| 265 | { 1, 0, 0, 0 }, |
| 266 | { 0, 1, 0, 0 }, |
| 267 | { 0, 0, 1, 0 }, |
| 268 | { 0, 0, 0, 1 } |
| 269 | }; |
| 270 | static const int32_t speed_div = 5; |
| 271 | static uint32_t start_time = 0; |
| 272 | |
| 273 | if (start_time == 0) |
| 274 | start_time = time; |
| 275 | |
| 276 | angle = ((time-start_time) / speed_div) % 360 * M_PI / 180.0; |
| 277 | rotation[0][0] = cos(angle); |
| 278 | rotation[0][2] = sin(angle); |
| 279 | rotation[2][0] = -sin(angle); |
| 280 | rotation[2][2] = cos(angle); |
| 281 | |
| 282 | glUniformMatrix4fv(window->gl.rotation_uniform, 1, GL_FALSE, |
| 283 | (GLfloat *) rotation); |
| 284 | |
| 285 | glClearColor(0.0, 0.0, 0.0, 0.5); |
| 286 | glClear(GL_COLOR_BUFFER_BIT); |
| 287 | |
| 288 | glVertexAttribPointer(window->gl.pos, 2, GL_FLOAT, GL_FALSE, 0, verts); |
| 289 | glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors); |
| 290 | glEnableVertexAttribArray(window->gl.pos); |
| 291 | glEnableVertexAttribArray(window->gl.col); |
| 292 | |
| 293 | glDrawArrays(GL_TRIANGLES, 0, 3); |
| 294 | |
| 295 | glDisableVertexAttribArray(window->gl.pos); |
| 296 | glDisableVertexAttribArray(window->gl.col); |
| 297 | |
| 298 | glFlush(); |
| 299 | |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 300 | eglSwapBuffers(window->display->egl.dpy, window->egl_surface); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 301 | if (callback) |
| 302 | wl_callback_destroy(callback); |
| 303 | |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 304 | window->callback = wl_surface_frame(window->surface); |
| 305 | wl_callback_add_listener(window->callback, &frame_listener, window); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 306 | } |
| 307 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 308 | static const struct wl_callback_listener frame_listener = { |
| 309 | redraw |
| 310 | }; |
| 311 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 312 | static void |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 313 | display_handle_global(struct wl_display *display, uint32_t id, |
| 314 | const char *interface, uint32_t version, void *data) |
| 315 | { |
| 316 | struct display *d = data; |
| 317 | |
Kristian Høgsberg | 8357cd6 | 2011-05-13 13:24:56 -0400 | [diff] [blame] | 318 | if (strcmp(interface, "wl_compositor") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 319 | d->compositor = |
| 320 | wl_display_bind(display, id, &wl_compositor_interface); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 321 | } else if (strcmp(interface, "wl_shell") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 322 | d->shell = wl_display_bind(display, id, &wl_shell_interface); |
Kristian Høgsberg | 8357cd6 | 2011-05-13 13:24:56 -0400 | [diff] [blame] | 323 | } |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static int |
| 327 | event_mask_update(uint32_t mask, void *data) |
| 328 | { |
| 329 | struct display *d = data; |
| 330 | |
| 331 | d->mask = mask; |
| 332 | |
| 333 | return 0; |
| 334 | } |
| 335 | |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 336 | static int running = 1; |
| 337 | |
| 338 | static void |
| 339 | signal_int(int signum) |
| 340 | { |
| 341 | running = 0; |
| 342 | } |
| 343 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 344 | int |
| 345 | main(int argc, char **argv) |
| 346 | { |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 347 | struct sigaction sigint; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 348 | struct display display = { 0 }; |
| 349 | struct window window = { 0 }; |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 350 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 351 | window.display = &display; |
| 352 | window.geometry.width = 250; |
| 353 | window.geometry.height = 250; |
| 354 | |
| 355 | display.display = wl_display_connect(NULL); |
| 356 | assert(display.display); |
| 357 | |
| 358 | wl_display_add_global_listener(display.display, |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 359 | display_handle_global, &display); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 360 | |
Benjamin Franzke | 65e5051 | 2011-05-31 11:36:31 +0200 | [diff] [blame] | 361 | wl_display_get_fd(display.display, event_mask_update, &display); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 362 | wl_display_iterate(display.display, WL_DISPLAY_READABLE); |
Benjamin Franzke | 65e5051 | 2011-05-31 11:36:31 +0200 | [diff] [blame] | 363 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 364 | init_egl(&display); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 365 | create_surface(&window); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 366 | init_gl(&window); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 367 | |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 368 | sigint.sa_handler = signal_int; |
| 369 | sigemptyset(&sigint.sa_mask); |
| 370 | sigint.sa_flags = SA_RESETHAND; |
| 371 | sigaction(SIGINT, &sigint, NULL); |
| 372 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 373 | redraw(&window, NULL, 0); |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 374 | |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 375 | while (running) |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 376 | wl_display_iterate(display.display, display.mask); |
Kristian Høgsberg | a495a5e | 2011-02-04 15:31:33 -0500 | [diff] [blame] | 377 | |
Pekka Paalanen | 88e60fc | 2011-12-13 12:09:09 +0200 | [diff] [blame] | 378 | fprintf(stderr, "simple-egl exiting\n"); |
| 379 | |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 380 | destroy_surface(&window); |
| 381 | fini_egl(&display); |
| 382 | |
| 383 | if (display.shell) |
| 384 | wl_shell_destroy(display.shell); |
| 385 | |
| 386 | if (display.compositor) |
| 387 | wl_compositor_destroy(display.compositor); |
| 388 | |
Pekka Paalanen | fb850c4 | 2011-12-15 10:07:52 +0200 | [diff] [blame^] | 389 | wl_display_flush(display.display); |
Pekka Paalanen | 2c2c106 | 2011-12-13 14:50:25 +0200 | [diff] [blame] | 390 | wl_display_destroy(display.display); |
| 391 | |
Benjamin Franzke | aabdce0 | 2011-01-15 00:40:17 +0100 | [diff] [blame] | 392 | return 0; |
| 393 | } |