Weston framerate (Re: bare bones opengl weston client sample)
jegde jedge
bubbah.t at gmail.com
Fri Sep 14 07:32:03 PDT 2012
Sorry about the delay.
I flew 8 legs in 4 days this week.
Here are the mains for both the glut and Wayland instance of my test
application.
uMfdInit, uMfdDraw, and c->controller->event() are the interface
functions, solely used by both implementations.
The code under the hood is IDENTICAL. (with the exception of
glutPostRedisplay() for pan gestures.)
In MainWayland you will see simple-egl.c conditionally compiled for my
application using
HAVE_GLES2 and SIMPLE_EGL
Both MainWayland.c and MainGlut.c use the functions above in the same way.
To recap I am hoping to allow unbounded redraws for testing purposes only.
<MainGlut.c>
<code>
#include "uMfd.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
extern UmfdContext *c;
void glutMotion(int x, int y)
{
c->controller->event(c, drag, x, y);
}
void glutMouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON)
{
if (state == GLUT_UP)
c->controller->event(c, leftUp, x, y);
else
c->controller->event(c, leftDown, x, y);
}
if (button == GLUT_RIGHT_BUTTON)
{
if (state == GLUT_UP)
c->controller->event(c, rightUp, x, y);
else
c->controller->event(c, rightDown, x, y);
}
}
void keyboardIn(unsigned char key, int x, int y)
{
fprintf(stderr, "key-%x; x-%d; y-%d\n", 0x00ff & key, x, y);
switch(key & 0xff)
{
case GLUT_KEY_UP:
c->controller->event(c, upArrow, 0, 0);
break;
case GLUT_KEY_DOWN:
c->controller->event(c, downArrow, 0, 0);
break;
case GLUT_KEY_RIGHT:
c->controller->event(c, rightArrow, 0, 0);
break;
case GLUT_KEY_LEFT:
c->controller->event(c, leftArrow, 0, 0);
break;
// PC menu tooggle
case 0x1b:
fprintf(stderr, "glut KB esc menu");
c->controller->event(c, menu, 0, 0);
break;
case '-':
case '_':
case 0x32:
c->controller->event(c, zoomOut, 2, 2);
break;
case '=':
case '+':
case 0x33:
c->controller->event(c, zoomIn, 3, 3);
break;
// PC menu select
case 0xa:
case 0xd:
fprintf(stderr, "glut KB enter menu select\n");
c->controller->event(c, menuSelect, 0, 0);
break;
}
}
void glutDraw()
{
uMfdDraw(c);
}
void glutIdle()
{
uMfdProcess(c);
//uMfdDraw(c);
}
void glutResize(int width, int height)
{
c->view->resize(c, width, height);
}
int InitializeGraphics()
{
int argc= 0;
char *argv[] = {"one", "two"};
fprintf(stderr, "pc glut init\n");
glutInit(&argc, argv);
/* defining the window with double buffer */
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutEnterGameMode();
if(0)
{
glutInitWindowSize(p.width, p.height);
glutInitWindowPosition(100, 100);
}
//glutFullScreen();
//glutCreateWindow("FBCB2 uMFD 'micro'");
glutDisplayFunc(glutDraw);
glutMotionFunc(glutMotion);
glutPassiveMotionFunc(glutMotion);
glutMouseFunc(glutMouse);
glutIdleFunc(glutIdle);
glutSpecialFunc((void*)keyboardIn);
glutKeyboardFunc((void*)keyboardIn);
glutReshapeFunc(glutResize);
glFrontFace(GL_CCW);
glShadeModel(GL_SMOOTH);
glEnable(GL_CULL_FACE);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
//glDepthMask(GL_TRUE);
//glEnable(GL_NORMALIZE);
//glEnable(GL_COLOR_MATERIAL);
//glEnable(GL_TEXTURE_2D);
glDisable(GL_STENCIL_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_SCISSOR_TEST);
{
GLfloat fSizes[2];
glGetFloatv(GL_SMOOTH_POINT_SIZE_RANGE, fSizes);
fprintf(stderr, "%f %f\n", fSizes[0], fSizes[1]);
}
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
printf("(e)GL engine initialized\n");
return(1);
}
int main(int argc, char *argv[])
{
/* perform graphics initialization here */
if (InitializeGraphics() == 0)
{
fprintf(stderr, "failed to initialize uMfd graphics interace\n");
return(1);
}
/* start up the plugins */
if (uMfdInit(argc, argv, UMFD_CONTEXT_GLUT) == 0)
{
fprintf(stderr, "failed to initialize uMfd plugin interface\n");
fprintf(stderr, "failed to initialize uMfd plugin interface\n");
return(1);
}
/* main render loop if needed */
glutMainLoop();
uMfdFree(c);
/* return success */
return(0);
}
</code>
</MainGlut.c>
<MainWayland.c>
<code>
/*
* Copyright © 2011 Benjamin Franzke
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <assert.h>
#include <signal.h>
#include <linux/input.h>
#include <wayland-client.h>
#include <wayland-egl.h>
#ifdef SIMPLE_EGL
#include <GLES2/gl2.h>
#include <EGL/egl.h>
#else
#include "uMfd.h"
/*
* Core uMfd components
*/
extern UmfdContext masterContext;
extern UmfdContext *c;
int _x=0, _y=0;
#endif
struct window;
struct seat;
struct display {
struct wl_display *display;
struct wl_compositor *compositor;
struct wl_shell *shell;
struct wl_seat *seat;
struct wl_pointer *pointer;
struct wl_keyboard *keyboard;
struct {
EGLDisplay dpy;
EGLContext ctx;
EGLConfig conf;
} egl;
uint32_t mask;
struct window *window;
};
struct geometry {
int width, height;
};
struct window {
struct display *display;
struct geometry geometry, window_size, fullscreen_size;
struct {
GLuint fbo;
GLuint color_rbo;
GLuint rotation_uniform;
GLuint pos;
GLuint col;
} gl;
struct wl_egl_window *native;
struct wl_surface *surface;
struct wl_shell_surface *shell_surface;
EGLSurface egl_surface;
struct wl_callback *callback;
int fullscreen, configured, opaque;
};
#ifdef HAVE_GLESS2
static const char *vert_shader_text =
"uniform mat4 rotation;\n"
"attribute vec4 pos;\n"
"attribute vec4 color;\n"
"varying vec4 v_color;\n"
"void main() {\n"
" gl_Position = rotation * pos;\n"
" v_color = color;\n"
"}\n";
static const char *frag_shader_text =
"precision mediump float;\n"
"varying vec4 v_color;\n"
"void main() {\n"
" gl_FragColor = v_color;\n"
"}\n";
#endif
static int running = 1;
static void
init_egl(struct display *display, int opaque)
{
static const EGLint context_attribs[] = {
#ifdef HAVE_GLES2
EGL_CONTEXT_CLIENT_VERSION, 2,
#endif
EGL_NONE
};
EGLint config_attribs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_ALPHA_SIZE, 1,
#ifdef HAVE_GLES2
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#else
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
#endif
EGL_NONE
};
EGLint major, minor, n;
EGLBoolean ret;
#ifdef SIMPLE_EGL
if (opaque)
config_attribs[9] = 0;
#endif
display->egl.dpy = eglGetDisplay(display->display);
assert(display->egl.dpy);
ret = eglInitialize(display->egl.dpy, &major, &minor);
assert(ret == EGL_TRUE);
#ifdef HAVE_GLES2
ret = eglBindAPI(EGL_OPENGL_ES_API);
#else
ret = eglBindAPI(EGL_OPENGL_API);
#endif
assert(ret == EGL_TRUE);
ret = eglChooseConfig(display->egl.dpy, config_attribs,
&display->egl.conf, 1, &n);
assert(ret && n == 1);
display->egl.ctx = eglCreateContext(display->egl.dpy,
display->egl.conf,
EGL_NO_CONTEXT, context_attribs);
assert(display->egl.ctx);
}
static void
fini_egl(struct display *display)
{
/* Required, otherwise segfault in egl_dri2.c: dri2_make_current()
* on eglReleaseThread(). */
eglMakeCurrent(display->egl.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
EGL_NO_CONTEXT);
eglTerminate(display->egl.dpy);
eglReleaseThread();
}
#ifdef HAVE_GLES2
static GLuint
create_shader(struct window *window, const char *source, GLenum shader_type)
{
GLuint shader;
GLint status;
shader = glCreateShader(shader_type);
assert(shader != 0);
glShaderSource(shader, 1, (const char **) &source, NULL);
glCompileShader(shader);
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if (!status) {
char log[1000];
GLsizei len;
glGetShaderInfoLog(shader, 1000, &len, log);
fprintf(stderr, "Error: compiling %s: %*s\n",
shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment",
len, log);
exit(1);
}
return shader;
}
#endif
#ifdef HAVE_GLES2
static void
init_gl(struct window *window)
{
GLuint frag, vert;
GLuint program;
GLint status;
frag = create_shader(window, frag_shader_text, GL_FRAGMENT_SHADER);
vert = create_shader(window, vert_shader_text, GL_VERTEX_SHADER);
program = glCreateProgram();
glAttachShader(program, frag);
glAttachShader(program, vert);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &status);
if (!status) {
char log[1000];
GLsizei len;
glGetProgramInfoLog(program, 1000, &len, log);
fprintf(stderr, "Error: linking:\n%*s\n", len, log);
exit(1);
}
glUseProgram(program);
window->gl.pos = 0;
window->gl.col = 1;
glBindAttribLocation(program, window->gl.pos, "pos");
glBindAttribLocation(program, window->gl.col, "color");
glLinkProgram(program);
window->gl.rotation_uniform =
glGetUniformLocation(program, "rotation");
}
#endif
static void
handle_ping(void *data, struct wl_shell_surface *shell_surface,
uint32_t serial)
{
fprintf(stderr, "MainWayland: handle_ping\n");
wl_shell_surface_pong(shell_surface, serial);
}
static void
handle_configure(void *data, struct wl_shell_surface *shell_surface,
uint32_t edges, int32_t width, int32_t height)
{
struct window *window = data;
fprintf(stderr, "MainWayland: handle_configure\n");
if (window->native)
wl_egl_window_resize(window->native, width, height, 0, 0);
window->geometry.width = width;
window->geometry.height = height;
if (window->fullscreen)
window->fullscreen_size = window->geometry;
else
window->window_size = window->geometry;
}
static void
handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
{
fprintf(stderr, "MainWayland: handle_popup_done\n");
}
static const struct wl_shell_surface_listener shell_surface_listener = {
handle_ping,
handle_configure,
handle_popup_done
};
static void
redraw(void *data, struct wl_callback *callback, uint32_t time);
static void
configure_callback(void *data, struct wl_callback *callback, uint32_t time)
{
struct window *window = data;
fprintf(stderr, "MainWayland: configure_callback\n");
wl_callback_destroy(callback);
window->configured = 1;
redraw(data, NULL, time);
}
static struct wl_callback_listener configure_callback_listener = {
configure_callback,
};
static void
toggle_fullscreen(struct window *window, int fullscreen)
{
struct wl_callback *callback;
fprintf(stderr, "MainWayland: toggle_fullscreen\n");
window->fullscreen = fullscreen;
window->configured = 0;
if (fullscreen) {
wl_shell_surface_set_fullscreen(window->shell_surface,
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
0, NULL);
} else {
wl_shell_surface_set_toplevel(window->shell_surface);
handle_configure(window, window->shell_surface, 0,
window->window_size.width,
window->window_size.height);
}
callback = wl_display_sync(window->display->display);
wl_callback_add_listener(callback, &configure_callback_listener,
window);
}
static void
create_surface(struct window *window)
{
struct display *display = window->display;
EGLBoolean ret;
fprintf(stderr, "MainWayland: create_surface\n");
window->surface = wl_compositor_create_surface(display->compositor);
window->shell_surface = wl_shell_get_shell_surface(display->shell,
window->surface);
wl_shell_surface_add_listener(window->shell_surface,
&shell_surface_listener, window);
window->native =
wl_egl_window_create(window->surface,
window->window_size.width,
window->window_size.height);
window->egl_surface =
eglCreateWindowSurface(display->egl.dpy,
display->egl.conf,
window->native, NULL);
ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface,
window->egl_surface, window->display->egl.ctx);
assert(ret == EGL_TRUE);
toggle_fullscreen(window, window->fullscreen);
}
static void
destroy_surface(struct window *window)
{
fprintf(stderr, "MainWayland: destroy_surface\n");
wl_egl_window_destroy(window->native);
wl_shell_surface_destroy(window->shell_surface);
wl_surface_destroy(window->surface);
if (window->callback)
wl_callback_destroy(window->callback);
}
static const struct wl_callback_listener frame_listener;
static void
redraw(void *data, struct wl_callback *callback, uint32_t time)
{
struct window *window = data;
#ifdef SIMPLE_EGL
static const GLfloat verts[3][2] = {
{ -0.5, -0.5 },
{ 0.5, -0.5 },
{ 0, 0.5 }
};
static const GLfloat colors[3][3] = {
{ 1, 0, 0 },
{ 0, 1, 0 },
{ 0, 0, 1 }
};
GLfloat angle;
GLfloat rotation[4][4] = {
{ 1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 0, 1 }
};
static const int32_t speed_div = 5;
static uint32_t start_time = 0;
#endif
struct wl_region *region;
if (callback)
wl_callback_destroy(callback);
#ifndef SIMPLE_EGL
if (window)
#endif
if (!window->configured)
return;
#ifdef SIMPLE_EGL
if (start_time == 0)
start_time = time;
angle = ((time-start_time) / speed_div) % 360 * M_PI / 180.0;
rotation[0][0] = cos(angle);
rotation[0][2] = sin(angle);
rotation[2][0] = -sin(angle);
rotation[2][2] = cos(angle);
glViewport(0, 0, window->geometry.width, window->geometry.height);
glUniformMatrix4fv(window->gl.rotation_uniform, 1, GL_FALSE,
(GLfloat *) rotation);
glClearColor(0.0, 0.0, 0.0, 0.5);
glClear(GL_COLOR_BUFFER_BIT);
glVertexAttribPointer(window->gl.pos, 2, GL_FLOAT, GL_FALSE, 0, verts);
glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors);
glEnableVertexAttribArray(window->gl.pos);
glEnableVertexAttribArray(window->gl.col);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(window->gl.pos);
glDisableVertexAttribArray(window->gl.col);
#else
uMfdDraw(c);
#endif
eglSwapBuffers(window->display->egl.dpy, window->egl_surface);
#ifdef SIMPLE_EGL
if (window->opaque) {
region =
wl_compositor_create_region(window->display->compositor);
wl_region_add(region, 0, 0,
window->window_size.width,
window->window_size.height);
wl_surface_set_opaque_region(window->surface, region);
wl_region_destroy(region);
}
#endif
#ifndef SIMPLE_EGL
if (window)
{
#endif
window->callback = wl_surface_frame(window->surface);
wl_callback_add_listener(window->callback, &frame_listener, window);
#ifndef SIMPLE_EGL
}
#endif
}
static const struct wl_callback_listener frame_listener = {
redraw
};
static void
pointer_handle_enter(void *data, struct wl_pointer *pointer,
uint32_t serial, struct wl_surface *surface,
wl_fixed_t sx, wl_fixed_t sy)
{
struct display *display = data;
fprintf(stderr, "MainWayland: pointer_handle_enter\n");
if (display->window->fullscreen)
wl_pointer_set_cursor(pointer, serial, NULL, 0, 0);
}
static void
pointer_handle_leave(void *data, struct wl_pointer *pointer,
uint32_t serial, struct wl_surface *surface)
{
fprintf(stderr, "MainWayland: pointer_handle_leave\n");
}
static void
pointer_handle_motion(void *data, struct wl_pointer *pointer,
uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
{
#ifndef SIMPLE_EGL
_x=sx/256;
_y=sy/256;
c->controller->event(c, drag, _x, _y);
#endif
}
static void
pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, uint32_t time, uint32_t button,
uint32_t state)
{
#ifndef SIMPLE_EGL
if (button == BTN_LEFT)
{
if (state == WL_POINTER_BUTTON_STATE_PRESSED)
c->controller->event(c, leftDown, _x, _y);
else
c->controller->event(c, leftUp, _x, _y);
}
else if (button == BTN_RIGHT)
{
if (state == WL_POINTER_BUTTON_STATE_PRESSED)
c->controller->event(c, rightDown, _x, _y);
else
c->controller->event(c, rightUp, _x, _y);
}
#else
struct display *display = data;
if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED)
wl_shell_surface_move(display->window->shell_surface,
display->seat, serial);
#endif
}
static void
pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis, wl_fixed_t value)
{
fprintf(stderr, "MainWayland: pointer_handle_axis\n");
}
static const struct wl_pointer_listener pointer_listener = {
pointer_handle_enter,
pointer_handle_leave,
pointer_handle_motion,
pointer_handle_button,
pointer_handle_axis,
};
static void
keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
uint32_t format, int fd, uint32_t size)
{
fprintf(stderr, "MainWayland: keyboard_handle_keymap\n");
}
static void
keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
uint32_t serial, struct wl_surface *surface,
struct wl_array *keys)
{
fprintf(stderr, "MainWayland: keyboard_handle_enter\n");
}
static void
keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
uint32_t serial, struct wl_surface *surface)
{
fprintf(stderr, "MainWayland: keyboard_handle_leave\n");
}
static void
keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
uint32_t serial, uint32_t time, uint32_t key,
uint32_t state)
{
struct display *d = data;
fprintf(stderr, "MainWayland: keyboard_handle_key\n");
if (key == KEY_F11 && state)
toggle_fullscreen(d->window, d->window->fullscreen ^ 1);
else if (key == KEY_ESC && state)
#ifdef SIMPLE_EGL
running = 0;
#else
c->controller->event(c, menu, 0, 0);
else if (key == KEY_UP && state)
c->controller->event(c, upArrow, 0, 0);
else if (key == KEY_RIGHT && state)
c->controller->event(c, rightArrow, 0, 0);
else if (key == KEY_LEFT && state)
c->controller->event(c, leftArrow, 0, 0);
else if (key == KEY_DOWN && state)
c->controller->event(c, downArrow, 0, 0);
else if (key == KEY_ENTER && state)
c->controller->event(c, menuSelect, 0, 0);
else if (key == KEY_SPACE && state)
c->controller->event(c, menuSelect, 0, 0);
#endif
}
static void
keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
uint32_t serial, uint32_t mods_depressed,
uint32_t mods_latched, uint32_t mods_locked,
uint32_t group)
{
fprintf(stderr, "MainWayland: keyboard_handle_modifiers\n");
}
static const struct wl_keyboard_listener keyboard_listener = {
keyboard_handle_keymap,
keyboard_handle_enter,
keyboard_handle_leave,
keyboard_handle_key,
keyboard_handle_modifiers,
};
static void
seat_handle_capabilities(void *data, struct wl_seat *seat,
enum wl_seat_capability caps)
{
struct display *d = data;
if ((caps & WL_SEAT_CAPABILITY_POINTER) && !d->pointer) {
d->pointer = wl_seat_get_pointer(seat);
wl_pointer_add_listener(d->pointer, &pointer_listener, d);
} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && d->pointer) {
wl_pointer_destroy(d->pointer);
d->pointer = NULL;
}
if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !d->keyboard) {
d->keyboard = wl_seat_get_keyboard(seat);
wl_keyboard_add_listener(d->keyboard, &keyboard_listener, d);
} else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && d->keyboard) {
wl_keyboard_destroy(d->keyboard);
d->keyboard = NULL;
}
}
static const struct wl_seat_listener seat_listener = {
seat_handle_capabilities,
};
static void
display_handle_global(struct wl_display *display, uint32_t id,
const char *interface, uint32_t version, void *data)
{
struct display *d = data;
if (strcmp(interface, "wl_compositor") == 0) {
d->compositor =
wl_display_bind(display, id, &wl_compositor_interface);
} else if (strcmp(interface, "wl_shell") == 0) {
d->shell = wl_display_bind(display, id, &wl_shell_interface);
} else if (strcmp(interface, "wl_seat") == 0) {
d->seat = wl_display_bind(d->display, id, &wl_seat_interface);
wl_seat_add_listener(d->seat, &seat_listener, d);
}
}
static int
event_mask_update(uint32_t mask, void *data)
{
struct display *d = data;
d->mask = mask;
return 0;
}
#ifdef SIMPLE_EGL
static void
signal_int(int signum)
{
running = 0;
}
#endif
static void
usage(int error_code)
{
fprintf(stderr, "MainWayland: Usage: simple-egl [OPTIONS]\n\n"
" -f\tRun in fullscreen mode\n"
" -o\tCreate an opaque surface\n"
" -h\tThis help text\n\n");
exit(error_code);
}
int
main(int argc, char **argv)
{
#ifdef SIMPLE_EGL
struct sigaction sigint;
#endif
struct display display = { 0 };
struct window window = { 0 };
int i;
window.display = &display;
display.window = &window;
#ifdef SIMPLE_EGL
window.window_size.width = 250;
window.window_size.height = 250;
#else
window.window_size.width = WIDTH;
window.window_size.height = HEIGHT;
#endif
for (i = 1; i < argc; i++) {
if (strcmp("-f", argv[i]) == 0)
window.fullscreen = 1;
else if (strcmp("-o", argv[i]) == 0)
window.opaque = 1;
else if (strcmp("-h", argv[i]) == 0)
usage(EXIT_SUCCESS);
else
usage(EXIT_FAILURE);
}
display.display = wl_display_connect(NULL);
assert(display.display);
wl_display_add_global_listener(display.display,
display_handle_global, &display);
wl_display_get_fd(display.display, event_mask_update, &display);
wl_display_iterate(display.display, WL_DISPLAY_READABLE);
if (window.fullscreen)
window.opaque = 1;
init_egl(&display, window.opaque);
create_surface(&window);
#ifdef HAVE_GLES2
init_gl(&window);
#endif
#ifdef SIMPLE_EGL
sigint.sa_handler = signal_int;
sigemptyset(&sigint.sa_mask);
sigint.sa_flags = SA_RESETHAND;
sigaction(SIGINT, &sigint, NULL);
#else
uMfdInit(0, NULL, UMFD_CONTEXT_WAYLAND);
#endif
while (running)
wl_display_iterate(display.display, display.mask);
fprintf(stderr, "simple-egl exiting\n");
destroy_surface(&window);
fini_egl(&display);
if (display.shell)
wl_shell_destroy(display.shell);
if (display.compositor)
wl_compositor_destroy(display.compositor);
wl_display_flush(display.display);
wl_display_disconnect(display.display);
return 0;
}
</code>
</MainWayland.c>
More information about the wayland-devel
mailing list