2011-01-15 02:40:17 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-04-07 15:40:35 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <assert.h>
|
2011-12-13 14:09:09 +04:00
|
|
|
#include <signal.h>
|
2011-01-15 02:40:17 +03:00
|
|
|
|
2012-06-26 18:09:11 +04:00
|
|
|
#include <linux/input.h>
|
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
#include <wayland-client.h>
|
2011-02-04 23:31:33 +03:00
|
|
|
#include <wayland-egl.h>
|
2012-10-30 01:41:46 +04:00
|
|
|
#include <wayland-cursor.h>
|
2011-01-15 02:40:17 +03:00
|
|
|
|
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#include <EGL/egl.h>
|
2013-05-08 19:37:28 +04:00
|
|
|
#include <EGL/eglext.h>
|
|
|
|
|
2014-02-08 05:01:57 +04:00
|
|
|
#include "xdg-shell-client-protocol.h"
|
2014-11-27 07:24:42 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "protocol/ivi-application-client-protocol.h"
|
|
|
|
#define IVI_SURFACE_ID 9000
|
2014-02-08 05:01:57 +04:00
|
|
|
|
2015-03-20 17:26:51 +03:00
|
|
|
#include "../shared/platform.h"
|
|
|
|
|
2013-05-08 19:37:28 +04:00
|
|
|
#ifndef EGL_EXT_swap_buffers_with_damage
|
|
|
|
#define EGL_EXT_swap_buffers_with_damage 1
|
|
|
|
typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC)(EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
|
|
|
|
#endif
|
2011-01-15 02:40:17 +03:00
|
|
|
|
2013-08-22 23:16:51 +04:00
|
|
|
#ifndef EGL_EXT_buffer_age
|
|
|
|
#define EGL_EXT_buffer_age 1
|
|
|
|
#define EGL_BUFFER_AGE_EXT 0x313D
|
|
|
|
#endif
|
|
|
|
|
2012-05-02 17:42:23 +04:00
|
|
|
struct window;
|
2012-05-16 21:45:18 +04:00
|
|
|
struct seat;
|
2012-05-02 17:42:23 +04:00
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
struct display {
|
|
|
|
struct wl_display *display;
|
2012-10-11 05:34:26 +04:00
|
|
|
struct wl_registry *registry;
|
2011-02-04 23:31:33 +03:00
|
|
|
struct wl_compositor *compositor;
|
2014-02-08 05:01:57 +04:00
|
|
|
struct xdg_shell *shell;
|
2012-05-17 00:16:19 +04:00
|
|
|
struct wl_seat *seat;
|
|
|
|
struct wl_pointer *pointer;
|
2013-08-15 20:10:08 +04:00
|
|
|
struct wl_touch *touch;
|
2012-07-27 18:18:13 +04:00
|
|
|
struct wl_keyboard *keyboard;
|
2012-10-30 01:41:46 +04:00
|
|
|
struct wl_shm *shm;
|
|
|
|
struct wl_cursor_theme *cursor_theme;
|
|
|
|
struct wl_cursor *default_cursor;
|
|
|
|
struct wl_surface *cursor_surface;
|
2011-01-15 02:40:17 +03:00
|
|
|
struct {
|
|
|
|
EGLDisplay dpy;
|
|
|
|
EGLContext ctx;
|
2011-02-04 23:31:33 +03:00
|
|
|
EGLConfig conf;
|
2011-01-15 02:40:17 +03:00
|
|
|
} egl;
|
2012-05-02 17:42:23 +04:00
|
|
|
struct window *window;
|
2014-11-27 07:24:42 +03:00
|
|
|
struct ivi_application *ivi_application;
|
2013-05-08 19:37:28 +04:00
|
|
|
|
|
|
|
PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC swap_buffers_with_damage;
|
2011-01-15 02:40:17 +03:00
|
|
|
};
|
|
|
|
|
2012-07-27 18:18:13 +04:00
|
|
|
struct geometry {
|
|
|
|
int width, height;
|
|
|
|
};
|
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
struct window {
|
|
|
|
struct display *display;
|
2012-08-31 00:44:15 +04:00
|
|
|
struct geometry geometry, window_size;
|
2011-01-15 02:40:17 +03:00
|
|
|
struct {
|
|
|
|
GLuint rotation_uniform;
|
|
|
|
GLuint pos;
|
|
|
|
GLuint col;
|
|
|
|
} gl;
|
2011-02-04 23:31:33 +03:00
|
|
|
|
2013-12-07 10:02:45 +04:00
|
|
|
uint32_t benchmark_time, frames;
|
2011-02-04 23:31:33 +03:00
|
|
|
struct wl_egl_window *native;
|
|
|
|
struct wl_surface *surface;
|
2014-02-08 05:01:57 +04:00
|
|
|
struct xdg_surface *xdg_surface;
|
2014-11-27 07:24:42 +03:00
|
|
|
struct ivi_surface *ivi_surface;
|
2011-02-04 23:31:33 +03:00
|
|
|
EGLSurface egl_surface;
|
2011-12-13 16:50:25 +04:00
|
|
|
struct wl_callback *callback;
|
2014-02-09 03:29:49 +04:00
|
|
|
int fullscreen, opaque, buffer_size, frame_sync;
|
2011-01-15 02:40:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
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 =
|
2011-01-15 04:39:21 +03:00
|
|
|
"precision mediump float;\n"
|
2011-01-15 02:40:17 +03:00
|
|
|
"varying vec4 v_color;\n"
|
|
|
|
"void main() {\n"
|
|
|
|
" gl_FragColor = v_color;\n"
|
|
|
|
"}\n";
|
|
|
|
|
2012-07-30 23:40:57 +04:00
|
|
|
static int running = 1;
|
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
static void
|
2013-10-16 09:03:31 +04:00
|
|
|
init_egl(struct display *display, struct window *window)
|
2011-01-15 02:40:17 +03:00
|
|
|
{
|
2011-01-15 04:39:21 +03:00
|
|
|
static const EGLint context_attribs[] = {
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
2013-05-08 19:37:28 +04:00
|
|
|
const char *extensions;
|
2011-01-15 04:39:21 +03:00
|
|
|
|
2012-05-02 17:42:23 +04:00
|
|
|
EGLint config_attribs[] = {
|
2012-01-11 23:24:46 +04:00
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
2011-02-04 23:31:33 +03:00
|
|
|
EGL_RED_SIZE, 1,
|
|
|
|
EGL_GREEN_SIZE, 1,
|
|
|
|
EGL_BLUE_SIZE, 1,
|
2014-08-25 22:56:48 +04:00
|
|
|
EGL_ALPHA_SIZE, 1,
|
2011-02-04 23:31:33 +03:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
2013-10-16 09:03:31 +04:00
|
|
|
EGLint major, minor, n, count, i, size;
|
|
|
|
EGLConfig *configs;
|
2011-01-15 02:40:17 +03:00
|
|
|
EGLBoolean ret;
|
|
|
|
|
2013-10-16 09:03:31 +04:00
|
|
|
if (window->opaque || window->buffer_size == 16)
|
2012-08-03 23:27:14 +04:00
|
|
|
config_attribs[9] = 0;
|
|
|
|
|
2015-03-20 17:26:51 +03:00
|
|
|
display->egl.dpy =
|
|
|
|
weston_platform_get_egl_display(EGL_PLATFORM_WAYLAND_KHR,
|
|
|
|
display->display, NULL);
|
2011-01-15 02:40:17 +03:00
|
|
|
assert(display->egl.dpy);
|
|
|
|
|
|
|
|
ret = eglInitialize(display->egl.dpy, &major, &minor);
|
|
|
|
assert(ret == EGL_TRUE);
|
2011-01-15 04:39:21 +03:00
|
|
|
ret = eglBindAPI(EGL_OPENGL_ES_API);
|
2011-01-15 02:40:17 +03:00
|
|
|
assert(ret == EGL_TRUE);
|
|
|
|
|
2013-10-16 09:03:31 +04:00
|
|
|
if (!eglGetConfigs(display->egl.dpy, NULL, 0, &count) || count < 1)
|
|
|
|
assert(0);
|
|
|
|
|
|
|
|
configs = calloc(count, sizeof *configs);
|
|
|
|
assert(configs);
|
|
|
|
|
2012-06-12 18:42:24 +04:00
|
|
|
ret = eglChooseConfig(display->egl.dpy, config_attribs,
|
2013-10-16 09:03:31 +04:00
|
|
|
configs, count, &n);
|
|
|
|
assert(ret && n >= 1);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
eglGetConfigAttrib(display->egl.dpy,
|
|
|
|
configs[i], EGL_BUFFER_SIZE, &size);
|
|
|
|
if (window->buffer_size == size) {
|
|
|
|
display->egl.conf = configs[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(configs);
|
|
|
|
if (display->egl.conf == NULL) {
|
|
|
|
fprintf(stderr, "did not find config with buffer size %d\n",
|
|
|
|
window->buffer_size);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2011-02-04 23:31:33 +03:00
|
|
|
|
|
|
|
display->egl.ctx = eglCreateContext(display->egl.dpy,
|
|
|
|
display->egl.conf,
|
2011-01-15 04:39:21 +03:00
|
|
|
EGL_NO_CONTEXT, context_attribs);
|
2011-01-15 02:40:17 +03:00
|
|
|
assert(display->egl.ctx);
|
2011-02-04 23:31:33 +03:00
|
|
|
|
2013-05-08 19:37:28 +04:00
|
|
|
display->swap_buffers_with_damage = NULL;
|
|
|
|
extensions = eglQueryString(display->egl.dpy, EGL_EXTENSIONS);
|
|
|
|
if (extensions &&
|
|
|
|
strstr(extensions, "EGL_EXT_swap_buffers_with_damage") &&
|
|
|
|
strstr(extensions, "EGL_EXT_buffer_age"))
|
|
|
|
display->swap_buffers_with_damage =
|
|
|
|
(PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC)
|
|
|
|
eglGetProcAddress("eglSwapBuffersWithDamageEXT");
|
|
|
|
|
|
|
|
if (display->swap_buffers_with_damage)
|
|
|
|
printf("has EGL_EXT_buffer_age and EGL_EXT_swap_buffers_with_damage\n");
|
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
}
|
|
|
|
|
2011-12-13 16:50:25 +04:00
|
|
|
static void
|
|
|
|
fini_egl(struct display *display)
|
|
|
|
{
|
|
|
|
eglTerminate(display->egl.dpy);
|
|
|
|
eglReleaseThread();
|
|
|
|
}
|
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_gl(struct window *window)
|
|
|
|
{
|
|
|
|
GLuint frag, vert;
|
2012-06-14 03:42:21 +04:00
|
|
|
GLuint program;
|
2011-01-15 02:40:17 +03:00
|
|
|
GLint status;
|
|
|
|
|
|
|
|
frag = create_shader(window, frag_shader_text, GL_FRAGMENT_SHADER);
|
|
|
|
vert = create_shader(window, vert_shader_text, GL_VERTEX_SHADER);
|
|
|
|
|
2012-06-14 03:42:21 +04:00
|
|
|
program = glCreateProgram();
|
|
|
|
glAttachShader(program, frag);
|
|
|
|
glAttachShader(program, vert);
|
|
|
|
glLinkProgram(program);
|
2011-01-15 02:40:17 +03:00
|
|
|
|
2012-06-14 03:42:21 +04:00
|
|
|
glGetProgramiv(program, GL_LINK_STATUS, &status);
|
2011-01-15 02:40:17 +03:00
|
|
|
if (!status) {
|
|
|
|
char log[1000];
|
|
|
|
GLsizei len;
|
2012-06-14 03:42:21 +04:00
|
|
|
glGetProgramInfoLog(program, 1000, &len, log);
|
2011-01-15 02:40:17 +03:00
|
|
|
fprintf(stderr, "Error: linking:\n%*s\n", len, log);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-06-14 03:42:21 +04:00
|
|
|
glUseProgram(program);
|
2014-11-27 07:24:42 +03:00
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
window->gl.pos = 0;
|
2012-06-14 03:42:21 +04:00
|
|
|
window->gl.col = 1;
|
2011-01-15 02:40:17 +03:00
|
|
|
|
2012-06-14 03:42:21 +04:00
|
|
|
glBindAttribLocation(program, window->gl.pos, "pos");
|
|
|
|
glBindAttribLocation(program, window->gl.col, "color");
|
|
|
|
glLinkProgram(program);
|
2011-01-15 02:40:17 +03:00
|
|
|
|
|
|
|
window->gl.rotation_uniform =
|
2012-06-14 03:42:21 +04:00
|
|
|
glGetUniformLocation(program, "rotation");
|
2011-01-15 02:40:17 +03:00
|
|
|
}
|
|
|
|
|
2012-05-02 17:42:23 +04:00
|
|
|
static void
|
2014-02-08 05:01:57 +04:00
|
|
|
handle_surface_configure(void *data, struct xdg_surface *surface,
|
2014-04-10 21:41:46 +04:00
|
|
|
int32_t width, int32_t height,
|
|
|
|
struct wl_array *states, uint32_t serial)
|
2012-05-02 17:42:23 +04:00
|
|
|
{
|
|
|
|
struct window *window = data;
|
2014-04-10 21:41:46 +04:00
|
|
|
uint32_t *p;
|
|
|
|
|
|
|
|
window->fullscreen = 0;
|
|
|
|
wl_array_for_each(p, states) {
|
|
|
|
uint32_t state = *p;
|
|
|
|
switch (state) {
|
|
|
|
case XDG_SURFACE_STATE_FULLSCREEN:
|
|
|
|
window->fullscreen = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-05-02 17:42:23 +04:00
|
|
|
|
2014-04-10 21:41:46 +04:00
|
|
|
if (width > 0 && height > 0) {
|
|
|
|
if (!window->fullscreen) {
|
|
|
|
window->window_size.width = width;
|
|
|
|
window->window_size.height = height;
|
|
|
|
}
|
|
|
|
window->geometry.width = width;
|
|
|
|
window->geometry.height = height;
|
|
|
|
} else if (!window->fullscreen) {
|
|
|
|
window->geometry = window->window_size;
|
2014-02-09 03:29:49 +04:00
|
|
|
}
|
2014-02-08 05:01:57 +04:00
|
|
|
|
2014-04-10 21:41:46 +04:00
|
|
|
if (window->native)
|
|
|
|
wl_egl_window_resize(window->native,
|
|
|
|
window->geometry.width,
|
|
|
|
window->geometry.height, 0, 0);
|
|
|
|
|
|
|
|
xdg_surface_ack_configure(surface, serial);
|
2014-02-08 05:01:57 +04:00
|
|
|
}
|
|
|
|
|
2014-02-09 03:31:10 +04:00
|
|
|
static void
|
|
|
|
handle_surface_delete(void *data, struct xdg_surface *xdg_surface)
|
|
|
|
{
|
|
|
|
running = 0;
|
|
|
|
}
|
|
|
|
|
2014-02-08 05:01:57 +04:00
|
|
|
static const struct xdg_surface_listener xdg_surface_listener = {
|
|
|
|
handle_surface_configure,
|
2014-02-09 03:31:10 +04:00
|
|
|
handle_surface_delete,
|
2012-05-02 17:42:23 +04:00
|
|
|
};
|
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
static void
|
2014-11-27 07:24:42 +03:00
|
|
|
handle_ivi_surface_configure(void *data, struct ivi_surface *ivi_surface,
|
|
|
|
int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
struct window *window = data;
|
|
|
|
|
|
|
|
wl_egl_window_resize(window->native, width, height, 0, 0);
|
|
|
|
|
|
|
|
window->geometry.width = width;
|
|
|
|
window->geometry.height = height;
|
|
|
|
|
|
|
|
if (!window->fullscreen)
|
|
|
|
window->window_size = window->geometry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ivi_surface_listener ivi_surface_listener = {
|
|
|
|
handle_ivi_surface_configure,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_xdg_surface(struct window *window, struct display *display)
|
2011-01-15 02:40:17 +03:00
|
|
|
{
|
2014-02-08 05:01:57 +04:00
|
|
|
window->xdg_surface = xdg_shell_get_xdg_surface(display->shell,
|
|
|
|
window->surface);
|
2012-05-02 17:42:23 +04:00
|
|
|
|
2014-02-08 05:01:57 +04:00
|
|
|
xdg_surface_add_listener(window->xdg_surface,
|
|
|
|
&xdg_surface_listener, window);
|
2012-05-02 17:42:23 +04:00
|
|
|
|
2014-11-27 07:24:42 +03:00
|
|
|
xdg_surface_set_title(window->xdg_surface, "simple-egl");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_ivi_surface(struct window *window, struct display *display)
|
|
|
|
{
|
|
|
|
uint32_t id_ivisurf = IVI_SURFACE_ID + (uint32_t)getpid();
|
|
|
|
window->ivi_surface =
|
|
|
|
ivi_application_surface_create(display->ivi_application,
|
|
|
|
id_ivisurf, window->surface);
|
|
|
|
|
|
|
|
if (window->ivi_surface == NULL) {
|
|
|
|
fprintf(stderr, "Failed to create ivi_client_surface\n");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
ivi_surface_add_listener(window->ivi_surface,
|
|
|
|
&ivi_surface_listener, window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_surface(struct window *window)
|
|
|
|
{
|
|
|
|
struct display *display = window->display;
|
|
|
|
EGLBoolean ret;
|
|
|
|
|
|
|
|
window->surface = wl_compositor_create_surface(display->compositor);
|
|
|
|
|
2011-02-04 23:31:33 +03:00
|
|
|
window->native =
|
2011-04-14 22:44:58 +04:00
|
|
|
wl_egl_window_create(window->surface,
|
2014-04-10 21:41:46 +04:00
|
|
|
window->geometry.width,
|
|
|
|
window->geometry.height);
|
2011-02-04 23:31:33 +03:00
|
|
|
window->egl_surface =
|
2015-03-24 15:12:09 +03:00
|
|
|
weston_platform_create_egl_surface(display->egl.dpy,
|
|
|
|
display->egl.conf,
|
|
|
|
window->native, NULL);
|
2015-03-20 17:26:53 +03:00
|
|
|
|
2011-02-04 23:31:33 +03:00
|
|
|
|
2014-11-27 07:24:42 +03:00
|
|
|
if (display->shell) {
|
|
|
|
create_xdg_surface(window, display);
|
|
|
|
} else if (display->ivi_application ) {
|
|
|
|
create_ivi_surface(window, display);
|
|
|
|
} else {
|
|
|
|
assert(0);
|
|
|
|
}
|
2012-10-07 18:56:30 +04:00
|
|
|
|
2011-02-04 23:31:33 +03:00
|
|
|
ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface,
|
|
|
|
window->egl_surface, window->display->egl.ctx);
|
|
|
|
assert(ret == EGL_TRUE);
|
2012-07-27 18:18:13 +04:00
|
|
|
|
2013-12-08 10:25:56 +04:00
|
|
|
if (!window->frame_sync)
|
|
|
|
eglSwapInterval(display->egl.dpy, 0);
|
|
|
|
|
2014-11-27 07:24:42 +03:00
|
|
|
if (!display->shell)
|
|
|
|
return;
|
|
|
|
|
2014-04-10 21:41:46 +04:00
|
|
|
if (window->fullscreen)
|
|
|
|
xdg_surface_set_fullscreen(window->xdg_surface, NULL);
|
2011-01-15 02:40:17 +03:00
|
|
|
}
|
|
|
|
|
2011-12-13 16:50:25 +04:00
|
|
|
static void
|
|
|
|
destroy_surface(struct window *window)
|
|
|
|
{
|
2013-04-19 21:49:12 +04:00
|
|
|
/* Required, otherwise segfault in egl_dri2.c: dri2_make_current()
|
|
|
|
* on eglReleaseThread(). */
|
|
|
|
eglMakeCurrent(window->display->egl.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
|
|
|
|
eglDestroySurface(window->display->egl.dpy, window->egl_surface);
|
2011-12-13 16:50:25 +04:00
|
|
|
wl_egl_window_destroy(window->native);
|
|
|
|
|
2014-11-27 07:24:42 +03:00
|
|
|
if (window->xdg_surface)
|
|
|
|
xdg_surface_destroy(window->xdg_surface);
|
|
|
|
if (window->display->ivi_application)
|
|
|
|
ivi_surface_destroy(window->ivi_surface);
|
2011-12-13 16:50:25 +04:00
|
|
|
wl_surface_destroy(window->surface);
|
|
|
|
|
|
|
|
if (window->callback)
|
|
|
|
wl_callback_destroy(window->callback);
|
|
|
|
}
|
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
static void
|
2011-08-17 07:01:28 +04:00
|
|
|
redraw(void *data, struct wl_callback *callback, uint32_t time)
|
2011-01-15 02:40:17 +03:00
|
|
|
{
|
|
|
|
struct window *window = data;
|
2013-05-08 19:37:28 +04:00
|
|
|
struct display *display = window->display;
|
2011-01-15 02:40:17 +03:00
|
|
|
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 }
|
|
|
|
};
|
2014-01-03 22:46:50 +04:00
|
|
|
static const uint32_t speed_div = 5, benchmark_interval = 5;
|
2012-08-03 23:27:14 +04:00
|
|
|
struct wl_region *region;
|
2013-05-08 19:37:28 +04:00
|
|
|
EGLint rect[4];
|
|
|
|
EGLint buffer_age = 0;
|
2013-12-07 10:02:45 +04:00
|
|
|
struct timeval tv;
|
2011-01-15 02:40:17 +03:00
|
|
|
|
2012-08-31 13:18:15 +04:00
|
|
|
assert(window->callback == callback);
|
|
|
|
window->callback = NULL;
|
|
|
|
|
2012-07-27 18:18:13 +04:00
|
|
|
if (callback)
|
|
|
|
wl_callback_destroy(callback);
|
|
|
|
|
2013-12-07 10:02:45 +04:00
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
|
|
|
if (window->frames == 0)
|
|
|
|
window->benchmark_time = time;
|
|
|
|
if (time - window->benchmark_time > (benchmark_interval * 1000)) {
|
|
|
|
printf("%d frames in %d seconds: %f fps\n",
|
|
|
|
window->frames,
|
|
|
|
benchmark_interval,
|
|
|
|
(float) window->frames / benchmark_interval);
|
|
|
|
window->benchmark_time = time;
|
|
|
|
window->frames = 0;
|
|
|
|
}
|
2011-01-15 02:40:17 +03:00
|
|
|
|
2013-12-07 10:02:45 +04:00
|
|
|
angle = (time / speed_div) % 360 * M_PI / 180.0;
|
2011-01-15 02:40:17 +03:00
|
|
|
rotation[0][0] = cos(angle);
|
|
|
|
rotation[0][2] = sin(angle);
|
|
|
|
rotation[2][0] = -sin(angle);
|
|
|
|
rotation[2][2] = cos(angle);
|
|
|
|
|
2013-05-08 19:37:28 +04:00
|
|
|
if (display->swap_buffers_with_damage)
|
|
|
|
eglQuerySurface(display->egl.dpy, window->egl_surface,
|
|
|
|
EGL_BUFFER_AGE_EXT, &buffer_age);
|
|
|
|
|
2012-07-27 18:18:13 +04:00
|
|
|
glViewport(0, 0, window->geometry.width, window->geometry.height);
|
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
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);
|
|
|
|
|
2012-09-10 16:55:53 +04:00
|
|
|
if (window->opaque || window->fullscreen) {
|
2012-08-03 23:27:14 +04:00
|
|
|
region = wl_compositor_create_region(window->display->compositor);
|
|
|
|
wl_region_add(region, 0, 0,
|
2012-09-07 18:32:16 +04:00
|
|
|
window->geometry.width,
|
|
|
|
window->geometry.height);
|
2012-08-03 23:27:14 +04:00
|
|
|
wl_surface_set_opaque_region(window->surface, region);
|
|
|
|
wl_region_destroy(region);
|
2012-11-20 01:17:52 +04:00
|
|
|
} else {
|
|
|
|
wl_surface_set_opaque_region(window->surface, NULL);
|
2012-08-03 23:27:14 +04:00
|
|
|
}
|
|
|
|
|
2013-05-08 19:37:28 +04:00
|
|
|
if (display->swap_buffers_with_damage && buffer_age > 0) {
|
|
|
|
rect[0] = window->geometry.width / 4 - 1;
|
|
|
|
rect[1] = window->geometry.height / 4 - 1;
|
|
|
|
rect[2] = window->geometry.width / 2 + 2;
|
|
|
|
rect[3] = window->geometry.height / 2 + 2;
|
|
|
|
display->swap_buffers_with_damage(display->egl.dpy,
|
|
|
|
window->egl_surface,
|
|
|
|
rect, 1);
|
|
|
|
} else {
|
|
|
|
eglSwapBuffers(display->egl.dpy, window->egl_surface);
|
|
|
|
}
|
2013-12-07 10:02:45 +04:00
|
|
|
window->frames++;
|
2011-01-15 02:40:17 +03:00
|
|
|
}
|
|
|
|
|
2012-05-02 17:42:23 +04:00
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
pointer_handle_enter(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t serial, struct wl_surface *surface,
|
|
|
|
wl_fixed_t sx, wl_fixed_t sy)
|
2012-05-02 17:42:23 +04:00
|
|
|
{
|
|
|
|
struct display *display = data;
|
2012-10-30 01:41:46 +04:00
|
|
|
struct wl_buffer *buffer;
|
|
|
|
struct wl_cursor *cursor = display->default_cursor;
|
|
|
|
struct wl_cursor_image *image;
|
2012-05-02 17:42:23 +04:00
|
|
|
|
|
|
|
if (display->window->fullscreen)
|
2012-06-15 18:27:35 +04:00
|
|
|
wl_pointer_set_cursor(pointer, serial, NULL, 0, 0);
|
2012-10-30 01:41:46 +04:00
|
|
|
else if (cursor) {
|
|
|
|
image = display->default_cursor->images[0];
|
|
|
|
buffer = wl_cursor_image_get_buffer(image);
|
2014-03-18 17:12:50 +04:00
|
|
|
if (!buffer)
|
|
|
|
return;
|
2012-10-30 01:41:46 +04:00
|
|
|
wl_pointer_set_cursor(pointer, serial,
|
|
|
|
display->cursor_surface,
|
|
|
|
image->hotspot_x,
|
|
|
|
image->hotspot_y);
|
|
|
|
wl_surface_attach(display->cursor_surface, buffer, 0, 0);
|
|
|
|
wl_surface_damage(display->cursor_surface, 0, 0,
|
|
|
|
image->width, image->height);
|
|
|
|
wl_surface_commit(display->cursor_surface);
|
|
|
|
}
|
2012-05-02 17:42:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
pointer_handle_leave(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t serial, struct wl_surface *surface)
|
2012-05-02 17:42:23 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
pointer_handle_motion(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
|
2012-05-02 17:42:23 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
|
|
|
|
uint32_t serial, uint32_t time, uint32_t button,
|
|
|
|
uint32_t state)
|
2012-05-02 17:42:23 +04:00
|
|
|
{
|
2012-06-26 18:09:11 +04:00
|
|
|
struct display *display = data;
|
|
|
|
|
2014-11-27 07:24:42 +03:00
|
|
|
if (!display->window->xdg_surface)
|
|
|
|
return;
|
|
|
|
|
2012-06-26 18:09:11 +04:00
|
|
|
if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED)
|
2014-02-08 05:01:57 +04:00
|
|
|
xdg_surface_move(display->window->xdg_surface,
|
2014-11-27 07:24:42 +03:00
|
|
|
display->seat, serial);
|
2012-05-02 17:42:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
|
2012-05-30 19:32:00 +04:00
|
|
|
uint32_t time, uint32_t axis, wl_fixed_t value)
|
2012-05-02 17:42:23 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-16 21:45:18 +04:00
|
|
|
static const struct wl_pointer_listener pointer_listener = {
|
|
|
|
pointer_handle_enter,
|
|
|
|
pointer_handle_leave,
|
|
|
|
pointer_handle_motion,
|
|
|
|
pointer_handle_button,
|
|
|
|
pointer_handle_axis,
|
|
|
|
};
|
2012-05-02 17:42:23 +04:00
|
|
|
|
2013-08-15 20:10:08 +04:00
|
|
|
static void
|
|
|
|
touch_handle_down(void *data, struct wl_touch *wl_touch,
|
|
|
|
uint32_t serial, uint32_t time, struct wl_surface *surface,
|
|
|
|
int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
|
|
|
|
{
|
|
|
|
struct display *d = (struct display *)data;
|
|
|
|
|
2014-11-27 07:24:42 +03:00
|
|
|
if (!d->shell)
|
|
|
|
return;
|
|
|
|
|
2014-02-08 05:01:57 +04:00
|
|
|
xdg_surface_move(d->window->xdg_surface, d->seat, serial);
|
2013-08-15 20:10:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
touch_handle_up(void *data, struct wl_touch *wl_touch,
|
|
|
|
uint32_t serial, uint32_t time, int32_t id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
touch_handle_motion(void *data, struct wl_touch *wl_touch,
|
|
|
|
uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
touch_handle_frame(void *data, struct wl_touch *wl_touch)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
touch_handle_cancel(void *data, struct wl_touch *wl_touch)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_touch_listener touch_listener = {
|
|
|
|
touch_handle_down,
|
|
|
|
touch_handle_up,
|
|
|
|
touch_handle_motion,
|
|
|
|
touch_handle_frame,
|
|
|
|
touch_handle_cancel,
|
|
|
|
};
|
|
|
|
|
2012-07-27 18:18:13 +04:00
|
|
|
static void
|
|
|
|
keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
|
|
|
|
uint32_t format, int fd, uint32_t size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
|
|
|
|
uint32_t serial, struct wl_surface *surface,
|
|
|
|
struct wl_array *keys)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
|
|
|
|
uint32_t serial, struct wl_surface *surface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-11-27 07:24:42 +03:00
|
|
|
if (!d->shell)
|
|
|
|
return;
|
|
|
|
|
2014-04-10 21:41:46 +04:00
|
|
|
if (key == KEY_F11 && state) {
|
|
|
|
if (d->window->fullscreen)
|
|
|
|
xdg_surface_unset_fullscreen(d->window->xdg_surface);
|
|
|
|
else
|
|
|
|
xdg_surface_set_fullscreen(d->window->xdg_surface, NULL);
|
|
|
|
} else if (key == KEY_ESC && state)
|
2012-07-30 23:40:57 +04:00
|
|
|
running = 0;
|
2012-07-27 18:18:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_keyboard_listener keyboard_listener = {
|
|
|
|
keyboard_handle_keymap,
|
|
|
|
keyboard_handle_enter,
|
|
|
|
keyboard_handle_leave,
|
|
|
|
keyboard_handle_key,
|
|
|
|
keyboard_handle_modifiers,
|
|
|
|
};
|
|
|
|
|
2012-05-02 17:42:23 +04:00
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
seat_handle_capabilities(void *data, struct wl_seat *seat,
|
|
|
|
enum wl_seat_capability caps)
|
2012-05-02 17:42:23 +04:00
|
|
|
{
|
2012-05-17 00:16:19 +04:00
|
|
|
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;
|
2012-05-16 21:45:18 +04:00
|
|
|
}
|
2012-07-27 18:18:13 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2013-08-15 20:10:08 +04:00
|
|
|
|
|
|
|
if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !d->touch) {
|
|
|
|
d->touch = wl_seat_get_touch(seat);
|
|
|
|
wl_touch_set_user_data(d->touch, d);
|
|
|
|
wl_touch_add_listener(d->touch, &touch_listener, d);
|
|
|
|
} else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && d->touch) {
|
|
|
|
wl_touch_destroy(d->touch);
|
|
|
|
d->touch = NULL;
|
|
|
|
}
|
2012-05-02 17:42:23 +04:00
|
|
|
}
|
|
|
|
|
2012-05-16 21:45:18 +04:00
|
|
|
static const struct wl_seat_listener seat_listener = {
|
|
|
|
seat_handle_capabilities,
|
|
|
|
};
|
2012-05-02 17:42:23 +04:00
|
|
|
|
2014-02-12 00:22:51 +04:00
|
|
|
static void
|
|
|
|
xdg_shell_ping(void *data, struct xdg_shell *shell, uint32_t serial)
|
|
|
|
{
|
|
|
|
xdg_shell_pong(shell, serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct xdg_shell_listener xdg_shell_listener = {
|
|
|
|
xdg_shell_ping,
|
|
|
|
};
|
|
|
|
|
2015-02-13 09:02:02 +03:00
|
|
|
#define XDG_VERSION 5 /* The version of xdg-shell that we implement */
|
2014-02-12 01:50:08 +04:00
|
|
|
#ifdef static_assert
|
|
|
|
static_assert(XDG_VERSION == XDG_SHELL_VERSION_CURRENT,
|
|
|
|
"Interface version doesn't match implementation version");
|
|
|
|
#endif
|
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
static void
|
2012-10-11 05:34:26 +04:00
|
|
|
registry_handle_global(void *data, struct wl_registry *registry,
|
|
|
|
uint32_t name, const char *interface, uint32_t version)
|
2011-01-15 02:40:17 +03:00
|
|
|
{
|
|
|
|
struct display *d = data;
|
|
|
|
|
2011-05-13 21:24:56 +04:00
|
|
|
if (strcmp(interface, "wl_compositor") == 0) {
|
2011-08-19 22:41:57 +04:00
|
|
|
d->compositor =
|
2012-10-11 05:34:26 +04:00
|
|
|
wl_registry_bind(registry, name,
|
|
|
|
&wl_compositor_interface, 1);
|
2014-02-08 05:01:57 +04:00
|
|
|
} else if (strcmp(interface, "xdg_shell") == 0) {
|
2012-10-11 05:34:26 +04:00
|
|
|
d->shell = wl_registry_bind(registry, name,
|
2014-02-08 05:01:57 +04:00
|
|
|
&xdg_shell_interface, 1);
|
2014-02-12 00:22:51 +04:00
|
|
|
xdg_shell_add_listener(d->shell, &xdg_shell_listener, d);
|
2014-02-12 01:50:08 +04:00
|
|
|
xdg_shell_use_unstable_version(d->shell, XDG_VERSION);
|
2012-05-16 21:45:18 +04:00
|
|
|
} else if (strcmp(interface, "wl_seat") == 0) {
|
2012-10-11 05:34:26 +04:00
|
|
|
d->seat = wl_registry_bind(registry, name,
|
|
|
|
&wl_seat_interface, 1);
|
2012-05-17 00:16:19 +04:00
|
|
|
wl_seat_add_listener(d->seat, &seat_listener, d);
|
2012-10-30 01:41:46 +04:00
|
|
|
} else if (strcmp(interface, "wl_shm") == 0) {
|
|
|
|
d->shm = wl_registry_bind(registry, name,
|
|
|
|
&wl_shm_interface, 1);
|
|
|
|
d->cursor_theme = wl_cursor_theme_load(NULL, 32, d->shm);
|
2014-03-18 17:12:50 +04:00
|
|
|
if (!d->cursor_theme) {
|
|
|
|
fprintf(stderr, "unable to load default theme\n");
|
|
|
|
return;
|
|
|
|
}
|
2012-10-30 01:41:46 +04:00
|
|
|
d->default_cursor =
|
|
|
|
wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr");
|
2014-03-18 17:12:50 +04:00
|
|
|
if (!d->default_cursor) {
|
|
|
|
fprintf(stderr, "unable to load default left pointer\n");
|
|
|
|
// TODO: abort ?
|
|
|
|
}
|
2014-11-27 07:24:42 +03:00
|
|
|
} else if (strcmp(interface, "ivi_application") == 0) {
|
|
|
|
d->ivi_application =
|
|
|
|
wl_registry_bind(registry, name,
|
|
|
|
&ivi_application_interface, 1);
|
2011-05-13 21:24:56 +04:00
|
|
|
}
|
2011-01-15 02:40:17 +03:00
|
|
|
}
|
|
|
|
|
2013-01-22 16:53:55 +04:00
|
|
|
static void
|
|
|
|
registry_handle_global_remove(void *data, struct wl_registry *registry,
|
|
|
|
uint32_t name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-11 05:34:26 +04:00
|
|
|
static const struct wl_registry_listener registry_listener = {
|
2013-01-22 16:53:55 +04:00
|
|
|
registry_handle_global,
|
|
|
|
registry_handle_global_remove
|
2012-10-11 05:34:26 +04:00
|
|
|
};
|
2011-01-15 02:40:17 +03:00
|
|
|
|
2011-12-13 14:09:09 +04:00
|
|
|
static void
|
|
|
|
signal_int(int signum)
|
|
|
|
{
|
|
|
|
running = 0;
|
|
|
|
}
|
|
|
|
|
2012-08-03 23:29:08 +04:00
|
|
|
static void
|
|
|
|
usage(int error_code)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: simple-egl [OPTIONS]\n\n"
|
|
|
|
" -f\tRun in fullscreen mode\n"
|
|
|
|
" -o\tCreate an opaque surface\n"
|
2013-10-16 09:03:31 +04:00
|
|
|
" -s\tUse a 16 bpp EGL config\n"
|
2013-12-08 10:25:56 +04:00
|
|
|
" -b\tDon't sync to compositor redraw (eglSwapInterval 0)\n"
|
2012-08-03 23:29:08 +04:00
|
|
|
" -h\tThis help text\n\n");
|
|
|
|
|
|
|
|
exit(error_code);
|
|
|
|
}
|
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2011-12-13 14:09:09 +04:00
|
|
|
struct sigaction sigint;
|
2011-01-15 02:40:17 +03:00
|
|
|
struct display display = { 0 };
|
|
|
|
struct window window = { 0 };
|
2012-10-16 21:16:10 +04:00
|
|
|
int i, ret = 0;
|
2011-01-15 02:40:17 +03:00
|
|
|
|
|
|
|
window.display = &display;
|
2012-05-02 17:42:23 +04:00
|
|
|
display.window = &window;
|
2014-04-10 21:41:46 +04:00
|
|
|
window.geometry.width = 250;
|
|
|
|
window.geometry.height = 250;
|
|
|
|
window.window_size = window.geometry;
|
2013-10-16 09:03:31 +04:00
|
|
|
window.buffer_size = 32;
|
2013-12-08 10:25:56 +04:00
|
|
|
window.frame_sync = 1;
|
2011-01-15 02:40:17 +03:00
|
|
|
|
2012-05-11 04:40:51 +04:00
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (strcmp("-f", argv[i]) == 0)
|
|
|
|
window.fullscreen = 1;
|
2012-08-03 23:29:08 +04:00
|
|
|
else if (strcmp("-o", argv[i]) == 0)
|
2012-09-10 16:55:53 +04:00
|
|
|
window.opaque = 1;
|
2013-10-16 09:03:31 +04:00
|
|
|
else if (strcmp("-s", argv[i]) == 0)
|
|
|
|
window.buffer_size = 16;
|
2013-12-08 10:25:56 +04:00
|
|
|
else if (strcmp("-b", argv[i]) == 0)
|
|
|
|
window.frame_sync = 0;
|
2012-08-03 23:29:08 +04:00
|
|
|
else if (strcmp("-h", argv[i]) == 0)
|
|
|
|
usage(EXIT_SUCCESS);
|
|
|
|
else
|
|
|
|
usage(EXIT_FAILURE);
|
2012-05-11 04:40:51 +04:00
|
|
|
}
|
2012-05-02 17:42:23 +04:00
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
display.display = wl_display_connect(NULL);
|
|
|
|
assert(display.display);
|
|
|
|
|
2012-10-11 05:34:26 +04:00
|
|
|
display.registry = wl_display_get_registry(display.display);
|
|
|
|
wl_registry_add_listener(display.registry,
|
|
|
|
®istry_listener, &display);
|
2011-01-15 02:40:17 +03:00
|
|
|
|
2012-10-11 05:34:26 +04:00
|
|
|
wl_display_dispatch(display.display);
|
2011-05-31 13:36:31 +04:00
|
|
|
|
2013-10-16 09:03:31 +04:00
|
|
|
init_egl(&display, &window);
|
2011-01-15 02:40:17 +03:00
|
|
|
create_surface(&window);
|
2011-02-04 23:31:33 +03:00
|
|
|
init_gl(&window);
|
2011-01-15 02:40:17 +03:00
|
|
|
|
2012-10-30 01:41:46 +04:00
|
|
|
display.cursor_surface =
|
|
|
|
wl_compositor_create_surface(display.compositor);
|
|
|
|
|
2011-12-13 14:09:09 +04:00
|
|
|
sigint.sa_handler = signal_int;
|
|
|
|
sigemptyset(&sigint.sa_mask);
|
|
|
|
sigint.sa_flags = SA_RESETHAND;
|
|
|
|
sigaction(SIGINT, &sigint, NULL);
|
|
|
|
|
2013-12-08 10:25:56 +04:00
|
|
|
/* The mainloop here is a little subtle. Redrawing will cause
|
|
|
|
* EGL to read events so we can just call
|
|
|
|
* wl_display_dispatch_pending() to handle any events that got
|
|
|
|
* queued up as a side effect. */
|
|
|
|
while (running && ret != -1) {
|
|
|
|
wl_display_dispatch_pending(display.display);
|
|
|
|
redraw(&window, NULL, 0);
|
|
|
|
}
|
2011-02-04 23:31:33 +03:00
|
|
|
|
2011-12-13 14:09:09 +04:00
|
|
|
fprintf(stderr, "simple-egl exiting\n");
|
|
|
|
|
2011-12-13 16:50:25 +04:00
|
|
|
destroy_surface(&window);
|
|
|
|
fini_egl(&display);
|
|
|
|
|
2012-10-30 01:41:46 +04:00
|
|
|
wl_surface_destroy(display.cursor_surface);
|
|
|
|
if (display.cursor_theme)
|
|
|
|
wl_cursor_theme_destroy(display.cursor_theme);
|
|
|
|
|
2011-12-13 16:50:25 +04:00
|
|
|
if (display.shell)
|
2014-02-08 05:01:57 +04:00
|
|
|
xdg_shell_destroy(display.shell);
|
2011-12-13 16:50:25 +04:00
|
|
|
|
2014-11-27 07:24:42 +03:00
|
|
|
if (display.ivi_application)
|
|
|
|
ivi_application_destroy(display.ivi_application);
|
|
|
|
|
2011-12-13 16:50:25 +04:00
|
|
|
if (display.compositor)
|
|
|
|
wl_compositor_destroy(display.compositor);
|
|
|
|
|
2012-12-04 18:01:15 +04:00
|
|
|
wl_registry_destroy(display.registry);
|
2011-12-15 12:07:52 +04:00
|
|
|
wl_display_flush(display.display);
|
2012-02-28 23:29:19 +04:00
|
|
|
wl_display_disconnect(display.display);
|
2011-12-13 16:50:25 +04:00
|
|
|
|
2011-01-15 02:40:17 +03:00
|
|
|
return 0;
|
|
|
|
}
|