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 if (resource != ctrllayer->resource) {
431 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
440 send_surface_event(struct wl_resource *resource,
441 struct ivisurface *ivisurf,
442 struct ivi_layout_SurfaceProperties *prop,
445 if (mask & IVI_NOTIFICATION_OPACITY) {
446 ivi_controller_surface_send_opacity(resource,
449 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
450 ivi_controller_surface_send_source_rectangle(resource,
451 prop->sourceX, prop->sourceY,
452 prop->sourceWidth, prop->sourceHeight);
454 if (mask & IVI_NOTIFICATION_DEST_RECT) {
455 ivi_controller_surface_send_destination_rectangle(resource,
456 prop->destX, prop->destY,
457 prop->destWidth, prop->destHeight);
459 if (mask & IVI_NOTIFICATION_ORIENTATION) {
460 ivi_controller_surface_send_orientation(resource,
463 if (mask & IVI_NOTIFICATION_VISIBILITY) {
464 ivi_controller_surface_send_visibility(resource,
467 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
468 ivi_controller_surface_send_pixelformat(resource,
471 if (mask & IVI_NOTIFICATION_ADD) {
472 send_surface_add_event(ivisurf, resource);
477 send_surface_prop(struct ivi_layout_surface *layout_surface,
478 struct ivi_layout_SurfaceProperties *prop,
479 enum ivi_layout_notification_mask mask,
482 struct ivisurface *ivisurf = userdata;
483 struct ivishell *shell = ivisurf->shell;
484 struct ivicontroller_surface *ctrlsurf = NULL;
485 uint32_t id_surface = 0;
487 id_surface = ivi_layout_getIdOfSurface(layout_surface);
489 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
490 if (id_surface != ctrlsurf->id_surface) {
493 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
498 send_layer_add_event(struct ivilayer *ivilayer,
499 struct wl_resource *resource)
501 struct ivi_layout_screen **pArray = NULL;
505 struct link_screen *link_scrn = NULL;
506 struct link_screen *next = NULL;
507 struct iviscreen *iviscrn = NULL;
508 struct ivishell *shell = ivilayer->shell;
510 struct wl_client *client = wl_resource_get_client(resource);
511 struct wl_resource *resource_output = NULL;
513 ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
516 weston_log("failed to get screens at send_layer_add_event\n");
520 /* Send Null to cancel added layer */
521 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
522 for (i = 0, found = 0; i < (int)length; i++) {
523 if (pArray[i] == link_scrn->screen->layout_screen) {
524 /* No need to send event, if new layer doesn't be added. */
533 ivi_controller_layer_send_screen(resource, NULL);
534 wl_list_remove(&link_scrn->link);
539 for (i = 0; i < (int)length; i++) {
541 wl_list_for_each(link_scrn, &ivilayer->list_screen, link) {
542 if (pArray[i] == link_scrn->screen->layout_screen) {
543 /* No need to send event, if new screen doesn't be added. */
552 /* Create list_screen */
553 link_scrn = calloc(1, sizeof(*link_scrn));
554 if (NULL == link_scrn) {
557 wl_list_init(&link_scrn->link);
558 link_scrn->screen = NULL;
559 wl_list_for_each(iviscrn, &shell->list_screen, link) {
560 if (iviscrn->layout_screen == pArray[i]) {
561 link_scrn->screen = iviscrn;
566 if (link_scrn->screen == NULL) {
571 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
573 /* Send new layer event */
575 wl_resource_find_for_client(&iviscrn->output->resource_list,
577 if (resource_output != NULL) {
578 ivi_controller_layer_send_screen(resource, resource_output);
587 send_layer_event(struct wl_resource *resource,
588 struct ivilayer *ivilayer,
589 struct ivi_layout_LayerProperties *prop,
592 if (mask & IVI_NOTIFICATION_OPACITY) {
593 ivi_controller_layer_send_opacity(resource,
596 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
597 ivi_controller_layer_send_source_rectangle(resource,
603 if (mask & IVI_NOTIFICATION_DEST_RECT) {
604 ivi_controller_layer_send_destination_rectangle(resource,
610 if (mask & IVI_NOTIFICATION_ORIENTATION) {
611 ivi_controller_layer_send_orientation(resource,
614 if (mask & IVI_NOTIFICATION_VISIBILITY) {
615 ivi_controller_layer_send_visibility(resource,
618 if (mask & IVI_NOTIFICATION_ADD) {
619 send_layer_add_event(ivilayer, resource);
621 if (mask & IVI_NOTIFICATION_REMOVE) {
622 send_layer_add_event(ivilayer, resource);
627 send_layer_prop(struct ivi_layout_layer *layer,
628 struct ivi_layout_LayerProperties *prop,
629 enum ivi_layout_notification_mask mask,
632 struct ivilayer *ivilayer = userdata;
633 struct ivicontroller_layer *ctrllayer = NULL;
634 struct ivishell *shell = ivilayer->shell;
635 uint32_t id_layout_layer = 0;
637 id_layout_layer = ivi_layout_getIdOfLayer(layer);
638 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
639 if (id_layout_layer != ctrllayer->id_layer) {
642 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
647 controller_surface_set_opacity(struct wl_client *client,
648 struct wl_resource *resource,
651 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
653 ivi_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
657 controller_surface_set_source_rectangle(struct wl_client *client,
658 struct wl_resource *resource,
664 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
666 ivi_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
667 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
671 controller_surface_set_destination_rectangle(struct wl_client *client,
672 struct wl_resource *resource,
678 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
680 ivi_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
681 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
685 controller_surface_set_visibility(struct wl_client *client,
686 struct wl_resource *resource,
689 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
691 ivi_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
695 controller_surface_set_configuration(struct wl_client *client,
696 struct wl_resource *resource,
697 int32_t width, int32_t height)
699 /* This interface has been supported yet. */
707 controller_surface_set_orientation(struct wl_client *client,
708 struct wl_resource *resource,
711 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
713 ivi_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
717 controller_surface_screenshot(struct wl_client *client,
718 struct wl_resource *resource,
719 const char *filename)
721 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
723 ivi_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
727 controller_surface_send_stats(struct wl_client *client,
728 struct wl_resource *resource)
730 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
734 wl_client_get_credentials(client, &pid, &uid, &gid);
736 ivi_controller_surface_send_stats(resource, 0, 0,
737 ivisurf->update_count, pid, "");
741 controller_surface_destroy(struct wl_client *client,
742 struct wl_resource *resource,
743 int32_t destroy_scene_object)
746 (void)destroy_scene_object;
747 wl_resource_destroy(resource);
751 controller_surface_set_input_focus(struct wl_client *client,
752 struct wl_resource *resource,
761 struct ivi_controller_surface_interface controller_surface_implementation = {
762 controller_surface_set_visibility,
763 controller_surface_set_opacity,
764 controller_surface_set_source_rectangle,
765 controller_surface_set_destination_rectangle,
766 controller_surface_set_configuration,
767 controller_surface_set_orientation,
768 controller_surface_screenshot,
769 controller_surface_send_stats,
770 controller_surface_destroy,
771 controller_surface_set_input_focus
775 controller_layer_set_source_rectangle(struct wl_client *client,
776 struct wl_resource *resource,
782 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
784 ivi_layout_layerSetSourceRectangle(ivilayer->layout_layer,
785 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
789 controller_layer_set_destination_rectangle(struct wl_client *client,
790 struct wl_resource *resource,
796 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
798 ivi_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
799 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
803 controller_layer_set_visibility(struct wl_client *client,
804 struct wl_resource *resource,
807 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
809 ivi_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
813 controller_layer_set_opacity(struct wl_client *client,
814 struct wl_resource *resource,
817 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
819 ivi_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
823 controller_layer_set_configuration(struct wl_client *client,
824 struct wl_resource *resource,
828 /* This interface has been supported yet. */
836 controller_layer_set_orientation(struct wl_client *client,
837 struct wl_resource *resource,
840 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
842 ivi_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
846 controller_layer_clear_surfaces(struct wl_client *client,
847 struct wl_resource *resource)
849 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
851 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
855 controller_layer_add_surface(struct wl_client *client,
856 struct wl_resource *resource,
857 struct wl_resource *surface)
859 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
860 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
862 ivi_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
866 controller_layer_remove_surface(struct wl_client *client,
867 struct wl_resource *resource,
868 struct wl_resource *surface)
870 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
871 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
873 ivi_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
877 controller_layer_screenshot(struct wl_client *client,
878 struct wl_resource *resource,
879 const char *filename)
887 controller_layer_set_render_order(struct wl_client *client,
888 struct wl_resource *resource,
889 struct wl_array *id_surfaces)
891 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
892 struct ivi_layout_surface **layoutsurf_array = NULL;
893 struct ivisurface *ivisurf = NULL;
894 uint32_t *id_surface = NULL;
895 uint32_t id_layout_surface = 0;
899 wl_array_for_each(id_surface, id_surfaces) {
900 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
901 id_layout_surface = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
902 if (*id_surface == id_layout_surface) {
903 layoutsurf_array[i] = ivisurf->layout_surface;
910 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer,
911 layoutsurf_array, id_surfaces->size);
912 free(layoutsurf_array);
916 controller_layer_destroy(struct wl_client *client,
917 struct wl_resource *resource,
918 int32_t destroy_scene_object)
920 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
921 struct ivishell *shell = ivilayer->shell;
922 struct ivicontroller_layer *ctrllayer = NULL;
923 struct ivicontroller_layer *next = NULL;
924 uint32_t id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
926 (void)destroy_scene_object;
928 ivilayer->layer_canbe_removed = 1;
929 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
930 if (ctrllayer->resource != resource) {
934 wl_resource_destroy(resource);
940 struct ivi_controller_layer_interface controller_layer_implementation = {
941 controller_layer_set_visibility,
942 controller_layer_set_opacity,
943 controller_layer_set_source_rectangle,
944 controller_layer_set_destination_rectangle,
945 controller_layer_set_configuration,
946 controller_layer_set_orientation,
947 controller_layer_screenshot,
948 controller_layer_clear_surfaces,
949 controller_layer_add_surface,
950 controller_layer_remove_surface,
951 controller_layer_set_render_order,
952 controller_layer_destroy
956 controller_screen_destroy(struct wl_client *client,
957 struct wl_resource *resource)
959 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
960 struct ivicontroller_screen *ctrlscrn = NULL;
961 struct ivicontroller_screen *next = NULL;
962 // uint32_t id_screen = ivi_layout_getIdOfScreen(iviscrn->layout_screen);
965 wl_list_for_each_safe(ctrlscrn, next,
966 &iviscrn->shell->list_controller_screen, link) {
967 if (resource != ctrlscrn->resource) {
971 wl_list_remove(&ctrlscrn->link);
974 wl_resource_destroy(ctrlscrn->resource);
980 controller_screen_clear(struct wl_client *client,
981 struct wl_resource *resource)
983 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
985 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
989 controller_screen_add_layer(struct wl_client *client,
990 struct wl_resource *resource,
991 struct wl_resource *layer)
993 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
994 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
996 ivi_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
1000 controller_screen_screenshot(struct wl_client *client,
1001 struct wl_resource *resource,
1002 const char *filename)
1004 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1006 ivi_layout_takeScreenshot(iviscrn->layout_screen, filename);
1010 controller_screen_set_render_order(struct wl_client *client,
1011 struct wl_resource *resource,
1012 struct wl_array *id_layers)
1014 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1015 struct ivi_layout_layer **layoutlayer_array = NULL;
1016 struct ivilayer *ivilayer = NULL;
1017 uint32_t *id_layer = NULL;
1018 uint32_t id_layout_layer = 0;
1022 *layoutlayer_array = (struct ivi_layout_layer*)calloc(
1023 id_layers->size, sizeof(void*));
1025 wl_array_for_each(id_layer, id_layers) {
1026 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1027 id_layout_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1028 if (*id_layer == id_layout_layer) {
1029 layoutlayer_array[i] = ivilayer->layout_layer;
1036 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen,
1037 layoutlayer_array, id_layers->size);
1038 free(layoutlayer_array);
1042 struct ivi_controller_screen_interface controller_screen_implementation = {
1043 controller_screen_destroy,
1044 controller_screen_clear,
1045 controller_screen_add_layer,
1046 controller_screen_screenshot,
1047 controller_screen_set_render_order
1051 controller_commit_changes(struct wl_client *client,
1052 struct wl_resource *resource)
1058 ans = ivi_layout_commitChanges();
1060 weston_log("Failed to commit changes at controller_commit_changes\n");
1065 controller_layer_create(struct wl_client *client,
1066 struct wl_resource *resource,
1072 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1073 struct ivishell *shell = ctrl->shell;
1074 struct ivi_layout_layer *layout_layer = NULL;
1075 struct ivicontroller_layer *ctrllayer = NULL;
1076 struct ivilayer *ivilayer = NULL;
1077 struct ivi_layout_LayerProperties prop;
1079 ivilayer = get_layer(&shell->list_layer, id_layer);
1080 if (ivilayer == NULL) {
1081 layout_layer = ivi_layout_layerCreateWithDimension(id_layer,
1082 (uint32_t)width, (uint32_t)height);
1083 if (layout_layer == NULL) {
1084 weston_log("id_layer is already created\n");
1088 /* ivilayer will be created by layer_event_create */
1089 ivilayer = get_layer(&shell->list_layer, id_layer);
1090 if (ivilayer == NULL) {
1091 weston_log("couldn't get layer object\n");
1096 ctrllayer = calloc(1, sizeof *ctrllayer);
1098 weston_log("no memory to allocate client layer\n");
1102 ++ivilayer->controller_layer_count;
1103 ivilayer->layer_canbe_removed = 0;
1105 ctrllayer->shell = shell;
1106 ctrllayer->client = client;
1108 ctrllayer->id_layer = id_layer;
1109 ctrllayer->resource = wl_resource_create(client,
1110 &ivi_controller_layer_interface, 1, id);
1111 if (ctrllayer->resource == NULL) {
1112 weston_log("couldn't get layer object\n");
1116 wl_list_init(&ctrllayer->link);
1117 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1119 wl_resource_set_implementation(ctrllayer->resource,
1120 &controller_layer_implementation,
1121 ivilayer, destroy_ivicontroller_layer);
1123 memset(&prop, 0, sizeof prop);
1125 ivi_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1126 send_layer_event(ctrllayer->resource, ivilayer,
1127 &prop, IVI_NOTIFICATION_ALL);
1131 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1133 struct ivishell *shell = userdata;
1134 struct ivicontroller_surface *ctrlsurf = NULL;
1135 uint32_t id_surface = 0;
1138 surface_event_remove(layout_surface, userdata);
1143 controller_surface_create(struct wl_client *client,
1144 struct wl_resource *resource,
1145 uint32_t id_surface,
1148 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1149 struct ivishell *shell = ctrl->shell;
1150 struct ivicontroller_surface *ctrlsurf = NULL;
1151 struct ivi_layout_SurfaceProperties prop;
1152 struct ivisurface *ivisurf = NULL;
1154 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1156 weston_log("no memory to allocate controller surface\n");
1160 ctrlsurf->shell = shell;
1161 ctrlsurf->client = client;
1163 ctrlsurf->id_surface = id_surface;
1164 wl_list_init(&ctrlsurf->link);
1165 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1167 ctrlsurf->resource = wl_resource_create(client,
1168 &ivi_controller_surface_interface, 1, id);
1169 if (ctrlsurf->resource == NULL) {
1170 weston_log("couldn't surface object");
1174 ivisurf = get_surface(&shell->list_surface, id_surface);
1175 if (ivisurf == NULL) {
1179 ++ivisurf->controller_surface_count;
1181 wl_resource_set_implementation(ctrlsurf->resource,
1182 &controller_surface_implementation,
1183 ivisurf, destroy_ivicontroller_surface);
1185 memset(&prop, 0, sizeof prop);
1187 ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1188 ivi_layout_surfaceSetContentObserver(ivisurf->layout_surface, surface_event_content, shell);
1190 send_surface_event(ctrlsurf->resource, ivisurf,
1191 &prop, IVI_NOTIFICATION_ALL);
1194 static const struct ivi_controller_interface controller_implementation = {
1195 controller_commit_changes,
1196 controller_layer_create,
1197 controller_surface_create
1201 add_client_to_resources(struct ivishell *shell,
1202 struct wl_client *client,
1203 struct ivicontroller *controller)
1205 struct ivisurface* ivisurf = NULL;
1206 struct ivilayer* ivilayer = NULL;
1207 struct iviscreen* iviscrn = NULL;
1208 struct ivicontroller_screen *ctrlscrn = NULL;
1209 struct wl_resource *resource_output = NULL;
1210 uint32_t id_layout_surface = 0;
1211 uint32_t id_layout_layer = 0;
1213 wl_list_for_each(ivisurf, &shell->list_surface, link) {
1215 ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1217 ivi_controller_send_surface(controller->resource,
1221 wl_list_for_each(ivilayer, &shell->list_layer, link) {
1223 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1225 ivi_controller_send_layer(controller->resource,
1229 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1230 resource_output = wl_resource_find_for_client(
1231 &iviscrn->output->resource_list, client);
1232 if (resource_output == NULL) {
1236 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1237 if (ctrlscrn == NULL) {
1241 ivi_controller_send_screen(controller->resource,
1242 wl_resource_get_id(resource_output),
1243 ctrlscrn->resource);
1248 bind_ivi_controller(struct wl_client *client, void *data,
1249 uint32_t version, uint32_t id)
1251 struct ivishell *shell = data;
1252 struct ivicontroller *controller;
1255 controller = calloc(1, sizeof *controller);
1256 if (controller == NULL) {
1257 weston_log("no memory to allocate controller\n");
1261 controller->resource =
1262 wl_resource_create(client, &ivi_controller_interface, 1, id);
1263 wl_resource_set_implementation(controller->resource,
1264 &controller_implementation,
1265 controller, unbind_resource_controller);
1267 controller->shell = shell;
1268 controller->client = client;
1269 controller->id = id;
1271 wl_list_init(&controller->link);
1272 wl_list_insert(&shell->list_controller, &controller->link);
1274 add_client_to_resources(shell, client, controller);
1277 static struct iviscreen*
1278 create_screen(struct ivishell *shell, struct weston_output *output)
1280 struct iviscreen *iviscrn;
1281 iviscrn = calloc(1, sizeof *iviscrn);
1282 if (iviscrn == NULL) {
1283 weston_log("no memory to allocate client screen\n");
1287 iviscrn->shell = shell;
1288 iviscrn->output = output;
1290 // TODO : Only Single display
1291 iviscrn->layout_screen = ivi_layout_getScreenFromId(0);
1293 wl_list_init(&iviscrn->link);
1298 static struct ivilayer*
1299 create_layer(struct ivishell *shell,
1300 struct ivi_layout_layer *layout_layer,
1303 struct ivilayer *ivilayer = NULL;
1304 struct ivicontroller *controller = NULL;
1306 ivilayer = get_layer(&shell->list_layer, id_layer);
1307 if (ivilayer != NULL) {
1308 weston_log("id_layer is already created\n");
1312 ivilayer = calloc(1, sizeof *ivilayer);
1313 if (NULL == ivilayer) {
1314 weston_log("no memory to allocate client layer\n");
1318 ivilayer->shell = shell;
1319 wl_list_init(&ivilayer->list_screen);
1320 wl_list_init(&ivilayer->link);
1321 wl_list_insert(&shell->list_layer, &ivilayer->link);
1322 ivilayer->layout_layer = layout_layer;
1324 ivi_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1326 wl_list_for_each(controller, &shell->list_controller, link) {
1327 ivi_controller_send_layer(controller->resource, id_layer);
1333 static struct ivisurface*
1334 create_surface(struct ivishell *shell,
1335 struct ivi_layout_surface *layout_surface,
1336 uint32_t id_surface)
1338 struct ivisurface *ivisurf = NULL;
1339 struct ivicontroller *controller = NULL;
1341 ivisurf = get_surface(&shell->list_surface, id_surface);
1342 if (ivisurf != NULL) {
1343 weston_log("id_surface is already created\n");
1347 ivisurf = calloc(1, sizeof *ivisurf);
1348 if (ivisurf == NULL) {
1349 weston_log("no memory to allocate client surface\n");
1353 ivisurf->shell = shell;
1354 ivisurf->layout_surface = layout_surface;
1355 wl_list_init(&ivisurf->list_layer);
1356 wl_list_init(&ivisurf->link);
1357 wl_list_insert(&shell->list_surface, &ivisurf->link);
1359 wl_list_for_each(controller, &shell->list_controller, link) {
1360 ivi_controller_send_surface(controller->resource,
1364 ivi_layout_surfaceAddNotification(layout_surface,
1365 send_surface_prop, ivisurf);
1371 layer_event_create(struct ivi_layout_layer *layout_layer,
1374 struct ivishell *shell = userdata;
1375 struct ivilayer *ivilayer = NULL;
1376 uint32_t id_layer = 0;
1378 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1380 ivilayer = create_layer(shell, layout_layer, id_layer);
1381 if (ivilayer == NULL) {
1382 weston_log("failed to create layer");
1388 layer_event_remove(struct ivi_layout_layer *layout_layer,
1391 struct ivishell *shell = userdata;
1392 struct ivicontroller_layer *ctrllayer = NULL;
1393 struct ivilayer *ivilayer = NULL;
1394 struct ivilayer *next = NULL;
1395 uint32_t id_layer = 0;
1398 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1399 if (layout_layer != ivilayer->layout_layer) {
1403 wl_list_remove(&ivilayer->link);
1412 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1414 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1415 if (id_layer != ctrllayer->id_layer) {
1418 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1425 surface_event_create(struct ivi_layout_surface *layout_surface,
1428 struct ivishell *shell = userdata;
1429 struct ivisurface *ivisurf = NULL;
1430 uint32_t id_surface = 0;
1432 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1434 ivisurf = create_surface(shell, layout_surface, id_surface);
1435 if (ivisurf == NULL) {
1436 weston_log("failed to create surface");
1442 surface_event_remove(struct ivi_layout_surface *layout_surface,
1445 struct ivishell *shell = userdata;
1446 struct ivicontroller_surface *ctrlsurf = NULL;
1447 struct ivisurface *ivisurf = NULL;
1448 struct ivisurface *next = NULL;
1449 uint32_t id_surface = 0;
1452 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1453 if (layout_surface != ivisurf->layout_surface) {
1457 wl_list_remove(&ivisurf->link);
1460 if (ivisurf->controller_surface_count == 0) {
1464 ivisurf->can_be_removed = 1;
1471 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1473 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1474 if (id_surface != ctrlsurf->id_surface) {
1477 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1483 surface_event_configure(struct ivi_layout_surface *layout_surface,
1486 struct ivishell *shell = userdata;
1487 struct ivisurface *ivisurf = NULL;
1488 struct ivicontroller_surface *ctrlsurf = NULL;
1489 struct ivi_layout_SurfaceProperties prop;
1490 uint32_t id_surface = 0;
1492 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1494 ivisurf = get_surface(&shell->list_surface, id_surface);
1495 if (ivisurf == NULL) {
1496 weston_log("id_surface is not created yet\n");
1500 memset(&prop, 0, sizeof prop);
1501 ivi_layout_getPropertiesOfSurface(layout_surface, &prop);
1503 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1504 if (id_surface != ctrlsurf->id_surface) {
1507 send_surface_event(ctrlsurf->resource, ivisurf,
1508 &prop, IVI_NOTIFICATION_ALL);
1513 check_layout_layers(struct ivishell *shell)
1515 struct ivi_layout_layer **pArray = NULL;
1516 struct ivilayer *ivilayer = NULL;
1517 uint32_t id_layer = 0;
1518 uint32_t length = 0;
1522 ret = ivi_layout_getLayers(&length, &pArray);
1524 weston_log("failed to get layers at check_layout_layers\n");
1529 /* if length is 0, pArray doesn't need to free.*/
1533 for (i = 0; i < length; i++) {
1534 id_layer = ivi_layout_getIdOfLayer(pArray[i]);
1535 ivilayer = create_layer(shell, pArray[i], id_layer);
1536 if (ivilayer == NULL) {
1537 weston_log("failed to create layer");
1548 check_layout_surfaces(struct ivishell *shell)
1550 struct ivi_layout_surface **pArray = NULL;
1551 struct ivisurface *ivisurf = NULL;
1552 uint32_t id_surface = 0;
1553 uint32_t length = 0;
1557 ret = ivi_layout_getSurfaces(&length, &pArray);
1559 weston_log("failed to get surfaces at check_layout_surfaces\n");
1564 /* if length is 0, pArray doesn't need to free.*/
1568 for (i = 0; i < length; i++) {
1569 id_surface = ivi_layout_getIdOfSurface(pArray[i]);
1570 ivisurf = create_surface(shell, pArray[i], id_surface);
1571 if (ivisurf == NULL) {
1572 weston_log("failed to create surface");
1583 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1585 struct weston_output *output = NULL;
1586 struct iviscreen *iviscrn = NULL;
1589 shell->compositor = ec;
1591 wl_list_init(&shell->list_surface);
1592 wl_list_init(&shell->list_layer);
1593 wl_list_init(&shell->list_screen);
1594 wl_list_init(&shell->list_weston_surface);
1595 wl_list_init(&shell->list_controller);
1596 wl_list_init(&shell->list_controller_screen);
1597 wl_list_init(&shell->list_controller_layer);
1598 wl_list_init(&shell->list_controller_surface);
1599 shell->event_restriction = 0;
1601 wl_list_for_each(output, &ec->output_list, link) {
1602 iviscrn = create_screen(shell, output);
1603 if (iviscrn != NULL) {
1604 wl_list_insert(&shell->list_screen, &iviscrn->link);
1608 ret = check_layout_layers(shell);
1610 weston_log("failed to check_layout_layers");
1613 ret = check_layout_surfaces(shell);
1615 weston_log("failed to check_layout_surfaces");
1618 ivi_layout_addNotificationCreateLayer(layer_event_create, shell);
1619 ivi_layout_addNotificationRemoveLayer(layer_event_remove, shell);
1621 ivi_layout_addNotificationCreateSurface(surface_event_create, shell);
1622 ivi_layout_addNotificationRemoveSurface(surface_event_remove, shell);
1623 ivi_layout_addNotificationConfigureSurface(surface_event_configure, shell);
1627 module_init(struct weston_compositor *ec,
1628 int *argc, char *argv[])
1630 struct ivishell *shell;
1634 shell = malloc(sizeof *shell);
1638 memset(shell, 0, sizeof *shell);
1639 init_ivi_shell(ec, shell);
1641 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
1642 shell, bind_ivi_controller) == NULL) {