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;
156 static void surface_event_remove(struct ivi_layout_surface *, void *);
159 destroy_ivicontroller_surface(struct wl_resource *resource)
161 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
162 struct ivishell *shell = ivisurf->shell;
163 struct ivicontroller_surface *ctrlsurf = NULL;
164 struct ivicontroller_surface *next = NULL;
167 wl_list_for_each_safe(ctrlsurf, next,
168 &shell->list_controller_surface, link) {
170 if (resource != ctrlsurf->resource) {
174 if (!wl_list_empty(&ctrlsurf->link)) {
175 wl_list_remove(&ctrlsurf->link);
181 --ivisurf->controller_surface_count;
185 if ((is_removed) && (ivisurf->controller_surface_count == 0)) {
186 if (ivisurf->can_be_removed) {
190 ivisurf->can_be_removed = 1;
196 destroy_ivicontroller_layer(struct wl_resource *resource)
198 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
199 struct ivishell *shell = ivilayer->shell;
200 struct ivicontroller_layer *ctrllayer = NULL;
201 struct ivicontroller_layer *next = NULL;
202 uint32_t id_layer = 0;
204 id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
206 wl_list_for_each_safe(ctrllayer, next,
207 &shell->list_controller_layer, link) {
209 if (resource != ctrllayer->resource) {
213 wl_list_remove(&ctrllayer->link);
214 --ivilayer->controller_layer_count;
220 if ((ivilayer->layout_layer != NULL) &&
221 (ivilayer->controller_layer_count == 0)) {
222 ivi_layout_layerRemove(ivilayer->layout_layer);
227 destroy_ivicontroller_screen(struct wl_resource *resource)
229 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
230 struct ivicontroller_screen *ctrlscrn = NULL;
231 struct ivicontroller_screen *next = NULL;
233 wl_list_for_each_safe(ctrlscrn, next,
234 &iviscrn->shell->list_controller_screen, link) {
235 // TODO : Only Single display
237 if (iviscrn->output->id != ctrlscrn->id_screen) {
242 if (resource != ctrlscrn->resource) {
246 wl_list_remove(&ctrlscrn->link);
254 unbind_resource_controller(struct wl_resource *resource)
256 struct ivicontroller *controller = wl_resource_get_user_data(resource);
258 wl_list_remove(&controller->link);
264 static struct ivisurface*
265 get_surface(struct wl_list *list_surf, uint32_t id_surface)
267 struct ivisurface *ivisurf = NULL;
268 uint32_t ivisurf_id = 0;
270 wl_list_for_each(ivisurf, list_surf, link) {
271 ivisurf_id = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
272 if (ivisurf_id == id_surface) {
280 static struct ivilayer*
281 get_layer(struct wl_list *list_layer, uint32_t id_layer)
283 struct ivilayer *ivilayer = NULL;
284 uint32_t ivilayer_id = 0;
286 wl_list_for_each(ivilayer, list_layer, link) {
287 ivilayer_id = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
288 if (ivilayer_id == id_layer) {
297 struct ivi_controller_screen_interface controller_screen_implementation;
299 static struct ivicontroller_screen*
300 controller_screen_create(struct ivishell *shell,
301 struct wl_client *client,
302 struct iviscreen *iviscrn)
304 struct ivicontroller_screen *ctrlscrn = NULL;
306 ctrlscrn = calloc(1, sizeof *ctrlscrn);
307 if (ctrlscrn == NULL) {
308 weston_log("no memory to allocate controller screen\n");
312 ctrlscrn->client = client;
313 ctrlscrn->shell = shell;
315 // TODO : Only Single display
317 /* ctrlscrn->id_screen = iviscrn->id_screen; */
319 ctrlscrn->id_screen = 0;
323 wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
324 if (ctrlscrn->resource == NULL) {
325 weston_log("couldn't new screen controller object");
333 wl_resource_set_implementation(ctrlscrn->resource,
334 &controller_screen_implementation,
335 iviscrn, destroy_ivicontroller_screen);
337 wl_list_init(&ctrlscrn->link);
338 wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
344 send_surface_add_event(struct ivisurface *ivisurf,
345 struct wl_resource *resource)
347 struct ivi_layout_layer **pArray = NULL;
351 struct link_layer *link_layer = NULL;
352 struct link_layer *next = NULL;
353 struct ivicontroller_layer *ctrllayer = NULL;
354 struct ivilayer *ivilayer = NULL;
355 struct ivishell *shell = ivisurf->shell;
356 uint32_t id_layout_layer = 0;
359 ans = ivi_layout_getLayersUnderSurface(ivisurf->layout_surface,
362 weston_log("failed to get layers at send_surface_add_event\n");
366 /* Send Null to cancel added surface */
367 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
368 for (i = 0, found = 0; i < (int)length; i++) {
369 if (pArray[i] == link_layer->layer->layout_layer) {
370 /* No need to send event, if new layer doesn't be added. */
379 ivi_controller_surface_send_layer(resource, NULL);
380 wl_list_remove(&link_layer->link);
385 for (i = 0; i < (int)length; i++) {
387 wl_list_for_each(link_layer, &ivisurf->list_layer, link) {
388 if (pArray[i] == link_layer->layer->layout_layer) {
389 /* No need to send event, if new layer doesn't be added. */
398 /* Create list_layer */
399 link_layer = calloc(1, sizeof(*link_layer));
400 if (NULL == link_layer) {
403 wl_list_init(&link_layer->link);
404 link_layer->layer = NULL;
405 wl_list_for_each(ivilayer, &shell->list_layer, link) {
406 if (ivilayer->layout_layer == pArray[i]) {
407 link_layer->layer = ivilayer;
412 if (link_layer->layer == NULL) {
417 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
419 /* Send new surface event */
421 ivi_layout_getIdOfLayer(link_layer->layer->layout_layer);
422 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
423 if (id_layout_layer != ctrllayer->id_layer) {
426 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
435 send_surface_event(struct wl_resource *resource,
436 struct ivisurface *ivisurf,
437 struct ivi_layout_SurfaceProperties *prop,
440 if (mask & IVI_NOTIFICATION_OPACITY) {
441 ivi_controller_surface_send_opacity(resource,
444 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
445 ivi_controller_surface_send_source_rectangle(resource,
446 prop->sourceX, prop->sourceY,
447 prop->sourceWidth, prop->sourceHeight);
449 if (mask & IVI_NOTIFICATION_DEST_RECT) {
450 ivi_controller_surface_send_destination_rectangle(resource,
451 prop->destX, prop->destY,
452 prop->destWidth, prop->destHeight);
454 if (mask & IVI_NOTIFICATION_ORIENTATION) {
455 ivi_controller_surface_send_orientation(resource,
458 if (mask & IVI_NOTIFICATION_VISIBILITY) {
459 ivi_controller_surface_send_visibility(resource,
462 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
463 ivi_controller_surface_send_pixelformat(resource,
466 if (mask & IVI_NOTIFICATION_ADD) {
467 send_surface_add_event(ivisurf, resource);
472 send_surface_prop(struct ivi_layout_surface *layout_surface,
473 struct ivi_layout_SurfaceProperties *prop,
474 enum ivi_layout_notification_mask mask,
477 struct ivisurface *ivisurf = userdata;
478 struct ivishell *shell = ivisurf->shell;
479 struct ivicontroller_surface *ctrlsurf = NULL;
480 uint32_t id_surface = 0;
482 id_surface = ivi_layout_getIdOfSurface(layout_surface);
484 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
485 if (id_surface != ctrlsurf->id_surface) {
488 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
493 send_layer_add_event(struct ivilayer *ivilayer,
494 struct wl_resource *resource)
496 struct ivi_layout_screen **pArray = NULL;
500 struct link_screen *link_scrn = NULL;
501 struct link_screen *next = NULL;
502 struct iviscreen *iviscrn = NULL;
503 struct ivishell *shell = ivilayer->shell;
505 struct wl_client *client = wl_resource_get_client(resource);
506 struct wl_resource *resource_output = NULL;
508 ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
511 weston_log("failed to get screens at send_layer_add_event\n");
515 /* Send Null to cancel added layer */
516 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
517 for (i = 0, found = 0; i < (int)length; i++) {
518 if (pArray[i] == link_scrn->screen->layout_screen) {
519 /* No need to send event, if new layer doesn't be added. */
528 ivi_controller_layer_send_screen(resource, NULL);
529 wl_list_remove(&link_scrn->link);
534 for (i = 0; i < (int)length; i++) {
536 wl_list_for_each(link_scrn, &ivilayer->list_screen, link) {
537 if (pArray[i] == link_scrn->screen->layout_screen) {
538 /* No need to send event, if new screen doesn't be added. */
547 /* Create list_screen */
548 link_scrn = calloc(1, sizeof(*link_scrn));
549 if (NULL == link_scrn) {
552 wl_list_init(&link_scrn->link);
553 link_scrn->screen = NULL;
554 wl_list_for_each(iviscrn, &shell->list_screen, link) {
555 if (iviscrn->layout_screen == pArray[i]) {
556 link_scrn->screen = iviscrn;
561 if (link_scrn->screen == NULL) {
566 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
568 /* Send new layer event */
570 wl_resource_find_for_client(&iviscrn->output->resource_list,
572 if (resource_output != NULL) {
573 ivi_controller_layer_send_screen(resource, resource_output);
582 send_layer_event(struct wl_resource *resource,
583 struct ivilayer *ivilayer,
584 struct ivi_layout_LayerProperties *prop,
587 if (mask & IVI_NOTIFICATION_OPACITY) {
588 ivi_controller_layer_send_opacity(resource,
591 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
592 ivi_controller_layer_send_source_rectangle(resource,
598 if (mask & IVI_NOTIFICATION_DEST_RECT) {
599 ivi_controller_layer_send_destination_rectangle(resource,
605 if (mask & IVI_NOTIFICATION_ORIENTATION) {
606 ivi_controller_layer_send_orientation(resource,
609 if (mask & IVI_NOTIFICATION_VISIBILITY) {
610 ivi_controller_layer_send_visibility(resource,
613 if (mask & IVI_NOTIFICATION_ADD) {
614 send_layer_add_event(ivilayer, resource);
616 if (mask & IVI_NOTIFICATION_REMOVE) {
617 send_layer_add_event(ivilayer, resource);
622 send_layer_prop(struct ivi_layout_layer *layer,
623 struct ivi_layout_LayerProperties *prop,
624 enum ivi_layout_notification_mask mask,
627 struct ivilayer *ivilayer = userdata;
628 struct ivicontroller_layer *ctrllayer = NULL;
629 struct ivishell *shell = ivilayer->shell;
630 uint32_t id_layout_layer = 0;
632 id_layout_layer = ivi_layout_getIdOfLayer(layer);
633 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
634 if (id_layout_layer != ctrllayer->id_layer) {
637 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
642 controller_surface_set_opacity(struct wl_client *client,
643 struct wl_resource *resource,
646 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
648 ivi_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
652 controller_surface_set_source_rectangle(struct wl_client *client,
653 struct wl_resource *resource,
659 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
661 ivi_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
662 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
666 controller_surface_set_destination_rectangle(struct wl_client *client,
667 struct wl_resource *resource,
673 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
675 ivi_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
676 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
680 controller_surface_set_visibility(struct wl_client *client,
681 struct wl_resource *resource,
684 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
686 ivi_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
690 controller_surface_set_configuration(struct wl_client *client,
691 struct wl_resource *resource,
692 int32_t width, int32_t height)
694 /* This interface has been supported yet. */
702 controller_surface_set_orientation(struct wl_client *client,
703 struct wl_resource *resource,
706 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
708 ivi_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
712 controller_surface_screenshot(struct wl_client *client,
713 struct wl_resource *resource,
714 const char *filename)
716 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
718 ivi_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
722 controller_surface_send_stats(struct wl_client *client,
723 struct wl_resource *resource)
725 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
729 wl_client_get_credentials(client, &pid, &uid, &gid);
731 ivi_controller_surface_send_stats(resource, 0, 0,
732 ivisurf->update_count, pid, "");
736 controller_surface_destroy(struct wl_client *client,
737 struct wl_resource *resource,
738 int32_t destroy_scene_object)
741 (void)destroy_scene_object;
742 wl_resource_destroy(resource);
746 controller_surface_set_input_focus(struct wl_client *client,
747 struct wl_resource *resource,
756 struct ivi_controller_surface_interface controller_surface_implementation = {
757 controller_surface_set_visibility,
758 controller_surface_set_opacity,
759 controller_surface_set_source_rectangle,
760 controller_surface_set_destination_rectangle,
761 controller_surface_set_configuration,
762 controller_surface_set_orientation,
763 controller_surface_screenshot,
764 controller_surface_send_stats,
765 controller_surface_destroy,
766 controller_surface_set_input_focus
770 controller_layer_set_source_rectangle(struct wl_client *client,
771 struct wl_resource *resource,
777 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
779 ivi_layout_layerSetSourceRectangle(ivilayer->layout_layer,
780 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
784 controller_layer_set_destination_rectangle(struct wl_client *client,
785 struct wl_resource *resource,
791 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
793 ivi_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
794 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
798 controller_layer_set_visibility(struct wl_client *client,
799 struct wl_resource *resource,
802 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
804 ivi_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
808 controller_layer_set_opacity(struct wl_client *client,
809 struct wl_resource *resource,
812 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
814 ivi_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
818 controller_layer_set_configuration(struct wl_client *client,
819 struct wl_resource *resource,
823 /* This interface has been supported yet. */
831 controller_layer_set_orientation(struct wl_client *client,
832 struct wl_resource *resource,
835 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
837 ivi_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
841 controller_layer_clear_surfaces(struct wl_client *client,
842 struct wl_resource *resource)
844 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
846 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
850 controller_layer_add_surface(struct wl_client *client,
851 struct wl_resource *resource,
852 struct wl_resource *surface)
854 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
855 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
857 ivi_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
861 controller_layer_remove_surface(struct wl_client *client,
862 struct wl_resource *resource,
863 struct wl_resource *surface)
865 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
866 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
868 ivi_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
872 controller_layer_screenshot(struct wl_client *client,
873 struct wl_resource *resource,
874 const char *filename)
882 controller_layer_set_render_order(struct wl_client *client,
883 struct wl_resource *resource,
884 struct wl_array *id_surfaces)
886 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
887 struct ivi_layout_surface **layoutsurf_array = NULL;
888 struct ivisurface *ivisurf = NULL;
889 uint32_t *id_surface = NULL;
890 uint32_t id_layout_surface = 0;
894 wl_array_for_each(id_surface, id_surfaces) {
895 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
896 id_layout_surface = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
897 if (*id_surface == id_layout_surface) {
898 layoutsurf_array[i] = ivisurf->layout_surface;
905 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer,
906 layoutsurf_array, id_surfaces->size);
907 free(layoutsurf_array);
911 controller_layer_destroy(struct wl_client *client,
912 struct wl_resource *resource,
913 int32_t destroy_scene_object)
915 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
916 struct ivishell *shell = ivilayer->shell;
917 struct ivicontroller_layer *ctrllayer = NULL;
918 struct ivicontroller_layer *next = NULL;
919 uint32_t id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
921 (void)destroy_scene_object;
923 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
924 if (ctrllayer->resource != resource) {
928 wl_resource_destroy(resource);
934 struct ivi_controller_layer_interface controller_layer_implementation = {
935 controller_layer_set_visibility,
936 controller_layer_set_opacity,
937 controller_layer_set_source_rectangle,
938 controller_layer_set_destination_rectangle,
939 controller_layer_set_configuration,
940 controller_layer_set_orientation,
941 controller_layer_screenshot,
942 controller_layer_clear_surfaces,
943 controller_layer_add_surface,
944 controller_layer_remove_surface,
945 controller_layer_set_render_order,
946 controller_layer_destroy
950 controller_screen_destroy(struct wl_client *client,
951 struct wl_resource *resource)
953 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
954 struct ivicontroller_screen *ctrlscrn = NULL;
955 struct ivicontroller_screen *next = NULL;
956 // uint32_t id_screen = ivi_layout_getIdOfScreen(iviscrn->layout_screen);
959 wl_list_for_each_safe(ctrlscrn, next,
960 &iviscrn->shell->list_controller_screen, link) {
961 if (resource != ctrlscrn->resource) {
965 wl_list_remove(&ctrlscrn->link);
968 wl_resource_destroy(ctrlscrn->resource);
974 controller_screen_clear(struct wl_client *client,
975 struct wl_resource *resource)
977 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
979 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
983 controller_screen_add_layer(struct wl_client *client,
984 struct wl_resource *resource,
985 struct wl_resource *layer)
987 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
988 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
990 ivi_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
994 controller_screen_screenshot(struct wl_client *client,
995 struct wl_resource *resource,
996 const char *filename)
998 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1000 ivi_layout_takeScreenshot(iviscrn->layout_screen, filename);
1004 controller_screen_set_render_order(struct wl_client *client,
1005 struct wl_resource *resource,
1006 struct wl_array *id_layers)
1008 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1009 struct ivi_layout_layer **layoutlayer_array = NULL;
1010 struct ivilayer *ivilayer = NULL;
1011 uint32_t *id_layer = NULL;
1012 uint32_t id_layout_layer = 0;
1016 *layoutlayer_array = (struct ivi_layout_layer*)calloc(
1017 id_layers->size, sizeof(void*));
1019 wl_array_for_each(id_layer, id_layers) {
1020 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1021 id_layout_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1022 if (*id_layer == id_layout_layer) {
1023 layoutlayer_array[i] = ivilayer->layout_layer;
1030 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen,
1031 layoutlayer_array, id_layers->size);
1032 free(layoutlayer_array);
1036 struct ivi_controller_screen_interface controller_screen_implementation = {
1037 controller_screen_destroy,
1038 controller_screen_clear,
1039 controller_screen_add_layer,
1040 controller_screen_screenshot,
1041 controller_screen_set_render_order
1045 controller_commit_changes(struct wl_client *client,
1046 struct wl_resource *resource)
1052 ans = ivi_layout_commitChanges();
1054 weston_log("Failed to commit changes at controller_commit_changes\n");
1059 controller_layer_create(struct wl_client *client,
1060 struct wl_resource *resource,
1066 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1067 struct ivishell *shell = ctrl->shell;
1068 struct ivi_layout_layer *layout_layer = NULL;
1069 struct ivicontroller_layer *ctrllayer = NULL;
1070 struct ivilayer *ivilayer = NULL;
1071 struct ivi_layout_LayerProperties prop;
1073 ivilayer = get_layer(&shell->list_layer, id_layer);
1074 if (ivilayer == NULL) {
1075 layout_layer = ivi_layout_layerCreateWithDimension(id_layer,
1076 (uint32_t)width, (uint32_t)height);
1077 if (layout_layer == NULL) {
1078 weston_log("id_layer is already created\n");
1082 /* ivilayer will be created by layer_event_create */
1083 ivilayer = get_layer(&shell->list_layer, id_layer);
1084 if (ivilayer == NULL) {
1085 weston_log("couldn't get layer object\n");
1090 ctrllayer = calloc(1, sizeof *ctrllayer);
1092 weston_log("no memory to allocate client layer\n");
1096 ++ivilayer->controller_layer_count;
1098 ctrllayer->shell = shell;
1099 ctrllayer->client = client;
1101 ctrllayer->id_layer = id_layer;
1102 ctrllayer->resource = wl_resource_create(client,
1103 &ivi_controller_layer_interface, 1, id);
1104 if (ctrllayer->resource == NULL) {
1105 weston_log("couldn't get layer object\n");
1109 wl_list_init(&ctrllayer->link);
1110 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1112 wl_resource_set_implementation(ctrllayer->resource,
1113 &controller_layer_implementation,
1114 ivilayer, destroy_ivicontroller_layer);
1116 memset(&prop, 0, sizeof prop);
1118 ivi_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1119 send_layer_event(ctrllayer->resource, ivilayer,
1120 &prop, IVI_NOTIFICATION_ALL);
1124 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1126 struct ivishell *shell = userdata;
1127 struct ivicontroller_surface *ctrlsurf = NULL;
1128 uint32_t id_surface = 0;
1131 surface_event_remove(layout_surface, userdata);
1136 controller_surface_create(struct wl_client *client,
1137 struct wl_resource *resource,
1138 uint32_t id_surface,
1141 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1142 struct ivishell *shell = ctrl->shell;
1143 struct ivicontroller_surface *ctrlsurf = NULL;
1144 struct ivi_layout_SurfaceProperties prop;
1145 struct ivisurface *ivisurf = NULL;
1147 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1149 weston_log("no memory to allocate controller surface\n");
1153 ctrlsurf->shell = shell;
1154 ctrlsurf->client = client;
1156 ctrlsurf->id_surface = id_surface;
1157 wl_list_init(&ctrlsurf->link);
1158 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1160 ctrlsurf->resource = wl_resource_create(client,
1161 &ivi_controller_surface_interface, 1, id);
1162 if (ctrlsurf->resource == NULL) {
1163 weston_log("couldn't surface object");
1167 ivisurf = get_surface(&shell->list_surface, id_surface);
1168 if (ivisurf == NULL) {
1172 ++ivisurf->controller_surface_count;
1174 wl_resource_set_implementation(ctrlsurf->resource,
1175 &controller_surface_implementation,
1176 ivisurf, destroy_ivicontroller_surface);
1178 memset(&prop, 0, sizeof prop);
1180 ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1181 ivi_layout_surfaceSetContentObserver(ivisurf->layout_surface, surface_event_content, shell);
1183 send_surface_event(ctrlsurf->resource, ivisurf,
1184 &prop, IVI_NOTIFICATION_ALL);
1187 static const struct ivi_controller_interface controller_implementation = {
1188 controller_commit_changes,
1189 controller_layer_create,
1190 controller_surface_create
1194 add_client_to_resources(struct ivishell *shell,
1195 struct wl_client *client,
1196 struct ivicontroller *controller)
1198 struct ivisurface* ivisurf = NULL;
1199 struct ivilayer* ivilayer = NULL;
1200 struct iviscreen* iviscrn = NULL;
1201 struct ivicontroller_screen *ctrlscrn = NULL;
1202 struct wl_resource *resource_output = NULL;
1203 uint32_t id_layout_surface = 0;
1204 uint32_t id_layout_layer = 0;
1206 wl_list_for_each(ivisurf, &shell->list_surface, link) {
1208 ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1210 ivi_controller_send_surface(controller->resource,
1214 wl_list_for_each(ivilayer, &shell->list_layer, link) {
1216 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1218 ivi_controller_send_layer(controller->resource,
1222 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1223 resource_output = wl_resource_find_for_client(
1224 &iviscrn->output->resource_list, client);
1225 if (resource_output == NULL) {
1229 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1230 if (ctrlscrn == NULL) {
1234 ivi_controller_send_screen(controller->resource,
1235 wl_resource_get_id(resource_output),
1236 ctrlscrn->resource);
1241 bind_ivi_controller(struct wl_client *client, void *data,
1242 uint32_t version, uint32_t id)
1244 struct ivishell *shell = data;
1245 struct ivicontroller *controller;
1248 controller = calloc(1, sizeof *controller);
1249 if (controller == NULL) {
1250 weston_log("no memory to allocate controller\n");
1254 controller->resource =
1255 wl_resource_create(client, &ivi_controller_interface, 1, id);
1256 wl_resource_set_implementation(controller->resource,
1257 &controller_implementation,
1258 controller, unbind_resource_controller);
1260 controller->shell = shell;
1261 controller->client = client;
1262 controller->id = id;
1264 wl_list_init(&controller->link);
1265 wl_list_insert(&shell->list_controller, &controller->link);
1267 add_client_to_resources(shell, client, controller);
1270 static struct iviscreen*
1271 create_screen(struct ivishell *shell, struct weston_output *output)
1273 struct iviscreen *iviscrn;
1274 iviscrn = calloc(1, sizeof *iviscrn);
1275 if (iviscrn == NULL) {
1276 weston_log("no memory to allocate client screen\n");
1280 iviscrn->shell = shell;
1281 iviscrn->output = output;
1283 // TODO : Only Single display
1284 iviscrn->layout_screen = ivi_layout_getScreenFromId(0);
1286 wl_list_init(&iviscrn->link);
1291 static struct ivilayer*
1292 create_layer(struct ivishell *shell,
1293 struct ivi_layout_layer *layout_layer,
1296 struct ivilayer *ivilayer = NULL;
1297 struct ivicontroller *controller = NULL;
1299 ivilayer = get_layer(&shell->list_layer, id_layer);
1300 if (ivilayer != NULL) {
1301 weston_log("id_layer is already created\n");
1305 ivilayer = calloc(1, sizeof *ivilayer);
1306 if (NULL == ivilayer) {
1307 weston_log("no memory to allocate client layer\n");
1311 ivilayer->shell = shell;
1312 wl_list_init(&ivilayer->list_screen);
1313 wl_list_init(&ivilayer->link);
1314 wl_list_insert(&shell->list_layer, &ivilayer->link);
1315 ivilayer->layout_layer = layout_layer;
1317 ivi_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1319 wl_list_for_each(controller, &shell->list_controller, link) {
1320 ivi_controller_send_layer(controller->resource, id_layer);
1326 static struct ivisurface*
1327 create_surface(struct ivishell *shell,
1328 struct ivi_layout_surface *layout_surface,
1329 uint32_t id_surface)
1331 struct ivisurface *ivisurf = NULL;
1332 struct ivicontroller *controller = NULL;
1334 ivisurf = get_surface(&shell->list_surface, id_surface);
1335 if (ivisurf != NULL) {
1336 weston_log("id_surface is already created\n");
1340 ivisurf = calloc(1, sizeof *ivisurf);
1341 if (ivisurf == NULL) {
1342 weston_log("no memory to allocate client surface\n");
1346 ivisurf->shell = shell;
1347 ivisurf->layout_surface = layout_surface;
1348 wl_list_init(&ivisurf->list_layer);
1349 wl_list_init(&ivisurf->link);
1350 wl_list_insert(&shell->list_surface, &ivisurf->link);
1352 wl_list_for_each(controller, &shell->list_controller, link) {
1353 ivi_controller_send_surface(controller->resource,
1357 ivi_layout_surfaceAddNotification(layout_surface,
1358 send_surface_prop, ivisurf);
1364 layer_event_create(struct ivi_layout_layer *layout_layer,
1367 struct ivishell *shell = userdata;
1368 struct ivilayer *ivilayer = NULL;
1369 uint32_t id_layer = 0;
1371 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1373 ivilayer = create_layer(shell, layout_layer, id_layer);
1374 if (ivilayer == NULL) {
1375 weston_log("failed to create layer");
1381 layer_event_remove(struct ivi_layout_layer *layout_layer,
1384 struct ivishell *shell = userdata;
1385 struct ivicontroller_layer *ctrllayer = NULL;
1386 struct ivilayer *ivilayer = NULL;
1387 struct ivilayer *next = NULL;
1388 uint32_t id_layer = 0;
1391 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1392 if (layout_layer != ivilayer->layout_layer) {
1396 wl_list_remove(&ivilayer->link);
1405 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1407 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1408 if (id_layer != ctrllayer->id_layer) {
1411 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1418 surface_event_create(struct ivi_layout_surface *layout_surface,
1421 struct ivishell *shell = userdata;
1422 struct ivisurface *ivisurf = NULL;
1423 uint32_t id_surface = 0;
1425 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1427 ivisurf = create_surface(shell, layout_surface, id_surface);
1428 if (ivisurf == NULL) {
1429 weston_log("failed to create surface");
1435 surface_event_remove(struct ivi_layout_surface *layout_surface,
1438 struct ivishell *shell = userdata;
1439 struct ivicontroller_surface *ctrlsurf = NULL;
1440 struct ivisurface *ivisurf = NULL;
1441 struct ivisurface *next = NULL;
1442 uint32_t id_surface = 0;
1445 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1446 if (layout_surface != ivisurf->layout_surface) {
1450 wl_list_remove(&ivisurf->link);
1453 if (ivisurf->controller_surface_count == 0) {
1457 ivisurf->can_be_removed = 1;
1464 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1466 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1467 if (id_surface != ctrlsurf->id_surface) {
1470 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1476 surface_event_configure(struct ivi_layout_surface *layout_surface,
1479 struct ivishell *shell = userdata;
1480 struct ivisurface *ivisurf = NULL;
1481 struct ivicontroller_surface *ctrlsurf = NULL;
1482 struct ivi_layout_SurfaceProperties prop;
1483 uint32_t id_surface = 0;
1485 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1487 ivisurf = get_surface(&shell->list_surface, id_surface);
1488 if (ivisurf == NULL) {
1489 weston_log("id_surface is not created yet\n");
1493 memset(&prop, 0, sizeof prop);
1494 ivi_layout_getPropertiesOfSurface(layout_surface, &prop);
1496 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1497 if (id_surface != ctrlsurf->id_surface) {
1500 send_surface_event(ctrlsurf->resource, ivisurf,
1501 &prop, IVI_NOTIFICATION_ALL);
1506 check_layout_layers(struct ivishell *shell)
1508 struct ivi_layout_layer **pArray = NULL;
1509 struct ivilayer *ivilayer = NULL;
1510 uint32_t id_layer = 0;
1511 uint32_t length = 0;
1515 ret = ivi_layout_getLayers(&length, &pArray);
1517 weston_log("failed to get layers at check_layout_layers\n");
1522 /* if length is 0, pArray doesn't need to free.*/
1526 for (i = 0; i < length; i++) {
1527 id_layer = ivi_layout_getIdOfLayer(pArray[i]);
1528 ivilayer = create_layer(shell, pArray[i], id_layer);
1529 if (ivilayer == NULL) {
1530 weston_log("failed to create layer");
1541 check_layout_surfaces(struct ivishell *shell)
1543 struct ivi_layout_surface **pArray = NULL;
1544 struct ivisurface *ivisurf = NULL;
1545 uint32_t id_surface = 0;
1546 uint32_t length = 0;
1550 ret = ivi_layout_getSurfaces(&length, &pArray);
1552 weston_log("failed to get surfaces at check_layout_surfaces\n");
1557 /* if length is 0, pArray doesn't need to free.*/
1561 for (i = 0; i < length; i++) {
1562 id_surface = ivi_layout_getIdOfSurface(pArray[i]);
1563 ivisurf = create_surface(shell, pArray[i], id_surface);
1564 if (ivisurf == NULL) {
1565 weston_log("failed to create surface");
1576 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1578 struct weston_output *output = NULL;
1579 struct iviscreen *iviscrn = NULL;
1582 shell->compositor = ec;
1584 wl_list_init(&shell->list_surface);
1585 wl_list_init(&shell->list_layer);
1586 wl_list_init(&shell->list_screen);
1587 wl_list_init(&shell->list_weston_surface);
1588 wl_list_init(&shell->list_controller);
1589 wl_list_init(&shell->list_controller_screen);
1590 wl_list_init(&shell->list_controller_layer);
1591 wl_list_init(&shell->list_controller_surface);
1592 shell->event_restriction = 0;
1594 wl_list_for_each(output, &ec->output_list, link) {
1595 iviscrn = create_screen(shell, output);
1596 if (iviscrn != NULL) {
1597 wl_list_insert(&shell->list_screen, &iviscrn->link);
1601 ret = check_layout_layers(shell);
1603 weston_log("failed to check_layout_layers");
1606 ret = check_layout_surfaces(shell);
1608 weston_log("failed to check_layout_surfaces");
1611 ivi_layout_addNotificationCreateLayer(layer_event_create, shell);
1612 ivi_layout_addNotificationRemoveLayer(layer_event_remove, shell);
1614 ivi_layout_addNotificationCreateSurface(surface_event_create, shell);
1615 ivi_layout_addNotificationRemoveSurface(surface_event_remove, shell);
1616 ivi_layout_addNotificationConfigureSurface(surface_event_configure, shell);
1620 module_init(struct weston_compositor *ec,
1621 int *argc, char *argv[])
1623 struct ivishell *shell;
1627 shell = malloc(sizeof *shell);
1631 memset(shell, 0, sizeof *shell);
1632 init_ivi_shell(ec, shell);
1634 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
1635 shell, bind_ivi_controller) == NULL) {