53d414fa0ef642c56662bc220f1014cbb80a38eb
[AGL/meta-agl-demo.git] / recipes-graphics / wayland / wayland-ivi-extension / 0001-wayland-ivi-extension-patch-for-wl-shell-emulator.patch
1 ---
2  CMakeLists.txt                                     |   1 +
3  .../EGLWLMockNavigation/src/OpenGLES2App.cpp       |   7 +-
4  weston-ivi-shell/src/ivi-controller-interface.h    |  19 +
5  wl-shell-emulator/CMakeLists.txt                   |  69 ++++
6  wl-shell-emulator/README                           |  21 ++
7  wl-shell-emulator/src/wl-shell-emulator.c          | 394 +++++++++++++++++++++
8  6 files changed, 509 insertions(+), 2 deletions(-)
9  create mode 100644 wl-shell-emulator/CMakeLists.txt
10  create mode 100644 wl-shell-emulator/README
11  create mode 100644 wl-shell-emulator/src/wl-shell-emulator.c
12
13 diff --git a/CMakeLists.txt b/CMakeLists.txt
14 index a75390f..3610fa9 100644
15 --- a/CMakeLists.txt
16 +++ b/CMakeLists.txt
17 @@ -42,6 +42,7 @@ if(WITH_ILM_INPUT)
18      add_subdirectory(ivi-input-modules/ivi-input-controller)
19  endif()
20  
21 +add_subdirectory(wl-shell-emulator)
22  
23  #=============================================================================================
24  # generate all documents
25 diff --git a/wl-shell-emulator/CMakeLists.txt b/wl-shell-emulator/CMakeLists.txt
26 new file mode 100644
27 index 0000000..2678098
28 --- /dev/null
29 +++ b/wl-shell-emulator/CMakeLists.txt
30 @@ -0,0 +1,69 @@
31 +############################################################################
32 +#
33 +# Copyright (C) 2015 Advanced Driver Information Technology Joint Venture GmbH
34 +#
35 +#
36 +# Licensed under the Apache License, Version 2.0 (the "License");
37 +# you may not use this file except in compliance with the License.
38 +# You may obtain a copy of the License at
39 +#
40 +#       http://www.apache.org/licenses/LICENSE-2.0
41 +#
42 +# Unless required by applicable law or agreed to in writing, software
43 +# distributed under the License is distributed on an "AS IS" BASIS,
44 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45 +# See the License for the specific language governing permissions and
46 +# limitations under the License.
47 +#
48 +############################################################################
49 +
50 +cmake_minimum_required (VERSION 2.6)
51 +
52 +project(wl-shell-emulator)
53 +
54 +find_package(PkgConfig REQUIRED)
55 +pkg_check_modules(WAYLAND_SERVER wayland-server REQUIRED)
56 +pkg_check_modules(WESTON weston REQUIRED)
57 +
58 +GET_TARGET_PROPERTY(IVI_EXTENSION_INCLUDE_DIRS ivi-extension-protocol INCLUDE_DIRECTORIES)
59 +GET_TARGET_PROPERTY(IVI_CONTROLLER_INCLUDE_DIRS ivi-controller INCLUDE_DIRECTORIES)
60 +
61 +include_directories(
62 +    include
63 +    ${IVI_EXTENSION_INCLUDE_DIRS}
64 +    ${IVI_CONTROLLER_INCLUDE_DIRS}
65 +    ${WAYLAND_SERVER_INCLUDE_DIRS}
66 +    ${WESTON_INCLUDE_DIRS}
67 +    ${WESTON_INCLUDE_DIRS}/weston
68 +)
69 +
70 +link_directories(
71 +    ${WAYLAND_SERVER_LIBRARY_DIRS}
72 +)
73 +
74 +
75 +add_library(${PROJECT_NAME} MODULE
76 +    src/wl-shell-emulator.c
77 +)
78 +
79 +set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
80 +
81 +add_dependencies(${PROJECT_NAME}
82 +    ivi-extension-protocol
83 +    ${WAYLAND_SERVER_LIBRARIES}
84 +)
85 +
86 +set(LIBS
87 +    ${LIBS}
88 +    ivi-extension-protocol
89 +    ${WAYLAND_SERVER_LIBRARIES}
90 +)
91 +
92 +set(CMAKE_C_LDFLAGS "-module -avoid-version")
93 +
94 +target_link_libraries(${PROJECT_NAME} ${LIBS})
95 +
96 +install (
97 +    TARGETS             ${PROJECT_NAME}
98 +    LIBRARY DESTINATION lib/weston
99 +)
100 diff --git a/wl-shell-emulator/README b/wl-shell-emulator/README
101 new file mode 100644
102 index 0000000..6eebc04
103 --- /dev/null
104 +++ b/wl-shell-emulator/README
105 @@ -0,0 +1,21 @@
106 +This directory contains the wl-shell-emulator module.
107 +To use this, add it to the "ivi-module" entry in your weston.ini.
108 +Multiple modules may be specified in the same entry by separating
109 +the modules with commas.
110 +Additionally, the basement of surface-id is indentified by weston.ini
111 +at "surface-id-for-wl-shell" entry. wl-shell-emulator will increment
112 +surface-id per wl-shell-surface creation.
113 +
114 +- Sample of weston.ini
115 +[core]
116 +shell=ivi-shell.so
117 +
118 +[ivi-shell]
119 +ivi-module=ivi-controller.so,wl-shell-emulator.so
120 +surface-id-for-wl-shell-app=0x30000000
121 +
122 +- How to
123 +ivi-layermanagement-examples/layer-add-surfaces is easy
124 +for you to try wl-shell-emulator. When you invoke wl_shell
125 +application. layer-add-surfaces can add the ivi-surface to a layer
126 +and set visibility for it.
127 diff --git a/wl-shell-emulator/src/wl-shell-emulator.c b/wl-shell-emulator/src/wl-shell-emulator.c
128 new file mode 100644
129 index 0000000..274b192
130 --- /dev/null
131 +++ b/wl-shell-emulator/src/wl-shell-emulator.c
132 @@ -0,0 +1,394 @@
133 + /*
134 + * Copyright (C) 2015 Advanced Driver Information Technology Joint Venture GmbH
135 + *
136 + * Permission to use, copy, modify, distribute, and sell this software and
137 + * its documentation for any purpose is hereby granted without fee, provided
138 + * that the above copyright notice appear in all copies and that both that
139 + * copyright notice and this permission notice appear in supporting
140 + * documentation, and that the name of the copyright holders not be used in
141 + * advertising or publicity pertaining to distribution of the software
142 + * without specific, written prior permission.  The copyright holders make
143 + * no representations about the suitability of this software for any
144 + * purpose.  It is provided "as is" without express or implied warranty.
145 + *
146 + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
147 + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
148 + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
149 + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
150 + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
151 + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
152 + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
153 + */
154 +
155 +#include <stdlib.h>
156 +#include <string.h>
157 +#include <assert.h>
158 +
159 +#include <weston/compositor.h>
160 +
161 +#include "weston/ivi-layout-export.h"
162 +
163 +
164 +#ifndef container_of
165 +#define container_of(ptr, type, member) ({                              \
166 +        const __typeof__( ((type *)0)->member ) *__mptr = (ptr);        \
167 +        (type *)( (char *)__mptr - offsetof(type,member) );})
168 +#endif
169 +
170 +#define DEFAULT_SURFACE_ID_FOR_WL_SHELL_APP 0x80000000
171 +
172 +struct emulator_surface {
173 +    struct wl_resource* resource;
174 +    struct emulator_context *context;
175 +    struct ivi_layout_surface *layout_surface;
176 +
177 +    struct weston_surface *surface;
178 +    struct wl_listener surface_destroy_listener;
179 +
180 +    uint32_t id_surface;
181 +    int32_t last_width;
182 +    int32_t last_height;
183 +
184 +    struct wl_list link;
185 +};
186 +
187 +struct emulator_controller {
188 +    struct wl_list link;
189 +    struct wl_resource *resource;
190 +    struct wl_client *client;
191 +    uint32_t id;
192 +    struct emulator_context *emulator_context;
193 +};
194 +
195 +struct emulator_context {
196 +    struct wl_list controller_list;
197 +    struct wl_list surface_list;
198 +    struct weston_compositor *compositor;
199 +    const struct ivi_layout_interface *ivi_layout_interface;
200 +
201 +    uint32_t id_surface_base;
202 +};
203 +
204 +static void
205 +emulator_surface_pong(struct wl_client *client,
206 +           struct wl_resource *resource, uint32_t serial)
207 +{
208 +
209 +}
210 +
211 +static void
212 +emulator_surface_move(struct wl_client *client, struct wl_resource *resource,
213 +           struct wl_resource *seat_resource, uint32_t serial)
214 +{
215 +/*Use ivi_layout_interface to implement*/
216 +}
217 +
218 +static void
219 +emulator_surface_resize(struct wl_client *client, struct wl_resource *resource,
220 +           struct wl_resource *seat_resource, uint32_t serial,
221 +           uint32_t edges)
222 +{
223 +/*Use ivi_layout_interface to implement*/
224 +}
225 +
226 +static void
227 +emulator_surface_set_toplevel(struct wl_client *client,
228 +           struct wl_resource *resource)
229 +{
230 +/*Use ivi_layout_interface to implement*/
231 +}
232 +
233 +static void
234 +emulator_surface_set_transient(struct wl_client *client,
235 +        struct wl_resource *resource,
236 +        struct wl_resource *parent_resource,
237 +        int x, int y, uint32_t flags)
238 +{
239 +/*Use ivi_layout_interface to implement*/
240 +}
241 +
242 +static void
243 +emulator_surface_set_fullscreen(struct wl_client *client,
244 +           struct wl_resource *resource,
245 +           uint32_t method,
246 +           uint32_t framerate,
247 +           struct wl_resource *output_resource)
248 +{
249 +/*Use ivi_layout_interface to implement*/
250 +}
251 +
252 +static void
253 +emulator_surface_set_popup(struct wl_client *client,
254 +        struct wl_resource *resource,
255 +        struct wl_resource *seat_resource,
256 +        uint32_t serial,
257 +        struct wl_resource *parent_resource,
258 +        int32_t x, int32_t y, uint32_t flags)
259 +{
260 +
261 +}
262 +
263 +static void
264 +emulator_surface_set_maximized(struct wl_client *client,
265 +        struct wl_resource *resource,
266 +        struct wl_resource *output_resource)
267 +{
268 +
269 +}
270 +
271 +static void
272 +emulator_surface_set_title(struct wl_client *client,
273 +        struct wl_resource *resource, const char *title)
274 +{
275 +
276 +}
277 +
278 +static void
279 +emulator_surface_set_class(struct wl_client *client,
280 +        struct wl_resource *resource, const char *class)
281 +{
282 +
283 +}
284 +
285 +static const struct wl_shell_surface_interface shell_surface_implementation = {
286 +        emulator_surface_pong,
287 +        emulator_surface_move,
288 +        emulator_surface_resize,
289 +        emulator_surface_set_toplevel,
290 +        emulator_surface_set_transient,
291 +        emulator_surface_set_fullscreen,
292 +        emulator_surface_set_popup,
293 +        emulator_surface_set_maximized,
294 +        emulator_surface_set_title,
295 +        emulator_surface_set_class
296 +};
297 +
298 +/* Gets called through the weston_surface destroy signal. */
299 +static void
300 +emulator_handle_surface_destroy(struct wl_listener *listener, void *data)
301 +{
302 +    struct emulator_surface *emulator_surface =
303 +            container_of(listener, struct emulator_surface,
304 +                surface_destroy_listener);
305 +
306 +    assert(emulator_surface != NULL);
307 +
308 +    if (emulator_surface->surface!=NULL) {
309 +        emulator_surface->surface->configure = NULL;
310 +        emulator_surface->surface->configure_private = NULL;
311 +        emulator_surface->surface = NULL;
312 +    }
313 +
314 +    wl_list_remove(&emulator_surface->surface_destroy_listener.link);
315 +    wl_list_remove(&emulator_surface->link);
316 +
317 +    if (emulator_surface->resource != NULL) {
318 +        wl_resource_set_user_data(emulator_surface->resource, NULL);
319 +        emulator_surface->resource = NULL;
320 +    }
321 +    free(emulator_surface);
322 +}
323 +
324 +static void
325 +emulator_surface_configure(struct weston_surface *surface,
326 +                           int32_t sx, int32_t sy)
327 +{
328 +    struct emulator_surface *surf = surface->configure_private;
329 +    struct emulator_context *ctx;
330 +
331 +    if ((surf == NULL) ||
332 +        (surf->layout_surface == NULL)) {
333 +        return;
334 +    }
335 +
336 +    if ((surf->last_width != surface->width) ||
337 +        (surf->last_height != surface->height)) {
338 +
339 +        surf->last_width = surface->width;
340 +        surf->last_height = surface->height;
341 +
342 +        ctx = surf->context;
343 +        ctx->ivi_layout_interface->surface_configure(surf->layout_surface,
344 +                                                         surface->width,
345 +                                                         surface->height);
346 +    }
347 +}
348 +
349 +/*
350 + * The ivi_surface wl_resource destructor.
351 + *
352 + * Gets called via ivi_surface.destroy request or automatic wl_client clean-up.
353 + */
354 +static void
355 +shell_destroy_shell_surface(struct wl_resource *resource)
356 +{
357 +    struct emulator_surface *surf = wl_resource_get_user_data(resource);
358 +    if (surf != NULL) {
359 +        surf->resource = NULL;
360 +    }
361 +}
362 +
363 +static void
364 +emulator_get_shell_surface(struct wl_client *client, struct wl_resource *resource,
365 +                           uint32_t id, struct wl_resource *surface_resource)
366 +{
367 +    struct emulator_controller *controller = wl_resource_get_user_data(resource);
368 +    struct emulator_context * context = controller->emulator_context;
369 +    struct emulator_surface *emulator_surface;
370 +    struct weston_surface *surface;
371 +    struct ivi_layout_surface *layout_surface;
372 +    struct wl_resource *res;
373 +    const struct ivi_layout_interface *interface =
374 +                            context->ivi_layout_interface;
375 +
376 +    surface = wl_resource_get_user_data(surface_resource);
377 +
378 +    layout_surface = interface->surface_create(surface, context->id_surface_base);
379 +
380 +    if (!layout_surface) {
381 +        wl_resource_post_no_memory(surface_resource);
382 +        return;
383 +    }
384 +
385 +    emulator_surface = zalloc(sizeof *emulator_surface);
386 +    if (emulator_surface == NULL) {
387 +        wl_resource_post_no_memory(resource);
388 +        return;
389 +    }
390 +
391 +    emulator_surface->layout_surface = layout_surface;
392 +    emulator_surface->id_surface = context->id_surface_base;
393 +    emulator_surface->last_width = 0;
394 +    emulator_surface->last_height = 0;
395 +
396 +    wl_list_init(&emulator_surface->link);
397 +    wl_list_insert(&context->surface_list, &emulator_surface->link);
398 +
399 +    emulator_surface->context = context;
400 +    ++(context->id_surface_base);
401 +
402 +    /** The following code relies on wl_surface destruction triggering
403 +    * immediateweston_surface destruction
404 +    */
405 +    emulator_surface->surface_destroy_listener.notify = emulator_handle_surface_destroy;
406 +    wl_signal_add(&surface->destroy_signal,
407 +                  &emulator_surface->surface_destroy_listener);
408 +
409 +    emulator_surface->surface = surface;
410 +    surface->configure = emulator_surface_configure;
411 +    surface->configure_private = emulator_surface;
412 +
413 +    res = wl_resource_create(client, &wl_shell_surface_interface, 1, id);
414 +    if (res == NULL) {
415 +        wl_client_post_no_memory(client);
416 +        return;
417 +    }
418 +
419 +    emulator_surface->resource = res;
420 +
421 +    wl_resource_set_implementation(res, &shell_surface_implementation,
422 +                                  emulator_surface, shell_destroy_shell_surface);
423 +}
424 +static const struct wl_shell_interface shell_implementation = {
425 +    emulator_get_shell_surface
426 +};
427 +
428 +static void
429 +unbind_resource_controller(struct wl_resource *resource)
430 +{
431 +    struct emulator_controller *controller = wl_resource_get_user_data(resource);
432 +
433 +    wl_list_remove(&controller->link);
434 +
435 +    free(controller);
436 +}
437 +
438 +static void
439 +bind_shell_implementation(struct wl_client *client, void *data,
440 +               uint32_t version, uint32_t id)
441 +{
442 +    struct emulator_context *ctx = data;
443 +    struct emulator_controller *controller;
444 +    controller = calloc(1, sizeof *controller);
445 +    if (controller == NULL) {
446 +        weston_log("%s: Failed to allocate memory for controller\n",
447 +                   __FUNCTION__);
448 +        return;
449 +    }
450 +
451 +    controller->emulator_context = ctx;
452 +    controller->resource =
453 +        wl_resource_create(client, &wl_shell_interface, 1, id);
454 +    wl_resource_set_implementation(controller->resource, &shell_implementation,
455 +                                   controller, unbind_resource_controller);
456 +
457 +    controller->client = client;
458 +    controller->id = id;
459 +
460 +    wl_list_insert(&ctx->controller_list, &controller->link);
461 +}
462 +
463 +static struct emulator_context *
464 +create_emulator_context(struct weston_compositor *ec,
465 +                     const struct ivi_layout_interface *interface)
466 +{
467 +    struct emulator_context *ctx = NULL;
468 +    ctx = calloc(1, sizeof *ctx);
469 +    if (ctx == NULL) {
470 +        weston_log("%s: Failed to allocate memory for input context\n",
471 +                   __FUNCTION__);
472 +        return NULL;
473 +    }
474 +
475 +    memset(ctx, 0, sizeof *ctx);
476 +
477 +    ctx->compositor = ec;
478 +    ctx->ivi_layout_interface = interface;
479 +    wl_list_init(&ctx->controller_list);
480 +    wl_list_init(&ctx->surface_list);
481 +
482 +    return ctx;
483 +}
484 +
485 +static int
486 +setup_emulator_config(struct emulator_context *ctx, int *argc, char *argv[])
487 +{
488 +    struct weston_config_section *section;
489 +
490 +    section = weston_config_get_section(ctx->compositor->config, "ivi-shell",
491 +                                        NULL, NULL);
492 +
493 +    if (section) {
494 +        weston_config_section_get_uint(section, "surface-id-for-wl-shell-app",
495 +                                       &ctx->id_surface_base,
496 +                                       DEFAULT_SURFACE_ID_FOR_WL_SHELL_APP);
497 +
498 +        weston_log("Based surface ID for wl_shell application: %u (0x%x)\n",
499 +                   ctx->id_surface_base, ctx->id_surface_base);
500 +    }
501 +
502 +    return 0;
503 +}
504 +
505 +WL_EXPORT int
506 +controller_module_init(struct weston_compositor *ec, int* argc, char *argv[],
507 +                       const struct ivi_layout_interface *interface,
508 +                       size_t interface_version)
509 +{
510 +    struct emulator_context *ctx = create_emulator_context(ec, interface);
511 +    if (ctx == NULL) {
512 +        weston_log("%s: Failed to create input context\n", __FUNCTION__);
513 +        return -1;
514 +    }
515 +
516 +    if (setup_emulator_config(ctx, argc, argv)) {
517 +        return -1;
518 +    }
519 +
520 +    if (wl_global_create(ec->wl_display, &wl_shell_interface, 1,
521 +                         ctx, bind_shell_implementation) == NULL) {
522 +        return -1;
523 +    }
524 +    weston_log("wl-shell-emulator module loaded successfully!\n");
525 +    return 0;
526 +}
527 --
528 1.8.3.1