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)
350 struct ivi_layout_layer **pArray = NULL;
354 struct link_layer *link_layer = NULL;
355 struct link_layer *next = NULL;
356 struct ivicontroller_layer *ctrllayer = NULL;
357 struct ivilayer *ivilayer = NULL;
358 struct ivishell *shell = ivisurf->shell;
359 uint32_t id_layout_layer = 0;
362 ans = ivi_layout_getLayersUnderSurface(ivisurf->layout_surface,
365 weston_log("failed to get layers at send_surface_add_event\n");
369 /* Send Null to cancel added surface */
370 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
371 for (i = 0, found = 0; i < (int)length; i++) {
372 if (pArray[i] == link_layer->layer->layout_layer) {
373 /* No need to send event, if new layer doesn't be added. */
382 ivi_controller_surface_send_layer(resource, NULL);
383 wl_list_remove(&link_layer->link);
388 for (i = 0; i < (int)length; i++) {
390 wl_list_for_each(link_layer, &ivisurf->list_layer, link) {
391 if (pArray[i] == link_layer->layer->layout_layer) {
392 /* No need to send event, if new layer doesn't be added. */
401 /* Create list_layer */
402 link_layer = calloc(1, sizeof(*link_layer));
403 if (NULL == link_layer) {
406 wl_list_init(&link_layer->link);
407 link_layer->layer = NULL;
408 wl_list_for_each(ivilayer, &shell->list_layer, link) {
409 if (ivilayer->layout_layer == pArray[i]) {
410 link_layer->layer = ivilayer;
415 if (link_layer->layer == NULL) {
420 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
422 /* Send new surface event */
424 ivi_layout_getIdOfLayer(link_layer->layer->layout_layer);
425 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
426 if (id_layout_layer != ctrllayer->id_layer) {
429 if (resource != ctrllayer->resource) {
432 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
441 send_surface_event(struct wl_resource *resource,
442 struct ivisurface *ivisurf,
443 struct ivi_layout_SurfaceProperties *prop,
446 if (mask & IVI_NOTIFICATION_OPACITY) {
447 ivi_controller_surface_send_opacity(resource,
450 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
451 ivi_controller_surface_send_source_rectangle(resource,
452 prop->sourceX, prop->sourceY,
453 prop->sourceWidth, prop->sourceHeight);
455 if (mask & IVI_NOTIFICATION_DEST_RECT) {
456 ivi_controller_surface_send_destination_rectangle(resource,
457 prop->destX, prop->destY,
458 prop->destWidth, prop->destHeight);
460 if (mask & IVI_NOTIFICATION_ORIENTATION) {
461 ivi_controller_surface_send_orientation(resource,
464 if (mask & IVI_NOTIFICATION_VISIBILITY) {
465 ivi_controller_surface_send_visibility(resource,
468 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
469 ivi_controller_surface_send_pixelformat(resource,
472 if (mask & IVI_NOTIFICATION_ADD) {
473 send_surface_add_event(ivisurf, resource);
478 send_surface_prop(struct ivi_layout_surface *layout_surface,
479 struct ivi_layout_SurfaceProperties *prop,
480 enum ivi_layout_notification_mask mask,
483 struct ivisurface *ivisurf = userdata;
484 struct ivishell *shell = ivisurf->shell;
485 struct ivicontroller_surface *ctrlsurf = NULL;
486 uint32_t id_surface = 0;
488 id_surface = ivi_layout_getIdOfSurface(layout_surface);
490 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
491 if (id_surface != ctrlsurf->id_surface) {
494 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
499 send_layer_add_event(struct ivilayer *ivilayer,
500 struct wl_resource *resource,
501 enum ivi_layout_notification_mask mask)
503 struct ivi_layout_screen **pArray = NULL;
507 struct link_screen *link_scrn = NULL;
508 struct link_screen *next = NULL;
509 struct iviscreen *iviscrn = NULL;
510 struct ivishell *shell = ivilayer->shell;
511 struct wl_client *client = wl_resource_get_client(resource);
512 struct wl_resource *resource_output = NULL;
514 ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
517 weston_log("failed to get screens at send_layer_add_event\n");
521 /* Send Null to cancel added layer */
522 if (mask & IVI_NOTIFICATION_REMOVE) {
523 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
524 ivi_controller_layer_send_screen(resource, NULL);
525 wl_list_remove(&link_scrn->link);
530 else if (mask & IVI_NOTIFICATION_ADD) {
531 for (i = 0; i < (int)length; i++) {
532 /* Create list_screen */
533 link_scrn = calloc(1, sizeof(*link_scrn));
534 if (NULL == link_scrn) {
537 wl_list_init(&link_scrn->link);
538 link_scrn->screen = NULL;
539 wl_list_for_each(iviscrn, &shell->list_screen, link) {
540 if (iviscrn->layout_screen == pArray[i]) {
541 link_scrn->screen = iviscrn;
546 if (link_scrn->screen == NULL) {
551 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
553 /* Send new layer event */
555 wl_resource_find_for_client(&iviscrn->output->resource_list,
557 if (resource_output != NULL) {
558 ivi_controller_layer_send_screen(resource, resource_output);
568 send_layer_event(struct wl_resource *resource,
569 struct ivilayer *ivilayer,
570 struct ivi_layout_LayerProperties *prop,
573 if (mask & IVI_NOTIFICATION_OPACITY) {
574 ivi_controller_layer_send_opacity(resource,
577 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
578 ivi_controller_layer_send_source_rectangle(resource,
584 if (mask & IVI_NOTIFICATION_DEST_RECT) {
585 ivi_controller_layer_send_destination_rectangle(resource,
591 if (mask & IVI_NOTIFICATION_ORIENTATION) {
592 ivi_controller_layer_send_orientation(resource,
595 if (mask & IVI_NOTIFICATION_VISIBILITY) {
596 ivi_controller_layer_send_visibility(resource,
599 if (mask & IVI_NOTIFICATION_ADD) {
600 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_ADD);
602 if (mask & IVI_NOTIFICATION_REMOVE) {
603 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_REMOVE);
608 send_layer_prop(struct ivi_layout_layer *layer,
609 struct ivi_layout_LayerProperties *prop,
610 enum ivi_layout_notification_mask mask,
613 struct ivilayer *ivilayer = userdata;
614 struct ivicontroller_layer *ctrllayer = NULL;
615 struct ivishell *shell = ivilayer->shell;
616 uint32_t id_layout_layer = 0;
618 id_layout_layer = ivi_layout_getIdOfLayer(layer);
619 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
620 if (id_layout_layer != ctrllayer->id_layer) {
623 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
628 controller_surface_set_opacity(struct wl_client *client,
629 struct wl_resource *resource,
632 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
634 ivi_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
638 controller_surface_set_source_rectangle(struct wl_client *client,
639 struct wl_resource *resource,
645 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
647 ivi_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
648 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
652 controller_surface_set_destination_rectangle(struct wl_client *client,
653 struct wl_resource *resource,
659 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
661 ivi_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
662 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
666 controller_surface_set_visibility(struct wl_client *client,
667 struct wl_resource *resource,
670 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
672 ivi_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
676 controller_surface_set_configuration(struct wl_client *client,
677 struct wl_resource *resource,
678 int32_t width, int32_t height)
680 /* This interface has been supported yet. */
688 controller_surface_set_orientation(struct wl_client *client,
689 struct wl_resource *resource,
692 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
694 ivi_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
698 controller_surface_screenshot(struct wl_client *client,
699 struct wl_resource *resource,
700 const char *filename)
702 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
704 ivi_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
708 controller_surface_send_stats(struct wl_client *client,
709 struct wl_resource *resource)
711 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
715 wl_client_get_credentials(client, &pid, &uid, &gid);
717 ivi_controller_surface_send_stats(resource, 0, 0,
718 ivisurf->update_count, pid, "");
722 controller_surface_destroy(struct wl_client *client,
723 struct wl_resource *resource,
724 int32_t destroy_scene_object)
727 (void)destroy_scene_object;
728 wl_resource_destroy(resource);
732 controller_surface_set_input_focus(struct wl_client *client,
733 struct wl_resource *resource,
742 struct ivi_controller_surface_interface controller_surface_implementation = {
743 controller_surface_set_visibility,
744 controller_surface_set_opacity,
745 controller_surface_set_source_rectangle,
746 controller_surface_set_destination_rectangle,
747 controller_surface_set_configuration,
748 controller_surface_set_orientation,
749 controller_surface_screenshot,
750 controller_surface_send_stats,
751 controller_surface_destroy,
752 controller_surface_set_input_focus
756 controller_layer_set_source_rectangle(struct wl_client *client,
757 struct wl_resource *resource,
763 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
765 ivi_layout_layerSetSourceRectangle(ivilayer->layout_layer,
766 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
770 controller_layer_set_destination_rectangle(struct wl_client *client,
771 struct wl_resource *resource,
777 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
779 ivi_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
780 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
784 controller_layer_set_visibility(struct wl_client *client,
785 struct wl_resource *resource,
788 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
790 ivi_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
794 controller_layer_set_opacity(struct wl_client *client,
795 struct wl_resource *resource,
798 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
800 ivi_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
804 controller_layer_set_configuration(struct wl_client *client,
805 struct wl_resource *resource,
809 /* This interface has been supported yet. */
817 controller_layer_set_orientation(struct wl_client *client,
818 struct wl_resource *resource,
821 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
823 ivi_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
827 controller_layer_clear_surfaces(struct wl_client *client,
828 struct wl_resource *resource)
830 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
832 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
836 controller_layer_add_surface(struct wl_client *client,
837 struct wl_resource *resource,
838 struct wl_resource *surface)
840 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
841 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
843 ivi_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
847 controller_layer_remove_surface(struct wl_client *client,
848 struct wl_resource *resource,
849 struct wl_resource *surface)
851 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
852 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
854 ivi_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
858 controller_layer_screenshot(struct wl_client *client,
859 struct wl_resource *resource,
860 const char *filename)
868 controller_layer_set_render_order(struct wl_client *client,
869 struct wl_resource *resource,
870 struct wl_array *id_surfaces)
872 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
873 struct ivi_layout_surface **layoutsurf_array = NULL;
874 struct ivisurface *ivisurf = NULL;
875 uint32_t *id_surface = NULL;
876 uint32_t id_layout_surface = 0;
880 wl_array_for_each(id_surface, id_surfaces) {
881 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
882 id_layout_surface = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
883 if (*id_surface == id_layout_surface) {
884 layoutsurf_array[i] = ivisurf->layout_surface;
891 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer,
892 layoutsurf_array, id_surfaces->size);
893 free(layoutsurf_array);
897 controller_layer_destroy(struct wl_client *client,
898 struct wl_resource *resource,
899 int32_t destroy_scene_object)
901 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
902 struct ivishell *shell = ivilayer->shell;
903 struct ivicontroller_layer *ctrllayer = NULL;
904 struct ivicontroller_layer *next = NULL;
905 uint32_t id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
907 (void)destroy_scene_object;
909 ivilayer->layer_canbe_removed = 1;
910 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
911 if (ctrllayer->id_layer != id_layer) {
915 wl_resource_destroy(ctrllayer->resource);
920 struct ivi_controller_layer_interface controller_layer_implementation = {
921 controller_layer_set_visibility,
922 controller_layer_set_opacity,
923 controller_layer_set_source_rectangle,
924 controller_layer_set_destination_rectangle,
925 controller_layer_set_configuration,
926 controller_layer_set_orientation,
927 controller_layer_screenshot,
928 controller_layer_clear_surfaces,
929 controller_layer_add_surface,
930 controller_layer_remove_surface,
931 controller_layer_set_render_order,
932 controller_layer_destroy
936 controller_screen_destroy(struct wl_client *client,
937 struct wl_resource *resource)
939 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
940 struct ivicontroller_screen *ctrlscrn = NULL;
941 struct ivicontroller_screen *next = NULL;
942 // uint32_t id_screen = ivi_layout_getIdOfScreen(iviscrn->layout_screen);
945 wl_list_for_each_safe(ctrlscrn, next,
946 &iviscrn->shell->list_controller_screen, link) {
947 if (resource != ctrlscrn->resource) {
951 wl_list_remove(&ctrlscrn->link);
954 wl_resource_destroy(ctrlscrn->resource);
960 controller_screen_clear(struct wl_client *client,
961 struct wl_resource *resource)
963 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
965 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
969 controller_screen_add_layer(struct wl_client *client,
970 struct wl_resource *resource,
971 struct wl_resource *layer)
973 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
974 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
976 ivi_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
980 controller_screen_screenshot(struct wl_client *client,
981 struct wl_resource *resource,
982 const char *filename)
984 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
986 ivi_layout_takeScreenshot(iviscrn->layout_screen, filename);
990 controller_screen_set_render_order(struct wl_client *client,
991 struct wl_resource *resource,
992 struct wl_array *id_layers)
994 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
995 struct ivi_layout_layer **layoutlayer_array = NULL;
996 struct ivilayer *ivilayer = NULL;
997 uint32_t *id_layer = NULL;
998 uint32_t id_layout_layer = 0;
1002 *layoutlayer_array = (struct ivi_layout_layer*)calloc(
1003 id_layers->size, sizeof(void*));
1005 wl_array_for_each(id_layer, id_layers) {
1006 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1007 id_layout_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1008 if (*id_layer == id_layout_layer) {
1009 layoutlayer_array[i] = ivilayer->layout_layer;
1016 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen,
1017 layoutlayer_array, id_layers->size);
1018 free(layoutlayer_array);
1022 struct ivi_controller_screen_interface controller_screen_implementation = {
1023 controller_screen_destroy,
1024 controller_screen_clear,
1025 controller_screen_add_layer,
1026 controller_screen_screenshot,
1027 controller_screen_set_render_order
1031 controller_commit_changes(struct wl_client *client,
1032 struct wl_resource *resource)
1038 ans = ivi_layout_commitChanges();
1040 weston_log("Failed to commit changes at controller_commit_changes\n");
1045 controller_layer_create(struct wl_client *client,
1046 struct wl_resource *resource,
1052 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1053 struct ivishell *shell = ctrl->shell;
1054 struct ivi_layout_layer *layout_layer = NULL;
1055 struct ivicontroller_layer *ctrllayer = NULL;
1056 struct ivilayer *ivilayer = NULL;
1057 struct ivi_layout_LayerProperties prop;
1059 ivilayer = get_layer(&shell->list_layer, id_layer);
1060 if (ivilayer == NULL) {
1061 layout_layer = ivi_layout_layerCreateWithDimension(id_layer,
1062 (uint32_t)width, (uint32_t)height);
1063 if (layout_layer == NULL) {
1064 weston_log("id_layer is already created\n");
1068 /* ivilayer will be created by layer_event_create */
1069 ivilayer = get_layer(&shell->list_layer, id_layer);
1070 if (ivilayer == NULL) {
1071 weston_log("couldn't get layer object\n");
1076 ctrllayer = calloc(1, sizeof *ctrllayer);
1078 weston_log("no memory to allocate client layer\n");
1082 ++ivilayer->controller_layer_count;
1083 ivilayer->layer_canbe_removed = 0;
1085 ctrllayer->shell = shell;
1086 ctrllayer->client = client;
1088 ctrllayer->id_layer = id_layer;
1089 ctrllayer->resource = wl_resource_create(client,
1090 &ivi_controller_layer_interface, 1, id);
1091 if (ctrllayer->resource == NULL) {
1092 weston_log("couldn't get layer object\n");
1096 wl_list_init(&ctrllayer->link);
1097 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1099 wl_resource_set_implementation(ctrllayer->resource,
1100 &controller_layer_implementation,
1101 ivilayer, destroy_ivicontroller_layer);
1103 memset(&prop, 0, sizeof prop);
1105 ivi_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1106 send_layer_event(ctrllayer->resource, ivilayer,
1107 &prop, IVI_NOTIFICATION_ALL);
1111 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1113 struct ivishell *shell = userdata;
1114 struct ivicontroller_surface *ctrlsurf = NULL;
1115 uint32_t id_surface = 0;
1118 surface_event_remove(layout_surface, userdata);
1123 controller_surface_create(struct wl_client *client,
1124 struct wl_resource *resource,
1125 uint32_t id_surface,
1128 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1129 struct ivishell *shell = ctrl->shell;
1130 struct ivicontroller_surface *ctrlsurf = NULL;
1131 struct ivi_layout_SurfaceProperties prop;
1132 struct ivisurface *ivisurf = NULL;
1134 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1136 weston_log("no memory to allocate controller surface\n");
1140 ctrlsurf->shell = shell;
1141 ctrlsurf->client = client;
1143 ctrlsurf->id_surface = id_surface;
1144 wl_list_init(&ctrlsurf->link);
1145 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1147 ctrlsurf->resource = wl_resource_create(client,
1148 &ivi_controller_surface_interface, 1, id);
1149 if (ctrlsurf->resource == NULL) {
1150 weston_log("couldn't surface object");
1154 ivisurf = get_surface(&shell->list_surface, id_surface);
1155 if (ivisurf == NULL) {
1159 ++ivisurf->controller_surface_count;
1161 wl_resource_set_implementation(ctrlsurf->resource,
1162 &controller_surface_implementation,
1163 ivisurf, destroy_ivicontroller_surface);
1165 memset(&prop, 0, sizeof prop);
1167 ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1168 ivi_layout_surfaceSetContentObserver(ivisurf->layout_surface, surface_event_content, shell);
1170 send_surface_event(ctrlsurf->resource, ivisurf,
1171 &prop, IVI_NOTIFICATION_ALL);
1174 static const struct ivi_controller_interface controller_implementation = {
1175 controller_commit_changes,
1176 controller_layer_create,
1177 controller_surface_create
1181 add_client_to_resources(struct ivishell *shell,
1182 struct wl_client *client,
1183 struct ivicontroller *controller)
1185 struct ivisurface* ivisurf = NULL;
1186 struct ivilayer* ivilayer = NULL;
1187 struct iviscreen* iviscrn = NULL;
1188 struct ivicontroller_screen *ctrlscrn = NULL;
1189 struct wl_resource *resource_output = NULL;
1190 uint32_t id_layout_surface = 0;
1191 uint32_t id_layout_layer = 0;
1193 wl_list_for_each(ivisurf, &shell->list_surface, link) {
1195 ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1197 ivi_controller_send_surface(controller->resource,
1201 wl_list_for_each(ivilayer, &shell->list_layer, link) {
1203 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1205 ivi_controller_send_layer(controller->resource,
1209 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1210 resource_output = wl_resource_find_for_client(
1211 &iviscrn->output->resource_list, client);
1212 if (resource_output == NULL) {
1216 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1217 if (ctrlscrn == NULL) {
1221 ivi_controller_send_screen(controller->resource,
1222 wl_resource_get_id(resource_output),
1223 ctrlscrn->resource);
1228 bind_ivi_controller(struct wl_client *client, void *data,
1229 uint32_t version, uint32_t id)
1231 struct ivishell *shell = data;
1232 struct ivicontroller *controller;
1235 controller = calloc(1, sizeof *controller);
1236 if (controller == NULL) {
1237 weston_log("no memory to allocate controller\n");
1241 controller->resource =
1242 wl_resource_create(client, &ivi_controller_interface, 1, id);
1243 wl_resource_set_implementation(controller->resource,
1244 &controller_implementation,
1245 controller, unbind_resource_controller);
1247 controller->shell = shell;
1248 controller->client = client;
1249 controller->id = id;
1251 wl_list_init(&controller->link);
1252 wl_list_insert(&shell->list_controller, &controller->link);
1254 add_client_to_resources(shell, client, controller);
1257 static struct iviscreen*
1258 create_screen(struct ivishell *shell, struct weston_output *output)
1260 struct iviscreen *iviscrn;
1261 iviscrn = calloc(1, sizeof *iviscrn);
1262 if (iviscrn == NULL) {
1263 weston_log("no memory to allocate client screen\n");
1267 iviscrn->shell = shell;
1268 iviscrn->output = output;
1270 // TODO : Only Single display
1271 iviscrn->layout_screen = ivi_layout_getScreenFromId(0);
1273 wl_list_init(&iviscrn->link);
1278 static struct ivilayer*
1279 create_layer(struct ivishell *shell,
1280 struct ivi_layout_layer *layout_layer,
1283 struct ivilayer *ivilayer = NULL;
1284 struct ivicontroller *controller = NULL;
1286 ivilayer = get_layer(&shell->list_layer, id_layer);
1287 if (ivilayer != NULL) {
1288 weston_log("id_layer is already created\n");
1292 ivilayer = calloc(1, sizeof *ivilayer);
1293 if (NULL == ivilayer) {
1294 weston_log("no memory to allocate client layer\n");
1298 ivilayer->shell = shell;
1299 wl_list_init(&ivilayer->list_screen);
1300 wl_list_init(&ivilayer->link);
1301 wl_list_insert(&shell->list_layer, &ivilayer->link);
1302 ivilayer->layout_layer = layout_layer;
1304 ivi_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1306 wl_list_for_each(controller, &shell->list_controller, link) {
1307 ivi_controller_send_layer(controller->resource, id_layer);
1313 static struct ivisurface*
1314 create_surface(struct ivishell *shell,
1315 struct ivi_layout_surface *layout_surface,
1316 uint32_t id_surface)
1318 struct ivisurface *ivisurf = NULL;
1319 struct ivicontroller *controller = NULL;
1321 ivisurf = get_surface(&shell->list_surface, id_surface);
1322 if (ivisurf != NULL) {
1323 weston_log("id_surface is already created\n");
1327 ivisurf = calloc(1, sizeof *ivisurf);
1328 if (ivisurf == NULL) {
1329 weston_log("no memory to allocate client surface\n");
1333 ivisurf->shell = shell;
1334 ivisurf->layout_surface = layout_surface;
1335 wl_list_init(&ivisurf->list_layer);
1336 wl_list_init(&ivisurf->link);
1337 wl_list_insert(&shell->list_surface, &ivisurf->link);
1339 wl_list_for_each(controller, &shell->list_controller, link) {
1340 ivi_controller_send_surface(controller->resource,
1344 ivi_layout_surfaceAddNotification(layout_surface,
1345 send_surface_prop, ivisurf);
1351 layer_event_create(struct ivi_layout_layer *layout_layer,
1354 struct ivishell *shell = userdata;
1355 struct ivilayer *ivilayer = NULL;
1356 uint32_t id_layer = 0;
1358 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1360 ivilayer = create_layer(shell, layout_layer, id_layer);
1361 if (ivilayer == NULL) {
1362 weston_log("failed to create layer");
1368 layer_event_remove(struct ivi_layout_layer *layout_layer,
1371 struct ivishell *shell = userdata;
1372 struct ivicontroller_layer *ctrllayer = NULL;
1373 struct ivilayer *ivilayer = NULL;
1374 struct ivilayer *next = NULL;
1375 uint32_t id_layer = 0;
1378 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1379 if (layout_layer != ivilayer->layout_layer) {
1383 wl_list_remove(&ivilayer->link);
1392 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1394 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1395 if (id_layer != ctrllayer->id_layer) {
1398 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1405 surface_event_create(struct ivi_layout_surface *layout_surface,
1408 struct ivishell *shell = userdata;
1409 struct ivisurface *ivisurf = NULL;
1410 uint32_t id_surface = 0;
1412 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1414 ivisurf = create_surface(shell, layout_surface, id_surface);
1415 if (ivisurf == NULL) {
1416 weston_log("failed to create surface");
1422 surface_event_remove(struct ivi_layout_surface *layout_surface,
1425 struct ivishell *shell = userdata;
1426 struct ivicontroller_surface *ctrlsurf = NULL;
1427 struct ivisurface *ivisurf = NULL;
1428 struct ivisurface *next = NULL;
1429 uint32_t id_surface = 0;
1432 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1433 if (layout_surface != ivisurf->layout_surface) {
1437 wl_list_remove(&ivisurf->link);
1440 if (ivisurf->controller_surface_count == 0) {
1444 ivisurf->can_be_removed = 1;
1451 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1453 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1454 if (id_surface != ctrlsurf->id_surface) {
1457 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1463 surface_event_configure(struct ivi_layout_surface *layout_surface,
1466 struct ivishell *shell = userdata;
1467 struct ivisurface *ivisurf = NULL;
1468 struct ivicontroller_surface *ctrlsurf = NULL;
1469 struct ivi_layout_SurfaceProperties prop;
1470 uint32_t id_surface = 0;
1472 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1474 ivisurf = get_surface(&shell->list_surface, id_surface);
1475 if (ivisurf == NULL) {
1476 weston_log("id_surface is not created yet\n");
1480 memset(&prop, 0, sizeof prop);
1481 ivi_layout_getPropertiesOfSurface(layout_surface, &prop);
1483 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1484 if (id_surface != ctrlsurf->id_surface) {
1487 send_surface_event(ctrlsurf->resource, ivisurf,
1488 &prop, IVI_NOTIFICATION_ALL);
1493 check_layout_layers(struct ivishell *shell)
1495 struct ivi_layout_layer **pArray = NULL;
1496 struct ivilayer *ivilayer = NULL;
1497 uint32_t id_layer = 0;
1498 uint32_t length = 0;
1502 ret = ivi_layout_getLayers(&length, &pArray);
1504 weston_log("failed to get layers at check_layout_layers\n");
1509 /* if length is 0, pArray doesn't need to free.*/
1513 for (i = 0; i < length; i++) {
1514 id_layer = ivi_layout_getIdOfLayer(pArray[i]);
1515 ivilayer = create_layer(shell, pArray[i], id_layer);
1516 if (ivilayer == NULL) {
1517 weston_log("failed to create layer");
1528 check_layout_surfaces(struct ivishell *shell)
1530 struct ivi_layout_surface **pArray = NULL;
1531 struct ivisurface *ivisurf = NULL;
1532 uint32_t id_surface = 0;
1533 uint32_t length = 0;
1537 ret = ivi_layout_getSurfaces(&length, &pArray);
1539 weston_log("failed to get surfaces at check_layout_surfaces\n");
1544 /* if length is 0, pArray doesn't need to free.*/
1548 for (i = 0; i < length; i++) {
1549 id_surface = ivi_layout_getIdOfSurface(pArray[i]);
1550 ivisurf = create_surface(shell, pArray[i], id_surface);
1551 if (ivisurf == NULL) {
1552 weston_log("failed to create surface");
1563 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1565 struct weston_output *output = NULL;
1566 struct iviscreen *iviscrn = NULL;
1569 shell->compositor = ec;
1571 wl_list_init(&shell->list_surface);
1572 wl_list_init(&shell->list_layer);
1573 wl_list_init(&shell->list_screen);
1574 wl_list_init(&shell->list_weston_surface);
1575 wl_list_init(&shell->list_controller);
1576 wl_list_init(&shell->list_controller_screen);
1577 wl_list_init(&shell->list_controller_layer);
1578 wl_list_init(&shell->list_controller_surface);
1579 shell->event_restriction = 0;
1581 wl_list_for_each(output, &ec->output_list, link) {
1582 iviscrn = create_screen(shell, output);
1583 if (iviscrn != NULL) {
1584 wl_list_insert(&shell->list_screen, &iviscrn->link);
1588 ret = check_layout_layers(shell);
1590 weston_log("failed to check_layout_layers");
1593 ret = check_layout_surfaces(shell);
1595 weston_log("failed to check_layout_surfaces");
1598 ivi_layout_addNotificationCreateLayer(layer_event_create, shell);
1599 ivi_layout_addNotificationRemoveLayer(layer_event_remove, shell);
1601 ivi_layout_addNotificationCreateSurface(surface_event_create, shell);
1602 ivi_layout_addNotificationRemoveSurface(surface_event_remove, shell);
1603 ivi_layout_addNotificationConfigureSurface(surface_event_configure, shell);
1607 module_init(struct weston_compositor *ec,
1608 int *argc, char *argv[])
1610 struct ivishell *shell;
1614 shell = malloc(sizeof *shell);
1618 memset(shell, 0, sizeof *shell);
1619 init_ivi_shell(ec, shell);
1621 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
1622 shell, bind_ivi_controller) == NULL) {