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;
71 struct ivishell *shell;
72 struct ivi_layout_screen *layout_screen;
73 struct weston_output *output;
76 struct ivicontroller_surface {
77 struct wl_resource *resource;
80 struct wl_client *client;
82 struct ivishell *shell;
85 struct ivicontroller_layer {
86 struct wl_resource *resource;
89 struct wl_client *client;
91 struct ivishell *shell;
94 struct ivicontroller_screen {
95 struct wl_resource *resource;
98 struct wl_client *client;
100 struct ivishell *shell;
103 struct ivicontroller {
104 struct wl_resource *resource;
106 struct wl_client *client;
108 struct ivishell *shell;
111 struct link_shell_weston_surface
113 struct wl_resource *resource;
114 struct wl_listener destroy_listener;
115 struct weston_surface *surface;
120 struct wl_resource *resource;
122 struct wl_listener destroy_listener;
124 struct weston_compositor *compositor;
126 struct weston_surface *surface;
128 struct weston_process process;
130 struct weston_seat *seat;
132 struct wl_list list_surface;
133 struct wl_list list_layer;
134 struct wl_list list_screen;
136 struct wl_list list_weston_surface;
138 struct wl_list list_controller;
139 struct wl_list list_controller_surface;
140 struct wl_list list_controller_layer;
141 struct wl_list list_controller_screen;
144 struct weston_process process;
145 struct wl_client *client;
146 struct wl_resource *desktop_shell;
154 int event_restriction;
158 destroy_ivicontroller_surface(struct wl_resource *resource)
160 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
161 struct ivishell *shell = ivisurf->shell;
162 struct ivicontroller_surface *ctrlsurf = NULL;
163 struct ivicontroller_surface *next = NULL;
166 wl_list_for_each_safe(ctrlsurf, next,
167 &shell->list_controller_surface, link) {
169 if (resource != ctrlsurf->resource) {
173 if (!wl_list_empty(&ctrlsurf->link)) {
174 wl_list_remove(&ctrlsurf->link);
180 --ivisurf->controller_surface_count;
184 if ((is_removed) && (ivisurf->controller_surface_count == 0)) {
185 if (ivisurf->can_be_removed) {
189 ivisurf->can_be_removed = 1;
195 destroy_ivicontroller_layer(struct wl_resource *resource)
197 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
198 struct ivishell *shell = ivilayer->shell;
199 struct ivicontroller_layer *ctrllayer = NULL;
200 struct ivicontroller_layer *next = NULL;
201 uint32_t id_layer = 0;
203 id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
205 wl_list_for_each_safe(ctrllayer, next,
206 &shell->list_controller_layer, link) {
208 if (resource != ctrllayer->resource) {
212 wl_list_remove(&ctrllayer->link);
213 --ivilayer->controller_layer_count;
219 if ((ivilayer->layout_layer != NULL) &&
220 (ivilayer->controller_layer_count == 0)) {
221 ivi_layout_layerRemove(ivilayer->layout_layer);
226 destroy_ivicontroller_screen(struct wl_resource *resource)
228 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
229 struct ivicontroller_screen *ctrlscrn = NULL;
230 struct ivicontroller_screen *next = NULL;
232 wl_list_for_each_safe(ctrlscrn, next,
233 &iviscrn->shell->list_controller_screen, link) {
234 // TODO : Only Single display
236 if (iviscrn->output->id != ctrlscrn->id_screen) {
241 if (resource != ctrlscrn->resource) {
245 wl_list_remove(&ctrlscrn->link);
253 unbind_resource_controller(struct wl_resource *resource)
255 struct ivicontroller *controller = wl_resource_get_user_data(resource);
257 wl_list_remove(&controller->link);
263 static struct ivisurface*
264 get_surface(struct wl_list *list_surf, uint32_t id_surface)
266 struct ivisurface *ivisurf = NULL;
267 uint32_t ivisurf_id = 0;
269 wl_list_for_each(ivisurf, list_surf, link) {
270 ivisurf_id = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
271 if (ivisurf_id == id_surface) {
279 static struct ivilayer*
280 get_layer(struct wl_list *list_layer, uint32_t id_layer)
282 struct ivilayer *ivilayer = NULL;
283 uint32_t ivilayer_id = 0;
285 wl_list_for_each(ivilayer, list_layer, link) {
286 ivilayer_id = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
287 if (ivilayer_id == id_layer) {
296 struct ivi_controller_screen_interface controller_screen_implementation;
298 static struct ivicontroller_screen*
299 controller_screen_create(struct ivishell *shell,
300 struct wl_client *client,
301 struct iviscreen *iviscrn)
303 struct ivicontroller_screen *ctrlscrn = NULL;
305 ctrlscrn = calloc(1, sizeof *ctrlscrn);
306 if (ctrlscrn == NULL) {
307 weston_log("no memory to allocate controller screen\n");
311 ctrlscrn->client = client;
312 ctrlscrn->shell = shell;
314 // TODO : Only Single display
316 /* ctrlscrn->id_screen = iviscrn->id_screen; */
318 ctrlscrn->id_screen = 0;
322 wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
323 if (ctrlscrn->resource == NULL) {
324 weston_log("couldn't new screen controller object");
332 wl_resource_set_implementation(ctrlscrn->resource,
333 &controller_screen_implementation,
334 iviscrn, destroy_ivicontroller_screen);
336 wl_list_init(&ctrlscrn->link);
337 wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
343 send_surface_add_event(struct ivisurface *ivisurf,
344 struct wl_resource *resource)
346 struct ivi_layout_layer **pArray = NULL;
350 struct link_layer *link_layer = NULL;
351 struct link_layer *next = NULL;
352 struct ivicontroller_layer *ctrllayer = NULL;
353 struct ivilayer *ivilayer = NULL;
354 struct ivishell *shell = ivisurf->shell;
355 uint32_t id_layout_layer = 0;
358 ans = ivi_layout_getLayersUnderSurface(ivisurf->layout_surface,
361 weston_log("failed to get layers at send_surface_add_event\n");
365 /* Send Null to cancel added surface */
366 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
367 for (i = 0, found = 0; i < (int)length; i++) {
368 if (pArray[i] == link_layer->layer->layout_layer) {
369 /* No need to send event, if new layer doesn't be added. */
378 ivi_controller_surface_send_layer(resource, NULL);
379 wl_list_remove(&link_layer->link);
384 for (i = 0; i < (int)length; i++) {
386 wl_list_for_each(link_layer, &ivisurf->list_layer, link) {
387 if (pArray[i] == link_layer->layer->layout_layer) {
388 /* No need to send event, if new layer doesn't be added. */
397 /* Create list_layer */
398 link_layer = calloc(1, sizeof(*link_layer));
399 if (NULL == link_layer) {
402 wl_list_init(&link_layer->link);
403 link_layer->layer = NULL;
404 wl_list_for_each(ivilayer, &shell->list_layer, link) {
405 if (ivilayer->layout_layer == pArray[i]) {
406 link_layer->layer = ivilayer;
411 if (link_layer->layer == NULL) {
416 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
418 /* Send new surface event */
420 ivi_layout_getIdOfLayer(link_layer->layer->layout_layer);
421 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
422 if (id_layout_layer != ctrllayer->id_layer) {
425 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
434 send_surface_event(struct wl_resource *resource,
435 struct ivisurface *ivisurf,
436 struct ivi_layout_SurfaceProperties *prop,
439 if (mask & IVI_NOTIFICATION_OPACITY) {
440 ivi_controller_surface_send_opacity(resource,
443 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
444 ivi_controller_surface_send_source_rectangle(resource,
445 prop->sourceX, prop->sourceY,
446 prop->sourceWidth, prop->sourceHeight);
448 if (mask & IVI_NOTIFICATION_DEST_RECT) {
449 ivi_controller_surface_send_destination_rectangle(resource,
450 prop->destX, prop->destY,
451 prop->destWidth, prop->destHeight);
453 if (mask & IVI_NOTIFICATION_ORIENTATION) {
454 ivi_controller_surface_send_orientation(resource,
457 if (mask & IVI_NOTIFICATION_VISIBILITY) {
458 ivi_controller_surface_send_visibility(resource,
461 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
462 ivi_controller_surface_send_pixelformat(resource,
465 if (mask & IVI_NOTIFICATION_ADD) {
466 send_surface_add_event(ivisurf, resource);
471 send_surface_prop(struct ivi_layout_surface *layout_surface,
472 struct ivi_layout_SurfaceProperties *prop,
473 enum ivi_layout_notification_mask mask,
476 struct ivisurface *ivisurf = userdata;
477 struct ivishell *shell = ivisurf->shell;
478 struct ivicontroller_surface *ctrlsurf = NULL;
479 uint32_t id_surface = 0;
481 id_surface = ivi_layout_getIdOfSurface(layout_surface);
483 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
484 if (id_surface != ctrlsurf->id_surface) {
487 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
492 send_layer_add_event(struct ivilayer *ivilayer,
493 struct wl_resource *resource)
495 struct ivi_layout_screen **pArray = NULL;
499 struct link_screen *link_scrn = NULL;
500 struct link_screen *next = NULL;
501 struct iviscreen *iviscrn = NULL;
502 struct ivishell *shell = ivilayer->shell;
504 struct wl_client *client = wl_resource_get_client(resource);
505 struct wl_resource *resource_output = NULL;
507 ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
510 weston_log("failed to get screens at send_layer_add_event\n");
514 /* Send Null to cancel added layer */
515 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
516 for (i = 0, found = 0; i < (int)length; i++) {
517 if (pArray[i] == link_scrn->screen->layout_screen) {
518 /* No need to send event, if new layer doesn't be added. */
527 ivi_controller_layer_send_screen(resource, NULL);
528 wl_list_remove(&link_scrn->link);
533 for (i = 0; i < (int)length; i++) {
535 wl_list_for_each(link_scrn, &ivilayer->list_screen, link) {
536 if (pArray[i] == link_scrn->screen->layout_screen) {
537 /* No need to send event, if new screen doesn't be added. */
546 /* Create list_screen */
547 link_scrn = calloc(1, sizeof(*link_scrn));
548 if (NULL == link_scrn) {
551 wl_list_init(&link_scrn->link);
552 link_scrn->screen = NULL;
553 wl_list_for_each(iviscrn, &shell->list_screen, link) {
554 if (iviscrn->layout_screen == pArray[i]) {
555 link_scrn->screen = iviscrn;
560 if (link_scrn->screen == NULL) {
565 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
567 /* Send new layer event */
569 wl_resource_find_for_client(&iviscrn->output->resource_list,
571 if (resource_output != NULL) {
572 ivi_controller_layer_send_screen(resource, resource_output);
581 send_layer_event(struct wl_resource *resource,
582 struct ivilayer *ivilayer,
583 struct ivi_layout_LayerProperties *prop,
586 if (mask & IVI_NOTIFICATION_OPACITY) {
587 ivi_controller_layer_send_opacity(resource,
590 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
591 ivi_controller_layer_send_source_rectangle(resource,
597 if (mask & IVI_NOTIFICATION_DEST_RECT) {
598 ivi_controller_layer_send_destination_rectangle(resource,
604 if (mask & IVI_NOTIFICATION_ORIENTATION) {
605 ivi_controller_layer_send_orientation(resource,
608 if (mask & IVI_NOTIFICATION_VISIBILITY) {
609 ivi_controller_layer_send_visibility(resource,
612 if (mask & IVI_NOTIFICATION_ADD) {
613 send_layer_add_event(ivilayer, resource);
615 if (mask & IVI_NOTIFICATION_REMOVE) {
616 send_layer_add_event(ivilayer, resource);
621 send_layer_prop(struct ivi_layout_layer *layer,
622 struct ivi_layout_LayerProperties *prop,
623 enum ivi_layout_notification_mask mask,
626 struct ivilayer *ivilayer = userdata;
627 struct ivicontroller_layer *ctrllayer = NULL;
628 struct ivishell *shell = ivilayer->shell;
629 uint32_t id_layout_layer = 0;
631 id_layout_layer = ivi_layout_getIdOfLayer(layer);
632 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
633 if (id_layout_layer != ctrllayer->id_layer) {
636 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
641 controller_surface_set_opacity(struct wl_client *client,
642 struct wl_resource *resource,
645 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
647 ivi_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
651 controller_surface_set_source_rectangle(struct wl_client *client,
652 struct wl_resource *resource,
658 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
660 ivi_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
661 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
665 controller_surface_set_destination_rectangle(struct wl_client *client,
666 struct wl_resource *resource,
672 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
674 ivi_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
675 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
679 controller_surface_set_visibility(struct wl_client *client,
680 struct wl_resource *resource,
683 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
685 ivi_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
689 controller_surface_set_configuration(struct wl_client *client,
690 struct wl_resource *resource,
691 int32_t width, int32_t height)
693 /* This interface has been supported yet. */
701 controller_surface_set_orientation(struct wl_client *client,
702 struct wl_resource *resource,
705 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
707 ivi_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
711 controller_surface_screenshot(struct wl_client *client,
712 struct wl_resource *resource,
713 const char *filename)
715 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
717 ivi_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
721 controller_surface_send_stats(struct wl_client *client,
722 struct wl_resource *resource)
724 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
728 wl_client_get_credentials(client, &pid, &uid, &gid);
730 ivi_controller_surface_send_stats(resource, 0, 0,
731 ivisurf->update_count, pid, "");
735 controller_surface_destroy(struct wl_client *client,
736 struct wl_resource *resource,
737 int32_t destroy_scene_object)
740 (void)destroy_scene_object;
741 wl_resource_destroy(resource);
745 controller_surface_set_input_focus(struct wl_client *client,
746 struct wl_resource *resource,
755 struct ivi_controller_surface_interface controller_surface_implementation = {
756 controller_surface_set_visibility,
757 controller_surface_set_opacity,
758 controller_surface_set_source_rectangle,
759 controller_surface_set_destination_rectangle,
760 controller_surface_set_configuration,
761 controller_surface_set_orientation,
762 controller_surface_screenshot,
763 controller_surface_send_stats,
764 controller_surface_destroy,
765 controller_surface_set_input_focus
769 controller_layer_set_source_rectangle(struct wl_client *client,
770 struct wl_resource *resource,
776 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
778 ivi_layout_layerSetSourceRectangle(ivilayer->layout_layer,
779 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
783 controller_layer_set_destination_rectangle(struct wl_client *client,
784 struct wl_resource *resource,
790 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
792 ivi_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
793 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
797 controller_layer_set_visibility(struct wl_client *client,
798 struct wl_resource *resource,
801 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
803 ivi_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
807 controller_layer_set_opacity(struct wl_client *client,
808 struct wl_resource *resource,
811 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
813 ivi_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
817 controller_layer_set_configuration(struct wl_client *client,
818 struct wl_resource *resource,
822 /* This interface has been supported yet. */
830 controller_layer_set_orientation(struct wl_client *client,
831 struct wl_resource *resource,
834 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
836 ivi_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
840 controller_layer_clear_surfaces(struct wl_client *client,
841 struct wl_resource *resource)
843 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
845 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
849 controller_layer_add_surface(struct wl_client *client,
850 struct wl_resource *resource,
851 struct wl_resource *surface)
853 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
854 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
856 ivi_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
860 controller_layer_remove_surface(struct wl_client *client,
861 struct wl_resource *resource,
862 struct wl_resource *surface)
864 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
865 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
867 ivi_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
871 controller_layer_screenshot(struct wl_client *client,
872 struct wl_resource *resource,
873 const char *filename)
881 controller_layer_set_render_order(struct wl_client *client,
882 struct wl_resource *resource,
883 struct wl_array *id_surfaces)
885 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
886 struct ivi_layout_surface **layoutsurf_array = NULL;
887 struct ivisurface *ivisurf = NULL;
888 uint32_t *id_surface = NULL;
889 uint32_t id_layout_surface = 0;
893 wl_array_for_each(id_surface, id_surfaces) {
894 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
895 id_layout_surface = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
896 if (*id_surface == id_layout_surface) {
897 layoutsurf_array[i] = ivisurf->layout_surface;
904 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer,
905 layoutsurf_array, id_surfaces->size);
906 free(layoutsurf_array);
910 controller_layer_destroy(struct wl_client *client,
911 struct wl_resource *resource,
912 int32_t destroy_scene_object)
914 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
915 struct ivishell *shell = ivilayer->shell;
916 struct ivicontroller_layer *ctrllayer = NULL;
917 struct ivicontroller_layer *next = NULL;
918 uint32_t id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
920 (void)destroy_scene_object;
922 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
923 if (ctrllayer->resource != resource) {
927 wl_resource_destroy(resource);
933 struct ivi_controller_layer_interface controller_layer_implementation = {
934 controller_layer_set_visibility,
935 controller_layer_set_opacity,
936 controller_layer_set_source_rectangle,
937 controller_layer_set_destination_rectangle,
938 controller_layer_set_configuration,
939 controller_layer_set_orientation,
940 controller_layer_screenshot,
941 controller_layer_clear_surfaces,
942 controller_layer_add_surface,
943 controller_layer_remove_surface,
944 controller_layer_set_render_order,
945 controller_layer_destroy
949 controller_screen_destroy(struct wl_client *client,
950 struct wl_resource *resource)
952 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
953 struct ivicontroller_screen *ctrlscrn = NULL;
954 struct ivicontroller_screen *next = NULL;
955 // uint32_t id_screen = ivi_layout_getIdOfScreen(iviscrn->layout_screen);
958 wl_list_for_each_safe(ctrlscrn, next,
959 &iviscrn->shell->list_controller_screen, link) {
960 if (resource != ctrlscrn->resource) {
964 wl_list_remove(&ctrlscrn->link);
967 wl_resource_destroy(ctrlscrn->resource);
973 controller_screen_clear(struct wl_client *client,
974 struct wl_resource *resource)
976 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
978 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
982 controller_screen_add_layer(struct wl_client *client,
983 struct wl_resource *resource,
984 struct wl_resource *layer)
986 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
987 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
989 ivi_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
993 controller_screen_screenshot(struct wl_client *client,
994 struct wl_resource *resource,
995 const char *filename)
997 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
999 ivi_layout_takeScreenshot(iviscrn->layout_screen, filename);
1003 controller_screen_set_render_order(struct wl_client *client,
1004 struct wl_resource *resource,
1005 struct wl_array *id_layers)
1007 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1008 struct ivi_layout_layer **layoutlayer_array = NULL;
1009 struct ivilayer *ivilayer = NULL;
1010 uint32_t *id_layer = NULL;
1011 uint32_t id_layout_layer = 0;
1015 *layoutlayer_array = (struct ivi_layout_layer*)calloc(
1016 id_layers->size, sizeof(void*));
1018 wl_array_for_each(id_layer, id_layers) {
1019 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1020 id_layout_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1021 if (*id_layer == id_layout_layer) {
1022 layoutlayer_array[i] = ivilayer->layout_layer;
1029 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen,
1030 layoutlayer_array, id_layers->size);
1031 free(layoutlayer_array);
1035 struct ivi_controller_screen_interface controller_screen_implementation = {
1036 controller_screen_destroy,
1037 controller_screen_clear,
1038 controller_screen_add_layer,
1039 controller_screen_screenshot,
1040 controller_screen_set_render_order
1044 controller_commit_changes(struct wl_client *client,
1045 struct wl_resource *resource)
1051 ans = ivi_layout_commitChanges();
1053 weston_log("Failed to commit changes at controller_commit_changes\n");
1058 controller_layer_create(struct wl_client *client,
1059 struct wl_resource *resource,
1065 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1066 struct ivishell *shell = ctrl->shell;
1067 struct ivi_layout_layer *layout_layer = NULL;
1068 struct ivicontroller_layer *ctrllayer = NULL;
1069 struct ivilayer *ivilayer = NULL;
1070 struct ivi_layout_LayerProperties prop;
1072 ivilayer = get_layer(&shell->list_layer, id_layer);
1073 if (ivilayer == NULL) {
1074 layout_layer = ivi_layout_layerCreateWithDimension(id_layer,
1075 (uint32_t)width, (uint32_t)height);
1076 if (layout_layer == NULL) {
1077 weston_log("id_layer is already created\n");
1081 /* ivilayer will be created by layer_event_create */
1082 ivilayer = get_layer(&shell->list_layer, id_layer);
1083 if (ivilayer == NULL) {
1084 weston_log("couldn't get layer object\n");
1089 ctrllayer = calloc(1, sizeof *ctrllayer);
1091 weston_log("no memory to allocate client layer\n");
1095 ++ivilayer->controller_layer_count;
1097 ctrllayer->shell = shell;
1098 ctrllayer->client = client;
1100 ctrllayer->id_layer = id_layer;
1101 ctrllayer->resource = wl_resource_create(client,
1102 &ivi_controller_layer_interface, 1, id);
1103 if (ctrllayer->resource == NULL) {
1104 weston_log("couldn't get layer object\n");
1108 wl_list_init(&ctrllayer->link);
1109 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1111 wl_resource_set_implementation(ctrllayer->resource,
1112 &controller_layer_implementation,
1113 ivilayer, destroy_ivicontroller_layer);
1115 memset(&prop, 0, sizeof prop);
1117 ivi_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1118 send_layer_event(ctrllayer->resource, ivilayer,
1119 &prop, IVI_NOTIFICATION_ALL);
1123 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1125 struct ivishell *shell = userdata;
1126 struct ivicontroller_surface *ctrlsurf = NULL;
1127 uint32_t id_surface = 0;
1130 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1132 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1133 if (id_surface != ctrlsurf->id_surface) {
1136 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1142 controller_surface_create(struct wl_client *client,
1143 struct wl_resource *resource,
1144 uint32_t id_surface,
1147 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1148 struct ivishell *shell = ctrl->shell;
1149 struct ivicontroller_surface *ctrlsurf = NULL;
1150 struct ivi_layout_SurfaceProperties prop;
1151 struct ivisurface *ivisurf = NULL;
1153 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1155 weston_log("no memory to allocate controller surface\n");
1159 ctrlsurf->shell = shell;
1160 ctrlsurf->client = client;
1162 ctrlsurf->id_surface = id_surface;
1163 wl_list_init(&ctrlsurf->link);
1164 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1166 ctrlsurf->resource = wl_resource_create(client,
1167 &ivi_controller_surface_interface, 1, id);
1168 if (ctrlsurf->resource == NULL) {
1169 weston_log("couldn't surface object");
1173 ivisurf = get_surface(&shell->list_surface, id_surface);
1174 if (ivisurf == NULL) {
1178 ++ivisurf->controller_surface_count;
1180 wl_resource_set_implementation(ctrlsurf->resource,
1181 &controller_surface_implementation,
1182 ivisurf, destroy_ivicontroller_surface);
1184 memset(&prop, 0, sizeof prop);
1186 ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1187 ivi_layout_surfaceSetContentObserver(ivisurf->layout_surface, surface_event_content, shell);
1189 send_surface_event(ctrlsurf->resource, ivisurf,
1190 &prop, IVI_NOTIFICATION_ALL);
1193 static const struct ivi_controller_interface controller_implementation = {
1194 controller_commit_changes,
1195 controller_layer_create,
1196 controller_surface_create
1200 add_client_to_resources(struct ivishell *shell,
1201 struct wl_client *client,
1202 struct ivicontroller *controller)
1204 struct ivisurface* ivisurf = NULL;
1205 struct ivilayer* ivilayer = NULL;
1206 struct iviscreen* iviscrn = NULL;
1207 struct ivicontroller_screen *ctrlscrn = NULL;
1208 struct wl_resource *resource_output = NULL;
1209 uint32_t id_layout_surface = 0;
1210 uint32_t id_layout_layer = 0;
1212 wl_list_for_each(ivisurf, &shell->list_surface, link) {
1214 ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1216 ivi_controller_send_surface(controller->resource,
1220 wl_list_for_each(ivilayer, &shell->list_layer, link) {
1222 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1224 ivi_controller_send_layer(controller->resource,
1228 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1229 resource_output = wl_resource_find_for_client(
1230 &iviscrn->output->resource_list, client);
1231 if (resource_output == NULL) {
1235 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1236 if (ctrlscrn == NULL) {
1240 ivi_controller_send_screen(controller->resource,
1241 wl_resource_get_id(resource_output),
1242 ctrlscrn->resource);
1247 bind_ivi_controller(struct wl_client *client, void *data,
1248 uint32_t version, uint32_t id)
1250 struct ivishell *shell = data;
1251 struct ivicontroller *controller;
1254 controller = calloc(1, sizeof *controller);
1255 if (controller == NULL) {
1256 weston_log("no memory to allocate controller\n");
1260 controller->resource =
1261 wl_resource_create(client, &ivi_controller_interface, 1, id);
1262 wl_resource_set_implementation(controller->resource,
1263 &controller_implementation,
1264 controller, unbind_resource_controller);
1266 controller->shell = shell;
1267 controller->client = client;
1268 controller->id = id;
1270 wl_list_init(&controller->link);
1271 wl_list_insert(&shell->list_controller, &controller->link);
1273 add_client_to_resources(shell, client, controller);
1276 static struct iviscreen*
1277 create_screen(struct ivishell *shell, struct weston_output *output)
1279 struct iviscreen *iviscrn;
1280 iviscrn = calloc(1, sizeof *iviscrn);
1281 if (iviscrn == NULL) {
1282 weston_log("no memory to allocate client screen\n");
1286 iviscrn->shell = shell;
1287 iviscrn->output = output;
1289 // TODO : Only Single display
1290 iviscrn->layout_screen = ivi_layout_getScreenFromId(0);
1292 wl_list_init(&iviscrn->link);
1297 static struct ivilayer*
1298 create_layer(struct ivishell *shell,
1299 struct ivi_layout_layer *layout_layer,
1302 struct ivilayer *ivilayer = NULL;
1303 struct ivicontroller *controller = NULL;
1305 ivilayer = get_layer(&shell->list_layer, id_layer);
1306 if (ivilayer != NULL) {
1307 weston_log("id_layer is already created\n");
1311 ivilayer = calloc(1, sizeof *ivilayer);
1312 if (NULL == ivilayer) {
1313 weston_log("no memory to allocate client layer\n");
1317 ivilayer->shell = shell;
1318 wl_list_init(&ivilayer->list_screen);
1319 wl_list_init(&ivilayer->link);
1320 wl_list_insert(&shell->list_layer, &ivilayer->link);
1321 ivilayer->layout_layer = layout_layer;
1323 ivi_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1325 wl_list_for_each(controller, &shell->list_controller, link) {
1326 ivi_controller_send_layer(controller->resource, id_layer);
1332 static struct ivisurface*
1333 create_surface(struct ivishell *shell,
1334 struct ivi_layout_surface *layout_surface,
1335 uint32_t id_surface)
1337 struct ivisurface *ivisurf = NULL;
1338 struct ivicontroller *controller = NULL;
1340 ivisurf = get_surface(&shell->list_surface, id_surface);
1341 if (ivisurf != NULL) {
1342 weston_log("id_surface is already created\n");
1346 ivisurf = calloc(1, sizeof *ivisurf);
1347 if (ivisurf == NULL) {
1348 weston_log("no memory to allocate client surface\n");
1352 ivisurf->shell = shell;
1353 ivisurf->layout_surface = layout_surface;
1354 wl_list_init(&ivisurf->list_layer);
1355 wl_list_init(&ivisurf->link);
1356 wl_list_insert(&shell->list_surface, &ivisurf->link);
1358 wl_list_for_each(controller, &shell->list_controller, link) {
1359 ivi_controller_send_surface(controller->resource,
1363 ivi_layout_surfaceAddNotification(layout_surface,
1364 send_surface_prop, ivisurf);
1370 layer_event_create(struct ivi_layout_layer *layout_layer,
1373 struct ivishell *shell = userdata;
1374 struct ivilayer *ivilayer = NULL;
1375 uint32_t id_layer = 0;
1377 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1379 ivilayer = create_layer(shell, layout_layer, id_layer);
1380 if (ivilayer == NULL) {
1381 weston_log("failed to create layer");
1387 layer_event_remove(struct ivi_layout_layer *layout_layer,
1390 struct ivishell *shell = userdata;
1391 struct ivicontroller_layer *ctrllayer = NULL;
1392 struct ivilayer *ivilayer = NULL;
1393 struct ivilayer *next = NULL;
1394 uint32_t id_layer = 0;
1397 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1398 if (layout_layer != ivilayer->layout_layer) {
1402 wl_list_remove(&ivilayer->link);
1411 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1413 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1414 if (id_layer != ctrllayer->id_layer) {
1417 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1424 surface_event_create(struct ivi_layout_surface *layout_surface,
1427 struct ivishell *shell = userdata;
1428 struct ivisurface *ivisurf = NULL;
1429 uint32_t id_surface = 0;
1431 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1433 ivisurf = create_surface(shell, layout_surface, id_surface);
1434 if (ivisurf == NULL) {
1435 weston_log("failed to create surface");
1441 surface_event_remove(struct ivi_layout_surface *layout_surface,
1444 struct ivishell *shell = userdata;
1445 struct ivicontroller_surface *ctrlsurf = NULL;
1446 struct ivisurface *ivisurf = NULL;
1447 struct ivisurface *next = NULL;
1448 uint32_t id_surface = 0;
1451 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1452 if (layout_surface != ivisurf->layout_surface) {
1456 wl_list_remove(&ivisurf->link);
1459 if (ivisurf->controller_surface_count == 0) {
1463 ivisurf->can_be_removed = 1;
1470 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1472 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1473 if (id_surface != ctrlsurf->id_surface) {
1476 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1482 surface_event_configure(struct ivi_layout_surface *layout_surface,
1485 struct ivishell *shell = userdata;
1486 struct ivisurface *ivisurf = NULL;
1487 struct ivicontroller_surface *ctrlsurf = NULL;
1488 struct ivi_layout_SurfaceProperties prop;
1489 uint32_t id_surface = 0;
1491 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1493 ivisurf = get_surface(&shell->list_surface, id_surface);
1494 if (ivisurf == NULL) {
1495 weston_log("id_surface is not created yet\n");
1499 memset(&prop, 0, sizeof prop);
1500 ivi_layout_getPropertiesOfSurface(layout_surface, &prop);
1502 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1503 if (id_surface != ctrlsurf->id_surface) {
1506 send_surface_event(ctrlsurf->resource, ivisurf,
1507 &prop, IVI_NOTIFICATION_ALL);
1512 check_layout_layers(struct ivishell *shell)
1514 struct ivi_layout_layer **pArray = NULL;
1515 struct ivilayer *ivilayer = NULL;
1516 uint32_t id_layer = 0;
1517 uint32_t length = 0;
1521 ret = ivi_layout_getLayers(&length, &pArray);
1523 weston_log("failed to get layers at check_layout_layers\n");
1528 /* if length is 0, pArray doesn't need to free.*/
1532 for (i = 0; i < length; i++) {
1533 id_layer = ivi_layout_getIdOfLayer(pArray[i]);
1534 ivilayer = create_layer(shell, pArray[i], id_layer);
1535 if (ivilayer == NULL) {
1536 weston_log("failed to create layer");
1547 check_layout_surfaces(struct ivishell *shell)
1549 struct ivi_layout_surface **pArray = NULL;
1550 struct ivisurface *ivisurf = NULL;
1551 uint32_t id_surface = 0;
1552 uint32_t length = 0;
1556 ret = ivi_layout_getSurfaces(&length, &pArray);
1558 weston_log("failed to get surfaces at check_layout_surfaces\n");
1563 /* if length is 0, pArray doesn't need to free.*/
1567 for (i = 0; i < length; i++) {
1568 id_surface = ivi_layout_getIdOfSurface(pArray[i]);
1569 ivisurf = create_surface(shell, pArray[i], id_surface);
1570 if (ivisurf == NULL) {
1571 weston_log("failed to create surface");
1582 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1584 struct weston_output *output = NULL;
1585 struct iviscreen *iviscrn = NULL;
1588 shell->compositor = ec;
1590 wl_list_init(&shell->list_surface);
1591 wl_list_init(&shell->list_layer);
1592 wl_list_init(&shell->list_screen);
1593 wl_list_init(&shell->list_weston_surface);
1594 wl_list_init(&shell->list_controller);
1595 wl_list_init(&shell->list_controller_screen);
1596 wl_list_init(&shell->list_controller_layer);
1597 wl_list_init(&shell->list_controller_surface);
1598 shell->event_restriction = 0;
1600 wl_list_for_each(output, &ec->output_list, link) {
1601 iviscrn = create_screen(shell, output);
1602 if (iviscrn != NULL) {
1603 wl_list_insert(&shell->list_screen, &iviscrn->link);
1607 ret = check_layout_layers(shell);
1609 weston_log("failed to check_layout_layers");
1612 ret = check_layout_surfaces(shell);
1614 weston_log("failed to check_layout_surfaces");
1617 ivi_layout_addNotificationCreateLayer(layer_event_create, shell);
1618 ivi_layout_addNotificationRemoveLayer(layer_event_remove, shell);
1620 ivi_layout_addNotificationCreateSurface(surface_event_create, shell);
1621 ivi_layout_addNotificationRemoveSurface(surface_event_remove, shell);
1622 ivi_layout_addNotificationConfigureSurface(surface_event_configure, shell);
1626 module_init(struct weston_compositor *ec,
1627 int *argc, char *argv[])
1629 struct ivishell *shell;
1633 shell = malloc(sizeof *shell);
1637 memset(shell, 0, sizeof *shell);
1638 init_ivi_shell(ec, shell);
1640 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
1641 shell, bind_ivi_controller) == NULL) {