blob: 5654bacb4691bcde4d4c0e69221d4a324418bee2 [file] [log] [blame]
Kristian Høgsbergffd710e2008-12-02 15:15:01 -05001/*
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -05002 * Copyright © 2008 Kristian Høgsberg
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.
Kristian Høgsbergffd710e2008-12-02 15:15:01 -050021 */
22
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050023#include <stdint.h>
24#include <stdio.h>
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050025#include <stdlib.h>
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050026#include <string.h>
27#include <fcntl.h>
28#include <unistd.h>
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050029#include <math.h>
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050030#include <time.h>
31#include <cairo.h>
32#include <glib.h>
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -050033#include <cairo-drm.h>
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050034
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050035#include <GL/gl.h>
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050036#include <eagle.h>
37
Kristian Høgsbergda1f30a2009-03-06 21:24:01 -050038#include "wayland-util.h"
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050039#include "wayland-client.h"
40#include "wayland-glib.h"
41
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050042#include "window.h"
43
44static const char gem_device[] = "/dev/dri/card0";
45static const char socket_name[] = "\0wayland";
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050046
47struct gears {
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050048 struct window *window;
49
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050050 struct display *d;
Kristian Høgsbergd2412e22008-12-15 20:35:24 -050051 struct wl_compositor *compositor;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050052 struct rectangle rectangle;
53
54 EGLDisplay display;
55 EGLConfig config;
56 EGLSurface surface;
57 EGLContext context;
58 int resized;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050059 GLfloat angle;
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -050060 cairo_surface_t *cairo_surface;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050061
62 GLint gear_list[3];
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050063};
64
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050065struct gear_template {
66 GLfloat material[4];
67 GLfloat inner_radius;
68 GLfloat outer_radius;
69 GLfloat width;
70 GLint teeth;
71 GLfloat tooth_depth;
72};
73
74const static struct gear_template gear_templates[] = {
75 { { 0.8, 0.1, 0.0, 1.0 }, 1.0, 4.0, 1.0, 20, 0.7 },
76 { { 0.0, 0.8, 0.2, 1.0 }, 0.5, 2.0, 2.0, 10, 0.7 },
77 { { 0.2, 0.2, 1.0, 1.0 }, 1.3, 2.0, 0.5, 10, 0.7 },
78};
79
80static GLfloat light_pos[4] = {5.0, 5.0, 10.0, 0.0};
81
82static void die(const char *msg)
83{
84 fprintf(stderr, "%s", msg);
85 exit(EXIT_FAILURE);
86}
87
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050088static void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050089make_gear(const struct gear_template *t)
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050090{
91 GLint i;
92 GLfloat r0, r1, r2;
93 GLfloat angle, da;
94 GLfloat u, v, len;
95
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050096 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, t->material);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050097
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050098 r0 = t->inner_radius;
99 r1 = t->outer_radius - t->tooth_depth / 2.0;
100 r2 = t->outer_radius + t->tooth_depth / 2.0;
101
102 da = 2.0 * M_PI / t->teeth / 4.0;
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500103
104 glShadeModel(GL_FLAT);
105
106 glNormal3f(0.0, 0.0, 1.0);
107
108 /* draw front face */
109 glBegin(GL_QUAD_STRIP);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500110 for (i = 0; i <= t->teeth; i++) {
111 angle = i * 2.0 * M_PI / t->teeth;
112 glVertex3f(r0 * cos(angle), r0 * sin(angle), t->width * 0.5);
113 glVertex3f(r1 * cos(angle), r1 * sin(angle), t->width * 0.5);
114 if (i < t->teeth) {
115 glVertex3f(r0 * cos(angle), r0 * sin(angle), t->width * 0.5);
116 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), t->width * 0.5);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500117 }
118 }
119 glEnd();
120
121 /* draw front sides of teeth */
122 glBegin(GL_QUADS);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500123 da = 2.0 * M_PI / t->teeth / 4.0;
124 for (i = 0; i < t->teeth; i++) {
125 angle = i * 2.0 * M_PI / t->teeth;
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500126
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500127 glVertex3f(r1 * cos(angle), r1 * sin(angle), t->width * 0.5);
128 glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), t->width * 0.5);
129 glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), t->width * 0.5);
130 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), t->width * 0.5);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500131 }
132 glEnd();
133
134 glNormal3f(0.0, 0.0, -1.0);
135
136 /* draw back face */
137 glBegin(GL_QUAD_STRIP);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500138 for (i = 0; i <= t->teeth; i++) {
139 angle = i * 2.0 * M_PI / t->teeth;
140 glVertex3f(r1 * cos(angle), r1 * sin(angle), -t->width * 0.5);
141 glVertex3f(r0 * cos(angle), r0 * sin(angle), -t->width * 0.5);
142 if (i < t->teeth) {
143 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -t->width * 0.5);
144 glVertex3f(r0 * cos(angle), r0 * sin(angle), -t->width * 0.5);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500145 }
146 }
147 glEnd();
148
149 /* draw back sides of teeth */
150 glBegin(GL_QUADS);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500151 da = 2.0 * M_PI / t->teeth / 4.0;
152 for (i = 0; i < t->teeth; i++) {
153 angle = i * 2.0 * M_PI / t->teeth;
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500154
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500155 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -t->width * 0.5);
156 glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -t->width * 0.5);
157 glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -t->width * 0.5);
158 glVertex3f(r1 * cos(angle), r1 * sin(angle), -t->width * 0.5);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500159 }
160 glEnd();
161
162 /* draw outward faces of teeth */
163 glBegin(GL_QUAD_STRIP);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500164 for (i = 0; i < t->teeth; i++) {
165 angle = i * 2.0 * M_PI / t->teeth;
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500166
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500167 glVertex3f(r1 * cos(angle), r1 * sin(angle), t->width * 0.5);
168 glVertex3f(r1 * cos(angle), r1 * sin(angle), -t->width * 0.5);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500169 u = r2 * cos(angle + da) - r1 * cos(angle);
170 v = r2 * sin(angle + da) - r1 * sin(angle);
171 len = sqrt(u * u + v * v);
172 u /= len;
173 v /= len;
174 glNormal3f(v, -u, 0.0);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500175 glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), t->width * 0.5);
176 glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -t->width * 0.5);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500177 glNormal3f(cos(angle), sin(angle), 0.0);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500178 glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), t->width * 0.5);
179 glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -t->width * 0.5);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500180 u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
181 v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
182 glNormal3f(v, -u, 0.0);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500183 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), t->width * 0.5);
184 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -t->width * 0.5);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500185 glNormal3f(cos(angle), sin(angle), 0.0);
186 }
187
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500188 glVertex3f(r1 * cos(0), r1 * sin(0), t->width * 0.5);
189 glVertex3f(r1 * cos(0), r1 * sin(0), -t->width * 0.5);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500190
191 glEnd();
192
193 glShadeModel(GL_SMOOTH);
194
195 /* draw inside radius cylinder */
196 glBegin(GL_QUAD_STRIP);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500197 for (i = 0; i <= t->teeth; i++) {
198 angle = i * 2.0 * M_PI / t->teeth;
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500199 glNormal3f(-cos(angle), -sin(angle), 0.0);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500200 glVertex3f(r0 * cos(angle), r0 * sin(angle), -t->width * 0.5);
201 glVertex3f(r0 * cos(angle), r0 * sin(angle), t->width * 0.5);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500202 }
203 glEnd();
204}
205
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500206static void
207draw_gears(struct gears *gears)
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500208{
209 GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
210
Kristian Høgsberg78231c82008-11-08 15:06:01 -0500211 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Kristian Høgsbergb8bf19b2008-11-05 07:38:46 -0500212
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500213 glPushMatrix();
214
215 glTranslatef(0.0, 0.0, -50);
216
217 glRotatef(view_rotx, 1.0, 0.0, 0.0);
218 glRotatef(view_roty, 0.0, 1.0, 0.0);
219 glRotatef(view_rotz, 0.0, 0.0, 1.0);
220
221 glPushMatrix();
222 glTranslatef(-3.0, -2.0, 0.0);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500223 glRotatef(gears->angle, 0.0, 0.0, 1.0);
224 glCallList(gears->gear_list[0]);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500225 glPopMatrix();
226
227 glPushMatrix();
228 glTranslatef(3.1, -2.0, 0.0);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500229 glRotatef(-2.0 * gears->angle - 9.0, 0.0, 0.0, 1.0);
230 glCallList(gears->gear_list[1]);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500231 glPopMatrix();
232
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500233 glPushMatrix();
234 glTranslatef(-3.1, 4.2, 0.0);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500235 glRotatef(-2.0 * gears->angle - 25.0, 0.0, 0.0, 1.0);
236 glCallList(gears->gear_list[2]);
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500237 glPopMatrix();
238
239 glPopMatrix();
240
241 glFlush();
242}
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500243
244static void
245resize_window(struct gears *gears)
246{
Kristian Høgsberg22106762008-12-08 13:50:07 -0500247 /* Constrain child size to be square and at least 300x300 */
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500248 window_get_child_rectangle(gears->window, &gears->rectangle);
Kristian Høgsberg22106762008-12-08 13:50:07 -0500249 if (gears->rectangle.width > gears->rectangle.height)
250 gears->rectangle.height = gears->rectangle.width;
251 else
252 gears->rectangle.width = gears->rectangle.height;
253 if (gears->rectangle.width < 300) {
254 gears->rectangle.width = 300;
255 gears->rectangle.height = 300;
256 }
257 window_set_child_size(gears->window, &gears->rectangle);
258
259 window_draw(gears->window);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500260
Kristian Høgsbergda1f30a2009-03-06 21:24:01 -0500261 if (gears->surface != NULL)
262 eglDestroySurface(gears->display, gears->surface);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500263
Kristian Høgsbergcda0e0d2009-05-27 20:07:38 -0400264 gears->surface = eglCreateSurface(gears->display,
265 gears->config,
266 gears->rectangle.width,
267 gears->rectangle.height,
268 1, NULL);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500269
270 eglMakeCurrent(gears->display,
271 gears->surface, gears->surface, gears->context);
272
273 glViewport(0, 0, gears->rectangle.width, gears->rectangle.height);
274 gears->resized = 0;
275}
276
277static void
Kristian Høgsberg22106762008-12-08 13:50:07 -0500278resize_handler(struct window *window, void *data)
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500279{
280 struct gears *gears = data;
281
282 /* Right now, resizing the window from the per-frame callback
283 * is fine, since the window drawing code is so slow that we
284 * can't draw more than one window per frame anyway. However,
285 * once we implement faster resizing, this will show lag
286 * between pointer motion and window size even if resizing is
287 * fast. We need to keep processing motion events and posting
288 * new frames as fast as possible so when the server
289 * composites the next frame it will have the most recent size
290 * possible, like what we do for window moves. */
291
292 gears->resized = 1;
293}
294
295static void
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500296handle_acknowledge(void *data,
297 struct wl_compositor *compositor,
298 uint32_t key, uint32_t frame)
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500299{
300 struct gears *gears = data;
301
302 if (key != 0)
303 return;
304
305 if (gears->resized)
306 resize_window(gears);
307
308 draw_gears(gears);
309}
310
311static void
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500312handle_frame(void *data,
313 struct wl_compositor *compositor,
314 uint32_t frame, uint32_t timestamp)
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500315{
316 struct gears *gears = data;
Kristian Høgsbergb22382b2009-03-10 23:40:35 -0400317 uint32_t name, handle, stride;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500318
Kristian Høgsbergcda0e0d2009-05-27 20:07:38 -0400319 eglGetColorBuffer(gears->surface, 0, &name, &handle, &stride);
Kristian Høgsbergda1f30a2009-03-06 21:24:01 -0500320
321 window_copy(gears->window, &gears->rectangle, name, stride);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500322
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500323 wl_compositor_commit(gears->compositor, 0);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500324
Kristian Høgsberg75b70ce2009-09-12 21:08:48 -0400325 gears->angle = (GLfloat) (timestamp % 8192) * 360 / 8192.0;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500326}
327
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500328static const struct wl_compositor_listener compositor_listener = {
329 handle_acknowledge,
330 handle_frame,
331};
332
Kristian Høgsberg1eff73c2009-02-16 00:26:22 -0500333static const EGLint config_attribs[] = {
334 EGL_DEPTH_SIZE, 24,
335 EGL_CONFIG_CAVEAT, EGL_NONE,
336 EGL_RED_SIZE, 8,
337 EGL_NONE
338};
339
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500340static struct gears *
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500341gears_create(struct display *display)
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500342{
343 const int x = 200, y = 200, width = 450, height = 500;
344 EGLint major, minor, count;
345 EGLConfig configs[64];
Kristian Høgsbergaa68fe32009-01-15 12:50:21 -0500346 struct udev *udev;
347 struct udev_device *device;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500348 struct gears *gears;
349 int i;
350
Kristian Høgsbergaa68fe32009-01-15 12:50:21 -0500351 udev = udev_new();
352 device = udev_device_new_from_syspath(udev, "/sys/class/drm/card0");
353
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500354 gears = malloc(sizeof *gears);
355 memset(gears, 0, sizeof *gears);
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500356 gears->d = display;
357 gears->window = window_create(display, "Wayland Gears",
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500358 x, y, width, height);
359
Kristian Høgsbergaa68fe32009-01-15 12:50:21 -0500360 gears->display = eglCreateDisplayNative(device);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500361 if (gears->display == NULL)
362 die("failed to create egl display\n");
363
364 if (!eglInitialize(gears->display, &major, &minor))
365 die("failed to initialize display\n");
366
367 if (!eglGetConfigs(gears->display, configs, 64, &count))
368 die("failed to get configs\n");
369
Kristian Høgsberg1eff73c2009-02-16 00:26:22 -0500370 if (!eglChooseConfig(gears->display, config_attribs, &gears->config, 1, NULL))
371 die("failed to pick a config\n");
372
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500373 gears->context = eglCreateContext(gears->display, gears->config, NULL, NULL);
374 if (gears->context == NULL)
375 die("failed to create context\n");
376
377 resize_window(gears);
378
379 for (i = 0; i < 3; i++) {
380 gears->gear_list[i] = glGenLists(1);
381 glNewList(gears->gear_list[i], GL_COMPILE);
382 make_gear(&gear_templates[i]);
383 glEndList();
384 }
385
386 glEnable(GL_NORMALIZE);
387
388 glMatrixMode(GL_PROJECTION);
389 glLoadIdentity();
390 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 200.0);
391 glMatrixMode(GL_MODELVIEW);
392
393 glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
394 glEnable(GL_CULL_FACE);
395 glEnable(GL_LIGHTING);
396 glEnable(GL_LIGHT0);
397 glEnable(GL_DEPTH_TEST);
398 glClearColor(0, 0, 0, 0.92);
399
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500400 gears->compositor = display_get_compositor(display);
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500401
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500402 draw_gears(gears);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500403
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500404 handle_frame(gears, gears->compositor, 0, 0);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500405
406 window_set_resize_handler(gears->window, resize_handler, gears);
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500407
408 wl_compositor_add_listener(gears->compositor,
409 &compositor_listener, gears);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500410
411 return gears;
412}
413
414int main(int argc, char *argv[])
415{
416 struct wl_display *display;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500417 struct display *d;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500418 int fd;
419 GMainLoop *loop;
420 GSource *source;
421 struct gears *gears;
422
423 fd = open(gem_device, O_RDWR);
424 if (fd < 0) {
425 fprintf(stderr, "drm open failed: %m\n");
426 return -1;
427 }
428
429 display = wl_display_create(socket_name, sizeof socket_name);
430 if (display == NULL) {
431 fprintf(stderr, "failed to create display: %m\n");
432 return -1;
433 }
434
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500435 d = display_create(display, fd);
436
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500437 loop = g_main_loop_new(NULL, FALSE);
438 source = wl_glib_source_new(display);
439 g_source_attach(source, NULL);
440
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500441 gears = gears_create(d);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500442
443 g_main_loop_run(loop);
444
445 return 0;
446}