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 "compositor.h"
32 #include "ivi-controller-server-protocol.h"
33 #include "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_event_source *source;
121 struct shell_surface {
122 struct wl_resource *resource;
124 struct weston_surface *surface;
125 struct wl_listener surface_destroy_listener;
127 struct ivishell *shell;
128 struct ping_timer *ping_timer;
136 const struct weston_shell_client *client;
137 struct weston_output *output;
141 struct wl_resource *resource;
143 struct wl_listener destroy_listener;
145 struct weston_compositor *compositor;
147 struct weston_surface *surface;
149 struct weston_process process;
151 struct weston_seat *seat;
153 struct wl_list list_surface;
154 struct wl_list list_layer;
155 struct wl_list list_screen;
157 struct wl_list list_weston_surface;
159 struct wl_list list_controller;
160 struct wl_list list_controller_surface;
161 struct wl_list list_controller_layer;
162 struct wl_list list_controller_screen;
165 struct weston_process process;
166 struct wl_client *client;
167 struct wl_resource *desktop_shell;
175 int event_restriction;
179 destroy_ivicontroller_surface(struct wl_resource *resource)
181 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
182 struct ivishell *shell = ivisurf->shell;
183 struct ivicontroller_surface *ctrlsurf = NULL;
184 struct ivicontroller_surface *next = NULL;
185 uint32_t id_surface = 0;
187 id_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
189 wl_list_for_each_safe(ctrlsurf, next,
190 &shell->list_controller_surface, link) {
191 if (id_surface != ctrlsurf->id_surface) {
195 wl_list_remove(&ctrlsurf->link);
203 destroy_ivicontroller_layer(struct wl_resource *resource)
205 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
206 struct ivishell *shell = ivilayer->shell;
207 struct ivicontroller_layer *ctrllayer = NULL;
208 struct ivicontroller_layer *next = NULL;
209 uint32_t id_layer = 0;
211 id_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
213 wl_list_for_each_safe(ctrllayer, next,
214 &shell->list_controller_layer, link) {
215 if (id_layer != ctrllayer->id_layer) {
219 wl_list_remove(&ctrllayer->link);
227 destroy_ivicontroller_screen(struct wl_resource *resource)
229 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
230 struct ivicontroller_screen *ctrlscrn = NULL;
231 struct ivicontroller_screen *next = NULL;
233 wl_list_for_each_safe(ctrlscrn, next,
234 &iviscrn->shell->list_controller_screen, link) {
235 // TODO : Only Single display
237 if (iviscrn->output->id != ctrlscrn->id_screen) {
241 wl_list_remove(&ctrlscrn->link);
249 unbind_resource_controller(struct wl_resource *resource)
251 struct ivicontroller *controller = wl_resource_get_user_data(resource);
253 wl_list_remove(&controller->link);
259 static struct ivisurface*
260 get_surface(struct wl_list *list_surf, uint32_t id_surface)
262 struct ivisurface *ivisurf = NULL;
263 uint32_t ivisurf_id = 0;
265 wl_list_for_each(ivisurf, list_surf, link) {
266 ivisurf_id = weston_layout_getIdOfSurface(ivisurf->layout_surface);
267 if (ivisurf_id == id_surface) {
275 static struct ivilayer*
276 get_layer(struct wl_list *list_layer, uint32_t id_layer)
278 struct ivilayer *ivilayer = NULL;
279 uint32_t ivilayer_id = 0;
281 wl_list_for_each(ivilayer, list_layer, link) {
282 ivilayer_id = weston_layout_getIdOfLayer(ivilayer->layout_layer);
283 if (ivilayer_id == id_layer) {
292 struct ivi_controller_screen_interface controller_screen_implementation;
294 static struct ivicontroller_screen*
295 controller_screen_create(struct ivishell *shell,
296 struct wl_client *client,
297 struct iviscreen *iviscrn)
299 struct ivicontroller_screen *ctrlscrn = NULL;
301 ctrlscrn = calloc(1, sizeof *ctrlscrn);
302 if (ctrlscrn == NULL) {
303 weston_log("no memory to allocate controller screen\n");
307 ctrlscrn->client = client;
308 ctrlscrn->shell = shell;
310 // TODO : Only Single display
312 /* ctrlscrn->id_screen = iviscrn->id_screen; */
314 ctrlscrn->id_screen = 0;
318 wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
319 if (ctrlscrn->resource == NULL) {
320 weston_log("couldn't new screen controller object");
328 wl_resource_set_implementation(ctrlscrn->resource,
329 &controller_screen_implementation,
330 iviscrn, destroy_ivicontroller_screen);
332 wl_list_init(&ctrlscrn->link);
333 wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
339 send_surface_add_event(struct ivisurface *ivisurf,
340 struct wl_resource *resource)
342 weston_layout_layer_ptr *pArray = NULL;
346 struct link_layer *link_layer = NULL;
347 struct link_layer *next = NULL;
348 struct ivicontroller_layer *ctrllayer = NULL;
349 struct ivilayer *ivilayer = NULL;
350 struct ivishell *shell = ivisurf->shell;
351 uint32_t id_layout_layer = 0;
354 ans = weston_layout_getLayersUnderSurface(ivisurf->layout_surface,
357 weston_log("failed to get layers at send_surface_add_event\n");
361 /* Send Null to cancel added surface */
362 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
363 for (i = 0, found = 0; i < (int)length; i++) {
364 if (pArray[i] == link_layer->layer->layout_layer) {
365 /* No need to send event, if new layer doesn't be added. */
374 ivi_controller_surface_send_layer(resource, NULL);
375 wl_list_remove(&link_layer->link);
380 for (i = 0; i < (int)length; i++) {
382 wl_list_for_each(link_layer, &ivisurf->list_layer, link) {
383 if (pArray[i] == link_layer->layer->layout_layer) {
384 /* No need to send event, if new layer doesn't be added. */
393 /* Create list_layer */
394 link_layer = calloc(1, sizeof(*link_layer));
395 if (NULL == link_layer) {
398 wl_list_init(&link_layer->link);
399 link_layer->layer = NULL;
400 wl_list_for_each(ivilayer, &shell->list_layer, link) {
401 if (ivilayer->layout_layer == pArray[i]) {
402 link_layer->layer = ivilayer;
407 if (link_layer->layer == NULL) {
412 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
414 /* Send new surface event */
416 weston_layout_getIdOfLayer(link_layer->layer->layout_layer);
417 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
418 if (id_layout_layer != ctrllayer->id_layer) {
421 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
430 send_surface_event(struct wl_resource *resource,
431 struct ivisurface *ivisurf,
432 struct weston_layout_SurfaceProperties *prop,
435 if (mask & IVI_NOTIFICATION_OPACITY) {
436 ivi_controller_surface_send_opacity(resource,
439 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
440 ivi_controller_surface_send_source_rectangle(resource,
441 prop->sourceX, prop->sourceY,
442 prop->sourceWidth, prop->sourceHeight);
444 if (mask & IVI_NOTIFICATION_DEST_RECT) {
445 ivi_controller_surface_send_destination_rectangle(resource,
446 prop->destX, prop->destY,
447 prop->destWidth, prop->destHeight);
449 if (mask & IVI_NOTIFICATION_ORIENTATION) {
450 ivi_controller_surface_send_orientation(resource,
453 if (mask & IVI_NOTIFICATION_VISIBILITY) {
454 ivi_controller_surface_send_visibility(resource,
457 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
458 ivi_controller_surface_send_pixelformat(resource,
461 if (mask & IVI_NOTIFICATION_ADD) {
462 send_surface_add_event(ivisurf, resource);
467 send_surface_prop(struct weston_layout_surface *layout_surface,
468 struct weston_layout_SurfaceProperties *prop,
469 enum weston_layout_notification_mask mask,
472 struct ivisurface *ivisurf = userdata;
473 struct ivishell *shell = ivisurf->shell;
474 struct ivicontroller_surface *ctrlsurf = NULL;
475 uint32_t id_surface = 0;
477 id_surface = weston_layout_getIdOfSurface(layout_surface);
479 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
480 if (id_surface != ctrlsurf->id_surface) {
483 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
488 send_layer_add_event(struct ivilayer *ivilayer,
489 struct wl_resource *resource)
491 weston_layout_screen_ptr *pArray = NULL;
495 struct link_screen *link_scrn = NULL;
496 struct link_screen *next = NULL;
497 struct iviscreen *iviscrn = NULL;
498 struct ivishell *shell = ivilayer->shell;
500 struct wl_client *client = wl_resource_get_client(resource);
501 struct wl_resource *resource_output = NULL;
503 ans = weston_layout_getScreensUnderLayer(ivilayer->layout_layer,
506 weston_log("failed to get screens at send_layer_add_event\n");
510 /* Send Null to cancel added layer */
511 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
512 for (i = 0, found = 0; i < (int)length; i++) {
513 if (pArray[i] == link_scrn->screen->layout_screen) {
514 /* No need to send event, if new layer doesn't be added. */
523 ivi_controller_layer_send_screen(resource, NULL);
524 wl_list_remove(&link_scrn->link);
529 for (i = 0; i < (int)length; i++) {
531 wl_list_for_each(link_scrn, &ivilayer->list_screen, link) {
532 if (pArray[i] == link_scrn->screen->layout_screen) {
533 /* No need to send event, if new screen doesn't be added. */
542 /* Create list_screen */
543 link_scrn = calloc(1, sizeof(*link_scrn));
544 if (NULL == link_scrn) {
547 wl_list_init(&link_scrn->link);
548 link_scrn->screen = NULL;
549 wl_list_for_each(iviscrn, &shell->list_screen, link) {
550 if (iviscrn->layout_screen == pArray[i]) {
551 link_scrn->screen = iviscrn;
556 if (link_scrn->screen == NULL) {
561 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
563 /* Send new layer event */
565 wl_resource_find_for_client(&iviscrn->output->resource_list,
567 if (resource_output != NULL) {
568 ivi_controller_layer_send_screen(resource, resource_output);
577 send_layer_event(struct wl_resource *resource,
578 struct ivilayer *ivilayer,
579 struct weston_layout_LayerProperties *prop,
582 if (mask & IVI_NOTIFICATION_OPACITY) {
583 ivi_controller_layer_send_opacity(resource,
586 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
587 ivi_controller_layer_send_source_rectangle(resource,
593 if (mask & IVI_NOTIFICATION_DEST_RECT) {
594 ivi_controller_layer_send_destination_rectangle(resource,
600 if (mask & IVI_NOTIFICATION_ORIENTATION) {
601 ivi_controller_layer_send_orientation(resource,
604 if (mask & IVI_NOTIFICATION_VISIBILITY) {
605 ivi_controller_layer_send_visibility(resource,
608 if (mask & IVI_NOTIFICATION_ADD) {
609 send_layer_add_event(ivilayer, resource);
614 send_layer_prop(struct weston_layout_layer *layer,
615 struct weston_layout_LayerProperties *prop,
616 enum weston_layout_notification_mask mask,
619 struct ivilayer *ivilayer = userdata;
620 struct ivicontroller_layer *ctrllayer = NULL;
621 struct ivishell *shell = ivilayer->shell;
622 uint32_t id_layout_layer = 0;
624 id_layout_layer = weston_layout_getIdOfLayer(layer);
625 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
626 if (id_layout_layer != ctrllayer->id_layer) {
629 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
634 controller_surface_set_opacity(struct wl_client *client,
635 struct wl_resource *resource,
638 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
640 weston_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
644 controller_surface_set_source_rectangle(struct wl_client *client,
645 struct wl_resource *resource,
651 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
653 weston_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
654 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
658 controller_surface_set_destination_rectangle(struct wl_client *client,
659 struct wl_resource *resource,
665 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
667 weston_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
668 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
672 controller_surface_set_visibility(struct wl_client *client,
673 struct wl_resource *resource,
676 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
678 weston_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
682 controller_surface_set_configuration(struct wl_client *client,
683 struct wl_resource *resource,
684 int32_t width, int32_t height)
686 /* This interface has been supported yet. */
694 controller_surface_set_orientation(struct wl_client *client,
695 struct wl_resource *resource,
698 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
700 weston_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
704 controller_surface_screenshot(struct wl_client *client,
705 struct wl_resource *resource,
706 const char *filename)
708 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
710 weston_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
714 controller_surface_send_stats(struct wl_client *client,
715 struct wl_resource *resource)
717 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
721 wl_client_get_credentials(client, &pid, &uid, &gid);
723 ivi_controller_surface_send_stats(resource, 0, 0,
724 ivisurf->update_count, pid, "");
728 controller_surface_destroy(struct wl_client *client,
729 struct wl_resource *resource,
730 int32_t destroy_scene_object)
732 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
733 struct ivishell *shell = ivisurf->shell;
734 struct ivicontroller_surface *ctrlsurf = NULL;
735 uint32_t id_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
737 (void)destroy_scene_object;
739 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
740 if (ctrlsurf->id_surface != id_surface) {
744 if (!wl_list_empty(&ctrlsurf->link)) {
745 wl_list_remove(&ctrlsurf->link);
747 wl_resource_destroy(resource);
753 controller_surface_set_input_focus(struct wl_client *client,
754 struct wl_resource *resource,
763 struct ivi_controller_surface_interface controller_surface_implementation = {
764 controller_surface_set_visibility,
765 controller_surface_set_opacity,
766 controller_surface_set_source_rectangle,
767 controller_surface_set_destination_rectangle,
768 controller_surface_set_configuration,
769 controller_surface_set_orientation,
770 controller_surface_screenshot,
771 controller_surface_send_stats,
772 controller_surface_destroy,
773 controller_surface_set_input_focus
777 controller_layer_set_source_rectangle(struct wl_client *client,
778 struct wl_resource *resource,
784 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
786 weston_layout_layerSetSourceRectangle(ivilayer->layout_layer,
787 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
791 controller_layer_set_destination_rectangle(struct wl_client *client,
792 struct wl_resource *resource,
798 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
800 weston_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
801 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
805 controller_layer_set_visibility(struct wl_client *client,
806 struct wl_resource *resource,
809 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
811 weston_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
815 controller_layer_set_opacity(struct wl_client *client,
816 struct wl_resource *resource,
819 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
821 weston_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
825 controller_layer_set_configuration(struct wl_client *client,
826 struct wl_resource *resource,
830 /* This interface has been supported yet. */
838 controller_layer_set_orientation(struct wl_client *client,
839 struct wl_resource *resource,
842 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
844 weston_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
848 controller_layer_clear_surfaces(struct wl_client *client,
849 struct wl_resource *resource)
851 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
853 weston_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
857 controller_layer_add_surface(struct wl_client *client,
858 struct wl_resource *resource,
859 struct wl_resource *surface)
861 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
862 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
864 weston_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
868 controller_layer_remove_surface(struct wl_client *client,
869 struct wl_resource *resource,
870 struct wl_resource *surface)
872 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
873 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
875 weston_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
879 controller_layer_screenshot(struct wl_client *client,
880 struct wl_resource *resource,
881 const char *filename)
889 controller_layer_set_render_order(struct wl_client *client,
890 struct wl_resource *resource,
891 struct wl_array *id_surfaces)
893 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
894 struct weston_layout_surface **layoutsurf_array = NULL;
895 struct ivisurface *ivisurf = NULL;
896 uint32_t *id_surface = NULL;
897 uint32_t id_layout_surface = 0;
901 wl_array_for_each(id_surface, id_surfaces) {
902 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
903 id_layout_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
904 if (*id_surface == id_layout_surface) {
905 layoutsurf_array[i] = ivisurf->layout_surface;
912 weston_layout_layerSetRenderOrder(ivilayer->layout_layer,
913 layoutsurf_array, id_surfaces->size);
914 free(layoutsurf_array);
918 controller_layer_destroy(struct wl_client *client,
919 struct wl_resource *resource,
920 int32_t destroy_scene_object)
922 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
923 struct ivishell *shell = ivilayer->shell;
924 struct ivicontroller_layer *ctrllayer = NULL;
925 uint32_t id_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
927 (void)destroy_scene_object;
929 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
930 if (ctrllayer->id_layer != id_layer) {
934 if (!wl_list_empty(&ctrllayer->link)) {
935 wl_list_remove(&ctrllayer->link);
937 wl_resource_destroy(resource);
941 weston_layout_layerRemove(ivilayer->layout_layer);
945 struct ivi_controller_layer_interface controller_layer_implementation = {
946 controller_layer_set_visibility,
947 controller_layer_set_opacity,
948 controller_layer_set_source_rectangle,
949 controller_layer_set_destination_rectangle,
950 controller_layer_set_configuration,
951 controller_layer_set_orientation,
952 controller_layer_screenshot,
953 controller_layer_clear_surfaces,
954 controller_layer_add_surface,
955 controller_layer_remove_surface,
956 controller_layer_set_render_order,
957 controller_layer_destroy
961 controller_screen_destroy(struct wl_client *client,
962 struct wl_resource *resource)
964 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
965 struct ivicontroller_screen *ctrlscrn = NULL;
966 struct ivicontroller_screen *next = NULL;
967 // uint32_t id_screen = weston_layout_getIdOfScreen(iviscrn->layout_screen);
970 wl_list_for_each_safe(ctrlscrn, next,
971 &iviscrn->shell->list_controller_screen, link) {
972 // TODO : Only Single display
973 destroy_ivicontroller_screen(ctrlscrn->resource);
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 weston_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 weston_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 weston_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 weston_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 weston_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 = weston_layout_getIdOfLayer(ivilayer->layout_layer);
1028 if (*id_layer == id_layout_layer) {
1029 layoutlayer_array[i] = ivilayer->layout_layer;
1036 weston_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 = weston_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 weston_layout_layer *layout_layer = NULL;
1075 struct ivicontroller_layer *ctrllayer = NULL;
1076 struct ivilayer *ivilayer = NULL;
1077 struct weston_layout_LayerProperties prop;
1079 ivilayer = get_layer(&shell->list_layer, id_layer);
1080 if (ivilayer == NULL) {
1081 layout_layer = weston_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 ctrllayer->shell = shell;
1103 ctrllayer->client = client;
1105 ctrllayer->id_layer = id_layer;
1106 ctrllayer->resource = wl_resource_create(client,
1107 &ivi_controller_layer_interface, 1, id);
1108 if (ctrllayer->resource == NULL) {
1109 weston_log("couldn't get layer object\n");
1113 wl_list_init(&ctrllayer->link);
1114 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1116 wl_resource_set_implementation(ctrllayer->resource,
1117 &controller_layer_implementation,
1118 ivilayer, destroy_ivicontroller_layer);
1120 memset(&prop, 0, sizeof prop);
1122 weston_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1124 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1125 if (id_layer != ctrllayer->id_layer) {
1128 send_layer_event(ctrllayer->resource, ivilayer,
1129 &prop, IVI_NOTIFICATION_ALL);
1134 controller_surface_create(struct wl_client *client,
1135 struct wl_resource *resource,
1136 uint32_t id_surface,
1139 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1140 struct ivishell *shell = ctrl->shell;
1141 struct ivicontroller_surface *ctrlsurf = NULL;
1142 struct weston_layout_SurfaceProperties prop;
1143 struct ivisurface *ivisurf = NULL;
1145 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1147 weston_log("no memory to allocate controller surface\n");
1151 ctrlsurf->shell = shell;
1152 ctrlsurf->client = client;
1154 ctrlsurf->id_surface = id_surface;
1155 wl_list_init(&ctrlsurf->link);
1156 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1158 ctrlsurf->resource = wl_resource_create(client,
1159 &ivi_controller_surface_interface, 1, id);
1160 if (ctrlsurf->resource == NULL) {
1161 weston_log("couldn't surface object");
1165 ivisurf = get_surface(&shell->list_surface, id_surface);
1166 if (ivisurf == NULL) {
1170 wl_resource_set_implementation(ctrlsurf->resource,
1171 &controller_surface_implementation,
1172 ivisurf, destroy_ivicontroller_surface);
1174 memset(&prop, 0, sizeof prop);
1176 weston_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1178 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1179 if (id_surface != ctrlsurf->id_surface) {
1182 send_surface_event(ctrlsurf->resource, ivisurf,
1183 &prop, IVI_NOTIFICATION_ALL);
1187 static const struct ivi_controller_interface controller_implementation = {
1188 controller_commit_changes,
1189 controller_layer_create,
1190 controller_surface_create
1194 add_client_to_resources(struct ivishell *shell,
1195 struct wl_client *client,
1196 struct ivicontroller *controller)
1198 struct ivisurface* ivisurf = NULL;
1199 struct ivilayer* ivilayer = NULL;
1200 struct iviscreen* iviscrn = NULL;
1201 struct ivicontroller_screen *ctrlscrn = NULL;
1202 struct wl_resource *resource_output = NULL;
1203 uint32_t id_layout_surface = 0;
1204 uint32_t id_layout_layer = 0;
1206 wl_list_for_each(ivisurf, &shell->list_surface, link) {
1208 weston_layout_getIdOfSurface(ivisurf->layout_surface);
1210 ivi_controller_send_surface(controller->resource,
1214 wl_list_for_each(ivilayer, &shell->list_layer, link) {
1216 weston_layout_getIdOfLayer(ivilayer->layout_layer);
1218 ivi_controller_send_layer(controller->resource,
1222 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1223 resource_output = wl_resource_find_for_client(
1224 &iviscrn->output->resource_list, client);
1225 if (resource_output == NULL) {
1229 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1230 if (ctrlscrn == NULL) {
1234 ivi_controller_send_screen(controller->resource,
1235 wl_resource_get_id(resource_output),
1236 ctrlscrn->resource);
1241 bind_ivi_controller(struct wl_client *client, void *data,
1242 uint32_t version, uint32_t id)
1244 struct ivishell *shell = data;
1245 struct ivicontroller *controller;
1248 controller = calloc(1, sizeof *controller);
1249 if (controller == NULL) {
1250 weston_log("no memory to allocate controller\n");
1254 controller->resource =
1255 wl_resource_create(client, &ivi_controller_interface, 1, id);
1256 wl_resource_set_implementation(controller->resource,
1257 &controller_implementation,
1258 controller, unbind_resource_controller);
1260 controller->shell = shell;
1261 controller->client = client;
1262 controller->id = id;
1264 wl_list_init(&controller->link);
1265 wl_list_insert(&shell->list_controller, &controller->link);
1267 add_client_to_resources(shell, client, controller);
1270 static struct iviscreen*
1271 create_screen(struct ivishell *shell, struct weston_output *output)
1273 struct iviscreen *iviscrn;
1274 iviscrn = calloc(1, sizeof *iviscrn);
1275 if (iviscrn == NULL) {
1276 weston_log("no memory to allocate client screen\n");
1280 iviscrn->shell = shell;
1281 iviscrn->output = output;
1283 // TODO : Only Single display
1284 iviscrn->layout_screen = weston_layout_getScreenFromId(0);
1286 wl_list_init(&iviscrn->link);
1292 layer_event_create(struct weston_layout_layer *layout_layer,
1295 struct ivishell *shell = userdata;
1296 struct ivicontroller *controller = NULL;
1297 struct ivilayer *ivilayer = NULL;
1298 uint32_t id_layer = 0;
1300 id_layer = weston_layout_getIdOfLayer(layout_layer);
1302 ivilayer = calloc(1, sizeof *ivilayer);
1304 weston_log("no memory to allocate client layer\n");
1308 ivilayer->shell = shell;
1309 wl_list_init(&ivilayer->list_screen);
1310 wl_list_init(&ivilayer->link);
1311 wl_list_insert(&shell->list_layer, &ivilayer->link);
1312 ivilayer->layout_layer = layout_layer;
1314 weston_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1316 wl_list_for_each(controller, &shell->list_controller, link) {
1317 ivi_controller_send_layer(controller->resource, id_layer);
1324 layer_event_remove(struct weston_layout_layer *layout_layer,
1327 struct ivishell *shell = userdata;
1328 struct ivicontroller_layer *ctrllayer = NULL;
1329 struct ivilayer *ivilayer = NULL;
1330 struct ivilayer *next = NULL;
1331 uint32_t id_layer = 0;
1333 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1334 if (layout_layer != ivilayer->layout_layer) {
1338 wl_list_remove(&ivilayer->link);
1344 id_layer = weston_layout_getIdOfLayer(layout_layer);
1346 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1347 if (id_layer != ctrllayer->id_layer) {
1350 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1356 surface_event_create(struct weston_layout_surface *layout_surface,
1359 struct ivishell *shell = userdata;
1360 struct ivisurface *ivisurf = NULL;
1361 struct ivicontroller *controller = NULL;
1362 uint32_t id_surface = 0;
1364 id_surface = weston_layout_getIdOfSurface(layout_surface);
1366 ivisurf = get_surface(&shell->list_surface, id_surface);
1367 if (ivisurf != NULL)
1369 weston_log("id_surface is already created\n");
1373 ivisurf = calloc(1, sizeof *ivisurf);
1374 if (ivisurf == NULL) {
1375 weston_log("no memory to allocate client surface\n");
1379 ivisurf->shell = shell;
1380 ivisurf->layout_surface = layout_surface;
1381 wl_list_init(&ivisurf->list_layer);
1382 wl_list_init(&ivisurf->link);
1383 wl_list_insert(&shell->list_surface, &ivisurf->link);
1385 wl_list_for_each(controller, &shell->list_controller, link) {
1386 ivi_controller_send_surface(controller->resource,
1390 weston_layout_surfaceAddNotification(layout_surface,
1391 &send_surface_prop, ivisurf);
1396 surface_event_remove(struct weston_layout_surface *layout_surface,
1399 struct ivishell *shell = userdata;
1400 struct ivicontroller_surface *ctrlsurf = NULL;
1401 struct ivisurface *ivisurf = NULL;
1402 struct ivisurface *next = NULL;
1403 uint32_t id_surface = 0;
1405 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1406 if (layout_surface != ivisurf->layout_surface) {
1410 wl_list_remove(&ivisurf->link);
1416 id_surface = weston_layout_getIdOfSurface(layout_surface);
1418 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1419 if (id_surface != ctrlsurf->id_surface) {
1422 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1427 surface_event_configure(struct weston_layout_surface *layout_surface,
1430 struct ivishell *shell = userdata;
1431 struct ivisurface *ivisurf = NULL;
1432 struct ivicontroller_surface *ctrlsurf = NULL;
1433 struct weston_layout_SurfaceProperties prop;
1434 uint32_t id_surface = 0;
1436 id_surface = weston_layout_getIdOfSurface(layout_surface);
1438 ivisurf = get_surface(&shell->list_surface, id_surface);
1439 if (ivisurf == NULL) {
1440 weston_log("id_surface is not created yet\n");
1444 memset(&prop, 0, sizeof prop);
1445 weston_layout_getPropertiesOfSurface(layout_surface, &prop);
1447 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1448 if (id_surface != ctrlsurf->id_surface) {
1451 send_surface_event(ctrlsurf->resource, ivisurf,
1452 &prop, IVI_NOTIFICATION_ALL);
1457 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1459 struct weston_output *output = NULL;
1460 struct iviscreen *iviscrn = NULL;
1461 shell->compositor = ec;
1463 wl_list_init(&ec->layer_list);
1464 wl_list_init(&shell->list_surface);
1465 wl_list_init(&shell->list_layer);
1466 wl_list_init(&shell->list_screen);
1467 wl_list_init(&shell->list_weston_surface);
1468 wl_list_init(&shell->list_controller);
1469 wl_list_init(&shell->list_controller_screen);
1470 wl_list_init(&shell->list_controller_layer);
1471 wl_list_init(&shell->list_controller_surface);
1472 shell->event_restriction = 0;
1474 wl_list_for_each(output, &ec->output_list, link) {
1475 iviscrn = create_screen(shell, output);
1476 if (iviscrn != NULL) {
1477 wl_list_insert(&shell->list_screen, &iviscrn->link);
1481 weston_layout_setNotificationCreateLayer(layer_event_create, shell);
1482 weston_layout_setNotificationRemoveLayer(layer_event_remove, shell);
1484 weston_layout_setNotificationCreateSurface(surface_event_create, shell);
1485 weston_layout_setNotificationRemoveSurface(surface_event_remove, shell);
1486 weston_layout_setNotificationConfigureSurface(surface_event_configure, shell);
1490 module_init(struct weston_compositor *ec,
1491 int *argc, char *argv[])
1493 struct ivishell *shell;
1497 shell = malloc(sizeof *shell);
1501 memset(shell, 0, sizeof *shell);
1502 init_ivi_shell(ec, shell);
1504 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
1505 shell, bind_ivi_controller) == NULL) {