2 * Copyright (C) 2013 DENSO CORPORATION
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 #include <linux/input.h>
31 #include "weston/compositor.h"
32 #include "ivi-controller-server-protocol.h"
33 #include "ivi-layout-export.h"
40 struct ivilayer *layer;
45 struct iviscreen *screen;
51 struct wl_client *client;
52 struct ivishell *shell;
53 uint32_t update_count;
54 struct ivi_layout_surface *layout_surface;
55 struct wl_listener surface_destroy_listener;
56 struct wl_list list_layer;
57 uint32_t controller_surface_count;
63 struct ivishell *shell;
64 struct ivi_layout_layer *layout_layer;
65 struct wl_list list_screen;
66 uint32_t controller_layer_count;
67 int layer_canbe_removed;
72 struct ivishell *shell;
73 struct ivi_layout_screen *layout_screen;
74 struct weston_output *output;
77 struct ivicontroller_surface {
78 struct wl_resource *resource;
81 struct wl_client *client;
83 struct ivishell *shell;
86 struct ivicontroller_layer {
87 struct wl_resource *resource;
90 struct wl_client *client;
92 struct ivishell *shell;
95 struct ivicontroller_screen {
96 struct wl_resource *resource;
99 struct wl_client *client;
101 struct ivishell *shell;
104 struct ivicontroller {
105 struct wl_resource *resource;
107 struct wl_client *client;
109 struct ivishell *shell;
112 struct link_shell_weston_surface
114 struct wl_resource *resource;
115 struct wl_listener destroy_listener;
116 struct weston_surface *surface;
121 struct wl_resource *resource;
123 struct wl_listener destroy_listener;
125 struct weston_compositor *compositor;
127 struct weston_surface *surface;
129 struct weston_process process;
131 struct weston_seat *seat;
133 struct wl_list list_surface;
134 struct wl_list list_layer;
135 struct wl_list list_screen;
137 struct wl_list list_weston_surface;
139 struct wl_list list_controller;
140 struct wl_list list_controller_surface;
141 struct wl_list list_controller_layer;
142 struct wl_list list_controller_screen;
145 struct weston_process process;
146 struct wl_client *client;
147 struct wl_resource *desktop_shell;
155 int event_restriction;
157 static void surface_event_remove(struct ivi_layout_surface *, void *);
160 destroy_ivicontroller_surface(struct wl_resource *resource)
162 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
163 struct ivishell *shell = ivisurf->shell;
164 struct ivicontroller_surface *ctrlsurf = NULL;
165 struct ivicontroller_surface *next = NULL;
168 wl_list_for_each_safe(ctrlsurf, next,
169 &shell->list_controller_surface, link) {
171 if (resource != ctrlsurf->resource) {
175 if (!wl_list_empty(&ctrlsurf->link)) {
176 wl_list_remove(&ctrlsurf->link);
182 --ivisurf->controller_surface_count;
186 if ((is_removed) && (ivisurf->controller_surface_count == 0)) {
187 if (ivisurf->can_be_removed) {
191 ivisurf->can_be_removed = 1;
197 destroy_ivicontroller_layer(struct wl_resource *resource)
199 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
200 struct ivishell *shell = ivilayer->shell;
201 struct ivicontroller_layer *ctrllayer = NULL;
202 struct ivicontroller_layer *next = NULL;
203 uint32_t id_layer = 0;
205 id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
207 wl_list_for_each_safe(ctrllayer, next,
208 &shell->list_controller_layer, link) {
210 if (resource != ctrllayer->resource) {
214 wl_list_remove(&ctrllayer->link);
215 --ivilayer->controller_layer_count;
216 ivi_controller_layer_send_destroyed(ctrllayer->resource);
222 if ((ivilayer->layout_layer != NULL) &&
223 (ivilayer->controller_layer_count == 0) &&
224 (ivilayer->layer_canbe_removed == 1)) {
225 ivi_layout_layerRemove(ivilayer->layout_layer);
230 destroy_ivicontroller_screen(struct wl_resource *resource)
232 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
233 struct ivicontroller_screen *ctrlscrn = NULL;
234 struct ivicontroller_screen *next = NULL;
236 wl_list_for_each_safe(ctrlscrn, next,
237 &iviscrn->shell->list_controller_screen, link) {
238 // TODO : Only Single display
240 if (iviscrn->output->id != ctrlscrn->id_screen) {
245 if (resource != ctrlscrn->resource) {
249 wl_list_remove(&ctrlscrn->link);
257 unbind_resource_controller(struct wl_resource *resource)
259 struct ivicontroller *controller = wl_resource_get_user_data(resource);
261 wl_list_remove(&controller->link);
267 static struct ivisurface*
268 get_surface(struct wl_list *list_surf, uint32_t id_surface)
270 struct ivisurface *ivisurf = NULL;
271 uint32_t ivisurf_id = 0;
273 wl_list_for_each(ivisurf, list_surf, link) {
274 ivisurf_id = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
275 if (ivisurf_id == id_surface) {
283 static struct ivilayer*
284 get_layer(struct wl_list *list_layer, uint32_t id_layer)
286 struct ivilayer *ivilayer = NULL;
287 uint32_t ivilayer_id = 0;
289 wl_list_for_each(ivilayer, list_layer, link) {
290 ivilayer_id = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
291 if (ivilayer_id == id_layer) {
300 struct ivi_controller_screen_interface controller_screen_implementation;
302 static struct ivicontroller_screen*
303 controller_screen_create(struct ivishell *shell,
304 struct wl_client *client,
305 struct iviscreen *iviscrn)
307 struct ivicontroller_screen *ctrlscrn = NULL;
309 ctrlscrn = calloc(1, sizeof *ctrlscrn);
310 if (ctrlscrn == NULL) {
311 weston_log("no memory to allocate controller screen\n");
315 ctrlscrn->client = client;
316 ctrlscrn->shell = shell;
318 // TODO : Only Single display
320 /* ctrlscrn->id_screen = iviscrn->id_screen; */
322 ctrlscrn->id_screen = 0;
326 wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
327 if (ctrlscrn->resource == NULL) {
328 weston_log("couldn't new screen controller object");
336 wl_resource_set_implementation(ctrlscrn->resource,
337 &controller_screen_implementation,
338 iviscrn, destroy_ivicontroller_screen);
340 wl_list_init(&ctrlscrn->link);
341 wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
347 send_surface_add_event(struct ivisurface *ivisurf,
348 struct wl_resource *resource,
349 enum ivi_layout_notification_mask mask)
351 struct ivi_layout_layer **pArray = NULL;
355 struct link_layer *link_layer = NULL;
356 struct link_layer *next = NULL;
357 struct ivicontroller_layer *ctrllayer = NULL;
358 struct ivilayer *ivilayer = NULL;
359 struct ivishell *shell = ivisurf->shell;
360 uint32_t id_layout_layer = 0;
361 struct wl_client *surface_client = wl_resource_get_client(resource);
364 ans = ivi_layout_getLayersUnderSurface(ivisurf->layout_surface,
367 weston_log("failed to get layers at send_surface_add_event\n");
371 /* Send Null to cancel added surface */
372 if (mask & IVI_NOTIFICATION_REMOVE) {
373 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
374 ivi_controller_surface_send_layer(resource, NULL);
375 wl_list_remove(&link_layer->link);
380 else if (mask & IVI_NOTIFICATION_ADD) {
381 for (i = 0; i < (int)length; i++) {
382 /* Create list_layer */
383 link_layer = calloc(1, sizeof(*link_layer));
384 if (NULL == link_layer) {
387 wl_list_init(&link_layer->link);
388 link_layer->layer = NULL;
389 wl_list_for_each(ivilayer, &shell->list_layer, link) {
390 if (ivilayer->layout_layer == pArray[i]) {
391 link_layer->layer = ivilayer;
396 if (link_layer->layer == NULL) {
402 struct link_layer *layer_link = NULL;
403 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
405 /* Send new surface event */
407 ivi_layout_getIdOfLayer(link_layer->layer->layout_layer);
408 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
409 if (id_layout_layer != ctrllayer->id_layer) {
413 struct wl_client *layer_client = wl_resource_get_client(ctrllayer->resource);
414 if (surface_client != layer_client) {
418 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
428 send_surface_event(struct wl_resource *resource,
429 struct ivisurface *ivisurf,
430 struct ivi_layout_SurfaceProperties *prop,
433 if (mask & IVI_NOTIFICATION_OPACITY) {
434 ivi_controller_surface_send_opacity(resource,
437 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
438 ivi_controller_surface_send_source_rectangle(resource,
439 prop->sourceX, prop->sourceY,
440 prop->sourceWidth, prop->sourceHeight);
442 if (mask & IVI_NOTIFICATION_DEST_RECT) {
443 ivi_controller_surface_send_destination_rectangle(resource,
444 prop->destX, prop->destY,
445 prop->destWidth, prop->destHeight);
447 if (mask & IVI_NOTIFICATION_ORIENTATION) {
448 ivi_controller_surface_send_orientation(resource,
451 if (mask & IVI_NOTIFICATION_VISIBILITY) {
452 ivi_controller_surface_send_visibility(resource,
455 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
456 ivi_controller_surface_send_pixelformat(resource,
459 if (mask & IVI_NOTIFICATION_ADD) {
460 send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_ADD);
462 if (mask & IVI_NOTIFICATION_REMOVE) {
463 send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_REMOVE);
468 send_surface_prop(struct ivi_layout_surface *layout_surface,
469 struct ivi_layout_SurfaceProperties *prop,
470 enum ivi_layout_notification_mask mask,
473 struct ivisurface *ivisurf = userdata;
474 struct ivishell *shell = ivisurf->shell;
475 struct ivicontroller_surface *ctrlsurf = NULL;
476 uint32_t id_surface = 0;
478 id_surface = ivi_layout_getIdOfSurface(layout_surface);
480 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
481 if (id_surface != ctrlsurf->id_surface) {
484 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
489 send_layer_add_event(struct ivilayer *ivilayer,
490 struct wl_resource *resource,
491 enum ivi_layout_notification_mask mask)
493 struct ivi_layout_screen **pArray = NULL;
497 struct link_screen *link_scrn = NULL;
498 struct link_screen *next = NULL;
499 struct iviscreen *iviscrn = NULL;
500 struct ivishell *shell = ivilayer->shell;
501 struct wl_client *client = wl_resource_get_client(resource);
502 struct wl_resource *resource_output = NULL;
504 ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
507 weston_log("failed to get screens at send_layer_add_event\n");
511 /* Send Null to cancel added layer */
512 if (mask & IVI_NOTIFICATION_REMOVE) {
513 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
514 ivi_controller_layer_send_screen(resource, NULL);
515 wl_list_remove(&link_scrn->link);
520 else if (mask & IVI_NOTIFICATION_ADD) {
521 for (i = 0; i < (int)length; i++) {
522 /* Create list_screen */
523 link_scrn = calloc(1, sizeof(*link_scrn));
524 if (NULL == link_scrn) {
527 wl_list_init(&link_scrn->link);
528 link_scrn->screen = NULL;
529 wl_list_for_each(iviscrn, &shell->list_screen, link) {
530 if (iviscrn->layout_screen == pArray[i]) {
531 link_scrn->screen = iviscrn;
536 if (link_scrn->screen == NULL) {
541 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
543 /* Send new layer event */
545 wl_resource_find_for_client(&iviscrn->output->resource_list,
547 if (resource_output != NULL) {
548 ivi_controller_layer_send_screen(resource, resource_output);
558 send_layer_event(struct wl_resource *resource,
559 struct ivilayer *ivilayer,
560 struct ivi_layout_LayerProperties *prop,
563 if (mask & IVI_NOTIFICATION_OPACITY) {
564 ivi_controller_layer_send_opacity(resource,
567 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
568 ivi_controller_layer_send_source_rectangle(resource,
574 if (mask & IVI_NOTIFICATION_DEST_RECT) {
575 ivi_controller_layer_send_destination_rectangle(resource,
581 if (mask & IVI_NOTIFICATION_ORIENTATION) {
582 ivi_controller_layer_send_orientation(resource,
585 if (mask & IVI_NOTIFICATION_VISIBILITY) {
586 ivi_controller_layer_send_visibility(resource,
589 if (mask & IVI_NOTIFICATION_ADD) {
590 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_ADD);
592 if (mask & IVI_NOTIFICATION_REMOVE) {
593 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_REMOVE);
598 send_layer_prop(struct ivi_layout_layer *layer,
599 struct ivi_layout_LayerProperties *prop,
600 enum ivi_layout_notification_mask mask,
603 struct ivilayer *ivilayer = userdata;
604 struct ivicontroller_layer *ctrllayer = NULL;
605 struct ivishell *shell = ivilayer->shell;
606 uint32_t id_layout_layer = 0;
608 id_layout_layer = ivi_layout_getIdOfLayer(layer);
609 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
610 if (id_layout_layer != ctrllayer->id_layer) {
613 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
618 controller_surface_set_opacity(struct wl_client *client,
619 struct wl_resource *resource,
622 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
624 ivi_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
628 controller_surface_set_source_rectangle(struct wl_client *client,
629 struct wl_resource *resource,
635 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
637 ivi_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
638 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
642 controller_surface_set_destination_rectangle(struct wl_client *client,
643 struct wl_resource *resource,
649 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
651 ivi_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
652 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
656 controller_surface_set_visibility(struct wl_client *client,
657 struct wl_resource *resource,
660 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
662 ivi_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
666 controller_surface_set_configuration(struct wl_client *client,
667 struct wl_resource *resource,
668 int32_t width, int32_t height)
670 /* This interface has been supported yet. */
678 controller_surface_set_orientation(struct wl_client *client,
679 struct wl_resource *resource,
682 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
684 ivi_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
688 controller_surface_screenshot(struct wl_client *client,
689 struct wl_resource *resource,
690 const char *filename)
692 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
694 ivi_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
698 controller_surface_send_stats(struct wl_client *client,
699 struct wl_resource *resource)
701 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
705 wl_client_get_credentials(client, &pid, &uid, &gid);
707 ivi_controller_surface_send_stats(resource, 0, 0,
708 ivisurf->update_count, pid, "");
712 controller_surface_destroy(struct wl_client *client,
713 struct wl_resource *resource,
714 int32_t destroy_scene_object)
717 (void)destroy_scene_object;
718 wl_resource_destroy(resource);
722 controller_surface_set_input_focus(struct wl_client *client,
723 struct wl_resource *resource,
732 struct ivi_controller_surface_interface controller_surface_implementation = {
733 controller_surface_set_visibility,
734 controller_surface_set_opacity,
735 controller_surface_set_source_rectangle,
736 controller_surface_set_destination_rectangle,
737 controller_surface_set_configuration,
738 controller_surface_set_orientation,
739 controller_surface_screenshot,
740 controller_surface_send_stats,
741 controller_surface_destroy,
742 controller_surface_set_input_focus
746 controller_layer_set_source_rectangle(struct wl_client *client,
747 struct wl_resource *resource,
753 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
755 ivi_layout_layerSetSourceRectangle(ivilayer->layout_layer,
756 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
760 controller_layer_set_destination_rectangle(struct wl_client *client,
761 struct wl_resource *resource,
767 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
769 ivi_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
770 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
774 controller_layer_set_visibility(struct wl_client *client,
775 struct wl_resource *resource,
778 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
780 ivi_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
784 controller_layer_set_opacity(struct wl_client *client,
785 struct wl_resource *resource,
788 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
790 ivi_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
794 controller_layer_set_configuration(struct wl_client *client,
795 struct wl_resource *resource,
799 /* This interface has been supported yet. */
807 controller_layer_set_orientation(struct wl_client *client,
808 struct wl_resource *resource,
811 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
813 ivi_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
817 controller_layer_clear_surfaces(struct wl_client *client,
818 struct wl_resource *resource)
820 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
822 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
826 controller_layer_add_surface(struct wl_client *client,
827 struct wl_resource *resource,
828 struct wl_resource *surface)
830 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
831 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
833 ivi_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
837 controller_layer_remove_surface(struct wl_client *client,
838 struct wl_resource *resource,
839 struct wl_resource *surface)
841 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
842 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
844 ivi_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
848 controller_layer_screenshot(struct wl_client *client,
849 struct wl_resource *resource,
850 const char *filename)
858 controller_layer_set_render_order(struct wl_client *client,
859 struct wl_resource *resource,
860 struct wl_array *id_surfaces)
862 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
863 struct ivi_layout_surface **layoutsurf_array = NULL;
864 struct ivisurface *ivisurf = NULL;
865 uint32_t *id_surface = NULL;
866 uint32_t id_layout_surface = 0;
870 wl_array_for_each(id_surface, id_surfaces) {
871 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
872 id_layout_surface = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
873 if (*id_surface == id_layout_surface) {
874 layoutsurf_array[i] = ivisurf->layout_surface;
881 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer,
882 layoutsurf_array, id_surfaces->size);
883 free(layoutsurf_array);
887 controller_layer_destroy(struct wl_client *client,
888 struct wl_resource *resource,
889 int32_t destroy_scene_object)
891 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
892 struct ivishell *shell = ivilayer->shell;
893 struct ivicontroller_layer *ctrllayer = NULL;
894 struct ivicontroller_layer *next = NULL;
895 uint32_t id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
897 (void)destroy_scene_object;
899 ivilayer->layer_canbe_removed = 1;
900 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
901 if (ctrllayer->id_layer != id_layer) {
905 wl_resource_destroy(ctrllayer->resource);
910 struct ivi_controller_layer_interface controller_layer_implementation = {
911 controller_layer_set_visibility,
912 controller_layer_set_opacity,
913 controller_layer_set_source_rectangle,
914 controller_layer_set_destination_rectangle,
915 controller_layer_set_configuration,
916 controller_layer_set_orientation,
917 controller_layer_screenshot,
918 controller_layer_clear_surfaces,
919 controller_layer_add_surface,
920 controller_layer_remove_surface,
921 controller_layer_set_render_order,
922 controller_layer_destroy
926 controller_screen_destroy(struct wl_client *client,
927 struct wl_resource *resource)
929 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
930 struct ivicontroller_screen *ctrlscrn = NULL;
931 struct ivicontroller_screen *next = NULL;
932 // uint32_t id_screen = ivi_layout_getIdOfScreen(iviscrn->layout_screen);
935 wl_list_for_each_safe(ctrlscrn, next,
936 &iviscrn->shell->list_controller_screen, link) {
937 if (resource != ctrlscrn->resource) {
941 wl_list_remove(&ctrlscrn->link);
944 wl_resource_destroy(ctrlscrn->resource);
950 controller_screen_clear(struct wl_client *client,
951 struct wl_resource *resource)
953 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
955 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
959 controller_screen_add_layer(struct wl_client *client,
960 struct wl_resource *resource,
961 struct wl_resource *layer)
963 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
964 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
966 ivi_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
970 controller_screen_screenshot(struct wl_client *client,
971 struct wl_resource *resource,
972 const char *filename)
974 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
976 ivi_layout_takeScreenshot(iviscrn->layout_screen, filename);
980 controller_screen_set_render_order(struct wl_client *client,
981 struct wl_resource *resource,
982 struct wl_array *id_layers)
984 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
985 struct ivi_layout_layer **layoutlayer_array = NULL;
986 struct ivilayer *ivilayer = NULL;
987 uint32_t *id_layer = NULL;
988 uint32_t id_layout_layer = 0;
992 *layoutlayer_array = (struct ivi_layout_layer*)calloc(
993 id_layers->size, sizeof(void*));
995 wl_array_for_each(id_layer, id_layers) {
996 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
997 id_layout_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
998 if (*id_layer == id_layout_layer) {
999 layoutlayer_array[i] = ivilayer->layout_layer;
1006 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen,
1007 layoutlayer_array, id_layers->size);
1008 free(layoutlayer_array);
1012 struct ivi_controller_screen_interface controller_screen_implementation = {
1013 controller_screen_destroy,
1014 controller_screen_clear,
1015 controller_screen_add_layer,
1016 controller_screen_screenshot,
1017 controller_screen_set_render_order
1021 controller_commit_changes(struct wl_client *client,
1022 struct wl_resource *resource)
1028 ans = ivi_layout_commitChanges();
1030 weston_log("Failed to commit changes at controller_commit_changes\n");
1035 controller_layer_create(struct wl_client *client,
1036 struct wl_resource *resource,
1042 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1043 struct ivishell *shell = ctrl->shell;
1044 struct ivi_layout_layer *layout_layer = NULL;
1045 struct ivicontroller_layer *ctrllayer = NULL;
1046 struct ivilayer *ivilayer = NULL;
1047 struct ivi_layout_LayerProperties prop;
1049 ivilayer = get_layer(&shell->list_layer, id_layer);
1050 if (ivilayer == NULL) {
1051 layout_layer = ivi_layout_layerCreateWithDimension(id_layer,
1052 (uint32_t)width, (uint32_t)height);
1053 if (layout_layer == NULL) {
1054 weston_log("id_layer is already created\n");
1058 /* ivilayer will be created by layer_event_create */
1059 ivilayer = get_layer(&shell->list_layer, id_layer);
1060 if (ivilayer == NULL) {
1061 weston_log("couldn't get layer object\n");
1066 ctrllayer = calloc(1, sizeof *ctrllayer);
1068 weston_log("no memory to allocate client layer\n");
1072 ++ivilayer->controller_layer_count;
1073 ivilayer->layer_canbe_removed = 0;
1075 ctrllayer->shell = shell;
1076 ctrllayer->client = client;
1078 ctrllayer->id_layer = id_layer;
1079 ctrllayer->resource = wl_resource_create(client,
1080 &ivi_controller_layer_interface, 1, id);
1081 if (ctrllayer->resource == NULL) {
1082 weston_log("couldn't get layer object\n");
1086 wl_list_init(&ctrllayer->link);
1087 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1089 wl_resource_set_implementation(ctrllayer->resource,
1090 &controller_layer_implementation,
1091 ivilayer, destroy_ivicontroller_layer);
1093 memset(&prop, 0, sizeof prop);
1095 ivi_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1096 send_layer_event(ctrllayer->resource, ivilayer,
1097 &prop, IVI_NOTIFICATION_ALL);
1101 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1103 struct ivishell *shell = userdata;
1104 struct ivicontroller_surface *ctrlsurf = NULL;
1105 uint32_t id_surface = 0;
1108 surface_event_remove(layout_surface, userdata);
1113 controller_surface_create(struct wl_client *client,
1114 struct wl_resource *resource,
1115 uint32_t id_surface,
1118 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1119 struct ivishell *shell = ctrl->shell;
1120 struct ivicontroller_surface *ctrlsurf = NULL;
1121 struct ivi_layout_SurfaceProperties prop;
1122 struct ivisurface *ivisurf = NULL;
1124 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1126 weston_log("no memory to allocate controller surface\n");
1130 ctrlsurf->shell = shell;
1131 ctrlsurf->client = client;
1133 ctrlsurf->id_surface = id_surface;
1134 wl_list_init(&ctrlsurf->link);
1135 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1137 ctrlsurf->resource = wl_resource_create(client,
1138 &ivi_controller_surface_interface, 1, id);
1139 if (ctrlsurf->resource == NULL) {
1140 weston_log("couldn't surface object");
1144 ivisurf = get_surface(&shell->list_surface, id_surface);
1145 if (ivisurf == NULL) {
1149 ++ivisurf->controller_surface_count;
1151 wl_resource_set_implementation(ctrlsurf->resource,
1152 &controller_surface_implementation,
1153 ivisurf, destroy_ivicontroller_surface);
1155 memset(&prop, 0, sizeof prop);
1157 ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1158 ivi_layout_surfaceSetContentObserver(ivisurf->layout_surface, surface_event_content, shell);
1160 send_surface_event(ctrlsurf->resource, ivisurf,
1161 &prop, IVI_NOTIFICATION_ALL);
1164 static const struct ivi_controller_interface controller_implementation = {
1165 controller_commit_changes,
1166 controller_layer_create,
1167 controller_surface_create
1171 add_client_to_resources(struct ivishell *shell,
1172 struct wl_client *client,
1173 struct ivicontroller *controller)
1175 struct ivisurface* ivisurf = NULL;
1176 struct ivilayer* ivilayer = NULL;
1177 struct iviscreen* iviscrn = NULL;
1178 struct ivicontroller_screen *ctrlscrn = NULL;
1179 struct wl_resource *resource_output = NULL;
1180 uint32_t id_layout_surface = 0;
1181 uint32_t id_layout_layer = 0;
1183 wl_list_for_each_reverse(ivisurf, &shell->list_surface, link) {
1185 ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1187 ivi_controller_send_surface(controller->resource,
1191 wl_list_for_each_reverse(ivilayer, &shell->list_layer, link) {
1193 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1195 ivi_controller_send_layer(controller->resource,
1199 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1200 resource_output = wl_resource_find_for_client(
1201 &iviscrn->output->resource_list, client);
1202 if (resource_output == NULL) {
1206 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1207 if (ctrlscrn == NULL) {
1211 ivi_controller_send_screen(controller->resource,
1212 wl_resource_get_id(resource_output),
1213 ctrlscrn->resource);
1218 bind_ivi_controller(struct wl_client *client, void *data,
1219 uint32_t version, uint32_t id)
1221 struct ivishell *shell = data;
1222 struct ivicontroller *controller;
1225 controller = calloc(1, sizeof *controller);
1226 if (controller == NULL) {
1227 weston_log("no memory to allocate controller\n");
1231 controller->resource =
1232 wl_resource_create(client, &ivi_controller_interface, 1, id);
1233 wl_resource_set_implementation(controller->resource,
1234 &controller_implementation,
1235 controller, unbind_resource_controller);
1237 controller->shell = shell;
1238 controller->client = client;
1239 controller->id = id;
1241 wl_list_init(&controller->link);
1242 wl_list_insert(&shell->list_controller, &controller->link);
1244 add_client_to_resources(shell, client, controller);
1247 static struct iviscreen*
1248 create_screen(struct ivishell *shell, struct weston_output *output)
1250 struct iviscreen *iviscrn;
1251 iviscrn = calloc(1, sizeof *iviscrn);
1252 if (iviscrn == NULL) {
1253 weston_log("no memory to allocate client screen\n");
1257 iviscrn->shell = shell;
1258 iviscrn->output = output;
1260 // TODO : Only Single display
1261 iviscrn->layout_screen = ivi_layout_getScreenFromId(0);
1263 wl_list_init(&iviscrn->link);
1268 static struct ivilayer*
1269 create_layer(struct ivishell *shell,
1270 struct ivi_layout_layer *layout_layer,
1273 struct ivilayer *ivilayer = NULL;
1274 struct ivicontroller *controller = NULL;
1276 ivilayer = get_layer(&shell->list_layer, id_layer);
1277 if (ivilayer != NULL) {
1278 weston_log("id_layer is already created\n");
1282 ivilayer = calloc(1, sizeof *ivilayer);
1283 if (NULL == ivilayer) {
1284 weston_log("no memory to allocate client layer\n");
1288 ivilayer->shell = shell;
1289 wl_list_init(&ivilayer->list_screen);
1290 wl_list_init(&ivilayer->link);
1291 wl_list_insert(&shell->list_layer, &ivilayer->link);
1292 ivilayer->layout_layer = layout_layer;
1294 ivi_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1296 wl_list_for_each(controller, &shell->list_controller, link) {
1297 ivi_controller_send_layer(controller->resource, id_layer);
1303 static struct ivisurface*
1304 create_surface(struct ivishell *shell,
1305 struct ivi_layout_surface *layout_surface,
1306 uint32_t id_surface)
1308 struct ivisurface *ivisurf = NULL;
1309 struct ivicontroller *controller = NULL;
1311 ivisurf = get_surface(&shell->list_surface, id_surface);
1312 if (ivisurf != NULL) {
1313 weston_log("id_surface is already created\n");
1317 ivisurf = calloc(1, sizeof *ivisurf);
1318 if (ivisurf == NULL) {
1319 weston_log("no memory to allocate client surface\n");
1323 ivisurf->shell = shell;
1324 ivisurf->layout_surface = layout_surface;
1325 wl_list_init(&ivisurf->list_layer);
1326 wl_list_init(&ivisurf->link);
1327 wl_list_insert(&shell->list_surface, &ivisurf->link);
1329 wl_list_for_each(controller, &shell->list_controller, link) {
1330 ivi_controller_send_surface(controller->resource,
1334 ivi_layout_surfaceAddNotification(layout_surface,
1335 send_surface_prop, ivisurf);
1341 layer_event_create(struct ivi_layout_layer *layout_layer,
1344 struct ivishell *shell = userdata;
1345 struct ivilayer *ivilayer = NULL;
1346 uint32_t id_layer = 0;
1348 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1350 ivilayer = create_layer(shell, layout_layer, id_layer);
1351 if (ivilayer == NULL) {
1352 weston_log("failed to create layer");
1358 layer_event_remove(struct ivi_layout_layer *layout_layer,
1361 struct ivishell *shell = userdata;
1362 struct ivicontroller_layer *ctrllayer = NULL;
1363 struct ivilayer *ivilayer = NULL;
1364 struct ivilayer *next = NULL;
1365 uint32_t id_layer = 0;
1368 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1369 if (layout_layer != ivilayer->layout_layer) {
1373 wl_list_remove(&ivilayer->link);
1382 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1384 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1385 if (id_layer != ctrllayer->id_layer) {
1388 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1395 surface_event_create(struct ivi_layout_surface *layout_surface,
1398 struct ivishell *shell = userdata;
1399 struct ivisurface *ivisurf = NULL;
1400 uint32_t id_surface = 0;
1402 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1404 ivisurf = create_surface(shell, layout_surface, id_surface);
1405 if (ivisurf == NULL) {
1406 weston_log("failed to create surface");
1412 surface_event_remove(struct ivi_layout_surface *layout_surface,
1415 struct ivishell *shell = userdata;
1416 struct ivicontroller_surface *ctrlsurf = NULL;
1417 struct ivisurface *ivisurf = NULL;
1418 struct ivisurface *next = NULL;
1419 uint32_t id_surface = 0;
1422 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1423 if (layout_surface != ivisurf->layout_surface) {
1427 wl_list_remove(&ivisurf->link);
1430 if (ivisurf->controller_surface_count == 0) {
1434 ivisurf->can_be_removed = 1;
1441 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1443 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1444 if (id_surface != ctrlsurf->id_surface) {
1447 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1453 surface_event_configure(struct ivi_layout_surface *layout_surface,
1456 struct ivishell *shell = userdata;
1457 struct ivisurface *ivisurf = NULL;
1458 struct ivicontroller_surface *ctrlsurf = NULL;
1459 struct ivi_layout_SurfaceProperties prop;
1460 uint32_t id_surface = 0;
1462 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1464 ivisurf = get_surface(&shell->list_surface, id_surface);
1465 if (ivisurf == NULL) {
1466 weston_log("id_surface is not created yet\n");
1470 memset(&prop, 0, sizeof prop);
1471 ivi_layout_getPropertiesOfSurface(layout_surface, &prop);
1473 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1474 if (id_surface != ctrlsurf->id_surface) {
1477 send_surface_event(ctrlsurf->resource, ivisurf,
1478 &prop, IVI_NOTIFICATION_ALL);
1483 check_layout_layers(struct ivishell *shell)
1485 struct ivi_layout_layer **pArray = NULL;
1486 struct ivilayer *ivilayer = NULL;
1487 uint32_t id_layer = 0;
1488 uint32_t length = 0;
1492 ret = ivi_layout_getLayers(&length, &pArray);
1494 weston_log("failed to get layers at check_layout_layers\n");
1499 /* if length is 0, pArray doesn't need to free.*/
1503 for (i = 0; i < length; i++) {
1504 id_layer = ivi_layout_getIdOfLayer(pArray[i]);
1505 ivilayer = create_layer(shell, pArray[i], id_layer);
1506 if (ivilayer == NULL) {
1507 weston_log("failed to create layer");
1518 check_layout_surfaces(struct ivishell *shell)
1520 struct ivi_layout_surface **pArray = NULL;
1521 struct ivisurface *ivisurf = NULL;
1522 uint32_t id_surface = 0;
1523 uint32_t length = 0;
1527 ret = ivi_layout_getSurfaces(&length, &pArray);
1529 weston_log("failed to get surfaces at check_layout_surfaces\n");
1534 /* if length is 0, pArray doesn't need to free.*/
1538 for (i = 0; i < length; i++) {
1539 id_surface = ivi_layout_getIdOfSurface(pArray[i]);
1540 ivisurf = create_surface(shell, pArray[i], id_surface);
1541 if (ivisurf == NULL) {
1542 weston_log("failed to create surface");
1553 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1555 struct weston_output *output = NULL;
1556 struct iviscreen *iviscrn = NULL;
1559 shell->compositor = ec;
1561 wl_list_init(&shell->list_surface);
1562 wl_list_init(&shell->list_layer);
1563 wl_list_init(&shell->list_screen);
1564 wl_list_init(&shell->list_weston_surface);
1565 wl_list_init(&shell->list_controller);
1566 wl_list_init(&shell->list_controller_screen);
1567 wl_list_init(&shell->list_controller_layer);
1568 wl_list_init(&shell->list_controller_surface);
1569 shell->event_restriction = 0;
1571 wl_list_for_each(output, &ec->output_list, link) {
1572 iviscrn = create_screen(shell, output);
1573 if (iviscrn != NULL) {
1574 wl_list_insert(&shell->list_screen, &iviscrn->link);
1578 ret = check_layout_layers(shell);
1580 weston_log("failed to check_layout_layers");
1583 ret = check_layout_surfaces(shell);
1585 weston_log("failed to check_layout_surfaces");
1588 ivi_layout_addNotificationCreateLayer(layer_event_create, shell);
1589 ivi_layout_addNotificationRemoveLayer(layer_event_remove, shell);
1591 ivi_layout_addNotificationCreateSurface(surface_event_create, shell);
1592 ivi_layout_addNotificationRemoveSurface(surface_event_remove, shell);
1593 ivi_layout_addNotificationConfigureSurface(surface_event_configure, shell);
1597 module_init(struct weston_compositor *ec,
1598 int *argc, char *argv[])
1600 struct ivishell *shell;
1604 shell = malloc(sizeof *shell);
1608 memset(shell, 0, sizeof *shell);
1609 init_ivi_shell(ec, shell);
1611 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
1612 shell, bind_ivi_controller) == NULL) {