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"
40 struct ivilayer *layer;
45 struct iviscreen *screen;
51 struct wl_client *client;
52 struct ivishell *shell;
53 uint32_t update_count;
54 struct weston_layout_surface *layout_surface;
55 struct wl_listener surface_destroy_listener;
56 struct wl_list list_layer;
61 struct ivishell *shell;
62 struct weston_layout_layer *layout_layer;
63 struct wl_list list_screen;
68 struct ivishell *shell;
69 struct weston_layout_screen *layout_screen;
70 struct weston_output *output;
73 struct ivicontroller_surface {
74 struct wl_resource *resource;
77 struct wl_client *client;
79 struct ivishell *shell;
82 struct ivicontroller_layer {
83 struct wl_resource *resource;
86 struct wl_client *client;
88 struct ivishell *shell;
91 struct ivicontroller_screen {
92 struct wl_resource *resource;
95 struct wl_client *client;
97 struct ivishell *shell;
100 struct ivicontroller {
101 struct wl_resource *resource;
103 struct wl_client *client;
105 struct ivishell *shell;
108 struct link_shell_weston_surface
110 struct wl_resource *resource;
111 struct wl_listener destroy_listener;
112 struct weston_surface *surface;
117 struct wl_resource *resource;
119 struct wl_listener destroy_listener;
121 struct weston_compositor *compositor;
123 struct weston_surface *surface;
125 struct weston_process process;
127 struct weston_seat *seat;
129 struct wl_list list_surface;
130 struct wl_list list_layer;
131 struct wl_list list_screen;
133 struct wl_list list_weston_surface;
135 struct wl_list list_controller;
136 struct wl_list list_controller_surface;
137 struct wl_list list_controller_layer;
138 struct wl_list list_controller_screen;
141 struct weston_process process;
142 struct wl_client *client;
143 struct wl_resource *desktop_shell;
151 int event_restriction;
155 destroy_ivicontroller_surface(struct wl_resource *resource)
157 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
158 struct ivishell *shell = ivisurf->shell;
159 struct ivicontroller_surface *ctrlsurf = NULL;
160 struct ivicontroller_surface *next = NULL;
161 uint32_t id_surface = 0;
163 id_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
165 wl_list_for_each_safe(ctrlsurf, next,
166 &shell->list_controller_surface, link) {
168 if (resource != ctrlsurf->resource) {
173 wl_list_remove(&ctrlsurf->link);
181 destroy_ivicontroller_layer(struct wl_resource *resource)
183 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
184 struct ivishell *shell = ivilayer->shell;
185 struct ivicontroller_layer *ctrllayer = NULL;
186 struct ivicontroller_layer *next = NULL;
187 uint32_t id_layer = 0;
189 id_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
191 wl_list_for_each_safe(ctrllayer, next,
192 &shell->list_controller_layer, link) {
194 if (resource != ctrllayer->resource) {
198 wl_list_remove(&ctrllayer->link);
206 destroy_ivicontroller_screen(struct wl_resource *resource)
208 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
209 struct ivicontroller_screen *ctrlscrn = NULL;
210 struct ivicontroller_screen *next = NULL;
212 wl_list_for_each_safe(ctrlscrn, next,
213 &iviscrn->shell->list_controller_screen, link) {
214 // TODO : Only Single display
216 if (iviscrn->output->id != ctrlscrn->id_screen) {
221 if (resource != ctrlscrn->resource) {
225 wl_list_remove(&ctrlscrn->link);
233 unbind_resource_controller(struct wl_resource *resource)
235 struct ivicontroller *controller = wl_resource_get_user_data(resource);
237 wl_list_remove(&controller->link);
243 static struct ivisurface*
244 get_surface(struct wl_list *list_surf, uint32_t id_surface)
246 struct ivisurface *ivisurf = NULL;
247 uint32_t ivisurf_id = 0;
249 wl_list_for_each(ivisurf, list_surf, link) {
250 ivisurf_id = weston_layout_getIdOfSurface(ivisurf->layout_surface);
251 if (ivisurf_id == id_surface) {
259 static struct ivilayer*
260 get_layer(struct wl_list *list_layer, uint32_t id_layer)
262 struct ivilayer *ivilayer = NULL;
263 uint32_t ivilayer_id = 0;
265 wl_list_for_each(ivilayer, list_layer, link) {
266 ivilayer_id = weston_layout_getIdOfLayer(ivilayer->layout_layer);
267 if (ivilayer_id == id_layer) {
276 struct ivi_controller_screen_interface controller_screen_implementation;
278 static struct ivicontroller_screen*
279 controller_screen_create(struct ivishell *shell,
280 struct wl_client *client,
281 struct iviscreen *iviscrn)
283 struct ivicontroller_screen *ctrlscrn = NULL;
285 ctrlscrn = calloc(1, sizeof *ctrlscrn);
286 if (ctrlscrn == NULL) {
287 weston_log("no memory to allocate controller screen\n");
291 ctrlscrn->client = client;
292 ctrlscrn->shell = shell;
294 // TODO : Only Single display
296 /* ctrlscrn->id_screen = iviscrn->id_screen; */
298 ctrlscrn->id_screen = 0;
302 wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
303 if (ctrlscrn->resource == NULL) {
304 weston_log("couldn't new screen controller object");
312 wl_resource_set_implementation(ctrlscrn->resource,
313 &controller_screen_implementation,
314 iviscrn, destroy_ivicontroller_screen);
316 wl_list_init(&ctrlscrn->link);
317 wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
323 send_surface_add_event(struct ivisurface *ivisurf,
324 struct wl_resource *resource)
326 weston_layout_layer_ptr *pArray = NULL;
330 struct link_layer *link_layer = NULL;
331 struct link_layer *next = NULL;
332 struct ivicontroller_layer *ctrllayer = NULL;
333 struct ivilayer *ivilayer = NULL;
334 struct ivishell *shell = ivisurf->shell;
335 uint32_t id_layout_layer = 0;
338 ans = weston_layout_getLayersUnderSurface(ivisurf->layout_surface,
341 weston_log("failed to get layers at send_surface_add_event\n");
345 /* Send Null to cancel added surface */
346 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
347 for (i = 0, found = 0; i < (int)length; i++) {
348 if (pArray[i] == link_layer->layer->layout_layer) {
349 /* No need to send event, if new layer doesn't be added. */
358 ivi_controller_surface_send_layer(resource, NULL);
359 wl_list_remove(&link_layer->link);
364 for (i = 0; i < (int)length; i++) {
366 wl_list_for_each(link_layer, &ivisurf->list_layer, link) {
367 if (pArray[i] == link_layer->layer->layout_layer) {
368 /* No need to send event, if new layer doesn't be added. */
377 /* Create list_layer */
378 link_layer = calloc(1, sizeof(*link_layer));
379 if (NULL == link_layer) {
382 wl_list_init(&link_layer->link);
383 link_layer->layer = NULL;
384 wl_list_for_each(ivilayer, &shell->list_layer, link) {
385 if (ivilayer->layout_layer == pArray[i]) {
386 link_layer->layer = ivilayer;
391 if (link_layer->layer == NULL) {
396 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
398 /* Send new surface event */
400 weston_layout_getIdOfLayer(link_layer->layer->layout_layer);
401 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
402 if (id_layout_layer != ctrllayer->id_layer) {
405 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
414 send_surface_event(struct wl_resource *resource,
415 struct ivisurface *ivisurf,
416 struct weston_layout_SurfaceProperties *prop,
419 if (mask & IVI_NOTIFICATION_OPACITY) {
420 ivi_controller_surface_send_opacity(resource,
423 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
424 ivi_controller_surface_send_source_rectangle(resource,
425 prop->sourceX, prop->sourceY,
426 prop->sourceWidth, prop->sourceHeight);
428 if (mask & IVI_NOTIFICATION_DEST_RECT) {
429 ivi_controller_surface_send_destination_rectangle(resource,
430 prop->destX, prop->destY,
431 prop->destWidth, prop->destHeight);
433 if (mask & IVI_NOTIFICATION_ORIENTATION) {
434 ivi_controller_surface_send_orientation(resource,
437 if (mask & IVI_NOTIFICATION_VISIBILITY) {
438 ivi_controller_surface_send_visibility(resource,
441 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
442 ivi_controller_surface_send_pixelformat(resource,
445 if (mask & IVI_NOTIFICATION_ADD) {
446 send_surface_add_event(ivisurf, resource);
451 send_surface_prop(struct weston_layout_surface *layout_surface,
452 struct weston_layout_SurfaceProperties *prop,
453 enum weston_layout_notification_mask mask,
456 struct ivisurface *ivisurf = userdata;
457 struct ivishell *shell = ivisurf->shell;
458 struct ivicontroller_surface *ctrlsurf = NULL;
459 uint32_t id_surface = 0;
461 id_surface = weston_layout_getIdOfSurface(layout_surface);
463 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
464 if (id_surface != ctrlsurf->id_surface) {
467 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
472 send_layer_add_event(struct ivilayer *ivilayer,
473 struct wl_resource *resource)
475 weston_layout_screen_ptr *pArray = NULL;
479 struct link_screen *link_scrn = NULL;
480 struct link_screen *next = NULL;
481 struct iviscreen *iviscrn = NULL;
482 struct ivishell *shell = ivilayer->shell;
484 struct wl_client *client = wl_resource_get_client(resource);
485 struct wl_resource *resource_output = NULL;
487 ans = weston_layout_getScreensUnderLayer(ivilayer->layout_layer,
490 weston_log("failed to get screens at send_layer_add_event\n");
494 /* Send Null to cancel added layer */
495 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
496 for (i = 0, found = 0; i < (int)length; i++) {
497 if (pArray[i] == link_scrn->screen->layout_screen) {
498 /* No need to send event, if new layer doesn't be added. */
507 ivi_controller_layer_send_screen(resource, NULL);
508 wl_list_remove(&link_scrn->link);
513 for (i = 0; i < (int)length; i++) {
515 wl_list_for_each(link_scrn, &ivilayer->list_screen, link) {
516 if (pArray[i] == link_scrn->screen->layout_screen) {
517 /* No need to send event, if new screen doesn't be added. */
526 /* Create list_screen */
527 link_scrn = calloc(1, sizeof(*link_scrn));
528 if (NULL == link_scrn) {
531 wl_list_init(&link_scrn->link);
532 link_scrn->screen = NULL;
533 wl_list_for_each(iviscrn, &shell->list_screen, link) {
534 if (iviscrn->layout_screen == pArray[i]) {
535 link_scrn->screen = iviscrn;
540 if (link_scrn->screen == NULL) {
545 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
547 /* Send new layer event */
549 wl_resource_find_for_client(&iviscrn->output->resource_list,
551 if (resource_output != NULL) {
552 ivi_controller_layer_send_screen(resource, resource_output);
561 send_layer_event(struct wl_resource *resource,
562 struct ivilayer *ivilayer,
563 struct weston_layout_LayerProperties *prop,
566 if (mask & IVI_NOTIFICATION_OPACITY) {
567 ivi_controller_layer_send_opacity(resource,
570 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
571 ivi_controller_layer_send_source_rectangle(resource,
577 if (mask & IVI_NOTIFICATION_DEST_RECT) {
578 ivi_controller_layer_send_destination_rectangle(resource,
584 if (mask & IVI_NOTIFICATION_ORIENTATION) {
585 ivi_controller_layer_send_orientation(resource,
588 if (mask & IVI_NOTIFICATION_VISIBILITY) {
589 ivi_controller_layer_send_visibility(resource,
592 if (mask & IVI_NOTIFICATION_ADD) {
593 send_layer_add_event(ivilayer, resource);
598 send_layer_prop(struct weston_layout_layer *layer,
599 struct weston_layout_LayerProperties *prop,
600 enum weston_layout_notification_mask mask,
603 struct ivilayer *ivilayer = userdata;
604 struct ivicontroller_layer *ctrllayer = NULL;
605 struct ivishell *shell = ivilayer->shell;
606 uint32_t id_layout_layer = 0;
608 id_layout_layer = weston_layout_getIdOfLayer(layer);
609 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
610 if (id_layout_layer != ctrllayer->id_layer) {
613 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
618 controller_surface_set_opacity(struct wl_client *client,
619 struct wl_resource *resource,
622 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
624 weston_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
628 controller_surface_set_source_rectangle(struct wl_client *client,
629 struct wl_resource *resource,
635 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
637 weston_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
638 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
642 controller_surface_set_destination_rectangle(struct wl_client *client,
643 struct wl_resource *resource,
649 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
651 weston_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
652 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
656 controller_surface_set_visibility(struct wl_client *client,
657 struct wl_resource *resource,
660 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
662 weston_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
666 controller_surface_set_configuration(struct wl_client *client,
667 struct wl_resource *resource,
668 int32_t width, int32_t height)
670 /* This interface has been supported yet. */
678 controller_surface_set_orientation(struct wl_client *client,
679 struct wl_resource *resource,
682 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
684 weston_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
688 controller_surface_screenshot(struct wl_client *client,
689 struct wl_resource *resource,
690 const char *filename)
692 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
694 weston_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
698 controller_surface_send_stats(struct wl_client *client,
699 struct wl_resource *resource)
701 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
705 wl_client_get_credentials(client, &pid, &uid, &gid);
707 ivi_controller_surface_send_stats(resource, 0, 0,
708 ivisurf->update_count, pid, "");
712 controller_surface_destroy(struct wl_client *client,
713 struct wl_resource *resource,
714 int32_t destroy_scene_object)
716 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
717 struct ivishell *shell = ivisurf->shell;
718 struct ivicontroller_surface *ctrlsurf = NULL;
719 struct ivicontroller_surface *next = NULL;
720 uint32_t id_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
722 (void)destroy_scene_object;
724 wl_list_for_each_safe(ctrlsurf, next,
725 &shell->list_controller_surface, link) {
726 if (ctrlsurf->resource != resource) {
730 if (!wl_list_empty(&ctrlsurf->link)) {
731 wl_list_remove(&ctrlsurf->link);
734 wl_resource_destroy(resource);
740 controller_surface_set_input_focus(struct wl_client *client,
741 struct wl_resource *resource,
750 struct ivi_controller_surface_interface controller_surface_implementation = {
751 controller_surface_set_visibility,
752 controller_surface_set_opacity,
753 controller_surface_set_source_rectangle,
754 controller_surface_set_destination_rectangle,
755 controller_surface_set_configuration,
756 controller_surface_set_orientation,
757 controller_surface_screenshot,
758 controller_surface_send_stats,
759 controller_surface_destroy,
760 controller_surface_set_input_focus
764 controller_layer_set_source_rectangle(struct wl_client *client,
765 struct wl_resource *resource,
771 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
773 weston_layout_layerSetSourceRectangle(ivilayer->layout_layer,
774 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
778 controller_layer_set_destination_rectangle(struct wl_client *client,
779 struct wl_resource *resource,
785 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
787 weston_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
788 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
792 controller_layer_set_visibility(struct wl_client *client,
793 struct wl_resource *resource,
796 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
798 weston_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
802 controller_layer_set_opacity(struct wl_client *client,
803 struct wl_resource *resource,
806 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
808 weston_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
812 controller_layer_set_configuration(struct wl_client *client,
813 struct wl_resource *resource,
817 /* This interface has been supported yet. */
825 controller_layer_set_orientation(struct wl_client *client,
826 struct wl_resource *resource,
829 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
831 weston_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
835 controller_layer_clear_surfaces(struct wl_client *client,
836 struct wl_resource *resource)
838 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
840 weston_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
844 controller_layer_add_surface(struct wl_client *client,
845 struct wl_resource *resource,
846 struct wl_resource *surface)
848 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
849 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
851 weston_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
855 controller_layer_remove_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 weston_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
866 controller_layer_screenshot(struct wl_client *client,
867 struct wl_resource *resource,
868 const char *filename)
876 controller_layer_set_render_order(struct wl_client *client,
877 struct wl_resource *resource,
878 struct wl_array *id_surfaces)
880 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
881 struct weston_layout_surface **layoutsurf_array = NULL;
882 struct ivisurface *ivisurf = NULL;
883 uint32_t *id_surface = NULL;
884 uint32_t id_layout_surface = 0;
888 wl_array_for_each(id_surface, id_surfaces) {
889 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
890 id_layout_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
891 if (*id_surface == id_layout_surface) {
892 layoutsurf_array[i] = ivisurf->layout_surface;
899 weston_layout_layerSetRenderOrder(ivilayer->layout_layer,
900 layoutsurf_array, id_surfaces->size);
901 free(layoutsurf_array);
905 controller_layer_destroy(struct wl_client *client,
906 struct wl_resource *resource,
907 int32_t destroy_scene_object)
909 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
910 struct ivishell *shell = ivilayer->shell;
911 struct ivicontroller_layer *ctrllayer = NULL;
912 uint32_t id_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
914 (void)destroy_scene_object;
916 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
917 if (ctrllayer->id_layer != id_layer) {
921 if (!wl_list_empty(&ctrllayer->link)) {
922 wl_list_remove(&ctrllayer->link);
925 wl_resource_destroy(resource);
929 weston_layout_layerRemove(ivilayer->layout_layer);
933 struct ivi_controller_layer_interface controller_layer_implementation = {
934 controller_layer_set_visibility,
935 controller_layer_set_opacity,
936 controller_layer_set_source_rectangle,
937 controller_layer_set_destination_rectangle,
938 controller_layer_set_configuration,
939 controller_layer_set_orientation,
940 controller_layer_screenshot,
941 controller_layer_clear_surfaces,
942 controller_layer_add_surface,
943 controller_layer_remove_surface,
944 controller_layer_set_render_order,
945 controller_layer_destroy
949 controller_screen_destroy(struct wl_client *client,
950 struct wl_resource *resource)
952 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
953 struct ivicontroller_screen *ctrlscrn = NULL;
954 struct ivicontroller_screen *next = NULL;
955 // uint32_t id_screen = weston_layout_getIdOfScreen(iviscrn->layout_screen);
958 wl_list_for_each_safe(ctrlscrn, next,
959 &iviscrn->shell->list_controller_screen, link) {
960 if (resource != ctrlscrn->resource) {
964 wl_list_remove(&ctrlscrn->link);
967 wl_resource_destroy(ctrlscrn->resource);
973 controller_screen_clear(struct wl_client *client,
974 struct wl_resource *resource)
976 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
978 weston_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
982 controller_screen_add_layer(struct wl_client *client,
983 struct wl_resource *resource,
984 struct wl_resource *layer)
986 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
987 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
989 weston_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
993 controller_screen_screenshot(struct wl_client *client,
994 struct wl_resource *resource,
995 const char *filename)
997 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
999 weston_layout_takeScreenshot(iviscrn->layout_screen, filename);
1003 controller_screen_set_render_order(struct wl_client *client,
1004 struct wl_resource *resource,
1005 struct wl_array *id_layers)
1007 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1008 struct weston_layout_layer **layoutlayer_array = NULL;
1009 struct ivilayer *ivilayer = NULL;
1010 uint32_t *id_layer = NULL;
1011 uint32_t id_layout_layer = 0;
1015 *layoutlayer_array = (struct weston_layout_layer*)calloc(
1016 id_layers->size, sizeof(void*));
1018 wl_array_for_each(id_layer, id_layers) {
1019 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1020 id_layout_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
1021 if (*id_layer == id_layout_layer) {
1022 layoutlayer_array[i] = ivilayer->layout_layer;
1029 weston_layout_screenSetRenderOrder(iviscrn->layout_screen,
1030 layoutlayer_array, id_layers->size);
1031 free(layoutlayer_array);
1035 struct ivi_controller_screen_interface controller_screen_implementation = {
1036 controller_screen_destroy,
1037 controller_screen_clear,
1038 controller_screen_add_layer,
1039 controller_screen_screenshot,
1040 controller_screen_set_render_order
1044 controller_commit_changes(struct wl_client *client,
1045 struct wl_resource *resource)
1051 ans = weston_layout_commitChanges();
1053 weston_log("Failed to commit changes at controller_commit_changes\n");
1058 controller_layer_create(struct wl_client *client,
1059 struct wl_resource *resource,
1065 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1066 struct ivishell *shell = ctrl->shell;
1067 struct weston_layout_layer *layout_layer = NULL;
1068 struct ivicontroller_layer *ctrllayer = NULL;
1069 struct ivilayer *ivilayer = NULL;
1070 struct weston_layout_LayerProperties prop;
1072 ivilayer = get_layer(&shell->list_layer, id_layer);
1073 if (ivilayer == NULL) {
1074 layout_layer = weston_layout_layerCreateWithDimension(id_layer,
1075 (uint32_t)width, (uint32_t)height);
1076 if (layout_layer == NULL) {
1077 weston_log("id_layer is already created\n");
1081 /* ivilayer will be created by layer_event_create */
1082 ivilayer = get_layer(&shell->list_layer, id_layer);
1083 if (ivilayer == NULL) {
1084 weston_log("couldn't get layer object\n");
1089 ctrllayer = calloc(1, sizeof *ctrllayer);
1091 weston_log("no memory to allocate client layer\n");
1095 ctrllayer->shell = shell;
1096 ctrllayer->client = client;
1098 ctrllayer->id_layer = id_layer;
1099 ctrllayer->resource = wl_resource_create(client,
1100 &ivi_controller_layer_interface, 1, id);
1101 if (ctrllayer->resource == NULL) {
1102 weston_log("couldn't get layer object\n");
1106 wl_list_init(&ctrllayer->link);
1107 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1109 wl_resource_set_implementation(ctrllayer->resource,
1110 &controller_layer_implementation,
1111 ivilayer, destroy_ivicontroller_layer);
1113 memset(&prop, 0, sizeof prop);
1115 weston_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1117 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1118 if (id_layer != ctrllayer->id_layer) {
1121 send_layer_event(ctrllayer->resource, ivilayer,
1122 &prop, IVI_NOTIFICATION_ALL);
1127 controller_surface_create(struct wl_client *client,
1128 struct wl_resource *resource,
1129 uint32_t id_surface,
1132 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1133 struct ivishell *shell = ctrl->shell;
1134 struct ivicontroller_surface *ctrlsurf = NULL;
1135 struct weston_layout_SurfaceProperties prop;
1136 struct ivisurface *ivisurf = NULL;
1138 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1140 weston_log("no memory to allocate controller surface\n");
1144 ctrlsurf->shell = shell;
1145 ctrlsurf->client = client;
1147 ctrlsurf->id_surface = id_surface;
1148 wl_list_init(&ctrlsurf->link);
1149 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1151 ctrlsurf->resource = wl_resource_create(client,
1152 &ivi_controller_surface_interface, 1, id);
1153 if (ctrlsurf->resource == NULL) {
1154 weston_log("couldn't surface object");
1158 ivisurf = get_surface(&shell->list_surface, id_surface);
1159 if (ivisurf == NULL) {
1163 wl_resource_set_implementation(ctrlsurf->resource,
1164 &controller_surface_implementation,
1165 ivisurf, destroy_ivicontroller_surface);
1167 memset(&prop, 0, sizeof prop);
1169 weston_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1171 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1172 if (id_surface != ctrlsurf->id_surface) {
1175 send_surface_event(ctrlsurf->resource, ivisurf,
1176 &prop, IVI_NOTIFICATION_ALL);
1180 static const struct ivi_controller_interface controller_implementation = {
1181 controller_commit_changes,
1182 controller_layer_create,
1183 controller_surface_create
1187 add_client_to_resources(struct ivishell *shell,
1188 struct wl_client *client,
1189 struct ivicontroller *controller)
1191 struct ivisurface* ivisurf = NULL;
1192 struct ivilayer* ivilayer = NULL;
1193 struct iviscreen* iviscrn = NULL;
1194 struct ivicontroller_screen *ctrlscrn = NULL;
1195 struct wl_resource *resource_output = NULL;
1196 uint32_t id_layout_surface = 0;
1197 uint32_t id_layout_layer = 0;
1199 wl_list_for_each(ivisurf, &shell->list_surface, link) {
1201 weston_layout_getIdOfSurface(ivisurf->layout_surface);
1203 ivi_controller_send_surface(controller->resource,
1207 wl_list_for_each(ivilayer, &shell->list_layer, link) {
1209 weston_layout_getIdOfLayer(ivilayer->layout_layer);
1211 ivi_controller_send_layer(controller->resource,
1215 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1216 resource_output = wl_resource_find_for_client(
1217 &iviscrn->output->resource_list, client);
1218 if (resource_output == NULL) {
1222 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1223 if (ctrlscrn == NULL) {
1227 ivi_controller_send_screen(controller->resource,
1228 wl_resource_get_id(resource_output),
1229 ctrlscrn->resource);
1234 bind_ivi_controller(struct wl_client *client, void *data,
1235 uint32_t version, uint32_t id)
1237 struct ivishell *shell = data;
1238 struct ivicontroller *controller;
1241 controller = calloc(1, sizeof *controller);
1242 if (controller == NULL) {
1243 weston_log("no memory to allocate controller\n");
1247 controller->resource =
1248 wl_resource_create(client, &ivi_controller_interface, 1, id);
1249 wl_resource_set_implementation(controller->resource,
1250 &controller_implementation,
1251 controller, unbind_resource_controller);
1253 controller->shell = shell;
1254 controller->client = client;
1255 controller->id = id;
1257 wl_list_init(&controller->link);
1258 wl_list_insert(&shell->list_controller, &controller->link);
1260 add_client_to_resources(shell, client, controller);
1263 static struct iviscreen*
1264 create_screen(struct ivishell *shell, struct weston_output *output)
1266 struct iviscreen *iviscrn;
1267 iviscrn = calloc(1, sizeof *iviscrn);
1268 if (iviscrn == NULL) {
1269 weston_log("no memory to allocate client screen\n");
1273 iviscrn->shell = shell;
1274 iviscrn->output = output;
1276 // TODO : Only Single display
1277 iviscrn->layout_screen = weston_layout_getScreenFromId(0);
1279 wl_list_init(&iviscrn->link);
1284 static struct ivilayer*
1285 create_layer(struct ivishell *shell,
1286 struct weston_layout_layer *layout_layer,
1289 struct ivilayer *ivilayer = NULL;
1290 struct ivicontroller *controller = NULL;
1292 ivilayer = get_layer(&shell->list_layer, id_layer);
1293 if (ivilayer != NULL) {
1294 weston_log("id_layer is already created\n");
1298 ivilayer = calloc(1, sizeof *ivilayer);
1299 if (NULL == ivilayer) {
1300 weston_log("no memory to allocate client layer\n");
1304 ivilayer->shell = shell;
1305 wl_list_init(&ivilayer->list_screen);
1306 wl_list_init(&ivilayer->link);
1307 wl_list_insert(&shell->list_layer, &ivilayer->link);
1308 ivilayer->layout_layer = layout_layer;
1310 weston_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1312 wl_list_for_each(controller, &shell->list_controller, link) {
1313 ivi_controller_send_layer(controller->resource, id_layer);
1319 static struct ivisurface*
1320 create_surface(struct ivishell *shell,
1321 struct weston_layout_surface *layout_surface,
1322 uint32_t id_surface)
1324 struct ivisurface *ivisurf = NULL;
1325 struct ivicontroller *controller = NULL;
1327 ivisurf = get_surface(&shell->list_surface, id_surface);
1328 if (ivisurf != NULL) {
1329 weston_log("id_surface is already created\n");
1333 ivisurf = calloc(1, sizeof *ivisurf);
1334 if (ivisurf == NULL) {
1335 weston_log("no memory to allocate client surface\n");
1339 ivisurf->shell = shell;
1340 ivisurf->layout_surface = layout_surface;
1341 wl_list_init(&ivisurf->list_layer);
1342 wl_list_init(&ivisurf->link);
1343 wl_list_insert(&shell->list_surface, &ivisurf->link);
1345 wl_list_for_each(controller, &shell->list_controller, link) {
1346 ivi_controller_send_surface(controller->resource,
1350 weston_layout_surfaceAddNotification(layout_surface,
1351 send_surface_prop, ivisurf);
1357 layer_event_create(struct weston_layout_layer *layout_layer,
1360 struct ivishell *shell = userdata;
1361 struct ivilayer *ivilayer = NULL;
1362 uint32_t id_layer = 0;
1364 id_layer = weston_layout_getIdOfLayer(layout_layer);
1366 ivilayer = create_layer(shell, layout_layer, id_layer);
1367 if (ivilayer == NULL) {
1368 weston_log("failed to create layer");
1374 layer_event_remove(struct weston_layout_layer *layout_layer,
1377 struct ivishell *shell = userdata;
1378 struct ivicontroller_layer *ctrllayer = NULL;
1379 struct ivilayer *ivilayer = NULL;
1380 struct ivilayer *next = NULL;
1381 uint32_t id_layer = 0;
1383 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1384 if (layout_layer != ivilayer->layout_layer) {
1388 wl_list_remove(&ivilayer->link);
1394 id_layer = weston_layout_getIdOfLayer(layout_layer);
1396 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1397 if (id_layer != ctrllayer->id_layer) {
1400 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1406 surface_event_create(struct weston_layout_surface *layout_surface,
1409 struct ivishell *shell = userdata;
1410 struct ivisurface *ivisurf = NULL;
1411 uint32_t id_surface = 0;
1413 id_surface = weston_layout_getIdOfSurface(layout_surface);
1415 ivisurf = create_surface(shell, layout_surface, id_surface);
1416 if (ivisurf == NULL) {
1417 weston_log("failed to create surface");
1423 surface_event_remove(struct weston_layout_surface *layout_surface,
1426 struct ivishell *shell = userdata;
1427 struct ivicontroller_surface *ctrlsurf = NULL;
1428 struct ivisurface *ivisurf = NULL;
1429 struct ivisurface *next = NULL;
1430 uint32_t id_surface = 0;
1432 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1433 if (layout_surface != ivisurf->layout_surface) {
1437 wl_list_remove(&ivisurf->link);
1443 id_surface = weston_layout_getIdOfSurface(layout_surface);
1445 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1446 if (id_surface != ctrlsurf->id_surface) {
1449 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1454 surface_event_configure(struct weston_layout_surface *layout_surface,
1457 struct ivishell *shell = userdata;
1458 struct ivisurface *ivisurf = NULL;
1459 struct ivicontroller_surface *ctrlsurf = NULL;
1460 struct weston_layout_SurfaceProperties prop;
1461 uint32_t id_surface = 0;
1463 id_surface = weston_layout_getIdOfSurface(layout_surface);
1465 ivisurf = get_surface(&shell->list_surface, id_surface);
1466 if (ivisurf == NULL) {
1467 weston_log("id_surface is not created yet\n");
1471 memset(&prop, 0, sizeof prop);
1472 weston_layout_getPropertiesOfSurface(layout_surface, &prop);
1474 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1475 if (id_surface != ctrlsurf->id_surface) {
1478 send_surface_event(ctrlsurf->resource, ivisurf,
1479 &prop, IVI_NOTIFICATION_ALL);
1484 check_layout_layers(struct ivishell *shell)
1486 weston_layout_layer_ptr *pArray = NULL;
1487 struct ivilayer *ivilayer = NULL;
1488 uint32_t id_layer = 0;
1489 uint32_t length = 0;
1493 ret = weston_layout_getLayers(&length, &pArray);
1495 weston_log("failed to get layers at check_layout_layers\n");
1500 /* if length is 0, pArray doesn't need to free.*/
1504 for (i = 0; i < length; i++) {
1505 id_layer = weston_layout_getIdOfLayer(pArray[i]);
1506 ivilayer = create_layer(shell, pArray[i], id_layer);
1507 if (ivilayer == NULL) {
1508 weston_log("failed to create layer");
1519 check_layout_surfaces(struct ivishell *shell)
1521 weston_layout_surface_ptr *pArray = NULL;
1522 struct ivisurface *ivisurf = NULL;
1523 uint32_t id_surface = 0;
1524 uint32_t length = 0;
1528 ret = weston_layout_getSurfaces(&length, &pArray);
1530 weston_log("failed to get surfaces at check_layout_surfaces\n");
1535 /* if length is 0, pArray doesn't need to free.*/
1539 for (i = 0; i < length; i++) {
1540 id_surface = weston_layout_getIdOfSurface(pArray[i]);
1541 ivisurf = create_surface(shell, pArray[i], id_surface);
1542 if (ivisurf == NULL) {
1543 weston_log("failed to create surface");
1554 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1556 struct weston_output *output = NULL;
1557 struct iviscreen *iviscrn = NULL;
1560 shell->compositor = ec;
1562 wl_list_init(&shell->list_surface);
1563 wl_list_init(&shell->list_layer);
1564 wl_list_init(&shell->list_screen);
1565 wl_list_init(&shell->list_weston_surface);
1566 wl_list_init(&shell->list_controller);
1567 wl_list_init(&shell->list_controller_screen);
1568 wl_list_init(&shell->list_controller_layer);
1569 wl_list_init(&shell->list_controller_surface);
1570 shell->event_restriction = 0;
1572 wl_list_for_each(output, &ec->output_list, link) {
1573 iviscrn = create_screen(shell, output);
1574 if (iviscrn != NULL) {
1575 wl_list_insert(&shell->list_screen, &iviscrn->link);
1579 ret = check_layout_layers(shell);
1581 weston_log("failed to check_layout_layers");
1584 ret = check_layout_surfaces(shell);
1586 weston_log("failed to check_layout_surfaces");
1589 weston_layout_setNotificationCreateLayer(layer_event_create, shell);
1590 weston_layout_setNotificationRemoveLayer(layer_event_remove, shell);
1592 weston_layout_setNotificationCreateSurface(surface_event_create, shell);
1593 weston_layout_setNotificationRemoveSurface(surface_event_remove, shell);
1594 weston_layout_setNotificationConfigureSurface(surface_event_configure, shell);
1598 module_init(struct weston_compositor *ec,
1599 int *argc, char *argv[])
1601 struct ivishell *shell;
1605 shell = malloc(sizeof *shell);
1609 memset(shell, 0, sizeof *shell);
1610 init_ivi_shell(ec, shell);
1612 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
1613 shell, bind_ivi_controller) == NULL) {