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 "weston/compositor.h"
33 #include "ivi-controller-server-protocol.h"
34 #include "ivi-layout-export.h"
42 struct ivilayer *layer;
47 struct iviscreen *screen;
53 struct wl_client *client;
54 struct ivishell *shell;
55 uint32_t update_count;
56 struct ivi_layout_surface *layout_surface;
57 struct wl_listener surface_destroy_listener;
58 struct wl_list list_layer;
59 uint32_t controller_surface_count;
65 struct ivishell *shell;
66 struct ivi_layout_layer *layout_layer;
67 struct wl_list list_screen;
68 uint32_t controller_layer_count;
69 int layer_canbe_removed;
74 struct ivishell *shell;
75 struct ivi_layout_screen *layout_screen;
76 struct weston_output *output;
79 struct ivicontroller_surface {
80 struct wl_resource *resource;
83 struct wl_client *client;
85 struct ivishell *shell;
86 int implementation_set;
89 struct ivicontroller_layer {
90 struct wl_resource *resource;
93 struct wl_client *client;
95 struct ivishell *shell;
98 struct ivicontroller_screen {
99 struct wl_resource *resource;
102 struct wl_client *client;
104 struct ivishell *shell;
107 struct ivicontroller {
108 struct wl_resource *resource;
110 struct wl_client *client;
112 struct ivishell *shell;
115 struct link_shell_weston_surface
117 struct wl_resource *resource;
118 struct wl_listener destroy_listener;
119 struct weston_surface *surface;
124 struct wl_resource *resource;
126 struct wl_listener destroy_listener;
128 struct weston_compositor *compositor;
130 struct weston_surface *surface;
132 struct weston_process process;
134 struct weston_seat *seat;
136 struct wl_list list_surface;
137 struct wl_list list_layer;
138 struct wl_list list_screen;
140 struct wl_list list_weston_surface;
142 struct wl_list list_controller;
143 struct wl_list list_controller_surface;
144 struct wl_list list_controller_layer;
145 struct wl_list list_controller_screen;
148 struct weston_process process;
149 struct wl_client *client;
150 struct wl_resource *desktop_shell;
158 int event_restriction;
160 static void surface_event_remove(struct ivi_layout_surface *, void *);
163 destroy_ivicontroller_surface(struct wl_resource *resource)
165 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
166 struct ivishell *shell = ivisurf->shell;
167 struct ivicontroller_surface *ctrlsurf = NULL;
168 struct ivicontroller_surface *next = NULL;
171 wl_list_for_each_safe(ctrlsurf, next,
172 &shell->list_controller_surface, link) {
174 if (resource != ctrlsurf->resource) {
178 if (!wl_list_empty(&ctrlsurf->link)) {
179 wl_list_remove(&ctrlsurf->link);
185 --ivisurf->controller_surface_count;
189 if ((is_removed) && (ivisurf->controller_surface_count == 0)) {
190 if (ivisurf->can_be_removed) {
197 destroy_ivicontroller_layer(struct wl_resource *resource)
199 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
200 struct ivishell *shell = ivilayer->shell;
201 struct ivicontroller_layer *ctrllayer = NULL;
202 struct ivicontroller_layer *next = NULL;
203 uint32_t id_layer = 0;
205 id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
207 wl_list_for_each_safe(ctrllayer, next,
208 &shell->list_controller_layer, link) {
210 if (resource != ctrllayer->resource) {
214 wl_list_remove(&ctrllayer->link);
215 --ivilayer->controller_layer_count;
216 ivi_controller_layer_send_destroyed(ctrllayer->resource);
222 if ((ivilayer->layout_layer != NULL) &&
223 (ivilayer->controller_layer_count == 0) &&
224 (ivilayer->layer_canbe_removed == 1)) {
225 ivi_layout_layerRemove(ivilayer->layout_layer);
230 destroy_ivicontroller_screen(struct wl_resource *resource)
232 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
233 struct ivicontroller_screen *ctrlscrn = NULL;
234 struct ivicontroller_screen *next = NULL;
236 wl_list_for_each_safe(ctrlscrn, next,
237 &iviscrn->shell->list_controller_screen, link) {
238 // TODO : Only Single display
240 if (iviscrn->output->id != ctrlscrn->id_screen) {
245 if (resource != ctrlscrn->resource) {
249 wl_list_remove(&ctrlscrn->link);
257 unbind_resource_controller(struct wl_resource *resource)
259 struct ivicontroller *controller = wl_resource_get_user_data(resource);
261 wl_list_remove(&controller->link);
267 static struct ivisurface*
268 get_surface(struct wl_list *list_surf, uint32_t id_surface)
270 struct ivisurface *ivisurf = NULL;
271 uint32_t ivisurf_id = 0;
273 wl_list_for_each(ivisurf, list_surf, link) {
274 ivisurf_id = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
275 if (ivisurf_id == id_surface) {
283 static struct ivilayer*
284 get_layer(struct wl_list *list_layer, uint32_t id_layer)
286 struct ivilayer *ivilayer = NULL;
287 uint32_t ivilayer_id = 0;
289 wl_list_for_each(ivilayer, list_layer, link) {
290 ivilayer_id = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
291 if (ivilayer_id == id_layer) {
300 struct ivi_controller_screen_interface controller_screen_implementation;
302 static struct ivicontroller_screen*
303 controller_screen_create(struct ivishell *shell,
304 struct wl_client *client,
305 struct iviscreen *iviscrn)
307 struct ivicontroller_screen *ctrlscrn = NULL;
309 ctrlscrn = calloc(1, sizeof *ctrlscrn);
310 if (ctrlscrn == NULL) {
311 weston_log("no memory to allocate controller screen\n");
315 ctrlscrn->client = client;
316 ctrlscrn->shell = shell;
318 // TODO : Only Single display
320 /* ctrlscrn->id_screen = iviscrn->id_screen; */
322 ctrlscrn->id_screen = 0;
326 wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
327 if (ctrlscrn->resource == NULL) {
328 weston_log("couldn't new screen controller object");
336 wl_resource_set_implementation(ctrlscrn->resource,
337 &controller_screen_implementation,
338 iviscrn, destroy_ivicontroller_screen);
340 wl_list_init(&ctrlscrn->link);
341 wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
347 send_surface_add_event(struct ivisurface *ivisurf,
348 struct wl_resource *resource,
349 enum ivi_layout_notification_mask mask)
351 struct ivi_layout_layer **pArray = NULL;
355 struct link_layer *link_layer = NULL;
356 struct link_layer *next = NULL;
357 struct ivicontroller_layer *ctrllayer = NULL;
358 struct ivilayer *ivilayer = NULL;
359 struct ivishell *shell = ivisurf->shell;
360 uint32_t id_layout_layer = 0;
361 struct wl_client *surface_client = wl_resource_get_client(resource);
364 ans = ivi_layout_getLayersUnderSurface(ivisurf->layout_surface,
367 weston_log("failed to get layers at send_surface_add_event\n");
371 /* Send Null to cancel added surface */
372 if (mask & IVI_NOTIFICATION_REMOVE) {
373 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
374 ivi_controller_surface_send_layer(resource, NULL);
377 else if (mask & IVI_NOTIFICATION_ADD) {
378 for (i = 0; i < (int)length; i++) {
379 /* Send new surface event */
381 wl_list_for_each(ivilayer, &shell->list_layer, link) {
382 if (ivilayer->layout_layer == pArray[i]) {
387 if (ivilayer == NULL) {
392 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
393 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
394 if (id_layout_layer != ctrllayer->id_layer) {
398 struct wl_client *layer_client = wl_resource_get_client(ctrllayer->resource);
399 if (surface_client != layer_client) {
403 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
413 send_surface_event(struct wl_resource *resource,
414 struct ivisurface *ivisurf,
415 struct ivi_layout_SurfaceProperties *prop,
418 if (mask & IVI_NOTIFICATION_OPACITY) {
419 ivi_controller_surface_send_opacity(resource,
422 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
423 ivi_controller_surface_send_source_rectangle(resource,
424 prop->sourceX, prop->sourceY,
425 prop->sourceWidth, prop->sourceHeight);
427 if (mask & IVI_NOTIFICATION_DEST_RECT) {
428 ivi_controller_surface_send_destination_rectangle(resource,
429 prop->destX, prop->destY,
430 prop->destWidth, prop->destHeight);
432 if (mask & IVI_NOTIFICATION_ORIENTATION) {
433 ivi_controller_surface_send_orientation(resource,
436 if (mask & IVI_NOTIFICATION_VISIBILITY) {
437 ivi_controller_surface_send_visibility(resource,
440 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
441 ivi_controller_surface_send_pixelformat(resource,
444 if (mask & IVI_NOTIFICATION_REMOVE) {
445 send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_REMOVE);
447 if (mask & IVI_NOTIFICATION_ADD) {
448 send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_ADD);
453 update_surface_prop(struct ivisurface *ivisurf,
456 struct ivi_layout_layer **pArray = NULL;
460 struct ivishell *shell = ivisurf->shell;
462 ans = ivi_layout_getLayersUnderSurface(ivisurf->layout_surface,
465 weston_log("failed to get layers at send_surface_add_event\n");
469 if (mask & IVI_NOTIFICATION_REMOVE) {
470 struct link_layer *link_layer = NULL;
471 struct link_layer *next = NULL;
473 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
474 wl_list_remove(&link_layer->link);
479 if (mask & IVI_NOTIFICATION_ADD) {
480 for (i = 0; i < (int)length; ++i) {
481 /* Create list_layer */
482 struct ivilayer *ivilayer = NULL;
483 struct link_layer *link_layer = calloc(1, sizeof(*link_layer));
484 if (NULL == link_layer) {
487 wl_list_init(&link_layer->link);
488 link_layer->layer = NULL;
489 wl_list_for_each(ivilayer, &shell->list_layer, link) {
490 if (ivilayer->layout_layer == pArray[i]) {
491 link_layer->layer = ivilayer;
496 if (link_layer->layer == NULL) {
502 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
508 send_surface_prop(struct ivi_layout_surface *layout_surface,
509 struct ivi_layout_SurfaceProperties *prop,
510 enum ivi_layout_notification_mask mask,
513 struct ivisurface *ivisurf = userdata;
514 struct ivishell *shell = ivisurf->shell;
515 struct ivicontroller_surface *ctrlsurf = NULL;
516 uint32_t id_surface = 0;
518 id_surface = ivi_layout_getIdOfSurface(layout_surface);
520 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
521 if (id_surface != ctrlsurf->id_surface) {
524 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
527 update_surface_prop(ivisurf, mask);
531 send_layer_add_event(struct ivilayer *ivilayer,
532 struct wl_resource *resource,
533 enum ivi_layout_notification_mask mask)
535 struct ivi_layout_screen **pArray = NULL;
539 struct link_screen *link_scrn = NULL;
540 struct link_screen *next = NULL;
541 struct iviscreen *iviscrn = NULL;
542 struct ivishell *shell = ivilayer->shell;
543 struct wl_client *client = wl_resource_get_client(resource);
544 struct wl_resource *resource_output = NULL;
546 ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
549 weston_log("failed to get screens at send_layer_add_event\n");
553 /* Send Null to cancel added layer */
554 if (mask & IVI_NOTIFICATION_REMOVE) {
555 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
556 ivi_controller_layer_send_screen(resource, NULL);
559 else if (mask & IVI_NOTIFICATION_ADD) {
560 for (i = 0; i < (int)length; i++) {
561 /* Send new layer event */
563 wl_list_for_each(iviscrn, &shell->list_screen, link) {
564 if (iviscrn->layout_screen == pArray[i]) {
569 if (iviscrn == NULL) {
574 wl_resource_find_for_client(&iviscrn->output->resource_list,
576 if (resource_output != NULL) {
577 ivi_controller_layer_send_screen(resource, resource_output);
587 send_layer_event(struct wl_resource *resource,
588 struct ivilayer *ivilayer,
589 struct ivi_layout_LayerProperties *prop,
592 if (mask & IVI_NOTIFICATION_OPACITY) {
593 ivi_controller_layer_send_opacity(resource,
596 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
597 ivi_controller_layer_send_source_rectangle(resource,
603 if (mask & IVI_NOTIFICATION_DEST_RECT) {
604 ivi_controller_layer_send_destination_rectangle(resource,
610 if (mask & IVI_NOTIFICATION_ORIENTATION) {
611 ivi_controller_layer_send_orientation(resource,
614 if (mask & IVI_NOTIFICATION_VISIBILITY) {
615 ivi_controller_layer_send_visibility(resource,
618 if (mask & IVI_NOTIFICATION_REMOVE) {
619 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_REMOVE);
621 if (mask & IVI_NOTIFICATION_ADD) {
622 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_ADD);
627 update_layer_prop(struct ivilayer *ivilayer,
628 enum ivi_layout_notification_mask mask)
630 struct ivi_layout_screen **pArray = NULL;
633 struct link_screen *link_scrn = NULL;
634 struct link_screen *next = NULL;
636 ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
639 weston_log("failed to get screens at send_layer_add_event\n");
643 /* Send Null to cancel added layer */
644 if (mask & IVI_NOTIFICATION_REMOVE) {
645 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
646 wl_list_remove(&link_scrn->link);
651 if (mask & IVI_NOTIFICATION_ADD) {
653 for (i = 0; i < (int)length; i++) {
654 struct ivishell *shell = ivilayer->shell;
655 struct iviscreen *iviscrn = NULL;
656 /* Create list_screen */
657 link_scrn = calloc(1, sizeof(*link_scrn));
658 if (NULL == link_scrn) {
661 wl_list_init(&link_scrn->link);
662 link_scrn->screen = NULL;
663 wl_list_for_each(iviscrn, &shell->list_screen, link) {
664 if (iviscrn->layout_screen == pArray[i]) {
665 link_scrn->screen = iviscrn;
670 if (link_scrn->screen == NULL) {
675 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
684 send_layer_prop(struct ivi_layout_layer *layer,
685 struct ivi_layout_LayerProperties *prop,
686 enum ivi_layout_notification_mask mask,
689 struct ivilayer *ivilayer = userdata;
690 struct ivicontroller_layer *ctrllayer = NULL;
691 struct ivishell *shell = ivilayer->shell;
692 uint32_t id_layout_layer = 0;
694 id_layout_layer = ivi_layout_getIdOfLayer(layer);
695 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
696 if (id_layout_layer != ctrllayer->id_layer) {
699 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
702 update_layer_prop(ivilayer, mask);
706 controller_surface_set_opacity(struct wl_client *client,
707 struct wl_resource *resource,
710 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
712 ivi_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
716 controller_surface_set_source_rectangle(struct wl_client *client,
717 struct wl_resource *resource,
723 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
725 ivi_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
726 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
730 controller_surface_set_destination_rectangle(struct wl_client *client,
731 struct wl_resource *resource,
737 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
740 // TODO: create set transition type protocol
741 ivi_layout_surfaceSetTransition( ivisurf->layout_surface,
742 IVI_LAYOUT_TRANSITION_NONE,
745 ivi_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
746 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
750 controller_surface_set_visibility(struct wl_client *client,
751 struct wl_resource *resource,
754 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
756 ivi_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
760 controller_surface_set_configuration(struct wl_client *client,
761 struct wl_resource *resource,
762 int32_t width, int32_t height)
764 /* This interface has been supported yet. */
772 controller_surface_set_orientation(struct wl_client *client,
773 struct wl_resource *resource,
776 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
778 ivi_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
782 shm_surface_screenshot(struct weston_surface *surface,
786 const char *filename)
788 struct weston_buffer *weston_buffer = NULL;
789 struct wl_shm_buffer *shm_buffer = NULL;
790 cairo_surface_t *cairo_surf = NULL;
791 uint8_t *source_buffer = NULL;
792 uint8_t *dest_buffer = NULL;
794 weston_buffer = surface->buffer_ref.buffer;
795 if (weston_buffer == NULL) {
796 fprintf(stderr, "Failed to get weston buffer.\n");
800 shm_buffer = wl_shm_buffer_get(weston_buffer->resource);
801 if (shm_buffer == NULL) {
805 source_buffer = wl_shm_buffer_get_data(shm_buffer);
806 if (source_buffer == NULL) {
807 fprintf(stderr, "Failed to get data from shm buffer.\n");
811 dest_buffer = malloc(stride * height);
812 if (dest_buffer == NULL) {
813 fprintf(stderr, "Failed to allocate memory.\n");
817 memcpy(dest_buffer, source_buffer, stride * height);
819 cairo_surf = cairo_image_surface_create_for_data(
826 cairo_surface_write_to_png(cairo_surf, filename);
827 cairo_surface_destroy(cairo_surf);
834 bind_framebuffer(GLuint *fbo_id, GLuint *tex_id, GLsizei width, GLsizei height)
836 glGenTextures(1, tex_id);
837 glGenFramebuffers(1, fbo_id);
838 glBindTexture(GL_TEXTURE_2D, *tex_id);
839 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
840 glBindFramebuffer(GL_FRAMEBUFFER, *fbo_id);
841 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *tex_id, 0);
842 glClearColor(0, 0, 0, 0);
843 glClear(GL_COLOR_BUFFER_BIT);
847 unbind_framebuffer(GLuint fbo_id, GLuint tex_id)
849 glBindTexture(GL_TEXTURE_2D, 0);
850 glBindFramebuffer(GL_FRAMEBUFFER, 0);
851 glDeleteTextures(1, &tex_id);
852 glDeleteFramebuffers(1, &fbo_id);
856 dump_surface(struct weston_output *output,
857 struct weston_compositor *compositor,
858 const char *filename,
859 struct weston_view *view,
865 struct weston_renderer *renderer = compositor->renderer;
866 pixman_region32_t region;
867 struct wl_list backup_transformation_list;
868 struct weston_transform *link = NULL;
869 struct weston_transform *next = NULL;
870 uint8_t *readpixs = NULL;
871 int32_t stride = width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
872 GLuint fbo_id, tex_id;
874 readpixs = malloc(stride * height);
875 if (readpixs == NULL) {
876 fprintf(stderr, "Failed to allocate memory.\n");
880 pixman_region32_init_rect(®ion, x, y, width, height);
881 bind_framebuffer(&fbo_id, &tex_id, output->current_mode->width, output->current_mode->height);
883 wl_list_init(&backup_transformation_list);
884 wl_list_for_each_safe(link, next, &view->geometry.transformation_list, link) {
885 wl_list_remove(&link->link);
886 wl_list_insert(&backup_transformation_list, &link->link);
889 wl_list_init(&view->geometry.transformation_list);
890 weston_view_geometry_dirty(view);
891 weston_view_update_transform(view);
893 renderer->repaint_output(output, ®ion);
896 y = output->current_mode->height - (y + height);
897 int result = renderer->read_pixels(output,
898 compositor->read_format,
905 wl_list_for_each_safe(link, next, &backup_transformation_list, link) {
906 wl_list_remove(&link->link);
907 wl_list_insert(&view->geometry.transformation_list, &link->link);
910 weston_view_geometry_dirty(view);
911 weston_view_update_transform(view);
913 unbind_framebuffer(fbo_id, tex_id);
915 save_as_bitmap(filename, readpixs, stride * height, width, height, PIXMAN_FORMAT_BPP(compositor->read_format));
919 static struct weston_view *
920 clear_viewlist_but_specified_surface(struct weston_compositor *compositor,
921 struct weston_surface *surface)
923 struct weston_view *view = NULL;
924 wl_list_init(&compositor->view_list);
926 wl_list_for_each(view, &surface->views, surface_link) {
931 wl_list_insert(compositor->view_list.prev, &view->link);
939 get_gl_surface_rectangle(struct ivi_layout_SurfaceProperties *prop,
951 *width = prop->sourceWidth;
952 *height = prop->sourceHeight;
956 gl_surface_screenshot(struct ivisurface *ivisurf,
957 struct weston_surface *surface,
958 const char *filename)
960 struct weston_compositor *compositor = surface->compositor;
961 struct ivishell *shell = ivisurf->shell;
962 struct weston_view *view = NULL;
963 struct weston_output *output = NULL;
964 struct iviscreen *link_scrn = NULL;
965 struct ivi_layout_SurfaceProperties prop = {};
971 wl_list_for_each(link_scrn, &shell->list_screen, link) {
972 if (link_scrn != NULL) {
977 if (link_scrn == NULL) {
978 fprintf(stderr, "Failed to get iviscreen\n");
982 if (ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop) != 0) {
983 fprintf(stderr, "Failed to get surface properties.");
987 view = clear_viewlist_but_specified_surface(compositor, surface);
989 int32_t plane_is_null = 0;
990 if (view->plane == NULL) {
992 view->plane = &compositor->primary_plane;
995 get_gl_surface_rectangle(&prop, &x, &y, &width, &height);
996 dump_surface(link_scrn->output,
1005 if (plane_is_null) {
1014 controller_surface_screenshot(struct wl_client *client,
1015 struct wl_resource *resource,
1016 const char *filename)
1018 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1019 struct weston_surface *weston_surface = NULL;
1024 weston_surface = ivi_layout_surfaceGetWestonSurface(ivisurf->layout_surface);
1025 if (weston_surface == NULL) {
1026 fprintf(stderr, "Failed to get weston surface.\n");
1030 if (ivi_layout_surfaceGetSize(ivisurf->layout_surface, &width, &height, &stride) != 0) {
1031 fprintf(stderr, "Failed to get surface size.\n");
1035 if (shm_surface_screenshot(weston_surface, width, height, stride, filename) != 0) {
1036 if (gl_surface_screenshot(ivisurf, weston_surface, filename) != 0) {
1037 fprintf(stderr, "Failed to capture surface.\n");
1044 controller_surface_send_stats(struct wl_client *client,
1045 struct wl_resource *resource)
1047 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1051 wl_client_get_credentials(client, &pid, &uid, &gid);
1053 ivi_controller_surface_send_stats(resource, 0, 0,
1054 ivisurf->update_count, pid, "");
1058 controller_surface_destroy(struct wl_client *client,
1059 struct wl_resource *resource,
1060 int32_t destroy_scene_object)
1063 (void)destroy_scene_object;
1064 wl_resource_destroy(resource);
1068 controller_surface_set_input_focus(struct wl_client *client,
1069 struct wl_resource *resource,
1074 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1076 if (device & IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD) {
1078 ivi_layout_SetKeyboardFocusOn(ivisurf->layout_surface);
1084 struct ivi_controller_surface_interface controller_surface_implementation = {
1085 controller_surface_set_visibility,
1086 controller_surface_set_opacity,
1087 controller_surface_set_source_rectangle,
1088 controller_surface_set_destination_rectangle,
1089 controller_surface_set_configuration,
1090 controller_surface_set_orientation,
1091 controller_surface_screenshot,
1092 controller_surface_send_stats,
1093 controller_surface_destroy,
1094 controller_surface_set_input_focus
1098 controller_layer_set_source_rectangle(struct wl_client *client,
1099 struct wl_resource *resource,
1105 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1107 ivi_layout_layerSetSourceRectangle(ivilayer->layout_layer,
1108 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
1112 controller_layer_set_destination_rectangle(struct wl_client *client,
1113 struct wl_resource *resource,
1119 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1121 ivi_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
1122 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
1126 controller_layer_set_visibility(struct wl_client *client,
1127 struct wl_resource *resource,
1128 uint32_t visibility)
1130 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1132 ivi_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
1136 controller_layer_set_opacity(struct wl_client *client,
1137 struct wl_resource *resource,
1140 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1142 ivi_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
1146 controller_layer_set_configuration(struct wl_client *client,
1147 struct wl_resource *resource,
1151 /* This interface has been supported yet. */
1159 controller_layer_set_orientation(struct wl_client *client,
1160 struct wl_resource *resource,
1161 int32_t orientation)
1163 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1165 ivi_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
1169 controller_layer_clear_surfaces(struct wl_client *client,
1170 struct wl_resource *resource)
1172 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1174 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
1178 controller_layer_add_surface(struct wl_client *client,
1179 struct wl_resource *resource,
1180 struct wl_resource *surface)
1182 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1183 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
1185 ivi_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
1189 controller_layer_remove_surface(struct wl_client *client,
1190 struct wl_resource *resource,
1191 struct wl_resource *surface)
1193 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1194 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
1196 ivi_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
1200 controller_layer_screenshot(struct wl_client *client,
1201 struct wl_resource *resource,
1202 const char *filename)
1210 controller_layer_set_render_order(struct wl_client *client,
1211 struct wl_resource *resource,
1212 struct wl_array *id_surfaces)
1214 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1215 struct ivi_layout_surface **layoutsurf_array = NULL;
1216 struct ivisurface *ivisurf = NULL;
1217 uint32_t *id_surface = NULL;
1218 uint32_t id_layout_surface = 0;
1222 layoutsurf_array = (struct ivi_layout_surface**)calloc(
1223 id_surfaces->size, sizeof(void*));
1225 wl_array_for_each(id_surface, id_surfaces) {
1226 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
1227 id_layout_surface = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1228 if (*id_surface == id_layout_surface) {
1229 layoutsurf_array[i] = ivisurf->layout_surface;
1236 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer,
1237 layoutsurf_array, i);
1238 free(layoutsurf_array);
1242 controller_layer_destroy(struct wl_client *client,
1243 struct wl_resource *resource,
1244 int32_t destroy_scene_object)
1246 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1247 struct ivishell *shell = ivilayer->shell;
1248 struct ivicontroller_layer *ctrllayer = NULL;
1249 struct ivicontroller_layer *next = NULL;
1250 uint32_t id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1252 (void)destroy_scene_object;
1254 ivilayer->layer_canbe_removed = 1;
1255 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
1256 if (ctrllayer->id_layer != id_layer) {
1260 wl_resource_destroy(ctrllayer->resource);
1265 struct ivi_controller_layer_interface controller_layer_implementation = {
1266 controller_layer_set_visibility,
1267 controller_layer_set_opacity,
1268 controller_layer_set_source_rectangle,
1269 controller_layer_set_destination_rectangle,
1270 controller_layer_set_configuration,
1271 controller_layer_set_orientation,
1272 controller_layer_screenshot,
1273 controller_layer_clear_surfaces,
1274 controller_layer_add_surface,
1275 controller_layer_remove_surface,
1276 controller_layer_set_render_order,
1277 controller_layer_destroy
1281 controller_screen_destroy(struct wl_client *client,
1282 struct wl_resource *resource)
1284 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1285 struct ivicontroller_screen *ctrlscrn = NULL;
1286 struct ivicontroller_screen *next = NULL;
1287 // uint32_t id_screen = ivi_layout_getIdOfScreen(iviscrn->layout_screen);
1290 wl_list_for_each_safe(ctrlscrn, next,
1291 &iviscrn->shell->list_controller_screen, link) {
1292 if (resource != ctrlscrn->resource) {
1296 wl_list_remove(&ctrlscrn->link);
1297 wl_resource_destroy(ctrlscrn->resource);
1305 controller_screen_clear(struct wl_client *client,
1306 struct wl_resource *resource)
1308 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1310 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
1314 controller_screen_add_layer(struct wl_client *client,
1315 struct wl_resource *resource,
1316 struct wl_resource *layer)
1318 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1319 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
1321 ivi_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
1325 controller_screen_screenshot(struct wl_client *client,
1326 struct wl_resource *resource,
1327 const char *filename)
1329 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1332 struct weston_output *output = NULL;
1333 cairo_surface_t *cairo_surf = NULL;
1338 uint8_t *readpixs = NULL;
1340 output = ivi_layout_screenGetOutput(iviscrn->layout_screen);
1341 --output->disable_planes;
1343 width = output->current_mode->width;
1344 height = output->current_mode->height;
1345 stride = width * (PIXMAN_FORMAT_BPP(output->compositor->read_format) / 8);
1347 readpixs = malloc(stride * height);
1348 if (readpixs == NULL) {
1349 weston_log("fails to allocate memory\n");
1353 output->compositor->renderer->read_pixels(
1355 output->compositor->read_format,
1362 save_as_bitmap(filename, readpixs, stride * height, width, height, PIXMAN_FORMAT_BPP(output->compositor->read_format));
1367 controller_screen_set_render_order(struct wl_client *client,
1368 struct wl_resource *resource,
1369 struct wl_array *id_layers)
1371 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1372 struct ivi_layout_layer **layoutlayer_array = NULL;
1373 struct ivilayer *ivilayer = NULL;
1374 uint32_t *id_layer = NULL;
1375 uint32_t id_layout_layer = 0;
1379 layoutlayer_array = (struct ivi_layout_layer**)calloc(
1380 id_layers->size, sizeof(void*));
1382 wl_array_for_each(id_layer, id_layers) {
1383 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1384 id_layout_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1385 if (*id_layer == id_layout_layer) {
1386 layoutlayer_array[i] = ivilayer->layout_layer;
1393 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen,
1394 layoutlayer_array, i);
1395 free(layoutlayer_array);
1399 struct ivi_controller_screen_interface controller_screen_implementation = {
1400 controller_screen_destroy,
1401 controller_screen_clear,
1402 controller_screen_add_layer,
1403 controller_screen_screenshot,
1404 controller_screen_set_render_order
1408 controller_commit_changes(struct wl_client *client,
1409 struct wl_resource *resource)
1415 ans = ivi_layout_commitChanges();
1417 weston_log("Failed to commit changes at controller_commit_changes\n");
1422 controller_layer_create(struct wl_client *client,
1423 struct wl_resource *resource,
1429 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1430 struct ivishell *shell = ctrl->shell;
1431 struct ivi_layout_layer *layout_layer = NULL;
1432 struct ivicontroller_layer *ctrllayer = NULL;
1433 struct ivilayer *ivilayer = NULL;
1434 struct ivi_layout_LayerProperties prop;
1436 ivilayer = get_layer(&shell->list_layer, id_layer);
1437 if (ivilayer == NULL) {
1438 layout_layer = ivi_layout_layerCreateWithDimension(id_layer,
1439 (uint32_t)width, (uint32_t)height);
1440 if (layout_layer == NULL) {
1441 weston_log("id_layer is already created\n");
1445 /* ivilayer will be created by layer_event_create */
1446 ivilayer = get_layer(&shell->list_layer, id_layer);
1447 if (ivilayer == NULL) {
1448 weston_log("couldn't get layer object\n");
1453 ctrllayer = calloc(1, sizeof *ctrllayer);
1455 weston_log("no memory to allocate client layer\n");
1459 ++ivilayer->controller_layer_count;
1460 ivilayer->layer_canbe_removed = 0;
1462 ctrllayer->shell = shell;
1463 ctrllayer->client = client;
1465 ctrllayer->id_layer = id_layer;
1466 ctrllayer->resource = wl_resource_create(client,
1467 &ivi_controller_layer_interface, 1, id);
1468 if (ctrllayer->resource == NULL) {
1469 weston_log("couldn't get layer object\n");
1473 wl_list_init(&ctrllayer->link);
1474 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1476 wl_resource_set_implementation(ctrllayer->resource,
1477 &controller_layer_implementation,
1478 ivilayer, destroy_ivicontroller_layer);
1480 memset(&prop, 0, sizeof prop);
1482 ivi_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1483 send_layer_event(ctrllayer->resource, ivilayer,
1484 &prop, IVI_NOTIFICATION_ALL);
1488 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1490 struct ivishell *shell = userdata;
1491 struct ivicontroller_surface *ctrlsurf = NULL;
1492 uint32_t id_surface = 0;
1495 surface_event_remove(layout_surface, userdata);
1500 controller_surface_create(struct wl_client *client,
1501 struct wl_resource *resource,
1502 uint32_t id_surface,
1505 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1506 struct ivishell *shell = ctrl->shell;
1507 struct ivicontroller_surface *ctrlsurf = NULL;
1508 struct ivi_layout_SurfaceProperties prop;
1509 struct ivisurface *ivisurf = NULL;
1510 struct ivicontroller_surface *ctrl_link = NULL;
1512 ivisurf = get_surface(&shell->list_surface, id_surface);
1513 if (ivisurf == NULL) {
1517 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1519 weston_log("no memory to allocate controller surface\n");
1523 ctrlsurf->shell = shell;
1524 ctrlsurf->client = client;
1526 ctrlsurf->id_surface = id_surface;
1527 wl_list_init(&ctrlsurf->link);
1528 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1530 ctrlsurf->resource = wl_resource_create(client,
1531 &ivi_controller_surface_interface, 1, id);
1532 if (ctrlsurf->resource == NULL) {
1533 weston_log("couldn't surface object");
1537 wl_list_for_each(ctrl_link, &shell->list_controller_surface, link) {
1538 if ((ctrl_link->implementation_set == 0) &&
1539 (ctrl_link->id_surface == id_surface) &&
1540 (ctrl_link->shell == shell) &&
1541 (ctrl_link->client != client)) {
1542 ++ivisurf->controller_surface_count;
1543 wl_resource_set_implementation(ctrl_link->resource,
1544 &controller_surface_implementation,
1545 ivisurf, destroy_ivicontroller_surface);
1546 ctrl_link->implementation_set = 1;
1550 ++ivisurf->controller_surface_count;
1552 wl_resource_set_implementation(ctrlsurf->resource,
1553 &controller_surface_implementation,
1554 ivisurf, destroy_ivicontroller_surface);
1556 ctrlsurf->implementation_set = 1;
1558 memset(&prop, 0, sizeof prop);
1560 ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1561 ivi_layout_surfaceSetContentObserver(ivisurf->layout_surface, surface_event_content, shell);
1563 send_surface_event(ctrlsurf->resource, ivisurf,
1564 &prop, IVI_NOTIFICATION_ALL);
1567 static const struct ivi_controller_interface controller_implementation = {
1568 controller_commit_changes,
1569 controller_layer_create,
1570 controller_surface_create
1574 add_client_to_resources(struct ivishell *shell,
1575 struct wl_client *client,
1576 struct ivicontroller *controller)
1578 struct ivisurface* ivisurf = NULL;
1579 struct ivilayer* ivilayer = NULL;
1580 struct iviscreen* iviscrn = NULL;
1581 struct ivicontroller_screen *ctrlscrn = NULL;
1582 struct wl_resource *resource_output = NULL;
1583 uint32_t id_layout_surface = 0;
1584 uint32_t id_layout_layer = 0;
1586 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1587 resource_output = wl_resource_find_for_client(
1588 &iviscrn->output->resource_list, client);
1589 if (resource_output == NULL) {
1593 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1594 if (ctrlscrn == NULL) {
1598 ivi_controller_send_screen(controller->resource,
1599 wl_resource_get_id(resource_output),
1600 ctrlscrn->resource);
1602 wl_list_for_each_reverse(ivilayer, &shell->list_layer, link) {
1604 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1606 ivi_controller_send_layer(controller->resource,
1609 wl_list_for_each_reverse(ivisurf, &shell->list_surface, link) {
1611 ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1613 ivi_controller_send_surface(controller->resource,
1619 bind_ivi_controller(struct wl_client *client, void *data,
1620 uint32_t version, uint32_t id)
1622 struct ivishell *shell = data;
1623 struct ivicontroller *controller;
1626 controller = calloc(1, sizeof *controller);
1627 if (controller == NULL) {
1628 weston_log("no memory to allocate controller\n");
1632 controller->resource =
1633 wl_resource_create(client, &ivi_controller_interface, 1, id);
1634 wl_resource_set_implementation(controller->resource,
1635 &controller_implementation,
1636 controller, unbind_resource_controller);
1638 controller->shell = shell;
1639 controller->client = client;
1640 controller->id = id;
1642 wl_list_init(&controller->link);
1643 wl_list_insert(&shell->list_controller, &controller->link);
1645 add_client_to_resources(shell, client, controller);
1648 static struct iviscreen*
1649 create_screen(struct ivishell *shell, struct weston_output *output)
1651 struct iviscreen *iviscrn;
1652 iviscrn = calloc(1, sizeof *iviscrn);
1653 if (iviscrn == NULL) {
1654 weston_log("no memory to allocate client screen\n");
1658 iviscrn->shell = shell;
1659 iviscrn->output = output;
1661 // TODO : Only Single display
1662 iviscrn->layout_screen = ivi_layout_getScreenFromId(0);
1664 wl_list_init(&iviscrn->link);
1669 static struct ivilayer*
1670 create_layer(struct ivishell *shell,
1671 struct ivi_layout_layer *layout_layer,
1674 struct ivilayer *ivilayer = NULL;
1675 struct ivicontroller *controller = NULL;
1677 ivilayer = get_layer(&shell->list_layer, id_layer);
1678 if (ivilayer != NULL) {
1679 weston_log("id_layer is already created\n");
1683 ivilayer = calloc(1, sizeof *ivilayer);
1684 if (NULL == ivilayer) {
1685 weston_log("no memory to allocate client layer\n");
1689 ivilayer->shell = shell;
1690 wl_list_init(&ivilayer->list_screen);
1691 wl_list_init(&ivilayer->link);
1692 wl_list_insert(&shell->list_layer, &ivilayer->link);
1693 ivilayer->layout_layer = layout_layer;
1695 ivi_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1697 wl_list_for_each(controller, &shell->list_controller, link) {
1698 ivi_controller_send_layer(controller->resource, id_layer);
1704 static struct ivisurface*
1705 create_surface(struct ivishell *shell,
1706 struct ivi_layout_surface *layout_surface,
1707 uint32_t id_surface)
1709 struct ivisurface *ivisurf = NULL;
1710 struct ivicontroller *controller = NULL;
1712 ivisurf = get_surface(&shell->list_surface, id_surface);
1713 if (ivisurf != NULL) {
1714 weston_log("id_surface is already created\n");
1718 ivisurf = calloc(1, sizeof *ivisurf);
1719 if (ivisurf == NULL) {
1720 weston_log("no memory to allocate client surface\n");
1724 ivisurf->shell = shell;
1725 ivisurf->layout_surface = layout_surface;
1726 wl_list_init(&ivisurf->list_layer);
1727 wl_list_init(&ivisurf->link);
1728 wl_list_insert(&shell->list_surface, &ivisurf->link);
1730 wl_list_for_each(controller, &shell->list_controller, link) {
1731 ivi_controller_send_surface(controller->resource,
1735 ivi_layout_surfaceAddNotification(layout_surface,
1736 send_surface_prop, ivisurf);
1742 layer_event_create(struct ivi_layout_layer *layout_layer,
1745 struct ivishell *shell = userdata;
1746 struct ivilayer *ivilayer = NULL;
1747 uint32_t id_layer = 0;
1749 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1751 ivilayer = create_layer(shell, layout_layer, id_layer);
1752 if (ivilayer == NULL) {
1753 weston_log("failed to create layer");
1759 layer_event_remove(struct ivi_layout_layer *layout_layer,
1762 struct ivishell *shell = userdata;
1763 struct ivicontroller_layer *ctrllayer = NULL;
1764 struct ivilayer *ivilayer = NULL;
1765 struct ivilayer *next = NULL;
1766 uint32_t id_layer = 0;
1769 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1770 if (layout_layer != ivilayer->layout_layer) {
1774 wl_list_remove(&ivilayer->link);
1783 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1785 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1786 if (id_layer != ctrllayer->id_layer) {
1789 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1796 surface_event_create(struct ivi_layout_surface *layout_surface,
1799 struct ivishell *shell = userdata;
1800 struct ivisurface *ivisurf = NULL;
1801 uint32_t id_surface = 0;
1802 struct ivicontroller_surface *ctrlsurf = NULL;
1804 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1806 ivisurf = create_surface(shell, layout_surface, id_surface);
1807 if (ivisurf == NULL) {
1808 weston_log("failed to create surface");
1812 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1813 if (id_surface != ctrlsurf->id_surface) {
1816 ivi_controller_surface_send_content(ctrlsurf->resource, IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_AVAILABLE);
1821 surface_event_remove(struct ivi_layout_surface *layout_surface,
1824 struct ivishell *shell = userdata;
1825 struct ivicontroller_surface *ctrlsurf = NULL;
1826 struct ivisurface *ivisurf = NULL;
1827 struct ivisurface *next = NULL;
1828 uint32_t id_surface = 0;
1831 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1832 if (layout_surface != ivisurf->layout_surface) {
1836 wl_list_remove(&ivisurf->link);
1839 if (ivisurf->controller_surface_count == 0) {
1843 ivisurf->can_be_removed = 1;
1850 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1852 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1853 if (id_surface != ctrlsurf->id_surface) {
1856 ivi_controller_surface_send_content(ctrlsurf->resource, IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED);
1857 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1863 surface_event_configure(struct ivi_layout_surface *layout_surface,
1866 struct ivishell *shell = userdata;
1867 struct ivisurface *ivisurf = NULL;
1868 struct ivicontroller_surface *ctrlsurf = NULL;
1869 struct ivi_layout_SurfaceProperties prop;
1870 uint32_t id_surface = 0;
1872 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1874 ivisurf = get_surface(&shell->list_surface, id_surface);
1875 if (ivisurf == NULL) {
1876 weston_log("id_surface is not created yet\n");
1880 memset(&prop, 0, sizeof prop);
1881 ivi_layout_getPropertiesOfSurface(layout_surface, &prop);
1883 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1884 if (id_surface != ctrlsurf->id_surface) {
1887 send_surface_event(ctrlsurf->resource, ivisurf,
1888 &prop, IVI_NOTIFICATION_ALL);
1893 check_layout_layers(struct ivishell *shell)
1895 struct ivi_layout_layer **pArray = NULL;
1896 struct ivilayer *ivilayer = NULL;
1897 uint32_t id_layer = 0;
1898 uint32_t length = 0;
1902 ret = ivi_layout_getLayers(&length, &pArray);
1904 weston_log("failed to get layers at check_layout_layers\n");
1909 /* if length is 0, pArray doesn't need to free.*/
1913 for (i = 0; i < length; i++) {
1914 id_layer = ivi_layout_getIdOfLayer(pArray[i]);
1915 ivilayer = create_layer(shell, pArray[i], id_layer);
1916 if (ivilayer == NULL) {
1917 weston_log("failed to create layer");
1928 check_layout_surfaces(struct ivishell *shell)
1930 struct ivi_layout_surface **pArray = NULL;
1931 struct ivisurface *ivisurf = NULL;
1932 uint32_t id_surface = 0;
1933 uint32_t length = 0;
1937 ret = ivi_layout_getSurfaces(&length, &pArray);
1939 weston_log("failed to get surfaces at check_layout_surfaces\n");
1944 /* if length is 0, pArray doesn't need to free.*/
1948 for (i = 0; i < length; i++) {
1949 id_surface = ivi_layout_getIdOfSurface(pArray[i]);
1950 ivisurf = create_surface(shell, pArray[i], id_surface);
1951 if (ivisurf == NULL) {
1952 weston_log("failed to create surface");
1963 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1965 struct weston_output *output = NULL;
1966 struct iviscreen *iviscrn = NULL;
1969 shell->compositor = ec;
1971 wl_list_init(&shell->list_surface);
1972 wl_list_init(&shell->list_layer);
1973 wl_list_init(&shell->list_screen);
1974 wl_list_init(&shell->list_weston_surface);
1975 wl_list_init(&shell->list_controller);
1976 wl_list_init(&shell->list_controller_screen);
1977 wl_list_init(&shell->list_controller_layer);
1978 wl_list_init(&shell->list_controller_surface);
1979 shell->event_restriction = 0;
1981 wl_list_for_each(output, &ec->output_list, link) {
1982 iviscrn = create_screen(shell, output);
1983 if (iviscrn != NULL) {
1984 wl_list_insert(&shell->list_screen, &iviscrn->link);
1988 ret = check_layout_layers(shell);
1990 weston_log("failed to check_layout_layers");
1993 ret = check_layout_surfaces(shell);
1995 weston_log("failed to check_layout_surfaces");
1998 ivi_layout_addNotificationCreateLayer(layer_event_create, shell);
1999 ivi_layout_addNotificationRemoveLayer(layer_event_remove, shell);
2001 ivi_layout_addNotificationCreateSurface(surface_event_create, shell);
2002 ivi_layout_addNotificationRemoveSurface(surface_event_remove, shell);
2003 ivi_layout_addNotificationConfigureSurface(surface_event_configure, shell);
2007 module_init(struct weston_compositor *ec,
2008 int *argc, char *argv[])
2010 struct ivishell *shell;
2014 shell = malloc(sizeof *shell);
2018 memset(shell, 0, sizeof *shell);
2019 init_ivi_shell(ec, shell);
2021 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
2022 shell, bind_ivi_controller) == NULL) {