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