[PATCH weston-ivi-shell v8 11/13] clients: support ivi-application.xml for clients/simple-egl.c

Nobuhiko Tanibata NOBUHIKO_TANIBATA at xddp.denso.co.jp
Wed Nov 26 20:24:42 PST 2014


Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA at xddp.denso.co.jp>
Reviewed-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
 Makefile.am          |  4 ++-
 clients/simple-egl.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 89 insertions(+), 10 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index e5fe359..de1d768 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -451,7 +451,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 <EGL/eglext.h>
 
 #include "xdg-shell-client-protocol.h"
+#include <sys/types.h>
+#include <unistd.h>
+#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);
 
-- 
1.8.3.1



More information about the wayland-devel mailing list