diff options
Diffstat (limited to 'ivi-layermanagement-examples/simple-weston-client/src/simple-weston-client.c')
-rw-r--r-- | ivi-layermanagement-examples/simple-weston-client/src/simple-weston-client.c | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/ivi-layermanagement-examples/simple-weston-client/src/simple-weston-client.c b/ivi-layermanagement-examples/simple-weston-client/src/simple-weston-client.c index 5b2c960..e101bf4 100644 --- a/ivi-layermanagement-examples/simple-weston-client/src/simple-weston-client.c +++ b/ivi-layermanagement-examples/simple-weston-client/src/simple-weston-client.c @@ -27,10 +27,17 @@ #include <errno.h> #include <fcntl.h> #include <sys/mman.h> +#include <assert.h> #include <wayland-cursor.h> #include <ivi-application-client-protocol.h> +#include "weston-debug-client-protocol.h" + +#ifndef MIN +#define MIN(x,y) (((x) < (y)) ? (x) : (y)) +#endif + typedef struct _BkGndSettings { uint32_t surface_id; @@ -45,6 +52,7 @@ typedef struct _WaylandContext { struct wl_compositor *wl_compositor; struct wl_shm *wl_shm; struct wl_seat *wl_seat; + struct weston_debug_v1 *debug_iface; struct wl_pointer *wl_pointer; struct wl_surface *wl_pointer_surface; struct ivi_application *ivi_application; @@ -56,8 +64,16 @@ typedef struct _WaylandContext { struct wl_cursor *cursor; void *bkgnddata; uint32_t formats; + struct wl_list stream_list; + int debug_fd; }WaylandContextStruct; +struct debug_stream { + struct wl_list link; + char *name; + struct weston_debug_stream_v1 *obj; +}; + static const char *left_ptrs[] = { "left_ptr", "default", @@ -88,6 +104,112 @@ get_bkgnd_settings(void) return bkgnd_settings; } +static struct debug_stream * +stream_alloc(WaylandContextStruct* wlcontext, const char *name) +{ + struct debug_stream *stream; + + stream = calloc(1, (sizeof *stream)); + if (!stream) + return NULL; + + stream->name = strdup(name); + if (!stream->name) { + free(stream); + return NULL; + } + + wl_list_insert(wlcontext->stream_list.prev, &stream->link); + + return stream; +} + +static void +stream_destroy(struct debug_stream *stream) +{ + if (stream->obj) + weston_debug_stream_v1_destroy(stream->obj); + + wl_list_remove(&stream->link); + free(stream->name); + free(stream); +} + +static void +destroy_streams(WaylandContextStruct* wlcontext) +{ + struct debug_stream *stream; + struct debug_stream *tmp; + + wl_list_for_each_safe(stream, tmp, &wlcontext->stream_list, link) { + stream_destroy(stream); + } +} + +static void +handle_stream_complete(void *data, struct weston_debug_stream_v1 *obj) +{ + struct debug_stream *stream = data; + + assert(stream->obj == obj); + + stream_destroy(stream); +} + +static void +handle_stream_failure(void *data, struct weston_debug_stream_v1 *obj, + const char *msg) +{ + struct debug_stream *stream = data; + + assert(stream->obj == obj); + + fprintf(stderr, "Debug stream '%s' aborted: %s\n", stream->name, msg); + + stream_destroy(stream); +} + +static const struct weston_debug_stream_v1_listener stream_listener = { + handle_stream_complete, + handle_stream_failure +}; + +static void +start_streams(WaylandContextStruct* wlcontext) +{ + struct debug_stream *stream; + + wl_list_for_each(stream, &wlcontext->stream_list, link) { + stream->obj = weston_debug_v1_subscribe(wlcontext->debug_iface, + stream->name, + wlcontext->debug_fd); + weston_debug_stream_v1_add_listener(stream->obj, + &stream_listener, stream); + } +} + +static void +get_debug_streams(WaylandContextStruct* wlcontext) +{ + char *stream_names; + char *stream; + const char separator[2] = " "; + + stream_names = getenv("IVI_CLIENT_DEBUG_STREAM_NAMES"); + + if(NULL == stream_names) + return; + + /* get the first stream */ + stream = strtok(stream_names, separator); + + /* walk through other streams */ + while( stream != NULL ) { + stream_alloc(wlcontext, stream); + stream = strtok(NULL, separator); + } +} + static void shm_format(void *data, struct wl_shm *wl_shm, uint32_t format) { @@ -299,6 +421,17 @@ registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, wl_registry_bind(registry, name, &wl_seat_interface, 1); wl_seat_add_listener(wlcontext->wl_seat, &seat_Listener, data); } + if (!strcmp(interface, weston_debug_v1_interface.name)) { + uint32_t myver; + + if (wlcontext->debug_iface || wl_list_empty(&wlcontext->stream_list)) + return; + + myver = MIN(1, version); + wlcontext->debug_iface = + wl_registry_bind(registry, name, + &weston_debug_v1_interface, myver); + } } static void @@ -348,6 +481,9 @@ void destroy_wayland_context(WaylandContextStruct* wlcontext) if(wlcontext->wl_display) wl_display_disconnect(wlcontext->wl_display); + + if(wlcontext->debug_iface) + weston_debug_v1_destroy(wlcontext->debug_iface); } int @@ -500,6 +636,12 @@ int main (int argc, const char * argv[]) /*init wayland context*/ wlcontext = (WaylandContextStruct*)calloc(1, sizeof(WaylandContextStruct)); wlcontext->bkgnd_settings = bkgnd_settings; + + /*init debug stream list*/ + wl_list_init(&wlcontext->stream_list); + get_debug_streams(wlcontext); + wlcontext->debug_fd = STDOUT_FILENO; + if (init_wayland_context(wlcontext)) { fprintf(stderr, "init_wayland_context failed\n"); goto ErrorContext; @@ -512,6 +654,11 @@ int main (int argc, const char * argv[]) wl_display_roundtrip(wlcontext->wl_display); + if (!wl_list_empty(&wlcontext->stream_list) && + wlcontext->debug_iface) { + start_streams(wlcontext); + } + /*draw the bkgnd display*/ draw_bkgnd_surface(wlcontext); @@ -519,6 +666,7 @@ int main (int argc, const char * argv[]) ret = wl_display_dispatch(wlcontext->wl_display); Error: + destroy_streams(wlcontext); destroy_bkgnd_surface(wlcontext); ErrorContext: destroy_wayland_context(wlcontext); |