Basic support for wayland engines
Next: Mouse/Keyboard support Signed-off-by: Eduardo Lima (Etrunko) <eduardo.lima@intel.com> SVN revision: 78799
This commit is contained in:
parent
2913da1dca
commit
f81697bb99
|
@ -142,9 +142,9 @@ proxy_text_random.c
|
|||
#filter_object_blur.c \
|
||||
#filter_object_blur_solid.c
|
||||
|
||||
expedite_CFLAGS = @WIN32_CFLAGS@
|
||||
expedite_CFLAGS = @WIN32_CFLAGS@ @WAYLAND_CLIENT_CFLAGS@ @WAYLAND_EGL_CFLAGS@
|
||||
expedite_CXXFLAGS = @EXPEDITE_CXXFLAGS@
|
||||
expedite_LDADD = @SDL_LIBS@ @x_libs@ @gdi_libs@ @ddraw_libs@ @d3d_libs@ @wince_16_libs@ @DIRECTFB_LIBS@ @XCB_LIBS@ @EVAS_LIBS@ @EINA_LIBS@ @EVIL_LIBS@ @gl_cocoa_libs@ -lm
|
||||
expedite_LDADD = @SDL_LIBS@ @x_libs@ @gdi_libs@ @ddraw_libs@ @d3d_libs@ @wince_16_libs@ @DIRECTFB_LIBS@ @XCB_LIBS@ @EVAS_LIBS@ @EINA_LIBS@ @EVIL_LIBS@ @gl_cocoa_libs@ @WAYLAND_CLIENT_LIBS@ @WAYLAND_EGL_LIBS@ -lm
|
||||
expedite_LDFLAGS = @lt_enable_auto_import@
|
||||
|
||||
if BUILD_SOFTWARE_XLIB
|
||||
|
@ -222,9 +222,14 @@ expedite_SOURCES += \
|
|||
engine_software_16_wince.c engine_software_16_wince.h engine_software_16_wince.rc
|
||||
endif
|
||||
|
||||
if BUILD_SOFTWARE_16_WINCE
|
||||
if BUILD_WAYLAND_EGL
|
||||
expedite_SOURCES += \
|
||||
engine_software_16_wince.c engine_software_16_wince.h engine_software_16_wince.rc
|
||||
engine_wayland_egl.c engine_wayland_egl.h
|
||||
endif
|
||||
|
||||
if BUILD_WAYLAND_SHM
|
||||
expedite_SOURCES += \
|
||||
engine_wayland_shm.c engine_wayland_shm.h
|
||||
endif
|
||||
|
||||
.rc.lo:
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
#include "main.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <Evas_Engine_Wayland_Egl.h>
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-egl.h>
|
||||
|
||||
/* Global struct */
|
||||
struct _engine_wayland_egl_display
|
||||
{
|
||||
struct wl_display *display;
|
||||
struct wl_registry *registry;
|
||||
struct wl_compositor *compositor;
|
||||
struct wl_surface *surface;
|
||||
struct wl_shell *shell;
|
||||
struct wl_shell_surface *shell_surface;
|
||||
};
|
||||
|
||||
static struct _engine_wayland_egl_display wl;
|
||||
|
||||
/*
|
||||
* Function prototypes
|
||||
*/
|
||||
/* Registry handler */
|
||||
static void _registry_handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version __UNUSED__);
|
||||
static const struct wl_registry_listener _registry_listener =
|
||||
{
|
||||
_registry_handle_global,
|
||||
};
|
||||
|
||||
/* Shell Surface handler */
|
||||
static void _shell_surface_handle_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial);
|
||||
|
||||
static const struct wl_shell_surface_listener _shell_surface_listener =
|
||||
{
|
||||
_shell_surface_handle_ping,
|
||||
};
|
||||
|
||||
/*
|
||||
* API
|
||||
*/
|
||||
Eina_Bool
|
||||
engine_wayland_egl_args(const char *engine __UNUSED__, int width, int height)
|
||||
{
|
||||
Evas_Engine_Info_Wayland_Egl *einfo;
|
||||
|
||||
evas_output_method_set(evas, evas_render_method_lookup("wayland_egl"));
|
||||
einfo = (Evas_Engine_Info_Wayland_Egl *)evas_engine_info_get(evas);
|
||||
if (!einfo)
|
||||
{
|
||||
printf("Evas does not support the Wayland EGL Engine\n");
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
wl.display = wl_display_connect(NULL);
|
||||
wl.registry = wl_display_get_registry(wl.display);
|
||||
wl_registry_add_listener(wl.registry, &_registry_listener, NULL);
|
||||
wl_display_roundtrip(wl.display);
|
||||
|
||||
assert(wl.compositor != NULL);
|
||||
assert(wl.shell != NULL);
|
||||
|
||||
wl.surface = wl_compositor_create_surface(wl.compositor);
|
||||
wl.shell_surface = wl_shell_get_shell_surface(wl.shell, wl.surface);
|
||||
wl_shell_surface_set_title(wl.shell_surface, "Expedite Wayland EGL");
|
||||
wl_shell_surface_add_listener(wl.shell_surface, &_shell_surface_listener, NULL);
|
||||
wl_shell_surface_set_toplevel(wl.shell_surface);
|
||||
|
||||
einfo->info.display = wl.display;
|
||||
einfo->info.surface = wl.surface;
|
||||
if (!evas_engine_info_set(evas, (Evas_Engine_Info *) einfo))
|
||||
{
|
||||
printf("Evas can not setup the informations of the Wayland EGL Engine\n");
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
engine_wayland_egl_loop(void)
|
||||
{
|
||||
assert(wl_display_dispatch_pending(wl.display) != -1);
|
||||
wl_display_flush(wl.display);
|
||||
}
|
||||
|
||||
void
|
||||
engine_wayland_egl_shutdown(void)
|
||||
{
|
||||
wl_shell_surface_destroy(wl.shell_surface);
|
||||
wl_surface_destroy(wl.surface);
|
||||
wl_shell_destroy(wl.shell);
|
||||
wl_compositor_destroy(wl.compositor);
|
||||
wl_display_flush(wl.display);
|
||||
wl_display_disconnect(wl.display);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function implementation
|
||||
*/
|
||||
static void
|
||||
_registry_handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version __UNUSED__)
|
||||
{
|
||||
if (!strcmp(interface, "wl_compositor"))
|
||||
wl.compositor = wl_registry_bind(wl.registry, id, &wl_compositor_interface, 1);
|
||||
else if (!strcmp(interface, "wl_shell"))
|
||||
wl.shell = wl_registry_bind(wl.registry, id, &wl_shell_interface, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
_shell_surface_handle_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial)
|
||||
{
|
||||
wl_shell_surface_pong(shell_surface, serial);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef ENGINE_WAYLAND_EGL_H
|
||||
#define ENGINE_WAYLAND_EGL_H
|
||||
|
||||
Eina_Bool engine_wayland_egl_args(const char *engine, int width, int height);
|
||||
void engine_wayland_egl_loop(void);
|
||||
void engine_wayland_egl_shutdown(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,210 @@
|
|||
#include "main.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <Evas_Engine_Wayland_Shm.h>
|
||||
#include <wayland-client.h>
|
||||
|
||||
/*
|
||||
* Global struct
|
||||
*/
|
||||
struct _engine_wayland_shm_display
|
||||
{
|
||||
struct wl_display *display;
|
||||
struct wl_registry *registry;
|
||||
struct wl_compositor *compositor;
|
||||
struct wl_surface *surface;
|
||||
struct wl_callback *frame_callback;
|
||||
struct wl_shell *shell;
|
||||
struct wl_shell_surface *shell_surface;
|
||||
struct wl_shm *shm;
|
||||
struct wl_buffer *buffer;
|
||||
void *data;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
static struct _engine_wayland_shm_display wl;
|
||||
|
||||
/*
|
||||
* Function Prototypes
|
||||
*/
|
||||
static void _engine_wayland_shm_create_buffer(int width, int height);
|
||||
|
||||
/* Registry handler */
|
||||
static void _registry_handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version __UNUSED__);
|
||||
static const struct wl_registry_listener _registry_listener =
|
||||
{
|
||||
_registry_handle_global,
|
||||
};
|
||||
|
||||
/* Shell Surface handler */
|
||||
static void _shell_surface_handle_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial);
|
||||
|
||||
static const struct wl_shell_surface_listener _shell_surface_listener =
|
||||
{
|
||||
_shell_surface_handle_ping,
|
||||
};
|
||||
|
||||
/* Frame handler */
|
||||
static void _surface_frame_handle_complete(void *data, struct wl_callback *callback, uint32_t time __UNUSED__);
|
||||
static const struct wl_callback_listener _surface_frame_listener =
|
||||
{
|
||||
_surface_frame_handle_complete,
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* API
|
||||
*/
|
||||
Eina_Bool
|
||||
engine_wayland_shm_args(const char *engine __UNUSED__, int width, int height)
|
||||
{
|
||||
Evas_Engine_Info_Wayland_Shm *einfo;
|
||||
struct wl_region *region;
|
||||
|
||||
evas_output_method_set(evas, evas_render_method_lookup("wayland_shm"));
|
||||
einfo = (Evas_Engine_Info_Wayland_Shm *)evas_engine_info_get(evas);
|
||||
if (!einfo)
|
||||
{
|
||||
printf("Evas does not support the Wayland SHM Engine\n");
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
wl.display = wl_display_connect(NULL);
|
||||
wl.registry = wl_display_get_registry(wl.display);
|
||||
wl_registry_add_listener(wl.registry, &_registry_listener, NULL);
|
||||
wl_display_roundtrip(wl.display);
|
||||
|
||||
assert(wl.compositor != NULL);
|
||||
assert(wl.shell != NULL);
|
||||
assert(wl.shm != NULL);
|
||||
|
||||
wl.surface = wl_compositor_create_surface(wl.compositor);
|
||||
wl.shell_surface = wl_shell_get_shell_surface(wl.shell, wl.surface);
|
||||
wl_shell_surface_set_title(wl.shell_surface, "Expedite Wayland SHM");
|
||||
wl_shell_surface_add_listener(wl.shell_surface, &_shell_surface_listener, NULL);
|
||||
wl_shell_surface_set_toplevel(wl.shell_surface);
|
||||
|
||||
_engine_wayland_shm_create_buffer(width, height);
|
||||
|
||||
assert(wl.buffer != NULL);
|
||||
assert(wl.data != NULL);
|
||||
|
||||
wl_surface_attach(wl.surface, wl.buffer, 0, 0);
|
||||
|
||||
einfo->info.dest = wl.data;
|
||||
if (!evas_engine_info_set(evas, (Evas_Engine_Info *) einfo))
|
||||
{
|
||||
printf("Evas can not setup the informations of the Wayland SHM Engine\n");
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
wl.width = width;
|
||||
wl.height = height;
|
||||
|
||||
_surface_frame_handle_complete(NULL, NULL, 0);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
engine_wayland_shm_loop(void)
|
||||
{
|
||||
assert(wl_display_dispatch(wl.display) != -1);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
engine_wayland_shm_shutdown(void)
|
||||
{
|
||||
if (wl.frame_callback)
|
||||
wl_callback_destroy(wl.frame_callback);
|
||||
|
||||
wl_buffer_destroy(wl.buffer);
|
||||
wl_shell_surface_destroy(wl.shell_surface);
|
||||
wl_surface_destroy(wl.surface);
|
||||
|
||||
wl_shm_destroy(wl.shm);
|
||||
wl_shell_destroy(wl.shell);
|
||||
wl_compositor_destroy(wl.compositor);
|
||||
wl_display_flush(wl.display);
|
||||
wl_display_disconnect(wl.display);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function implementation
|
||||
*/
|
||||
static void
|
||||
_registry_handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version __UNUSED__)
|
||||
{
|
||||
if (!strcmp(interface, "wl_compositor"))
|
||||
wl.compositor = wl_registry_bind(wl.registry, id, &wl_compositor_interface, 1);
|
||||
else if (!strcmp(interface, "wl_shell"))
|
||||
wl.shell = wl_registry_bind(wl.registry, id, &wl_shell_interface, 1);
|
||||
else if (!strcmp(interface, "wl_shm"))
|
||||
wl.shm = wl_registry_bind(wl.registry, id, &wl_shm_interface, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
_shell_surface_handle_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial)
|
||||
{
|
||||
wl_shell_surface_pong(shell_surface, serial);
|
||||
}
|
||||
|
||||
static void
|
||||
_engine_wayland_shm_create_buffer(int width, int height)
|
||||
{
|
||||
struct wl_shm_pool *pool;
|
||||
int fd, size, stride;
|
||||
char tmp[PATH_MAX];
|
||||
|
||||
stride = width * 4;
|
||||
size = stride * height;
|
||||
|
||||
strcpy(tmp, "/tmp/expedite-wayland_shm-XXXXXX");
|
||||
if ((fd = mkstemp(tmp)) < 0)
|
||||
{
|
||||
fprintf(stderr, "Could not create temporary file.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ftruncate(fd, size) < 0)
|
||||
{
|
||||
fprintf(stderr, "Could not truncate temporary file.\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
wl.data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (wl.data == MAP_FAILED)
|
||||
{
|
||||
wl.data = NULL;
|
||||
fprintf(stderr, "mmap failed\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
pool = wl_shm_create_pool(wl.shm, fd, size);
|
||||
wl.buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride, WL_SHM_FORMAT_XRGB8888);
|
||||
wl_shm_pool_destroy(pool);
|
||||
|
||||
end:
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void
|
||||
_surface_frame_handle_complete(void *data, struct wl_callback *callback, uint32_t time)
|
||||
{
|
||||
wl_surface_damage(wl.surface, 0, 0, wl.width, wl.height);
|
||||
|
||||
if (wl.frame_callback)
|
||||
wl_callback_destroy(wl.frame_callback);
|
||||
|
||||
wl.frame_callback = wl_surface_frame(wl.surface);
|
||||
wl_callback_add_listener(wl.frame_callback, &_surface_frame_listener, NULL);
|
||||
|
||||
wl_surface_commit(wl.surface);
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef ENGINE_WAYLAND_SHM_H
|
||||
#define ENGINE_WAYLAND_SHM_H
|
||||
|
||||
Eina_Bool engine_wayland_shm_args(const char *engine, int width, int height);
|
||||
void engine_wayland_shm_loop(void);
|
||||
void engine_wayland_shm_shutdown(void);
|
||||
|
||||
#endif
|
|
@ -1185,6 +1185,12 @@ static const Expedite_Engine engines[] = {
|
|||
{ "wince-gapi", engine_software_16_wince_args, engine_software_16_wince_loop, engine_software_16_wince_shutdown },
|
||||
{ "wince-ddraw", engine_software_16_wince_args, engine_software_16_wince_loop, engine_software_16_wince_shutdown },
|
||||
{ "wince-gdi", engine_software_16_wince_args, engine_software_16_wince_loop, engine_software_16_wince_shutdown },
|
||||
#endif
|
||||
#if defined(HAVE_EVAS_WAYLAND_EGL) && defined(BUILD_WAYLAND_EGL)
|
||||
{ "wayland-egl", engine_wayland_egl_args, engine_wayland_egl_loop, engine_wayland_egl_shutdown },
|
||||
#endif
|
||||
#if defined(HAVE_EVAS_WAYLAND_SHM) && defined(BUILD_WAYLAND_SHM)
|
||||
{ "wayland-shm", engine_wayland_shm_args, engine_wayland_shm_loop, engine_wayland_shm_shutdown },
|
||||
#endif
|
||||
{ NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
|
|
@ -77,6 +77,12 @@
|
|||
#if HAVE_EVAS_SOFTWARE_16_WINCE
|
||||
#include "engine_software_16_wince.h"
|
||||
#endif
|
||||
#if defined(HAVE_EVAS_WAYLAND_EGL) && defined(BUILD_WAYLAND_EGL)
|
||||
#include "engine_wayland_egl.h"
|
||||
#endif
|
||||
#if defined(HAVE_EVAS_WAYLAND_SHM) && defined(BUILD_WAYLAND_SHM)
|
||||
#include "engine_wayland_shm.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
|
|
Loading…
Reference in New Issue