Compare commits

...

5 Commits

Author SHA1 Message Date
Nicolas Aguirre 9dcafb7737 ecore_evas: Add eglfs backend 2016-03-18 16:43:53 +01:00
Nicolas Aguirre 608c328579 ecore_fb: use libinput for all inputs 2016-03-18 14:12:30 +01:00
Nicolas Aguirre a02edfc86b evas: add eglfs evas module. 2016-03-18 14:12:30 +01:00
Clément Bénier 0150491740 evas: remove check for wayland-egl version.
wayland-egl minimal version currently checked is 9.2.0 which is the
Mesa version of wayland-egl. If wayland-egl is shipped with closed
source drivers or in case of libhybris, the wayland-egl.pc pontetially
contains a different value. This commit remove the check for the
version.

Signed-off-by: Nicolas Aguirre <aguirre.nicolas@gmail.com>
2016-03-18 14:12:30 +01:00
Florent Revest 0db3c010dd ecore_evas_fb: Comments ecore_fb_ts calls that aren't resolved at runtime 2016-03-18 14:12:30 +01:00
22 changed files with 4081 additions and 13 deletions

View File

@ -188,6 +188,10 @@ if BUILD_ENGINE_FB
pkgconfig_DATA += pc/evas-fb.pc
endif
if BUILD_ENGINE_EGLFS
pkgconfig_DATA += pc/evas-eglfs.pc
endif
if BUILD_ENGINE_BUFFER
pkgconfig_DATA += pc/evas-software-buffer.pc
endif

View File

@ -1624,6 +1624,19 @@ AC_ARG_ENABLE([fb],
],
[want_fb="no"])
# Eglfs
AC_ARG_ENABLE([eglfs],
[AS_HELP_STRING([--enable-eglfs],[enable hardware accelerated framebuffer access. @<:@default=disabled@:>@])],
[
if test "x${enableval}" = "xyes" ; then
want_eglfs="yes"
want_fb="yes"
else
want_eglfs="no"
fi
],
[want_eglfs="no"])
# SDL
AC_ARG_ENABLE([sdl],
[AS_HELP_STRING([--enable-sdl],[enable SDL support. @<:@default=disabled@:>@])],
@ -2080,6 +2093,7 @@ EVAS_CHECK_ENGINE([wayland-egl], [${want_evas_engine_wayland_egl}], [no], [Wayla
EVAS_CHECK_ENGINE([wayland-shm], [${want_wayland}], [no], [Wayland Shm])
EVAS_CHECK_ENGINE([drm], [${want_drm}], [no], [Drm])
EVAS_CHECK_ENGINE([gl-drm], [${want_gl_drm}], [no], [OpenGL Drm])
EVAS_CHECK_ENGINE([eglfs], [${want_eglfs}], [no], [OpenGL Fb])
# Software XCB
@ -2236,6 +2250,7 @@ if test "x$have_evas_engine_gl_xlib" = "xyes" || \
test "x$have_evas_engine_gl_sdl" = "xyes" || \
test "x$have_evas_engine_gl_cocoa" = "xyes" || \
test "x$have_evas_engine_gl_drm" = "xyes" || \
test "x$have_evas_engine_eglfs" = "xyes" || \
test "x$have_evas_engine_wayland_egl" = "xyes"; then
have_evas_engine_gl_common="yes"
fi
@ -2244,6 +2259,7 @@ if test "x$have_evas_engine_gl_xlib" = "xstatic" || \
test "x$have_evas_engine_gl_sdl" = "xstatic" || \
test "x$have_evas_engine_gl_cocoa" = "xstatic" || \
test "x$have_evas_engine_gl_drm" = "xstatic" || \
test "x$have_evas_engine_eglfs" = "xstatic" || \
test "x$have_evas_engine_wayland_egl" = "xstatic"; then
have_evas_engine_gl_common="yes"
have_static_evas_engine_gl_common="yes"
@ -3106,10 +3122,12 @@ AC_ARG_ENABLE([tslib],
### Checks for libraries
EFL_INTERNAL_DEPEND_PKG([ECORE_FB], [ecore])
EFL_INTERNAL_DEPEND_PKG([ECORE_FB], [ecore-input])
EFL_INTERNAL_DEPEND_PKG([ECORE_FB], [eeze])
EFL_INTERNAL_DEPEND_PKG([ECORE_FB], [eo])
EFL_INTERNAL_DEPEND_PKG([ECORE_FB], [eina])
EFL_OPTIONAL_DEPEND_PKG([ECORE_FB], [${want_tslib}], [TSLIB], [tslib])
EFL_DEPEND_PKG([ECORE_FB], [LIBINPUT], [libinput >= 0.6.0 xkbcommon >= 0.3.0])
EFL_ADD_FEATURE([ECORE_FB], [tslib])
EFL_EVAL_PKGS([ECORE_FB])
@ -4199,6 +4217,7 @@ want_ecore_evas_gl_cocoa="${have_evas_engine_gl_cocoa}"
want_ecore_evas_wayland_egl="${have_evas_engine_wayland_egl}"
want_ecore_evas_extn="yes"
want_ecore_evas_drm="${have_evas_engine_drm}"
want_ecore_evas_eglfs="${have_evas_engine_eglfs}"
if test "x${have_ecore_ipc}" = "xno" || \
test "x${efl_func_shm_open}" = "xno" || \
@ -4231,6 +4250,7 @@ ECORE_EVAS_MODULE([drm], [${want_drm}],
ECORE_EVAS_MODULE([gl-drm], [${want_gl_drm}],
[EFL_OPTIONAL_INTERNAL_DEPEND_PKG([ECORE_EVAS], [${want_gl_drm}], [ecore-drm])])
ECORE_EVAS_MODULE([psl1ght], [${have_ps3}])
ECORE_EVAS_MODULE([eglfs], [${want_eglfs}])
ECORE_EVAS_MODULE([opengl-cocoa], [${want_ecore_evas_gl_cocoa}])
@ -5095,6 +5115,7 @@ pc/eo-js.pc
pc/efl.pc
pc/efl-cxx.pc
pc/evas-fb.pc
pc/evas-eglfs.pc
pc/evas-opengl-x11.pc
pc/evas-opengl-sdl.pc
pc/evas-opengl-cocoa.pc

View File

@ -560,7 +560,7 @@ else
gl_library="gl"
fi
PKG_CHECK_EXISTS([egl ${gl_library} wayland-client >= 1.3.0 wayland-egl >= 9.2.0],
PKG_CHECK_EXISTS([egl ${gl_library} wayland-client >= 1.3.0 wayland-egl],
[
have_dep="yes"
requirement="egl ${gl_library} wayland-client wayland-egl"
@ -661,6 +661,49 @@ AS_IF([test "x${have_dep}" = "xyes"], [$4], [$5])
])
dnl use: EVAS_CHECK_ENGINE_DEP_EGLFS(engine, simple, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
AC_DEFUN([EVAS_CHECK_ENGINE_DEP_EGLFS],
[
requirement=""
have_dep="no"
have_hw_dep="no"
evas_engine_[]$1[]_cflags=""
evas_engine_[]$1[]_libs=""
if test "x${with_opengl}" = "xes" ; then
gl_library="glesv2"
else
AC_MSG_ERROR([We do not support Eglfs without OpenGL ES. Please consider OpenGL ES if you want to use it.])
fi
PKG_CHECK_EXISTS([egl >= 7.10 ${gl_library}],
[
have_dep="yes"
requirement="egl >= 7.10 ${gl_library}"
],
[have_dep="no"])
if test "x${have_dep}" = "xyes" ; then
if test "x$3" = "xstatic" ; then
requirements_pc_evas="${requirement} ${requirements_pc_evas}"
requirements_pc_deps_evas="${requirement} ${requirements_pc_deps_evas}"
else
PKG_CHECK_MODULES([EGLFS], [${requirement}])
evas_engine_[]$1[]_cflags="${EGLFS_CFLAGS}"
evas_engine_[]$1[]_libs="${EGLFS_LIBS}"
evas_engine_gl_common_libs="$evas_engine_[]$1[]_libdirs -lGLESv2 -lm -lEGL"
fi
fi
AC_SUBST([evas_engine_$1_cflags])
AC_SUBST([evas_engine_$1_libs])
AS_IF([test "x${have_dep}" = "xyes"], [$4], [$5])
])
dnl use: EVAS_ENGINE(name, want_engine, [DEPENDENCY-CHECK-CODE])
dnl

1
pc/.gitignore vendored
View File

@ -44,6 +44,7 @@
/ethumb_client.pc
/evas-drm.pc
/evas-fb.pc
/evas-eglfs.pc
/evas-opengl-cocoa.pc
/evas-opengl-sdl.pc
/evas-opengl-x11.pc

3
pc/evas-eglfs.pc.in Normal file
View File

@ -0,0 +1,3 @@
Name: evas-eglfs
Description: Evas eglfs engine
Version: @VERSION@

View File

@ -133,9 +133,12 @@ modules_ecore_evas_engines_fb_module_la_SOURCES = $(FBSOURCES)
modules_ecore_evas_engines_fb_module_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
@ECORE_EVAS_CFLAGS@ \
@ECORE_FB_CFLAGS@ \
-I$(top_srcdir)/src/modules/evas/engines/fb
-I$(top_srcdir)/src/modules/evas/engines/fb \
-I$(top_srcdir)/src/modules/evas/engines/eglfs \
@ecore_evas_engines_eglfs_cflags@
modules_ecore_evas_engines_fb_module_la_LIBADD = \
@USE_ECORE_EVAS_LIBS@ \
@ecore_evas_engines_eglfs_libs@ \
@USE_ECORE_FB_LIBS@
modules_ecore_evas_engines_fb_module_la_DEPENDENCIES = \
@USE_ECORE_EVAS_INTERNAL_LIBS@ \

View File

@ -14,7 +14,10 @@ lib/ecore_fb/ecore_fb_li.c \
lib/ecore_fb/ecore_fb_ts.c \
lib/ecore_fb/ecore_fb_vt.c \
lib/ecore_fb/ecore_fb_keytable.h \
lib/ecore_fb/ecore_fb_private.h
lib/ecore_fb/ecore_fb_private.h \
lib/ecore_fb/ecore_fb_inputs.c \
lib/ecore_fb/ecore_fb_evdev.c \
lib/ecore_fb/ecore_fb_device.c
lib_ecore_fb_libecore_fb_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl @ECORE_FB_CFLAGS@
lib_ecore_fb_libecore_fb_la_LIBADD = @ECORE_FB_LIBS@

View File

@ -874,6 +874,9 @@ endif
if BUILD_ENGINE_GL_DRM
modules_evas_engines_gl_common_libevas_engine_gl_common_la_CPPFLAGS += @evas_engine_gl_drm_cflags@
endif
if BUILD_ENGINE_EGLFS
modules_evas_engines_gl_common_libevas_engine_gl_common_la_CPPFLAGS += @evas_engine_eglfs_cflags@
endif
modules_evas_engines_gl_common_libevas_engine_gl_common_la_LIBADD = @USE_EVAS_LIBS@
modules_evas_engines_gl_common_libevas_engine_gl_common_la_DEPENDENCIES = @USE_EVAS_INTERNAL_LIBS@
modules_evas_engines_gl_common_libevas_engine_gl_common_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@
@ -1330,6 +1333,45 @@ modules_evas_engines_gl_drm_module_la_LIBTOOLFLAGS = --tag=disable-static
endif
endif
if BUILD_ENGINE_EGLFS
dist_installed_evasmainheaders_DATA += modules/evas/engines/eglfs/Evas_Engine_Eglfs.h
EGLFS_SOURCES = \
modules/evas/engines/eglfs/evas_outbuf.c \
modules/evas/engines/eglfs/evas_engine.c \
modules/evas/engines/eglfs/evas_engine.h \
modules/evas/engines/eglfs/Evas_Engine_Eglfs.h
if EVAS_STATIC_BUILD_EGLFS
lib_evas_libevas_la_SOURCES += $(EGLFS_SOURCES)
lib_evas_libevas_la_CPPFLAGS += @evas_engine_eglfs_cflags@
lib_evas_libevas_la_LIBADD += @evas_engine_eglfs_libs@
else
engineeglfspkgdir = $(libdir)/evas/modules/engines/eglfs/$(MODULE_ARCH)
engineeglfspkg_LTLIBRARIES = modules/evas/engines/eglfs/module.la
# Workaround for broken parallel install support in automake (relink issue)
# http://debbugs.gnu.org/cgi/bugreport.cgi?bug=7328
install_engineeglfspkgLTLIBRARIES = install-engineeglfspkgLTLIBRARIES
$(install_engineeglfspkgLTLIBRARIES): install-libLTLIBRARIES
modules_evas_engines_eglfs_module_la_SOURCES = $(EGLFS_SOURCES)
modules_evas_engines_eglfs_module_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
-I$(top_srcdir)/src/lib/evas/include \
-I$(top_srcdir)/src/lib/evas/cserve2 \
-I$(top_srcdir)/src/modules/evas/engines/eglfs \
@EVAS_CFLAGS@ \
@ECORE_DRM_CFLAGS@ \
@evas_engine_eglfs_cflags@
modules_evas_engines_eglfs_module_la_LIBADD = \
@USE_EVAS_LIBS@ \
@USE_ECORE_DRM_LIBS@ \
@evas_engine_eglfs_libs@ \
@USE_EEZE_INTERNAL_LIBS@
modules_evas_engines_eglfs_module_la_DEPENDENCIES = @USE_EVAS_INTERNAL_LIBS@ @USE_EEZE_INTERNAL_LIBS@ @USE_ECORE_DRM_INTERNAL_LIBS@
modules_evas_engines_eglfs_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@
modules_evas_engines_eglfs_module_la_LIBTOOLFLAGS = --tag=disable-static
endif
endif
### Cserve2 binary
if EVAS_CSERVE2

View File

@ -91,6 +91,7 @@ extern "C" {
*/
#define HAVE_ECORE_EVAS_X 1
#define HAVE_ECORE_EVAS_FB 1
#define HAVE_ECORE_EVAS_EGLFS 1
#define HAVE_ECORE_EVAS_X11_GL 1
//#define HAVE_ECORE_EVAS_X11_16 1
//#define HAVE_ECORE_EVAS_DIRECTFB 1
@ -121,6 +122,7 @@ typedef enum _Ecore_Evas_Engine_Type
ECORE_EVAS_ENGINE_SOFTWARE_SDL,
ECORE_EVAS_ENGINE_DIRECTFB,
ECORE_EVAS_ENGINE_SOFTWARE_FB,
ECORE_EVAS_ENGINE_EGLFS,
ECORE_EVAS_ENGINE_SOFTWARE_8_X11,
ECORE_EVAS_ENGINE_SOFTWARE_16_X11,
ECORE_EVAS_ENGINE_SOFTWARE_16_DDRAW,
@ -1303,6 +1305,7 @@ EAPI void ecore_evas_software_x11_16_extra_event_window_add(Ecore_Eva
* @return The new Ecore_Evas.
*/
EAPI Ecore_Evas *ecore_evas_fb_new(const char *disp_name, int rotation, int w, int h);
EAPI Ecore_Evas *ecore_evas_eglfs_new(const char *disp_name, int rotation, int w, int h);
EAPI Ecore_Evas *ecore_evas_directfb_new(const char *disp_name, int windowed, int x, int y, int w, int h) EINA_DEPRECATED;
EAPI Ecore_DirectFB_Window *ecore_evas_directfb_window_get(const Ecore_Evas *ee) EINA_DEPRECATED;

View File

@ -282,6 +282,12 @@ ecore_evas_engine_type_supported_get(Ecore_Evas_Engine_Type engine)
#else
return EINA_FALSE;
#endif
case ECORE_EVAS_ENGINE_EGLFS:
#ifdef BUILD_ECORE_EVAS_EGLFS
return EINA_TRUE;
#else
return EINA_FALSE;
#endif
case ECORE_EVAS_ENGINE_SOFTWARE_8_X11:
return EINA_FALSE;
@ -645,6 +651,22 @@ _ecore_evas_constructor_fb(int x EINA_UNUSED, int y EINA_UNUSED, int w, int h, c
return ee;
}
static Ecore_Evas *
_ecore_evas_constructor_eglfs(int x EINA_UNUSED, int y EINA_UNUSED, int w, int h, const char *extra_options)
{
Ecore_Evas *ee;
char *disp_name = NULL;
unsigned int rotation = 0;
_ecore_evas_parse_extra_options_str(extra_options, "display=", &disp_name);
_ecore_evas_parse_extra_options_uint(extra_options, "rotation=", &rotation);
ee = ecore_evas_eglfs_new(disp_name, rotation, w, h);
free(disp_name);
return ee;
}
static Ecore_Evas *
_ecore_evas_constructor_psl1ght(int x EINA_UNUSED, int y EINA_UNUSED, int w, int h, const char *extra_options)
{
@ -769,6 +791,7 @@ static const struct ecore_evas_engine _engines[] = {
{"software_x11", _ecore_evas_constructor_software_x11},
{"opengl_x11", _ecore_evas_constructor_opengl_x11},
{"fb", _ecore_evas_constructor_fb},
{"eglfs", _ecore_evas_constructor_eglfs},
{"software_gdi", _ecore_evas_constructor_software_gdi},
{"software_ddraw", _ecore_evas_constructor_software_ddraw},
{"direct3d", _ecore_evas_constructor_direct3d},
@ -3646,6 +3669,19 @@ ecore_evas_fb_new(const char *disp_name, int rotation, int w, int h)
return new(disp_name, rotation, w, h);
}
EAPI Ecore_Evas *
ecore_evas_eglfs_new(const char *disp_name, int rotation, int w, int h)
{
Ecore_Evas *(*new)(const char *, int, int, int);
Eina_Module *m = _ecore_evas_engine_load("fb");
EINA_SAFETY_ON_NULL_RETURN_VAL(m, NULL);
new = eina_module_symbol_get(m, "ecore_evas_eglfs_new_internal");
EINA_SAFETY_ON_NULL_RETURN_VAL(new, NULL);
return new(disp_name, rotation, w, h);
}
EAPI Ecore_Evas *
ecore_evas_software_x11_new(const char *disp_name, Ecore_X_Window parent, int x, int y, int w, int h)
{

View File

@ -188,6 +188,9 @@ _ecore_evas_available_engines_get(void)
{
#ifdef BUILD_ECORE_EVAS_FB
ADDENG("fb");
#endif
#ifdef BUILD_ECORE_EVAS_EGLFS
ADDENG("eglfs");
#endif
}
else if (!strcmp(name, "x"))

View File

@ -66,6 +66,23 @@ enum _Ecore_Fb_Input_Device_Cap
*/
typedef enum _Ecore_Fb_Input_Device_Cap Ecore_Fb_Input_Device_Cap;
/* opaque structure to represent a fb input */
typedef struct _Ecore_Fb_Input Ecore_Fb_Input;
/* opaque structure to represent a fb evdev input */
typedef struct _Ecore_Fb_Evdev Ecore_Fb_Evdev;
/* opaque structure to represent a fb seat */
typedef struct _Ecore_Fb_Seat Ecore_Fb_Seat;
/* opaque structure to represent a fb device */
typedef struct _Ecore_Fb_Device Ecore_Fb_Device;
/* opaque structure to represent a fb output */
typedef struct _Ecore_Fb_Output Ecore_Fb_Output;
/* ecore_fb_vt.c */
EAPI void ecore_fb_callback_gain_set(void (*func) (void *data), void *data);
EAPI void ecore_fb_callback_lose_set(void (*func) (void *data), void *data);
@ -90,6 +107,18 @@ EAPI void ecore_fb_size_get(int *w, int *h);
EAPI void ecore_fb_touch_screen_calibrate_set(int xscale, int xtrans, int yscale, int ytrans, int xyswap);
EAPI void ecore_fb_touch_screen_calibrate_get(int *xscale, int *xtrans, int *yscale, int *ytrans, int *xyswap);
/* ecore_fb_inputs.c */
EAPI Eina_Bool ecore_fb_inputs_create(Ecore_Fb_Device *dev);
EAPI void ecore_fb_inputs_destroy(Ecore_Fb_Device *dev);
EAPI Eina_Bool ecore_fb_inputs_enable(Ecore_Fb_Input *input);
EAPI void ecore_fb_inputs_disable(Ecore_Fb_Input *input);
EAPI void ecore_fb_inputs_device_axis_size_set(Ecore_Fb_Evdev *dev, int w, int h);
/* ecore_fb_devices */
EAPI Ecore_Fb_Device *ecore_fb_device_find(const char *name);
EAPI void ecore_fb_device_window_set(Ecore_Fb_Device *dev, unsigned int window);
/**
* @}
*/

View File

@ -5,6 +5,9 @@
#include "Ecore_Fb.h"
#include "ecore_fb_private.h"
/* external variables */
int _ecore_fb_log_dom = -1;
static void _ecore_fb_size_get(int *w, int *h);
static int _ecore_fb_init_count = 0;
@ -43,6 +46,43 @@ ecore_fb_init(const char *name EINA_UNUSED)
if (++_ecore_fb_init_count != 1)
return _ecore_fb_init_count;
/* try to init eina */
if (!eina_init()) return --_ecore_fb_init_count;
/* try to init ecore */
if (!ecore_init())
{
eina_shutdown();
return --_ecore_fb_init_count;
}
/* try to init ecore_event */
if (!ecore_event_init())
{
ecore_shutdown();
eina_shutdown();
return --_ecore_fb_init_count;
}
/* set logging level */
eina_log_level_set(EINA_LOG_LEVEL_DBG);
/* try to create logging domain */
_ecore_fb_log_dom =
eina_log_domain_register("ecore_fb", ECORE_FB_DEFAULT_LOG_COLOR);
if (!_ecore_fb_log_dom)
{
EINA_LOG_ERR("Could not create log domain for Ecore_Fb");
goto log_err;
}
/* set default logging level for this domain */
if (!eina_log_domain_level_check(_ecore_fb_log_dom, EINA_LOG_LEVEL_DBG))
eina_log_domain_level_set("ecore_fb", EINA_LOG_LEVEL_DBG);
/* try to init eeze */
if (!eeze_init()) goto eeze_err;
if (!ecore_fb_vt_init())
return --_ecore_fb_init_count;
@ -50,10 +90,21 @@ ecore_fb_init(const char *name EINA_UNUSED)
{
oldhand = signal(SIGINT, nosigint);
}
_ecore_fb_size_get(&_ecore_fb_console_w, &_ecore_fb_console_h);
return _ecore_fb_init_count;
eeze_err:
eina_log_domain_unregister(_ecore_fb_log_dom);
_ecore_fb_log_dom = -1;
log_err:
ecore_event_shutdown();
ecore_shutdown();
eina_shutdown();
return --_ecore_fb_init_count;
}
/**
@ -76,7 +127,7 @@ ecore_fb_shutdown(void)
signal(SIGINT, oldhand);
oldhand = NULL;
}
ecore_fb_vt_shutdown();
return _ecore_fb_init_count;

View File

@ -0,0 +1,72 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "ecore_fb_private.h"
static Eina_List *fb_devices;
EAPI Ecore_Fb_Device *
ecore_fb_device_find(const char *name)
{
Ecore_Fb_Device *dev = NULL;
Eina_List *devs, *l;
const char *device;
/* try to get a list of fb devics */
if (!(devs = eeze_udev_find_by_type(EEZE_UDEV_TYPE_GRAPHICS, name)))
{
return NULL;
}
DBG("Find Framebuffer Device: %s", name);
EINA_LIST_FOREACH(devs, l, device)
{
const char *devpath;
const char *devseat;
const char *devparent;
if (!(devpath = eeze_udev_syspath_get_devpath(device)))
continue;
DBG("Found Fb Device");
DBG("\tDevice: %s", device);
DBG("\tDevpath: %s", devpath);
if ((name) && (!strstr(name, devpath)))
{
eina_stringshare_del(devpath);
if ((dev = calloc(1, sizeof(Ecore_Fb_Device))))
{
dev->seat = eeze_udev_syspath_get_property(device, "ID_SEAT");
if (!dev->seat) dev->seat = eina_stringshare_add("seat0");
fb_devices = eina_list_append(fb_devices, dev);
/* try to create xkb context */
if (!(dev->xkb_ctx = xkb_context_new(0)))
{
ERR("Failed to create xkb context: %m");
return EINA_FALSE;
}
}
break;
}
eina_stringshare_del(devpath);
}
EINA_LIST_FREE(devs, device)
eina_stringshare_del(device);
return dev;
}
EAPI void
ecore_fb_device_window_set(Ecore_Fb_Device *dev, unsigned int window)
{
/* check for valid device */
EINA_SAFETY_ON_TRUE_RETURN((!dev));
dev->window = window;
}

View File

@ -0,0 +1,982 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "ecore_fb_private.h"
#include <ctype.h>
static void _device_modifiers_update(Ecore_Fb_Evdev *edev);
static void
_device_calibration_set(Ecore_Fb_Evdev *edev)
{
const char *sysname;
float cal[6];
const char *device;
Eina_List *devices;
const char *vals;
enum libinput_config_status status;
int width, height;
if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
(libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
return;
sysname = libinput_device_get_sysname(edev->device);
devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
if (eina_list_count(devices) < 1) return;
ecore_fb_size_get(&width, &height);
EINA_LIST_FREE(devices, device)
{
vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
if ((!vals) ||
(sscanf(vals, "%f %f %f %f %f %f",
&cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
goto cont;
cal[2] /= width;
cal[5] /= height;
status =
libinput_device_config_calibration_set_matrix(edev->device, cal);
if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
ERR("Failed to apply calibration");
cont:
eina_stringshare_del(device);
continue;
}
}
static void
_device_output_set(Ecore_Fb_Evdev *edev)
{
Ecore_Fb_Input *input;
Ecore_Fb_Output *output = NULL;
const char *oname;
if (!edev->seat) return;
if (!(input = edev->seat->input)) return;
/* oname = libinput_device_get_output_name(edev->device); */
/* if (oname) */
/* { */
/* Eina_List *l; */
/* DBG("Device Has Output Name: %s", oname); */
/* EINA_LIST_FOREACH(input->dev->outputs, l, output) */
/* if ((output->name) && (!strcmp(output->name, oname))) break; */
/* } */
/* if (!output) */
/* output = eina_list_nth(input->dev->outputs, 0); */
/* if (!output) return; */
/* edev->output = output; */
if (libinput_device_has_capability(edev->device,
LIBINPUT_DEVICE_CAP_POINTER))
{
Ecore_Fb_Input *pointer_input;
Ecore_Event_Mouse_Move *ev;
int width, height;
ecore_fb_size_get(&width, &height);
edev->mouse.dx = width / 2;
edev->mouse.dy = height / 2;
/* send a fake motion event to let other know the initial pos of mouse */
if (!(pointer_input = edev->seat->input)) return;
if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
ev->window = (Ecore_Window)pointer_input->dev->window;
ev->event_window = (Ecore_Window)pointer_input->dev->window;
ev->root_window = (Ecore_Window)pointer_input->dev->window;
_device_modifiers_update(edev);
ev->modifiers = edev->xkb.modifiers;
ev->same_screen = 1;
ev->x = edev->mouse.dx;
ev->y = edev->mouse.dy;
ev->root.x = ev->x;
ev->root.y = ev->y;
ev->multi.device = edev->mt_slot;
ev->multi.radius = 1;
ev->multi.radius_x = 1;
ev->multi.radius_y = 1;
ev->multi.pressure = 1.0;
ev->multi.angle = 0.0;
ev->multi.x = ev->x;
ev->multi.y = ev->y;
ev->multi.root.x = ev->x;
ev->multi.root.y = ev->y;
ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
}
}
static void
_device_configure(Ecore_Fb_Evdev *edev)
{
int width, height;
ecore_fb_size_get(&width, &height);
if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
{
Eina_Bool tap = EINA_FALSE;
tap = libinput_device_config_tap_get_default_enabled(edev->device);
libinput_device_config_tap_set_enabled(edev->device, tap);
}
edev->mouse.minx = 0;
edev->mouse.miny = 0;
edev->mouse.maxw = width;
edev->mouse.maxh = height;
_device_output_set(edev);
_device_calibration_set(edev);
}
static void
_device_keyboard_setup(Ecore_Fb_Evdev *edev)
{
Ecore_Fb_Input *input;
if ((!edev) || (!edev->seat)) return;
if (!(input = edev->seat->input)) return;
if (!input->dev->xkb_ctx) return;
/* create keymap from xkb context */
edev->xkb.keymap = xkb_map_new_from_names(input->dev->xkb_ctx, NULL, 0);
if (!edev->xkb.keymap)
{
ERR("Failed to create keymap: %m");
return;
}
/* create xkb state */
if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
{
ERR("Failed to create xkb state: %m");
return;
}
edev->xkb.ctrl_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
edev->xkb.alt_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
edev->xkb.shift_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
edev->xkb.win_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
edev->xkb.scroll_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
edev->xkb.num_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
edev->xkb.caps_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
edev->xkb.altgr_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
}
static int
_device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
{
unsigned long hbytes = 0;
unsigned char c;
if (!keysym) return 0;
hbytes = (keysym >> 8);
if (!(bytes &&
((hbytes == 0) ||
((hbytes == 0xFF) &&
(((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
(keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
(keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
(keysym == XKB_KEY_KP_Enter) ||
((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
(keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
return 0;
if (keysym == XKB_KEY_KP_Space)
c = (XKB_KEY_space & 0x7F);
else if (hbytes == 0xFF)
c = (keysym & 0x7F);
else
c = (keysym & 0xFF);
if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
{
if (((c >= '@') && (c < '\177')) || c == ' ')
c &= 0x1F;
else if (c == '2')
c = '\000';
else if ((c >= '3') && (c <= '7'))
c -= ('3' - '\033');
else if (c == '8')
c = '\177';
else if (c == '/')
c = '_' & 0x1F;
}
buffer[0] = c;
return 1;
}
static void
_device_modifiers_update_device(Ecore_Fb_Evdev *edev, Ecore_Fb_Evdev *from)
{
xkb_mod_mask_t mask;
edev->xkb.depressed =
xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
edev->xkb.latched =
xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
edev->xkb.locked =
xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
edev->xkb.group =
xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
mask = (edev->xkb.depressed | edev->xkb.latched);
if (mask & from->xkb.ctrl_mask)
edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
if (mask & from->xkb.alt_mask)
edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
if (mask & from->xkb.shift_mask)
edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
if (mask & from->xkb.win_mask)
edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
if (mask & from->xkb.scroll_mask)
edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
if (mask & from->xkb.num_mask)
edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
if (mask & from->xkb.caps_mask)
edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
if (mask & from->xkb.altgr_mask)
edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
}
static void
_device_modifiers_update(Ecore_Fb_Evdev *edev)
{
edev->xkb.modifiers = 0;
if (edev->seat_caps & EVDEV_SEAT_KEYBOARD)
_device_modifiers_update_device(edev, edev);
else
{
Eina_List *l;
Ecore_Fb_Evdev *ed;
EINA_LIST_FOREACH(edev->seat->devices, l, ed)
{
if (!(ed->seat_caps & EVDEV_SEAT_KEYBOARD)) continue;
_device_modifiers_update_device(edev, ed);
}
}
}
static void
_device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
{
Ecore_Fb_Evdev *edev;
Ecore_Fb_Input *input;
uint32_t timestamp;
uint32_t code, nsyms;
const xkb_keysym_t *syms;
enum libinput_key_state state;
int key_count;
xkb_keysym_t sym = XKB_KEY_NoSymbol;
char key[256], keyname[256], compose_buffer[256];
Ecore_Event_Key *e;
char *tmp = NULL, *compose = NULL;
if (!(edev = libinput_device_get_user_data(device))) return;
if (!(input = edev->seat->input)) return;
timestamp = libinput_event_keyboard_get_time(event);
code = libinput_event_keyboard_get_key(event) + 8;
state = libinput_event_keyboard_get_key_state(event);
key_count = libinput_event_keyboard_get_seat_key_count(event);
/* ignore key events that are not seat wide state changes */
if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
return;
xkb_state_update_key(edev->xkb.state, code,
(state ? XKB_KEY_DOWN : XKB_KEY_UP));
/* get the keysym for this code */
nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
if (nsyms == 1) sym = syms[0];
/* get the keyname for this sym */
memset(key, 0, sizeof(key));
xkb_keysym_get_name(sym, key, sizeof(key));
memset(keyname, 0, sizeof(keyname));
memcpy(keyname, key, sizeof(keyname));
if (keyname[0] == '\0')
snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
/* if shift is active, we need to transform the key to lower */
if (xkb_state_mod_index_is_active(edev->xkb.state,
xkb_map_mod_get_index(edev->xkb.keymap,
XKB_MOD_NAME_SHIFT),
XKB_STATE_MODS_EFFECTIVE))
{
if (keyname[0] != '\0')
keyname[0] = tolower(keyname[0]);
}
memset(compose_buffer, 0, sizeof(compose_buffer));
if (_device_keysym_translate(sym, edev->xkb.modifiers,
compose_buffer, sizeof(compose_buffer)))
{
compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
if (!compose)
{
ERR("Ecore_FB cannot convert input key string '%s' to UTF-8. "
"Is Eina built with iconv support?", compose_buffer);
}
else
tmp = compose;
}
if (!compose) compose = compose_buffer;
e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
((compose[0] != '\0') ? strlen(compose) : 0) + 3);
if (!e) return;
e->keyname = (char *)(e + 1);
e->key = e->keyname + strlen(keyname) + 1;
e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
e->string = e->compose;
strcpy((char *)e->keyname, keyname);
strcpy((char *)e->key, key);
if (strlen(compose)) strcpy((char *)e->compose, compose);
e->window = (Ecore_Window)input->dev->window;
e->event_window = (Ecore_Window)input->dev->window;
e->root_window = (Ecore_Window)input->dev->window;
e->timestamp = timestamp;
e->same_screen = 1;
e->keycode = code;
_device_modifiers_update(edev);
e->modifiers = edev->xkb.modifiers;
if (state)
ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL);
else
ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL);
if (tmp) free(tmp);
}
static void
_device_pointer_motion(Ecore_Fb_Evdev *edev, struct libinput_event_pointer *event)
{
Ecore_Fb_Input *input;
Ecore_Event_Mouse_Move *ev;
if (!(input = edev->seat->input)) return;
if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
if (edev->mouse.ix < edev->mouse.minx)
edev->mouse.dx = edev->mouse.ix = edev->mouse.minx;
else if (edev->mouse.ix >= (edev->mouse.minx + edev->mouse.maxw))
edev->mouse.dx = edev->mouse.ix = (edev->mouse.minx + edev->mouse.maxw - 1);
if (edev->mouse.iy < edev->mouse.miny)
edev->mouse.dy = edev->mouse.iy = edev->mouse.miny;
else if (edev->mouse.iy >= (edev->mouse.miny + edev->mouse.maxh))
edev->mouse.dy = edev->mouse.iy = (edev->mouse.miny + edev->mouse.maxh - 1);
ev->window = (Ecore_Window)input->dev->window;
ev->event_window = (Ecore_Window)input->dev->window;
ev->root_window = (Ecore_Window)input->dev->window;
ev->timestamp = libinput_event_pointer_get_time(event);
ev->same_screen = 1;
_device_modifiers_update(edev);
ev->modifiers = edev->xkb.modifiers;
ev->x = edev->mouse.ix;
ev->y = edev->mouse.iy;
ev->root.x = ev->x;
ev->root.y = ev->y;
ev->multi.device = edev->mt_slot;
ev->multi.radius = 1;
ev->multi.radius_x = 1;
ev->multi.radius_y = 1;
ev->multi.pressure = 1.0;
ev->multi.angle = 0.0;
ev->multi.x = ev->x;
ev->multi.y = ev->y;
ev->multi.root.x = ev->x;
ev->multi.root.y = ev->y;
ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
}
static void
_device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
{
Ecore_Fb_Evdev *edev;
if (!(edev = libinput_device_get_user_data(device))) return;
edev->mouse.dx += libinput_event_pointer_get_dx(event);
edev->mouse.dy += libinput_event_pointer_get_dy(event);
if (floor(edev->mouse.dx) == edev->mouse.ix &&
floor(edev->mouse.dy) == edev->mouse.iy) return;
edev->mouse.ix = edev->mouse.dx;
edev->mouse.iy = edev->mouse.dy;
_device_pointer_motion(edev, event);
}
static void
_device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
{
Ecore_Fb_Evdev *edev;
int width, height;
ecore_fb_size_get(&width, &height);
if (!(edev = libinput_device_get_user_data(device))) return;
edev->mouse.dx =
libinput_event_pointer_get_absolute_x_transformed(event, width);
edev->mouse.dy =
libinput_event_pointer_get_absolute_y_transformed(event, height);
if (floor(edev->mouse.dx) == edev->mouse.ix &&
floor(edev->mouse.dy) == edev->mouse.iy) return;
_device_pointer_motion(edev, event);
}
static void
_device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
{
Ecore_Fb_Evdev *edev;
Ecore_Fb_Input *input;
Ecore_Event_Mouse_Button *ev;
enum libinput_button_state state;
uint32_t button, timestamp;
if (!(edev = libinput_device_get_user_data(device))) return;
if (!(input = edev->seat->input)) return;
if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
state = libinput_event_pointer_get_button_state(event);
button = libinput_event_pointer_get_button(event);
timestamp = libinput_event_pointer_get_time(event);
button = ((button & 0x00F) + 1);
if (button == 3) button = 2;
else if (button == 2) button = 3;
ev->window = (Ecore_Window)input->dev->window;
ev->event_window = (Ecore_Window)input->dev->window;
ev->root_window = (Ecore_Window)input->dev->window;
ev->timestamp = timestamp;
ev->same_screen = 1;
_device_modifiers_update(edev);
ev->modifiers = edev->xkb.modifiers;
ev->x = edev->mouse.ix;
ev->y = edev->mouse.iy;
ev->root.x = ev->x;
ev->root.y = ev->y;
ev->multi.device = edev->mt_slot;
ev->multi.radius = 1;
ev->multi.radius_x = 1;
ev->multi.radius_y = 1;
ev->multi.pressure = 1.0;
ev->multi.angle = 0.0;
ev->multi.x = ev->x;
ev->multi.y = ev->y;
ev->multi.root.x = ev->x;
ev->multi.root.y = ev->y;
if (state)
{
unsigned int current;
current = timestamp;
edev->mouse.did_double = EINA_FALSE;
edev->mouse.did_triple = EINA_FALSE;
if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
(button == edev->mouse.prev_button))
{
edev->mouse.did_double = EINA_TRUE;
if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
(button == edev->mouse.last_button))
{
edev->mouse.did_triple = EINA_TRUE;
edev->mouse.prev = 0;
edev->mouse.last = 0;
current = 0;
}
}
edev->mouse.last = edev->mouse.prev;
edev->mouse.prev = current;
edev->mouse.last_button = edev->mouse.prev_button;
edev->mouse.prev_button = button;
}
ev->buttons = button;
if (edev->mouse.did_double)
ev->double_click = 1;
if (edev->mouse.did_triple)
ev->triple_click = 1;
if (state)
ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
else
ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
}
static void
_device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
{
Ecore_Fb_Evdev *edev;
Ecore_Fb_Input *input;
Ecore_Event_Mouse_Wheel *ev;
uint32_t timestamp;
enum libinput_pointer_axis axis;
if (!(edev = libinput_device_get_user_data(device))) return;
if (!(input = edev->seat->input)) return;
if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel)))) return;
timestamp = libinput_event_pointer_get_time(event);
ev->window = (Ecore_Window)input->dev->window;
ev->event_window = (Ecore_Window)input->dev->window;
ev->root_window = (Ecore_Window)input->dev->window;
ev->timestamp = timestamp;
ev->same_screen = 1;
_device_modifiers_update(edev);
ev->modifiers = edev->xkb.modifiers;
ev->x = edev->mouse.ix;
ev->y = edev->mouse.iy;
ev->root.x = ev->x;
ev->root.y = ev->y;
#if LIBINPUT_HIGHER_08
axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
if (libinput_event_pointer_has_axis(event, axis))
ev->z = libinput_event_pointer_get_axis_value(event, axis);
axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
if (libinput_event_pointer_has_axis(event, axis))
{
ev->direction = 1;
ev->z = libinput_event_pointer_get_axis_value(event, axis);
}
#else
axis = libinput_event_pointer_get_axis(event);
if (axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL) ev->direction = 1;
ev->z = libinput_event_pointer_get_axis_value(event);
#endif
ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL);
}
Ecore_Fb_Evdev *
_ecore_fb_evdev_device_create(Ecore_Fb_Seat *seat, struct libinput_device *device)
{
Ecore_Fb_Evdev *edev;
Eina_List *devices;
EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
/* try to allocate space for new evdev */
if (!(edev = calloc(1, sizeof(Ecore_Fb_Evdev)))) return NULL;
edev->seat = seat;
edev->device = device;
edev->path = eina_stringshare_add(libinput_device_get_sysname(device));
devices = eeze_udev_find_by_filter("input", NULL, edev->path);
if (eina_list_count(devices) >= 1)
{
Eina_List *l;
const char *dev, *name;
EINA_LIST_FOREACH(devices, l, dev)
{
name = eeze_udev_syspath_get_devname(dev);
if (strstr(name, edev->path))
{
eina_stringshare_replace(&edev->path, eeze_udev_syspath_get_devpath(dev));
break;
}
}
EINA_LIST_FREE(devices, dev)
eina_stringshare_del(dev);
}
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
{
edev->seat_caps |= EVDEV_SEAT_KEYBOARD;
_device_keyboard_setup(edev);
}
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
{
edev->seat_caps |= EVDEV_SEAT_POINTER;
/* TODO: make this configurable */
edev->mouse.threshold = 250;
}
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
{
edev->seat_caps |= EVDEV_SEAT_TOUCH;
}
libinput_device_set_user_data(device, edev);
libinput_device_ref(device);
/* configure device */
_device_configure(edev);
return edev;
}
static void
_device_handle_touch_event_send(Ecore_Fb_Evdev *edev, struct libinput_event_touch *event, int state)
{
Ecore_Fb_Input *input;
Ecore_Event_Mouse_Button *ev;
uint32_t timestamp, button = 0;
if (!edev) return;
if (!(input = edev->seat->input)) return;
if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
timestamp = libinput_event_touch_get_time(event);
ev->window = (Ecore_Window)input->dev->window;
ev->event_window = (Ecore_Window)input->dev->window;
ev->root_window = (Ecore_Window)input->dev->window;
ev->timestamp = timestamp;
ev->same_screen = 1;
_device_modifiers_update(edev);
ev->modifiers = edev->xkb.modifiers;
ev->x = edev->mouse.ix;
ev->y = edev->mouse.iy;
ev->root.x = ev->x;
ev->root.y = ev->y;
ev->multi.device = edev->mt_slot;
ev->multi.radius = 1;
ev->multi.radius_x = 1;
ev->multi.radius_y = 1;
ev->multi.pressure = 1.0;
ev->multi.angle = 0.0;
ev->multi.x = ev->x;
ev->multi.y = ev->y;
ev->multi.root.x = ev->x;
ev->multi.root.y = ev->y;
if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
{
unsigned int current;
current = timestamp;
edev->mouse.did_double = EINA_FALSE;
edev->mouse.did_triple = EINA_FALSE;
if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
(button == edev->mouse.prev_button))
{
edev->mouse.did_double = EINA_TRUE;
if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
(button == edev->mouse.last_button))
{
edev->mouse.did_triple = EINA_TRUE;
edev->mouse.prev = 0;
edev->mouse.last = 0;
current = 0;
}
}
edev->mouse.last = edev->mouse.prev;
edev->mouse.prev = current;
edev->mouse.last_button = edev->mouse.prev_button;
edev->mouse.prev_button = button;
}
ev->buttons = ((button & 0x00F) + 1);
if (edev->mouse.did_double)
ev->double_click = 1;
if (edev->mouse.did_triple)
ev->triple_click = 1;
ecore_event_add(state, ev, NULL, NULL);
}
static void
_device_handle_touch_motion_send(Ecore_Fb_Evdev *edev, struct libinput_event_touch *event)
{
Ecore_Fb_Input *input;
Ecore_Event_Mouse_Move *ev;
if (!edev) return;
if (!(input = edev->seat->input)) return;
if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
ev->window = (Ecore_Window)input->dev->window;
ev->event_window = (Ecore_Window)input->dev->window;
ev->root_window = (Ecore_Window)input->dev->window;
ev->timestamp = libinput_event_touch_get_time(event);
ev->same_screen = 1;
_device_modifiers_update(edev);
ev->modifiers = edev->xkb.modifiers;
ev->modifiers = 0;
ev->x = edev->mouse.ix;
ev->y = edev->mouse.iy;
ev->root.x = ev->x;
ev->root.y = ev->y;
ev->multi.device = edev->mt_slot;
ev->multi.radius = 1;
ev->multi.radius_x = 1;
ev->multi.radius_y = 1;
ev->multi.pressure = 1.0;
ev->multi.angle = 0.0;
ev->multi.x = ev->x;
ev->multi.y = ev->y;
ev->multi.root.x = ev->x;
ev->multi.root.y = ev->y;
ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
}
static void
_device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
{
Ecore_Fb_Evdev *edev;
int width, height;
ecore_fb_size_get(&width, &height);
if (!(edev = libinput_device_get_user_data(device))) return;
edev->mouse.ix = edev->mouse.dx =
libinput_event_touch_get_x_transformed(event, width);
edev->mouse.iy = edev->mouse.dy =
libinput_event_touch_get_y_transformed(event, height);
edev->mt_slot = libinput_event_touch_get_seat_slot(event);
_device_handle_touch_motion_send(edev, event);
_device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
}
static void
_device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
{
Ecore_Fb_Evdev *edev;
if (!(edev = libinput_device_get_user_data(device))) return;
int width, height;
ecore_fb_size_get(&width, &height);
edev->mouse.dx =
libinput_event_touch_get_x_transformed(event, width);
edev->mouse.dy =
libinput_event_touch_get_y_transformed(event, height);
if (floor(edev->mouse.dx) == edev->mouse.ix &&
floor(edev->mouse.dy) == edev->mouse.iy) return;
edev->mouse.ix = edev->mouse.dx;
edev->mouse.iy = edev->mouse.dy;
edev->mt_slot = libinput_event_touch_get_seat_slot(event);
_device_handle_touch_motion_send(edev, event);
}
static void
_device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
{
Ecore_Fb_Evdev *edev;
if (!(edev = libinput_device_get_user_data(device))) return;
edev->mt_slot = libinput_event_touch_get_seat_slot(event);
_device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
}
static void
_device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
{
/* DBG("Unhandled Touch Frame Event"); */
}
void
_ecore_fb_evdev_device_destroy(Ecore_Fb_Evdev *edev)
{
EINA_SAFETY_ON_NULL_RETURN(edev);
if (edev->seat_caps & EVDEV_SEAT_KEYBOARD)
{
if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
}
if (edev->path) eina_stringshare_del(edev->path);
if (edev->device) libinput_device_unref(edev->device);
free(edev);
}
Eina_Bool
_ecore_fb_evdev_event_process(struct libinput_event *event)
{
struct libinput_device *device;
Eina_Bool ret = EINA_TRUE;
device = libinput_event_get_device(event);
switch (libinput_event_get_type(event))
{
case LIBINPUT_EVENT_KEYBOARD_KEY:
_device_handle_key(device, libinput_event_get_keyboard_event(event));
break;
case LIBINPUT_EVENT_POINTER_MOTION:
_device_handle_pointer_motion(device,
libinput_event_get_pointer_event(event));
break;
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
_device_handle_pointer_motion_absolute(device,
libinput_event_get_pointer_event(event));
break;
case LIBINPUT_EVENT_POINTER_BUTTON:
_device_handle_button(device, libinput_event_get_pointer_event(event));
break;
case LIBINPUT_EVENT_POINTER_AXIS:
_device_handle_axis(device, libinput_event_get_pointer_event(event));
break;
case LIBINPUT_EVENT_TOUCH_DOWN:
_device_handle_touch_down(device, libinput_event_get_touch_event(event));
break;
case LIBINPUT_EVENT_TOUCH_MOTION:
_device_handle_touch_motion(device,
libinput_event_get_touch_event(event));
break;
case LIBINPUT_EVENT_TOUCH_UP:
_device_handle_touch_up(device, libinput_event_get_touch_event(event));
break;
case LIBINPUT_EVENT_TOUCH_FRAME:
_device_handle_touch_frame(device, libinput_event_get_touch_event(event));
break;
default:
ret = EINA_FALSE;
break;
}
return ret;
}
/**
* @brief Set the axis size of the given device.
*
* @param dev The device to set the axis size to.
* @param w The width of the axis.
* @param h The height of the axis.
*
* This function sets set the width @p w and height @p h of the axis
* of device @p dev. If @p dev is a relative input device, a width and
* height must set for it. If its absolute set the ioctl correctly, if
* not, unsupported device.
*/
EAPI void
ecore_fb_inputs_device_axis_size_set(Ecore_Fb_Evdev *edev, int w, int h)
{
const char *sysname;
float cal[6];
const char *device;
Eina_List *devices;
const char *vals;
enum libinput_config_status status;
EINA_SAFETY_ON_NULL_RETURN(edev);
EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
(libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
return;
sysname = libinput_device_get_sysname(edev->device);
devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
if (eina_list_count(devices) < 1) return;
EINA_LIST_FREE(devices, device)
{
vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
if ((!vals) ||
(sscanf(vals, "%f %f %f %f %f %f",
&cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
goto cont;
cal[2] /= w;
cal[5] /= h;
status =
libinput_device_config_calibration_set_matrix(edev->device, cal);
if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
ERR("Failed to apply calibration");
cont:
eina_stringshare_del(device);
continue;
}
}

View File

@ -0,0 +1,371 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "ecore_fb_private.h"
EAPI int ECORE_FB_EVENT_SEAT_ADD = -1;
/* local functions */
int
_ecore_fb_launcher_device_open_no_pending(const char *device, int flags)
{
int fd = -1;
struct stat s;
fd = open(device, flags | O_CLOEXEC);
if (fd < 0) return fd;
if (fstat(fd, &s) == -1)
{
close(fd);
return -1;
}
return fd;
}
void
_ecore_fb_launcher_device_close(const char *device EINA_UNUSED, int fd)
{
close(fd);
}
static int
_cb_open_restricted(const char *path, int flags, void *data)
{
Ecore_Fb_Input *input;
Ecore_Fb_Seat *seat;
Ecore_Fb_Evdev *edev;
Eina_List *l, *ll;
int fd = -1;
if (!(input = data)) return -1;
/* try to open the device */
fd = _ecore_fb_launcher_device_open_no_pending(path, flags);
if (fd < 0) ERR("Could not open device");
EINA_LIST_FOREACH(input->dev->seats, l, seat)
{
EINA_LIST_FOREACH(seat->devices, ll, edev)
{
if (strstr(path, edev->path))
{
edev->fd = fd;
return fd;
}
}
}
return fd;
}
static void
_cb_close_restricted(int fd, void *data)
{
Ecore_Fb_Input *input;
Ecore_Fb_Seat *seat;
Ecore_Fb_Evdev *edev;
Eina_List *l, *ll;
if (!(input = data)) return;
EINA_LIST_FOREACH(input->dev->seats, l, seat)
{
EINA_LIST_FOREACH(seat->devices, ll, edev)
{
if (edev->fd == fd)
{
_ecore_fb_launcher_device_close(edev->path, fd);
return;
}
}
}
}
static Ecore_Fb_Seat *
_seat_create(Ecore_Fb_Input *input, const char *seat)
{
Ecore_Fb_Seat *s;
/* try to allocate space for new seat */
if (!(s = calloc(1, sizeof(Ecore_Fb_Seat))))
return NULL;
s->input = input;
s->name = eina_stringshare_add(seat);
/* add this new seat to list */
input->dev->seats = eina_list_append(input->dev->seats, s);
ecore_event_add(ECORE_FB_EVENT_SEAT_ADD, NULL, NULL, NULL);
return s;
}
static Ecore_Fb_Seat *
_seat_get(Ecore_Fb_Input *input, const char *seat)
{
Ecore_Fb_Seat *s;
Eina_List *l;
/* search for this name in existing seats */
EINA_LIST_FOREACH(input->dev->seats, l, s)
if (!strcmp(s->name, seat)) return s;
return _seat_create(input, seat);
}
static void
_device_added(Ecore_Fb_Input *input, struct libinput_device *device)
{
struct libinput_seat *libinput_seat;
const char *seat_name;
Ecore_Fb_Seat *seat;
Ecore_Fb_Evdev *edev;
libinput_seat = libinput_device_get_seat(device);
seat_name = libinput_seat_get_logical_name(libinput_seat);
/* try to get a seat */
if (!(seat = _seat_get(input, seat_name)))
{
ERR("Could not get matching seat: %s", seat_name);
return;
}
/* try to create a new evdev device */
if (!(edev = _ecore_fb_evdev_device_create(seat, device)))
{
ERR("Failed to create new evdev device");
return;
}
/* append this device to the seat */
seat->devices = eina_list_append(seat->devices, edev);
}
static void
_device_removed(Ecore_Fb_Input *input EINA_UNUSED, struct libinput_device *device)
{
Ecore_Fb_Evdev *edev;
/* try to get the evdev structure */
if (!(edev = libinput_device_get_user_data(device)))
return;
/* remove this evdev from the seat's list of devices */
edev->seat->devices = eina_list_remove(edev->seat->devices, edev);
/* tell launcher to release device */
_ecore_fb_launcher_device_close(edev->path, edev->fd);
/* destroy this evdev */
_ecore_fb_evdev_device_destroy(edev);
}
static int
_udev_event_process(struct libinput_event *event)
{
struct libinput *libinput;
struct libinput_device *device;
Ecore_Fb_Input *input;
Eina_Bool ret = EINA_TRUE;
libinput = libinput_event_get_context(event);
input = libinput_get_user_data(libinput);
device = libinput_event_get_device(event);
switch (libinput_event_get_type(event))
{
case LIBINPUT_EVENT_DEVICE_ADDED:
_device_added(input, device);
break;
case LIBINPUT_EVENT_DEVICE_REMOVED:
_device_removed(input, device);
break;
default:
ret = EINA_FALSE;
}
return ret;
}
static void
_input_event_process(struct libinput_event *event)
{
if (_udev_event_process(event)) return;
if (_ecore_fb_evdev_event_process(event)) return;
}
static void
_input_events_process(Ecore_Fb_Input *input)
{
struct libinput_event *event;
while ((event = libinput_get_event(input->libinput)))
{
_input_event_process(event);
libinput_event_destroy(event);
}
}
static Eina_Bool
_cb_input_dispatch(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED)
{
Ecore_Fb_Input *input;
if (!(input = data)) return EINA_TRUE;
if (libinput_dispatch(input->libinput) != 0)
ERR("Failed to dispatch libinput events: %m");
/* process pending events */
_input_events_process(input);
return EINA_TRUE;
}
const struct libinput_interface _input_interface =
{
_cb_open_restricted,
_cb_close_restricted,
};
/* public functions */
EAPI Eina_Bool
ecore_fb_inputs_create(Ecore_Fb_Device *dev)
{
Ecore_Fb_Input *input;
/* check for valid device */
EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
/* try to allocate space for new input structure */
if (!(input = calloc(1, sizeof(Ecore_Fb_Input))))
return EINA_FALSE;
/* set reference for parent device */
input->dev = dev;
/* try to create libinput context */
input->libinput =
libinput_udev_create_context(&_input_interface, input, eeze_udev_get());
if (!input->libinput)
{
ERR("Could not create libinput context: %m");
goto err;
}
/* set libinput log priority */
libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
/* assign udev seat */
if (libinput_udev_assign_seat(input->libinput, dev->seat) != 0)
{
ERR("Failed to assign seat: %m");
goto err;
}
/* process pending events */
_input_events_process(input);
/* enable this input */
if (!ecore_fb_inputs_enable(input))
{
ERR("Failed to enable input");
goto err;
}
/* append this input */
dev->inputs = eina_list_append(dev->inputs, input);
return EINA_TRUE;
err:
if (input->libinput) libinput_unref(input->libinput);
free(input);
return EINA_FALSE;
}
EAPI void
ecore_fb_inputs_destroy(Ecore_Fb_Device *dev)
{
Ecore_Fb_Input *input;
Ecore_Fb_Seat *seat;
Ecore_Fb_Evdev *edev;
EINA_SAFETY_ON_NULL_RETURN(dev);
EINA_LIST_FREE(dev->seats, seat)
{
EINA_LIST_FREE(seat->devices, edev)
{
_ecore_fb_launcher_device_close(edev->path, edev->fd);
_ecore_fb_evdev_device_destroy(edev);
}
if (seat->name) eina_stringshare_del(seat->name);
free(seat);
}
EINA_LIST_FREE(dev->inputs, input)
{
if (input->hdlr) ecore_main_fd_handler_del(input->hdlr);
if (input->libinput) libinput_unref(input->libinput);
free(input);
}
}
EAPI Eina_Bool
ecore_fb_inputs_enable(Ecore_Fb_Input *input)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(input->libinput, EINA_FALSE);
input->fd = libinput_get_fd(input->libinput);
if (!input->hdlr)
{
input->hdlr =
ecore_main_fd_handler_add(input->fd, ECORE_FD_READ,
_cb_input_dispatch, input, NULL, NULL);
}
if (input->suspended)
{
if (libinput_resume(input->libinput) != 0)
goto err;
input->suspended = EINA_FALSE;
/* process pending events */
_input_events_process(input);
}
input->enabled = EINA_TRUE;
input->suspended = EINA_FALSE;
return EINA_TRUE;
err:
input->enabled = EINA_FALSE;
if (input->hdlr) ecore_main_fd_handler_del(input->hdlr);
input->hdlr = NULL;
return EINA_FALSE;
}
EAPI void
ecore_fb_inputs_disable(Ecore_Fb_Input *input)
{
EINA_SAFETY_ON_NULL_RETURN(input);
EINA_SAFETY_ON_TRUE_RETURN(input->suspended);
/* suspend this input */
libinput_suspend(input->libinput);
/* process pending events */
_input_events_process(input);
input->suspended = EINA_TRUE;
}

View File

@ -1,6 +1,10 @@
#ifndef _ECORE_FB_PRIVATE_H
#define _ECORE_FB_PRIVATE_H
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
#include "Ecore.h"
#include "ecore_private.h"
#include "Ecore_Input.h"
@ -18,7 +22,7 @@
#include <linux/vt.h>
#include <linux/fb.h>
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
#define kernel_ulong_t unsigned long
#define kernel_ulong_t unsigned long
#define BITS_PER_LONG 32
#include <linux/input.h>
#undef kernel_ulong_t
@ -26,12 +30,15 @@
#else
#include <linux/input.h>
#endif
#include <libinput.h>
#include <xkbcommon/xkbcommon.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include "Ecore_Fb.h"
#include <Eeze.h>
#include <Ecore_Fb.h>
#ifdef EAPI
# undef EAPI
@ -47,13 +54,148 @@
# define EAPI
#endif
# ifdef ECORE_FB_DEFAULT_LOG_COLOR
# undef ECORE_FB_DEFAULT_LOG_COLOR
# endif
# define ECORE_FB_DEFAULT_LOG_COLOR EINA_COLOR_BLUE
# ifdef ERR
# undef ERR
# endif
# ifdef DBG
# undef DBG
# endif
# ifdef INF
# undef INF
# endif
# ifdef WRN
# undef WRN
# endif
# ifdef CRIT
# undef CRIT
# endif
extern int _ecore_fb_log_dom;
# define ERR(...) EINA_LOG_DOM_ERR(_ecore_fb_log_dom, __VA_ARGS__)
# define DBG(...) EINA_LOG_DOM_DBG(_ecore_fb_log_dom, __VA_ARGS__)
# define INF(...) EINA_LOG_DOM_INFO(_ecore_fb_log_dom, __VA_ARGS__)
# define WRN(...) EINA_LOG_DOM_WARN(_ecore_fb_log_dom, __VA_ARGS__)
# define CRIT(...) EINA_LOG_DOM_CRIT(_ecore_fb_log_dom, __VA_ARGS__)
typedef enum _Ecore_Fb_Seat_Capabilities
{
EVDEV_SEAT_POINTER = (1 << 0),
EVDEV_SEAT_KEYBOARD = (1 << 1),
EVDEV_SEAT_TOUCH = (1 << 2),
} Ecore_Fb_Seat_Capabilities;
struct _Ecore_Fb_Output
{
Ecore_Fb_Device *dev;
int x, y, phys_width, phys_height;
const char *make, *model, *name;
Eina_List *modes;
};
struct _Ecore_Fb_Device
{
Eina_List *inputs;
Eina_List *seats;
Eina_List *outputs;
const char *seat;
int window;
struct xkb_context *xkb_ctx;
};
struct _Ecore_Fb_Seat
{
// struct libinput_seat *seat;
const char *name;
Ecore_Fb_Input *input;
Eina_List *devices;
};
struct _Ecore_Fb_Input
{
int fd;
Ecore_Fb_Device *dev;
struct libinput *libinput;
Ecore_Fd_Handler *hdlr;
Eina_Bool enabled : 1;
Eina_Bool suspended : 1;
};
struct _Ecore_Fb_Evdev
{
Ecore_Fb_Seat *seat;
struct libinput_device *device;
const char *path;
int fd;
int mt_slot;
Ecore_Fb_Output *output;
/* struct */
/* { */
/* int min_x, min_y; */
/* int max_x, max_y; */
/* double rel_w, rel_h; */
/* struct */
/* { */
/* int x[2]; */
/* int y[2]; */
/* Eina_Bool down : 1; */
/* } pt[EVDEV_MAX_SLOTS]; */
/* } abs; */
struct
{
int ix, iy;
int minx, miny, maxw, maxh;
double dx, dy;
unsigned int last, prev;
uint32_t threshold;
Eina_Bool did_double : 1;
Eina_Bool did_triple : 1;
uint32_t prev_button, last_button;
} mouse;
struct
{
struct xkb_keymap *keymap;
struct xkb_state *state;
xkb_mod_mask_t ctrl_mask;
xkb_mod_mask_t alt_mask;
xkb_mod_mask_t shift_mask;
xkb_mod_mask_t win_mask;
xkb_mod_mask_t scroll_mask;
xkb_mod_mask_t num_mask;
xkb_mod_mask_t caps_mask;
xkb_mod_mask_t altgr_mask;
unsigned int modifiers;
unsigned int depressed, latched, locked, group;
} xkb;
/* Ecore_Fb_Evdev_Capabilities caps; */
Ecore_Fb_Seat_Capabilities seat_caps;
};
/* ecore_fb_li.c */
struct _Ecore_Fb_Input_Device
{
int fd;
Ecore_Fd_Handler *handler;
int listen;
struct
struct
{
Ecore_Fb_Input_Device_Cap cap;
char *name;
@ -98,6 +240,11 @@ EAPI void ecore_fb_ts_event_window_set(void *window);
int ecore_fb_vt_init(void);
void ecore_fb_vt_shutdown(void);
/* ecore_fb_evdev.c */
Ecore_Fb_Evdev *_ecore_fb_evdev_device_create(Ecore_Fb_Seat *seat, struct libinput_device *device);
void _ecore_fb_evdev_device_destroy(Ecore_Fb_Evdev *evdev);
Eina_Bool _ecore_fb_evdev_event_process(struct libinput_event *event);
/* hacks to stop people NEEDING #include <linux/h3600_ts.h> */
#ifndef TS_SET_CAL
#define TS_SET_CAL 0x4014660b
@ -105,7 +252,7 @@ void ecore_fb_vt_shutdown(void);
#ifndef TS_GET_CAL
#define TS_GET_CAL 0x8014660a
#endif
#undef EAPI
#define EAPI

View File

@ -41,6 +41,7 @@
#endif /* ! _WIN32 */
static int _ecore_evas_init_count = 0;
static Ecore_Fb_Device *dev = NULL;
static char *ecore_evas_default_display = "0";
static Eina_List *ecore_evas_input_devices = NULL;
@ -212,8 +213,18 @@ _ecore_evas_fb_init(Ecore_Evas *ee, int w, int h)
_ecore_evas_init_count++;
if (_ecore_evas_init_count > 1) return _ecore_evas_init_count;
if (!(dev = ecore_fb_device_find("fb0")))
{
ERR("Could not find framebuffer device with name: %s.", "/dev/fb0");
}
ecore_fb_device_window_set(dev, ee);
ecore_event_evas_init();
ecore_fb_inputs_create(dev);
return _ecore_evas_init_count;
/* register all input devices */
ls = eina_file_direct_ls("/dev/input/");
@ -262,9 +273,9 @@ _ecore_evas_fb_init(Ecore_Evas *ee, int w, int h)
if ((!mouse_handled) || (always_ts))
{
if (ecore_fb_ts_init())
if (1) //ecore_fb_ts_init())
{
ecore_fb_ts_event_window_set(ee);
// ecore_fb_ts_event_window_set(ee);
ecore_evas_event_handlers[0] = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _ecore_evas_event_mouse_button_down, NULL);
ecore_evas_event_handlers[1] = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, _ecore_evas_event_mouse_button_up, NULL);
ecore_evas_event_handlers[2] = ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, _ecore_evas_event_mouse_move, NULL);
@ -287,7 +298,7 @@ _ecore_evas_fb_shutdown(void)
if (ecore_evas_event_handlers[i])
ecore_event_handler_del(ecore_evas_event_handlers[i]);
}
ecore_fb_ts_shutdown();
// ecore_fb_ts_shutdown();
ecore_event_evas_shutdown();
}
if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0;
@ -743,7 +754,115 @@ ecore_evas_fb_new_internal(const char *disp_name, int rotation, int w, int h)
(Ecore_Event_Mouse_Move_Cb)_ecore_evas_mouse_move_process,
(Ecore_Event_Multi_Move_Cb)_ecore_evas_mouse_multi_move_process,
(Ecore_Event_Multi_Down_Cb)_ecore_evas_mouse_multi_down_process,
(Ecore_Event_Multi_Up_Cb)_ecore_evas_mouse_multi_up_process);
(Ecore_Event_Multi_Up_Cb)_ecore_evas_mouse_multi_up_process);
evas_event_feed_mouse_in(ee->evas, (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), NULL);
return ee;
}
#ifdef BUILD_ECORE_EVAS_EGLFS
EAPI Ecore_Evas *
ecore_evas_eglfs_new_internal(const char *disp_name, int rotation, int w, int h)
{
Evas_Engine_Info_FB *einfo;
Ecore_Evas_Engine_FB_Data *idata;
Ecore_Evas *ee;
int rmethod;
if (!disp_name)
disp_name = ecore_evas_default_display;
rmethod = evas_render_method_lookup("eglfs");
if (!rmethod) return NULL;
if (!ecore_fb_init(disp_name)) return NULL;
ee = calloc(1, sizeof(Ecore_Evas));
if (!ee) return NULL;
idata = calloc(1, sizeof(Ecore_Evas_Engine_FB_Data));
ee->engine.data = idata;
ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
_ecore_evas_fb_init(ee, w, h);
ecore_fb_callback_gain_set(_ecore_evas_fb_gain, ee);
ecore_fb_callback_lose_set(_ecore_evas_fb_lose, ee);
ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_fb_engine_func;
ee->driver = "eglfs";
if (disp_name) ee->name = strdup(disp_name);
if (w < 1) w = 1;
if (h < 1) h = 1;
ee->rotation = rotation;
ee->visible = 1;
ee->w = w;
ee->h = h;
ee->req.w = ee->w;
ee->req.h = ee->h;
ee->prop.max.w = 0;
ee->prop.max.h = 0;
ee->prop.layer = 0;
ee->prop.focused = EINA_FALSE;
ee->prop.borderless = EINA_TRUE;
ee->prop.override = EINA_TRUE;
ee->prop.maximized = EINA_TRUE;
ee->prop.fullscreen = EINA_FALSE;
ee->prop.withdrawn = EINA_TRUE;
ee->prop.sticky = EINA_FALSE;
/* init evas here */
ee->evas = evas_new();
evas_data_attach_set(ee->evas, ee);
evas_output_method_set(ee->evas, rmethod);
if (ECORE_EVAS_PORTRAIT(ee))
{
evas_output_size_set(ee->evas, w, h);
evas_output_viewport_set(ee->evas, 0, 0, w, h);
}
else
{
evas_output_size_set(ee->evas, h, w);
evas_output_viewport_set(ee->evas, 0, 0, h, w);
}
einfo = (Evas_Engine_Info_FB *)evas_engine_info_get(ee->evas);
if (einfo && disp_name)
{
einfo->info.virtual_terminal = 0;
einfo->info.device_number = strtol(disp_name, NULL, 10);
einfo->info.refresh = 0;
einfo->info.rotation = ee->rotation;
if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo))
{
ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver);
ecore_evas_free(ee);
return NULL;
}
}
else
{
ERR("evas_engine_info_set() init engine '%s' failed.", ee->driver);
ecore_evas_free(ee);
return NULL;
}
ecore_evas_input_event_register(ee);
ee->engine.func->fn_render = _ecore_evas_fb_render;
_ecore_evas_register(ee);
ecore_evas_input_event_register(ee);
ecore_event_window_register(1, ee, ee->evas,
(Ecore_Event_Mouse_Move_Cb)_ecore_evas_mouse_move_process,
(Ecore_Event_Multi_Move_Cb)_ecore_evas_mouse_multi_move_process,
(Ecore_Event_Multi_Down_Cb)_ecore_evas_mouse_multi_down_process,
(Ecore_Event_Multi_Up_Cb)_ecore_evas_mouse_multi_up_process);
evas_event_feed_mouse_in(ee->evas, (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), NULL);
return ee;
}
#endif

View File

@ -0,0 +1,45 @@
#ifndef _EVAS_ENGINE_EGLFS_H
# define _EVAS_ENGINE_EGLFS_H
typedef enum _Evas_Engine_Info_Eglfs_Swap_Mode
{
EVAS_ENGINE_EGLFS_SWAP_MODE_AUTO = 0,
EVAS_ENGINE_EGLFS_SWAP_MODE_FULL = 1,
EVAS_ENGINE_EGLFS_SWAP_MODE_COPY = 2,
EVAS_ENGINE_EGLFS_SWAP_MODE_DOUBLE = 3,
EVAS_ENGINE_EGLFS_SWAP_MODE_TRIPLE = 4,
EVAS_ENGINE_EGLFS_SWAP_MODE_QUADRUPLE = 5
} Evas_Engine_Info_Eglfs_Swap_Mode;
typedef struct _Evas_Engine_Info_Eglfs Evas_Engine_Info_Eglfs;
struct _Evas_Engine_Info_Eglfs
{
/* PRIVATE - don't mess with this baby or evas will poke its tongue out */
/* at you and make nasty noises */
Evas_Engine_Info magic;
struct
{
unsigned int rotation, depth;
unsigned int crtc_id, conn_id, buffer_id;
unsigned int format, flags;
Eina_Bool destination_alpha : 1;
Eina_Bool vsync : 1;
Eina_Bool indirect : 1;
unsigned char swap_mode : 4;
} info;
struct
{
void (*pre_swap)(void *data, Evas *evas);
void (*post_swap)(void *data, Evas *evas);
void *data;
} callback;
/* non-blocking or blocking mode */
Evas_Engine_Render_Mode render_mode;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,133 @@
#ifndef EVAS_ENGINE_H
# define EVAS_ENGINE_H
# include "evas_common_private.h"
# include "evas_macros.h"
# include "evas_private.h"
# include "Evas.h"
# include "Evas_Engine_Eglfs.h"
# define EGL_EGLEXT_PROTOTYPES
# define GL_GLEXT_PROTOTYPES
# include <EGL/egl.h>
# include <EGL/eglext.h>
# include <EGL/eglmesaext.h>
# include <GLES2/gl2.h>
# include <GLES2/gl2ext.h>
# include <hwcomposer.h>
# include <hardware/hardware.h>
# include <hardware/hwcomposer.h>
# include "../gl_generic/Evas_Engine_GL_Generic.h"
extern int _evas_engine_eglfs_log_dom;
extern int _extn_have_buffer_age;
# ifdef ERR
# undef ERR
# endif
# define ERR(...) EINA_LOG_DOM_ERR(_evas_engine_eglfs_log_dom, __VA_ARGS__)
# ifdef DBG
# undef DBG
# endif
# define DBG(...) EINA_LOG_DOM_DBG(_evas_engine_eglfs_log_dom, __VA_ARGS__)
# ifdef INF
# undef INF
# endif
# define INF(...) EINA_LOG_DOM_INFO(_evas_engine_eglfs_log_dom, __VA_ARGS__)
# ifdef WRN
# undef WRN
# endif
# define WRN(...) EINA_LOG_DOM_WARN(_evas_engine_eglfs_log_dom, __VA_ARGS__)
# ifdef CRI
# undef CRI
# endif
# define CRI(...) EINA_LOG_DOM_CRIT(_evas_engine_eglfs_log_dom, __VA_ARGS__)
extern Evas_GL_Common_Context_New glsym_evas_gl_common_context_new;
extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_flush;
extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_free;
extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_use;
extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_newframe;
extern Evas_GL_Common_Context_Call glsym_evas_gl_common_context_done;
extern Evas_GL_Common_Context_Resize_Call glsym_evas_gl_common_context_resize;
extern Evas_GL_Common_Buffer_Dump_Call glsym_evas_gl_common_buffer_dump;
extern Evas_GL_Preload_Render_Call glsym_evas_gl_preload_render_lock;
extern Evas_GL_Preload_Render_Call glsym_evas_gl_preload_render_unlock;
struct _Context_3D
{
EGLDisplay display;
EGLContext context;
EGLSurface surface;
};
struct _Outbuf
{
Evas_Engine_Info_Eglfs *info;
Evas_Engine_GL_Context *gl_context;
Evas *evas; // used for pre_swap, post_swap
int w, h;
unsigned int rotation, depth;
Render_Engine_Swap_Mode swap_mode;
struct
{
EGLContext context[1];
EGLSurface surface[1];
EGLConfig config;
EGLDisplay disp;
} egl;
struct
{
int prev_age, frame_cnt;
int curr, last, num;
Eina_List *pending_writes;
} priv;
Eina_Bool destination_alpha : 1;
Eina_Bool vsync : 1;
Eina_Bool lost_back : 1;
Eina_Bool surf : 1;
Eina_Bool drew : 1;
};
Outbuf *evas_outbuf_new(Evas_Engine_Info_Eglfs *info, int w, int h, Render_Engine_Swap_Mode swap_mode);
void evas_outbuf_free(Outbuf *ob);
void evas_outbuf_use(Outbuf *ob);
void evas_outbuf_resurf(Outbuf *ob);
void evas_outbuf_unsurf(Outbuf *ob);
void evas_outbuf_reconfigure(Outbuf *ob, int w, int h, int rot, Outbuf_Depth depth);
Render_Engine_Swap_Mode evas_outbuf_buffer_state_get(Outbuf *ob);
int evas_outbuf_rot_get(Outbuf *ob);
Eina_Bool evas_outbuf_update_region_first_rect(Outbuf *ob);
void *evas_outbuf_update_region_new(Outbuf *ob, int x, int y, int w, int h, int *cx, int *cy, int *cw, int *ch);
void evas_outbuf_update_region_push(Outbuf *ob, RGBA_Image *update, int x, int y, int w, int h);
void evas_outbuf_update_region_free(Outbuf *ob, RGBA_Image *update);
void evas_outbuf_flush(Outbuf *ob, Tilebuf_Rect *rects, Evas_Render_Mode render_mode);
Evas_Engine_GL_Context* evas_outbuf_gl_context_get(Outbuf *ob);
void *evas_outbuf_egl_display_get(Outbuf *ob);
Context_3D *evas_outbuf_gl_context_new(Outbuf *ob);
void evas_outbuf_gl_context_use(Context_3D *ctx);
EGLNativeWindowType create_hwcomposernativewindow(void);
static inline Eina_Bool
_re_wincheck(Outbuf *ob)
{
if (ob->surf) return EINA_TRUE;
evas_outbuf_resurf(ob);
ob->lost_back = 1;
if (!ob->surf) ERR("GL engine can't re-create window surface!");
return EINA_FALSE;
}
extern unsigned int (*glsym_eglSwapBuffersWithDamage)(EGLDisplay a, void *b, const EGLint *d, EGLint c);
#endif

View File

@ -0,0 +1,703 @@
#include "evas_engine.h"
#include <hybris/hwcomposerwindow/hwcomposer.h>
#include <hardware/hwcomposer.h>
#include <hardware/hardware.h>
#include <android-config.h>
static hwc_layer_1_t *fblayer;
static hwc_composer_device_1_t *hwcDevicePtr;
static hwc_display_contents_1_t **mList;
void present(void *user_data, struct ANativeWindow *window,
struct ANativeWindowBuffer *buffer)
{
int oldretire = mList[0]->retireFenceFd;
mList[0]->retireFenceFd = -1;
fblayer->handle = buffer->handle;
fblayer->acquireFenceFd = HWCNativeBufferGetFence(buffer);
fblayer->releaseFenceFd = -1;
int err = hwcDevicePtr->prepare(hwcDevicePtr, HWC_NUM_DISPLAY_TYPES, mList);
//assert(err == 0);
err = hwcDevicePtr->set(hwcDevicePtr, HWC_NUM_DISPLAY_TYPES, mList);
//assert(err == 0);
HWCNativeBufferSetFence(buffer, fblayer->releaseFenceFd);
if (oldretire != -1)
{
sync_wait(oldretire, -1);
close(oldretire);
}
}
EGLNativeWindowType create_hwcomposernativewindow(void)
{
int err;
hw_module_t *hwcModule = 0;
hwcDevicePtr = 0;
err = hw_get_module(HWC_HARDWARE_MODULE_ID, (const hw_module_t **) &hwcModule);
//assert(err == 0);
err = hwc_open_1(hwcModule, &hwcDevicePtr);
//assert(err == 0);
hwcDevicePtr->blank(hwcDevicePtr, 0, 0);
uint32_t configs[5];
size_t numConfigs = 5;
err = hwcDevicePtr->getDisplayConfigs(hwcDevicePtr, 0, configs, &numConfigs);
//assert (err == 0);
int32_t attr_values[2];
uint32_t attributes[] = { HWC_DISPLAY_WIDTH, HWC_DISPLAY_HEIGHT, HWC_DISPLAY_NO_ATTRIBUTE };
hwcDevicePtr->getDisplayAttributes(hwcDevicePtr, 0,
configs[0], attributes, attr_values);
size_t size = sizeof(hwc_display_contents_1_t) + 2 * sizeof(hwc_layer_1_t);
hwc_display_contents_1_t *list = (hwc_display_contents_1_t *) malloc(size);
mList = (hwc_display_contents_1_t **) malloc(HWC_NUM_DISPLAY_TYPES * sizeof(hwc_display_contents_1_t *));
const hwc_rect_t r = { 0, 0, attr_values[0], attr_values[1] };
int counter = 0;
for (; counter < HWC_NUM_DISPLAY_TYPES; counter++)
mList[counter] = NULL;
// Assign buffer only to the first item, otherwise you get tearing
// if passed the same to multiple places
mList[0] = list;
fblayer = &list->hwLayers[0];
memset(fblayer, 0, sizeof(hwc_layer_1_t));
fblayer->compositionType = HWC_FRAMEBUFFER;
fblayer->hints = 0;
fblayer->flags = 0;
fblayer->handle = 0;
fblayer->transform = 0;
fblayer->blending = HWC_BLENDING_NONE;
fblayer->sourceCrop = r;
fblayer->displayFrame = r;
fblayer->visibleRegionScreen.numRects = 1;
fblayer->visibleRegionScreen.rects = &fblayer->displayFrame;
fblayer->acquireFenceFd = -1;
fblayer->releaseFenceFd = -1;
fblayer = &list->hwLayers[1];
memset(fblayer, 0, sizeof(hwc_layer_1_t));
fblayer->compositionType = HWC_FRAMEBUFFER_TARGET;
fblayer->hints = 0;
fblayer->flags = 0;
fblayer->handle = 0;
fblayer->transform = 0;
fblayer->blending = HWC_BLENDING_NONE;
fblayer->sourceCrop = r;
fblayer->displayFrame = r;
fblayer->visibleRegionScreen.numRects = 1;
fblayer->visibleRegionScreen.rects = &fblayer->displayFrame;
fblayer->acquireFenceFd = -1;
fblayer->releaseFenceFd = -1;
list->retireFenceFd = -1;
list->flags = HWC_GEOMETRY_CHANGED;
list->numHwLayers = 2;
EGLNativeWindowType win = NULL;
win = (EGLNativeWindowType)HWCNativeWindowCreate(attr_values[0], attr_values[1], HAL_PIXEL_FORMAT_RGBA_8888, present, NULL);
return win;
}
/* local variables */
static Outbuf *_evas_eglfs_window = NULL;
static EGLContext context = EGL_NO_CONTEXT;
static int win_count = 0;
static Eina_Bool
_evas_outbuf_make_current(void *data, void *doit)
{
Outbuf *ob;
if (!(ob = data)) return EINA_FALSE;
if (doit)
{
if (!eglMakeCurrent(ob->egl.disp, ob->egl.surface[0],
ob->egl.surface[0], ob->egl.context[0]))
return EINA_FALSE;
}
else
{
if (!eglMakeCurrent(ob->egl.disp, EGL_NO_SURFACE,
EGL_NO_SURFACE, EGL_NO_CONTEXT))
return EINA_FALSE;
}
return EINA_TRUE;
}
void _hwcomposer_present_cb(void *user_data, struct ANativeWindow *window, struct ANativeWindowBuffer *buffer)
{
}
static Eina_Bool
_evas_outbuf_egl_setup(Outbuf *ob)
{
int ctx_attr[3];
int cfg_attr[40];
int maj = 0, min = 0, n = 0, i = 0;
EGLint ncfg;
EGLConfig *cfgs;
const GLubyte *vendor, *renderer, *version, *glslversion;
Eina_Bool blacklist = EINA_FALSE;
/* setup egl surface */
ctx_attr[0] = EGL_CONTEXT_CLIENT_VERSION;
ctx_attr[1] = 2;
ctx_attr[2] = EGL_NONE;
cfg_attr[n++] = EGL_BUFFER_SIZE;
cfg_attr[n++] = 32;
cfg_attr[n++] = EGL_DEPTH_SIZE;
cfg_attr[n++] = EGL_DONT_CARE;
cfg_attr[n++] = EGL_STENCIL_SIZE;
cfg_attr[n++] = EGL_DONT_CARE;
cfg_attr[n++] = EGL_RENDERABLE_TYPE;
cfg_attr[n++] = EGL_OPENGL_ES2_BIT;
cfg_attr[n++] = EGL_SURFACE_TYPE;
cfg_attr[n++] = EGL_WINDOW_BIT;
cfg_attr[n++] = EGL_ALPHA_SIZE;
if (ob->destination_alpha) cfg_attr[n++] = 1;
else cfg_attr[n++] = 0;
cfg_attr[n++] = EGL_NONE;
int err;
hw_module_t *hwcModule = 0;
hwc_composer_device_1_t *hwcDevicePtr = 0;
err = hw_get_module(HWC_HARDWARE_MODULE_ID, (const hw_module_t **) &hwcModule);
if (err != 0)
{
ERR("hw_get_module() fail. code=%d", err);
return EINA_FALSE;
}
err = hwc_open_1(hwcModule, &hwcDevicePtr);
if (err != 0)
{
ERR("hwc_open_1 fail. code=%d", err);
return EINA_FALSE;
}
hwcDevicePtr->blank(hwcDevicePtr, 0, 0);
uint32_t configs[5];
size_t numConfigs = 5;
err = hwcDevicePtr->getDisplayConfigs(hwcDevicePtr, 0, configs, &numConfigs);
if (err != 0)
{
ERR("getDisplayConfig. code=%d", err);
return EINA_FALSE;
}
int32_t attr_values[2];
uint32_t attributes[] = { HWC_DISPLAY_WIDTH, HWC_DISPLAY_HEIGHT, HWC_DISPLAY_NO_ATTRIBUTE };
hwcDevicePtr->getDisplayAttributes(hwcDevicePtr, 0,
configs[0], attributes, attr_values);
DBG("width: %i height: %i\n", attr_values[0], attr_values[1]);
size_t size = sizeof(hwc_display_contents_1_t) + 2 * sizeof(hwc_layer_1_t);
hwc_display_contents_1_t *list = (hwc_display_contents_1_t *) malloc(size);
hwc_display_contents_1_t **mList = (hwc_display_contents_1_t **) malloc(HWC_NUM_DISPLAY_TYPES * sizeof(hwc_display_contents_1_t *));
const hwc_rect_t r = { 0, 0, attr_values[0], attr_values[1] };
int counter = 0;
for (; counter < HWC_NUM_DISPLAY_TYPES; counter++)
mList[counter] = NULL;
mList[0] = list;
hwc_layer_1_t *layer = &list->hwLayers[0];
memset(layer, 0, sizeof(hwc_layer_1_t));
layer->compositionType = HWC_FRAMEBUFFER;
layer->hints = 0;
layer->flags = 0;
layer->handle = 0;
layer->transform = 0;
layer->blending = HWC_BLENDING_NONE;
layer->sourceCrop = r;
layer->displayFrame = r;
layer->visibleRegionScreen.numRects = 1;
layer->visibleRegionScreen.rects = &layer->displayFrame;
layer->acquireFenceFd = -1;
layer->releaseFenceFd = -1;
layer = &list->hwLayers[1];
memset(layer, 0, sizeof(hwc_layer_1_t));
layer->compositionType = HWC_FRAMEBUFFER_TARGET;
layer->hints = 0;
layer->flags = 0;
layer->handle = 0;
layer->transform = 0;
layer->blending = HWC_BLENDING_NONE;
layer->sourceCrop = r;
layer->displayFrame = r;
layer->visibleRegionScreen.numRects = 1;
layer->visibleRegionScreen.rects = &layer->displayFrame;
layer->acquireFenceFd = -1;
layer->releaseFenceFd = -1;
list->retireFenceFd = -1;
list->flags = HWC_GEOMETRY_CHANGED;
list->numHwLayers = 2;
ob->egl.disp = eglGetDisplay(NULL);
if (ob->egl.disp == EGL_NO_DISPLAY)
{
ERR("eglGetDisplay() fail. code=%#x", eglGetError());
return EINA_FALSE;
}
if (!eglInitialize(ob->egl.disp, &maj, &min))
{
ERR("eglInitialize() fail. code=%#x", eglGetError());
return EINA_FALSE;
}
eglBindAPI(EGL_OPENGL_ES_API);
if (eglGetError() != EGL_SUCCESS)
{
ERR("eglBindAPI() fail. code=%#x", eglGetError());
return EINA_FALSE;
}
if (!eglGetConfigs(ob->egl.disp, NULL, 0, &ncfg) || (ncfg == 0))
{
ERR("eglGetConfigs() fail. code=%#x", eglGetError());
return EINA_FALSE;
}
cfgs = malloc(ncfg * sizeof(EGLConfig));
if (!cfgs)
{
ERR("Failed to malloc space for egl configs");
return EINA_FALSE;
}
if (!eglChooseConfig(ob->egl.disp, cfg_attr, cfgs,
ncfg, &ncfg) || (ncfg == 0))
{
ERR("eglChooseConfig() fail. code=%#x", eglGetError());
return EINA_FALSE;
}
// First is always best...
ob->egl.config = cfgs[0];
EGLNativeWindowType win = create_hwcomposernativewindow();
ob->egl.surface[0] =
eglCreateWindowSurface(ob->egl.disp, ob->egl.config,
(EGLNativeWindowType)win, NULL);
if (ob->egl.surface[0] == EGL_NO_SURFACE)
{
ERR("eglCreateWindowSurface() fail for %p. code=%#x",
NULL, eglGetError());
return EINA_FALSE;
}
ob->egl.context[0] =
eglCreateContext(ob->egl.disp, ob->egl.config, EGL_NO_CONTEXT, ctx_attr);
if (ob->egl.context[0] == EGL_NO_CONTEXT)
{
ERR("eglCreateContext() fail. code=%#x", eglGetError());
return EINA_FALSE;
}
if (context == EGL_NO_CONTEXT) context = ob->egl.context[0];
if (eglMakeCurrent(ob->egl.disp, ob->egl.surface[0],
ob->egl.surface[0], ob->egl.context[0]) == EGL_FALSE)
{
ERR("eglMakeCurrent() fail. code=%#x", eglGetError());
return EINA_FALSE;
}
vendor = glGetString(GL_VENDOR);
renderer = glGetString(GL_RENDERER);
version = glGetString(GL_VERSION);
glslversion = glGetString(GL_SHADING_LANGUAGE_VERSION);
if (!vendor) vendor = (unsigned char *)"-UNKNOWN-";
if (!renderer) renderer = (unsigned char *)"-UNKNOWN-";
if (!version) version = (unsigned char *)"-UNKNOWN-";
if (!glslversion) glslversion = (unsigned char *)"-UNKNOWN-";
if (getenv("EVAS_GL_INFO"))
{
fprintf(stderr, "vendor : %s\n", vendor);
fprintf(stderr, "renderer: %s\n", renderer);
fprintf(stderr, "version : %s\n", version);
fprintf(stderr, "glsl ver: %s\n", glslversion);
}
if (strstr((const char *)vendor, "Mesa Project"))
{
if (strstr((const char *)renderer, "Software Rasterizer"))
blacklist = EINA_TRUE;
}
if (strstr((const char *)renderer, "softpipe"))
blacklist = EINA_TRUE;
if (strstr((const char *)renderer, "llvmpipe"))
blacklist = EINA_TRUE;
if ((blacklist) && (!getenv("EVAS_GL_NO_BLACKLIST")))
{
ERR("OpenGL Driver blacklisted:");
ERR("Vendor: %s", (const char *)vendor);
ERR("Renderer: %s", (const char *)renderer);
ERR("Version: %s", (const char *)version);
return EINA_FALSE;
}
ob->gl_context = glsym_evas_gl_common_context_new();
if (!ob->gl_context) return EINA_FALSE;
#ifdef GL_GLES
ob->gl_context->egldisp = ob->egl.disp;
ob->gl_context->eglctxt = ob->egl.context[0];
#endif
evas_outbuf_use(ob);
glsym_evas_gl_common_context_resize(ob->gl_context,
ob->w, ob->h, ob->rotation);
ob->surf = EINA_TRUE;
return EINA_TRUE;
}
Outbuf *
evas_outbuf_new(Evas_Engine_Info_Eglfs *info, int w, int h, Render_Engine_Swap_Mode swap_mode)
{
Outbuf *ob;
char *num;
if (!info) return NULL;
/* try to allocate space for outbuf */
if (!(ob = calloc(1, sizeof(Outbuf)))) return NULL;
win_count++;
ob->w = w;
ob->h = h;
ob->info = info;
ob->depth = info->info.depth;
ob->rotation = info->info.rotation;
ob->destination_alpha = info->info.destination_alpha;
ob->swap_mode = swap_mode;
ob->priv.num = 2;
if ((num = getenv("EVAS_EGLFS_BUFFERS")))
{
ob->priv.num = atoi(num);
if (ob->priv.num <= 0) ob->priv.num = 1;
else if (ob->priv.num > 4) ob->priv.num = 4;
}
if ((num = getenv("EVAS_EGLFS_VSYNC")))
ob->vsync = atoi(num);
if (!_evas_outbuf_egl_setup(ob))
{
evas_outbuf_free(ob);
return NULL;
}
return ob;
}
void
evas_outbuf_free(Outbuf *ob)
{
int ref = 0;
win_count--;
evas_outbuf_use(ob);
if (ob == _evas_eglfs_window) _evas_eglfs_window = NULL;
if (ob->gl_context)
{
ref = ob->gl_context->references - 1;
glsym_evas_gl_common_context_free(ob->gl_context);
}
eglMakeCurrent(ob->egl.disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (ob->egl.context[0] != context)
eglDestroyContext(ob->egl.disp, ob->egl.context[0]);
if (ob->egl.surface[0] != EGL_NO_SURFACE)
eglDestroySurface(ob->egl.disp, ob->egl.surface[0]);
if (ref == 0)
{
if (context) eglDestroyContext(ob->egl.disp, context);
eglTerminate(ob->egl.disp);
eglReleaseThread();
context = EGL_NO_CONTEXT;
}
free(ob);
}
void
evas_outbuf_use(Outbuf *ob)
{
Eina_Bool force = EINA_FALSE;
glsym_evas_gl_preload_render_lock(_evas_outbuf_make_current, ob);
if (_evas_eglfs_window)
{
if (eglGetCurrentContext() != _evas_eglfs_window->egl.context[0])
force = EINA_TRUE;
}
if ((_evas_eglfs_window != ob) || (force))
{
if (_evas_eglfs_window)
{
glsym_evas_gl_common_context_use(_evas_eglfs_window->gl_context);
glsym_evas_gl_common_context_flush(_evas_eglfs_window->gl_context);
}
_evas_eglfs_window = ob;
if (ob)
{
if (ob->egl.surface[0] != EGL_NO_SURFACE)
{
if (eglMakeCurrent(ob->egl.disp, ob->egl.surface[0],
ob->egl.surface[0],
ob->egl.context[0]) == EGL_FALSE)
ERR("eglMakeCurrent() failed!");
}
}
}
if (ob) glsym_evas_gl_common_context_use(ob->gl_context);
}
void
evas_outbuf_resurf(Outbuf *ob)
{
if (ob->surf) return;
if (getenv("EVAS_GL_INFO")) printf("resurf %p\n", ob);
ob->egl.surface[0] =
eglCreateWindowSurface(ob->egl.disp, ob->egl.config,
NULL, NULL);
if (ob->egl.surface[0] == EGL_NO_SURFACE)
{
ERR("eglCreateWindowSurface() fail for %p. code=%#x",
NULL, eglGetError());
return;
}
if (eglMakeCurrent(ob->egl.disp, ob->egl.surface[0], ob->egl.surface[0],
ob->egl.context[0]) == EGL_FALSE)
ERR("eglMakeCurrent() failed!");
ob->surf = EINA_TRUE;
}
void
evas_outbuf_unsurf(Outbuf *ob)
{
if (!ob->surf) return;
if (!getenv("EVAS_GL_WIN_RESURF")) return;
if (getenv("EVAS_GL_INFO")) printf("unsurf %p\n", ob);
if (_evas_eglfs_window)
glsym_evas_gl_common_context_flush(_evas_eglfs_window->gl_context);
if (_evas_eglfs_window == ob)
{
eglMakeCurrent(ob->egl.disp, EGL_NO_SURFACE,
EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (ob->egl.surface[0] != EGL_NO_SURFACE)
eglDestroySurface(ob->egl.disp, ob->egl.surface[0]);
ob->egl.surface[0] = EGL_NO_SURFACE;
_evas_eglfs_window = NULL;
}
ob->surf = EINA_FALSE;
}
void
evas_outbuf_reconfigure(Outbuf *ob, int w, int h, int rot, Outbuf_Depth depth)
{
if (depth == OUTBUF_DEPTH_INHERIT) depth = ob->depth;
ob->w = w;
ob->h = h;
ob->depth = depth;
ob->rotation = rot;
evas_outbuf_use(ob);
glsym_evas_gl_common_context_resize(ob->gl_context, w, h, rot);
}
Render_Engine_Swap_Mode
evas_outbuf_buffer_state_get(Outbuf *ob)
{
return MODE_FULL;
// Forces re-rendering all the screen, that is bad for performance. However
// partial rendering makes black area. We should try to find a better solution.
}
int
evas_outbuf_rot_get(Outbuf *ob)
{
return ob->rotation;
}
Eina_Bool
evas_outbuf_update_region_first_rect(Outbuf *ob)
{
glsym_evas_gl_preload_render_lock(_evas_outbuf_make_current, ob);
evas_outbuf_use(ob);
if (!_re_wincheck(ob)) return EINA_TRUE;
glsym_evas_gl_common_context_flush(ob->gl_context);
glsym_evas_gl_common_context_newframe(ob->gl_context);
return EINA_FALSE;
}
void *
evas_outbuf_update_region_new(Outbuf *ob, int x, int y, int w, int h, int *cx EINA_UNUSED, int *cy EINA_UNUSED, int *cw EINA_UNUSED, int *ch EINA_UNUSED)
{
if ((w == ob->w) && (h == ob->h))
ob->gl_context->master_clip.enabled = EINA_FALSE;
else
{
ob->gl_context->master_clip.enabled = EINA_TRUE;
ob->gl_context->master_clip.x = x;
ob->gl_context->master_clip.y = y;
ob->gl_context->master_clip.w = w;
ob->gl_context->master_clip.h = h;
}
return ob->gl_context->def_surface;
}
void
evas_outbuf_update_region_push(Outbuf *ob, RGBA_Image *update EINA_UNUSED, int x EINA_UNUSED, int y EINA_UNUSED, int w EINA_UNUSED, int h EINA_UNUSED)
{
/* Is it really necessary to flush per region ? Shouldn't we be able to
still do that for the full canvas when doing partial update */
if (!_re_wincheck(ob)) return;
ob->drew = EINA_TRUE;
glsym_evas_gl_common_context_flush(ob->gl_context);
}
void
evas_outbuf_update_region_free(Outbuf *ob EINA_UNUSED, RGBA_Image *update EINA_UNUSED)
{
/* Nothing to do here as we don't really create an image per area */
}
void
evas_outbuf_flush(Outbuf *ob, Tilebuf_Rect *rects EINA_UNUSED, Evas_Render_Mode render_mode)
{
if (render_mode == EVAS_RENDER_MODE_ASYNC_INIT) goto end;
if (!_re_wincheck(ob)) goto end;
if (!ob->drew) goto end;
ob->drew = EINA_FALSE;
evas_outbuf_use(ob);
glsym_evas_gl_common_context_done(ob->gl_context);
if (!ob->vsync)
{
if (ob->info->info.vsync) eglSwapInterval(ob->egl.disp, 1);
else eglSwapInterval(ob->egl.disp, 0);
ob->vsync = 1;
}
if (ob->info->callback.pre_swap)
ob->info->callback.pre_swap(ob->info->callback.data, ob->evas);
eglSwapBuffers(ob->egl.disp, ob->egl.surface[0]);
if (ob->info->callback.post_swap)
ob->info->callback.post_swap(ob->info->callback.data, ob->evas);
ob->priv.frame_cnt++;
end:
glsym_evas_gl_preload_render_unlock(_evas_outbuf_make_current, ob);
}
Evas_Engine_GL_Context *
evas_outbuf_gl_context_get(Outbuf *ob)
{
return ob->gl_context;
}
void *
evas_outbuf_egl_display_get(Outbuf *ob)
{
return ob->egl.disp;
}
Context_3D *
evas_outbuf_gl_context_new(Outbuf *ob)
{
Context_3D *ctx;
int context_attrs[3] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
if (!ob) return NULL;
ctx = calloc(1, sizeof(Context_3D));
if (!ctx) return NULL;
ctx->context = eglCreateContext(ob->egl.disp, ob->egl.config,
ob->egl.context[0], context_attrs);
if (!ctx->context)
{
ERR("EGL context creation failed.");
goto error;
}
ctx->display = ob->egl.disp;
ctx->surface = ob->egl.surface[0];
return ctx;
error:
free(ctx);
return NULL;
}
void
evas_outbuf_gl_context_free(Context_3D *ctx)
{
eglDestroyContext(ctx->display, ctx->context);
free(ctx);
}
void
evas_outbuf_gl_context_use(Context_3D *ctx)
{
if (eglMakeCurrent(ctx->display, ctx->surface,
ctx->surface, ctx->context) == EGL_FALSE)
ERR("eglMakeCurrent() failed.");
}