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;
221 if ((ivilayer->layout_layer != NULL) &&
222 (ivilayer->controller_layer_count == 0) &&
223 (ivilayer->layer_canbe_removed == 1)) {
224 ivi_layout_layerRemove(ivilayer->layout_layer);
229 destroy_ivicontroller_screen(struct wl_resource *resource)
231 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
232 struct ivicontroller_screen *ctrlscrn = NULL;
233 struct ivicontroller_screen *next = NULL;
235 wl_list_for_each_safe(ctrlscrn, next,
236 &iviscrn->shell->list_controller_screen, link) {
237 // TODO : Only Single display
239 if (iviscrn->output->id != ctrlscrn->id_screen) {
244 if (resource != ctrlscrn->resource) {
248 wl_list_remove(&ctrlscrn->link);
256 unbind_resource_controller(struct wl_resource *resource)
258 struct ivicontroller *controller = wl_resource_get_user_data(resource);
260 wl_list_remove(&controller->link);
266 static struct ivisurface*
267 get_surface(struct wl_list *list_surf, uint32_t id_surface)
269 struct ivisurface *ivisurf = NULL;
270 uint32_t ivisurf_id = 0;
272 wl_list_for_each(ivisurf, list_surf, link) {
273 ivisurf_id = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
274 if (ivisurf_id == id_surface) {
282 static struct ivilayer*
283 get_layer(struct wl_list *list_layer, uint32_t id_layer)
285 struct ivilayer *ivilayer = NULL;
286 uint32_t ivilayer_id = 0;
288 wl_list_for_each(ivilayer, list_layer, link) {
289 ivilayer_id = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
290 if (ivilayer_id == id_layer) {
299 struct ivi_controller_screen_interface controller_screen_implementation;
301 static struct ivicontroller_screen*
302 controller_screen_create(struct ivishell *shell,
303 struct wl_client *client,
304 struct iviscreen *iviscrn)
306 struct ivicontroller_screen *ctrlscrn = NULL;
308 ctrlscrn = calloc(1, sizeof *ctrlscrn);
309 if (ctrlscrn == NULL) {
310 weston_log("no memory to allocate controller screen\n");
314 ctrlscrn->client = client;
315 ctrlscrn->shell = shell;
317 // TODO : Only Single display
319 /* ctrlscrn->id_screen = iviscrn->id_screen; */
321 ctrlscrn->id_screen = 0;
325 wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
326 if (ctrlscrn->resource == NULL) {
327 weston_log("couldn't new screen controller object");
335 wl_resource_set_implementation(ctrlscrn->resource,
336 &controller_screen_implementation,
337 iviscrn, destroy_ivicontroller_screen);
339 wl_list_init(&ctrlscrn->link);
340 wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
346 send_surface_add_event(struct ivisurface *ivisurf,
347 struct wl_resource *resource)
349 struct ivi_layout_layer **pArray = NULL;
353 struct link_layer *link_layer = NULL;
354 struct link_layer *next = NULL;
355 struct ivicontroller_layer *ctrllayer = NULL;
356 struct ivilayer *ivilayer = NULL;
357 struct ivishell *shell = ivisurf->shell;
358 uint32_t id_layout_layer = 0;
361 ans = ivi_layout_getLayersUnderSurface(ivisurf->layout_surface,
364 weston_log("failed to get layers at send_surface_add_event\n");
368 /* Send Null to cancel added surface */
369 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
370 for (i = 0, found = 0; i < (int)length; i++) {
371 if (pArray[i] == link_layer->layer->layout_layer) {
372 /* No need to send event, if new layer doesn't be added. */
381 ivi_controller_surface_send_layer(resource, NULL);
382 wl_list_remove(&link_layer->link);
387 for (i = 0; i < (int)length; i++) {
389 wl_list_for_each(link_layer, &ivisurf->list_layer, link) {
390 if (pArray[i] == link_layer->layer->layout_layer) {
391 /* No need to send event, if new layer doesn't be added. */
400 /* Create list_layer */
401 link_layer = calloc(1, sizeof(*link_layer));
402 if (NULL == link_layer) {
405 wl_list_init(&link_layer->link);
406 link_layer->layer = NULL;
407 wl_list_for_each(ivilayer, &shell->list_layer, link) {
408 if (ivilayer->layout_layer == pArray[i]) {
409 link_layer->layer = ivilayer;
414 if (link_layer->layer == NULL) {
419 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
421 /* Send new surface event */
423 ivi_layout_getIdOfLayer(link_layer->layer->layout_layer);
424 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
425 if (id_layout_layer != ctrllayer->id_layer) {
428 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
437 send_surface_event(struct wl_resource *resource,
438 struct ivisurface *ivisurf,
439 struct ivi_layout_SurfaceProperties *prop,
442 if (mask & IVI_NOTIFICATION_OPACITY) {
443 ivi_controller_surface_send_opacity(resource,
446 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
447 ivi_controller_surface_send_source_rectangle(resource,
448 prop->sourceX, prop->sourceY,
449 prop->sourceWidth, prop->sourceHeight);
451 if (mask & IVI_NOTIFICATION_DEST_RECT) {
452 ivi_controller_surface_send_destination_rectangle(resource,
453 prop->destX, prop->destY,
454 prop->destWidth, prop->destHeight);
456 if (mask & IVI_NOTIFICATION_ORIENTATION) {
457 ivi_controller_surface_send_orientation(resource,
460 if (mask & IVI_NOTIFICATION_VISIBILITY) {
461 ivi_controller_surface_send_visibility(resource,
464 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
465 ivi_controller_surface_send_pixelformat(resource,
468 if (mask & IVI_NOTIFICATION_ADD) {
469 send_surface_add_event(ivisurf, resource);
474 send_surface_prop(struct ivi_layout_surface *layout_surface,
475 struct ivi_layout_SurfaceProperties *prop,
476 enum ivi_layout_notification_mask mask,
479 struct ivisurface *ivisurf = userdata;
480 struct ivishell *shell = ivisurf->shell;
481 struct ivicontroller_surface *ctrlsurf = NULL;
482 uint32_t id_surface = 0;
484 id_surface = ivi_layout_getIdOfSurface(layout_surface);
486 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
487 if (id_surface != ctrlsurf->id_surface) {
490 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
495 send_layer_add_event(struct ivilayer *ivilayer,
496 struct wl_resource *resource)
498 struct ivi_layout_screen **pArray = NULL;
502 struct link_screen *link_scrn = NULL;
503 struct link_screen *next = NULL;
504 struct iviscreen *iviscrn = NULL;
505 struct ivishell *shell = ivilayer->shell;
507 struct wl_client *client = wl_resource_get_client(resource);
508 struct wl_resource *resource_output = NULL;
510 ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
513 weston_log("failed to get screens at send_layer_add_event\n");
517 /* Send Null to cancel added layer */
518 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
519 for (i = 0, found = 0; i < (int)length; i++) {
520 if (pArray[i] == link_scrn->screen->layout_screen) {
521 /* No need to send event, if new layer doesn't be added. */
530 ivi_controller_layer_send_screen(resource, NULL);
531 wl_list_remove(&link_scrn->link);
536 for (i = 0; i < (int)length; i++) {
538 wl_list_for_each(link_scrn, &ivilayer->list_screen, link) {
539 if (pArray[i] == link_scrn->screen->layout_screen) {
540 /* No need to send event, if new screen doesn't be added. */
549 /* Create list_screen */
550 link_scrn = calloc(1, sizeof(*link_scrn));
551 if (NULL == link_scrn) {
554 wl_list_init(&link_scrn->link);
555 link_scrn->screen = NULL;
556 wl_list_for_each(iviscrn, &shell->list_screen, link) {
557 if (iviscrn->layout_screen == pArray[i]) {
558 link_scrn->screen = iviscrn;
563 if (link_scrn->screen == NULL) {
568 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
570 /* Send new layer event */
572 wl_resource_find_for_client(&iviscrn->output->resource_list,
574 if (resource_output != NULL) {
575 ivi_controller_layer_send_screen(resource, resource_output);
584 send_layer_event(struct wl_resource *resource,
585 struct ivilayer *ivilayer,
586 struct ivi_layout_LayerProperties *prop,
589 if (mask & IVI_NOTIFICATION_OPACITY) {
590 ivi_controller_layer_send_opacity(resource,
593 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
594 ivi_controller_layer_send_source_rectangle(resource,
600 if (mask & IVI_NOTIFICATION_DEST_RECT) {
601 ivi_controller_layer_send_destination_rectangle(resource,
607 if (mask & IVI_NOTIFICATION_ORIENTATION) {
608 ivi_controller_layer_send_orientation(resource,
611 if (mask & IVI_NOTIFICATION_VISIBILITY) {
612 ivi_controller_layer_send_visibility(resource,
615 if (mask & IVI_NOTIFICATION_ADD) {
616 send_layer_add_event(ivilayer, resource);
618 if (mask & IVI_NOTIFICATION_REMOVE) {
619 send_layer_add_event(ivilayer, resource);
624 send_layer_prop(struct ivi_layout_layer *layer,
625 struct ivi_layout_LayerProperties *prop,
626 enum ivi_layout_notification_mask mask,
629 struct ivilayer *ivilayer = userdata;
630 struct ivicontroller_layer *ctrllayer = NULL;
631 struct ivishell *shell = ivilayer->shell;
632 uint32_t id_layout_layer = 0;
634 id_layout_layer = ivi_layout_getIdOfLayer(layer);
635 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
636 if (id_layout_layer != ctrllayer->id_layer) {
639 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
644 controller_surface_set_opacity(struct wl_client *client,
645 struct wl_resource *resource,
648 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
650 ivi_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
654 controller_surface_set_source_rectangle(struct wl_client *client,
655 struct wl_resource *resource,
661 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
663 ivi_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
664 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
668 controller_surface_set_destination_rectangle(struct wl_client *client,
669 struct wl_resource *resource,
675 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
677 ivi_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
678 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
682 controller_surface_set_visibility(struct wl_client *client,
683 struct wl_resource *resource,
686 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
688 ivi_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
692 controller_surface_set_configuration(struct wl_client *client,
693 struct wl_resource *resource,
694 int32_t width, int32_t height)
696 /* This interface has been supported yet. */
704 controller_surface_set_orientation(struct wl_client *client,
705 struct wl_resource *resource,
708 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
710 ivi_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
714 controller_surface_screenshot(struct wl_client *client,
715 struct wl_resource *resource,
716 const char *filename)
718 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
720 ivi_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
724 controller_surface_send_stats(struct wl_client *client,
725 struct wl_resource *resource)
727 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
731 wl_client_get_credentials(client, &pid, &uid, &gid);
733 ivi_controller_surface_send_stats(resource, 0, 0,
734 ivisurf->update_count, pid, "");
738 controller_surface_destroy(struct wl_client *client,
739 struct wl_resource *resource,
740 int32_t destroy_scene_object)
743 (void)destroy_scene_object;
744 wl_resource_destroy(resource);
748 controller_surface_set_input_focus(struct wl_client *client,
749 struct wl_resource *resource,
758 struct ivi_controller_surface_interface controller_surface_implementation = {
759 controller_surface_set_visibility,
760 controller_surface_set_opacity,
761 controller_surface_set_source_rectangle,
762 controller_surface_set_destination_rectangle,
763 controller_surface_set_configuration,
764 controller_surface_set_orientation,
765 controller_surface_screenshot,
766 controller_surface_send_stats,
767 controller_surface_destroy,
768 controller_surface_set_input_focus
772 controller_layer_set_source_rectangle(struct wl_client *client,
773 struct wl_resource *resource,
779 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
781 ivi_layout_layerSetSourceRectangle(ivilayer->layout_layer,
782 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
786 controller_layer_set_destination_rectangle(struct wl_client *client,
787 struct wl_resource *resource,
793 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
795 ivi_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
796 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
800 controller_layer_set_visibility(struct wl_client *client,
801 struct wl_resource *resource,
804 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
806 ivi_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
810 controller_layer_set_opacity(struct wl_client *client,
811 struct wl_resource *resource,
814 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
816 ivi_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
820 controller_layer_set_configuration(struct wl_client *client,
821 struct wl_resource *resource,
825 /* This interface has been supported yet. */
833 controller_layer_set_orientation(struct wl_client *client,
834 struct wl_resource *resource,
837 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
839 ivi_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
843 controller_layer_clear_surfaces(struct wl_client *client,
844 struct wl_resource *resource)
846 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
848 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
852 controller_layer_add_surface(struct wl_client *client,
853 struct wl_resource *resource,
854 struct wl_resource *surface)
856 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
857 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
859 ivi_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
863 controller_layer_remove_surface(struct wl_client *client,
864 struct wl_resource *resource,
865 struct wl_resource *surface)
867 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
868 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
870 ivi_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
874 controller_layer_screenshot(struct wl_client *client,
875 struct wl_resource *resource,
876 const char *filename)
884 controller_layer_set_render_order(struct wl_client *client,
885 struct wl_resource *resource,
886 struct wl_array *id_surfaces)
888 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
889 struct ivi_layout_surface **layoutsurf_array = NULL;
890 struct ivisurface *ivisurf = NULL;
891 uint32_t *id_surface = NULL;
892 uint32_t id_layout_surface = 0;
896 wl_array_for_each(id_surface, id_surfaces) {
897 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
898 id_layout_surface = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
899 if (*id_surface == id_layout_surface) {
900 layoutsurf_array[i] = ivisurf->layout_surface;
907 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer,
908 layoutsurf_array, id_surfaces->size);
909 free(layoutsurf_array);
913 controller_layer_destroy(struct wl_client *client,
914 struct wl_resource *resource,
915 int32_t destroy_scene_object)
917 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
918 struct ivishell *shell = ivilayer->shell;
919 struct ivicontroller_layer *ctrllayer = NULL;
920 struct ivicontroller_layer *next = NULL;
921 uint32_t id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
923 (void)destroy_scene_object;
925 ivilayer->layer_canbe_removed = 1;
926 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
927 if (ctrllayer->resource != resource) {
931 wl_resource_destroy(resource);
937 struct ivi_controller_layer_interface controller_layer_implementation = {
938 controller_layer_set_visibility,
939 controller_layer_set_opacity,
940 controller_layer_set_source_rectangle,
941 controller_layer_set_destination_rectangle,
942 controller_layer_set_configuration,
943 controller_layer_set_orientation,
944 controller_layer_screenshot,
945 controller_layer_clear_surfaces,
946 controller_layer_add_surface,
947 controller_layer_remove_surface,
948 controller_layer_set_render_order,
949 controller_layer_destroy
953 controller_screen_destroy(struct wl_client *client,
954 struct wl_resource *resource)
956 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
957 struct ivicontroller_screen *ctrlscrn = NULL;
958 struct ivicontroller_screen *next = NULL;
959 // uint32_t id_screen = ivi_layout_getIdOfScreen(iviscrn->layout_screen);
962 wl_list_for_each_safe(ctrlscrn, next,
963 &iviscrn->shell->list_controller_screen, link) {
964 if (resource != ctrlscrn->resource) {
968 wl_list_remove(&ctrlscrn->link);
971 wl_resource_destroy(ctrlscrn->resource);
977 controller_screen_clear(struct wl_client *client,
978 struct wl_resource *resource)
980 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
982 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
986 controller_screen_add_layer(struct wl_client *client,
987 struct wl_resource *resource,
988 struct wl_resource *layer)
990 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
991 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
993 ivi_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
997 controller_screen_screenshot(struct wl_client *client,
998 struct wl_resource *resource,
999 const char *filename)
1001 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1003 ivi_layout_takeScreenshot(iviscrn->layout_screen, filename);
1007 controller_screen_set_render_order(struct wl_client *client,
1008 struct wl_resource *resource,
1009 struct wl_array *id_layers)
1011 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1012 struct ivi_layout_layer **layoutlayer_array = NULL;
1013 struct ivilayer *ivilayer = NULL;
1014 uint32_t *id_layer = NULL;
1015 uint32_t id_layout_layer = 0;
1019 *layoutlayer_array = (struct ivi_layout_layer*)calloc(
1020 id_layers->size, sizeof(void*));
1022 wl_array_for_each(id_layer, id_layers) {
1023 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1024 id_layout_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1025 if (*id_layer == id_layout_layer) {
1026 layoutlayer_array[i] = ivilayer->layout_layer;
1033 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen,
1034 layoutlayer_array, id_layers->size);
1035 free(layoutlayer_array);
1039 struct ivi_controller_screen_interface controller_screen_implementation = {
1040 controller_screen_destroy,
1041 controller_screen_clear,
1042 controller_screen_add_layer,
1043 controller_screen_screenshot,
1044 controller_screen_set_render_order
1048 controller_commit_changes(struct wl_client *client,
1049 struct wl_resource *resource)
1055 ans = ivi_layout_commitChanges();
1057 weston_log("Failed to commit changes at controller_commit_changes\n");
1062 controller_layer_create(struct wl_client *client,
1063 struct wl_resource *resource,
1069 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1070 struct ivishell *shell = ctrl->shell;
1071 struct ivi_layout_layer *layout_layer = NULL;
1072 struct ivicontroller_layer *ctrllayer = NULL;
1073 struct ivilayer *ivilayer = NULL;
1074 struct ivi_layout_LayerProperties prop;
1076 ivilayer = get_layer(&shell->list_layer, id_layer);
1077 if (ivilayer == NULL) {
1078 layout_layer = ivi_layout_layerCreateWithDimension(id_layer,
1079 (uint32_t)width, (uint32_t)height);
1080 if (layout_layer == NULL) {
1081 weston_log("id_layer is already created\n");
1085 /* ivilayer will be created by layer_event_create */
1086 ivilayer = get_layer(&shell->list_layer, id_layer);
1087 if (ivilayer == NULL) {
1088 weston_log("couldn't get layer object\n");
1093 ctrllayer = calloc(1, sizeof *ctrllayer);
1095 weston_log("no memory to allocate client layer\n");
1099 ++ivilayer->controller_layer_count;
1100 ivilayer->layer_canbe_removed = 0;
1102 ctrllayer->shell = shell;
1103 ctrllayer->client = client;
1105 ctrllayer->id_layer = id_layer;
1106 ctrllayer->resource = wl_resource_create(client,
1107 &ivi_controller_layer_interface, 1, id);
1108 if (ctrllayer->resource == NULL) {
1109 weston_log("couldn't get layer object\n");
1113 wl_list_init(&ctrllayer->link);
1114 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1116 wl_resource_set_implementation(ctrllayer->resource,
1117 &controller_layer_implementation,
1118 ivilayer, destroy_ivicontroller_layer);
1120 memset(&prop, 0, sizeof prop);
1122 ivi_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1123 send_layer_event(ctrllayer->resource, ivilayer,
1124 &prop, IVI_NOTIFICATION_ALL);
1128 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1130 struct ivishell *shell = userdata;
1131 struct ivicontroller_surface *ctrlsurf = NULL;
1132 uint32_t id_surface = 0;
1135 surface_event_remove(layout_surface, userdata);
1140 controller_surface_create(struct wl_client *client,
1141 struct wl_resource *resource,
1142 uint32_t id_surface,
1145 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1146 struct ivishell *shell = ctrl->shell;
1147 struct ivicontroller_surface *ctrlsurf = NULL;
1148 struct ivi_layout_SurfaceProperties prop;
1149 struct ivisurface *ivisurf = NULL;
1151 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1153 weston_log("no memory to allocate controller surface\n");
1157 ctrlsurf->shell = shell;
1158 ctrlsurf->client = client;
1160 ctrlsurf->id_surface = id_surface;
1161 wl_list_init(&ctrlsurf->link);
1162 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1164 ctrlsurf->resource = wl_resource_create(client,
1165 &ivi_controller_surface_interface, 1, id);
1166 if (ctrlsurf->resource == NULL) {
1167 weston_log("couldn't surface object");
1171 ivisurf = get_surface(&shell->list_surface, id_surface);
1172 if (ivisurf == NULL) {
1176 ++ivisurf->controller_surface_count;
1178 wl_resource_set_implementation(ctrlsurf->resource,
1179 &controller_surface_implementation,
1180 ivisurf, destroy_ivicontroller_surface);
1182 memset(&prop, 0, sizeof prop);
1184 ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1185 ivi_layout_surfaceSetContentObserver(ivisurf->layout_surface, surface_event_content, shell);
1187 send_surface_event(ctrlsurf->resource, ivisurf,
1188 &prop, IVI_NOTIFICATION_ALL);
1191 static const struct ivi_controller_interface controller_implementation = {
1192 controller_commit_changes,
1193 controller_layer_create,
1194 controller_surface_create
1198 add_client_to_resources(struct ivishell *shell,
1199 struct wl_client *client,
1200 struct ivicontroller *controller)
1202 struct ivisurface* ivisurf = NULL;
1203 struct ivilayer* ivilayer = NULL;
1204 struct iviscreen* iviscrn = NULL;
1205 struct ivicontroller_screen *ctrlscrn = NULL;
1206 struct wl_resource *resource_output = NULL;
1207 uint32_t id_layout_surface = 0;
1208 uint32_t id_layout_layer = 0;
1210 wl_list_for_each(ivisurf, &shell->list_surface, link) {
1212 ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1214 ivi_controller_send_surface(controller->resource,
1218 wl_list_for_each(ivilayer, &shell->list_layer, link) {
1220 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1222 ivi_controller_send_layer(controller->resource,
1226 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1227 resource_output = wl_resource_find_for_client(
1228 &iviscrn->output->resource_list, client);
1229 if (resource_output == NULL) {
1233 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1234 if (ctrlscrn == NULL) {
1238 ivi_controller_send_screen(controller->resource,
1239 wl_resource_get_id(resource_output),
1240 ctrlscrn->resource);
1245 bind_ivi_controller(struct wl_client *client, void *data,
1246 uint32_t version, uint32_t id)
1248 struct ivishell *shell = data;
1249 struct ivicontroller *controller;
1252 controller = calloc(1, sizeof *controller);
1253 if (controller == NULL) {
1254 weston_log("no memory to allocate controller\n");
1258 controller->resource =
1259 wl_resource_create(client, &ivi_controller_interface, 1, id);
1260 wl_resource_set_implementation(controller->resource,
1261 &controller_implementation,
1262 controller, unbind_resource_controller);
1264 controller->shell = shell;
1265 controller->client = client;
1266 controller->id = id;
1268 wl_list_init(&controller->link);
1269 wl_list_insert(&shell->list_controller, &controller->link);
1271 add_client_to_resources(shell, client, controller);
1274 static struct iviscreen*
1275 create_screen(struct ivishell *shell, struct weston_output *output)
1277 struct iviscreen *iviscrn;
1278 iviscrn = calloc(1, sizeof *iviscrn);
1279 if (iviscrn == NULL) {
1280 weston_log("no memory to allocate client screen\n");
1284 iviscrn->shell = shell;
1285 iviscrn->output = output;
1287 // TODO : Only Single display
1288 iviscrn->layout_screen = ivi_layout_getScreenFromId(0);
1290 wl_list_init(&iviscrn->link);
1295 static struct ivilayer*
1296 create_layer(struct ivishell *shell,
1297 struct ivi_layout_layer *layout_layer,
1300 struct ivilayer *ivilayer = NULL;
1301 struct ivicontroller *controller = NULL;
1303 ivilayer = get_layer(&shell->list_layer, id_layer);
1304 if (ivilayer != NULL) {
1305 weston_log("id_layer is already created\n");
1309 ivilayer = calloc(1, sizeof *ivilayer);
1310 if (NULL == ivilayer) {
1311 weston_log("no memory to allocate client layer\n");
1315 ivilayer->shell = shell;
1316 wl_list_init(&ivilayer->list_screen);
1317 wl_list_init(&ivilayer->link);
1318 wl_list_insert(&shell->list_layer, &ivilayer->link);
1319 ivilayer->layout_layer = layout_layer;
1321 ivi_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1323 wl_list_for_each(controller, &shell->list_controller, link) {
1324 ivi_controller_send_layer(controller->resource, id_layer);
1330 static struct ivisurface*
1331 create_surface(struct ivishell *shell,
1332 struct ivi_layout_surface *layout_surface,
1333 uint32_t id_surface)
1335 struct ivisurface *ivisurf = NULL;
1336 struct ivicontroller *controller = NULL;
1338 ivisurf = get_surface(&shell->list_surface, id_surface);
1339 if (ivisurf != NULL) {
1340 weston_log("id_surface is already created\n");
1344 ivisurf = calloc(1, sizeof *ivisurf);
1345 if (ivisurf == NULL) {
1346 weston_log("no memory to allocate client surface\n");
1350 ivisurf->shell = shell;
1351 ivisurf->layout_surface = layout_surface;
1352 wl_list_init(&ivisurf->list_layer);
1353 wl_list_init(&ivisurf->link);
1354 wl_list_insert(&shell->list_surface, &ivisurf->link);
1356 wl_list_for_each(controller, &shell->list_controller, link) {
1357 ivi_controller_send_surface(controller->resource,
1361 ivi_layout_surfaceAddNotification(layout_surface,
1362 send_surface_prop, ivisurf);
1368 layer_event_create(struct ivi_layout_layer *layout_layer,
1371 struct ivishell *shell = userdata;
1372 struct ivilayer *ivilayer = NULL;
1373 uint32_t id_layer = 0;
1375 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1377 ivilayer = create_layer(shell, layout_layer, id_layer);
1378 if (ivilayer == NULL) {
1379 weston_log("failed to create layer");
1385 layer_event_remove(struct ivi_layout_layer *layout_layer,
1388 struct ivishell *shell = userdata;
1389 struct ivicontroller_layer *ctrllayer = NULL;
1390 struct ivilayer *ivilayer = NULL;
1391 struct ivilayer *next = NULL;
1392 uint32_t id_layer = 0;
1395 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1396 if (layout_layer != ivilayer->layout_layer) {
1400 wl_list_remove(&ivilayer->link);
1409 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1411 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1412 if (id_layer != ctrllayer->id_layer) {
1415 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1422 surface_event_create(struct ivi_layout_surface *layout_surface,
1425 struct ivishell *shell = userdata;
1426 struct ivisurface *ivisurf = NULL;
1427 uint32_t id_surface = 0;
1429 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1431 ivisurf = create_surface(shell, layout_surface, id_surface);
1432 if (ivisurf == NULL) {
1433 weston_log("failed to create surface");
1439 surface_event_remove(struct ivi_layout_surface *layout_surface,
1442 struct ivishell *shell = userdata;
1443 struct ivicontroller_surface *ctrlsurf = NULL;
1444 struct ivisurface *ivisurf = NULL;
1445 struct ivisurface *next = NULL;
1446 uint32_t id_surface = 0;
1449 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1450 if (layout_surface != ivisurf->layout_surface) {
1454 wl_list_remove(&ivisurf->link);
1457 if (ivisurf->controller_surface_count == 0) {
1461 ivisurf->can_be_removed = 1;
1468 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1470 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1471 if (id_surface != ctrlsurf->id_surface) {
1474 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1480 surface_event_configure(struct ivi_layout_surface *layout_surface,
1483 struct ivishell *shell = userdata;
1484 struct ivisurface *ivisurf = NULL;
1485 struct ivicontroller_surface *ctrlsurf = NULL;
1486 struct ivi_layout_SurfaceProperties prop;
1487 uint32_t id_surface = 0;
1489 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1491 ivisurf = get_surface(&shell->list_surface, id_surface);
1492 if (ivisurf == NULL) {
1493 weston_log("id_surface is not created yet\n");
1497 memset(&prop, 0, sizeof prop);
1498 ivi_layout_getPropertiesOfSurface(layout_surface, &prop);
1500 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1501 if (id_surface != ctrlsurf->id_surface) {
1504 send_surface_event(ctrlsurf->resource, ivisurf,
1505 &prop, IVI_NOTIFICATION_ALL);
1510 check_layout_layers(struct ivishell *shell)
1512 struct ivi_layout_layer **pArray = NULL;
1513 struct ivilayer *ivilayer = NULL;
1514 uint32_t id_layer = 0;
1515 uint32_t length = 0;
1519 ret = ivi_layout_getLayers(&length, &pArray);
1521 weston_log("failed to get layers at check_layout_layers\n");
1526 /* if length is 0, pArray doesn't need to free.*/
1530 for (i = 0; i < length; i++) {
1531 id_layer = ivi_layout_getIdOfLayer(pArray[i]);
1532 ivilayer = create_layer(shell, pArray[i], id_layer);
1533 if (ivilayer == NULL) {
1534 weston_log("failed to create layer");
1545 check_layout_surfaces(struct ivishell *shell)
1547 struct ivi_layout_surface **pArray = NULL;
1548 struct ivisurface *ivisurf = NULL;
1549 uint32_t id_surface = 0;
1550 uint32_t length = 0;
1554 ret = ivi_layout_getSurfaces(&length, &pArray);
1556 weston_log("failed to get surfaces at check_layout_surfaces\n");
1561 /* if length is 0, pArray doesn't need to free.*/
1565 for (i = 0; i < length; i++) {
1566 id_surface = ivi_layout_getIdOfSurface(pArray[i]);
1567 ivisurf = create_surface(shell, pArray[i], id_surface);
1568 if (ivisurf == NULL) {
1569 weston_log("failed to create surface");
1580 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1582 struct weston_output *output = NULL;
1583 struct iviscreen *iviscrn = NULL;
1586 shell->compositor = ec;
1588 wl_list_init(&shell->list_surface);
1589 wl_list_init(&shell->list_layer);
1590 wl_list_init(&shell->list_screen);
1591 wl_list_init(&shell->list_weston_surface);
1592 wl_list_init(&shell->list_controller);
1593 wl_list_init(&shell->list_controller_screen);
1594 wl_list_init(&shell->list_controller_layer);
1595 wl_list_init(&shell->list_controller_surface);
1596 shell->event_restriction = 0;
1598 wl_list_for_each(output, &ec->output_list, link) {
1599 iviscrn = create_screen(shell, output);
1600 if (iviscrn != NULL) {
1601 wl_list_insert(&shell->list_screen, &iviscrn->link);
1605 ret = check_layout_layers(shell);
1607 weston_log("failed to check_layout_layers");
1610 ret = check_layout_surfaces(shell);
1612 weston_log("failed to check_layout_surfaces");
1615 ivi_layout_addNotificationCreateLayer(layer_event_create, shell);
1616 ivi_layout_addNotificationRemoveLayer(layer_event_remove, shell);
1618 ivi_layout_addNotificationCreateSurface(surface_event_create, shell);
1619 ivi_layout_addNotificationRemoveSurface(surface_event_remove, shell);
1620 ivi_layout_addNotificationConfigureSurface(surface_event_configure, shell);
1624 module_init(struct weston_compositor *ec,
1625 int *argc, char *argv[])
1627 struct ivishell *shell;
1631 shell = malloc(sizeof *shell);
1635 memset(shell, 0, sizeof *shell);
1636 init_ivi_shell(ec, shell);
1638 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
1639 shell, bind_ivi_controller) == NULL) {