2014-11-27 04:22:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 DENSO CORPORATION
|
|
|
|
*
|
2015-06-11 19:55:55 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
2014-11-27 04:22:37 +00:00
|
|
|
*
|
2015-06-11 19:55:55 +00:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2014-11-27 04:22:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 <string.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <assert.h>
|
2015-02-19 15:12:19 +00:00
|
|
|
#include <linux/input.h>
|
2014-11-27 04:22:37 +00:00
|
|
|
|
|
|
|
#include "ivi-shell.h"
|
|
|
|
#include "ivi-application-server-protocol.h"
|
2014-12-15 04:22:31 +00:00
|
|
|
#include "ivi-layout-export.h"
|
2016-03-15 15:21:00 +00:00
|
|
|
#include "ivi-layout-shell.h"
|
2015-06-15 22:37:08 +00:00
|
|
|
#include "shared/helpers.h"
|
2016-06-02 18:48:11 +00:00
|
|
|
#include "weston.h"
|
2014-11-27 04:22:37 +00:00
|
|
|
|
|
|
|
/* Representation of ivi_surface protocol object. */
|
|
|
|
struct ivi_shell_surface
|
|
|
|
{
|
|
|
|
struct wl_resource* resource;
|
|
|
|
struct ivi_shell *shell;
|
|
|
|
struct ivi_layout_surface *layout_surface;
|
|
|
|
|
|
|
|
struct weston_surface *surface;
|
|
|
|
struct wl_listener surface_destroy_listener;
|
|
|
|
|
|
|
|
uint32_t id_surface;
|
|
|
|
|
|
|
|
int32_t width;
|
|
|
|
int32_t height;
|
|
|
|
|
|
|
|
struct wl_list link;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ivi_shell_setting
|
|
|
|
{
|
|
|
|
char *ivi_module;
|
2015-02-19 15:08:44 +00:00
|
|
|
int developermode;
|
2014-11-27 04:22:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
2016-03-16 12:54:12 +00:00
|
|
|
struct ivi_shell_surface *shsurf;
|
2014-11-27 04:22:37 +00:00
|
|
|
|
2016-03-16 12:54:12 +00:00
|
|
|
if (surface->configure != ivi_shell_surface_configure)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
shsurf = surface->configure_private;
|
|
|
|
assert(shsurf);
|
|
|
|
assert(shsurf->surface == surface);
|
|
|
|
|
|
|
|
return shsurf;
|
2014-11-27 04:22:37 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 13:06:58 +00:00
|
|
|
struct ivi_layout_surface *
|
|
|
|
shell_get_ivi_layout_surface(struct weston_surface *surface)
|
|
|
|
{
|
|
|
|
struct ivi_shell_surface *shsurf;
|
|
|
|
|
|
|
|
shsurf = get_ivi_shell_surface(surface);
|
|
|
|
if (!shsurf)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return shsurf->layout_surface;
|
|
|
|
}
|
|
|
|
|
2016-03-15 14:57:51 +00:00
|
|
|
void
|
|
|
|
shell_surface_send_configure(struct weston_surface *surface,
|
|
|
|
int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
struct ivi_shell_surface *shsurf;
|
|
|
|
|
|
|
|
shsurf = get_ivi_shell_surface(surface);
|
|
|
|
assert(shsurf);
|
|
|
|
if (!shsurf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (shsurf->resource)
|
|
|
|
ivi_surface_send_configure(shsurf->resource, width, height);
|
|
|
|
}
|
|
|
|
|
2014-11-27 04:22:37 +00:00
|
|
|
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);
|
|
|
|
|
2016-03-16 13:05:03 +00:00
|
|
|
assert(ivisurf);
|
|
|
|
if (!ivisurf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (surface->width == 0 || surface->height == 0)
|
2014-11-27 04:22:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (ivisurf->width != surface->width ||
|
|
|
|
ivisurf->height != surface->height) {
|
|
|
|
ivisurf->width = surface->width;
|
|
|
|
ivisurf->height = surface->height;
|
|
|
|
|
2014-12-15 04:22:31 +00:00
|
|
|
ivi_layout_surface_configure(ivisurf->layout_surface,
|
|
|
|
surface->width, surface->height);
|
2014-11-27 04:22:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 14:19:37 +00:00
|
|
|
static int
|
|
|
|
ivi_shell_surface_get_label(struct weston_surface *surface,
|
|
|
|
char *buf,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
struct ivi_shell_surface *shell_surf = get_ivi_shell_surface(surface);
|
|
|
|
|
|
|
|
if (!shell_surf)
|
|
|
|
return snprintf(buf, len, "unidentified window in ivi-shell");
|
|
|
|
|
|
|
|
return snprintf(buf, len, "ivi-surface %#x", shell_surf->id_surface);
|
|
|
|
}
|
|
|
|
|
2015-06-22 06:30:53 +00:00
|
|
|
static void
|
|
|
|
layout_surface_cleanup(struct ivi_shell_surface *ivisurf)
|
|
|
|
{
|
|
|
|
assert(ivisurf->layout_surface != NULL);
|
|
|
|
|
|
|
|
ivi_layout_surface_destroy(ivisurf->layout_surface);
|
|
|
|
ivisurf->layout_surface = NULL;
|
|
|
|
|
|
|
|
ivisurf->surface->configure = NULL;
|
|
|
|
ivisurf->surface->configure_private = NULL;
|
2016-03-07 14:19:37 +00:00
|
|
|
weston_surface_set_label_func(ivisurf->surface, NULL);
|
2015-06-22 06:30:53 +00:00
|
|
|
ivisurf->surface = NULL;
|
|
|
|
|
|
|
|
// destroy weston_surface destroy signal.
|
|
|
|
wl_list_remove(&ivisurf->surface_destroy_listener.link);
|
|
|
|
}
|
|
|
|
|
2014-11-27 04:22:37 +00:00
|
|
|
/*
|
|
|
|
* The ivi_surface wl_resource destructor.
|
|
|
|
*
|
|
|
|
* Gets called via ivi_surface.destroy request or automatic wl_client clean-up.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
shell_destroy_shell_surface(struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
struct ivi_shell_surface *ivisurf = wl_resource_get_user_data(resource);
|
2015-06-22 06:31:08 +00:00
|
|
|
|
|
|
|
if (ivisurf == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(ivisurf->resource == resource);
|
|
|
|
|
|
|
|
if (ivisurf->layout_surface != NULL)
|
|
|
|
layout_surface_cleanup(ivisurf);
|
|
|
|
|
|
|
|
wl_list_remove(&ivisurf->link);
|
|
|
|
|
|
|
|
free(ivisurf);
|
2014-11-27 04:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Gets called through the weston_surface destroy signal. */
|
|
|
|
static void
|
|
|
|
shell_handle_surface_destroy(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct ivi_shell_surface *ivisurf =
|
|
|
|
container_of(listener, struct ivi_shell_surface,
|
|
|
|
surface_destroy_listener);
|
|
|
|
|
|
|
|
assert(ivisurf != NULL);
|
|
|
|
|
2015-06-22 06:30:53 +00:00
|
|
|
if (ivisurf->layout_surface != NULL)
|
|
|
|
layout_surface_cleanup(ivisurf);
|
2014-11-27 04:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Gets called, when a client sends ivi_surface.destroy request. */
|
|
|
|
static void
|
|
|
|
surface_destroy(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Fires the wl_resource destroy signal, and then calls
|
|
|
|
* ivi_surface wl_resource destructor: shell_destroy_shell_surface()
|
|
|
|
*/
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ivi_surface_interface surface_implementation = {
|
|
|
|
surface_destroy,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request handler for ivi_application.surface_create.
|
|
|
|
*
|
|
|
|
* Creates an ivi_surface protocol object associated with the given wl_surface.
|
|
|
|
* ivi_surface protocol object is represented by struct ivi_shell_surface.
|
|
|
|
*
|
|
|
|
* \param client The client.
|
|
|
|
* \param resource The ivi_application protocol object.
|
|
|
|
* \param id_surface The IVI surface ID.
|
|
|
|
* \param surface_resource The wl_surface protocol object.
|
|
|
|
* \param id The protocol object id for the new ivi_surface protocol object.
|
|
|
|
*
|
|
|
|
* The wl_surface is given the ivi_surface role and associated with a unique
|
|
|
|
* IVI ID which is used to identify the surface in a controller
|
|
|
|
* (window manager).
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
struct ivi_layout_surface *layout_surface;
|
|
|
|
struct weston_surface *weston_surface =
|
|
|
|
wl_resource_get_user_data(surface_resource);
|
|
|
|
struct wl_resource *res;
|
|
|
|
|
|
|
|
if (weston_surface_set_role(weston_surface, "ivi_surface",
|
|
|
|
resource, IVI_APPLICATION_ERROR_ROLE) < 0)
|
|
|
|
return;
|
|
|
|
|
2014-12-15 04:22:31 +00:00
|
|
|
layout_surface = ivi_layout_surface_create(weston_surface, id_surface);
|
2014-11-27 04:22:37 +00:00
|
|
|
|
|
|
|
/* check if id_ivi is already used for wl_surface*/
|
2015-08-06 20:12:19 +00:00
|
|
|
if (layout_surface == NULL) {
|
2014-11-27 04:22:37 +00:00
|
|
|
wl_resource_post_error(resource,
|
|
|
|
IVI_APPLICATION_ERROR_IVI_ID,
|
|
|
|
"surface_id is already assigned "
|
|
|
|
"by another app");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ivisurf = zalloc(sizeof *ivisurf);
|
|
|
|
if (ivisurf == NULL) {
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
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;
|
2016-03-15 14:57:51 +00:00
|
|
|
|
2014-11-27 04:22:37 +00:00
|
|
|
/*
|
|
|
|
* The following code relies on wl_surface destruction triggering
|
|
|
|
* immediateweston_surface destruction
|
|
|
|
*/
|
|
|
|
ivisurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
|
|
|
|
wl_signal_add(&weston_surface->destroy_signal,
|
|
|
|
&ivisurf->surface_destroy_listener);
|
|
|
|
|
|
|
|
ivisurf->surface = weston_surface;
|
|
|
|
|
|
|
|
weston_surface->configure = ivi_shell_surface_configure;
|
|
|
|
weston_surface->configure_private = ivisurf;
|
2016-03-07 14:19:37 +00:00
|
|
|
weston_surface_set_label_func(weston_surface,
|
|
|
|
ivi_shell_surface_get_label);
|
2014-11-27 04:22:37 +00:00
|
|
|
|
|
|
|
res = wl_resource_create(client, &ivi_surface_interface, 1, id);
|
|
|
|
if (res == NULL) {
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ivisurf->resource = res;
|
|
|
|
|
|
|
|
wl_resource_set_implementation(res, &surface_implementation,
|
|
|
|
ivisurf, shell_destroy_shell_surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ivi_application_interface application_implementation = {
|
|
|
|
application_surface_create
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle wl_registry.bind of ivi_application global singleton.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
|
|
|
resource = wl_resource_create(client, &ivi_application_interface,
|
|
|
|
1, id);
|
|
|
|
|
|
|
|
wl_resource_set_implementation(resource,
|
|
|
|
&application_implementation,
|
|
|
|
shell, NULL);
|
|
|
|
}
|
|
|
|
|
2014-11-27 04:25:34 +00:00
|
|
|
struct weston_view *
|
|
|
|
get_default_view(struct weston_surface *surface)
|
|
|
|
{
|
|
|
|
struct weston_view *view;
|
|
|
|
|
|
|
|
if (!surface || wl_list_empty(&surface->views))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
wl_list_for_each(view, &surface->views, surface_link) {
|
|
|
|
if (weston_view_is_mapped(view))
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
return container_of(surface->views.next,
|
|
|
|
struct weston_view, surface_link);
|
|
|
|
}
|
|
|
|
|
2014-11-27 04:22:37 +00:00
|
|
|
/*
|
|
|
|
* Called through the compositor's destroy signal.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
text_backend: make destructor call explicit
We used to rely on the order in which the
weston_compositor::destroy_signal callbacks happened, to not access
freed memory. Don't know when, but this broke at least with ivi-shell,
which caused crashes in random places on compositor shutdown.
Valgrind found the following:
Invalid write of size 8
at 0xC2EDC69: unbind_input_panel (input-panel-ivi.c:340)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea360 is 208 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Invalid write of size 8
at 0x4E3E0D7: wl_list_remove (wayland-util.c:57)
by 0xC2EDEE9: destroy_input_panel_surface (input-panel-ivi.c:191)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3BC7B: wl_resource_destroy (wayland-server.c:550)
by 0x40DB8B: wl_signal_emit (wayland-server-core.h:264)
by 0x40DB8B: weston_surface_destroy (compositor.c:1883)
by 0x40DB8B: weston_surface_destroy (compositor.c:1873)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea370 is 224 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Invalid write of size 8
at 0x4E3E0E7: wl_list_remove (wayland-util.c:58)
by 0xC2EDEE9: destroy_input_panel_surface (input-panel-ivi.c:191)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3BC7B: wl_resource_destroy (wayland-server.c:550)
by 0x40DB8B: wl_signal_emit (wayland-server-core.h:264)
by 0x40DB8B: weston_surface_destroy (compositor.c:1883)
by 0x40DB8B: weston_surface_destroy (compositor.c:1873)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea368 is 216 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Looking at the first of these, unbind_input_panel() gets called when the
text-backend destroys its helper client which has bound to input_panel
interface. This happens after the shell's destroy_signal callback has
been called, so the shell has already been freed.
The other two errors come from
wl_list_remove(&input_panel_surface->link);
which has gone stale when the shell was destroyed
(shell->input_panel.surfaces list).
Rather than creating even more destroy listeners and hooking them up in
spaghetti, modify text-backend to not hook up to the compositor destroy
signal. Instead, make it the text_backend_init() callers' responsibility
to also call text_backend_destroy() appropriately, before the shell goes
away.
This fixed all the above Valgrind errors, and avoid a crash with
ivi-shell when exiting Weston.
Also using desktop-shell exhibited similar Valgrind errors which are
fixed by this patch, but those didn't happen to cause any crashes AFAIK.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-By: Derek Foreman <derekf@osg.samsung.com>
2015-06-24 13:09:17 +00:00
|
|
|
text_backend_destroy(shell->text_backend);
|
2014-11-27 04:25:34 +00:00
|
|
|
input_panel_destroy(shell);
|
|
|
|
|
2014-11-27 04:22:37 +00:00
|
|
|
wl_list_for_each_safe(ivisurf, next, &shell->ivi_surface_list, link) {
|
|
|
|
wl_list_remove(&ivisurf->link);
|
|
|
|
free(ivisurf);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(shell);
|
|
|
|
}
|
|
|
|
|
2015-02-19 15:12:19 +00:00
|
|
|
static void
|
2015-07-15 18:00:36 +00:00
|
|
|
terminate_binding(struct weston_keyboard *keyboard, uint32_t time,
|
|
|
|
uint32_t key, void *data)
|
2015-02-19 15:12:19 +00:00
|
|
|
{
|
|
|
|
struct weston_compositor *compositor = data;
|
|
|
|
|
|
|
|
wl_display_terminate(compositor->wl_display);
|
|
|
|
}
|
|
|
|
|
2014-11-27 04:22:37 +00:00
|
|
|
static void
|
2015-02-19 15:08:44 +00:00
|
|
|
init_ivi_shell(struct weston_compositor *compositor, struct ivi_shell *shell,
|
|
|
|
const struct ivi_shell_setting *setting)
|
2014-11-27 04:22:37 +00:00
|
|
|
{
|
|
|
|
shell->compositor = compositor;
|
|
|
|
|
|
|
|
wl_list_init(&shell->ivi_surface_list);
|
|
|
|
|
2014-11-27 04:25:34 +00:00
|
|
|
weston_layer_init(&shell->input_panel_layer, NULL);
|
2015-02-19 15:08:44 +00:00
|
|
|
|
2015-02-19 15:12:19 +00:00
|
|
|
if (setting->developermode) {
|
2015-02-19 15:08:44 +00:00
|
|
|
weston_install_debug_key_binding(compositor, MODIFIER_SUPER);
|
2015-02-19 15:12:19 +00:00
|
|
|
|
|
|
|
weston_compositor_add_key_binding(compositor, KEY_BACKSPACE,
|
|
|
|
MODIFIER_CTRL | MODIFIER_ALT,
|
|
|
|
terminate_binding,
|
|
|
|
compositor);
|
|
|
|
}
|
2014-11-27 04:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ivi_shell_setting_create(struct ivi_shell_setting *dest,
|
2015-03-20 13:53:53 +00:00
|
|
|
struct weston_compositor *compositor,
|
|
|
|
int *argc, char *argv[])
|
2014-11-27 04:22:37 +00:00
|
|
|
{
|
|
|
|
int result = 0;
|
2016-06-02 18:48:11 +00:00
|
|
|
struct weston_config *config = wet_get_config(compositor);
|
2014-11-27 04:22:37 +00:00
|
|
|
struct weston_config_section *section;
|
|
|
|
|
2015-03-20 13:53:53 +00:00
|
|
|
const struct weston_option ivi_shell_options[] = {
|
|
|
|
{ WESTON_OPTION_STRING, "ivi-module", 0, &dest->ivi_module },
|
|
|
|
};
|
|
|
|
|
|
|
|
parse_options(ivi_shell_options, ARRAY_LENGTH(ivi_shell_options),
|
|
|
|
argc, argv);
|
2014-11-27 04:22:37 +00:00
|
|
|
|
|
|
|
section = weston_config_get_section(config, "ivi-shell", NULL, NULL);
|
|
|
|
|
2015-03-20 13:53:53 +00:00
|
|
|
if (!dest->ivi_module &&
|
|
|
|
weston_config_section_get_string(section, "ivi-module",
|
|
|
|
&dest->ivi_module, NULL) < 0) {
|
|
|
|
weston_log("Error: ivi-shell: No ivi-module set\n");
|
2014-11-27 04:22:37 +00:00
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
|
2015-02-19 15:08:44 +00:00
|
|
|
weston_config_section_get_bool(section, "developermode",
|
|
|
|
&dest->developermode, 0);
|
|
|
|
|
2014-11-27 04:22:37 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-12-09 06:03:47 +00:00
|
|
|
static void
|
|
|
|
activate_binding(struct weston_seat *seat,
|
|
|
|
struct weston_view *focus_view)
|
|
|
|
{
|
|
|
|
struct weston_surface *focus = focus_view->surface;
|
|
|
|
struct weston_surface *main_surface =
|
|
|
|
weston_surface_get_main_surface(focus);
|
|
|
|
|
|
|
|
if (get_ivi_shell_surface(main_surface) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
weston_surface_activate(focus, seat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
click_to_activate_binding(struct weston_pointer *pointer, uint32_t time,
|
|
|
|
uint32_t button, void *data)
|
|
|
|
{
|
|
|
|
if (pointer->grab != &pointer->default_grab)
|
|
|
|
return;
|
|
|
|
if (pointer->focus == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
activate_binding(pointer->seat, pointer->focus);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
touch_to_activate_binding(struct weston_touch *touch, uint32_t time,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
if (touch->grab != &touch->default_grab)
|
|
|
|
return;
|
|
|
|
if (touch->focus == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
activate_binding(touch->seat, touch->focus);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_add_bindings(struct weston_compositor *compositor,
|
|
|
|
struct ivi_shell *shell)
|
|
|
|
{
|
|
|
|
weston_compositor_add_button_binding(compositor, BTN_LEFT, 0,
|
|
|
|
click_to_activate_binding,
|
|
|
|
shell);
|
|
|
|
weston_compositor_add_button_binding(compositor, BTN_RIGHT, 0,
|
|
|
|
click_to_activate_binding,
|
|
|
|
shell);
|
|
|
|
weston_compositor_add_touch_binding(compositor, 0,
|
|
|
|
touch_to_activate_binding,
|
|
|
|
shell);
|
|
|
|
}
|
|
|
|
|
2014-11-27 04:22:37 +00:00
|
|
|
/*
|
|
|
|
* Initialization of ivi-shell.
|
|
|
|
*/
|
|
|
|
WL_EXPORT int
|
|
|
|
module_init(struct weston_compositor *compositor,
|
|
|
|
int *argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct ivi_shell *shell;
|
|
|
|
struct ivi_shell_setting setting = { };
|
2015-02-19 15:08:44 +00:00
|
|
|
int retval = -1;
|
2014-11-27 04:22:37 +00:00
|
|
|
|
|
|
|
shell = zalloc(sizeof *shell);
|
|
|
|
if (shell == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2015-03-20 13:53:53 +00:00
|
|
|
if (ivi_shell_setting_create(&setting, compositor, argc, argv) != 0)
|
2015-02-19 15:08:44 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
init_ivi_shell(compositor, shell, &setting);
|
2014-11-27 04:22:37 +00:00
|
|
|
|
|
|
|
shell->destroy_listener.notify = shell_destroy;
|
|
|
|
wl_signal_add(&compositor->destroy_signal, &shell->destroy_listener);
|
|
|
|
|
2014-11-27 04:25:34 +00:00
|
|
|
if (input_panel_setup(shell) < 0)
|
2015-02-19 15:08:44 +00:00
|
|
|
goto out_settings;
|
2014-11-27 04:22:37 +00:00
|
|
|
|
text_backend: make destructor call explicit
We used to rely on the order in which the
weston_compositor::destroy_signal callbacks happened, to not access
freed memory. Don't know when, but this broke at least with ivi-shell,
which caused crashes in random places on compositor shutdown.
Valgrind found the following:
Invalid write of size 8
at 0xC2EDC69: unbind_input_panel (input-panel-ivi.c:340)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea360 is 208 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Invalid write of size 8
at 0x4E3E0D7: wl_list_remove (wayland-util.c:57)
by 0xC2EDEE9: destroy_input_panel_surface (input-panel-ivi.c:191)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3BC7B: wl_resource_destroy (wayland-server.c:550)
by 0x40DB8B: wl_signal_emit (wayland-server-core.h:264)
by 0x40DB8B: weston_surface_destroy (compositor.c:1883)
by 0x40DB8B: weston_surface_destroy (compositor.c:1873)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea370 is 224 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Invalid write of size 8
at 0x4E3E0E7: wl_list_remove (wayland-util.c:58)
by 0xC2EDEE9: destroy_input_panel_surface (input-panel-ivi.c:191)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3BC7B: wl_resource_destroy (wayland-server.c:550)
by 0x40DB8B: wl_signal_emit (wayland-server-core.h:264)
by 0x40DB8B: weston_surface_destroy (compositor.c:1883)
by 0x40DB8B: weston_surface_destroy (compositor.c:1873)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea368 is 216 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Looking at the first of these, unbind_input_panel() gets called when the
text-backend destroys its helper client which has bound to input_panel
interface. This happens after the shell's destroy_signal callback has
been called, so the shell has already been freed.
The other two errors come from
wl_list_remove(&input_panel_surface->link);
which has gone stale when the shell was destroyed
(shell->input_panel.surfaces list).
Rather than creating even more destroy listeners and hooking them up in
spaghetti, modify text-backend to not hook up to the compositor destroy
signal. Instead, make it the text_backend_init() callers' responsibility
to also call text_backend_destroy() appropriately, before the shell goes
away.
This fixed all the above Valgrind errors, and avoid a crash with
ivi-shell when exiting Weston.
Also using desktop-shell exhibited similar Valgrind errors which are
fixed by this patch, but those didn't happen to cause any crashes AFAIK.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-By: Derek Foreman <derekf@osg.samsung.com>
2015-06-24 13:09:17 +00:00
|
|
|
shell->text_backend = text_backend_init(compositor);
|
|
|
|
if (!shell->text_backend)
|
2015-06-10 21:16:02 +00:00
|
|
|
goto out_settings;
|
|
|
|
|
2014-11-27 04:22:37 +00:00
|
|
|
if (wl_global_create(compositor->wl_display,
|
|
|
|
&ivi_application_interface, 1,
|
|
|
|
shell, bind_ivi_application) == NULL)
|
2015-02-19 15:08:44 +00:00
|
|
|
goto out_settings;
|
2014-11-27 04:22:37 +00:00
|
|
|
|
2014-12-15 04:22:31 +00:00
|
|
|
ivi_layout_init_with_compositor(compositor);
|
2015-12-09 06:03:47 +00:00
|
|
|
shell_add_bindings(compositor, shell);
|
2014-11-27 04:22:37 +00:00
|
|
|
|
|
|
|
/* Call module_init of ivi-modules which are defined in weston.ini */
|
2015-02-19 15:08:44 +00:00
|
|
|
if (load_controller_modules(compositor, setting.ivi_module,
|
|
|
|
argc, argv) < 0)
|
|
|
|
goto out_settings;
|
|
|
|
|
|
|
|
retval = 0;
|
2014-11-27 04:22:37 +00:00
|
|
|
|
2015-02-19 15:08:44 +00:00
|
|
|
out_settings:
|
2014-11-27 04:22:37 +00:00
|
|
|
free(setting.ivi_module);
|
2015-02-19 15:08:44 +00:00
|
|
|
|
|
|
|
return retval;
|
2014-11-27 04:22:37 +00:00
|
|
|
}
|