2 * Copyright (C) 2013 DENSO CORPORATION
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 #include <linux/input.h>
31 #include "weston/compositor.h"
32 #include "ivi-controller-server-protocol.h"
33 #include "ivi-layout-export.h"
40 struct ivilayer *layer;
45 struct iviscreen *screen;
51 struct wl_client *client;
52 struct ivishell *shell;
53 uint32_t update_count;
54 struct ivi_layout_surface *layout_surface;
55 struct wl_listener surface_destroy_listener;
56 struct wl_list list_layer;
57 uint32_t controller_surface_count;
63 struct ivishell *shell;
64 struct ivi_layout_layer *layout_layer;
65 struct wl_list list_screen;
66 uint32_t controller_layer_count;
67 int layer_canbe_removed;
72 struct ivishell *shell;
73 struct ivi_layout_screen *layout_screen;
74 struct weston_output *output;
77 struct ivicontroller_surface {
78 struct wl_resource *resource;
81 struct wl_client *client;
83 struct ivishell *shell;
86 struct ivicontroller_layer {
87 struct wl_resource *resource;
90 struct wl_client *client;
92 struct ivishell *shell;
95 struct ivicontroller_screen {
96 struct wl_resource *resource;
99 struct wl_client *client;
101 struct ivishell *shell;
104 struct ivicontroller {
105 struct wl_resource *resource;
107 struct wl_client *client;
109 struct ivishell *shell;
112 struct link_shell_weston_surface
114 struct wl_resource *resource;
115 struct wl_listener destroy_listener;
116 struct weston_surface *surface;
121 struct wl_resource *resource;
123 struct wl_listener destroy_listener;
125 struct weston_compositor *compositor;
127 struct weston_surface *surface;
129 struct weston_process process;
131 struct weston_seat *seat;
133 struct wl_list list_surface;
134 struct wl_list list_layer;
135 struct wl_list list_screen;
137 struct wl_list list_weston_surface;
139 struct wl_list list_controller;
140 struct wl_list list_controller_surface;
141 struct wl_list list_controller_layer;
142 struct wl_list list_controller_screen;
145 struct weston_process process;
146 struct wl_client *client;
147 struct wl_resource *desktop_shell;
155 int event_restriction;
157 static void surface_event_remove(struct ivi_layout_surface *, void *);
160 destroy_ivicontroller_surface(struct wl_resource *resource)
162 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
163 struct ivishell *shell = ivisurf->shell;
164 struct ivicontroller_surface *ctrlsurf = NULL;
165 struct ivicontroller_surface *next = NULL;
168 wl_list_for_each_safe(ctrlsurf, next,
169 &shell->list_controller_surface, link) {
171 if (resource != ctrlsurf->resource) {
175 if (!wl_list_empty(&ctrlsurf->link)) {
176 wl_list_remove(&ctrlsurf->link);
182 --ivisurf->controller_surface_count;
186 if ((is_removed) && (ivisurf->controller_surface_count == 0)) {
187 if (ivisurf->can_be_removed) {
191 ivisurf->can_be_removed = 1;
197 destroy_ivicontroller_layer(struct wl_resource *resource)
199 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
200 struct ivishell *shell = ivilayer->shell;
201 struct ivicontroller_layer *ctrllayer = NULL;
202 struct ivicontroller_layer *next = NULL;
203 uint32_t id_layer = 0;
205 id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
207 wl_list_for_each_safe(ctrllayer, next,
208 &shell->list_controller_layer, link) {
210 if (resource != ctrllayer->resource) {
214 wl_list_remove(&ctrllayer->link);
215 --ivilayer->controller_layer_count;
216 ivi_controller_layer_send_destroyed(ctrllayer->resource);
222 if ((ivilayer->layout_layer != NULL) &&
223 (ivilayer->controller_layer_count == 0) &&
224 (ivilayer->layer_canbe_removed == 1)) {
225 ivi_layout_layerRemove(ivilayer->layout_layer);
230 destroy_ivicontroller_screen(struct wl_resource *resource)
232 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
233 struct ivicontroller_screen *ctrlscrn = NULL;
234 struct ivicontroller_screen *next = NULL;
236 wl_list_for_each_safe(ctrlscrn, next,
237 &iviscrn->shell->list_controller_screen, link) {
238 // TODO : Only Single display
240 if (iviscrn->output->id != ctrlscrn->id_screen) {
245 if (resource != ctrlscrn->resource) {
249 wl_list_remove(&ctrlscrn->link);
257 unbind_resource_controller(struct wl_resource *resource)
259 struct ivicontroller *controller = wl_resource_get_user_data(resource);
261 wl_list_remove(&controller->link);
267 static struct ivisurface*
268 get_surface(struct wl_list *list_surf, uint32_t id_surface)
270 struct ivisurface *ivisurf = NULL;
271 uint32_t ivisurf_id = 0;
273 wl_list_for_each(ivisurf, list_surf, link) {
274 ivisurf_id = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
275 if (ivisurf_id == id_surface) {
283 static struct ivilayer*
284 get_layer(struct wl_list *list_layer, uint32_t id_layer)
286 struct ivilayer *ivilayer = NULL;
287 uint32_t ivilayer_id = 0;
289 wl_list_for_each(ivilayer, list_layer, link) {
290 ivilayer_id = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
291 if (ivilayer_id == id_layer) {
300 struct ivi_controller_screen_interface controller_screen_implementation;
302 static struct ivicontroller_screen*
303 controller_screen_create(struct ivishell *shell,
304 struct wl_client *client,
305 struct iviscreen *iviscrn)
307 struct ivicontroller_screen *ctrlscrn = NULL;
309 ctrlscrn = calloc(1, sizeof *ctrlscrn);
310 if (ctrlscrn == NULL) {
311 weston_log("no memory to allocate controller screen\n");
315 ctrlscrn->client = client;
316 ctrlscrn->shell = shell;
318 // TODO : Only Single display
320 /* ctrlscrn->id_screen = iviscrn->id_screen; */
322 ctrlscrn->id_screen = 0;
326 wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
327 if (ctrlscrn->resource == NULL) {
328 weston_log("couldn't new screen controller object");
336 wl_resource_set_implementation(ctrlscrn->resource,
337 &controller_screen_implementation,
338 iviscrn, destroy_ivicontroller_screen);
340 wl_list_init(&ctrlscrn->link);
341 wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
347 send_surface_add_event(struct ivisurface *ivisurf,
348 struct wl_resource *resource,
349 enum ivi_layout_notification_mask mask)
351 struct ivi_layout_layer **pArray = NULL;
355 struct link_layer *link_layer = NULL;
356 struct link_layer *next = NULL;
357 struct ivicontroller_layer *ctrllayer = NULL;
358 struct ivilayer *ivilayer = NULL;
359 struct ivishell *shell = ivisurf->shell;
360 uint32_t id_layout_layer = 0;
361 struct wl_client *surface_client = wl_resource_get_client(resource);
364 ans = ivi_layout_getLayersUnderSurface(ivisurf->layout_surface,
367 weston_log("failed to get layers at send_surface_add_event\n");
371 /* Send Null to cancel added surface */
372 if (mask & IVI_NOTIFICATION_REMOVE) {
373 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
374 ivi_controller_surface_send_layer(resource, NULL);
377 else if (mask & IVI_NOTIFICATION_ADD) {
378 for (i = 0; i < (int)length; i++) {
379 /* Send new surface event */
381 wl_list_for_each(ivilayer, &shell->list_layer, link) {
382 if (ivilayer->layout_layer == pArray[i]) {
387 if (ivilayer == NULL) {
392 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
393 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
394 if (id_layout_layer != ctrllayer->id_layer) {
398 struct wl_client *layer_client = wl_resource_get_client(ctrllayer->resource);
399 if (surface_client != layer_client) {
403 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
413 send_surface_event(struct wl_resource *resource,
414 struct ivisurface *ivisurf,
415 struct ivi_layout_SurfaceProperties *prop,
418 if (mask & IVI_NOTIFICATION_OPACITY) {
419 ivi_controller_surface_send_opacity(resource,
422 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
423 ivi_controller_surface_send_source_rectangle(resource,
424 prop->sourceX, prop->sourceY,
425 prop->sourceWidth, prop->sourceHeight);
427 if (mask & IVI_NOTIFICATION_DEST_RECT) {
428 ivi_controller_surface_send_destination_rectangle(resource,
429 prop->destX, prop->destY,
430 prop->destWidth, prop->destHeight);
432 if (mask & IVI_NOTIFICATION_ORIENTATION) {
433 ivi_controller_surface_send_orientation(resource,
436 if (mask & IVI_NOTIFICATION_VISIBILITY) {
437 ivi_controller_surface_send_visibility(resource,
440 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
441 ivi_controller_surface_send_pixelformat(resource,
444 if (mask & IVI_NOTIFICATION_REMOVE) {
445 send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_REMOVE);
447 if (mask & IVI_NOTIFICATION_ADD) {
448 send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_ADD);
453 update_surface_prop(struct ivisurface *ivisurf,
456 struct ivi_layout_layer **pArray = NULL;
460 struct ivishell *shell = ivisurf->shell;
462 ans = ivi_layout_getLayersUnderSurface(ivisurf->layout_surface,
465 weston_log("failed to get layers at send_surface_add_event\n");
469 if (mask & IVI_NOTIFICATION_REMOVE) {
470 struct link_layer *link_layer = NULL;
471 struct link_layer *next = NULL;
473 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
474 wl_list_remove(&link_layer->link);
479 if (mask & IVI_NOTIFICATION_ADD) {
480 for (i = 0; i < (int)length; ++i) {
481 /* Create list_layer */
482 struct ivilayer *ivilayer = NULL;
483 struct link_layer *link_layer = calloc(1, sizeof(*link_layer));
484 if (NULL == link_layer) {
487 wl_list_init(&link_layer->link);
488 link_layer->layer = NULL;
489 wl_list_for_each(ivilayer, &shell->list_layer, link) {
490 if (ivilayer->layout_layer == pArray[i]) {
491 link_layer->layer = ivilayer;
496 if (link_layer->layer == NULL) {
502 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
508 send_surface_prop(struct ivi_layout_surface *layout_surface,
509 struct ivi_layout_SurfaceProperties *prop,
510 enum ivi_layout_notification_mask mask,
513 struct ivisurface *ivisurf = userdata;
514 struct ivishell *shell = ivisurf->shell;
515 struct ivicontroller_surface *ctrlsurf = NULL;
516 uint32_t id_surface = 0;
518 id_surface = ivi_layout_getIdOfSurface(layout_surface);
520 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
521 if (id_surface != ctrlsurf->id_surface) {
524 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
527 update_surface_prop(ivisurf, mask);
531 send_layer_add_event(struct ivilayer *ivilayer,
532 struct wl_resource *resource,
533 enum ivi_layout_notification_mask mask)
535 struct ivi_layout_screen **pArray = NULL;
539 struct link_screen *link_scrn = NULL;
540 struct link_screen *next = NULL;
541 struct iviscreen *iviscrn = NULL;
542 struct ivishell *shell = ivilayer->shell;
543 struct wl_client *client = wl_resource_get_client(resource);
544 struct wl_resource *resource_output = NULL;
546 ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
549 weston_log("failed to get screens at send_layer_add_event\n");
553 /* Send Null to cancel added layer */
554 if (mask & IVI_NOTIFICATION_REMOVE) {
555 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
556 ivi_controller_layer_send_screen(resource, NULL);
559 else if (mask & IVI_NOTIFICATION_ADD) {
560 for (i = 0; i < (int)length; i++) {
561 /* Send new layer event */
563 wl_list_for_each(iviscrn, &shell->list_screen, link) {
564 if (iviscrn->layout_screen == pArray[i]) {
569 if (iviscrn == NULL) {
574 wl_resource_find_for_client(&iviscrn->output->resource_list,
576 if (resource_output != NULL) {
577 ivi_controller_layer_send_screen(resource, resource_output);
587 send_layer_event(struct wl_resource *resource,
588 struct ivilayer *ivilayer,
589 struct ivi_layout_LayerProperties *prop,
592 if (mask & IVI_NOTIFICATION_OPACITY) {
593 ivi_controller_layer_send_opacity(resource,
596 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
597 ivi_controller_layer_send_source_rectangle(resource,
603 if (mask & IVI_NOTIFICATION_DEST_RECT) {
604 ivi_controller_layer_send_destination_rectangle(resource,
610 if (mask & IVI_NOTIFICATION_ORIENTATION) {
611 ivi_controller_layer_send_orientation(resource,
614 if (mask & IVI_NOTIFICATION_VISIBILITY) {
615 ivi_controller_layer_send_visibility(resource,
618 if (mask & IVI_NOTIFICATION_REMOVE) {
619 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_REMOVE);
621 if (mask & IVI_NOTIFICATION_ADD) {
622 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_ADD);
627 update_layer_prop(struct ivilayer *ivilayer,
628 enum ivi_layout_notification_mask mask)
630 struct ivi_layout_screen **pArray = NULL;
633 struct link_screen *link_scrn = NULL;
634 struct link_screen *next = NULL;
636 ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
639 weston_log("failed to get screens at send_layer_add_event\n");
643 /* Send Null to cancel added layer */
644 if (mask & IVI_NOTIFICATION_REMOVE) {
645 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
646 wl_list_remove(&link_scrn->link);
651 if (mask & IVI_NOTIFICATION_ADD) {
653 for (i = 0; i < (int)length; i++) {
654 struct ivishell *shell = ivilayer->shell;
655 struct iviscreen *iviscrn = NULL;
656 /* Create list_screen */
657 link_scrn = calloc(1, sizeof(*link_scrn));
658 if (NULL == link_scrn) {
661 wl_list_init(&link_scrn->link);
662 link_scrn->screen = NULL;
663 wl_list_for_each(iviscrn, &shell->list_screen, link) {
664 if (iviscrn->layout_screen == pArray[i]) {
665 link_scrn->screen = iviscrn;
670 if (link_scrn->screen == NULL) {
675 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
684 send_layer_prop(struct ivi_layout_layer *layer,
685 struct ivi_layout_LayerProperties *prop,
686 enum ivi_layout_notification_mask mask,
689 struct ivilayer *ivilayer = userdata;
690 struct ivicontroller_layer *ctrllayer = NULL;
691 struct ivishell *shell = ivilayer->shell;
692 uint32_t id_layout_layer = 0;
694 id_layout_layer = ivi_layout_getIdOfLayer(layer);
695 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
696 if (id_layout_layer != ctrllayer->id_layer) {
699 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
702 update_layer_prop(ivilayer, mask);
706 controller_surface_set_opacity(struct wl_client *client,
707 struct wl_resource *resource,
710 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
712 ivi_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
716 controller_surface_set_source_rectangle(struct wl_client *client,
717 struct wl_resource *resource,
723 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
725 ivi_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
726 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
730 controller_surface_set_destination_rectangle(struct wl_client *client,
731 struct wl_resource *resource,
737 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
739 ivi_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
740 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
744 controller_surface_set_visibility(struct wl_client *client,
745 struct wl_resource *resource,
748 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
750 ivi_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
754 controller_surface_set_configuration(struct wl_client *client,
755 struct wl_resource *resource,
756 int32_t width, int32_t height)
758 /* This interface has been supported yet. */
766 controller_surface_set_orientation(struct wl_client *client,
767 struct wl_resource *resource,
770 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
772 ivi_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
776 controller_surface_screenshot(struct wl_client *client,
777 struct wl_resource *resource,
778 const char *filename)
780 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
782 ivi_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
786 controller_surface_send_stats(struct wl_client *client,
787 struct wl_resource *resource)
789 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
793 wl_client_get_credentials(client, &pid, &uid, &gid);
795 ivi_controller_surface_send_stats(resource, 0, 0,
796 ivisurf->update_count, pid, "");
800 controller_surface_destroy(struct wl_client *client,
801 struct wl_resource *resource,
802 int32_t destroy_scene_object)
805 (void)destroy_scene_object;
806 wl_resource_destroy(resource);
810 controller_surface_set_input_focus(struct wl_client *client,
811 struct wl_resource *resource,
820 struct ivi_controller_surface_interface controller_surface_implementation = {
821 controller_surface_set_visibility,
822 controller_surface_set_opacity,
823 controller_surface_set_source_rectangle,
824 controller_surface_set_destination_rectangle,
825 controller_surface_set_configuration,
826 controller_surface_set_orientation,
827 controller_surface_screenshot,
828 controller_surface_send_stats,
829 controller_surface_destroy,
830 controller_surface_set_input_focus
834 controller_layer_set_source_rectangle(struct wl_client *client,
835 struct wl_resource *resource,
841 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
843 ivi_layout_layerSetSourceRectangle(ivilayer->layout_layer,
844 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
848 controller_layer_set_destination_rectangle(struct wl_client *client,
849 struct wl_resource *resource,
855 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
857 ivi_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
858 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
862 controller_layer_set_visibility(struct wl_client *client,
863 struct wl_resource *resource,
866 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
868 ivi_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
872 controller_layer_set_opacity(struct wl_client *client,
873 struct wl_resource *resource,
876 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
878 ivi_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
882 controller_layer_set_configuration(struct wl_client *client,
883 struct wl_resource *resource,
887 /* This interface has been supported yet. */
895 controller_layer_set_orientation(struct wl_client *client,
896 struct wl_resource *resource,
899 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
901 ivi_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
905 controller_layer_clear_surfaces(struct wl_client *client,
906 struct wl_resource *resource)
908 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
910 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
914 controller_layer_add_surface(struct wl_client *client,
915 struct wl_resource *resource,
916 struct wl_resource *surface)
918 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
919 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
921 ivi_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
925 controller_layer_remove_surface(struct wl_client *client,
926 struct wl_resource *resource,
927 struct wl_resource *surface)
929 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
930 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
932 ivi_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
936 controller_layer_screenshot(struct wl_client *client,
937 struct wl_resource *resource,
938 const char *filename)
946 controller_layer_set_render_order(struct wl_client *client,
947 struct wl_resource *resource,
948 struct wl_array *id_surfaces)
950 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
951 struct ivi_layout_surface **layoutsurf_array = NULL;
952 struct ivisurface *ivisurf = NULL;
953 uint32_t *id_surface = NULL;
954 uint32_t id_layout_surface = 0;
958 wl_array_for_each(id_surface, id_surfaces) {
959 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
960 id_layout_surface = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
961 if (*id_surface == id_layout_surface) {
962 layoutsurf_array[i] = ivisurf->layout_surface;
969 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer,
970 layoutsurf_array, id_surfaces->size);
971 free(layoutsurf_array);
975 controller_layer_destroy(struct wl_client *client,
976 struct wl_resource *resource,
977 int32_t destroy_scene_object)
979 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
980 struct ivishell *shell = ivilayer->shell;
981 struct ivicontroller_layer *ctrllayer = NULL;
982 struct ivicontroller_layer *next = NULL;
983 uint32_t id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
985 (void)destroy_scene_object;
987 ivilayer->layer_canbe_removed = 1;
988 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
989 if (ctrllayer->id_layer != id_layer) {
993 wl_resource_destroy(ctrllayer->resource);
998 struct ivi_controller_layer_interface controller_layer_implementation = {
999 controller_layer_set_visibility,
1000 controller_layer_set_opacity,
1001 controller_layer_set_source_rectangle,
1002 controller_layer_set_destination_rectangle,
1003 controller_layer_set_configuration,
1004 controller_layer_set_orientation,
1005 controller_layer_screenshot,
1006 controller_layer_clear_surfaces,
1007 controller_layer_add_surface,
1008 controller_layer_remove_surface,
1009 controller_layer_set_render_order,
1010 controller_layer_destroy
1014 controller_screen_destroy(struct wl_client *client,
1015 struct wl_resource *resource)
1017 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1018 struct ivicontroller_screen *ctrlscrn = NULL;
1019 struct ivicontroller_screen *next = NULL;
1020 // uint32_t id_screen = ivi_layout_getIdOfScreen(iviscrn->layout_screen);
1023 wl_list_for_each_safe(ctrlscrn, next,
1024 &iviscrn->shell->list_controller_screen, link) {
1025 if (resource != ctrlscrn->resource) {
1029 wl_list_remove(&ctrlscrn->link);
1032 wl_resource_destroy(ctrlscrn->resource);
1038 controller_screen_clear(struct wl_client *client,
1039 struct wl_resource *resource)
1041 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1043 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
1047 controller_screen_add_layer(struct wl_client *client,
1048 struct wl_resource *resource,
1049 struct wl_resource *layer)
1051 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1052 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
1054 ivi_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
1058 controller_screen_screenshot(struct wl_client *client,
1059 struct wl_resource *resource,
1060 const char *filename)
1062 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1064 ivi_layout_takeScreenshot(iviscrn->layout_screen, filename);
1068 controller_screen_set_render_order(struct wl_client *client,
1069 struct wl_resource *resource,
1070 struct wl_array *id_layers)
1072 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1073 struct ivi_layout_layer **layoutlayer_array = NULL;
1074 struct ivilayer *ivilayer = NULL;
1075 uint32_t *id_layer = NULL;
1076 uint32_t id_layout_layer = 0;
1080 *layoutlayer_array = (struct ivi_layout_layer*)calloc(
1081 id_layers->size, sizeof(void*));
1083 wl_array_for_each(id_layer, id_layers) {
1084 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1085 id_layout_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1086 if (*id_layer == id_layout_layer) {
1087 layoutlayer_array[i] = ivilayer->layout_layer;
1094 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen,
1095 layoutlayer_array, id_layers->size);
1096 free(layoutlayer_array);
1100 struct ivi_controller_screen_interface controller_screen_implementation = {
1101 controller_screen_destroy,
1102 controller_screen_clear,
1103 controller_screen_add_layer,
1104 controller_screen_screenshot,
1105 controller_screen_set_render_order
1109 controller_commit_changes(struct wl_client *client,
1110 struct wl_resource *resource)
1116 ans = ivi_layout_commitChanges();
1118 weston_log("Failed to commit changes at controller_commit_changes\n");
1123 controller_layer_create(struct wl_client *client,
1124 struct wl_resource *resource,
1130 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1131 struct ivishell *shell = ctrl->shell;
1132 struct ivi_layout_layer *layout_layer = NULL;
1133 struct ivicontroller_layer *ctrllayer = NULL;
1134 struct ivilayer *ivilayer = NULL;
1135 struct ivi_layout_LayerProperties prop;
1137 ivilayer = get_layer(&shell->list_layer, id_layer);
1138 if (ivilayer == NULL) {
1139 layout_layer = ivi_layout_layerCreateWithDimension(id_layer,
1140 (uint32_t)width, (uint32_t)height);
1141 if (layout_layer == NULL) {
1142 weston_log("id_layer is already created\n");
1146 /* ivilayer will be created by layer_event_create */
1147 ivilayer = get_layer(&shell->list_layer, id_layer);
1148 if (ivilayer == NULL) {
1149 weston_log("couldn't get layer object\n");
1154 ctrllayer = calloc(1, sizeof *ctrllayer);
1156 weston_log("no memory to allocate client layer\n");
1160 ++ivilayer->controller_layer_count;
1161 ivilayer->layer_canbe_removed = 0;
1163 ctrllayer->shell = shell;
1164 ctrllayer->client = client;
1166 ctrllayer->id_layer = id_layer;
1167 ctrllayer->resource = wl_resource_create(client,
1168 &ivi_controller_layer_interface, 1, id);
1169 if (ctrllayer->resource == NULL) {
1170 weston_log("couldn't get layer object\n");
1174 wl_list_init(&ctrllayer->link);
1175 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1177 wl_resource_set_implementation(ctrllayer->resource,
1178 &controller_layer_implementation,
1179 ivilayer, destroy_ivicontroller_layer);
1181 memset(&prop, 0, sizeof prop);
1183 ivi_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1184 send_layer_event(ctrllayer->resource, ivilayer,
1185 &prop, IVI_NOTIFICATION_ALL);
1189 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1191 struct ivishell *shell = userdata;
1192 struct ivicontroller_surface *ctrlsurf = NULL;
1193 uint32_t id_surface = 0;
1196 surface_event_remove(layout_surface, userdata);
1201 controller_surface_create(struct wl_client *client,
1202 struct wl_resource *resource,
1203 uint32_t id_surface,
1206 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1207 struct ivishell *shell = ctrl->shell;
1208 struct ivicontroller_surface *ctrlsurf = NULL;
1209 struct ivi_layout_SurfaceProperties prop;
1210 struct ivisurface *ivisurf = NULL;
1212 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1214 weston_log("no memory to allocate controller surface\n");
1218 ctrlsurf->shell = shell;
1219 ctrlsurf->client = client;
1221 ctrlsurf->id_surface = id_surface;
1222 wl_list_init(&ctrlsurf->link);
1223 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1225 ctrlsurf->resource = wl_resource_create(client,
1226 &ivi_controller_surface_interface, 1, id);
1227 if (ctrlsurf->resource == NULL) {
1228 weston_log("couldn't surface object");
1232 ivisurf = get_surface(&shell->list_surface, id_surface);
1233 if (ivisurf == NULL) {
1237 ++ivisurf->controller_surface_count;
1239 wl_resource_set_implementation(ctrlsurf->resource,
1240 &controller_surface_implementation,
1241 ivisurf, destroy_ivicontroller_surface);
1243 memset(&prop, 0, sizeof prop);
1245 ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1246 ivi_layout_surfaceSetContentObserver(ivisurf->layout_surface, surface_event_content, shell);
1248 send_surface_event(ctrlsurf->resource, ivisurf,
1249 &prop, IVI_NOTIFICATION_ALL);
1252 static const struct ivi_controller_interface controller_implementation = {
1253 controller_commit_changes,
1254 controller_layer_create,
1255 controller_surface_create
1259 add_client_to_resources(struct ivishell *shell,
1260 struct wl_client *client,
1261 struct ivicontroller *controller)
1263 struct ivisurface* ivisurf = NULL;
1264 struct ivilayer* ivilayer = NULL;
1265 struct iviscreen* iviscrn = NULL;
1266 struct ivicontroller_screen *ctrlscrn = NULL;
1267 struct wl_resource *resource_output = NULL;
1268 uint32_t id_layout_surface = 0;
1269 uint32_t id_layout_layer = 0;
1271 wl_list_for_each_reverse(ivisurf, &shell->list_surface, link) {
1273 ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1275 ivi_controller_send_surface(controller->resource,
1279 wl_list_for_each_reverse(ivilayer, &shell->list_layer, link) {
1281 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1283 ivi_controller_send_layer(controller->resource,
1287 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1288 resource_output = wl_resource_find_for_client(
1289 &iviscrn->output->resource_list, client);
1290 if (resource_output == NULL) {
1294 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1295 if (ctrlscrn == NULL) {
1299 ivi_controller_send_screen(controller->resource,
1300 wl_resource_get_id(resource_output),
1301 ctrlscrn->resource);
1306 bind_ivi_controller(struct wl_client *client, void *data,
1307 uint32_t version, uint32_t id)
1309 struct ivishell *shell = data;
1310 struct ivicontroller *controller;
1313 controller = calloc(1, sizeof *controller);
1314 if (controller == NULL) {
1315 weston_log("no memory to allocate controller\n");
1319 controller->resource =
1320 wl_resource_create(client, &ivi_controller_interface, 1, id);
1321 wl_resource_set_implementation(controller->resource,
1322 &controller_implementation,
1323 controller, unbind_resource_controller);
1325 controller->shell = shell;
1326 controller->client = client;
1327 controller->id = id;
1329 wl_list_init(&controller->link);
1330 wl_list_insert(&shell->list_controller, &controller->link);
1332 add_client_to_resources(shell, client, controller);
1335 static struct iviscreen*
1336 create_screen(struct ivishell *shell, struct weston_output *output)
1338 struct iviscreen *iviscrn;
1339 iviscrn = calloc(1, sizeof *iviscrn);
1340 if (iviscrn == NULL) {
1341 weston_log("no memory to allocate client screen\n");
1345 iviscrn->shell = shell;
1346 iviscrn->output = output;
1348 // TODO : Only Single display
1349 iviscrn->layout_screen = ivi_layout_getScreenFromId(0);
1351 wl_list_init(&iviscrn->link);
1356 static struct ivilayer*
1357 create_layer(struct ivishell *shell,
1358 struct ivi_layout_layer *layout_layer,
1361 struct ivilayer *ivilayer = NULL;
1362 struct ivicontroller *controller = NULL;
1364 ivilayer = get_layer(&shell->list_layer, id_layer);
1365 if (ivilayer != NULL) {
1366 weston_log("id_layer is already created\n");
1370 ivilayer = calloc(1, sizeof *ivilayer);
1371 if (NULL == ivilayer) {
1372 weston_log("no memory to allocate client layer\n");
1376 ivilayer->shell = shell;
1377 wl_list_init(&ivilayer->list_screen);
1378 wl_list_init(&ivilayer->link);
1379 wl_list_insert(&shell->list_layer, &ivilayer->link);
1380 ivilayer->layout_layer = layout_layer;
1382 ivi_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1384 wl_list_for_each(controller, &shell->list_controller, link) {
1385 ivi_controller_send_layer(controller->resource, id_layer);
1391 static struct ivisurface*
1392 create_surface(struct ivishell *shell,
1393 struct ivi_layout_surface *layout_surface,
1394 uint32_t id_surface)
1396 struct ivisurface *ivisurf = NULL;
1397 struct ivicontroller *controller = NULL;
1399 ivisurf = get_surface(&shell->list_surface, id_surface);
1400 if (ivisurf != NULL) {
1401 weston_log("id_surface is already created\n");
1405 ivisurf = calloc(1, sizeof *ivisurf);
1406 if (ivisurf == NULL) {
1407 weston_log("no memory to allocate client surface\n");
1411 ivisurf->shell = shell;
1412 ivisurf->layout_surface = layout_surface;
1413 wl_list_init(&ivisurf->list_layer);
1414 wl_list_init(&ivisurf->link);
1415 wl_list_insert(&shell->list_surface, &ivisurf->link);
1417 wl_list_for_each(controller, &shell->list_controller, link) {
1418 ivi_controller_send_surface(controller->resource,
1422 ivi_layout_surfaceAddNotification(layout_surface,
1423 send_surface_prop, ivisurf);
1429 layer_event_create(struct ivi_layout_layer *layout_layer,
1432 struct ivishell *shell = userdata;
1433 struct ivilayer *ivilayer = NULL;
1434 uint32_t id_layer = 0;
1436 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1438 ivilayer = create_layer(shell, layout_layer, id_layer);
1439 if (ivilayer == NULL) {
1440 weston_log("failed to create layer");
1446 layer_event_remove(struct ivi_layout_layer *layout_layer,
1449 struct ivishell *shell = userdata;
1450 struct ivicontroller_layer *ctrllayer = NULL;
1451 struct ivilayer *ivilayer = NULL;
1452 struct ivilayer *next = NULL;
1453 uint32_t id_layer = 0;
1456 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1457 if (layout_layer != ivilayer->layout_layer) {
1461 wl_list_remove(&ivilayer->link);
1470 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1472 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1473 if (id_layer != ctrllayer->id_layer) {
1476 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1483 surface_event_create(struct ivi_layout_surface *layout_surface,
1486 struct ivishell *shell = userdata;
1487 struct ivisurface *ivisurf = NULL;
1488 uint32_t id_surface = 0;
1490 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1492 ivisurf = create_surface(shell, layout_surface, id_surface);
1493 if (ivisurf == NULL) {
1494 weston_log("failed to create surface");
1500 surface_event_remove(struct ivi_layout_surface *layout_surface,
1503 struct ivishell *shell = userdata;
1504 struct ivicontroller_surface *ctrlsurf = NULL;
1505 struct ivisurface *ivisurf = NULL;
1506 struct ivisurface *next = NULL;
1507 uint32_t id_surface = 0;
1510 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1511 if (layout_surface != ivisurf->layout_surface) {
1515 wl_list_remove(&ivisurf->link);
1518 if (ivisurf->controller_surface_count == 0) {
1522 ivisurf->can_be_removed = 1;
1529 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1531 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1532 if (id_surface != ctrlsurf->id_surface) {
1535 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1541 surface_event_configure(struct ivi_layout_surface *layout_surface,
1544 struct ivishell *shell = userdata;
1545 struct ivisurface *ivisurf = NULL;
1546 struct ivicontroller_surface *ctrlsurf = NULL;
1547 struct ivi_layout_SurfaceProperties prop;
1548 uint32_t id_surface = 0;
1550 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1552 ivisurf = get_surface(&shell->list_surface, id_surface);
1553 if (ivisurf == NULL) {
1554 weston_log("id_surface is not created yet\n");
1558 memset(&prop, 0, sizeof prop);
1559 ivi_layout_getPropertiesOfSurface(layout_surface, &prop);
1561 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1562 if (id_surface != ctrlsurf->id_surface) {
1565 send_surface_event(ctrlsurf->resource, ivisurf,
1566 &prop, IVI_NOTIFICATION_ALL);
1571 check_layout_layers(struct ivishell *shell)
1573 struct ivi_layout_layer **pArray = NULL;
1574 struct ivilayer *ivilayer = NULL;
1575 uint32_t id_layer = 0;
1576 uint32_t length = 0;
1580 ret = ivi_layout_getLayers(&length, &pArray);
1582 weston_log("failed to get layers at check_layout_layers\n");
1587 /* if length is 0, pArray doesn't need to free.*/
1591 for (i = 0; i < length; i++) {
1592 id_layer = ivi_layout_getIdOfLayer(pArray[i]);
1593 ivilayer = create_layer(shell, pArray[i], id_layer);
1594 if (ivilayer == NULL) {
1595 weston_log("failed to create layer");
1606 check_layout_surfaces(struct ivishell *shell)
1608 struct ivi_layout_surface **pArray = NULL;
1609 struct ivisurface *ivisurf = NULL;
1610 uint32_t id_surface = 0;
1611 uint32_t length = 0;
1615 ret = ivi_layout_getSurfaces(&length, &pArray);
1617 weston_log("failed to get surfaces at check_layout_surfaces\n");
1622 /* if length is 0, pArray doesn't need to free.*/
1626 for (i = 0; i < length; i++) {
1627 id_surface = ivi_layout_getIdOfSurface(pArray[i]);
1628 ivisurf = create_surface(shell, pArray[i], id_surface);
1629 if (ivisurf == NULL) {
1630 weston_log("failed to create surface");
1641 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1643 struct weston_output *output = NULL;
1644 struct iviscreen *iviscrn = NULL;
1647 shell->compositor = ec;
1649 wl_list_init(&shell->list_surface);
1650 wl_list_init(&shell->list_layer);
1651 wl_list_init(&shell->list_screen);
1652 wl_list_init(&shell->list_weston_surface);
1653 wl_list_init(&shell->list_controller);
1654 wl_list_init(&shell->list_controller_screen);
1655 wl_list_init(&shell->list_controller_layer);
1656 wl_list_init(&shell->list_controller_surface);
1657 shell->event_restriction = 0;
1659 wl_list_for_each(output, &ec->output_list, link) {
1660 iviscrn = create_screen(shell, output);
1661 if (iviscrn != NULL) {
1662 wl_list_insert(&shell->list_screen, &iviscrn->link);
1666 ret = check_layout_layers(shell);
1668 weston_log("failed to check_layout_layers");
1671 ret = check_layout_surfaces(shell);
1673 weston_log("failed to check_layout_surfaces");
1676 ivi_layout_addNotificationCreateLayer(layer_event_create, shell);
1677 ivi_layout_addNotificationRemoveLayer(layer_event_remove, shell);
1679 ivi_layout_addNotificationCreateSurface(surface_event_create, shell);
1680 ivi_layout_addNotificationRemoveSurface(surface_event_remove, shell);
1681 ivi_layout_addNotificationConfigureSurface(surface_event_configure, shell);
1685 module_init(struct weston_compositor *ec,
1686 int *argc, char *argv[])
1688 struct ivishell *shell;
1692 shell = malloc(sizeof *shell);
1696 memset(shell, 0, sizeof *shell);
1697 init_ivi_shell(ec, shell);
1699 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
1700 shell, bind_ivi_controller) == NULL) {