24bf8394f21bdb04f4e55d07349c6f800399c3d4
[AGL/meta-agl-demo.git] / recipes-graphics / wayland / wayland-ivi-extension / 0001-simple-id-agent-for-2.0.2.patch
1 diff --git a/CMakeLists.txt b/CMakeLists.txt
2 index c82136e..eeed7a6 100644
3 --- a/CMakeLists.txt
4 +++ b/CMakeLists.txt
5 @@ -35,6 +35,7 @@ add_subdirectory(ivi-layermanagement-api/ilmClient)
6  add_subdirectory(ivi-layermanagement-api/ilmControl)
7  add_subdirectory(ivi-layermanagement-api/test)
8  add_subdirectory(ivi-layermanagement-examples)
9 +add_subdirectory(id-agent-modules/simple-id-agent)
10
11  if(WITH_ILM_INPUT)
12      add_subdirectory(ivi-input-api/ilmInput)
13 diff --git a/id-agent-modules/simple-id-agent/CMakeLists.txt b/id-agent-modules/simple-id-agent/CMakeLists.txt
14 new file mode 100644
15 index 0000000..8290722
16 --- /dev/null
17 +++ b/id-agent-modules/simple-id-agent/CMakeLists.txt
18 @@ -0,0 +1,72 @@
19 +############################################################################
20 +#
21 +# Copyright (C) 2013 DENSO CORPORATION
22 +# Copyright 2014 BMW Car IT GmbH
23 +#
24 +#
25 +# Licensed under the Apache License, Version 2.0 (the "License");
26 +# you may not use this file except in compliance with the License.
27 +# You may obtain a copy of the License at
28 +#
29 +#              http://www.apache.org/licenses/LICENSE-2.0
30 +#
31 +# Unless required by applicable law or agreed to in writing, software
32 +# distributed under the License is distributed on an "AS IS" BASIS,
33 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34 +# See the License for the specific language governing permissions and
35 +# limitations under the License.
36 +#
37 +############################################################################
38 +
39 +cmake_minimum_required (VERSION 2.6)
40 +
41 +project(simple-id-agent)
42 +
43 +find_package(PkgConfig REQUIRED)
44 +pkg_check_modules(WAYLAND_SERVER wayland-server>=1.13.0 REQUIRED)
45 +pkg_check_modules(WESTON weston>=2.0.0 REQUIRED)
46 +pkg_check_modules(PIXMAN pixman-1 REQUIRED)
47 +
48 +find_package(Threads REQUIRED)
49 +
50 +GET_TARGET_PROPERTY(IVI_EXTENSION_INCLUDE_DIRS ivi-extension-protocol INCLUDE_DIRECTORIES)
51 +
52 +include_directories(
53 +    src
54 +    ${IVI_EXTENSION_INCLUDE_DIRS}
55 +    ${WAYLAND_SERVER_INCLUDE_DIRS}
56 +    ${WESTON_INCLUDE_DIRS}
57 +    ${PIXMAN_INCLUDE_DIRS}
58 +)
59 +
60 +link_directories(
61 +    ${WAYLAND_SERVER_LIBRARY_DIRS}
62 +    ${PIXMAN_LIBRARY_DIRS}
63 +)
64 +
65 +add_library(${PROJECT_NAME} MODULE
66 +    src/simple-id-agent.c
67 +)
68 +
69 +set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
70 +
71 +add_dependencies(${PROJECT_NAME}
72 +    ivi-extension-protocol
73 +    ${WAYLAND_SERVER_LIBRARIES}
74 +    ${PIXMAN_LIBRARIES}
75 +)
76 +
77 +set(LIBS
78 +    ${LIBS}
79 +    ivi-extension-protocol
80 +    ${WAYLAND_SERVER_LIBRARIES}
81 +)
82 +
83 +set(CMAKE_C_LDFLAGS "-module -avoid-version")
84 +
85 +target_link_libraries(${PROJECT_NAME} ${LIBS})
86 +
87 +install (
88 +    TARGETS             ${PROJECT_NAME}
89 +    LIBRARY DESTINATION lib${LIB_SUFFIX}/weston
90 +)
91 diff --git a/id-agent-modules/simple-id-agent/src/simple-id-agent.c b/id-agent-modules/simple-id-agent/src/simple-id-agent.c
92 new file mode 100644
93 index 0000000..3c9e989
94 --- /dev/null
95 +++ b/id-agent-modules/simple-id-agent/src/simple-id-agent.c
96 @@ -0,0 +1,124 @@
97 +/*
98 + * Copyright (C) 2017 Advanced Driver Information Technology Joint Venture GmbH
99 + *
100 + * Permission to use, copy, modify, distribute, and sell this software and
101 + * its documentation for any purpose is hereby granted without fee, provided
102 + * that the above copyright notice appear in all copies and that both that
103 + * copyright notice and this permission notice appear in supporting
104 + * documentation, and that the name of the copyright holders not be used in
105 + * advertising or publicity pertaining to distribution of the software
106 + * without specific, written prior permission.  The copyright holders make
107 + * no representations about the suitability of this software for any
108 + * purpose.  It is provided "as is" without express or implied warranty.
109 + *
110 + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
111 + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
112 + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
113 + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
114 + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
115 + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
116 + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
117 + */
118 +
119 +#include <stdlib.h>
120 +#include <stdio.h>
121 +#include <string.h>
122 +#include <limits.h>
123 +
124 +#include <weston.h>
125 +#include <weston/ivi-layout-export.h>
126 +
127 +struct ivi_id_agent
128 +{
129 +    uint32_t default_id_offset;
130 +    uint32_t last_assigned_id;
131 +    struct weston_compositor *compositor;
132 +    const struct ivi_layout_interface *interface;
133 +    struct wl_listener desktop_surface_configured;
134 +};
135 +
136 +static void
137 +desktop_surface_event_configure(struct wl_listener *listener,
138 +        void *data)
139 +{
140 +    struct ivi_id_agent *ida = wl_container_of(listener, ida,
141 +            desktop_surface_configured);
142 +    struct ivi_layout_surface *layout_surface =
143 +            (struct ivi_layout_surface *) data;
144 +    uint32_t tmp_id;
145 +
146 +    tmp_id = ++ida->last_assigned_id;
147 +
148 +    /* Find an unused id */
149 +    while(ida->interface->get_surface_from_id(tmp_id)) {
150 +        weston_log("simple-id-agent: surface id: %d is already used\n", tmp_id);
151 +        tmp_id++;
152 +    }
153 +
154 +    ida->last_assigned_id = tmp_id;
155 +
156 +    if (ida->interface->surface_set_id(layout_surface, ida->last_assigned_id) != 0)
157 +        weston_log("simple-id-agent: failed to set surface id :%d\n", ida->last_assigned_id);
158 +}
159 +
160 +static void
161 +deinit(struct ivi_id_agent *ida)
162 +{
163 +    wl_list_remove(&ida->desktop_surface_configured.link);
164 +    free(ida);
165 +}
166 +
167 +static int32_t
168 +read_config(struct ivi_id_agent *ida)
169 +{
170 +    struct weston_config *config = NULL;
171 +    struct weston_config_section *section = NULL;
172 +    const char *name = NULL;
173 +
174 +    config = wet_get_config(ida->compositor);
175 +    if (!config)
176 +        return -1;
177 +
178 +    section = weston_config_get_section(config, "id-agent", NULL, NULL);
179 +
180 +    if (section) {
181 +
182 +        weston_config_section_get_uint(section, "default-id-offset",
183 +                &ida->default_id_offset, 0);
184 +
185 +    } else {
186 +        ida->default_id_offset = 0;
187 +    }
188 +
189 +    return 0;
190 +}
191 +
192 +WL_EXPORT int32_t
193 +id_agent_module_init(struct weston_compositor *ec,
194 +                             const struct ivi_layout_interface *interface,
195 +                             size_t interface_version)
196 +{
197 +    struct ivi_id_agent *ida;
198 +
199 +    ida = calloc(1, sizeof *ida);
200 +    if (ida == NULL) {
201 +        weston_log("failed to allocate ivi_id_agent\n");
202 +        return -1;
203 +    }
204 +
205 +    ida->compositor = ec;
206 +    ida->interface = interface;
207 +    ida->desktop_surface_configured.notify = desktop_surface_event_configure;
208 +    ida->interface->add_listener_configure_desktop_surface(&ida->desktop_surface_configured);
209 +
210 +    if(read_config(ida) != 0) {
211 +        deinit(ida);
212 +        return -1;
213 +    }
214 +
215 +    ida->last_assigned_id = ida->default_id_offset;
216 +
217 +    weston_log("id_agent_module_init: success\n");
218 +
219 +    return 0;
220 +}
221 diff --git a/id-agent-modules/simple-id-agent/weston.ini.in b/id-agent-modules/simple-id-agent/weston.ini.in
222 new file mode 100644
223 index 0000000..b5e5fa1
224 --- /dev/null
225 +++ b/id-agent-modules/simple-id-agent/weston.ini.in
226 @@ -0,0 +1,11 @@
227 +[core]
228 +shell=ivi-shell.so
229 +require-input=false
230 +
231 +[ivi-shell]
232 +ivi-module=ivi-controller.so
233 +ivi-input-module=ivi-input-controller.so
234 +id-agent-module=simple-id-agent.so
235 +
236 +[id-agent]
237 +default-id-offset=10
238 diff --git a/weston-ivi-shell/src/ivi-controller.c b/weston-ivi-shell/src/ivi-controller.c
239 index 6d95c88..5e61e76 100644
240 --- a/weston-ivi-shell/src/ivi-controller.c
241 +++ b/weston-ivi-shell/src/ivi-controller.c
242 @@ -2164,6 +2164,40 @@ load_input_module(struct ivishell *shell)
243      return 0;
244  }
245  
246 +static int load_id_agent_module(struct weston_compositor *ec,
247 +                  const struct ivi_layout_interface *interface,
248 +                  size_t interface_version)
249 +{
250 +    struct weston_config *config = wet_get_config(ec);
251 +    struct weston_config_section *section;
252 +    char *id_agent_module = NULL;
253 +
254 +    int (*id_agent_module_init)(struct weston_compositor *ec,
255 +                             const struct ivi_layout_interface *interface,
256 +                             size_t interface_version);
257 +
258 +    section = weston_config_get_section(config, "ivi-shell", NULL, NULL);
259 +
260 +    if (weston_config_section_get_string(section, "id-agent-module",
261 +                                         &id_agent_module, NULL) < 0) {
262 +        weston_log("ivi-controller: No id-agent-module set\n");
263 +        return 0;
264 +    }
265 +
266 +    id_agent_module_init = wet_load_module_entrypoint(id_agent_module, "id_agent_module_init");
267 +    if (!id_agent_module_init)
268 +        return -1;
269 +
270 +    if (id_agent_module_init(ec, interface,
271 +                             sizeof(struct ivi_layout_interface)) != 0) {
272 +        weston_log("ivi-controller: Initialization of id agent module fails\n");
273 +        return -1;
274 +    }
275 +
276 +    free(id_agent_module);
277 +    return 0;
278 +}
279 +
280  static void
281  launch_client_process(void *data)
282  {
283 @@ -2229,6 +2263,11 @@ controller_module_init(struct weston_compositor *compositor,
284          return -1;
285      }
286
287 +    if (load_id_agent_module(compositor, interface, interface_version) < 0) {
288 +        free(shell);
289 +        return -1;
290 +    }
291 +
292      if (shell->bkgnd_surface_id && shell->ivi_client_name) {
293          loop = wl_display_get_event_loop(compositor->wl_display);
294          wl_event_loop_add_idle(loop, launch_client_process, shell);