[PATCH weston-ivi-shell v6 2/9] ivi-shell: add the shell plugin for In-Vehicle Infotainment system
Nobuhiko Tanibata
NOBUHIKO_TANIBATA at xddp.denso.co.jp
Wed Jun 25 05:06:19 PDT 2014
In-Vehicle Infotainment system traditionally manages surfaces with global
identification. A protocol, ivi_application, supports such a feature by
implementing a request, ivi_application::surface_creation defined in
ivi_application.xml.
The ivi-shell explicitly loads ivi-layout.so and a module to add business
logic like how to layout surfaces by using ivi-layout APIs.
Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA at xddp.denso.co.jp>
---
Changes for v2:
- apply review comments of mailing list.
- squash update of Makefile into this patch.
- move this patch after patch of weston-layout.
- support inherit propoerties of id_surface when client attaches another
wl_surface with id_surface after destroying ivi_surface once.
Changes for v3:
- squash internal method, configure, to ivi_shell_surface_configure.
Changes for v4:
- nothing. Version number aligned to the first patch
Changes for v5:
- rebase weston v1.5 branch
- apply review comments from mailing list
Changes for v6:
- apply bug fixes found in TIZEN IVI and GENIVI
- apply review comments from Mailing list
- use signed integers except flags, bitfields, object ids.
Makefile.am | 22 +++
configure.ac | 12 ++
ivi-shell/ivi-layout.h | 75 +++++++++
ivi-shell/ivi-shell.c | 413 +++++++++++++++++++++++++++++++++++++++++++++++++
ivi-shell/ivi-shell.h | 35 +++++
5 files changed, 557 insertions(+)
create mode 100644 ivi-shell/ivi-layout.h
create mode 100644 ivi-shell/ivi-shell.c
create mode 100644 ivi-shell/ivi-shell.h
diff --git a/Makefile.am b/Makefile.am
index 343adc6..279fffc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -700,6 +700,28 @@ nodist_fullscreen_shell_la_SOURCES = \
BUILT_SOURCES += $(nodist_fullscreen_shell_la_SOURCES)
endif
+if ENABLE_IVI_SHELL
+
+module_LTLIBRARIES += \
+ $(ivi_shell)
+
+ivi_shell = ivi-shell.la
+ivi_shell_la_LDFLAGS = -module -avoid-version
+ivi_shell_la_LIBADD = $(COMPOSITOR_LIBS) $(IVI_SHELL_LIBS) libshared.la
+ivi_shell_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS) $(IVI_SHELL_CFLAGS)
+ivi_shell_la_SOURCES = \
+ ivi-shell/ivi-shell.h \
+ ivi-shell/ivi-shell.c \
+ ivi-shell/ivi-layout.h
+nodist_ivi_shell_la_SOURCES = \
+ protocol/ivi-application-protocol.c \
+ protocol/ivi-application-server-protocol.h
+
+BUILT_SOURCES += $(nodist_ivi_shell_la_SOURCES)
+
+endif
+
+
if ENABLE_SCREEN_SHARING
module_LTLIBRARIES += screen-share.la
diff --git a/configure.ac b/configure.ac
index 031a26f..23e6ba5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -433,6 +433,16 @@ if test "x$enable_dbus" != "xno"; then
fi
AM_CONDITIONAL(ENABLE_DBUS, test "x$enable_dbus" = "xyes")
+# ivi-shell support
+AC_ARG_ENABLE(ivi-shell,
+ AS_HELP_STRING([--disable-ivi-shell],
+ [do not build ivi-shell server plugin and client]),,
+ enable_ivi_shell=yes)
+AM_CONDITIONAL(ENABLE_IVI_SHELL, test "x$enable_ivi_shell" = "xyes")
+if test x$enable_ivi_shell = xyes; then
+ PKG_CHECK_MODULES(IVI_SHELL, [cairo])
+fi
+
AC_ARG_ENABLE(wcap-tools, [ --disable-wcap-tools],, enable_wcap_tools=yes)
AM_CONDITIONAL(BUILD_WCAP_TOOLS, test x$enable_wcap_tools = xyes)
if test x$enable_wcap_tools = xyes; then
@@ -522,6 +532,8 @@ AC_MSG_RESULT([
XWayland ${enable_xwayland}
dbus ${enable_dbus}
+ ivi-shell ${enable_ivi_shell}
+
Build wcap utility ${enable_wcap_tools}
Build Fullscreen Shell ${enable_fullscreen_shell}
diff --git a/ivi-shell/ivi-layout.h b/ivi-shell/ivi-layout.h
new file mode 100644
index 0000000..2027d89
--- /dev/null
+++ b/ivi-shell/ivi-layout.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2013 DENSO CORPORATION
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/**
+ * The ivi-layout library supports API set of controlling properties of
+ * surface and layer which groups surfaces. An unique ID whose type is integer
+ * is required to create surface and layer. With the unique ID, surface and
+ * layer are identified to control them. The API set consists of APIs to control
+ * properties of surface and layers about followings,
+ * - visibility.
+ * - opacity.
+ * - clipping (x,y,width,height).
+ * - position and size of it to be displayed.
+ * - orientation per 90 degree.
+ * - add or remove surfaces to a layer.
+ * - order of surfaces/layers in layer/screen to be displayed.
+ * - commit to apply property changes.
+ * - notifications of property change.
+ *
+ * Management of surfaces and layers grouping these surfaces are common way in
+ * In-Vehicle Infotainment system, which integrate several domains in one system.
+ * A layer is allocated to a domain in order to control application surfaces
+ * grouped to the layer all together.
+ */
+
+#ifndef _IVI_LAYOUT_H_
+#define _IVI_LAYOUT_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "compositor.h"
+
+struct ivi_layout_surface;
+
+struct ivi_layout_interface {
+ struct weston_view* (*get_weston_view)(struct ivi_layout_surface *surface);
+ void (*surfaceConfigure)(struct ivi_layout_surface *ivisurf,
+ int32_t width, int32_t height);
+ int32_t (*surfaceSetNativeContent)(struct weston_surface *wl_surface,
+ int32_t width,
+ int32_t height,
+ uint32_t id_surface);
+ struct ivi_layout_surface* (*surfaceCreate)(struct weston_surface *wl_surface,
+ uint32_t id_surface);
+ void (*initWithCompositor)(struct weston_compositor *ec);
+};
+
+WL_EXPORT struct ivi_layout_interface ivi_layout_interface;
+
+#ifdef __cplusplus
+} /**/
+#endif /* __cplusplus */
+
+#endif /* _IVI_LAYOUT_H_ */
diff --git a/ivi-shell/ivi-shell.c b/ivi-shell/ivi-shell.c
new file mode 100644
index 0000000..1f188ce
--- /dev/null
+++ b/ivi-shell/ivi-shell.c
@@ -0,0 +1,413 @@
+/*
+ * Copyright (C) 2013 DENSO CORPORATION
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+
+/**
+ * ivi-shell supports a type of shell for In-Vehicle Infotainment system.
+ * In-Vehicle Infotainment system traditionally manages surfaces with global
+ * identification. A protocol, ivi_application, supports such a feature
+ * by implementing a request, ivi_application::surface_creation defined in
+ * ivi_application.xml.
+ *
+ * The ivi-shell explicitly loads a module to add business logic like how to
+ * layout surfaces by using internal ivi-layout APIs.
+ */
+#include "config.h"
+
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <linux/input.h>
+#include <dlfcn.h>
+#include <limits.h>
+
+#include "ivi-shell.h"
+#include "ivi-application-server-protocol.h"
+#include "ivi-layout.h"
+
+#include "../shared/os-compatibility.h"
+
+struct ivi_shell_surface
+{
+ struct ivi_shell *shell;
+ struct ivi_layout_surface *layout_surface;
+
+ struct weston_surface *surface;
+ uint32_t id_surface;
+
+ int32_t width;
+ int32_t height;
+
+ struct wl_list link;
+};
+
+struct ivi_shell_setting
+{
+ char *ivi_module;
+};
+
+static struct ivi_layout_interface *ivi_layout;
+
+/* ------------------------------------------------------------------------- */
+
+ /* common functions */
+/* ------------------------------------------------------------------------- */
+
+/**
+ * Implementation of ivi_surface
+ */
+
+static void
+ivi_shell_surface_configure(struct weston_surface *, int32_t, int32_t);
+
+static struct ivi_shell_surface *
+get_ivi_shell_surface(struct weston_surface *surface)
+{
+ if (surface->configure == ivi_shell_surface_configure) {
+ return surface->configure_private;
+ } else {
+ return NULL;
+ }
+}
+
+static void
+ivi_shell_surface_configure(struct weston_surface *surface,
+ int32_t sx, int32_t sy)
+{
+ struct ivi_shell_surface *ivisurf = get_ivi_shell_surface(surface);
+ struct weston_view *view = NULL;
+ float from_x = 0.0f;
+ float from_y = 0.0f;
+ float to_x = 0.0f;
+ float to_y = 0.0f;
+
+ if ((surface->width == 0) || (surface->height == 0) || (ivisurf == NULL)) {
+ return;
+ }
+
+ view = ivi_layout->get_weston_view(ivisurf->layout_surface);
+ if (view == NULL) {
+ return;
+ }
+
+ if (ivisurf->width != surface->width || ivisurf->height != surface->height) {
+
+ ivisurf->width = surface->width;
+ ivisurf->height = surface->height;
+
+ weston_view_to_global_float(view, 0, 0, &from_x, &from_y);
+ weston_view_to_global_float(view, sx, sy, &to_x, &to_y);
+
+ weston_view_set_position(view,
+ view->geometry.x + to_x - from_x,
+ view->geometry.y + to_y - from_y);
+ weston_view_update_transform(view);
+
+ ivi_layout->surfaceConfigure(ivisurf->layout_surface, surface->width, surface->height);
+ }
+}
+
+static void
+surface_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+ struct ivi_shell_surface *ivisurf = wl_resource_get_user_data(resource);
+ if (ivisurf != NULL) {
+ ivisurf->surface->configure = NULL;
+ ivisurf->surface->configure_private = NULL;
+ ivisurf->surface = NULL;
+ ivi_layout->surfaceSetNativeContent(NULL, 0, 0, ivisurf->id_surface);
+ }
+
+ wl_resource_destroy(resource);
+}
+
+static const struct ivi_surface_interface surface_implementation = {
+ surface_destroy,
+};
+
+static struct ivi_shell_surface *
+is_surf_in_surfaces(struct wl_list *list_surf, uint32_t id_surface)
+{
+ struct ivi_shell_surface *ivisurf;
+
+ wl_list_for_each(ivisurf, list_surf, link) {
+ if (ivisurf->id_surface == id_surface) {
+ return ivisurf;
+ }
+ }
+
+ return NULL;
+}
+
+static const struct {
+ uint32_t warning_code; /* enum ivi_surface_warning_code */
+ const char *msg;
+} warning_strings[] = {
+ {IVI_SURFACE_WARNING_CODE_INVALID_WL_SURFACE, "wl_surface is invalid"},
+ {IVI_SURFACE_WARNING_CODE_IVI_ID_IN_USE, "surface_id is already assigned by another app"}
+};
+
+/**
+ * Implementation of ivi_application::surface_create.
+ * Creating new ivi_shell_surface with identification to identify the surface
+ * in the system.
+ */
+static void
+application_surface_create(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id_surface,
+ struct wl_resource *surface_resource,
+ uint32_t id)
+{
+ struct ivi_shell *shell = wl_resource_get_user_data(resource);
+ struct ivi_shell_surface *ivisurf = NULL;
+ struct ivi_layout_surface *layout_surface = NULL;
+ struct weston_surface *weston_surface = wl_resource_get_user_data(surface_resource);
+ struct wl_resource *res;
+ int32_t warn_idx = -1;
+
+ if (weston_surface != NULL) {
+
+ /* check if a surface already has another role*/
+ if (weston_surface->configure) {
+ wl_resource_post_error(weston_surface->resource,
+ WL_DISPLAY_ERROR_INVALID_OBJECT,
+ "surface->configure already "
+ "set");
+ return;
+ }
+
+ layout_surface = ivi_layout->surfaceCreate(weston_surface, id_surface);
+
+ if (layout_surface == NULL)
+ warn_idx = 1;
+ } else {
+ warn_idx = 0;
+ }
+
+ res = wl_resource_create(client, &ivi_surface_interface, 1, id);
+ if (res == NULL) {
+ wl_client_post_no_memory(client);
+ return;
+ }
+
+ if (warn_idx >= 0) {
+ wl_resource_set_implementation(res, &surface_implementation,
+ NULL, NULL);
+ ivi_surface_send_warning(res,
+ warning_strings[warn_idx].warning_code,
+ warning_strings[warn_idx].msg);
+ return;
+ }
+
+ ivisurf = is_surf_in_surfaces(&shell->ivi_surface_list, id_surface);
+ if (ivisurf == NULL) {
+ ivisurf = zalloc(sizeof *ivisurf);
+ if (ivisurf == NULL) {
+ wl_resource_post_no_memory(res);
+ return;
+ }
+
+ wl_list_init(&ivisurf->link);
+ wl_list_insert(&shell->ivi_surface_list, &ivisurf->link);
+
+ ivisurf->shell = shell;
+ ivisurf->id_surface = id_surface;
+ }
+
+ ivisurf->width = 0;
+ ivisurf->height = 0;
+ ivisurf->layout_surface = layout_surface;
+ ivisurf->surface = weston_surface;
+
+ weston_surface->configure = ivi_shell_surface_configure;
+ weston_surface->configure_private = ivisurf;
+
+ wl_resource_set_implementation(res, &surface_implementation,
+ ivisurf, NULL);
+}
+
+static const struct ivi_application_interface application_implementation = {
+ application_surface_create
+};
+
+static void
+bind_ivi_application(struct wl_client *client,
+ void *data, uint32_t version, uint32_t id)
+{
+ struct ivi_shell *shell = data;
+ struct wl_resource *resource = NULL;
+
+ resource = wl_resource_create(client, &ivi_application_interface, 1, id);
+
+ wl_resource_set_implementation(resource,
+ &application_implementation,
+ shell, NULL);
+}
+
+/**
+ * Initialization/destruction method of ivi-shell
+ */
+static void
+shell_destroy(struct wl_listener *listener, void *data)
+{
+ struct ivi_shell *shell =
+ container_of(listener, struct ivi_shell, destroy_listener);
+ struct ivi_shell_surface *ivisurf, *next;
+
+ wl_list_for_each_safe(ivisurf, next, &shell->ivi_surface_list, link) {
+ wl_list_remove(&ivisurf->link);
+ free(ivisurf);
+ }
+
+ free(shell);
+}
+
+static void
+init_ivi_shell(struct weston_compositor *compositor, struct ivi_shell *shell)
+{
+ shell->compositor = compositor;
+
+ wl_list_init(&shell->ivi_surface_list);
+}
+
+static int
+ivi_shell_setting_create(struct ivi_shell_setting *dest)
+{
+ int result = 0;
+ struct weston_config *config = NULL;
+ struct weston_config_section *section = NULL;
+
+ if (NULL == dest) {
+ return -1;
+ }
+
+ config = weston_config_parse("weston.ini");
+ section = weston_config_get_section(config, "ivi-shell", NULL, NULL);
+
+ if (weston_config_section_get_string(
+ section, "ivi-module", (char **)&dest->ivi_module, NULL) != 0)
+ {
+ result = -1;
+ }
+
+ weston_config_destroy(config);
+ return result;
+}
+
+/**
+ * Initialization of ivi-shell.
+ */
+static int
+ivi_load_modules(struct weston_compositor *compositor, const char *modules,
+ int *argc, char *argv[])
+{
+ const char *p, *end;
+ char buffer[256];
+ int (*module_init)(struct weston_compositor *compositor,
+ int *argc, char *argv[]);
+
+ if (modules == NULL)
+ return 0;
+
+ p = modules;
+ while (*p) {
+ end = strchrnul(p, ',');
+ snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
+ module_init = weston_load_module(buffer, "module_init");
+ if (module_init)
+ module_init(compositor, argc, argv);
+ p = end;
+ while (*p == ',')
+ p++;
+
+ }
+
+ return 0;
+}
+
+WL_EXPORT int
+module_init(struct weston_compositor *compositor,
+ int *argc, char *argv[])
+{
+ struct ivi_shell *shell = NULL;
+ char ivi_layout_path[PATH_MAX];
+ void *module;
+ struct ivi_shell_setting setting = { };
+
+ shell = zalloc(sizeof *shell);
+ if (shell == NULL) {
+ return -1;
+ }
+
+ init_ivi_shell(compositor, shell);
+
+ shell->destroy_listener.notify = shell_destroy;
+ wl_signal_add(&compositor->destroy_signal, &shell->destroy_listener);
+
+ if (wl_global_create(compositor->wl_display, &ivi_application_interface, 1,
+ shell, bind_ivi_application) == NULL) {
+ return -1;
+ }
+
+ if (ivi_shell_setting_create(&setting) != 0) {
+ return 0;
+ }
+
+ /*load module:ivi-layout*/
+ /*ivi_layout_interface is referred by ivi-shell to use ivi-layout*/
+ snprintf(ivi_layout_path, sizeof ivi_layout_path, "%s/%s", MODULEDIR, "ivi-layout.so");
+ module = dlopen(ivi_layout_path, RTLD_NOW | RTLD_NOLOAD);
+ if (module) {
+ weston_log("ivi-shell: Module '%s' already loaded\n", ivi_layout_path);
+ dlclose(module);
+ return -1;
+ }
+
+ weston_log("ivi-shell: Loading module '%s'\n", ivi_layout_path);
+ module = dlopen(ivi_layout_path, RTLD_NOW | RTLD_GLOBAL);
+ if (!module) {
+ weston_log("ivi-shell: Failed to load module: %s\n", dlerror());
+ return -1;
+ }
+
+ ivi_layout = dlsym(module,"ivi_layout_interface");
+ if (!ivi_layout){
+ weston_log("ivi-shell: couldn't find ivi_layout_interface in '%s'\n", ivi_layout_path);
+ free(setting.ivi_module);
+ return -1;
+ }
+ else{
+ ivi_layout->initWithCompositor(compositor);
+ }
+
+ /*Call module_init of ivi-modules which are defined in weston.ini*/
+ if (ivi_load_modules(compositor,setting.ivi_module,argc,argv) < 0){
+ free(setting.ivi_module);
+ return -1;
+ }
+
+ free(setting.ivi_module);
+ return 0;
+}
diff --git a/ivi-shell/ivi-shell.h b/ivi-shell/ivi-shell.h
new file mode 100644
index 0000000..157c5ae
--- /dev/null
+++ b/ivi-shell/ivi-shell.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2013 DENSO CORPORATION
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdbool.h>
+
+#include "compositor.h"
+
+struct ivi_shell
+{
+ struct wl_resource *resource;
+ struct wl_listener destroy_listener;
+
+ struct weston_compositor *compositor;
+
+ struct wl_list ivi_surface_list; /* struct ivi_shell_surface::link */
+};
--
1.8.3.1
More information about the wayland-devel
mailing list