diff options
author | Emre Ucan <eucan@de.adit-jv.com> | 2015-07-02 13:17:22 +0200 |
---|---|---|
committer | Nobuhiko Tanibata <nobuhiko_tanibata@xddp.denso.co.jp> | 2015-07-17 09:09:35 +0900 |
commit | 899df71f847b9070d170881bfc02dbf56d5b70e5 (patch) | |
tree | 6d8c6e102f8b79ab51598e88f554aa615763da22 /ivi-layermanagement-examples | |
parent | 343155c4bab9a2535b5771607cd3e36325e2cd48 (diff) | |
download | wayland-ivi-extension-899df71f847b9070d170881bfc02dbf56d5b70e5.tar.gz |
EGLWLInputEventExample: modify WaitforEvent to read the socket
it is not enough to dispatch the pending events in the mainloop.
Event should be also read from the socket with wl_display_read_events
call. This Implementation also avoids the busy loop in main.c, because
WaitforEvent function waits at poll() till an event comes to the socket.
Signed-off-by: Emre Ucan <eucan@de.adit-jv.com>
Diffstat (limited to 'ivi-layermanagement-examples')
3 files changed, 37 insertions, 5 deletions
diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLEyesRenderer.h b/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLEyesRenderer.h index e630ecc..ea76110 100644 --- a/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLEyesRenderer.h +++ b/ivi-layermanagement-examples/EGLWLInputEventExample/include/WLEyesRenderer.h @@ -27,7 +27,7 @@ bool InitRenderer(); bool InitShader(); bool InitVertexBuffer(); -void WaitForEvent(struct wl_display* wlDisplay); +void WaitForEvent(struct wl_display* wlDisplay, int fd); void TerminateRenderer(); // Pointer event handler diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLEyesRenderer.cpp b/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLEyesRenderer.cpp index e21f347..a4f6c11 100644 --- a/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLEyesRenderer.cpp +++ b/ivi-layermanagement-examples/EGLWLInputEventExample/src/WLEyesRenderer.cpp @@ -24,6 +24,7 @@ #include "WLEGLSurface.h" #include "WLEyes.h" #include "WLEyesRenderer.h" +#include <poll.h> #define WL_UNUSED(A) (A)=(A) @@ -55,9 +56,39 @@ const struct wl_touch_listener TouchListener = { TouchHandleCancel, }; -void WaitForEvent(struct wl_display* wlDisplay) +void WaitForEvent(struct wl_display* wlDisplay, int fd) { - wl_display_dispatch_pending(wlDisplay); + int err; + + /* Execute every pending event in the display and stop any other thread from placing + * events into this display */ + while (wl_display_prepare_read(wlDisplay) != 0) { + wl_display_dispatch_pending(wlDisplay); + } + + if (wl_display_flush(wlDisplay) == -1) + { + err = wl_display_get_error(wlDisplay); + printf("Error communicating with wayland: %d",err); + return; + } + + /*Wait till an event occurs */ + struct pollfd pfd[1]; + pfd[0].fd = fd; + pfd[0].events = POLLIN; + int pollret = poll(pfd, 1, -1); + + if (pollret != -1 && (pfd[0].revents & POLLIN)) + { + /* Read the upcoming events from the file descriptor and execute them */ + wl_display_read_events(wlDisplay); + wl_display_dispatch_pending(wlDisplay); + } + else { + /*Unblock other threads, if an error happens */ + wl_display_cancel_read(wlDisplay); + } } ////////////////////////////////////////////////////////////////////////////// diff --git a/ivi-layermanagement-examples/EGLWLInputEventExample/src/main.cpp b/ivi-layermanagement-examples/EGLWLInputEventExample/src/main.cpp index f1b29a1..20c611f 100644 --- a/ivi-layermanagement-examples/EGLWLInputEventExample/src/main.cpp +++ b/ivi-layermanagement-examples/EGLWLInputEventExample/src/main.cpp @@ -79,6 +79,8 @@ int main(int argc, char **argv) wlContext = new WLContext(); wlContext->InitWLContext(&PointerListener, &KeyboardListener, &TouchListener); + int const fd = wl_display_get_fd(wlContext->GetWLDisplay()); + ilmClient_init((t_ilm_nativedisplay)wlContext->GetWLDisplay()); eglSurface = new WLEGLSurface(wlContext); @@ -100,12 +102,11 @@ int main(int argc, char **argv) gRunLoop = 1; gNeedRedraw = 0; while (gRunLoop){ - WaitForEvent(wlContext->GetWLDisplay()); + WaitForEvent(wlContext->GetWLDisplay(), fd); if (gNeedRedraw && gRunLoop){ DrawEyes(eglSurface, eyes); gNeedRedraw = 0; } - usleep(50); } TerminateRenderer(); |