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 "weston/weston-layout.h"
34 #include "weston/ivi-shell-ext.h"
41 struct ivilayer *layer;
46 struct iviscreen *screen;
52 struct wl_client *client;
53 struct ivishell *shell;
54 uint32_t update_count;
55 struct weston_layout_surface *layout_surface;
56 struct wl_listener surface_destroy_listener;
57 struct wl_list list_layer;
62 struct ivishell *shell;
63 struct weston_layout_layer *layout_layer;
64 struct wl_list list_screen;
69 struct ivishell *shell;
70 struct weston_layout_screen *layout_screen;
71 struct weston_output *output;
74 struct ivicontroller_surface {
75 struct wl_resource *resource;
78 struct wl_client *client;
80 struct ivishell *shell;
83 struct ivicontroller_layer {
84 struct wl_resource *resource;
87 struct wl_client *client;
89 struct ivishell *shell;
92 struct ivicontroller_screen {
93 struct wl_resource *resource;
96 struct wl_client *client;
98 struct ivishell *shell;
101 struct ivicontroller {
102 struct wl_resource *resource;
104 struct wl_client *client;
106 struct ivishell *shell;
109 struct link_shell_weston_surface
111 struct wl_resource *resource;
112 struct wl_listener destroy_listener;
113 struct weston_surface *surface;
118 struct wl_resource *resource;
120 struct wl_listener destroy_listener;
122 struct weston_compositor *compositor;
124 struct weston_surface *surface;
126 struct weston_process process;
128 struct weston_seat *seat;
130 struct wl_list list_surface;
131 struct wl_list list_layer;
132 struct wl_list list_screen;
134 struct wl_list list_weston_surface;
136 struct wl_list list_controller;
137 struct wl_list list_controller_surface;
138 struct wl_list list_controller_layer;
139 struct wl_list list_controller_screen;
142 struct weston_process process;
143 struct wl_client *client;
144 struct wl_resource *desktop_shell;
152 int event_restriction;
156 destroy_ivicontroller_surface(struct wl_resource *resource)
158 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
159 struct ivishell *shell = ivisurf->shell;
160 struct ivicontroller_surface *ctrlsurf = NULL;
161 struct ivicontroller_surface *next = NULL;
162 uint32_t id_surface = 0;
164 id_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
166 wl_list_for_each_safe(ctrlsurf, next,
167 &shell->list_controller_surface, link) {
168 if (id_surface != ctrlsurf->id_surface) {
172 wl_list_remove(&ctrlsurf->link);
180 destroy_ivicontroller_layer(struct wl_resource *resource)
182 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
183 struct ivishell *shell = ivilayer->shell;
184 struct ivicontroller_layer *ctrllayer = NULL;
185 struct ivicontroller_layer *next = NULL;
186 uint32_t id_layer = 0;
188 id_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
190 wl_list_for_each_safe(ctrllayer, next,
191 &shell->list_controller_layer, link) {
192 if (id_layer != ctrllayer->id_layer) {
196 wl_list_remove(&ctrllayer->link);
204 destroy_ivicontroller_screen(struct wl_resource *resource)
206 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
207 struct ivicontroller_screen *ctrlscrn = NULL;
208 struct ivicontroller_screen *next = NULL;
210 wl_list_for_each_safe(ctrlscrn, next,
211 &iviscrn->shell->list_controller_screen, link) {
212 // TODO : Only Single display
214 if (iviscrn->output->id != ctrlscrn->id_screen) {
218 wl_list_remove(&ctrlscrn->link);
226 unbind_resource_controller(struct wl_resource *resource)
228 struct ivicontroller *controller = wl_resource_get_user_data(resource);
230 wl_list_remove(&controller->link);
236 static struct ivisurface*
237 get_surface(struct wl_list *list_surf, uint32_t id_surface)
239 struct ivisurface *ivisurf = NULL;
240 uint32_t ivisurf_id = 0;
242 wl_list_for_each(ivisurf, list_surf, link) {
243 ivisurf_id = weston_layout_getIdOfSurface(ivisurf->layout_surface);
244 if (ivisurf_id == id_surface) {
252 static struct ivilayer*
253 get_layer(struct wl_list *list_layer, uint32_t id_layer)
255 struct ivilayer *ivilayer = NULL;
256 uint32_t ivilayer_id = 0;
258 wl_list_for_each(ivilayer, list_layer, link) {
259 ivilayer_id = weston_layout_getIdOfLayer(ivilayer->layout_layer);
260 if (ivilayer_id == id_layer) {
269 struct ivi_controller_screen_interface controller_screen_implementation;
271 static struct ivicontroller_screen*
272 controller_screen_create(struct ivishell *shell,
273 struct wl_client *client,
274 struct iviscreen *iviscrn)
276 struct ivicontroller_screen *ctrlscrn = NULL;
278 ctrlscrn = calloc(1, sizeof *ctrlscrn);
279 if (ctrlscrn == NULL) {
280 weston_log("no memory to allocate controller screen\n");
284 ctrlscrn->client = client;
285 ctrlscrn->shell = shell;
287 // TODO : Only Single display
289 /* ctrlscrn->id_screen = iviscrn->id_screen; */
291 ctrlscrn->id_screen = 0;
295 wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
296 if (ctrlscrn->resource == NULL) {
297 weston_log("couldn't new screen controller object");
305 wl_resource_set_implementation(ctrlscrn->resource,
306 &controller_screen_implementation,
307 iviscrn, destroy_ivicontroller_screen);
309 wl_list_init(&ctrlscrn->link);
310 wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
316 send_surface_add_event(struct ivisurface *ivisurf,
317 struct wl_resource *resource)
319 weston_layout_layer_ptr *pArray = NULL;
323 struct link_layer *link_layer = NULL;
324 struct link_layer *next = NULL;
325 struct ivicontroller_layer *ctrllayer = NULL;
326 struct ivilayer *ivilayer = NULL;
327 struct ivishell *shell = ivisurf->shell;
328 uint32_t id_layout_layer = 0;
331 ans = weston_layout_getLayersUnderSurface(ivisurf->layout_surface,
334 weston_log("failed to get layers at send_surface_add_event\n");
338 /* Send Null to cancel added surface */
339 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
340 for (i = 0, found = 0; i < (int)length; i++) {
341 if (pArray[i] == link_layer->layer->layout_layer) {
342 /* No need to send event, if new layer doesn't be added. */
351 ivi_controller_surface_send_layer(resource, NULL);
352 wl_list_remove(&link_layer->link);
357 for (i = 0; i < (int)length; i++) {
359 wl_list_for_each(link_layer, &ivisurf->list_layer, link) {
360 if (pArray[i] == link_layer->layer->layout_layer) {
361 /* No need to send event, if new layer doesn't be added. */
370 /* Create list_layer */
371 link_layer = calloc(1, sizeof(*link_layer));
372 if (NULL == link_layer) {
375 wl_list_init(&link_layer->link);
376 link_layer->layer = NULL;
377 wl_list_for_each(ivilayer, &shell->list_layer, link) {
378 if (ivilayer->layout_layer == pArray[i]) {
379 link_layer->layer = ivilayer;
384 if (link_layer->layer == NULL) {
389 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
391 /* Send new surface event */
393 weston_layout_getIdOfLayer(link_layer->layer->layout_layer);
394 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
395 if (id_layout_layer != ctrllayer->id_layer) {
398 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
407 send_surface_event(struct wl_resource *resource,
408 struct ivisurface *ivisurf,
409 struct weston_layout_SurfaceProperties *prop,
412 if (mask & IVI_NOTIFICATION_OPACITY) {
413 ivi_controller_surface_send_opacity(resource,
416 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
417 ivi_controller_surface_send_source_rectangle(resource,
418 prop->sourceX, prop->sourceY,
419 prop->sourceWidth, prop->sourceHeight);
421 if (mask & IVI_NOTIFICATION_DEST_RECT) {
422 ivi_controller_surface_send_destination_rectangle(resource,
423 prop->destX, prop->destY,
424 prop->destWidth, prop->destHeight);
426 if (mask & IVI_NOTIFICATION_ORIENTATION) {
427 ivi_controller_surface_send_orientation(resource,
430 if (mask & IVI_NOTIFICATION_VISIBILITY) {
431 ivi_controller_surface_send_visibility(resource,
434 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
435 ivi_controller_surface_send_pixelformat(resource,
438 if (mask & IVI_NOTIFICATION_ADD) {
439 send_surface_add_event(ivisurf, resource);
444 send_surface_prop(struct weston_layout_surface *layout_surface,
445 struct weston_layout_SurfaceProperties *prop,
446 enum weston_layout_notification_mask mask,
449 struct ivisurface *ivisurf = userdata;
450 struct ivishell *shell = ivisurf->shell;
451 struct ivicontroller_surface *ctrlsurf = NULL;
452 uint32_t id_surface = 0;
454 id_surface = weston_layout_getIdOfSurface(layout_surface);
456 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
457 if (id_surface != ctrlsurf->id_surface) {
460 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
465 send_layer_add_event(struct ivilayer *ivilayer,
466 struct wl_resource *resource)
468 weston_layout_screen_ptr *pArray = NULL;
472 struct link_screen *link_scrn = NULL;
473 struct link_screen *next = NULL;
474 struct iviscreen *iviscrn = NULL;
475 struct ivishell *shell = ivilayer->shell;
477 struct wl_client *client = wl_resource_get_client(resource);
478 struct wl_resource *resource_output = NULL;
480 ans = weston_layout_getScreensUnderLayer(ivilayer->layout_layer,
483 weston_log("failed to get screens at send_layer_add_event\n");
487 /* Send Null to cancel added layer */
488 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
489 for (i = 0, found = 0; i < (int)length; i++) {
490 if (pArray[i] == link_scrn->screen->layout_screen) {
491 /* No need to send event, if new layer doesn't be added. */
500 ivi_controller_layer_send_screen(resource, NULL);
501 wl_list_remove(&link_scrn->link);
506 for (i = 0; i < (int)length; i++) {
508 wl_list_for_each(link_scrn, &ivilayer->list_screen, link) {
509 if (pArray[i] == link_scrn->screen->layout_screen) {
510 /* No need to send event, if new screen doesn't be added. */
519 /* Create list_screen */
520 link_scrn = calloc(1, sizeof(*link_scrn));
521 if (NULL == link_scrn) {
524 wl_list_init(&link_scrn->link);
525 link_scrn->screen = NULL;
526 wl_list_for_each(iviscrn, &shell->list_screen, link) {
527 if (iviscrn->layout_screen == pArray[i]) {
528 link_scrn->screen = iviscrn;
533 if (link_scrn->screen == NULL) {
538 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
540 /* Send new layer event */
542 wl_resource_find_for_client(&iviscrn->output->resource_list,
544 if (resource_output != NULL) {
545 ivi_controller_layer_send_screen(resource, resource_output);
554 send_layer_event(struct wl_resource *resource,
555 struct ivilayer *ivilayer,
556 struct weston_layout_LayerProperties *prop,
559 if (mask & IVI_NOTIFICATION_OPACITY) {
560 ivi_controller_layer_send_opacity(resource,
563 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
564 ivi_controller_layer_send_source_rectangle(resource,
570 if (mask & IVI_NOTIFICATION_DEST_RECT) {
571 ivi_controller_layer_send_destination_rectangle(resource,
577 if (mask & IVI_NOTIFICATION_ORIENTATION) {
578 ivi_controller_layer_send_orientation(resource,
581 if (mask & IVI_NOTIFICATION_VISIBILITY) {
582 ivi_controller_layer_send_visibility(resource,
585 if (mask & IVI_NOTIFICATION_ADD) {
586 send_layer_add_event(ivilayer, resource);
591 send_layer_prop(struct weston_layout_layer *layer,
592 struct weston_layout_LayerProperties *prop,
593 enum weston_layout_notification_mask mask,
596 struct ivilayer *ivilayer = userdata;
597 struct ivicontroller_layer *ctrllayer = NULL;
598 struct ivishell *shell = ivilayer->shell;
599 uint32_t id_layout_layer = 0;
601 id_layout_layer = weston_layout_getIdOfLayer(layer);
602 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
603 if (id_layout_layer != ctrllayer->id_layer) {
606 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
611 controller_surface_set_opacity(struct wl_client *client,
612 struct wl_resource *resource,
615 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
617 weston_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
621 controller_surface_set_source_rectangle(struct wl_client *client,
622 struct wl_resource *resource,
628 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
630 weston_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
631 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
635 controller_surface_set_destination_rectangle(struct wl_client *client,
636 struct wl_resource *resource,
642 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
644 weston_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
645 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
649 controller_surface_set_visibility(struct wl_client *client,
650 struct wl_resource *resource,
653 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
655 weston_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
659 controller_surface_set_configuration(struct wl_client *client,
660 struct wl_resource *resource,
661 int32_t width, int32_t height)
663 /* This interface has been supported yet. */
671 controller_surface_set_orientation(struct wl_client *client,
672 struct wl_resource *resource,
675 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
677 weston_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
681 controller_surface_screenshot(struct wl_client *client,
682 struct wl_resource *resource,
683 const char *filename)
685 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
687 weston_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
691 controller_surface_send_stats(struct wl_client *client,
692 struct wl_resource *resource)
694 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
698 wl_client_get_credentials(client, &pid, &uid, &gid);
700 ivi_controller_surface_send_stats(resource, 0, 0,
701 ivisurf->update_count, pid, "");
705 controller_surface_destroy(struct wl_client *client,
706 struct wl_resource *resource,
707 int32_t destroy_scene_object)
709 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
710 struct ivishell *shell = ivisurf->shell;
711 struct ivicontroller_surface *ctrlsurf = NULL;
712 uint32_t id_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
714 (void)destroy_scene_object;
716 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
717 if (ctrlsurf->id_surface != id_surface) {
721 if (!wl_list_empty(&ctrlsurf->link)) {
722 wl_list_remove(&ctrlsurf->link);
724 wl_resource_destroy(resource);
730 controller_surface_set_input_focus(struct wl_client *client,
731 struct wl_resource *resource,
740 struct ivi_controller_surface_interface controller_surface_implementation = {
741 controller_surface_set_visibility,
742 controller_surface_set_opacity,
743 controller_surface_set_source_rectangle,
744 controller_surface_set_destination_rectangle,
745 controller_surface_set_configuration,
746 controller_surface_set_orientation,
747 controller_surface_screenshot,
748 controller_surface_send_stats,
749 controller_surface_destroy,
750 controller_surface_set_input_focus
754 controller_layer_set_source_rectangle(struct wl_client *client,
755 struct wl_resource *resource,
761 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
763 weston_layout_layerSetSourceRectangle(ivilayer->layout_layer,
764 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
768 controller_layer_set_destination_rectangle(struct wl_client *client,
769 struct wl_resource *resource,
775 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
777 weston_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
778 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
782 controller_layer_set_visibility(struct wl_client *client,
783 struct wl_resource *resource,
786 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
788 weston_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
792 controller_layer_set_opacity(struct wl_client *client,
793 struct wl_resource *resource,
796 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
798 weston_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
802 controller_layer_set_configuration(struct wl_client *client,
803 struct wl_resource *resource,
807 /* This interface has been supported yet. */
815 controller_layer_set_orientation(struct wl_client *client,
816 struct wl_resource *resource,
819 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
821 weston_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
825 controller_layer_clear_surfaces(struct wl_client *client,
826 struct wl_resource *resource)
828 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
830 weston_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
834 controller_layer_add_surface(struct wl_client *client,
835 struct wl_resource *resource,
836 struct wl_resource *surface)
838 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
839 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
841 weston_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
845 controller_layer_remove_surface(struct wl_client *client,
846 struct wl_resource *resource,
847 struct wl_resource *surface)
849 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
850 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
852 weston_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
856 controller_layer_screenshot(struct wl_client *client,
857 struct wl_resource *resource,
858 const char *filename)
866 controller_layer_set_render_order(struct wl_client *client,
867 struct wl_resource *resource,
868 struct wl_array *id_surfaces)
870 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
871 struct weston_layout_surface **layoutsurf_array = NULL;
872 struct ivisurface *ivisurf = NULL;
873 uint32_t *id_surface = NULL;
874 uint32_t id_layout_surface = 0;
878 wl_array_for_each(id_surface, id_surfaces) {
879 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
880 id_layout_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
881 if (*id_surface == id_layout_surface) {
882 layoutsurf_array[i] = ivisurf->layout_surface;
889 weston_layout_layerSetRenderOrder(ivilayer->layout_layer,
890 layoutsurf_array, id_surfaces->size);
891 free(layoutsurf_array);
895 controller_layer_destroy(struct wl_client *client,
896 struct wl_resource *resource,
897 int32_t destroy_scene_object)
899 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
900 struct ivishell *shell = ivilayer->shell;
901 struct ivicontroller_layer *ctrllayer = NULL;
902 uint32_t id_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
904 (void)destroy_scene_object;
906 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
907 if (ctrllayer->id_layer != id_layer) {
911 if (!wl_list_empty(&ctrllayer->link)) {
912 wl_list_remove(&ctrllayer->link);
914 wl_resource_destroy(resource);
918 weston_layout_layerRemove(ivilayer->layout_layer);
922 struct ivi_controller_layer_interface controller_layer_implementation = {
923 controller_layer_set_visibility,
924 controller_layer_set_opacity,
925 controller_layer_set_source_rectangle,
926 controller_layer_set_destination_rectangle,
927 controller_layer_set_configuration,
928 controller_layer_set_orientation,
929 controller_layer_screenshot,
930 controller_layer_clear_surfaces,
931 controller_layer_add_surface,
932 controller_layer_remove_surface,
933 controller_layer_set_render_order,
934 controller_layer_destroy
938 controller_screen_destroy(struct wl_client *client,
939 struct wl_resource *resource)
941 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
942 struct ivicontroller_screen *ctrlscrn = NULL;
943 struct ivicontroller_screen *next = NULL;
944 // uint32_t id_screen = weston_layout_getIdOfScreen(iviscrn->layout_screen);
947 wl_list_for_each_safe(ctrlscrn, next,
948 &iviscrn->shell->list_controller_screen, link) {
949 // TODO : Only Single display
950 destroy_ivicontroller_screen(ctrlscrn->resource);
951 wl_resource_destroy(ctrlscrn->resource);
957 controller_screen_clear(struct wl_client *client,
958 struct wl_resource *resource)
960 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
962 weston_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
966 controller_screen_add_layer(struct wl_client *client,
967 struct wl_resource *resource,
968 struct wl_resource *layer)
970 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
971 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
973 weston_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
977 controller_screen_screenshot(struct wl_client *client,
978 struct wl_resource *resource,
979 const char *filename)
981 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
983 weston_layout_takeScreenshot(iviscrn->layout_screen, filename);
987 controller_screen_set_render_order(struct wl_client *client,
988 struct wl_resource *resource,
989 struct wl_array *id_layers)
991 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
992 struct weston_layout_layer **layoutlayer_array = NULL;
993 struct ivilayer *ivilayer = NULL;
994 uint32_t *id_layer = NULL;
995 uint32_t id_layout_layer = 0;
999 *layoutlayer_array = (struct weston_layout_layer*)calloc(
1000 id_layers->size, sizeof(void*));
1002 wl_array_for_each(id_layer, id_layers) {
1003 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1004 id_layout_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
1005 if (*id_layer == id_layout_layer) {
1006 layoutlayer_array[i] = ivilayer->layout_layer;
1013 weston_layout_screenSetRenderOrder(iviscrn->layout_screen,
1014 layoutlayer_array, id_layers->size);
1015 free(layoutlayer_array);
1019 struct ivi_controller_screen_interface controller_screen_implementation = {
1020 controller_screen_destroy,
1021 controller_screen_clear,
1022 controller_screen_add_layer,
1023 controller_screen_screenshot,
1024 controller_screen_set_render_order
1028 controller_commit_changes(struct wl_client *client,
1029 struct wl_resource *resource)
1035 ans = weston_layout_commitChanges();
1037 weston_log("Failed to commit changes at controller_commit_changes\n");
1042 controller_layer_create(struct wl_client *client,
1043 struct wl_resource *resource,
1049 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1050 struct ivishell *shell = ctrl->shell;
1051 struct weston_layout_layer *layout_layer = NULL;
1052 struct ivicontroller_layer *ctrllayer = NULL;
1053 struct ivilayer *ivilayer = NULL;
1054 struct weston_layout_LayerProperties prop;
1056 ivilayer = get_layer(&shell->list_layer, id_layer);
1057 if (ivilayer == NULL) {
1058 layout_layer = weston_layout_layerCreateWithDimension(id_layer,
1059 (uint32_t)width, (uint32_t)height);
1060 if (layout_layer == NULL) {
1061 weston_log("id_layer is already created\n");
1065 /* ivilayer will be created by layer_event_create */
1066 ivilayer = get_layer(&shell->list_layer, id_layer);
1067 if (ivilayer == NULL) {
1068 weston_log("couldn't get layer object\n");
1073 ctrllayer = calloc(1, sizeof *ctrllayer);
1075 weston_log("no memory to allocate client layer\n");
1079 ctrllayer->shell = shell;
1080 ctrllayer->client = client;
1082 ctrllayer->id_layer = id_layer;
1083 ctrllayer->resource = wl_resource_create(client,
1084 &ivi_controller_layer_interface, 1, id);
1085 if (ctrllayer->resource == NULL) {
1086 weston_log("couldn't get layer object\n");
1090 wl_list_init(&ctrllayer->link);
1091 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1093 wl_resource_set_implementation(ctrllayer->resource,
1094 &controller_layer_implementation,
1095 ivilayer, destroy_ivicontroller_layer);
1097 memset(&prop, 0, sizeof prop);
1099 weston_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1101 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1102 if (id_layer != ctrllayer->id_layer) {
1105 send_layer_event(ctrllayer->resource, ivilayer,
1106 &prop, IVI_NOTIFICATION_ALL);
1111 controller_surface_create(struct wl_client *client,
1112 struct wl_resource *resource,
1113 uint32_t id_surface,
1116 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1117 struct ivishell *shell = ctrl->shell;
1118 struct ivicontroller_surface *ctrlsurf = NULL;
1119 struct weston_layout_SurfaceProperties prop;
1120 struct ivisurface *ivisurf = NULL;
1122 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1124 weston_log("no memory to allocate controller surface\n");
1128 ctrlsurf->shell = shell;
1129 ctrlsurf->client = client;
1131 ctrlsurf->id_surface = id_surface;
1132 wl_list_init(&ctrlsurf->link);
1133 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1135 ctrlsurf->resource = wl_resource_create(client,
1136 &ivi_controller_surface_interface, 1, id);
1137 if (ctrlsurf->resource == NULL) {
1138 weston_log("couldn't surface object");
1142 ivisurf = get_surface(&shell->list_surface, id_surface);
1143 if (ivisurf == NULL) {
1147 wl_resource_set_implementation(ctrlsurf->resource,
1148 &controller_surface_implementation,
1149 ivisurf, destroy_ivicontroller_surface);
1151 memset(&prop, 0, sizeof prop);
1153 weston_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1155 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1156 if (id_surface != ctrlsurf->id_surface) {
1159 send_surface_event(ctrlsurf->resource, ivisurf,
1160 &prop, IVI_NOTIFICATION_ALL);
1165 controller_get_native_handle(struct wl_client *client,
1166 struct wl_resource *resource,
1167 uint32_t id_process,
1170 struct wl_array surfaces;
1171 ivi_shell_get_shell_surfaces(&surfaces);
1172 struct shell_surface ** surface;
1174 wl_array_for_each(surface, &surfaces) {
1176 uint32_t pid = shell_surface_get_process_id(*surface);
1177 if (pid != id_process) {
1182 char* surface_title = shell_surface_get_title(*surface);
1183 if (strcmp(title, surface_title)) {
1188 struct weston_surface *es = shell_surface_get_surface(*surface);
1190 struct wl_resource *res = wl_resource_create(client, &wl_surface_interface, 1, 0);
1191 wl_resource_set_user_data(res, es);
1193 ivi_controller_send_native_handle(resource, res);
1197 wl_array_release(&surfaces);
1199 int32_t id_object = 0;
1200 ivi_controller_send_error(
1201 resource, id_object, IVI_CONTROLLER_OBJECT_TYPE_SURFACE,
1202 IVI_CONTROLLER_ERROR_CODE_NATIVE_HANDLE_END, "");
1205 static const struct ivi_controller_interface controller_implementation = {
1206 controller_commit_changes,
1207 controller_layer_create,
1208 controller_surface_create,
1209 controller_get_native_handle
1213 add_client_to_resources(struct ivishell *shell,
1214 struct wl_client *client,
1215 struct ivicontroller *controller)
1217 struct ivisurface* ivisurf = NULL;
1218 struct ivilayer* ivilayer = NULL;
1219 struct iviscreen* iviscrn = NULL;
1220 struct ivicontroller_screen *ctrlscrn = NULL;
1221 struct wl_resource *resource_output = NULL;
1222 uint32_t id_layout_surface = 0;
1223 uint32_t id_layout_layer = 0;
1225 wl_list_for_each(ivisurf, &shell->list_surface, link) {
1227 weston_layout_getIdOfSurface(ivisurf->layout_surface);
1229 ivi_controller_send_surface(controller->resource,
1233 wl_list_for_each(ivilayer, &shell->list_layer, link) {
1235 weston_layout_getIdOfLayer(ivilayer->layout_layer);
1237 ivi_controller_send_layer(controller->resource,
1241 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1242 resource_output = wl_resource_find_for_client(
1243 &iviscrn->output->resource_list, client);
1244 if (resource_output == NULL) {
1248 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1249 if (ctrlscrn == NULL) {
1253 ivi_controller_send_screen(controller->resource,
1254 wl_resource_get_id(resource_output),
1255 ctrlscrn->resource);
1260 bind_ivi_controller(struct wl_client *client, void *data,
1261 uint32_t version, uint32_t id)
1263 struct ivishell *shell = data;
1264 struct ivicontroller *controller;
1267 controller = calloc(1, sizeof *controller);
1268 if (controller == NULL) {
1269 weston_log("no memory to allocate controller\n");
1273 controller->resource =
1274 wl_resource_create(client, &ivi_controller_interface, 1, id);
1275 wl_resource_set_implementation(controller->resource,
1276 &controller_implementation,
1277 controller, unbind_resource_controller);
1279 controller->shell = shell;
1280 controller->client = client;
1281 controller->id = id;
1283 wl_list_init(&controller->link);
1284 wl_list_insert(&shell->list_controller, &controller->link);
1286 add_client_to_resources(shell, client, controller);
1289 static struct iviscreen*
1290 create_screen(struct ivishell *shell, struct weston_output *output)
1292 struct iviscreen *iviscrn;
1293 iviscrn = calloc(1, sizeof *iviscrn);
1294 if (iviscrn == NULL) {
1295 weston_log("no memory to allocate client screen\n");
1299 iviscrn->shell = shell;
1300 iviscrn->output = output;
1302 // TODO : Only Single display
1303 iviscrn->layout_screen = weston_layout_getScreenFromId(0);
1305 wl_list_init(&iviscrn->link);
1310 static struct ivilayer*
1311 create_layer(struct ivishell *shell,
1312 struct weston_layout_layer *layout_layer,
1315 struct ivilayer *ivilayer = NULL;
1316 struct ivicontroller *controller = NULL;
1318 ivilayer = get_layer(&shell->list_layer, id_layer);
1319 if (ivilayer != NULL) {
1320 weston_log("id_layer is already created\n");
1324 ivilayer = calloc(1, sizeof *ivilayer);
1325 if (NULL == ivilayer) {
1326 weston_log("no memory to allocate client layer\n");
1330 ivilayer->shell = shell;
1331 wl_list_init(&ivilayer->list_screen);
1332 wl_list_init(&ivilayer->link);
1333 wl_list_insert(&shell->list_layer, &ivilayer->link);
1334 ivilayer->layout_layer = layout_layer;
1336 weston_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1338 wl_list_for_each(controller, &shell->list_controller, link) {
1339 ivi_controller_send_layer(controller->resource, id_layer);
1345 static struct ivisurface*
1346 create_surface(struct ivishell *shell,
1347 struct weston_layout_surface *layout_surface,
1348 uint32_t id_surface)
1350 struct ivisurface *ivisurf = NULL;
1351 struct ivicontroller *controller = NULL;
1353 ivisurf = get_surface(&shell->list_surface, id_surface);
1354 if (ivisurf != NULL) {
1355 weston_log("id_surface is already created\n");
1359 ivisurf = calloc(1, sizeof *ivisurf);
1360 if (ivisurf == NULL) {
1361 weston_log("no memory to allocate client surface\n");
1365 ivisurf->shell = shell;
1366 ivisurf->layout_surface = layout_surface;
1367 wl_list_init(&ivisurf->list_layer);
1368 wl_list_init(&ivisurf->link);
1369 wl_list_insert(&shell->list_surface, &ivisurf->link);
1371 wl_list_for_each(controller, &shell->list_controller, link) {
1372 ivi_controller_send_surface(controller->resource,
1376 weston_layout_surfaceAddNotification(layout_surface,
1377 send_surface_prop, ivisurf);
1383 layer_event_create(struct weston_layout_layer *layout_layer,
1386 struct ivishell *shell = userdata;
1387 struct ivilayer *ivilayer = NULL;
1388 uint32_t id_layer = 0;
1390 id_layer = weston_layout_getIdOfLayer(layout_layer);
1392 ivilayer = create_layer(shell, layout_layer, id_layer);
1393 if (ivilayer == NULL) {
1394 weston_log("failed to create layer");
1400 layer_event_remove(struct weston_layout_layer *layout_layer,
1403 struct ivishell *shell = userdata;
1404 struct ivicontroller_layer *ctrllayer = NULL;
1405 struct ivilayer *ivilayer = NULL;
1406 struct ivilayer *next = NULL;
1407 uint32_t id_layer = 0;
1409 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1410 if (layout_layer != ivilayer->layout_layer) {
1414 wl_list_remove(&ivilayer->link);
1420 id_layer = weston_layout_getIdOfLayer(layout_layer);
1422 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1423 if (id_layer != ctrllayer->id_layer) {
1426 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1432 surface_event_create(struct weston_layout_surface *layout_surface,
1435 struct ivishell *shell = userdata;
1436 struct ivisurface *ivisurf = NULL;
1437 uint32_t id_surface = 0;
1439 id_surface = weston_layout_getIdOfSurface(layout_surface);
1441 ivisurf = create_surface(shell, layout_surface, id_surface);
1442 if (ivisurf == NULL) {
1443 weston_log("failed to create surface");
1449 surface_event_remove(struct weston_layout_surface *layout_surface,
1452 struct ivishell *shell = userdata;
1453 struct ivicontroller_surface *ctrlsurf = NULL;
1454 struct ivisurface *ivisurf = NULL;
1455 struct ivisurface *next = NULL;
1456 uint32_t id_surface = 0;
1458 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1459 if (layout_surface != ivisurf->layout_surface) {
1463 wl_list_remove(&ivisurf->link);
1469 id_surface = weston_layout_getIdOfSurface(layout_surface);
1471 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1472 if (id_surface != ctrlsurf->id_surface) {
1475 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1480 surface_event_configure(struct weston_layout_surface *layout_surface,
1483 struct ivishell *shell = userdata;
1484 struct ivisurface *ivisurf = NULL;
1485 struct ivicontroller_surface *ctrlsurf = NULL;
1486 struct weston_layout_SurfaceProperties prop;
1487 uint32_t id_surface = 0;
1489 id_surface = weston_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 weston_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 weston_layout_layer_ptr *pArray = NULL;
1513 struct ivilayer *ivilayer = NULL;
1514 uint32_t id_layer = 0;
1515 uint32_t length = 0;
1519 ret = weston_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 = weston_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 weston_layout_surface_ptr *pArray = NULL;
1548 struct ivisurface *ivisurf = NULL;
1549 uint32_t id_surface = 0;
1550 uint32_t length = 0;
1554 ret = weston_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 = weston_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 weston_layout_setNotificationCreateLayer(layer_event_create, shell);
1616 weston_layout_setNotificationRemoveLayer(layer_event_remove, shell);
1618 weston_layout_setNotificationCreateSurface(surface_event_create, shell);
1619 weston_layout_setNotificationRemoveSurface(surface_event_remove, shell);
1620 weston_layout_setNotificationConfigureSurface(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) {