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>
30 #include <GLES2/gl2.h>
32 #include <wayland-server.h>
34 #include <weston/compositor.h>
35 #include <weston/ivi-shell.h>
36 #include <weston/ivi-shell-ext.h>
37 #include <weston/ivi-layout-export.h>
38 #include "ivi-controller-server-protocol.h"
46 struct ivilayer *layer;
51 struct iviscreen *screen;
57 struct wl_client *client;
58 struct ivishell *shell;
59 uint32_t update_count;
60 struct ivi_layout_surface *layout_surface;
61 struct wl_listener surface_destroy_listener;
62 struct wl_list list_layer;
63 uint32_t controller_surface_count;
69 struct ivishell *shell;
70 struct ivi_layout_layer *layout_layer;
71 struct wl_list list_screen;
72 uint32_t controller_layer_count;
73 int layer_canbe_removed;
78 struct ivishell *shell;
79 struct ivi_layout_screen *layout_screen;
80 struct weston_output *output;
83 struct ivicontroller_surface {
84 struct wl_resource *resource;
87 struct wl_client *client;
89 struct ivishell *shell;
90 int implementation_set;
93 struct ivicontroller_layer {
94 struct wl_resource *resource;
97 struct wl_client *client;
99 struct ivishell *shell;
102 struct ivicontroller_screen {
103 struct wl_resource *resource;
106 struct wl_client *client;
108 struct ivishell *shell;
111 struct ivicontroller {
112 struct wl_resource *resource;
114 struct wl_client *client;
116 struct ivishell *shell;
119 struct link_shell_weston_surface
121 struct wl_resource *resource;
122 struct wl_listener destroy_listener;
123 struct weston_surface *surface;
128 struct wl_resource *resource;
130 struct wl_listener destroy_listener;
132 struct weston_compositor *compositor;
134 struct weston_surface *surface;
136 struct weston_process process;
138 struct weston_seat *seat;
140 struct wl_list list_surface;
141 struct wl_list list_layer;
142 struct wl_list list_screen;
144 struct wl_list list_weston_surface;
146 struct wl_list list_controller;
147 struct wl_list list_controller_surface;
148 struct wl_list list_controller_layer;
149 struct wl_list list_controller_screen;
152 struct weston_process process;
153 struct wl_client *client;
154 struct wl_resource *desktop_shell;
162 int event_restriction;
164 static void surface_event_remove(struct ivi_layout_surface *, void *);
166 static struct ivi_layout_layer_properties no_layer_props;
167 static struct ivi_layout_surface_properties no_surface_props;
172 destroy_ivicontroller_surface(struct wl_resource *resource)
174 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
175 struct ivishell *shell = ivisurf->shell;
176 struct ivicontroller_surface *ctrlsurf = NULL;
177 struct ivicontroller_surface *next = NULL;
180 wl_list_for_each_safe(ctrlsurf, next,
181 &shell->list_controller_surface, link) {
183 if (resource != ctrlsurf->resource) {
187 if (!wl_list_empty(&ctrlsurf->link)) {
188 wl_list_remove(&ctrlsurf->link);
194 --ivisurf->controller_surface_count;
198 if ((is_removed) && (ivisurf->controller_surface_count == 0)) {
199 if (ivisurf->can_be_removed) {
206 destroy_ivicontroller_layer(struct wl_resource *resource)
208 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
209 struct ivishell *shell = ivilayer->shell;
210 struct ivicontroller_layer *ctrllayer = NULL;
211 struct ivicontroller_layer *next = NULL;
212 uint32_t id_layer = 0;
214 id_layer = ivi_layout_get_id_of_layer(ivilayer->layout_layer);
216 wl_list_for_each_safe(ctrllayer, next,
217 &shell->list_controller_layer, link) {
219 if (resource != ctrllayer->resource) {
223 wl_list_remove(&ctrllayer->link);
224 --ivilayer->controller_layer_count;
225 ivi_controller_layer_send_destroyed(ctrllayer->resource);
231 if ((ivilayer->layout_layer != NULL) &&
232 (ivilayer->controller_layer_count == 0) &&
233 (ivilayer->layer_canbe_removed == 1)) {
234 ivi_layout_layer_remove(ivilayer->layout_layer);
239 destroy_ivicontroller_screen(struct wl_resource *resource)
241 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
242 struct ivicontroller_screen *ctrlscrn = NULL;
243 struct ivicontroller_screen *next = NULL;
245 wl_list_for_each_safe(ctrlscrn, next,
246 &iviscrn->shell->list_controller_screen, link) {
247 // TODO : Only Single display
249 if (iviscrn->output->id != ctrlscrn->id_screen) {
254 if (resource != ctrlscrn->resource) {
258 wl_list_remove(&ctrlscrn->link);
266 unbind_resource_controller(struct wl_resource *resource)
268 struct ivicontroller *controller = wl_resource_get_user_data(resource);
270 wl_list_remove(&controller->link);
276 static struct ivisurface*
277 get_surface(struct wl_list *list_surf, uint32_t id_surface)
279 struct ivisurface *ivisurf = NULL;
280 uint32_t ivisurf_id = 0;
282 wl_list_for_each(ivisurf, list_surf, link) {
283 ivisurf_id = ivi_layout_get_id_of_surface(ivisurf->layout_surface);
284 if (ivisurf_id == id_surface) {
292 static struct ivilayer*
293 get_layer(struct wl_list *list_layer, uint32_t id_layer)
295 struct ivilayer *ivilayer = NULL;
296 uint32_t ivilayer_id = 0;
298 wl_list_for_each(ivilayer, list_layer, link) {
299 ivilayer_id = ivi_layout_get_id_of_layer(ivilayer->layout_layer);
300 if (ivilayer_id == id_layer) {
309 struct ivi_controller_screen_interface controller_screen_implementation;
311 static struct ivicontroller_screen*
312 controller_screen_create(struct ivishell *shell,
313 struct wl_client *client,
314 struct iviscreen *iviscrn)
316 struct ivicontroller_screen *ctrlscrn = NULL;
318 ctrlscrn = calloc(1, sizeof *ctrlscrn);
319 if (ctrlscrn == NULL) {
320 weston_log("no memory to allocate controller screen\n");
324 ctrlscrn->client = client;
325 ctrlscrn->shell = shell;
327 // TODO : Only Single display
329 /* ctrlscrn->id_screen = iviscrn->id_screen; */
331 ctrlscrn->id_screen = 0;
335 wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
336 if (ctrlscrn->resource == NULL) {
337 weston_log("couldn't new screen controller object");
345 wl_resource_set_implementation(ctrlscrn->resource,
346 &controller_screen_implementation,
347 iviscrn, destroy_ivicontroller_screen);
349 wl_list_init(&ctrlscrn->link);
350 wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
356 send_surface_add_event(struct ivisurface *ivisurf,
357 struct wl_resource *resource,
358 enum ivi_layout_notification_mask mask)
360 struct ivi_layout_layer **pArray = NULL;
364 struct link_layer *link_layer = NULL;
365 struct link_layer *next = NULL;
366 struct ivicontroller_layer *ctrllayer = NULL;
367 struct ivilayer *ivilayer = NULL;
368 struct ivishell *shell = ivisurf->shell;
369 uint32_t id_layout_layer = 0;
370 struct wl_client *surface_client = wl_resource_get_client(resource);
373 ans = ivi_layout_get_layers_under_surface(ivisurf->layout_surface,
376 weston_log("failed to get layers at send_surface_add_event\n");
380 /* Send Null to cancel added surface */
381 if (mask & IVI_NOTIFICATION_REMOVE) {
382 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
383 ivi_controller_surface_send_layer(resource, NULL);
386 else if (mask & IVI_NOTIFICATION_ADD) {
387 for (i = 0; i < (int)length; i++) {
388 /* Send new surface event */
390 wl_list_for_each(ivilayer, &shell->list_layer, link) {
391 if (ivilayer->layout_layer == pArray[i]) {
396 if (ivilayer == NULL) {
401 ivi_layout_get_id_of_layer(ivilayer->layout_layer);
402 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
403 if (id_layout_layer != ctrllayer->id_layer) {
407 struct wl_client *layer_client = wl_resource_get_client(ctrllayer->resource);
408 if (surface_client != layer_client) {
412 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
422 send_surface_event(struct wl_resource *resource,
423 struct ivisurface *ivisurf,
424 struct ivi_layout_surface_properties *prop,
427 if (mask & IVI_NOTIFICATION_OPACITY) {
428 ivi_controller_surface_send_opacity(resource,
429 wl_fixed_from_double(prop->opacity));
431 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
432 ivi_controller_surface_send_source_rectangle(resource,
433 prop->source_x, prop->source_y,
434 prop->source_width, prop->source_height);
436 if (mask & IVI_NOTIFICATION_DEST_RECT) {
437 ivi_controller_surface_send_destination_rectangle(resource,
438 prop->dest_x, prop->dest_y,
439 prop->dest_width, prop->dest_height);
441 if (mask & IVI_NOTIFICATION_ORIENTATION) {
442 ivi_controller_surface_send_orientation(resource,
445 if (mask & IVI_NOTIFICATION_VISIBILITY) {
446 ivi_controller_surface_send_visibility(resource,
449 #ifdef SUPPORT_PIXELFORMAT_PROPERTY
450 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
451 ivi_controller_surface_send_pixelformat(resource,
455 if (mask & IVI_NOTIFICATION_KEYBOARD_FOCUS) {
456 ivi_controller_surface_send_input_focus(resource,
457 IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD,
458 prop->has_keyboard_focus);
460 if (mask & IVI_NOTIFICATION_REMOVE) {
461 send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_REMOVE);
463 if (mask & IVI_NOTIFICATION_ADD) {
464 send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_ADD);
469 update_surface_prop(struct ivisurface *ivisurf,
472 struct ivi_layout_layer **pArray = NULL;
476 struct ivishell *shell = ivisurf->shell;
478 ans = ivi_layout_get_layers_under_surface(ivisurf->layout_surface,
481 weston_log("failed to get layers at send_surface_add_event\n");
485 if (mask & IVI_NOTIFICATION_REMOVE) {
486 struct link_layer *link_layer = NULL;
487 struct link_layer *next = NULL;
489 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
490 wl_list_remove(&link_layer->link);
495 if (mask & IVI_NOTIFICATION_ADD) {
496 for (i = 0; i < (int)length; ++i) {
497 /* Create list_layer */
498 struct ivilayer *ivilayer = NULL;
499 struct link_layer *link_layer = calloc(1, sizeof(*link_layer));
500 if (NULL == link_layer) {
503 wl_list_init(&link_layer->link);
504 link_layer->layer = NULL;
505 wl_list_for_each(ivilayer, &shell->list_layer, link) {
506 if (ivilayer->layout_layer == pArray[i]) {
507 link_layer->layer = ivilayer;
512 if (link_layer->layer == NULL) {
518 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
524 send_surface_prop(struct ivi_layout_surface *layout_surface,
525 struct ivi_layout_surface_properties *prop,
526 enum ivi_layout_notification_mask mask,
529 struct ivisurface *ivisurf = userdata;
530 struct ivishell *shell = ivisurf->shell;
531 struct ivicontroller_surface *ctrlsurf = NULL;
532 uint32_t id_surface = 0;
534 id_surface = ivi_layout_get_id_of_surface(layout_surface);
536 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
537 if (id_surface != ctrlsurf->id_surface) {
540 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
543 update_surface_prop(ivisurf, mask);
547 send_layer_add_event(struct ivilayer *ivilayer,
548 struct wl_resource *resource,
549 enum ivi_layout_notification_mask mask)
551 struct ivi_layout_screen **pArray = NULL;
555 struct link_screen *link_scrn = NULL;
556 struct link_screen *next = NULL;
557 struct iviscreen *iviscrn = NULL;
558 struct ivishell *shell = ivilayer->shell;
559 struct wl_client *client = wl_resource_get_client(resource);
560 struct wl_resource *resource_output = NULL;
562 ans = ivi_layout_get_screens_under_layer(ivilayer->layout_layer,
565 weston_log("failed to get screens at send_layer_add_event\n");
569 /* Send Null to cancel added layer */
570 if (mask & IVI_NOTIFICATION_REMOVE) {
571 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
572 ivi_controller_layer_send_screen(resource, NULL);
575 else if (mask & IVI_NOTIFICATION_ADD) {
576 for (i = 0; i < (int)length; i++) {
577 /* Send new layer event */
579 wl_list_for_each(iviscrn, &shell->list_screen, link) {
580 if (iviscrn->layout_screen == pArray[i]) {
585 if (iviscrn == NULL) {
590 wl_resource_find_for_client(&iviscrn->output->resource_list,
592 if (resource_output != NULL) {
593 ivi_controller_layer_send_screen(resource, resource_output);
603 send_layer_event(struct wl_resource *resource,
604 struct ivilayer *ivilayer,
605 struct ivi_layout_layer_properties *prop,
608 if (mask & IVI_NOTIFICATION_OPACITY) {
609 ivi_controller_layer_send_opacity(resource,
610 wl_fixed_from_double(prop->opacity));
612 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
613 ivi_controller_layer_send_source_rectangle(resource,
617 prop->source_height);
619 if (mask & IVI_NOTIFICATION_DEST_RECT) {
620 ivi_controller_layer_send_destination_rectangle(resource,
626 if (mask & IVI_NOTIFICATION_ORIENTATION) {
627 ivi_controller_layer_send_orientation(resource,
630 if (mask & IVI_NOTIFICATION_VISIBILITY) {
631 ivi_controller_layer_send_visibility(resource,
634 if (mask & IVI_NOTIFICATION_REMOVE) {
635 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_REMOVE);
637 if (mask & IVI_NOTIFICATION_ADD) {
638 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_ADD);
643 update_layer_prop(struct ivilayer *ivilayer,
644 enum ivi_layout_notification_mask mask)
646 struct ivi_layout_screen **pArray = NULL;
649 struct link_screen *link_scrn = NULL;
650 struct link_screen *next = NULL;
652 ans = ivi_layout_get_screens_under_layer(ivilayer->layout_layer,
655 weston_log("failed to get screens at send_layer_add_event\n");
659 /* Send Null to cancel added layer */
660 if (mask & IVI_NOTIFICATION_REMOVE) {
661 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
662 wl_list_remove(&link_scrn->link);
667 if (mask & IVI_NOTIFICATION_ADD) {
669 for (i = 0; i < (int)length; i++) {
670 struct ivishell *shell = ivilayer->shell;
671 struct iviscreen *iviscrn = NULL;
672 /* Create list_screen */
673 link_scrn = calloc(1, sizeof(*link_scrn));
674 if (NULL == link_scrn) {
677 wl_list_init(&link_scrn->link);
678 link_scrn->screen = NULL;
679 wl_list_for_each(iviscrn, &shell->list_screen, link) {
680 if (iviscrn->layout_screen == pArray[i]) {
681 link_scrn->screen = iviscrn;
686 if (link_scrn->screen == NULL) {
691 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
700 send_layer_prop(struct ivi_layout_layer *layer,
701 const struct ivi_layout_layer_properties *prop,
702 enum ivi_layout_notification_mask mask,
705 struct ivilayer *ivilayer = userdata;
706 struct ivicontroller_layer *ctrllayer = NULL;
707 struct ivishell *shell = ivilayer->shell;
708 uint32_t id_layout_layer = 0;
710 id_layout_layer = ivi_layout_get_id_of_layer(layer);
711 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
712 if (id_layout_layer != ctrllayer->id_layer) {
715 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
718 update_layer_prop(ivilayer, mask);
722 controller_surface_set_opacity(struct wl_client *client,
723 struct wl_resource *resource,
726 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
728 ivi_layout_surface_set_opacity(ivisurf->layout_surface,
729 wl_fixed_to_double(opacity));
733 controller_surface_set_source_rectangle(struct wl_client *client,
734 struct wl_resource *resource,
740 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
742 ivi_layout_surface_set_source_rectangle(ivisurf->layout_surface,
743 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
747 controller_surface_set_destination_rectangle(struct wl_client *client,
748 struct wl_resource *resource,
754 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
757 // TODO: create set transition type protocol
758 ivi_layout_surface_set_transition(ivisurf->layout_surface,
759 IVI_LAYOUT_TRANSITION_NONE,
762 ivi_layout_surface_set_destination_rectangle(ivisurf->layout_surface,
763 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
767 controller_surface_set_visibility(struct wl_client *client,
768 struct wl_resource *resource,
771 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
773 ivi_layout_surface_set_visibility(ivisurf->layout_surface, visibility);
777 controller_surface_set_configuration(struct wl_client *client,
778 struct wl_resource *resource,
779 int32_t width, int32_t height)
781 /* This interface has been supported yet. */
789 controller_surface_set_orientation(struct wl_client *client,
790 struct wl_resource *resource,
793 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
795 ivi_layout_surface_set_orientation(ivisurf->layout_surface, (uint32_t)orientation);
799 shm_surface_screenshot(struct weston_surface *surface,
803 const char *filename)
805 struct weston_buffer *weston_buffer = NULL;
806 struct wl_shm_buffer *shm_buffer = NULL;
807 cairo_surface_t *cairo_surf = NULL;
808 uint8_t *source_buffer = NULL;
809 uint8_t *dest_buffer = NULL;
811 weston_buffer = surface->buffer_ref.buffer;
812 if (weston_buffer == NULL) {
813 fprintf(stderr, "Failed to get weston buffer.\n");
817 shm_buffer = wl_shm_buffer_get(weston_buffer->resource);
818 if (shm_buffer == NULL) {
822 source_buffer = wl_shm_buffer_get_data(shm_buffer);
823 if (source_buffer == NULL) {
824 fprintf(stderr, "Failed to get data from shm buffer.\n");
828 dest_buffer = malloc(stride * height);
829 if (dest_buffer == NULL) {
830 fprintf(stderr, "Failed to allocate memory.\n");
834 memcpy(dest_buffer, source_buffer, stride * height);
836 cairo_surf = cairo_image_surface_create_for_data(
843 cairo_surface_write_to_png(cairo_surf, filename);
844 cairo_surface_destroy(cairo_surf);
851 bind_framebuffer(GLuint *fbo_id, GLuint *tex_id, GLsizei width, GLsizei height)
853 glGenTextures(1, tex_id);
854 glGenFramebuffers(1, fbo_id);
855 glBindTexture(GL_TEXTURE_2D, *tex_id);
856 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
857 glBindFramebuffer(GL_FRAMEBUFFER, *fbo_id);
858 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *tex_id, 0);
859 glClearColor(0, 0, 0, 0);
860 glClear(GL_COLOR_BUFFER_BIT);
864 unbind_framebuffer(GLuint fbo_id, GLuint tex_id)
866 glBindTexture(GL_TEXTURE_2D, 0);
867 glBindFramebuffer(GL_FRAMEBUFFER, 0);
868 glDeleteTextures(1, &tex_id);
869 glDeleteFramebuffers(1, &fbo_id);
873 dump_surface(struct weston_output *output,
874 struct weston_compositor *compositor,
875 const char *filename,
876 struct weston_view *view,
882 struct weston_renderer *renderer = compositor->renderer;
883 pixman_region32_t region;
884 struct wl_list backup_transformation_list;
885 struct weston_transform *link = NULL;
886 struct weston_transform *next = NULL;
887 uint8_t *readpixs = NULL;
888 int32_t stride = width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
889 GLuint fbo_id, tex_id;
891 readpixs = malloc(stride * height);
892 if (readpixs == NULL) {
893 fprintf(stderr, "Failed to allocate memory.\n");
897 pixman_region32_init_rect(®ion, x, y, width, height);
898 bind_framebuffer(&fbo_id, &tex_id, output->current_mode->width, output->current_mode->height);
900 wl_list_init(&backup_transformation_list);
901 wl_list_for_each_safe(link, next, &view->geometry.transformation_list, link) {
902 wl_list_remove(&link->link);
903 wl_list_insert(&backup_transformation_list, &link->link);
906 wl_list_init(&view->geometry.transformation_list);
907 weston_view_geometry_dirty(view);
908 weston_view_update_transform(view);
910 renderer->repaint_output(output, ®ion);
913 y = output->current_mode->height - (y + height);
914 int result = renderer->read_pixels(output,
915 compositor->read_format,
922 wl_list_for_each_safe(link, next, &backup_transformation_list, link) {
923 wl_list_remove(&link->link);
924 wl_list_insert(&view->geometry.transformation_list, &link->link);
927 weston_view_geometry_dirty(view);
928 weston_view_update_transform(view);
930 unbind_framebuffer(fbo_id, tex_id);
932 save_as_bitmap(filename, readpixs, stride * height, width, height, PIXMAN_FORMAT_BPP(compositor->read_format));
936 static struct weston_view *
937 clear_viewlist_but_specified_surface(struct weston_compositor *compositor,
938 struct weston_surface *surface)
940 struct weston_view *view = NULL;
941 wl_list_init(&compositor->view_list);
943 wl_list_for_each(view, &surface->views, surface_link) {
948 wl_list_insert(compositor->view_list.prev, &view->link);
956 get_gl_surface_rectangle(struct ivi_layout_surface_properties *prop,
968 *width = prop->source_width;
969 *height = prop->source_height;
973 gl_surface_screenshot(struct ivisurface *ivisurf,
974 struct weston_surface *surface,
975 const char *filename)
977 struct weston_compositor *compositor = surface->compositor;
978 struct ivishell *shell = ivisurf->shell;
979 struct weston_view *view = NULL;
980 struct weston_output *output = NULL;
981 struct iviscreen *link_scrn = NULL;
982 const struct ivi_layout_surface_properties *prop;
988 wl_list_for_each(link_scrn, &shell->list_screen, link) {
989 if (link_scrn != NULL) {
994 if (link_scrn == NULL) {
995 fprintf(stderr, "Failed to get iviscreen\n");
999 if (!(prop = ivi_layout_get_properties_of_surface(ivisurf->layout_surface))) {
1000 fprintf(stderr, "Failed to get surface properties.");
1004 view = clear_viewlist_but_specified_surface(compositor, surface);
1006 int32_t plane_is_null = 0;
1007 if (view->plane == NULL) {
1009 view->plane = &compositor->primary_plane;
1012 get_gl_surface_rectangle(prop, &x, &y, &width, &height);
1013 dump_surface(link_scrn->output,
1022 if (plane_is_null) {
1031 controller_surface_screenshot(struct wl_client *client,
1032 struct wl_resource *resource,
1033 const char *filename)
1035 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1036 struct weston_surface *weston_surface = NULL;
1041 weston_surface = ivi_layout_surface_get_weston_surface(ivisurf->layout_surface);
1042 if (weston_surface == NULL) {
1043 fprintf(stderr, "Failed to get weston surface.\n");
1047 if (ivi_layout_surface_get_size(ivisurf->layout_surface, &width, &height, &stride) != 0) {
1048 fprintf(stderr, "Failed to get surface size.\n");
1052 if (shm_surface_screenshot(weston_surface, width, height, stride, filename) != 0) {
1053 if (gl_surface_screenshot(ivisurf, weston_surface, filename) != 0) {
1054 fprintf(stderr, "Failed to capture surface.\n");
1061 controller_surface_send_stats(struct wl_client *client,
1062 struct wl_resource *resource)
1064 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1068 wl_client_get_credentials(client, &pid, &uid, &gid);
1070 ivi_controller_surface_send_stats(resource, 0, 0,
1071 ivisurf->update_count, pid, "");
1075 controller_surface_destroy(struct wl_client *client,
1076 struct wl_resource *resource,
1077 int32_t destroy_scene_object)
1080 (void)destroy_scene_object;
1081 wl_resource_destroy(resource);
1084 static void send_all_keyboard_focus(struct ivishell *shell)
1086 const struct ivi_layout_surface_properties *props;
1087 struct ivicontroller_surface *ctrlsurf;
1088 struct ivisurface *current_surf;
1089 uint32_t id_surface;
1091 wl_list_for_each(current_surf, &shell->list_surface, link) {
1092 if (!(props = ivi_layout_get_properties_of_surface(current_surf->layout_surface)))
1093 props = &no_surface_props;
1095 id_surface = ivi_layout_get_id_of_surface(current_surf->layout_surface);
1096 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1097 if (id_surface != ctrlsurf->id_surface) {
1100 ivi_controller_surface_send_input_focus(ctrlsurf->resource,
1101 IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD,
1102 props->has_keyboard_focus);
1108 controller_surface_set_input_focus(struct wl_client *client,
1109 struct wl_resource *resource,
1114 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1116 if (device & IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD) {
1118 ivi_layout_set_keyboard_focus_on(ivisurf->layout_surface);
1119 send_all_keyboard_focus(ivisurf->shell);
1125 struct ivi_controller_surface_interface controller_surface_implementation = {
1126 controller_surface_set_visibility,
1127 controller_surface_set_opacity,
1128 controller_surface_set_source_rectangle,
1129 controller_surface_set_destination_rectangle,
1130 controller_surface_set_configuration,
1131 controller_surface_set_orientation,
1132 controller_surface_screenshot,
1133 controller_surface_send_stats,
1134 controller_surface_destroy,
1135 controller_surface_set_input_focus
1139 controller_layer_set_source_rectangle(struct wl_client *client,
1140 struct wl_resource *resource,
1146 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1148 ivi_layout_layer_set_source_rectangle(ivilayer->layout_layer,
1149 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
1153 controller_layer_set_destination_rectangle(struct wl_client *client,
1154 struct wl_resource *resource,
1160 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1162 ivi_layout_layer_set_destination_rectangle(ivilayer->layout_layer,
1163 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
1167 controller_layer_set_visibility(struct wl_client *client,
1168 struct wl_resource *resource,
1169 uint32_t visibility)
1171 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1173 ivi_layout_layer_set_visibility(ivilayer->layout_layer, visibility);
1177 controller_layer_set_opacity(struct wl_client *client,
1178 struct wl_resource *resource,
1181 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1183 ivi_layout_layer_set_opacity(ivilayer->layout_layer,
1184 wl_fixed_to_double(opacity));
1188 controller_layer_set_configuration(struct wl_client *client,
1189 struct wl_resource *resource,
1193 /* This interface has been supported yet. */
1201 controller_layer_set_orientation(struct wl_client *client,
1202 struct wl_resource *resource,
1203 int32_t orientation)
1205 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1207 ivi_layout_layer_set_orientation(ivilayer->layout_layer, (uint32_t)orientation);
1211 controller_layer_clear_surfaces(struct wl_client *client,
1212 struct wl_resource *resource)
1214 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1216 ivi_layout_layer_set_render_order(ivilayer->layout_layer, NULL, 0);
1220 controller_layer_add_surface(struct wl_client *client,
1221 struct wl_resource *resource,
1222 struct wl_resource *surface)
1224 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1225 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
1227 ivi_layout_layer_add_surface(ivilayer->layout_layer, ivisurf->layout_surface);
1231 controller_layer_remove_surface(struct wl_client *client,
1232 struct wl_resource *resource,
1233 struct wl_resource *surface)
1235 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1236 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
1238 ivi_layout_layer_remove_surface(ivilayer->layout_layer, ivisurf->layout_surface);
1242 controller_layer_screenshot(struct wl_client *client,
1243 struct wl_resource *resource,
1244 const char *filename)
1252 controller_layer_set_render_order(struct wl_client *client,
1253 struct wl_resource *resource,
1254 struct wl_array *id_surfaces)
1256 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1257 struct ivi_layout_surface **layoutsurf_array = NULL;
1258 struct ivisurface *ivisurf = NULL;
1259 uint32_t *id_surface = NULL;
1260 uint32_t id_layout_surface = 0;
1264 layoutsurf_array = (struct ivi_layout_surface**)calloc(
1265 id_surfaces->size, sizeof(void*));
1267 wl_array_for_each(id_surface, id_surfaces) {
1268 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
1269 id_layout_surface = ivi_layout_get_id_of_surface(ivisurf->layout_surface);
1270 if (*id_surface == id_layout_surface) {
1271 layoutsurf_array[i] = ivisurf->layout_surface;
1278 ivi_layout_layer_set_render_order(ivilayer->layout_layer,
1279 layoutsurf_array, i);
1280 free(layoutsurf_array);
1284 controller_layer_destroy(struct wl_client *client,
1285 struct wl_resource *resource,
1286 int32_t destroy_scene_object)
1288 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1289 struct ivishell *shell = ivilayer->shell;
1290 struct ivicontroller_layer *ctrllayer = NULL;
1291 struct ivicontroller_layer *next = NULL;
1292 uint32_t id_layer = ivi_layout_get_id_of_layer(ivilayer->layout_layer);
1294 (void)destroy_scene_object;
1296 ivilayer->layer_canbe_removed = 1;
1297 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
1298 if (ctrllayer->id_layer != id_layer) {
1302 wl_resource_destroy(ctrllayer->resource);
1307 struct ivi_controller_layer_interface controller_layer_implementation = {
1308 controller_layer_set_visibility,
1309 controller_layer_set_opacity,
1310 controller_layer_set_source_rectangle,
1311 controller_layer_set_destination_rectangle,
1312 controller_layer_set_configuration,
1313 controller_layer_set_orientation,
1314 controller_layer_screenshot,
1315 controller_layer_clear_surfaces,
1316 controller_layer_add_surface,
1317 controller_layer_remove_surface,
1318 controller_layer_set_render_order,
1319 controller_layer_destroy
1323 controller_screen_destroy(struct wl_client *client,
1324 struct wl_resource *resource)
1326 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1327 struct ivicontroller_screen *ctrlscrn = NULL;
1328 struct ivicontroller_screen *next = NULL;
1329 // uint32_t id_screen = ivi_layout_get_id_of_screen(iviscrn->layout_screen);
1332 wl_list_for_each_safe(ctrlscrn, next,
1333 &iviscrn->shell->list_controller_screen, link) {
1334 if (resource != ctrlscrn->resource) {
1338 wl_list_remove(&ctrlscrn->link);
1339 wl_resource_destroy(ctrlscrn->resource);
1347 controller_screen_clear(struct wl_client *client,
1348 struct wl_resource *resource)
1350 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1352 ivi_layout_screen_set_render_order(iviscrn->layout_screen, NULL, 0);
1356 controller_screen_add_layer(struct wl_client *client,
1357 struct wl_resource *resource,
1358 struct wl_resource *layer)
1360 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1361 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
1363 ivi_layout_screen_add_layer(iviscrn->layout_screen, ivilayer->layout_layer);
1367 controller_screen_screenshot(struct wl_client *client,
1368 struct wl_resource *resource,
1369 const char *filename)
1371 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1374 struct weston_output *output = NULL;
1375 cairo_surface_t *cairo_surf = NULL;
1380 uint8_t *readpixs = NULL;
1382 output = ivi_layout_screen_get_output(iviscrn->layout_screen);
1383 --output->disable_planes;
1385 width = output->current_mode->width;
1386 height = output->current_mode->height;
1387 stride = width * (PIXMAN_FORMAT_BPP(output->compositor->read_format) / 8);
1389 readpixs = malloc(stride * height);
1390 if (readpixs == NULL) {
1391 weston_log("fails to allocate memory\n");
1395 output->compositor->renderer->read_pixels(
1397 output->compositor->read_format,
1404 save_as_bitmap(filename, readpixs, stride * height, width, height, PIXMAN_FORMAT_BPP(output->compositor->read_format));
1409 controller_screen_set_render_order(struct wl_client *client,
1410 struct wl_resource *resource,
1411 struct wl_array *id_layers)
1413 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1414 struct ivi_layout_layer **layoutlayer_array = NULL;
1415 struct ivilayer *ivilayer = NULL;
1416 uint32_t *id_layer = NULL;
1417 uint32_t id_layout_layer = 0;
1421 layoutlayer_array = (struct ivi_layout_layer**)calloc(
1422 id_layers->size, sizeof(void*));
1424 wl_array_for_each(id_layer, id_layers) {
1425 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1426 id_layout_layer = ivi_layout_get_id_of_layer(ivilayer->layout_layer);
1427 if (*id_layer == id_layout_layer) {
1428 layoutlayer_array[i] = ivilayer->layout_layer;
1435 ivi_layout_screen_set_render_order(iviscrn->layout_screen,
1436 layoutlayer_array, i);
1437 free(layoutlayer_array);
1441 struct ivi_controller_screen_interface controller_screen_implementation = {
1442 controller_screen_destroy,
1443 controller_screen_clear,
1444 controller_screen_add_layer,
1445 controller_screen_screenshot,
1446 controller_screen_set_render_order
1450 controller_commit_changes(struct wl_client *client,
1451 struct wl_resource *resource)
1457 ans = ivi_layout_commit_changes();
1459 weston_log("Failed to commit changes at controller_commit_changes\n");
1464 controller_layer_create(struct wl_client *client,
1465 struct wl_resource *resource,
1471 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1472 struct ivishell *shell = ctrl->shell;
1473 struct ivi_layout_layer *layout_layer = NULL;
1474 struct ivicontroller_layer *ctrllayer = NULL;
1475 struct ivilayer *ivilayer = NULL;
1476 const struct ivi_layout_layer_properties *prop;
1478 ivilayer = get_layer(&shell->list_layer, id_layer);
1479 if (ivilayer == NULL) {
1480 layout_layer = ivi_layout_layer_create_with_dimension(id_layer,
1481 (uint32_t)width, (uint32_t)height);
1482 if (layout_layer == NULL) {
1483 weston_log("id_layer is already created\n");
1487 /* ivilayer will be created by layer_event_create */
1488 ivilayer = get_layer(&shell->list_layer, id_layer);
1489 if (ivilayer == NULL) {
1490 weston_log("couldn't get layer object\n");
1495 ctrllayer = calloc(1, sizeof *ctrllayer);
1497 weston_log("no memory to allocate client layer\n");
1501 ++ivilayer->controller_layer_count;
1502 ivilayer->layer_canbe_removed = 0;
1504 ctrllayer->shell = shell;
1505 ctrllayer->client = client;
1507 ctrllayer->id_layer = id_layer;
1508 ctrllayer->resource = wl_resource_create(client,
1509 &ivi_controller_layer_interface, 1, id);
1510 if (ctrllayer->resource == NULL) {
1511 weston_log("couldn't get layer object\n");
1515 wl_list_init(&ctrllayer->link);
1516 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1518 wl_resource_set_implementation(ctrllayer->resource,
1519 &controller_layer_implementation,
1520 ivilayer, destroy_ivicontroller_layer);
1522 if (!(prop = ivi_layout_get_properties_of_layer(ivilayer->layout_layer)))
1523 prop = &no_layer_props;
1525 send_layer_event(ctrllayer->resource, ivilayer,
1526 prop, IVI_NOTIFICATION_ALL);
1530 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1532 struct ivishell *shell = userdata;
1533 struct ivicontroller_surface *ctrlsurf = NULL;
1534 uint32_t id_surface = 0;
1537 surface_event_remove(layout_surface, userdata);
1542 controller_surface_create(struct wl_client *client,
1543 struct wl_resource *resource,
1544 uint32_t id_surface,
1547 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1548 struct ivishell *shell = ctrl->shell;
1549 struct ivicontroller_surface *ctrlsurf = NULL;
1550 const struct ivi_layout_surface_properties *prop;
1551 struct ivisurface *ivisurf = NULL;
1552 struct ivicontroller_surface *ctrl_link = NULL;
1554 ivisurf = get_surface(&shell->list_surface, id_surface);
1555 if (ivisurf == NULL) {
1559 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1561 weston_log("no memory to allocate controller surface\n");
1565 ctrlsurf->shell = shell;
1566 ctrlsurf->client = client;
1568 ctrlsurf->id_surface = id_surface;
1569 wl_list_init(&ctrlsurf->link);
1570 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1572 ctrlsurf->resource = wl_resource_create(client,
1573 &ivi_controller_surface_interface, 1, id);
1574 if (ctrlsurf->resource == NULL) {
1575 weston_log("couldn't surface object");
1579 wl_list_for_each(ctrl_link, &shell->list_controller_surface, link) {
1580 if ((ctrl_link->implementation_set == 0) &&
1581 (ctrl_link->id_surface == id_surface) &&
1582 (ctrl_link->shell == shell) &&
1583 (ctrl_link->client != client)) {
1584 ++ivisurf->controller_surface_count;
1585 wl_resource_set_implementation(ctrl_link->resource,
1586 &controller_surface_implementation,
1587 ivisurf, destroy_ivicontroller_surface);
1588 ctrl_link->implementation_set = 1;
1592 ++ivisurf->controller_surface_count;
1594 wl_resource_set_implementation(ctrlsurf->resource,
1595 &controller_surface_implementation,
1596 ivisurf, destroy_ivicontroller_surface);
1598 ctrlsurf->implementation_set = 1;
1600 if (!(prop = ivi_layout_get_properties_of_surface(ivisurf->layout_surface)))
1601 prop = &no_surface_props;
1603 ivi_layout_surface_set_content_observer(ivisurf->layout_surface, surface_event_content, shell);
1605 send_surface_event(ctrlsurf->resource, ivisurf,
1606 prop, IVI_NOTIFICATION_ALL);
1610 controller_get_native_handle(struct wl_client *client,
1611 struct wl_resource *resource,
1612 uint32_t id_process,
1615 struct wl_array surfaces;
1616 ivi_shell_get_shell_surfaces(&surfaces);
1617 struct shell_surface ** surface;
1619 wl_array_for_each(surface, &surfaces) {
1621 uint32_t pid = shell_surface_get_process_id(*surface);
1622 if (pid != id_process) {
1627 char* surface_title = shell_surface_get_title(*surface);
1628 if (strcmp(title, surface_title)) {
1633 struct weston_surface *es = shell_surface_get_surface(*surface);
1635 struct wl_resource *res = wl_resource_create(client, &wl_surface_interface, 1, 0);
1636 wl_resource_set_user_data(res, es);
1638 ivi_controller_send_native_handle(resource, res);
1642 wl_array_release(&surfaces);
1644 int32_t id_object = 0;
1645 ivi_controller_send_error(
1646 resource, id_object, IVI_CONTROLLER_OBJECT_TYPE_SURFACE,
1647 IVI_CONTROLLER_ERROR_CODE_NATIVE_HANDLE_END, "");
1651 controller_set_keyboard_focus(struct wl_client *client,
1652 struct wl_resource *resource,
1653 struct wl_array *surfaces)
1656 /* this supposed to go away in later rteleases as
1657 ivi_layout_set_keyboard_focus_on() nowadays takes a single surface
1658 as opposed to an array */
1659 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1660 ivi_layout_set_keyboard_focus_on(surfaces->data, surfaces->size);
1661 send_all_keyboard_focus(ctrl->shell);
1665 static const struct ivi_controller_interface controller_implementation = {
1666 controller_commit_changes,
1667 controller_layer_create,
1668 controller_surface_create,
1669 controller_set_keyboard_focus,
1670 controller_get_native_handle
1674 add_client_to_resources(struct ivishell *shell,
1675 struct wl_client *client,
1676 struct ivicontroller *controller)
1678 struct ivisurface* ivisurf = NULL;
1679 struct ivilayer* ivilayer = NULL;
1680 struct iviscreen* iviscrn = NULL;
1681 struct ivicontroller_screen *ctrlscrn = NULL;
1682 struct wl_resource *resource_output = NULL;
1683 uint32_t id_layout_surface = 0;
1684 uint32_t id_layout_layer = 0;
1685 struct ivi_layout_surface *layout_surface;
1687 const char *window_title;
1689 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1690 resource_output = wl_resource_find_for_client(
1691 &iviscrn->output->resource_list, client);
1692 if (resource_output == NULL) {
1696 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1697 if (ctrlscrn == NULL) {
1701 ivi_controller_send_screen(controller->resource,
1702 wl_resource_get_id(resource_output),
1703 ctrlscrn->resource);
1705 wl_list_for_each_reverse(ivilayer, &shell->list_layer, link) {
1707 ivi_layout_get_id_of_layer(ivilayer->layout_layer);
1709 ivi_controller_send_layer(controller->resource,
1712 wl_list_for_each_reverse(ivisurf, &shell->list_surface, link) {
1713 layout_surface = ivisurf->layout_surface;
1714 id_layout_surface = ivi_layout_get_id_of_surface(layout_surface);
1716 get_wl_shell_info(layout_surface, id_layout_surface,
1717 &pid, &window_title);
1719 ivi_controller_send_surface(controller->resource,
1720 id_layout_surface, pid, window_title);
1725 bind_ivi_controller(struct wl_client *client, void *data,
1726 uint32_t version, uint32_t id)
1728 struct ivishell *shell = data;
1729 struct ivicontroller *controller;
1732 controller = calloc(1, sizeof *controller);
1733 if (controller == NULL) {
1734 weston_log("no memory to allocate controller\n");
1738 controller->resource =
1739 wl_resource_create(client, &ivi_controller_interface, 1, id);
1740 wl_resource_set_implementation(controller->resource,
1741 &controller_implementation,
1742 controller, unbind_resource_controller);
1744 controller->shell = shell;
1745 controller->client = client;
1746 controller->id = id;
1748 wl_list_init(&controller->link);
1749 wl_list_insert(&shell->list_controller, &controller->link);
1751 add_client_to_resources(shell, client, controller);
1754 static struct iviscreen*
1755 create_screen(struct ivishell *shell, struct weston_output *output)
1757 struct iviscreen *iviscrn;
1758 iviscrn = calloc(1, sizeof *iviscrn);
1759 if (iviscrn == NULL) {
1760 weston_log("no memory to allocate client screen\n");
1764 iviscrn->shell = shell;
1765 iviscrn->output = output;
1767 // TODO : Only Single display
1768 iviscrn->layout_screen = ivi_layout_get_screen_from_id(0);
1770 wl_list_init(&iviscrn->link);
1775 static struct ivilayer*
1776 create_layer(struct ivishell *shell,
1777 struct ivi_layout_layer *layout_layer,
1780 struct ivilayer *ivilayer = NULL;
1781 struct ivicontroller *controller = NULL;
1783 ivilayer = get_layer(&shell->list_layer, id_layer);
1784 if (ivilayer != NULL) {
1785 weston_log("id_layer is already created\n");
1789 ivilayer = calloc(1, sizeof *ivilayer);
1790 if (NULL == ivilayer) {
1791 weston_log("no memory to allocate client layer\n");
1795 ivilayer->shell = shell;
1796 wl_list_init(&ivilayer->list_screen);
1797 wl_list_init(&ivilayer->link);
1798 wl_list_insert(&shell->list_layer, &ivilayer->link);
1799 ivilayer->layout_layer = layout_layer;
1801 ivi_layout_layer_add_notification(layout_layer, send_layer_prop, ivilayer);
1803 wl_list_for_each(controller, &shell->list_controller, link) {
1804 ivi_controller_send_layer(controller->resource, id_layer);
1810 static struct ivisurface*
1811 create_surface(struct ivishell *shell,
1812 struct ivi_layout_surface *layout_surface,
1813 uint32_t id_surface)
1815 struct ivisurface *ivisurf = NULL;
1816 struct ivicontroller *controller = NULL;
1818 const char *window_title;
1820 ivisurf = get_surface(&shell->list_surface, id_surface);
1821 if (ivisurf != NULL) {
1822 weston_log("id_surface is already created\n");
1826 ivisurf = calloc(1, sizeof *ivisurf);
1827 if (ivisurf == NULL) {
1828 weston_log("no memory to allocate client surface\n");
1832 ivisurf->shell = shell;
1833 ivisurf->layout_surface = layout_surface;
1834 wl_list_init(&ivisurf->list_layer);
1835 wl_list_init(&ivisurf->link);
1836 wl_list_insert(&shell->list_surface, &ivisurf->link);
1838 get_wl_shell_info(layout_surface, id_surface, &pid, &window_title);
1840 wl_list_for_each(controller, &shell->list_controller, link) {
1841 ivi_controller_send_surface(controller->resource,
1842 id_surface, pid, window_title);
1845 ivi_layout_surface_add_notification(layout_surface,
1846 send_surface_prop, ivisurf);
1852 layer_event_create(struct ivi_layout_layer *layout_layer,
1855 struct ivishell *shell = userdata;
1856 struct ivilayer *ivilayer = NULL;
1857 uint32_t id_layer = 0;
1859 id_layer = ivi_layout_get_id_of_layer(layout_layer);
1861 ivilayer = create_layer(shell, layout_layer, id_layer);
1862 if (ivilayer == NULL) {
1863 weston_log("failed to create layer");
1869 layer_event_remove(struct ivi_layout_layer *layout_layer,
1872 struct ivishell *shell = userdata;
1873 struct ivicontroller_layer *ctrllayer = NULL;
1874 struct ivilayer *ivilayer = NULL;
1875 struct ivilayer *next = NULL;
1876 uint32_t id_layer = 0;
1879 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1880 if (layout_layer != ivilayer->layout_layer) {
1884 wl_list_remove(&ivilayer->link);
1893 id_layer = ivi_layout_get_id_of_layer(layout_layer);
1895 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1896 if (id_layer != ctrllayer->id_layer) {
1899 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1906 surface_event_create(struct ivi_layout_surface *layout_surface,
1909 struct ivishell *shell = userdata;
1910 struct ivisurface *ivisurf = NULL;
1911 uint32_t id_surface = 0;
1912 struct ivicontroller_surface *ctrlsurf = NULL;
1914 id_surface = ivi_layout_get_id_of_surface(layout_surface);
1916 ivisurf = create_surface(shell, layout_surface, id_surface);
1917 if (ivisurf == NULL) {
1918 weston_log("failed to create surface");
1922 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1923 if (id_surface != ctrlsurf->id_surface) {
1926 ivi_controller_surface_send_content(ctrlsurf->resource, IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_AVAILABLE);
1931 surface_event_remove(struct ivi_layout_surface *layout_surface,
1934 struct ivishell *shell = userdata;
1935 struct ivicontroller_surface *ctrlsurf = NULL;
1936 struct ivisurface *ivisurf = NULL;
1937 struct ivisurface *next = NULL;
1938 uint32_t id_surface = 0;
1941 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1942 if (layout_surface != ivisurf->layout_surface) {
1946 wl_list_remove(&ivisurf->link);
1949 if (ivisurf->controller_surface_count == 0) {
1953 ivisurf->can_be_removed = 1;
1960 id_surface = ivi_layout_get_id_of_surface(layout_surface);
1962 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1963 if (id_surface != ctrlsurf->id_surface) {
1966 ivi_controller_surface_send_content(ctrlsurf->resource, IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED);
1967 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1973 surface_event_configure(struct ivi_layout_surface *layout_surface,
1976 struct ivishell *shell = userdata;
1977 struct ivisurface *ivisurf = NULL;
1978 struct ivicontroller_surface *ctrlsurf = NULL;
1979 struct ivi_layout_surface_properties *prop;
1980 uint32_t id_surface = 0;
1982 id_surface = ivi_layout_get_id_of_surface(layout_surface);
1984 ivisurf = get_surface(&shell->list_surface, id_surface);
1985 if (ivisurf == NULL) {
1986 weston_log("id_surface is not created yet\n");
1990 if (!(prop = ivi_layout_get_properties_of_surface(layout_surface)))
1991 prop = &no_surface_props;
1993 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1994 if (id_surface != ctrlsurf->id_surface) {
1997 send_surface_event(ctrlsurf->resource, ivisurf,
1998 prop, IVI_NOTIFICATION_ALL);
2003 check_layout_layers(struct ivishell *shell)
2005 struct ivi_layout_layer **pArray = NULL;
2006 struct ivilayer *ivilayer = NULL;
2007 uint32_t id_layer = 0;
2008 uint32_t length = 0;
2012 ret = ivi_layout_get_layers(&length, &pArray);
2014 weston_log("failed to get layers at check_layout_layers\n");
2019 /* if length is 0, pArray doesn't need to free.*/
2023 for (i = 0; i < length; i++) {
2024 id_layer = ivi_layout_get_id_of_layer(pArray[i]);
2025 ivilayer = create_layer(shell, pArray[i], id_layer);
2026 if (ivilayer == NULL) {
2027 weston_log("failed to create layer");
2038 check_layout_surfaces(struct ivishell *shell)
2040 struct ivi_layout_surface **pArray = NULL;
2041 struct ivisurface *ivisurf = NULL;
2042 uint32_t id_surface = 0;
2043 uint32_t length = 0;
2047 ret = ivi_layout_get_surfaces(&length, &pArray);
2049 weston_log("failed to get surfaces at check_layout_surfaces\n");
2054 /* if length is 0, pArray doesn't need to free.*/
2058 for (i = 0; i < length; i++) {
2059 id_surface = ivi_layout_get_id_of_surface(pArray[i]);
2060 ivisurf = create_surface(shell, pArray[i], id_surface);
2061 if (ivisurf == NULL) {
2062 weston_log("failed to create surface");
2073 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
2075 struct weston_output *output = NULL;
2076 struct iviscreen *iviscrn = NULL;
2079 shell->compositor = ec;
2081 wl_list_init(&shell->list_surface);
2082 wl_list_init(&shell->list_layer);
2083 wl_list_init(&shell->list_screen);
2084 wl_list_init(&shell->list_weston_surface);
2085 wl_list_init(&shell->list_controller);
2086 wl_list_init(&shell->list_controller_screen);
2087 wl_list_init(&shell->list_controller_layer);
2088 wl_list_init(&shell->list_controller_surface);
2089 shell->event_restriction = 0;
2091 wl_list_for_each(output, &ec->output_list, link) {
2092 iviscrn = create_screen(shell, output);
2093 if (iviscrn != NULL) {
2094 wl_list_insert(&shell->list_screen, &iviscrn->link);
2098 ret = check_layout_layers(shell);
2100 weston_log("failed to check_layout_layers");
2103 ret = check_layout_surfaces(shell);
2105 weston_log("failed to check_layout_surfaces");
2108 ivi_layout_add_notification_create_layer(layer_event_create, shell);
2109 ivi_layout_add_notification_remove_layer(layer_event_remove, shell);
2111 ivi_layout_add_notification_create_surface(surface_event_create, shell);
2112 ivi_layout_add_notification_remove_surface(surface_event_remove, shell);
2113 ivi_layout_add_notification_configure_surface(surface_event_configure, shell);
2117 module_init(struct weston_compositor *ec,
2118 int *argc, char *argv[])
2120 struct ivishell *shell;
2124 shell = malloc(sizeof *shell);
2128 memset(shell, 0, sizeof *shell);
2129 init_ivi_shell(ec, shell);
2131 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
2132 shell, bind_ivi_controller) == NULL) {