From: Nobuhiko Tanibata Date: Wed, 15 Oct 2014 03:13:14 +0000 (+0900) Subject: clients: support ivi-application.xml for clients/simple-egl.c X-Git-Tag: upstream/0.1.8~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=19e71261b1df2dcb8556887c743f9687b02d2e74;p=profile%2Fivi%2Fweston-ivi-shell.git clients: support ivi-application.xml for clients/simple-egl.c Signed-off-by: Nobuhiko Tanibata Reviewed-by: Pekka Paalanen --- diff --git a/Makefile.am b/Makefile.am index 6c5321f..8999fed 100644 --- a/Makefile.am +++ b/Makefile.am @@ -441,7 +441,9 @@ demo_clients += weston-simple-egl weston_simple_egl_SOURCES = clients/simple-egl.c nodist_weston_simple_egl_SOURCES = \ protocol/xdg-shell-protocol.c \ - protocol/xdg-shell-client-protocol.h + protocol/xdg-shell-client-protocol.h \ + protocol/ivi-application-protocol.c \ + protocol/ivi-application-client-protocol.h weston_simple_egl_CFLAGS = $(AM_CFLAGS) $(SIMPLE_EGL_CLIENT_CFLAGS) weston_simple_egl_LDADD = $(SIMPLE_EGL_CLIENT_LIBS) -lm endif diff --git a/clients/simple-egl.c b/clients/simple-egl.c index 33e711c..d3c205f 100644 --- a/clients/simple-egl.c +++ b/clients/simple-egl.c @@ -41,6 +41,10 @@ #include #include "xdg-shell-client-protocol.h" +#include +#include +#include "protocol/ivi-application-client-protocol.h" +#define IVI_SURFACE_ID 9000 #ifndef EGL_EXT_swap_buffers_with_damage #define EGL_EXT_swap_buffers_with_damage 1 @@ -74,6 +78,7 @@ struct display { EGLConfig conf; } egl; struct window *window; + struct ivi_application *ivi_application; PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC swap_buffers_with_damage; }; @@ -95,6 +100,7 @@ struct window { struct wl_egl_window *native; struct wl_surface *surface; struct xdg_surface *xdg_surface; + struct ivi_surface *ivi_surface; EGLSurface egl_surface; struct wl_callback *callback; int fullscreen, opaque, buffer_size, frame_sync; @@ -255,7 +261,7 @@ init_gl(struct window *window) } glUseProgram(program); - + window->gl.pos = 0; window->gl.col = 1; @@ -316,18 +322,61 @@ static const struct xdg_surface_listener xdg_surface_listener = { }; static void -create_surface(struct window *window) +handle_ivi_surface_configure(void *data, struct ivi_surface *ivi_surface, + int32_t width, int32_t height) +{ + struct window *window = data; + + wl_egl_window_resize(window->native, width, height, 0, 0); + + window->geometry.width = width; + window->geometry.height = height; + + if (!window->fullscreen) + window->window_size = window->geometry; +} + +static const struct ivi_surface_listener ivi_surface_listener = { + handle_ivi_surface_configure, +}; + +static void +create_xdg_surface(struct window *window, struct display *display) { - struct display *display = window->display; - EGLBoolean ret; - - window->surface = wl_compositor_create_surface(display->compositor); window->xdg_surface = xdg_shell_get_xdg_surface(display->shell, window->surface); xdg_surface_add_listener(window->xdg_surface, &xdg_surface_listener, window); + xdg_surface_set_title(window->xdg_surface, "simple-egl"); +} + +static void +create_ivi_surface(struct window *window, struct display *display) +{ + uint32_t id_ivisurf = IVI_SURFACE_ID + (uint32_t)getpid(); + window->ivi_surface = + ivi_application_surface_create(display->ivi_application, + id_ivisurf, window->surface); + + if (window->ivi_surface == NULL) { + fprintf(stderr, "Failed to create ivi_client_surface\n"); + abort(); + } + + ivi_surface_add_listener(window->ivi_surface, + &ivi_surface_listener, window); +} + +static void +create_surface(struct window *window) +{ + struct display *display = window->display; + EGLBoolean ret; + + window->surface = wl_compositor_create_surface(display->compositor); + window->native = wl_egl_window_create(window->surface, window->geometry.width, @@ -337,7 +386,13 @@ create_surface(struct window *window) display->egl.conf, window->native, NULL); - xdg_surface_set_title(window->xdg_surface, "simple-egl"); + if (display->shell) { + create_xdg_surface(window, display); + } else if (display->ivi_application ) { + create_ivi_surface(window, display); + } else { + assert(0); + } ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface, window->egl_surface, window->display->egl.ctx); @@ -346,6 +401,9 @@ create_surface(struct window *window) if (!window->frame_sync) eglSwapInterval(display->egl.dpy, 0); + if (!display->shell) + return; + if (window->fullscreen) xdg_surface_set_fullscreen(window->xdg_surface, NULL); } @@ -361,7 +419,10 @@ destroy_surface(struct window *window) eglDestroySurface(window->display->egl.dpy, window->egl_surface); wl_egl_window_destroy(window->native); - xdg_surface_destroy(window->xdg_surface); + if (window->xdg_surface) + xdg_surface_destroy(window->xdg_surface); + if (window->display->ivi_application) + ivi_surface_destroy(window->ivi_surface); wl_surface_destroy(window->surface); if (window->callback) @@ -515,9 +576,12 @@ pointer_handle_button(void *data, struct wl_pointer *wl_pointer, { struct display *display = data; + if (!display->window->xdg_surface) + return; + if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) xdg_surface_move(display->window->xdg_surface, - display->seat, serial); + display->seat, serial); } static void @@ -541,6 +605,9 @@ touch_handle_down(void *data, struct wl_touch *wl_touch, { struct display *d = (struct display *)data; + if (!d->shell) + return; + xdg_surface_move(d->window->xdg_surface, d->seat, serial); } @@ -600,6 +667,9 @@ keyboard_handle_key(void *data, struct wl_keyboard *keyboard, { struct display *d = data; + if (!d->shell) + return; + if (key == KEY_F11 && state) { if (d->window->fullscreen) xdg_surface_unset_fullscreen(d->window->xdg_surface); @@ -710,6 +780,10 @@ registry_handle_global(void *data, struct wl_registry *registry, fprintf(stderr, "unable to load default left pointer\n"); // TODO: abort ? } + } else if (strcmp(interface, "ivi_application") == 0) { + d->ivi_application = + wl_registry_bind(registry, name, + &ivi_application_interface, 1); } } @@ -816,6 +890,9 @@ main(int argc, char **argv) if (display.shell) xdg_shell_destroy(display.shell); + if (display.ivi_application) + ivi_application_destroy(display.ivi_application); + if (display.compositor) wl_compositor_destroy(display.compositor);