aboutsummaryrefslogtreecommitdiffstats
path: root/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_vsync.c
diff options
context:
space:
mode:
Diffstat (limited to 'legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_vsync.c')
-rw-r--r--legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_vsync.c215
1 files changed, 123 insertions, 92 deletions
diff --git a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_vsync.c b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_vsync.c
index 22a44440d0..47efefcc1b 100644
--- a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_vsync.c
+++ b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_vsync.c
@@ -3,7 +3,7 @@
# include <dlfcn.h>
# include <X11/Xlib-xcb.h>
-#define ECORE_XCB_VSYNC_DRI2 1
+#define ECORE_XCB_VSYNC_DRI2 1
#define DRM_EVENT_CONTEXT_VERSION 2
#ifdef ECORE_XCB_VSYNC_DRI2
@@ -26,51 +26,76 @@ typedef enum
typedef struct _drmVBlankReq
{
drmVBlankSeqType type;
- unsigned int sequence;
- unsigned long signal;
+ unsigned int sequence;
+ unsigned long signal;
} drmVBlankReq;
typedef struct _drmVBlankReply
{
drmVBlankSeqType type;
- unsigned int sequence;
- long tval_sec, tval_usec;
+ unsigned int sequence;
+ long tval_sec, tval_usec;
} drmVBlankReply;
typedef union _drmVBlank
{
- drmVBlankReq request;
+ drmVBlankReq request;
drmVBlankReply reply;
} drmVBlank;
typedef struct _drmEventContext
{
int version;
- void (*vblank_handler)(int fd, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data);
- void (*page_flip_handler)(int fd, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data);
+ void (*vblank_handler)(int fd,
+ unsigned int sequence,
+ unsigned int tv_sec,
+ unsigned int tv_usec,
+ void *user_data);
+ void (*page_flip_handler)(int fd,
+ unsigned int sequence,
+ unsigned int tv_sec,
+ unsigned int tv_usec,
+ void *user_data);
} drmEventContext;
-static int (*sym_drmClose) (int fd) = NULL;
-static int (*sym_drmGetMagic) (int fd, drm_magic_t * magic) = NULL;
-static int (*sym_drmWaitVBlank) (int fd, drmVBlank *vbl) = NULL;
-static int (*sym_drmHandleEvent) (int fd, drmEventContext *evctx) = NULL;
+static int (*sym_drmClose)(int fd) = NULL;
+static int (*sym_drmGetMagic)(int fd,
+ drm_magic_t *magic) = NULL;
+static int (*sym_drmWaitVBlank)(int fd,
+ drmVBlank *vbl) = NULL;
+static int (*sym_drmHandleEvent)(int fd,
+ drmEventContext *evctx) = NULL;
/* dri */
-static Bool (*sym_DRI2QueryExtension) (Display *display, int *eventBase, int *errorBase) = NULL;
-static Bool (*sym_DRI2QueryVersion) (Display *display, int *major, int *minor) = NULL;
-static Bool (*sym_DRI2Connect) (Display *display, XID window, char **driverName, char **deviceName) = NULL;
-static Bool (*sym_DRI2Authenticate) (Display *display, XID window, drm_magic_t magic) = NULL;
+static Bool (*sym_DRI2QueryExtension)(Display *display,
+ int *eventBase,
+ int *errorBase) = NULL;
+static Bool (*sym_DRI2QueryVersion)(Display *display,
+ int *major,
+ int *minor) = NULL;
+static Bool (*sym_DRI2Connect)(Display *display,
+ XID window,
+ char **driverName,
+ char **deviceName) = NULL;
+static Bool (*sym_DRI2Authenticate)(Display *display,
+ XID window,
+ drm_magic_t magic) = NULL;
/* local function prototypes */
static Eina_Bool _ecore_xcb_dri_link(void);
static Eina_Bool _ecore_xcb_dri_start(void);
-static void _ecore_xcb_dri_shutdown(void);
-
-static Eina_Bool _ecore_xcb_dri_cb(void *data __UNUSED__, Ecore_Fd_Handler *fdh __UNUSED__);
-static void _ecore_xcb_dri_tick_begin(void *data __UNUSED__);
-static void _ecore_xcb_dri_tick_end(void *data __UNUSED__);
-static void _ecore_xcb_dri_tick_schedule(void);
-static void _ecore_xcb_dri_vblank_handler(int fd __UNUSED__, unsigned int frame __UNUSED__, unsigned int sec __UNUSED__, unsigned int usec __UNUSED__, void *data __UNUSED__);
+static void _ecore_xcb_dri_shutdown(void);
+
+static Eina_Bool _ecore_xcb_dri_cb(void *data __UNUSED__,
+ Ecore_Fd_Handler *fdh __UNUSED__);
+static void _ecore_xcb_dri_tick_begin(void *data __UNUSED__);
+static void _ecore_xcb_dri_tick_end(void *data __UNUSED__);
+static void _ecore_xcb_dri_tick_schedule(void);
+static void _ecore_xcb_dri_vblank_handler(int fd __UNUSED__,
+ unsigned int frame __UNUSED__,
+ unsigned int sec __UNUSED__,
+ unsigned int usec __UNUSED__,
+ void *data __UNUSED__);
/* local variables */
static Ecore_X_Window _vsync_root = 0;
@@ -83,20 +108,20 @@ static void *_dri_lib = NULL;
static drmEventContext _drm_evctx;
#endif
-void
-_ecore_xcb_dri_init(void)
+void
+_ecore_xcb_dri_init(void)
{
LOGFN(__FILE__, __LINE__, __FUNCTION__);
}
-void
-_ecore_xcb_dri_finalize(void)
+void
+_ecore_xcb_dri_finalize(void)
{
LOGFN(__FILE__, __LINE__, __FUNCTION__);
}
-EAPI Eina_Bool
-ecore_x_vsync_animator_tick_source_set(Ecore_X_Window win)
+EAPI Eina_Bool
+ecore_x_vsync_animator_tick_source_set(Ecore_X_Window win)
{
#ifdef ECORE_XCB_VSYNC_DRI2
Ecore_X_Window root;
@@ -107,18 +132,18 @@ ecore_x_vsync_animator_tick_source_set(Ecore_X_Window win)
#ifdef ECORE_XCB_VSYNC_DRI2
root = ecore_x_window_root_get(win);
- if (root != _vsync_root)
+ if (root != _vsync_root)
{
_vsync_root = root;
- if (_vsync_root)
+ if (_vsync_root)
{
- if (!_ecore_xcb_dri_link())
+ if (!_ecore_xcb_dri_link())
{
ecore_animator_source_set(ECORE_ANIMATOR_SOURCE_TIMER);
return EINA_FALSE;
}
_ecore_xcb_dri_shutdown();
- if (!_ecore_xcb_dri_start())
+ if (!_ecore_xcb_dri_start())
{
_vsync_root = 0;
ecore_animator_source_set(ECORE_ANIMATOR_SOURCE_TIMER);
@@ -130,9 +155,9 @@ ecore_x_vsync_animator_tick_source_set(Ecore_X_Window win)
(_ecore_xcb_dri_tick_end, NULL);
ecore_animator_source_set(ECORE_ANIMATOR_SOURCE_CUSTOM);
}
- else
+ else
{
- if (_drm_fd >= 0)
+ if (_drm_fd >= 0)
{
_ecore_xcb_dri_shutdown();
ecore_animator_custom_source_tick_begin_callback_set
@@ -152,57 +177,57 @@ ecore_x_vsync_animator_tick_source_set(Ecore_X_Window win)
/* local functions */
#ifdef ECORE_XCB_VSYNC_DRI2
-static Eina_Bool
-_ecore_xcb_dri_link(void)
+static Eina_Bool
+_ecore_xcb_dri_link(void)
{
- const char *_drm_libs[] =
- {
- "libdrm.so.2",
- "libdrm.so.1",
- "libdrm.so.0",
- "libdrm.so",
- NULL,
- };
- const char *_dri_libs[] =
- {
- "libdri2.so.2",
- "libdri2.so.1",
- "libdri2.so.0",
- "libdri2.so",
- "libGL.so.4",
- "libGL.so.3",
- "libGL.so.2",
- "libGL.so.1",
- "libGL.so.0",
- "libGL.so",
- NULL,
- };
+ const char *_drm_libs[] =
+ {
+ "libdrm.so.2",
+ "libdrm.so.1",
+ "libdrm.so.0",
+ "libdrm.so",
+ NULL,
+ };
+ const char *_dri_libs[] =
+ {
+ "libdri2.so.2",
+ "libdri2.so.1",
+ "libdri2.so.0",
+ "libdri2.so",
+ "libGL.so.4",
+ "libGL.so.3",
+ "libGL.so.2",
+ "libGL.so.1",
+ "libGL.so.0",
+ "libGL.so",
+ NULL,
+ };
int i = 0, fail = 0;
LOGFN(__FILE__, __LINE__, __FUNCTION__);
-# define SYM(lib, xx) \
- do { \
- sym_## xx = dlsym(lib, #xx); \
- if (!(sym_## xx)) { \
- fprintf(stderr, "%s\n", dlerror()); \
- fail = 1; \
- } \
- } while (0);
+# define SYM(lib, xx) \
+ do { \
+ sym_## xx = dlsym(lib, #xx); \
+ if (!(sym_## xx)) { \
+ fprintf(stderr, "%s\n", dlerror()); \
+ fail = 1; \
+ } \
+ } while (0);
if (_drm_lib) return EINA_TRUE;
- for (i = 0; _drm_libs[i]; i++)
+ for (i = 0; _drm_libs[i]; i++)
{
_drm_lib = dlopen(_drm_libs[i], (RTLD_LOCAL | RTLD_LAZY));
- if (_drm_lib)
+ if (_drm_lib)
{
fail = 0;
SYM(_drm_lib, drmClose);
SYM(_drm_lib, drmGetMagic);
SYM(_drm_lib, drmWaitVBlank);
SYM(_drm_lib, drmHandleEvent);
- if (fail)
+ if (fail)
{
dlclose(_drm_lib);
_drm_lib = NULL;
@@ -212,16 +237,16 @@ _ecore_xcb_dri_link(void)
}
}
if (!_drm_lib) return EINA_FALSE;
- for (i = 0; _dri_libs[i]; i++)
+ for (i = 0; _dri_libs[i]; i++)
{
- if ((_dri_lib = dlopen(_dri_libs[i], (RTLD_LOCAL | RTLD_LAZY))))
+ if ((_dri_lib = dlopen(_dri_libs[i], (RTLD_LOCAL | RTLD_LAZY))))
{
fail = 0;
SYM(_dri_lib, DRI2QueryExtension);
SYM(_dri_lib, DRI2QueryVersion);
SYM(_dri_lib, DRI2Connect);
SYM(_dri_lib, DRI2Authenticate);
- if (fail)
+ if (fail)
{
dlclose(_dri_lib);
_dri_lib = NULL;
@@ -230,7 +255,7 @@ _ecore_xcb_dri_link(void)
break;
}
}
- if (!_dri_lib)
+ if (!_dri_lib)
{
dlclose(_drm_lib);
_drm_lib = NULL;
@@ -240,8 +265,8 @@ _ecore_xcb_dri_link(void)
return EINA_TRUE;
}
-static Eina_Bool
-_ecore_xcb_dri_start(void)
+static Eina_Bool
+_ecore_xcb_dri_start(void)
{
Ecore_X_Display *disp;
int _dri2_event = 0, _dri2_error = 0;
@@ -273,9 +298,9 @@ _ecore_xcb_dri_start(void)
_drm_evctx.vblank_handler = _ecore_xcb_dri_vblank_handler;
_drm_evctx.page_flip_handler = NULL;
- _drm_fdh = ecore_main_fd_handler_add(_drm_fd, ECORE_FD_READ,
+ _drm_fdh = ecore_main_fd_handler_add(_drm_fd, ECORE_FD_READ,
_ecore_xcb_dri_cb, NULL, NULL, NULL);
- if (!_drm_fdh)
+ if (!_drm_fdh)
{
close(_drm_fd);
_drm_fd = -1;
@@ -285,43 +310,44 @@ _ecore_xcb_dri_start(void)
return EINA_TRUE;
}
-static void
-_ecore_xcb_dri_shutdown(void)
+static void
+_ecore_xcb_dri_shutdown(void)
{
- if (_drm_fd >= 0)
+ if (_drm_fd >= 0)
{
close(_drm_fd);
_drm_fd = -1;
}
- if (_drm_fdh)
+ if (_drm_fdh)
{
ecore_main_fd_handler_del(_drm_fdh);
_drm_fdh = NULL;
}
}
-static Eina_Bool
-_ecore_xcb_dri_cb(void *data __UNUSED__, Ecore_Fd_Handler *fdh __UNUSED__)
+static Eina_Bool
+_ecore_xcb_dri_cb(void *data __UNUSED__,
+ Ecore_Fd_Handler *fdh __UNUSED__)
{
sym_drmHandleEvent(_drm_fd, &_drm_evctx);
return ECORE_CALLBACK_RENEW;
}
-static void
-_ecore_xcb_dri_tick_begin(void *data __UNUSED__)
+static void
+_ecore_xcb_dri_tick_begin(void *data __UNUSED__)
{
_drm_event_busy = EINA_TRUE;
_ecore_xcb_dri_tick_schedule();
}
-static void
-_ecore_xcb_dri_tick_end(void *data __UNUSED__)
+static void
+_ecore_xcb_dri_tick_end(void *data __UNUSED__)
{
_drm_event_busy = EINA_FALSE;
}
-static void
-_ecore_xcb_dri_tick_schedule(void)
+static void
+_ecore_xcb_dri_tick_schedule(void)
{
drmVBlank vbl;
@@ -335,10 +361,15 @@ _ecore_xcb_dri_tick_schedule(void)
sym_drmWaitVBlank(_drm_fd, &vbl);
}
-static void
-_ecore_xcb_dri_vblank_handler(int fd __UNUSED__, unsigned int frame __UNUSED__, unsigned int sec __UNUSED__, unsigned int usec __UNUSED__, void *data __UNUSED__)
+static void
+_ecore_xcb_dri_vblank_handler(int fd __UNUSED__,
+ unsigned int frame __UNUSED__,
+ unsigned int sec __UNUSED__,
+ unsigned int usec __UNUSED__,
+ void *data __UNUSED__)
{
ecore_animator_custom_tick();
if (_drm_event_busy) _ecore_xcb_dri_tick_schedule();
}
+
#endif