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);
557 wl_list_remove(&link_scrn->link);
562 else if (mask & IVI_NOTIFICATION_ADD) {
563 for (i = 0; i < (int)length; i++) {
564 /* Create list_screen */
565 link_scrn = calloc(1, sizeof(*link_scrn));
566 if (NULL == link_scrn) {
569 wl_list_init(&link_scrn->link);
570 link_scrn->screen = NULL;
571 wl_list_for_each(iviscrn, &shell->list_screen, link) {
572 if (iviscrn->layout_screen == pArray[i]) {
573 link_scrn->screen = iviscrn;
578 if (link_scrn->screen == NULL) {
583 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
585 /* Send new layer event */
587 wl_resource_find_for_client(&iviscrn->output->resource_list,
589 if (resource_output != NULL) {
590 ivi_controller_layer_send_screen(resource, resource_output);
600 send_layer_event(struct wl_resource *resource,
601 struct ivilayer *ivilayer,
602 struct ivi_layout_LayerProperties *prop,
605 if (mask & IVI_NOTIFICATION_OPACITY) {
606 ivi_controller_layer_send_opacity(resource,
609 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
610 ivi_controller_layer_send_source_rectangle(resource,
616 if (mask & IVI_NOTIFICATION_DEST_RECT) {
617 ivi_controller_layer_send_destination_rectangle(resource,
623 if (mask & IVI_NOTIFICATION_ORIENTATION) {
624 ivi_controller_layer_send_orientation(resource,
627 if (mask & IVI_NOTIFICATION_VISIBILITY) {
628 ivi_controller_layer_send_visibility(resource,
631 if (mask & IVI_NOTIFICATION_ADD) {
632 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_ADD);
634 if (mask & IVI_NOTIFICATION_REMOVE) {
635 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_REMOVE);
640 send_layer_prop(struct ivi_layout_layer *layer,
641 struct ivi_layout_LayerProperties *prop,
642 enum ivi_layout_notification_mask mask,
645 struct ivilayer *ivilayer = userdata;
646 struct ivicontroller_layer *ctrllayer = NULL;
647 struct ivishell *shell = ivilayer->shell;
648 uint32_t id_layout_layer = 0;
650 id_layout_layer = ivi_layout_getIdOfLayer(layer);
651 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
652 if (id_layout_layer != ctrllayer->id_layer) {
655 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
660 controller_surface_set_opacity(struct wl_client *client,
661 struct wl_resource *resource,
664 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
666 ivi_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
670 controller_surface_set_source_rectangle(struct wl_client *client,
671 struct wl_resource *resource,
677 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
679 ivi_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
680 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
684 controller_surface_set_destination_rectangle(struct wl_client *client,
685 struct wl_resource *resource,
691 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
693 ivi_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
694 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
698 controller_surface_set_visibility(struct wl_client *client,
699 struct wl_resource *resource,
702 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
704 ivi_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
708 controller_surface_set_configuration(struct wl_client *client,
709 struct wl_resource *resource,
710 int32_t width, int32_t height)
712 /* This interface has been supported yet. */
720 controller_surface_set_orientation(struct wl_client *client,
721 struct wl_resource *resource,
724 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
726 ivi_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
730 controller_surface_screenshot(struct wl_client *client,
731 struct wl_resource *resource,
732 const char *filename)
734 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
736 ivi_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
740 controller_surface_send_stats(struct wl_client *client,
741 struct wl_resource *resource)
743 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
747 wl_client_get_credentials(client, &pid, &uid, &gid);
749 ivi_controller_surface_send_stats(resource, 0, 0,
750 ivisurf->update_count, pid, "");
754 controller_surface_destroy(struct wl_client *client,
755 struct wl_resource *resource,
756 int32_t destroy_scene_object)
759 (void)destroy_scene_object;
760 wl_resource_destroy(resource);
764 controller_surface_set_input_focus(struct wl_client *client,
765 struct wl_resource *resource,
774 struct ivi_controller_surface_interface controller_surface_implementation = {
775 controller_surface_set_visibility,
776 controller_surface_set_opacity,
777 controller_surface_set_source_rectangle,
778 controller_surface_set_destination_rectangle,
779 controller_surface_set_configuration,
780 controller_surface_set_orientation,
781 controller_surface_screenshot,
782 controller_surface_send_stats,
783 controller_surface_destroy,
784 controller_surface_set_input_focus
788 controller_layer_set_source_rectangle(struct wl_client *client,
789 struct wl_resource *resource,
795 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
797 ivi_layout_layerSetSourceRectangle(ivilayer->layout_layer,
798 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
802 controller_layer_set_destination_rectangle(struct wl_client *client,
803 struct wl_resource *resource,
809 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
811 ivi_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
812 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
816 controller_layer_set_visibility(struct wl_client *client,
817 struct wl_resource *resource,
820 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
822 ivi_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
826 controller_layer_set_opacity(struct wl_client *client,
827 struct wl_resource *resource,
830 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
832 ivi_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
836 controller_layer_set_configuration(struct wl_client *client,
837 struct wl_resource *resource,
841 /* This interface has been supported yet. */
849 controller_layer_set_orientation(struct wl_client *client,
850 struct wl_resource *resource,
853 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
855 ivi_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
859 controller_layer_clear_surfaces(struct wl_client *client,
860 struct wl_resource *resource)
862 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
864 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
868 controller_layer_add_surface(struct wl_client *client,
869 struct wl_resource *resource,
870 struct wl_resource *surface)
872 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
873 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
875 ivi_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
879 controller_layer_remove_surface(struct wl_client *client,
880 struct wl_resource *resource,
881 struct wl_resource *surface)
883 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
884 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
886 ivi_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
890 controller_layer_screenshot(struct wl_client *client,
891 struct wl_resource *resource,
892 const char *filename)
900 controller_layer_set_render_order(struct wl_client *client,
901 struct wl_resource *resource,
902 struct wl_array *id_surfaces)
904 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
905 struct ivi_layout_surface **layoutsurf_array = NULL;
906 struct ivisurface *ivisurf = NULL;
907 uint32_t *id_surface = NULL;
908 uint32_t id_layout_surface = 0;
912 wl_array_for_each(id_surface, id_surfaces) {
913 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
914 id_layout_surface = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
915 if (*id_surface == id_layout_surface) {
916 layoutsurf_array[i] = ivisurf->layout_surface;
923 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer,
924 layoutsurf_array, id_surfaces->size);
925 free(layoutsurf_array);
929 controller_layer_destroy(struct wl_client *client,
930 struct wl_resource *resource,
931 int32_t destroy_scene_object)
933 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
934 struct ivishell *shell = ivilayer->shell;
935 struct ivicontroller_layer *ctrllayer = NULL;
936 struct ivicontroller_layer *next = NULL;
937 uint32_t id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
939 (void)destroy_scene_object;
941 ivilayer->layer_canbe_removed = 1;
942 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
943 if (ctrllayer->id_layer != id_layer) {
947 wl_resource_destroy(ctrllayer->resource);
952 struct ivi_controller_layer_interface controller_layer_implementation = {
953 controller_layer_set_visibility,
954 controller_layer_set_opacity,
955 controller_layer_set_source_rectangle,
956 controller_layer_set_destination_rectangle,
957 controller_layer_set_configuration,
958 controller_layer_set_orientation,
959 controller_layer_screenshot,
960 controller_layer_clear_surfaces,
961 controller_layer_add_surface,
962 controller_layer_remove_surface,
963 controller_layer_set_render_order,
964 controller_layer_destroy
968 controller_screen_destroy(struct wl_client *client,
969 struct wl_resource *resource)
971 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
972 struct ivicontroller_screen *ctrlscrn = NULL;
973 struct ivicontroller_screen *next = NULL;
974 // uint32_t id_screen = ivi_layout_getIdOfScreen(iviscrn->layout_screen);
977 wl_list_for_each_safe(ctrlscrn, next,
978 &iviscrn->shell->list_controller_screen, link) {
979 if (resource != ctrlscrn->resource) {
983 wl_list_remove(&ctrlscrn->link);
986 wl_resource_destroy(ctrlscrn->resource);
992 controller_screen_clear(struct wl_client *client,
993 struct wl_resource *resource)
995 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
997 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
1001 controller_screen_add_layer(struct wl_client *client,
1002 struct wl_resource *resource,
1003 struct wl_resource *layer)
1005 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1006 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
1008 ivi_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
1012 controller_screen_screenshot(struct wl_client *client,
1013 struct wl_resource *resource,
1014 const char *filename)
1016 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1018 ivi_layout_takeScreenshot(iviscrn->layout_screen, filename);
1022 controller_screen_set_render_order(struct wl_client *client,
1023 struct wl_resource *resource,
1024 struct wl_array *id_layers)
1026 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1027 struct ivi_layout_layer **layoutlayer_array = NULL;
1028 struct ivilayer *ivilayer = NULL;
1029 uint32_t *id_layer = NULL;
1030 uint32_t id_layout_layer = 0;
1034 *layoutlayer_array = (struct ivi_layout_layer*)calloc(
1035 id_layers->size, sizeof(void*));
1037 wl_array_for_each(id_layer, id_layers) {
1038 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1039 id_layout_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1040 if (*id_layer == id_layout_layer) {
1041 layoutlayer_array[i] = ivilayer->layout_layer;
1048 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen,
1049 layoutlayer_array, id_layers->size);
1050 free(layoutlayer_array);
1054 struct ivi_controller_screen_interface controller_screen_implementation = {
1055 controller_screen_destroy,
1056 controller_screen_clear,
1057 controller_screen_add_layer,
1058 controller_screen_screenshot,
1059 controller_screen_set_render_order
1063 controller_commit_changes(struct wl_client *client,
1064 struct wl_resource *resource)
1070 ans = ivi_layout_commitChanges();
1072 weston_log("Failed to commit changes at controller_commit_changes\n");
1077 controller_layer_create(struct wl_client *client,
1078 struct wl_resource *resource,
1084 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1085 struct ivishell *shell = ctrl->shell;
1086 struct ivi_layout_layer *layout_layer = NULL;
1087 struct ivicontroller_layer *ctrllayer = NULL;
1088 struct ivilayer *ivilayer = NULL;
1089 struct ivi_layout_LayerProperties prop;
1091 ivilayer = get_layer(&shell->list_layer, id_layer);
1092 if (ivilayer == NULL) {
1093 layout_layer = ivi_layout_layerCreateWithDimension(id_layer,
1094 (uint32_t)width, (uint32_t)height);
1095 if (layout_layer == NULL) {
1096 weston_log("id_layer is already created\n");
1100 /* ivilayer will be created by layer_event_create */
1101 ivilayer = get_layer(&shell->list_layer, id_layer);
1102 if (ivilayer == NULL) {
1103 weston_log("couldn't get layer object\n");
1108 ctrllayer = calloc(1, sizeof *ctrllayer);
1110 weston_log("no memory to allocate client layer\n");
1114 ++ivilayer->controller_layer_count;
1115 ivilayer->layer_canbe_removed = 0;
1117 ctrllayer->shell = shell;
1118 ctrllayer->client = client;
1120 ctrllayer->id_layer = id_layer;
1121 ctrllayer->resource = wl_resource_create(client,
1122 &ivi_controller_layer_interface, 1, id);
1123 if (ctrllayer->resource == NULL) {
1124 weston_log("couldn't get layer object\n");
1128 wl_list_init(&ctrllayer->link);
1129 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1131 wl_resource_set_implementation(ctrllayer->resource,
1132 &controller_layer_implementation,
1133 ivilayer, destroy_ivicontroller_layer);
1135 memset(&prop, 0, sizeof prop);
1137 ivi_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1138 send_layer_event(ctrllayer->resource, ivilayer,
1139 &prop, IVI_NOTIFICATION_ALL);
1143 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1145 struct ivishell *shell = userdata;
1146 struct ivicontroller_surface *ctrlsurf = NULL;
1147 uint32_t id_surface = 0;
1150 surface_event_remove(layout_surface, userdata);
1155 controller_surface_create(struct wl_client *client,
1156 struct wl_resource *resource,
1157 uint32_t id_surface,
1160 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1161 struct ivishell *shell = ctrl->shell;
1162 struct ivicontroller_surface *ctrlsurf = NULL;
1163 struct ivi_layout_SurfaceProperties prop;
1164 struct ivisurface *ivisurf = NULL;
1166 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1168 weston_log("no memory to allocate controller surface\n");
1172 ctrlsurf->shell = shell;
1173 ctrlsurf->client = client;
1175 ctrlsurf->id_surface = id_surface;
1176 wl_list_init(&ctrlsurf->link);
1177 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1179 ctrlsurf->resource = wl_resource_create(client,
1180 &ivi_controller_surface_interface, 1, id);
1181 if (ctrlsurf->resource == NULL) {
1182 weston_log("couldn't surface object");
1186 ivisurf = get_surface(&shell->list_surface, id_surface);
1187 if (ivisurf == NULL) {
1191 ++ivisurf->controller_surface_count;
1193 wl_resource_set_implementation(ctrlsurf->resource,
1194 &controller_surface_implementation,
1195 ivisurf, destroy_ivicontroller_surface);
1197 memset(&prop, 0, sizeof prop);
1199 ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1200 ivi_layout_surfaceSetContentObserver(ivisurf->layout_surface, surface_event_content, shell);
1202 send_surface_event(ctrlsurf->resource, ivisurf,
1203 &prop, IVI_NOTIFICATION_ALL);
1206 static const struct ivi_controller_interface controller_implementation = {
1207 controller_commit_changes,
1208 controller_layer_create,
1209 controller_surface_create
1213 add_client_to_resources(struct ivishell *shell,
1214 struct wl_client *client,
1215 struct ivicontroller *controller)
1217 struct ivisurface* ivisurf = NULL;
1218 struct ivilayer* ivilayer = NULL;
1219 struct iviscreen* iviscrn = NULL;
1220 struct ivicontroller_screen *ctrlscrn = NULL;
1221 struct wl_resource *resource_output = NULL;
1222 uint32_t id_layout_surface = 0;
1223 uint32_t id_layout_layer = 0;
1225 wl_list_for_each_reverse(ivisurf, &shell->list_surface, link) {
1227 ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1229 ivi_controller_send_surface(controller->resource,
1233 wl_list_for_each_reverse(ivilayer, &shell->list_layer, link) {
1235 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1237 ivi_controller_send_layer(controller->resource,
1241 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1242 resource_output = wl_resource_find_for_client(
1243 &iviscrn->output->resource_list, client);
1244 if (resource_output == NULL) {
1248 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1249 if (ctrlscrn == NULL) {
1253 ivi_controller_send_screen(controller->resource,
1254 wl_resource_get_id(resource_output),
1255 ctrlscrn->resource);
1260 bind_ivi_controller(struct wl_client *client, void *data,
1261 uint32_t version, uint32_t id)
1263 struct ivishell *shell = data;
1264 struct ivicontroller *controller;
1267 controller = calloc(1, sizeof *controller);
1268 if (controller == NULL) {
1269 weston_log("no memory to allocate controller\n");
1273 controller->resource =
1274 wl_resource_create(client, &ivi_controller_interface, 1, id);
1275 wl_resource_set_implementation(controller->resource,
1276 &controller_implementation,
1277 controller, unbind_resource_controller);
1279 controller->shell = shell;
1280 controller->client = client;
1281 controller->id = id;
1283 wl_list_init(&controller->link);
1284 wl_list_insert(&shell->list_controller, &controller->link);
1286 add_client_to_resources(shell, client, controller);
1289 static struct iviscreen*
1290 create_screen(struct ivishell *shell, struct weston_output *output)
1292 struct iviscreen *iviscrn;
1293 iviscrn = calloc(1, sizeof *iviscrn);
1294 if (iviscrn == NULL) {
1295 weston_log("no memory to allocate client screen\n");
1299 iviscrn->shell = shell;
1300 iviscrn->output = output;
1302 // TODO : Only Single display
1303 iviscrn->layout_screen = ivi_layout_getScreenFromId(0);
1305 wl_list_init(&iviscrn->link);
1310 static struct ivilayer*
1311 create_layer(struct ivishell *shell,
1312 struct ivi_layout_layer *layout_layer,
1315 struct ivilayer *ivilayer = NULL;
1316 struct ivicontroller *controller = NULL;
1318 ivilayer = get_layer(&shell->list_layer, id_layer);
1319 if (ivilayer != NULL) {
1320 weston_log("id_layer is already created\n");
1324 ivilayer = calloc(1, sizeof *ivilayer);
1325 if (NULL == ivilayer) {
1326 weston_log("no memory to allocate client layer\n");
1330 ivilayer->shell = shell;
1331 wl_list_init(&ivilayer->list_screen);
1332 wl_list_init(&ivilayer->link);
1333 wl_list_insert(&shell->list_layer, &ivilayer->link);
1334 ivilayer->layout_layer = layout_layer;
1336 ivi_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1338 wl_list_for_each(controller, &shell->list_controller, link) {
1339 ivi_controller_send_layer(controller->resource, id_layer);
1345 static struct ivisurface*
1346 create_surface(struct ivishell *shell,
1347 struct ivi_layout_surface *layout_surface,
1348 uint32_t id_surface)
1350 struct ivisurface *ivisurf = NULL;
1351 struct ivicontroller *controller = NULL;
1353 ivisurf = get_surface(&shell->list_surface, id_surface);
1354 if (ivisurf != NULL) {
1355 weston_log("id_surface is already created\n");
1359 ivisurf = calloc(1, sizeof *ivisurf);
1360 if (ivisurf == NULL) {
1361 weston_log("no memory to allocate client surface\n");
1365 ivisurf->shell = shell;
1366 ivisurf->layout_surface = layout_surface;
1367 wl_list_init(&ivisurf->list_layer);
1368 wl_list_init(&ivisurf->link);
1369 wl_list_insert(&shell->list_surface, &ivisurf->link);
1371 wl_list_for_each(controller, &shell->list_controller, link) {
1372 ivi_controller_send_surface(controller->resource,
1376 ivi_layout_surfaceAddNotification(layout_surface,
1377 send_surface_prop, ivisurf);
1383 layer_event_create(struct ivi_layout_layer *layout_layer,
1386 struct ivishell *shell = userdata;
1387 struct ivilayer *ivilayer = NULL;
1388 uint32_t id_layer = 0;
1390 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1392 ivilayer = create_layer(shell, layout_layer, id_layer);
1393 if (ivilayer == NULL) {
1394 weston_log("failed to create layer");
1400 layer_event_remove(struct ivi_layout_layer *layout_layer,
1403 struct ivishell *shell = userdata;
1404 struct ivicontroller_layer *ctrllayer = NULL;
1405 struct ivilayer *ivilayer = NULL;
1406 struct ivilayer *next = NULL;
1407 uint32_t id_layer = 0;
1410 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1411 if (layout_layer != ivilayer->layout_layer) {
1415 wl_list_remove(&ivilayer->link);
1424 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1426 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1427 if (id_layer != ctrllayer->id_layer) {
1430 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1437 surface_event_create(struct ivi_layout_surface *layout_surface,
1440 struct ivishell *shell = userdata;
1441 struct ivisurface *ivisurf = NULL;
1442 uint32_t id_surface = 0;
1444 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1446 ivisurf = create_surface(shell, layout_surface, id_surface);
1447 if (ivisurf == NULL) {
1448 weston_log("failed to create surface");
1454 surface_event_remove(struct ivi_layout_surface *layout_surface,
1457 struct ivishell *shell = userdata;
1458 struct ivicontroller_surface *ctrlsurf = NULL;
1459 struct ivisurface *ivisurf = NULL;
1460 struct ivisurface *next = NULL;
1461 uint32_t id_surface = 0;
1464 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1465 if (layout_surface != ivisurf->layout_surface) {
1469 wl_list_remove(&ivisurf->link);
1472 if (ivisurf->controller_surface_count == 0) {
1476 ivisurf->can_be_removed = 1;
1483 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1485 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1486 if (id_surface != ctrlsurf->id_surface) {
1489 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1495 surface_event_configure(struct ivi_layout_surface *layout_surface,
1498 struct ivishell *shell = userdata;
1499 struct ivisurface *ivisurf = NULL;
1500 struct ivicontroller_surface *ctrlsurf = NULL;
1501 struct ivi_layout_SurfaceProperties prop;
1502 uint32_t id_surface = 0;
1504 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1506 ivisurf = get_surface(&shell->list_surface, id_surface);
1507 if (ivisurf == NULL) {
1508 weston_log("id_surface is not created yet\n");
1512 memset(&prop, 0, sizeof prop);
1513 ivi_layout_getPropertiesOfSurface(layout_surface, &prop);
1515 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1516 if (id_surface != ctrlsurf->id_surface) {
1519 send_surface_event(ctrlsurf->resource, ivisurf,
1520 &prop, IVI_NOTIFICATION_ALL);
1525 check_layout_layers(struct ivishell *shell)
1527 struct ivi_layout_layer **pArray = NULL;
1528 struct ivilayer *ivilayer = NULL;
1529 uint32_t id_layer = 0;
1530 uint32_t length = 0;
1534 ret = ivi_layout_getLayers(&length, &pArray);
1536 weston_log("failed to get layers at check_layout_layers\n");
1541 /* if length is 0, pArray doesn't need to free.*/
1545 for (i = 0; i < length; i++) {
1546 id_layer = ivi_layout_getIdOfLayer(pArray[i]);
1547 ivilayer = create_layer(shell, pArray[i], id_layer);
1548 if (ivilayer == NULL) {
1549 weston_log("failed to create layer");
1560 check_layout_surfaces(struct ivishell *shell)
1562 struct ivi_layout_surface **pArray = NULL;
1563 struct ivisurface *ivisurf = NULL;
1564 uint32_t id_surface = 0;
1565 uint32_t length = 0;
1569 ret = ivi_layout_getSurfaces(&length, &pArray);
1571 weston_log("failed to get surfaces at check_layout_surfaces\n");
1576 /* if length is 0, pArray doesn't need to free.*/
1580 for (i = 0; i < length; i++) {
1581 id_surface = ivi_layout_getIdOfSurface(pArray[i]);
1582 ivisurf = create_surface(shell, pArray[i], id_surface);
1583 if (ivisurf == NULL) {
1584 weston_log("failed to create surface");
1595 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1597 struct weston_output *output = NULL;
1598 struct iviscreen *iviscrn = NULL;
1601 shell->compositor = ec;
1603 wl_list_init(&shell->list_surface);
1604 wl_list_init(&shell->list_layer);
1605 wl_list_init(&shell->list_screen);
1606 wl_list_init(&shell->list_weston_surface);
1607 wl_list_init(&shell->list_controller);
1608 wl_list_init(&shell->list_controller_screen);
1609 wl_list_init(&shell->list_controller_layer);
1610 wl_list_init(&shell->list_controller_surface);
1611 shell->event_restriction = 0;
1613 wl_list_for_each(output, &ec->output_list, link) {
1614 iviscrn = create_screen(shell, output);
1615 if (iviscrn != NULL) {
1616 wl_list_insert(&shell->list_screen, &iviscrn->link);
1620 ret = check_layout_layers(shell);
1622 weston_log("failed to check_layout_layers");
1625 ret = check_layout_surfaces(shell);
1627 weston_log("failed to check_layout_surfaces");
1630 ivi_layout_addNotificationCreateLayer(layer_event_create, shell);
1631 ivi_layout_addNotificationRemoveLayer(layer_event_remove, shell);
1633 ivi_layout_addNotificationCreateSurface(surface_event_create, shell);
1634 ivi_layout_addNotificationRemoveSurface(surface_event_remove, shell);
1635 ivi_layout_addNotificationConfigureSurface(surface_event_configure, shell);
1639 module_init(struct weston_compositor *ec,
1640 int *argc, char *argv[])
1642 struct ivishell *shell;
1646 shell = malloc(sizeof *shell);
1650 memset(shell, 0, sizeof *shell);
1651 init_ivi_shell(ec, shell);
1653 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
1654 shell, bind_ivi_controller) == NULL) {