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 #ifdef SUPPORT_INPUT_FOCUS
456 if (mask & IVI_NOTIFICATION_KEYBOARD_FOCUS) {
457 ivi_controller_surface_send_input_focus(resource,
458 IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD,
459 prop->has_keyboard_focus);
462 if (mask & IVI_NOTIFICATION_REMOVE) {
463 send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_REMOVE);
465 if (mask & IVI_NOTIFICATION_ADD) {
466 send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_ADD);
471 update_surface_prop(struct ivisurface *ivisurf,
474 struct ivi_layout_layer **pArray = NULL;
478 struct ivishell *shell = ivisurf->shell;
480 ans = ivi_layout_get_layers_under_surface(ivisurf->layout_surface,
483 weston_log("failed to get layers at send_surface_add_event\n");
487 if (mask & IVI_NOTIFICATION_REMOVE) {
488 struct link_layer *link_layer = NULL;
489 struct link_layer *next = NULL;
491 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
492 wl_list_remove(&link_layer->link);
497 if (mask & IVI_NOTIFICATION_ADD) {
498 for (i = 0; i < (int)length; ++i) {
499 /* Create list_layer */
500 struct ivilayer *ivilayer = NULL;
501 struct link_layer *link_layer = calloc(1, sizeof(*link_layer));
502 if (NULL == link_layer) {
505 wl_list_init(&link_layer->link);
506 link_layer->layer = NULL;
507 wl_list_for_each(ivilayer, &shell->list_layer, link) {
508 if (ivilayer->layout_layer == pArray[i]) {
509 link_layer->layer = ivilayer;
514 if (link_layer->layer == NULL) {
520 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
526 send_surface_prop(struct ivi_layout_surface *layout_surface,
527 struct ivi_layout_surface_properties *prop,
528 enum ivi_layout_notification_mask mask,
531 struct ivisurface *ivisurf = userdata;
532 struct ivishell *shell = ivisurf->shell;
533 struct ivicontroller_surface *ctrlsurf = NULL;
534 uint32_t id_surface = 0;
536 id_surface = ivi_layout_get_id_of_surface(layout_surface);
538 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
539 if (id_surface != ctrlsurf->id_surface) {
542 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
545 update_surface_prop(ivisurf, mask);
549 send_layer_add_event(struct ivilayer *ivilayer,
550 struct wl_resource *resource,
551 enum ivi_layout_notification_mask mask)
553 struct ivi_layout_screen **pArray = NULL;
557 struct link_screen *link_scrn = NULL;
558 struct link_screen *next = NULL;
559 struct iviscreen *iviscrn = NULL;
560 struct ivishell *shell = ivilayer->shell;
561 struct wl_client *client = wl_resource_get_client(resource);
562 struct wl_resource *resource_output = NULL;
564 ans = ivi_layout_get_screens_under_layer(ivilayer->layout_layer,
567 weston_log("failed to get screens at send_layer_add_event\n");
571 /* Send Null to cancel added layer */
572 if (mask & IVI_NOTIFICATION_REMOVE) {
573 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
574 ivi_controller_layer_send_screen(resource, NULL);
577 else if (mask & IVI_NOTIFICATION_ADD) {
578 for (i = 0; i < (int)length; i++) {
579 /* Send new layer event */
581 wl_list_for_each(iviscrn, &shell->list_screen, link) {
582 if (iviscrn->layout_screen == pArray[i]) {
587 if (iviscrn == NULL) {
592 wl_resource_find_for_client(&iviscrn->output->resource_list,
594 if (resource_output != NULL) {
595 ivi_controller_layer_send_screen(resource, resource_output);
605 send_layer_event(struct wl_resource *resource,
606 struct ivilayer *ivilayer,
607 struct ivi_layout_layer_properties *prop,
610 if (mask & IVI_NOTIFICATION_OPACITY) {
611 ivi_controller_layer_send_opacity(resource,
612 wl_fixed_from_double(prop->opacity));
614 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
615 ivi_controller_layer_send_source_rectangle(resource,
619 prop->source_height);
621 if (mask & IVI_NOTIFICATION_DEST_RECT) {
622 ivi_controller_layer_send_destination_rectangle(resource,
628 if (mask & IVI_NOTIFICATION_ORIENTATION) {
629 ivi_controller_layer_send_orientation(resource,
632 if (mask & IVI_NOTIFICATION_VISIBILITY) {
633 ivi_controller_layer_send_visibility(resource,
636 if (mask & IVI_NOTIFICATION_REMOVE) {
637 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_REMOVE);
639 if (mask & IVI_NOTIFICATION_ADD) {
640 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_ADD);
645 update_layer_prop(struct ivilayer *ivilayer,
646 enum ivi_layout_notification_mask mask)
648 struct ivi_layout_screen **pArray = NULL;
651 struct link_screen *link_scrn = NULL;
652 struct link_screen *next = NULL;
654 ans = ivi_layout_get_screens_under_layer(ivilayer->layout_layer,
657 weston_log("failed to get screens at send_layer_add_event\n");
661 /* Send Null to cancel added layer */
662 if (mask & IVI_NOTIFICATION_REMOVE) {
663 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
664 wl_list_remove(&link_scrn->link);
669 if (mask & IVI_NOTIFICATION_ADD) {
671 for (i = 0; i < (int)length; i++) {
672 struct ivishell *shell = ivilayer->shell;
673 struct iviscreen *iviscrn = NULL;
674 /* Create list_screen */
675 link_scrn = calloc(1, sizeof(*link_scrn));
676 if (NULL == link_scrn) {
679 wl_list_init(&link_scrn->link);
680 link_scrn->screen = NULL;
681 wl_list_for_each(iviscrn, &shell->list_screen, link) {
682 if (iviscrn->layout_screen == pArray[i]) {
683 link_scrn->screen = iviscrn;
688 if (link_scrn->screen == NULL) {
693 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
702 send_layer_prop(struct ivi_layout_layer *layer,
703 const struct ivi_layout_layer_properties *prop,
704 enum ivi_layout_notification_mask mask,
707 struct ivilayer *ivilayer = userdata;
708 struct ivicontroller_layer *ctrllayer = NULL;
709 struct ivishell *shell = ivilayer->shell;
710 uint32_t id_layout_layer = 0;
712 id_layout_layer = ivi_layout_get_id_of_layer(layer);
713 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
714 if (id_layout_layer != ctrllayer->id_layer) {
717 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
720 update_layer_prop(ivilayer, mask);
724 controller_surface_set_opacity(struct wl_client *client,
725 struct wl_resource *resource,
728 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
730 ivi_layout_surface_set_opacity(ivisurf->layout_surface,
731 wl_fixed_to_double(opacity));
735 controller_surface_set_source_rectangle(struct wl_client *client,
736 struct wl_resource *resource,
742 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
744 ivi_layout_surface_set_source_rectangle(ivisurf->layout_surface,
745 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
749 controller_surface_set_destination_rectangle(struct wl_client *client,
750 struct wl_resource *resource,
756 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
759 // TODO: create set transition type protocol
760 ivi_layout_surface_set_transition(ivisurf->layout_surface,
761 IVI_LAYOUT_TRANSITION_NONE,
764 ivi_layout_surface_set_destination_rectangle(ivisurf->layout_surface,
765 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
769 controller_surface_set_visibility(struct wl_client *client,
770 struct wl_resource *resource,
773 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
775 ivi_layout_surface_set_visibility(ivisurf->layout_surface, visibility);
779 controller_surface_set_configuration(struct wl_client *client,
780 struct wl_resource *resource,
781 int32_t width, int32_t height)
783 /* This interface has been supported yet. */
791 controller_surface_set_orientation(struct wl_client *client,
792 struct wl_resource *resource,
795 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
797 ivi_layout_surface_set_orientation(ivisurf->layout_surface, (uint32_t)orientation);
801 shm_surface_screenshot(struct weston_surface *surface,
805 const char *filename)
807 struct weston_buffer *weston_buffer = NULL;
808 struct wl_shm_buffer *shm_buffer = NULL;
809 cairo_surface_t *cairo_surf = NULL;
810 uint8_t *source_buffer = NULL;
811 uint8_t *dest_buffer = NULL;
813 weston_buffer = surface->buffer_ref.buffer;
814 if (weston_buffer == NULL) {
815 fprintf(stderr, "Failed to get weston buffer.\n");
819 shm_buffer = wl_shm_buffer_get(weston_buffer->resource);
820 if (shm_buffer == NULL) {
824 source_buffer = wl_shm_buffer_get_data(shm_buffer);
825 if (source_buffer == NULL) {
826 fprintf(stderr, "Failed to get data from shm buffer.\n");
830 dest_buffer = malloc(stride * height);
831 if (dest_buffer == NULL) {
832 fprintf(stderr, "Failed to allocate memory.\n");
836 memcpy(dest_buffer, source_buffer, stride * height);
838 cairo_surf = cairo_image_surface_create_for_data(
845 cairo_surface_write_to_png(cairo_surf, filename);
846 cairo_surface_destroy(cairo_surf);
853 bind_framebuffer(GLuint *fbo_id, GLuint *tex_id, GLsizei width, GLsizei height)
855 glGenTextures(1, tex_id);
856 glGenFramebuffers(1, fbo_id);
857 glBindTexture(GL_TEXTURE_2D, *tex_id);
858 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
859 glBindFramebuffer(GL_FRAMEBUFFER, *fbo_id);
860 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *tex_id, 0);
861 glClearColor(0, 0, 0, 0);
862 glClear(GL_COLOR_BUFFER_BIT);
866 unbind_framebuffer(GLuint fbo_id, GLuint tex_id)
868 glBindTexture(GL_TEXTURE_2D, 0);
869 glBindFramebuffer(GL_FRAMEBUFFER, 0);
870 glDeleteTextures(1, &tex_id);
871 glDeleteFramebuffers(1, &fbo_id);
875 dump_surface(struct weston_output *output,
876 struct weston_compositor *compositor,
877 const char *filename,
878 struct weston_view *view,
884 struct weston_renderer *renderer = compositor->renderer;
885 pixman_region32_t region;
886 struct wl_list backup_transformation_list;
887 struct weston_transform *link = NULL;
888 struct weston_transform *next = NULL;
889 uint8_t *readpixs = NULL;
890 int32_t stride = width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
891 GLuint fbo_id, tex_id;
893 readpixs = malloc(stride * height);
894 if (readpixs == NULL) {
895 fprintf(stderr, "Failed to allocate memory.\n");
899 pixman_region32_init_rect(®ion, x, y, width, height);
900 bind_framebuffer(&fbo_id, &tex_id, output->current_mode->width, output->current_mode->height);
902 wl_list_init(&backup_transformation_list);
903 wl_list_for_each_safe(link, next, &view->geometry.transformation_list, link) {
904 wl_list_remove(&link->link);
905 wl_list_insert(&backup_transformation_list, &link->link);
908 wl_list_init(&view->geometry.transformation_list);
909 weston_view_geometry_dirty(view);
910 weston_view_update_transform(view);
912 renderer->repaint_output(output, ®ion);
915 y = output->current_mode->height - (y + height);
916 int result = renderer->read_pixels(output,
917 compositor->read_format,
924 wl_list_for_each_safe(link, next, &backup_transformation_list, link) {
925 wl_list_remove(&link->link);
926 wl_list_insert(&view->geometry.transformation_list, &link->link);
929 weston_view_geometry_dirty(view);
930 weston_view_update_transform(view);
932 unbind_framebuffer(fbo_id, tex_id);
934 save_as_bitmap(filename, readpixs, stride * height, width, height, PIXMAN_FORMAT_BPP(compositor->read_format));
938 static struct weston_view *
939 clear_viewlist_but_specified_surface(struct weston_compositor *compositor,
940 struct weston_surface *surface)
942 struct weston_view *view = NULL;
943 wl_list_init(&compositor->view_list);
945 wl_list_for_each(view, &surface->views, surface_link) {
950 wl_list_insert(compositor->view_list.prev, &view->link);
958 get_gl_surface_rectangle(struct ivi_layout_surface_properties *prop,
970 *width = prop->source_width;
971 *height = prop->source_height;
975 gl_surface_screenshot(struct ivisurface *ivisurf,
976 struct weston_surface *surface,
977 const char *filename)
979 struct weston_compositor *compositor = surface->compositor;
980 struct ivishell *shell = ivisurf->shell;
981 struct weston_view *view = NULL;
982 struct weston_output *output = NULL;
983 struct iviscreen *link_scrn = NULL;
984 const struct ivi_layout_surface_properties *prop;
990 wl_list_for_each(link_scrn, &shell->list_screen, link) {
991 if (link_scrn != NULL) {
996 if (link_scrn == NULL) {
997 fprintf(stderr, "Failed to get iviscreen\n");
1001 if (!(prop = ivi_layout_get_properties_of_surface(ivisurf->layout_surface))) {
1002 fprintf(stderr, "Failed to get surface properties.");
1006 view = clear_viewlist_but_specified_surface(compositor, surface);
1008 int32_t plane_is_null = 0;
1009 if (view->plane == NULL) {
1011 view->plane = &compositor->primary_plane;
1014 get_gl_surface_rectangle(prop, &x, &y, &width, &height);
1015 dump_surface(link_scrn->output,
1024 if (plane_is_null) {
1033 controller_surface_screenshot(struct wl_client *client,
1034 struct wl_resource *resource,
1035 const char *filename)
1037 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1038 struct weston_surface *weston_surface = NULL;
1043 weston_surface = ivi_layout_surface_get_weston_surface(ivisurf->layout_surface);
1044 if (weston_surface == NULL) {
1045 fprintf(stderr, "Failed to get weston surface.\n");
1049 if (ivi_layout_surface_get_size(ivisurf->layout_surface, &width, &height, &stride) != 0) {
1050 fprintf(stderr, "Failed to get surface size.\n");
1054 if (shm_surface_screenshot(weston_surface, width, height, stride, filename) != 0) {
1055 if (gl_surface_screenshot(ivisurf, weston_surface, filename) != 0) {
1056 fprintf(stderr, "Failed to capture surface.\n");
1063 controller_surface_send_stats(struct wl_client *client,
1064 struct wl_resource *resource)
1066 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1070 wl_client_get_credentials(client, &pid, &uid, &gid);
1072 ivi_controller_surface_send_stats(resource, 0, 0,
1073 ivisurf->update_count, pid, "");
1077 controller_surface_destroy(struct wl_client *client,
1078 struct wl_resource *resource,
1079 int32_t destroy_scene_object)
1082 (void)destroy_scene_object;
1083 wl_resource_destroy(resource);
1086 static void send_all_keyboard_focus(struct ivishell *shell)
1088 #ifdef SUPPORT_INPUT_FOCUS
1089 const struct ivi_layout_surface_properties *props;
1090 struct ivicontroller_surface *ctrlsurf;
1091 struct ivisurface *current_surf;
1092 uint32_t id_surface;
1094 wl_list_for_each(current_surf, &shell->list_surface, link) {
1095 if (!(props = ivi_layout_get_properties_of_surface(current_surf->layout_surface)))
1096 props = &no_surface_props;
1098 id_surface = ivi_layout_get_id_of_surface(current_surf->layout_surface);
1099 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1100 if (id_surface != ctrlsurf->id_surface) {
1103 ivi_controller_surface_send_input_focus(ctrlsurf->resource,
1104 IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD,
1105 props->has_keyboard_focus);
1112 controller_surface_set_input_focus(struct wl_client *client,
1113 struct wl_resource *resource,
1117 #ifdef SUPPORT_INPUT_FOCUS
1119 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1121 if (device & IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD) {
1123 uint32_t id = ivi_layout_get_id_of_surface(ivisurf->layout_surface);
1124 ivi_layout_set_keyboard_focus_on(&id, 1);
1125 send_all_keyboard_focus(ivisurf->shell);
1132 struct ivi_controller_surface_interface controller_surface_implementation = {
1133 controller_surface_set_visibility,
1134 controller_surface_set_opacity,
1135 controller_surface_set_source_rectangle,
1136 controller_surface_set_destination_rectangle,
1137 controller_surface_set_configuration,
1138 controller_surface_set_orientation,
1139 controller_surface_screenshot,
1140 controller_surface_send_stats,
1141 controller_surface_destroy,
1142 controller_surface_set_input_focus
1146 controller_layer_set_source_rectangle(struct wl_client *client,
1147 struct wl_resource *resource,
1153 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1155 ivi_layout_layer_set_source_rectangle(ivilayer->layout_layer,
1156 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
1160 controller_layer_set_destination_rectangle(struct wl_client *client,
1161 struct wl_resource *resource,
1167 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1169 ivi_layout_layer_set_destination_rectangle(ivilayer->layout_layer,
1170 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
1174 controller_layer_set_visibility(struct wl_client *client,
1175 struct wl_resource *resource,
1176 uint32_t visibility)
1178 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1180 ivi_layout_layer_set_visibility(ivilayer->layout_layer, visibility);
1184 controller_layer_set_opacity(struct wl_client *client,
1185 struct wl_resource *resource,
1188 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1190 ivi_layout_layer_set_opacity(ivilayer->layout_layer,
1191 wl_fixed_to_double(opacity));
1195 controller_layer_set_configuration(struct wl_client *client,
1196 struct wl_resource *resource,
1200 /* This interface has been supported yet. */
1208 controller_layer_set_orientation(struct wl_client *client,
1209 struct wl_resource *resource,
1210 int32_t orientation)
1212 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1214 ivi_layout_layer_set_orientation(ivilayer->layout_layer, (uint32_t)orientation);
1218 controller_layer_clear_surfaces(struct wl_client *client,
1219 struct wl_resource *resource)
1221 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1223 ivi_layout_layer_set_render_order(ivilayer->layout_layer, NULL, 0);
1227 controller_layer_add_surface(struct wl_client *client,
1228 struct wl_resource *resource,
1229 struct wl_resource *surface)
1231 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1232 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
1234 ivi_layout_layer_add_surface(ivilayer->layout_layer, ivisurf->layout_surface);
1238 controller_layer_remove_surface(struct wl_client *client,
1239 struct wl_resource *resource,
1240 struct wl_resource *surface)
1242 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1243 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
1245 ivi_layout_layer_remove_surface(ivilayer->layout_layer, ivisurf->layout_surface);
1249 controller_layer_screenshot(struct wl_client *client,
1250 struct wl_resource *resource,
1251 const char *filename)
1259 controller_layer_set_render_order(struct wl_client *client,
1260 struct wl_resource *resource,
1261 struct wl_array *id_surfaces)
1263 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1264 struct ivi_layout_surface **layoutsurf_array = NULL;
1265 struct ivisurface *ivisurf = NULL;
1266 uint32_t *id_surface = NULL;
1267 uint32_t id_layout_surface = 0;
1271 layoutsurf_array = (struct ivi_layout_surface**)calloc(
1272 id_surfaces->size, sizeof(void*));
1274 wl_array_for_each(id_surface, id_surfaces) {
1275 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
1276 id_layout_surface = ivi_layout_get_id_of_surface(ivisurf->layout_surface);
1277 if (*id_surface == id_layout_surface) {
1278 layoutsurf_array[i] = ivisurf->layout_surface;
1285 ivi_layout_layer_set_render_order(ivilayer->layout_layer,
1286 layoutsurf_array, i);
1287 free(layoutsurf_array);
1291 controller_layer_destroy(struct wl_client *client,
1292 struct wl_resource *resource,
1293 int32_t destroy_scene_object)
1295 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1296 struct ivishell *shell = ivilayer->shell;
1297 struct ivicontroller_layer *ctrllayer = NULL;
1298 struct ivicontroller_layer *next = NULL;
1299 uint32_t id_layer = ivi_layout_get_id_of_layer(ivilayer->layout_layer);
1301 (void)destroy_scene_object;
1303 ivilayer->layer_canbe_removed = 1;
1304 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
1305 if (ctrllayer->id_layer != id_layer) {
1309 wl_resource_destroy(ctrllayer->resource);
1314 struct ivi_controller_layer_interface controller_layer_implementation = {
1315 controller_layer_set_visibility,
1316 controller_layer_set_opacity,
1317 controller_layer_set_source_rectangle,
1318 controller_layer_set_destination_rectangle,
1319 controller_layer_set_configuration,
1320 controller_layer_set_orientation,
1321 controller_layer_screenshot,
1322 controller_layer_clear_surfaces,
1323 controller_layer_add_surface,
1324 controller_layer_remove_surface,
1325 controller_layer_set_render_order,
1326 controller_layer_destroy
1330 controller_screen_destroy(struct wl_client *client,
1331 struct wl_resource *resource)
1333 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1334 struct ivicontroller_screen *ctrlscrn = NULL;
1335 struct ivicontroller_screen *next = NULL;
1336 // uint32_t id_screen = ivi_layout_get_id_of_screen(iviscrn->layout_screen);
1339 wl_list_for_each_safe(ctrlscrn, next,
1340 &iviscrn->shell->list_controller_screen, link) {
1341 if (resource != ctrlscrn->resource) {
1345 wl_list_remove(&ctrlscrn->link);
1346 wl_resource_destroy(ctrlscrn->resource);
1354 controller_screen_clear(struct wl_client *client,
1355 struct wl_resource *resource)
1357 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1359 ivi_layout_screen_set_render_order(iviscrn->layout_screen, NULL, 0);
1363 controller_screen_add_layer(struct wl_client *client,
1364 struct wl_resource *resource,
1365 struct wl_resource *layer)
1367 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1368 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
1370 ivi_layout_screen_add_layer(iviscrn->layout_screen, ivilayer->layout_layer);
1374 controller_screen_screenshot(struct wl_client *client,
1375 struct wl_resource *resource,
1376 const char *filename)
1378 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1381 struct weston_output *output = NULL;
1382 cairo_surface_t *cairo_surf = NULL;
1387 uint8_t *readpixs = NULL;
1389 output = ivi_layout_screen_get_output(iviscrn->layout_screen);
1390 --output->disable_planes;
1392 width = output->current_mode->width;
1393 height = output->current_mode->height;
1394 stride = width * (PIXMAN_FORMAT_BPP(output->compositor->read_format) / 8);
1396 readpixs = malloc(stride * height);
1397 if (readpixs == NULL) {
1398 weston_log("fails to allocate memory\n");
1402 output->compositor->renderer->read_pixels(
1404 output->compositor->read_format,
1411 save_as_bitmap(filename, readpixs, stride * height, width, height, PIXMAN_FORMAT_BPP(output->compositor->read_format));
1416 controller_screen_set_render_order(struct wl_client *client,
1417 struct wl_resource *resource,
1418 struct wl_array *id_layers)
1420 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1421 struct ivi_layout_layer **layoutlayer_array = NULL;
1422 struct ivilayer *ivilayer = NULL;
1423 uint32_t *id_layer = NULL;
1424 uint32_t id_layout_layer = 0;
1428 layoutlayer_array = (struct ivi_layout_layer**)calloc(
1429 id_layers->size, sizeof(void*));
1431 wl_array_for_each(id_layer, id_layers) {
1432 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1433 id_layout_layer = ivi_layout_get_id_of_layer(ivilayer->layout_layer);
1434 if (*id_layer == id_layout_layer) {
1435 layoutlayer_array[i] = ivilayer->layout_layer;
1442 ivi_layout_screen_set_render_order(iviscrn->layout_screen,
1443 layoutlayer_array, i);
1444 free(layoutlayer_array);
1448 struct ivi_controller_screen_interface controller_screen_implementation = {
1449 controller_screen_destroy,
1450 controller_screen_clear,
1451 controller_screen_add_layer,
1452 controller_screen_screenshot,
1453 controller_screen_set_render_order
1457 controller_commit_changes(struct wl_client *client,
1458 struct wl_resource *resource)
1464 ans = ivi_layout_commit_changes();
1466 weston_log("Failed to commit changes at controller_commit_changes\n");
1471 controller_layer_create(struct wl_client *client,
1472 struct wl_resource *resource,
1478 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1479 struct ivishell *shell = ctrl->shell;
1480 struct ivi_layout_layer *layout_layer = NULL;
1481 struct ivicontroller_layer *ctrllayer = NULL;
1482 struct ivilayer *ivilayer = NULL;
1483 const struct ivi_layout_layer_properties *prop;
1485 ivilayer = get_layer(&shell->list_layer, id_layer);
1486 if (ivilayer == NULL) {
1487 layout_layer = ivi_layout_layer_create_with_dimension(id_layer,
1488 (uint32_t)width, (uint32_t)height);
1489 if (layout_layer == NULL) {
1490 weston_log("id_layer is already created\n");
1494 /* ivilayer will be created by layer_event_create */
1495 ivilayer = get_layer(&shell->list_layer, id_layer);
1496 if (ivilayer == NULL) {
1497 weston_log("couldn't get layer object\n");
1502 ctrllayer = calloc(1, sizeof *ctrllayer);
1504 weston_log("no memory to allocate client layer\n");
1508 ++ivilayer->controller_layer_count;
1509 ivilayer->layer_canbe_removed = 0;
1511 ctrllayer->shell = shell;
1512 ctrllayer->client = client;
1514 ctrllayer->id_layer = id_layer;
1515 ctrllayer->resource = wl_resource_create(client,
1516 &ivi_controller_layer_interface, 1, id);
1517 if (ctrllayer->resource == NULL) {
1518 weston_log("couldn't get layer object\n");
1522 wl_list_init(&ctrllayer->link);
1523 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1525 wl_resource_set_implementation(ctrllayer->resource,
1526 &controller_layer_implementation,
1527 ivilayer, destroy_ivicontroller_layer);
1529 if (!(prop = ivi_layout_get_properties_of_layer(ivilayer->layout_layer)))
1530 prop = &no_layer_props;
1532 send_layer_event(ctrllayer->resource, ivilayer,
1533 prop, IVI_NOTIFICATION_ALL);
1537 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1539 struct ivishell *shell = userdata;
1540 struct ivicontroller_surface *ctrlsurf = NULL;
1541 uint32_t id_surface = 0;
1544 surface_event_remove(layout_surface, userdata);
1549 controller_surface_create(struct wl_client *client,
1550 struct wl_resource *resource,
1551 uint32_t id_surface,
1554 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1555 struct ivishell *shell = ctrl->shell;
1556 struct ivicontroller_surface *ctrlsurf = NULL;
1557 const struct ivi_layout_surface_properties *prop;
1558 struct ivisurface *ivisurf = NULL;
1559 struct ivicontroller_surface *ctrl_link = NULL;
1561 ivisurf = get_surface(&shell->list_surface, id_surface);
1562 if (ivisurf == NULL) {
1566 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1568 weston_log("no memory to allocate controller surface\n");
1572 ctrlsurf->shell = shell;
1573 ctrlsurf->client = client;
1575 ctrlsurf->id_surface = id_surface;
1576 wl_list_init(&ctrlsurf->link);
1577 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1579 ctrlsurf->resource = wl_resource_create(client,
1580 &ivi_controller_surface_interface, 1, id);
1581 if (ctrlsurf->resource == NULL) {
1582 weston_log("couldn't surface object");
1586 wl_list_for_each(ctrl_link, &shell->list_controller_surface, link) {
1587 if ((ctrl_link->implementation_set == 0) &&
1588 (ctrl_link->id_surface == id_surface) &&
1589 (ctrl_link->shell == shell) &&
1590 (ctrl_link->client != client)) {
1591 ++ivisurf->controller_surface_count;
1592 wl_resource_set_implementation(ctrl_link->resource,
1593 &controller_surface_implementation,
1594 ivisurf, destroy_ivicontroller_surface);
1595 ctrl_link->implementation_set = 1;
1599 ++ivisurf->controller_surface_count;
1601 wl_resource_set_implementation(ctrlsurf->resource,
1602 &controller_surface_implementation,
1603 ivisurf, destroy_ivicontroller_surface);
1605 ctrlsurf->implementation_set = 1;
1607 if (!(prop = ivi_layout_get_properties_of_surface(ivisurf->layout_surface)))
1608 prop = &no_surface_props;
1610 ivi_layout_surface_set_content_observer(ivisurf->layout_surface, surface_event_content, shell);
1612 send_surface_event(ctrlsurf->resource, ivisurf,
1613 prop, IVI_NOTIFICATION_ALL);
1617 controller_get_native_handle(struct wl_client *client,
1618 struct wl_resource *resource,
1619 uint32_t id_process,
1622 struct wl_array surfaces;
1623 ivi_shell_get_shell_surfaces(&surfaces);
1624 struct shell_surface ** surface;
1626 wl_array_for_each(surface, &surfaces) {
1628 uint32_t pid = shell_surface_get_process_id(*surface);
1629 if (pid != id_process) {
1634 char* surface_title = shell_surface_get_title(*surface);
1635 if (strcmp(title, surface_title)) {
1640 struct weston_surface *es = shell_surface_get_surface(*surface);
1642 struct wl_resource *res = wl_resource_create(client, &wl_surface_interface, 1, 0);
1643 wl_resource_set_user_data(res, es);
1645 ivi_controller_send_native_handle(resource, res);
1649 wl_array_release(&surfaces);
1651 int32_t id_object = 0;
1652 ivi_controller_send_error(
1653 resource, id_object, IVI_CONTROLLER_OBJECT_TYPE_SURFACE,
1654 IVI_CONTROLLER_ERROR_CODE_NATIVE_HANDLE_END, "");
1658 controller_set_keyboard_focus(struct wl_client *client,
1659 struct wl_resource *resource,
1660 struct wl_array *surfaces)
1662 #ifdef SUPPORT_INPUT_FOCUS
1663 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1664 ivi_layout_set_keyboard_focus_on(surfaces->data, surfaces->size);
1665 send_all_keyboard_focus(ctrl->shell);
1669 static const struct ivi_controller_interface controller_implementation = {
1670 controller_commit_changes,
1671 controller_layer_create,
1672 controller_surface_create,
1673 controller_set_keyboard_focus,
1674 controller_get_native_handle
1678 add_client_to_resources(struct ivishell *shell,
1679 struct wl_client *client,
1680 struct ivicontroller *controller)
1682 struct ivisurface* ivisurf = NULL;
1683 struct ivilayer* ivilayer = NULL;
1684 struct iviscreen* iviscrn = NULL;
1685 struct ivicontroller_screen *ctrlscrn = NULL;
1686 struct wl_resource *resource_output = NULL;
1687 uint32_t id_layout_surface = 0;
1688 uint32_t id_layout_layer = 0;
1689 struct ivi_layout_surface *layout_surface;
1691 const char *window_title;
1693 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1694 resource_output = wl_resource_find_for_client(
1695 &iviscrn->output->resource_list, client);
1696 if (resource_output == NULL) {
1700 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1701 if (ctrlscrn == NULL) {
1705 ivi_controller_send_screen(controller->resource,
1706 wl_resource_get_id(resource_output),
1707 ctrlscrn->resource);
1709 wl_list_for_each_reverse(ivilayer, &shell->list_layer, link) {
1711 ivi_layout_get_id_of_layer(ivilayer->layout_layer);
1713 ivi_controller_send_layer(controller->resource,
1716 wl_list_for_each_reverse(ivisurf, &shell->list_surface, link) {
1717 layout_surface = ivisurf->layout_surface;
1718 id_layout_surface = ivi_layout_get_id_of_surface(layout_surface);
1720 get_wl_shell_info(layout_surface, id_layout_surface,
1721 &pid, &window_title);
1723 ivi_controller_send_surface(controller->resource,
1724 id_layout_surface, pid, window_title);
1729 bind_ivi_controller(struct wl_client *client, void *data,
1730 uint32_t version, uint32_t id)
1732 struct ivishell *shell = data;
1733 struct ivicontroller *controller;
1736 controller = calloc(1, sizeof *controller);
1737 if (controller == NULL) {
1738 weston_log("no memory to allocate controller\n");
1742 controller->resource =
1743 wl_resource_create(client, &ivi_controller_interface, 1, id);
1744 wl_resource_set_implementation(controller->resource,
1745 &controller_implementation,
1746 controller, unbind_resource_controller);
1748 controller->shell = shell;
1749 controller->client = client;
1750 controller->id = id;
1752 wl_list_init(&controller->link);
1753 wl_list_insert(&shell->list_controller, &controller->link);
1755 add_client_to_resources(shell, client, controller);
1758 static struct iviscreen*
1759 create_screen(struct ivishell *shell, struct weston_output *output)
1761 struct iviscreen *iviscrn;
1762 iviscrn = calloc(1, sizeof *iviscrn);
1763 if (iviscrn == NULL) {
1764 weston_log("no memory to allocate client screen\n");
1768 iviscrn->shell = shell;
1769 iviscrn->output = output;
1771 // TODO : Only Single display
1772 iviscrn->layout_screen = ivi_layout_get_screen_from_id(0);
1774 wl_list_init(&iviscrn->link);
1779 static struct ivilayer*
1780 create_layer(struct ivishell *shell,
1781 struct ivi_layout_layer *layout_layer,
1784 struct ivilayer *ivilayer = NULL;
1785 struct ivicontroller *controller = NULL;
1787 ivilayer = get_layer(&shell->list_layer, id_layer);
1788 if (ivilayer != NULL) {
1789 weston_log("id_layer is already created\n");
1793 ivilayer = calloc(1, sizeof *ivilayer);
1794 if (NULL == ivilayer) {
1795 weston_log("no memory to allocate client layer\n");
1799 ivilayer->shell = shell;
1800 wl_list_init(&ivilayer->list_screen);
1801 wl_list_init(&ivilayer->link);
1802 wl_list_insert(&shell->list_layer, &ivilayer->link);
1803 ivilayer->layout_layer = layout_layer;
1805 ivi_layout_layer_add_notification(layout_layer, send_layer_prop, ivilayer);
1807 wl_list_for_each(controller, &shell->list_controller, link) {
1808 ivi_controller_send_layer(controller->resource, id_layer);
1814 static struct ivisurface*
1815 create_surface(struct ivishell *shell,
1816 struct ivi_layout_surface *layout_surface,
1817 uint32_t id_surface)
1819 struct ivisurface *ivisurf = NULL;
1820 struct ivicontroller *controller = NULL;
1822 const char *window_title;
1824 ivisurf = get_surface(&shell->list_surface, id_surface);
1825 if (ivisurf != NULL) {
1826 weston_log("id_surface is already created\n");
1830 ivisurf = calloc(1, sizeof *ivisurf);
1831 if (ivisurf == NULL) {
1832 weston_log("no memory to allocate client surface\n");
1836 ivisurf->shell = shell;
1837 ivisurf->layout_surface = layout_surface;
1838 wl_list_init(&ivisurf->list_layer);
1839 wl_list_init(&ivisurf->link);
1840 wl_list_insert(&shell->list_surface, &ivisurf->link);
1842 get_wl_shell_info(layout_surface, id_surface, &pid, &window_title);
1844 wl_list_for_each(controller, &shell->list_controller, link) {
1845 ivi_controller_send_surface(controller->resource,
1846 id_surface, pid, window_title);
1849 ivi_layout_surface_add_notification(layout_surface,
1850 send_surface_prop, ivisurf);
1856 layer_event_create(struct ivi_layout_layer *layout_layer,
1859 struct ivishell *shell = userdata;
1860 struct ivilayer *ivilayer = NULL;
1861 uint32_t id_layer = 0;
1863 id_layer = ivi_layout_get_id_of_layer(layout_layer);
1865 ivilayer = create_layer(shell, layout_layer, id_layer);
1866 if (ivilayer == NULL) {
1867 weston_log("failed to create layer");
1873 layer_event_remove(struct ivi_layout_layer *layout_layer,
1876 struct ivishell *shell = userdata;
1877 struct ivicontroller_layer *ctrllayer = NULL;
1878 struct ivilayer *ivilayer = NULL;
1879 struct ivilayer *next = NULL;
1880 uint32_t id_layer = 0;
1883 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1884 if (layout_layer != ivilayer->layout_layer) {
1888 wl_list_remove(&ivilayer->link);
1897 id_layer = ivi_layout_get_id_of_layer(layout_layer);
1899 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1900 if (id_layer != ctrllayer->id_layer) {
1903 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1910 surface_event_create(struct ivi_layout_surface *layout_surface,
1913 struct ivishell *shell = userdata;
1914 struct ivisurface *ivisurf = NULL;
1915 uint32_t id_surface = 0;
1916 struct ivicontroller_surface *ctrlsurf = NULL;
1918 id_surface = ivi_layout_get_id_of_surface(layout_surface);
1920 ivisurf = create_surface(shell, layout_surface, id_surface);
1921 if (ivisurf == NULL) {
1922 weston_log("failed to create surface");
1926 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1927 if (id_surface != ctrlsurf->id_surface) {
1930 ivi_controller_surface_send_content(ctrlsurf->resource, IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_AVAILABLE);
1935 surface_event_remove(struct ivi_layout_surface *layout_surface,
1938 struct ivishell *shell = userdata;
1939 struct ivicontroller_surface *ctrlsurf = NULL;
1940 struct ivisurface *ivisurf = NULL;
1941 struct ivisurface *next = NULL;
1942 uint32_t id_surface = 0;
1945 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1946 if (layout_surface != ivisurf->layout_surface) {
1950 wl_list_remove(&ivisurf->link);
1953 if (ivisurf->controller_surface_count == 0) {
1957 ivisurf->can_be_removed = 1;
1964 id_surface = ivi_layout_get_id_of_surface(layout_surface);
1966 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1967 if (id_surface != ctrlsurf->id_surface) {
1970 ivi_controller_surface_send_content(ctrlsurf->resource, IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED);
1971 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1977 surface_event_configure(struct ivi_layout_surface *layout_surface,
1980 struct ivishell *shell = userdata;
1981 struct ivisurface *ivisurf = NULL;
1982 struct ivicontroller_surface *ctrlsurf = NULL;
1983 struct ivi_layout_surface_properties *prop;
1984 uint32_t id_surface = 0;
1986 id_surface = ivi_layout_get_id_of_surface(layout_surface);
1988 ivisurf = get_surface(&shell->list_surface, id_surface);
1989 if (ivisurf == NULL) {
1990 weston_log("id_surface is not created yet\n");
1994 if (!(prop = ivi_layout_get_properties_of_surface(layout_surface)))
1995 prop = &no_surface_props;
1997 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1998 if (id_surface != ctrlsurf->id_surface) {
2001 send_surface_event(ctrlsurf->resource, ivisurf,
2002 prop, IVI_NOTIFICATION_ALL);
2007 check_layout_layers(struct ivishell *shell)
2009 struct ivi_layout_layer **pArray = NULL;
2010 struct ivilayer *ivilayer = NULL;
2011 uint32_t id_layer = 0;
2012 uint32_t length = 0;
2016 ret = ivi_layout_get_layers(&length, &pArray);
2018 weston_log("failed to get layers at check_layout_layers\n");
2023 /* if length is 0, pArray doesn't need to free.*/
2027 for (i = 0; i < length; i++) {
2028 id_layer = ivi_layout_get_id_of_layer(pArray[i]);
2029 ivilayer = create_layer(shell, pArray[i], id_layer);
2030 if (ivilayer == NULL) {
2031 weston_log("failed to create layer");
2042 check_layout_surfaces(struct ivishell *shell)
2044 struct ivi_layout_surface **pArray = NULL;
2045 struct ivisurface *ivisurf = NULL;
2046 uint32_t id_surface = 0;
2047 uint32_t length = 0;
2051 ret = ivi_layout_get_surfaces(&length, &pArray);
2053 weston_log("failed to get surfaces at check_layout_surfaces\n");
2058 /* if length is 0, pArray doesn't need to free.*/
2062 for (i = 0; i < length; i++) {
2063 id_surface = ivi_layout_get_id_of_surface(pArray[i]);
2064 ivisurf = create_surface(shell, pArray[i], id_surface);
2065 if (ivisurf == NULL) {
2066 weston_log("failed to create surface");
2077 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
2079 struct weston_output *output = NULL;
2080 struct iviscreen *iviscrn = NULL;
2083 shell->compositor = ec;
2085 wl_list_init(&shell->list_surface);
2086 wl_list_init(&shell->list_layer);
2087 wl_list_init(&shell->list_screen);
2088 wl_list_init(&shell->list_weston_surface);
2089 wl_list_init(&shell->list_controller);
2090 wl_list_init(&shell->list_controller_screen);
2091 wl_list_init(&shell->list_controller_layer);
2092 wl_list_init(&shell->list_controller_surface);
2093 shell->event_restriction = 0;
2095 wl_list_for_each(output, &ec->output_list, link) {
2096 iviscrn = create_screen(shell, output);
2097 if (iviscrn != NULL) {
2098 wl_list_insert(&shell->list_screen, &iviscrn->link);
2102 ret = check_layout_layers(shell);
2104 weston_log("failed to check_layout_layers");
2107 ret = check_layout_surfaces(shell);
2109 weston_log("failed to check_layout_surfaces");
2112 ivi_layout_add_notification_create_layer(layer_event_create, shell);
2113 ivi_layout_add_notification_remove_layer(layer_event_remove, shell);
2115 ivi_layout_add_notification_create_surface(surface_event_create, shell);
2116 ivi_layout_add_notification_remove_surface(surface_event_remove, shell);
2117 ivi_layout_add_notification_configure_surface(surface_event_configure, shell);
2121 module_init(struct weston_compositor *ec,
2122 int *argc, char *argv[])
2124 struct ivishell *shell;
2128 shell = malloc(sizeof *shell);
2132 memset(shell, 0, sizeof *shell);
2133 init_ivi_shell(ec, shell);
2135 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
2136 shell, bind_ivi_controller) == NULL) {