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_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) {
167 if (id_surface != ctrlsurf->id_surface) {
171 wl_list_remove(&ctrlsurf->link);
179 destroy_ivicontroller_layer(struct wl_resource *resource)
181 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
182 struct ivishell *shell = ivilayer->shell;
183 struct ivicontroller_layer *ctrllayer = NULL;
184 struct ivicontroller_layer *next = NULL;
185 uint32_t id_layer = 0;
187 id_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
189 wl_list_for_each_safe(ctrllayer, next,
190 &shell->list_controller_layer, link) {
191 if (id_layer != ctrllayer->id_layer) {
195 wl_list_remove(&ctrllayer->link);
203 destroy_ivicontroller_screen(struct wl_resource *resource)
205 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
206 struct ivicontroller_screen *ctrlscrn = NULL;
207 struct ivicontroller_screen *next = NULL;
209 wl_list_for_each_safe(ctrlscrn, next,
210 &iviscrn->shell->list_controller_screen, link) {
211 // TODO : Only Single display
213 if (iviscrn->output->id != ctrlscrn->id_screen) {
217 wl_list_remove(&ctrlscrn->link);
225 unbind_resource_controller(struct wl_resource *resource)
227 struct ivicontroller *controller = wl_resource_get_user_data(resource);
229 wl_list_remove(&controller->link);
235 static struct ivisurface*
236 get_surface(struct wl_list *list_surf, uint32_t id_surface)
238 struct ivisurface *ivisurf = NULL;
239 uint32_t ivisurf_id = 0;
241 wl_list_for_each(ivisurf, list_surf, link) {
242 ivisurf_id = weston_layout_getIdOfSurface(ivisurf->layout_surface);
243 if (ivisurf_id == id_surface) {
251 static struct ivilayer*
252 get_layer(struct wl_list *list_layer, uint32_t id_layer)
254 struct ivilayer *ivilayer = NULL;
255 uint32_t ivilayer_id = 0;
257 wl_list_for_each(ivilayer, list_layer, link) {
258 ivilayer_id = weston_layout_getIdOfLayer(ivilayer->layout_layer);
259 if (ivilayer_id == id_layer) {
268 struct ivi_controller_screen_interface controller_screen_implementation;
270 static struct ivicontroller_screen*
271 controller_screen_create(struct ivishell *shell,
272 struct wl_client *client,
273 struct iviscreen *iviscrn)
275 struct ivicontroller_screen *ctrlscrn = NULL;
277 ctrlscrn = calloc(1, sizeof *ctrlscrn);
278 if (ctrlscrn == NULL) {
279 weston_log("no memory to allocate controller screen\n");
283 ctrlscrn->client = client;
284 ctrlscrn->shell = shell;
286 // TODO : Only Single display
288 /* ctrlscrn->id_screen = iviscrn->id_screen; */
290 ctrlscrn->id_screen = 0;
294 wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
295 if (ctrlscrn->resource == NULL) {
296 weston_log("couldn't new screen controller object");
304 wl_resource_set_implementation(ctrlscrn->resource,
305 &controller_screen_implementation,
306 iviscrn, destroy_ivicontroller_screen);
308 wl_list_init(&ctrlscrn->link);
309 wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
315 send_surface_add_event(struct ivisurface *ivisurf,
316 struct wl_resource *resource)
318 weston_layout_layer_ptr *pArray = NULL;
322 struct link_layer *link_layer = NULL;
323 struct link_layer *next = NULL;
324 struct ivicontroller_layer *ctrllayer = NULL;
325 struct ivilayer *ivilayer = NULL;
326 struct ivishell *shell = ivisurf->shell;
327 uint32_t id_layout_layer = 0;
330 ans = weston_layout_getLayersUnderSurface(ivisurf->layout_surface,
333 weston_log("failed to get layers at send_surface_add_event\n");
337 /* Send Null to cancel added surface */
338 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
339 for (i = 0, found = 0; i < (int)length; i++) {
340 if (pArray[i] == link_layer->layer->layout_layer) {
341 /* No need to send event, if new layer doesn't be added. */
350 ivi_controller_surface_send_layer(resource, NULL);
351 wl_list_remove(&link_layer->link);
356 for (i = 0; i < (int)length; i++) {
358 wl_list_for_each(link_layer, &ivisurf->list_layer, link) {
359 if (pArray[i] == link_layer->layer->layout_layer) {
360 /* No need to send event, if new layer doesn't be added. */
369 /* Create list_layer */
370 link_layer = calloc(1, sizeof(*link_layer));
371 if (NULL == link_layer) {
374 wl_list_init(&link_layer->link);
375 link_layer->layer = NULL;
376 wl_list_for_each(ivilayer, &shell->list_layer, link) {
377 if (ivilayer->layout_layer == pArray[i]) {
378 link_layer->layer = ivilayer;
383 if (link_layer->layer == NULL) {
388 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
390 /* Send new surface event */
392 weston_layout_getIdOfLayer(link_layer->layer->layout_layer);
393 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
394 if (id_layout_layer != ctrllayer->id_layer) {
397 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
406 send_surface_event(struct wl_resource *resource,
407 struct ivisurface *ivisurf,
408 struct weston_layout_SurfaceProperties *prop,
411 if (mask & IVI_NOTIFICATION_OPACITY) {
412 ivi_controller_surface_send_opacity(resource,
415 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
416 ivi_controller_surface_send_source_rectangle(resource,
417 prop->sourceX, prop->sourceY,
418 prop->sourceWidth, prop->sourceHeight);
420 if (mask & IVI_NOTIFICATION_DEST_RECT) {
421 ivi_controller_surface_send_destination_rectangle(resource,
422 prop->destX, prop->destY,
423 prop->destWidth, prop->destHeight);
425 if (mask & IVI_NOTIFICATION_ORIENTATION) {
426 ivi_controller_surface_send_orientation(resource,
429 if (mask & IVI_NOTIFICATION_VISIBILITY) {
430 ivi_controller_surface_send_visibility(resource,
433 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
434 ivi_controller_surface_send_pixelformat(resource,
437 if (mask & IVI_NOTIFICATION_ADD) {
438 send_surface_add_event(ivisurf, resource);
443 send_surface_prop(struct weston_layout_surface *layout_surface,
444 struct weston_layout_SurfaceProperties *prop,
445 enum weston_layout_notification_mask mask,
448 struct ivisurface *ivisurf = userdata;
449 struct ivishell *shell = ivisurf->shell;
450 struct ivicontroller_surface *ctrlsurf = NULL;
451 uint32_t id_surface = 0;
453 id_surface = weston_layout_getIdOfSurface(layout_surface);
455 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
456 if (id_surface != ctrlsurf->id_surface) {
459 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
464 send_layer_add_event(struct ivilayer *ivilayer,
465 struct wl_resource *resource)
467 weston_layout_screen_ptr *pArray = NULL;
471 struct link_screen *link_scrn = NULL;
472 struct link_screen *next = NULL;
473 struct iviscreen *iviscrn = NULL;
474 struct ivishell *shell = ivilayer->shell;
476 struct wl_client *client = wl_resource_get_client(resource);
477 struct wl_resource *resource_output = NULL;
479 ans = weston_layout_getScreensUnderLayer(ivilayer->layout_layer,
482 weston_log("failed to get screens at send_layer_add_event\n");
486 /* Send Null to cancel added layer */
487 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
488 for (i = 0, found = 0; i < (int)length; i++) {
489 if (pArray[i] == link_scrn->screen->layout_screen) {
490 /* No need to send event, if new layer doesn't be added. */
499 ivi_controller_layer_send_screen(resource, NULL);
500 wl_list_remove(&link_scrn->link);
505 for (i = 0; i < (int)length; i++) {
507 wl_list_for_each(link_scrn, &ivilayer->list_screen, link) {
508 if (pArray[i] == link_scrn->screen->layout_screen) {
509 /* No need to send event, if new screen doesn't be added. */
518 /* Create list_screen */
519 link_scrn = calloc(1, sizeof(*link_scrn));
520 if (NULL == link_scrn) {
523 wl_list_init(&link_scrn->link);
524 link_scrn->screen = NULL;
525 wl_list_for_each(iviscrn, &shell->list_screen, link) {
526 if (iviscrn->layout_screen == pArray[i]) {
527 link_scrn->screen = iviscrn;
532 if (link_scrn->screen == NULL) {
537 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
539 /* Send new layer event */
541 wl_resource_find_for_client(&iviscrn->output->resource_list,
543 if (resource_output != NULL) {
544 ivi_controller_layer_send_screen(resource, resource_output);
553 send_layer_event(struct wl_resource *resource,
554 struct ivilayer *ivilayer,
555 struct weston_layout_LayerProperties *prop,
558 if (mask & IVI_NOTIFICATION_OPACITY) {
559 ivi_controller_layer_send_opacity(resource,
562 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
563 ivi_controller_layer_send_source_rectangle(resource,
569 if (mask & IVI_NOTIFICATION_DEST_RECT) {
570 ivi_controller_layer_send_destination_rectangle(resource,
576 if (mask & IVI_NOTIFICATION_ORIENTATION) {
577 ivi_controller_layer_send_orientation(resource,
580 if (mask & IVI_NOTIFICATION_VISIBILITY) {
581 ivi_controller_layer_send_visibility(resource,
584 if (mask & IVI_NOTIFICATION_ADD) {
585 send_layer_add_event(ivilayer, resource);
590 send_layer_prop(struct weston_layout_layer *layer,
591 struct weston_layout_LayerProperties *prop,
592 enum weston_layout_notification_mask mask,
595 struct ivilayer *ivilayer = userdata;
596 struct ivicontroller_layer *ctrllayer = NULL;
597 struct ivishell *shell = ivilayer->shell;
598 uint32_t id_layout_layer = 0;
600 id_layout_layer = weston_layout_getIdOfLayer(layer);
601 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
602 if (id_layout_layer != ctrllayer->id_layer) {
605 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
610 controller_surface_set_opacity(struct wl_client *client,
611 struct wl_resource *resource,
614 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
616 weston_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
620 controller_surface_set_source_rectangle(struct wl_client *client,
621 struct wl_resource *resource,
627 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
629 weston_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
630 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
634 controller_surface_set_destination_rectangle(struct wl_client *client,
635 struct wl_resource *resource,
641 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
643 weston_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
644 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
648 controller_surface_set_visibility(struct wl_client *client,
649 struct wl_resource *resource,
652 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
654 weston_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
658 controller_surface_set_configuration(struct wl_client *client,
659 struct wl_resource *resource,
660 int32_t width, int32_t height)
662 /* This interface has been supported yet. */
670 controller_surface_set_orientation(struct wl_client *client,
671 struct wl_resource *resource,
674 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
676 weston_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
680 controller_surface_screenshot(struct wl_client *client,
681 struct wl_resource *resource,
682 const char *filename)
684 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
686 weston_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
690 controller_surface_send_stats(struct wl_client *client,
691 struct wl_resource *resource)
693 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
697 wl_client_get_credentials(client, &pid, &uid, &gid);
699 ivi_controller_surface_send_stats(resource, 0, 0,
700 ivisurf->update_count, pid, "");
704 controller_surface_destroy(struct wl_client *client,
705 struct wl_resource *resource,
706 int32_t destroy_scene_object)
708 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
709 struct ivishell *shell = ivisurf->shell;
710 struct ivicontroller_surface *ctrlsurf = NULL;
711 uint32_t id_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
713 (void)destroy_scene_object;
715 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
716 if (ctrlsurf->id_surface != id_surface) {
720 if (!wl_list_empty(&ctrlsurf->link)) {
721 wl_list_remove(&ctrlsurf->link);
723 wl_resource_destroy(resource);
729 controller_surface_set_input_focus(struct wl_client *client,
730 struct wl_resource *resource,
739 struct ivi_controller_surface_interface controller_surface_implementation = {
740 controller_surface_set_visibility,
741 controller_surface_set_opacity,
742 controller_surface_set_source_rectangle,
743 controller_surface_set_destination_rectangle,
744 controller_surface_set_configuration,
745 controller_surface_set_orientation,
746 controller_surface_screenshot,
747 controller_surface_send_stats,
748 controller_surface_destroy,
749 controller_surface_set_input_focus
753 controller_layer_set_source_rectangle(struct wl_client *client,
754 struct wl_resource *resource,
760 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
762 weston_layout_layerSetSourceRectangle(ivilayer->layout_layer,
763 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
767 controller_layer_set_destination_rectangle(struct wl_client *client,
768 struct wl_resource *resource,
774 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
776 weston_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
777 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
781 controller_layer_set_visibility(struct wl_client *client,
782 struct wl_resource *resource,
785 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
787 weston_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
791 controller_layer_set_opacity(struct wl_client *client,
792 struct wl_resource *resource,
795 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
797 weston_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
801 controller_layer_set_configuration(struct wl_client *client,
802 struct wl_resource *resource,
806 /* This interface has been supported yet. */
814 controller_layer_set_orientation(struct wl_client *client,
815 struct wl_resource *resource,
818 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
820 weston_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
824 controller_layer_clear_surfaces(struct wl_client *client,
825 struct wl_resource *resource)
827 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
829 weston_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
833 controller_layer_add_surface(struct wl_client *client,
834 struct wl_resource *resource,
835 struct wl_resource *surface)
837 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
838 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
840 weston_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
844 controller_layer_remove_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_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
855 controller_layer_screenshot(struct wl_client *client,
856 struct wl_resource *resource,
857 const char *filename)
865 controller_layer_set_render_order(struct wl_client *client,
866 struct wl_resource *resource,
867 struct wl_array *id_surfaces)
869 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
870 struct weston_layout_surface **layoutsurf_array = NULL;
871 struct ivisurface *ivisurf = NULL;
872 uint32_t *id_surface = NULL;
873 uint32_t id_layout_surface = 0;
877 wl_array_for_each(id_surface, id_surfaces) {
878 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
879 id_layout_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
880 if (*id_surface == id_layout_surface) {
881 layoutsurf_array[i] = ivisurf->layout_surface;
888 weston_layout_layerSetRenderOrder(ivilayer->layout_layer,
889 layoutsurf_array, id_surfaces->size);
890 free(layoutsurf_array);
894 controller_layer_destroy(struct wl_client *client,
895 struct wl_resource *resource,
896 int32_t destroy_scene_object)
898 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
899 struct ivishell *shell = ivilayer->shell;
900 struct ivicontroller_layer *ctrllayer = NULL;
901 uint32_t id_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
903 (void)destroy_scene_object;
905 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
906 if (ctrllayer->id_layer != id_layer) {
910 if (!wl_list_empty(&ctrllayer->link)) {
911 wl_list_remove(&ctrllayer->link);
913 wl_resource_destroy(resource);
917 weston_layout_layerRemove(ivilayer->layout_layer);
921 struct ivi_controller_layer_interface controller_layer_implementation = {
922 controller_layer_set_visibility,
923 controller_layer_set_opacity,
924 controller_layer_set_source_rectangle,
925 controller_layer_set_destination_rectangle,
926 controller_layer_set_configuration,
927 controller_layer_set_orientation,
928 controller_layer_screenshot,
929 controller_layer_clear_surfaces,
930 controller_layer_add_surface,
931 controller_layer_remove_surface,
932 controller_layer_set_render_order,
933 controller_layer_destroy
937 controller_screen_destroy(struct wl_client *client,
938 struct wl_resource *resource)
940 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
941 struct ivicontroller_screen *ctrlscrn = NULL;
942 struct ivicontroller_screen *next = NULL;
943 // uint32_t id_screen = weston_layout_getIdOfScreen(iviscrn->layout_screen);
946 wl_list_for_each_safe(ctrlscrn, next,
947 &iviscrn->shell->list_controller_screen, link) {
948 // TODO : Only Single display
949 destroy_ivicontroller_screen(ctrlscrn->resource);
950 wl_resource_destroy(ctrlscrn->resource);
956 controller_screen_clear(struct wl_client *client,
957 struct wl_resource *resource)
959 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
961 weston_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
965 controller_screen_add_layer(struct wl_client *client,
966 struct wl_resource *resource,
967 struct wl_resource *layer)
969 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
970 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
972 weston_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
976 controller_screen_screenshot(struct wl_client *client,
977 struct wl_resource *resource,
978 const char *filename)
980 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
982 weston_layout_takeScreenshot(iviscrn->layout_screen, filename);
986 controller_screen_set_render_order(struct wl_client *client,
987 struct wl_resource *resource,
988 struct wl_array *id_layers)
990 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
991 struct weston_layout_layer **layoutlayer_array = NULL;
992 struct ivilayer *ivilayer = NULL;
993 uint32_t *id_layer = NULL;
994 uint32_t id_layout_layer = 0;
998 *layoutlayer_array = (struct weston_layout_layer*)calloc(
999 id_layers->size, sizeof(void*));
1001 wl_array_for_each(id_layer, id_layers) {
1002 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1003 id_layout_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
1004 if (*id_layer == id_layout_layer) {
1005 layoutlayer_array[i] = ivilayer->layout_layer;
1012 weston_layout_screenSetRenderOrder(iviscrn->layout_screen,
1013 layoutlayer_array, id_layers->size);
1014 free(layoutlayer_array);
1018 struct ivi_controller_screen_interface controller_screen_implementation = {
1019 controller_screen_destroy,
1020 controller_screen_clear,
1021 controller_screen_add_layer,
1022 controller_screen_screenshot,
1023 controller_screen_set_render_order
1027 controller_commit_changes(struct wl_client *client,
1028 struct wl_resource *resource)
1034 ans = weston_layout_commitChanges();
1036 weston_log("Failed to commit changes at controller_commit_changes\n");
1041 controller_layer_create(struct wl_client *client,
1042 struct wl_resource *resource,
1048 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1049 struct ivishell *shell = ctrl->shell;
1050 struct weston_layout_layer *layout_layer = NULL;
1051 struct ivicontroller_layer *ctrllayer = NULL;
1052 struct ivilayer *ivilayer = NULL;
1053 struct weston_layout_LayerProperties prop;
1055 ivilayer = get_layer(&shell->list_layer, id_layer);
1056 if (ivilayer == NULL) {
1057 layout_layer = weston_layout_layerCreateWithDimension(id_layer,
1058 (uint32_t)width, (uint32_t)height);
1059 if (layout_layer == NULL) {
1060 weston_log("id_layer is already created\n");
1064 /* ivilayer will be created by layer_event_create */
1065 ivilayer = get_layer(&shell->list_layer, id_layer);
1066 if (ivilayer == NULL) {
1067 weston_log("couldn't get layer object\n");
1072 ctrllayer = calloc(1, sizeof *ctrllayer);
1074 weston_log("no memory to allocate client layer\n");
1078 ctrllayer->shell = shell;
1079 ctrllayer->client = client;
1081 ctrllayer->id_layer = id_layer;
1082 ctrllayer->resource = wl_resource_create(client,
1083 &ivi_controller_layer_interface, 1, id);
1084 if (ctrllayer->resource == NULL) {
1085 weston_log("couldn't get layer object\n");
1089 wl_list_init(&ctrllayer->link);
1090 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1092 wl_resource_set_implementation(ctrllayer->resource,
1093 &controller_layer_implementation,
1094 ivilayer, destroy_ivicontroller_layer);
1096 memset(&prop, 0, sizeof prop);
1098 weston_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1100 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1101 if (id_layer != ctrllayer->id_layer) {
1104 send_layer_event(ctrllayer->resource, ivilayer,
1105 &prop, IVI_NOTIFICATION_ALL);
1110 controller_surface_create(struct wl_client *client,
1111 struct wl_resource *resource,
1112 uint32_t id_surface,
1115 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1116 struct ivishell *shell = ctrl->shell;
1117 struct ivicontroller_surface *ctrlsurf = NULL;
1118 struct weston_layout_SurfaceProperties prop;
1119 struct ivisurface *ivisurf = NULL;
1121 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1123 weston_log("no memory to allocate controller surface\n");
1127 ctrlsurf->shell = shell;
1128 ctrlsurf->client = client;
1130 ctrlsurf->id_surface = id_surface;
1131 wl_list_init(&ctrlsurf->link);
1132 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1134 ctrlsurf->resource = wl_resource_create(client,
1135 &ivi_controller_surface_interface, 1, id);
1136 if (ctrlsurf->resource == NULL) {
1137 weston_log("couldn't surface object");
1141 ivisurf = get_surface(&shell->list_surface, id_surface);
1142 if (ivisurf == NULL) {
1146 wl_resource_set_implementation(ctrlsurf->resource,
1147 &controller_surface_implementation,
1148 ivisurf, destroy_ivicontroller_surface);
1150 memset(&prop, 0, sizeof prop);
1152 weston_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1154 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1155 if (id_surface != ctrlsurf->id_surface) {
1158 send_surface_event(ctrlsurf->resource, ivisurf,
1159 &prop, IVI_NOTIFICATION_ALL);
1163 static const struct ivi_controller_interface controller_implementation = {
1164 controller_commit_changes,
1165 controller_layer_create,
1166 controller_surface_create
1170 add_client_to_resources(struct ivishell *shell,
1171 struct wl_client *client,
1172 struct ivicontroller *controller)
1174 struct ivisurface* ivisurf = NULL;
1175 struct ivilayer* ivilayer = NULL;
1176 struct iviscreen* iviscrn = NULL;
1177 struct ivicontroller_screen *ctrlscrn = NULL;
1178 struct wl_resource *resource_output = NULL;
1179 uint32_t id_layout_surface = 0;
1180 uint32_t id_layout_layer = 0;
1182 wl_list_for_each(ivisurf, &shell->list_surface, link) {
1184 weston_layout_getIdOfSurface(ivisurf->layout_surface);
1186 ivi_controller_send_surface(controller->resource,
1190 wl_list_for_each(ivilayer, &shell->list_layer, link) {
1192 weston_layout_getIdOfLayer(ivilayer->layout_layer);
1194 ivi_controller_send_layer(controller->resource,
1198 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1199 resource_output = wl_resource_find_for_client(
1200 &iviscrn->output->resource_list, client);
1201 if (resource_output == NULL) {
1205 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1206 if (ctrlscrn == NULL) {
1210 ivi_controller_send_screen(controller->resource,
1211 wl_resource_get_id(resource_output),
1212 ctrlscrn->resource);
1217 bind_ivi_controller(struct wl_client *client, void *data,
1218 uint32_t version, uint32_t id)
1220 struct ivishell *shell = data;
1221 struct ivicontroller *controller;
1224 controller = calloc(1, sizeof *controller);
1225 if (controller == NULL) {
1226 weston_log("no memory to allocate controller\n");
1230 controller->resource =
1231 wl_resource_create(client, &ivi_controller_interface, 1, id);
1232 wl_resource_set_implementation(controller->resource,
1233 &controller_implementation,
1234 controller, unbind_resource_controller);
1236 controller->shell = shell;
1237 controller->client = client;
1238 controller->id = id;
1240 wl_list_init(&controller->link);
1241 wl_list_insert(&shell->list_controller, &controller->link);
1243 add_client_to_resources(shell, client, controller);
1246 static struct iviscreen*
1247 create_screen(struct ivishell *shell, struct weston_output *output)
1249 struct iviscreen *iviscrn;
1250 iviscrn = calloc(1, sizeof *iviscrn);
1251 if (iviscrn == NULL) {
1252 weston_log("no memory to allocate client screen\n");
1256 iviscrn->shell = shell;
1257 iviscrn->output = output;
1259 // TODO : Only Single display
1260 iviscrn->layout_screen = weston_layout_getScreenFromId(0);
1262 wl_list_init(&iviscrn->link);
1267 static struct ivilayer*
1268 create_layer(struct ivishell *shell,
1269 struct weston_layout_layer *layout_layer,
1272 struct ivilayer *ivilayer = NULL;
1273 struct ivicontroller *controller = NULL;
1275 ivilayer = get_layer(&shell->list_layer, id_layer);
1276 if (ivilayer != NULL) {
1277 weston_log("id_layer is already created\n");
1281 ivilayer = calloc(1, sizeof *ivilayer);
1282 if (NULL == ivilayer) {
1283 weston_log("no memory to allocate client layer\n");
1287 ivilayer->shell = shell;
1288 wl_list_init(&ivilayer->list_screen);
1289 wl_list_init(&ivilayer->link);
1290 wl_list_insert(&shell->list_layer, &ivilayer->link);
1291 ivilayer->layout_layer = layout_layer;
1293 weston_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1295 wl_list_for_each(controller, &shell->list_controller, link) {
1296 ivi_controller_send_layer(controller->resource, id_layer);
1302 static struct ivisurface*
1303 create_surface(struct ivishell *shell,
1304 struct weston_layout_surface *layout_surface,
1305 uint32_t id_surface)
1307 struct ivisurface *ivisurf = NULL;
1308 struct ivicontroller *controller = NULL;
1310 ivisurf = get_surface(&shell->list_surface, id_surface);
1311 if (ivisurf != NULL) {
1312 weston_log("id_surface is already created\n");
1316 ivisurf = calloc(1, sizeof *ivisurf);
1317 if (ivisurf == NULL) {
1318 weston_log("no memory to allocate client surface\n");
1322 ivisurf->shell = shell;
1323 ivisurf->layout_surface = layout_surface;
1324 wl_list_init(&ivisurf->list_layer);
1325 wl_list_init(&ivisurf->link);
1326 wl_list_insert(&shell->list_surface, &ivisurf->link);
1328 wl_list_for_each(controller, &shell->list_controller, link) {
1329 ivi_controller_send_surface(controller->resource,
1333 weston_layout_surfaceAddNotification(layout_surface,
1334 send_surface_prop, ivisurf);
1340 layer_event_create(struct weston_layout_layer *layout_layer,
1343 struct ivishell *shell = userdata;
1344 struct ivilayer *ivilayer = NULL;
1345 uint32_t id_layer = 0;
1347 id_layer = weston_layout_getIdOfLayer(layout_layer);
1349 ivilayer = create_layer(shell, layout_layer, id_layer);
1350 if (ivilayer == NULL) {
1351 weston_log("failed to create layer");
1357 layer_event_remove(struct weston_layout_layer *layout_layer,
1360 struct ivishell *shell = userdata;
1361 struct ivicontroller_layer *ctrllayer = NULL;
1362 struct ivilayer *ivilayer = NULL;
1363 struct ivilayer *next = NULL;
1364 uint32_t id_layer = 0;
1366 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1367 if (layout_layer != ivilayer->layout_layer) {
1371 wl_list_remove(&ivilayer->link);
1377 id_layer = weston_layout_getIdOfLayer(layout_layer);
1379 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1380 if (id_layer != ctrllayer->id_layer) {
1383 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1389 surface_event_create(struct weston_layout_surface *layout_surface,
1392 struct ivishell *shell = userdata;
1393 struct ivisurface *ivisurf = NULL;
1394 uint32_t id_surface = 0;
1396 id_surface = weston_layout_getIdOfSurface(layout_surface);
1398 ivisurf = create_surface(shell, layout_surface, id_surface);
1399 if (ivisurf == NULL) {
1400 weston_log("failed to create surface");
1406 surface_event_remove(struct weston_layout_surface *layout_surface,
1409 struct ivishell *shell = userdata;
1410 struct ivicontroller_surface *ctrlsurf = NULL;
1411 struct ivisurface *ivisurf = NULL;
1412 struct ivisurface *next = NULL;
1413 uint32_t id_surface = 0;
1415 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1416 if (layout_surface != ivisurf->layout_surface) {
1420 wl_list_remove(&ivisurf->link);
1426 id_surface = weston_layout_getIdOfSurface(layout_surface);
1428 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1429 if (id_surface != ctrlsurf->id_surface) {
1432 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1437 surface_event_configure(struct weston_layout_surface *layout_surface,
1440 struct ivishell *shell = userdata;
1441 struct ivisurface *ivisurf = NULL;
1442 struct ivicontroller_surface *ctrlsurf = NULL;
1443 struct weston_layout_SurfaceProperties prop;
1444 uint32_t id_surface = 0;
1446 id_surface = weston_layout_getIdOfSurface(layout_surface);
1448 ivisurf = get_surface(&shell->list_surface, id_surface);
1449 if (ivisurf == NULL) {
1450 weston_log("id_surface is not created yet\n");
1454 memset(&prop, 0, sizeof prop);
1455 weston_layout_getPropertiesOfSurface(layout_surface, &prop);
1457 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1458 if (id_surface != ctrlsurf->id_surface) {
1461 send_surface_event(ctrlsurf->resource, ivisurf,
1462 &prop, IVI_NOTIFICATION_ALL);
1467 check_layout_layers(struct ivishell *shell)
1469 weston_layout_layer_ptr *pArray = NULL;
1470 struct ivilayer *ivilayer = NULL;
1471 uint32_t id_layer = 0;
1472 uint32_t length = 0;
1476 ret = weston_layout_getLayers(&length, &pArray);
1478 weston_log("failed to get layers at check_layout_layers\n");
1483 /* if length is 0, pArray doesn't need to free.*/
1487 for (i = 0; i < length; i++) {
1488 id_layer = weston_layout_getIdOfLayer(pArray[i]);
1489 ivilayer = create_layer(shell, pArray[i], id_layer);
1490 if (ivilayer == NULL) {
1491 weston_log("failed to create layer");
1502 check_layout_surfaces(struct ivishell *shell)
1504 weston_layout_surface_ptr *pArray = NULL;
1505 struct ivisurface *ivisurf = NULL;
1506 uint32_t id_surface = 0;
1507 uint32_t length = 0;
1511 ret = weston_layout_getSurfaces(&length, &pArray);
1513 weston_log("failed to get surfaces at check_layout_surfaces\n");
1518 /* if length is 0, pArray doesn't need to free.*/
1522 for (i = 0; i < length; i++) {
1523 id_surface = weston_layout_getIdOfSurface(pArray[i]);
1524 ivisurf = create_surface(shell, pArray[i], id_surface);
1525 if (ivisurf == NULL) {
1526 weston_log("failed to create surface");
1537 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1539 struct weston_output *output = NULL;
1540 struct iviscreen *iviscrn = NULL;
1543 shell->compositor = ec;
1545 wl_list_init(&ec->layer_list);
1546 wl_list_init(&shell->list_surface);
1547 wl_list_init(&shell->list_layer);
1548 wl_list_init(&shell->list_screen);
1549 wl_list_init(&shell->list_weston_surface);
1550 wl_list_init(&shell->list_controller);
1551 wl_list_init(&shell->list_controller_screen);
1552 wl_list_init(&shell->list_controller_layer);
1553 wl_list_init(&shell->list_controller_surface);
1554 shell->event_restriction = 0;
1556 wl_list_for_each(output, &ec->output_list, link) {
1557 iviscrn = create_screen(shell, output);
1558 if (iviscrn != NULL) {
1559 wl_list_insert(&shell->list_screen, &iviscrn->link);
1563 ret = check_layout_layers(shell);
1565 weston_log("failed to check_layout_layers");
1568 ret = check_layout_surfaces(shell);
1570 weston_log("failed to check_layout_surfaces");
1573 weston_layout_setNotificationCreateLayer(layer_event_create, shell);
1574 weston_layout_setNotificationRemoveLayer(layer_event_remove, shell);
1576 weston_layout_setNotificationCreateSurface(surface_event_create, shell);
1577 weston_layout_setNotificationRemoveSurface(surface_event_remove, shell);
1578 weston_layout_setNotificationConfigureSurface(surface_event_configure, shell);
1582 module_init(struct weston_compositor *ec,
1583 int *argc, char *argv[])
1585 struct ivishell *shell;
1589 shell = malloc(sizeof *shell);
1593 memset(shell, 0, sizeof *shell);
1594 init_ivi_shell(ec, shell);
1596 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
1597 shell, bind_ivi_controller) == NULL) {