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,
864 struct weston_renderer *renderer = compositor->renderer;
865 pixman_region32_t region;
866 uint8_t *readpixs = NULL;
867 int32_t stride = width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
868 GLuint fbo_id, tex_id;
870 readpixs = malloc(stride * height);
871 if (readpixs == NULL) {
872 fprintf(stderr, "Failed to allocate memory.\n");
876 pixman_region32_init_rect(®ion, x, y, width, height);
877 bind_framebuffer(&fbo_id, &tex_id, output->current_mode->width, output->current_mode->height);
878 renderer->repaint_output(output, ®ion);
881 y = output->current_mode->height - (y + height);
882 int result = renderer->read_pixels(output,
883 compositor->read_format,
889 unbind_framebuffer(fbo_id, tex_id);
891 save_as_bitmap(filename, readpixs, stride * height, width, height, PIXMAN_FORMAT_BPP(compositor->read_format));
896 clear_viewlist_but_specified_surface(struct weston_compositor *compositor,
897 struct weston_surface *surface)
899 struct weston_view *view = NULL;
900 wl_list_init(&compositor->view_list);
902 wl_list_for_each(view, &surface->views, surface_link) {
907 wl_list_insert(compositor->view_list.prev, &view->link);
912 get_gl_surface_rectangle(struct ivi_layout_SurfaceProperties *prop,
922 if ((prop->destX == 0) &&
923 (prop->destY == 0) &&
924 (prop->destWidth == 0) &&
925 (prop->destHeight == 0)) {
928 *width = prop->sourceWidth;
929 *height = prop->sourceHeight;
934 *width = prop->destWidth;
935 *height = prop->destHeight;
940 gl_surface_screenshot(struct ivisurface *ivisurf,
941 struct weston_surface *surface,
942 const char *filename)
944 struct weston_compositor *compositor = surface->compositor;
945 struct link_layer *link_layer = NULL;
946 struct link_screen *link_scrn = NULL;
947 struct ivi_layout_SurfaceProperties prop = {};
953 wl_list_for_each(link_layer, &ivisurf->list_layer, link) {
954 if (link_layer == NULL) {
958 wl_list_for_each(link_scrn, &link_layer->layer->list_screen, link) {
959 if (link_scrn != NULL) {
965 if (link_scrn == NULL) {
966 fprintf(stderr, "Failed to get iviscreen\n");
970 if (ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop) != 0) {
971 fprintf(stderr, "Failed to get surface properties.");
975 get_gl_surface_rectangle(&prop, &x, &y, &width, &height);
976 clear_viewlist_but_specified_surface(compositor, surface);
977 dump_surface(link_scrn->screen->output,
989 controller_surface_screenshot(struct wl_client *client,
990 struct wl_resource *resource,
991 const char *filename)
993 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
994 struct weston_surface *weston_surface = NULL;
999 weston_surface = ivi_layout_surfaceGetWestonSurface(ivisurf->layout_surface);
1000 if (weston_surface == NULL) {
1001 fprintf(stderr, "Failed to get weston surface.\n");
1005 if (ivi_layout_surfaceGetSize(ivisurf->layout_surface, &width, &height, &stride) != 0) {
1006 fprintf(stderr, "Failed to get surface size.\n");
1010 if (shm_surface_screenshot(weston_surface, width, height, stride, filename) != 0) {
1011 if (gl_surface_screenshot(ivisurf, weston_surface, filename) != 0) {
1012 fprintf(stderr, "Failed to capture surface.\n");
1019 controller_surface_send_stats(struct wl_client *client,
1020 struct wl_resource *resource)
1022 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1026 wl_client_get_credentials(client, &pid, &uid, &gid);
1028 ivi_controller_surface_send_stats(resource, 0, 0,
1029 ivisurf->update_count, pid, "");
1033 controller_surface_destroy(struct wl_client *client,
1034 struct wl_resource *resource,
1035 int32_t destroy_scene_object)
1038 (void)destroy_scene_object;
1039 wl_resource_destroy(resource);
1043 controller_surface_set_input_focus(struct wl_client *client,
1044 struct wl_resource *resource,
1055 struct ivi_controller_surface_interface controller_surface_implementation = {
1056 controller_surface_set_visibility,
1057 controller_surface_set_opacity,
1058 controller_surface_set_source_rectangle,
1059 controller_surface_set_destination_rectangle,
1060 controller_surface_set_configuration,
1061 controller_surface_set_orientation,
1062 controller_surface_screenshot,
1063 controller_surface_send_stats,
1064 controller_surface_destroy,
1065 controller_surface_set_input_focus
1069 controller_layer_set_source_rectangle(struct wl_client *client,
1070 struct wl_resource *resource,
1076 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1078 ivi_layout_layerSetSourceRectangle(ivilayer->layout_layer,
1079 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
1083 controller_layer_set_destination_rectangle(struct wl_client *client,
1084 struct wl_resource *resource,
1090 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1092 ivi_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
1093 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
1097 controller_layer_set_visibility(struct wl_client *client,
1098 struct wl_resource *resource,
1099 uint32_t visibility)
1101 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1103 ivi_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
1107 controller_layer_set_opacity(struct wl_client *client,
1108 struct wl_resource *resource,
1111 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1113 ivi_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
1117 controller_layer_set_configuration(struct wl_client *client,
1118 struct wl_resource *resource,
1122 /* This interface has been supported yet. */
1130 controller_layer_set_orientation(struct wl_client *client,
1131 struct wl_resource *resource,
1132 int32_t orientation)
1134 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1136 ivi_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
1140 controller_layer_clear_surfaces(struct wl_client *client,
1141 struct wl_resource *resource)
1143 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1145 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
1149 controller_layer_add_surface(struct wl_client *client,
1150 struct wl_resource *resource,
1151 struct wl_resource *surface)
1153 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1154 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
1156 ivi_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
1160 controller_layer_remove_surface(struct wl_client *client,
1161 struct wl_resource *resource,
1162 struct wl_resource *surface)
1164 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1165 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
1167 ivi_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
1171 controller_layer_screenshot(struct wl_client *client,
1172 struct wl_resource *resource,
1173 const char *filename)
1181 controller_layer_set_render_order(struct wl_client *client,
1182 struct wl_resource *resource,
1183 struct wl_array *id_surfaces)
1185 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1186 struct ivi_layout_surface **layoutsurf_array = NULL;
1187 struct ivisurface *ivisurf = NULL;
1188 uint32_t *id_surface = NULL;
1189 uint32_t id_layout_surface = 0;
1193 layoutsurf_array = (struct ivi_layout_surface**)calloc(
1194 id_surfaces->size, sizeof(void*));
1196 wl_array_for_each(id_surface, id_surfaces) {
1197 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
1198 id_layout_surface = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1199 if (*id_surface == id_layout_surface) {
1200 layoutsurf_array[i] = ivisurf->layout_surface;
1207 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer,
1208 layoutsurf_array, i);
1209 free(layoutsurf_array);
1213 controller_layer_destroy(struct wl_client *client,
1214 struct wl_resource *resource,
1215 int32_t destroy_scene_object)
1217 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1218 struct ivishell *shell = ivilayer->shell;
1219 struct ivicontroller_layer *ctrllayer = NULL;
1220 struct ivicontroller_layer *next = NULL;
1221 uint32_t id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1223 (void)destroy_scene_object;
1225 ivilayer->layer_canbe_removed = 1;
1226 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
1227 if (ctrllayer->id_layer != id_layer) {
1231 wl_resource_destroy(ctrllayer->resource);
1236 struct ivi_controller_layer_interface controller_layer_implementation = {
1237 controller_layer_set_visibility,
1238 controller_layer_set_opacity,
1239 controller_layer_set_source_rectangle,
1240 controller_layer_set_destination_rectangle,
1241 controller_layer_set_configuration,
1242 controller_layer_set_orientation,
1243 controller_layer_screenshot,
1244 controller_layer_clear_surfaces,
1245 controller_layer_add_surface,
1246 controller_layer_remove_surface,
1247 controller_layer_set_render_order,
1248 controller_layer_destroy
1252 controller_screen_destroy(struct wl_client *client,
1253 struct wl_resource *resource)
1255 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1256 struct ivicontroller_screen *ctrlscrn = NULL;
1257 struct ivicontroller_screen *next = NULL;
1258 // uint32_t id_screen = ivi_layout_getIdOfScreen(iviscrn->layout_screen);
1261 wl_list_for_each_safe(ctrlscrn, next,
1262 &iviscrn->shell->list_controller_screen, link) {
1263 if (resource != ctrlscrn->resource) {
1267 wl_list_remove(&ctrlscrn->link);
1268 wl_resource_destroy(ctrlscrn->resource);
1276 controller_screen_clear(struct wl_client *client,
1277 struct wl_resource *resource)
1279 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1281 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
1285 controller_screen_add_layer(struct wl_client *client,
1286 struct wl_resource *resource,
1287 struct wl_resource *layer)
1289 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1290 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
1292 ivi_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
1296 controller_screen_screenshot(struct wl_client *client,
1297 struct wl_resource *resource,
1298 const char *filename)
1300 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1303 struct weston_output *output = NULL;
1304 cairo_surface_t *cairo_surf = NULL;
1309 uint8_t *readpixs = NULL;
1311 output = ivi_layout_screenGetOutput(iviscrn->layout_screen);
1312 --output->disable_planes;
1314 width = output->current_mode->width;
1315 height = output->current_mode->height;
1316 stride = width * (PIXMAN_FORMAT_BPP(output->compositor->read_format) / 8);
1318 readpixs = malloc(stride * height);
1319 if (readpixs == NULL) {
1320 weston_log("fails to allocate memory\n");
1324 output->compositor->renderer->read_pixels(
1326 output->compositor->read_format,
1333 save_as_bitmap(filename, readpixs, stride * height, width, height, PIXMAN_FORMAT_BPP(output->compositor->read_format));
1338 controller_screen_set_render_order(struct wl_client *client,
1339 struct wl_resource *resource,
1340 struct wl_array *id_layers)
1342 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1343 struct ivi_layout_layer **layoutlayer_array = NULL;
1344 struct ivilayer *ivilayer = NULL;
1345 uint32_t *id_layer = NULL;
1346 uint32_t id_layout_layer = 0;
1350 layoutlayer_array = (struct ivi_layout_layer**)calloc(
1351 id_layers->size, sizeof(void*));
1353 wl_array_for_each(id_layer, id_layers) {
1354 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1355 id_layout_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1356 if (*id_layer == id_layout_layer) {
1357 layoutlayer_array[i] = ivilayer->layout_layer;
1364 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen,
1365 layoutlayer_array, i);
1366 free(layoutlayer_array);
1370 struct ivi_controller_screen_interface controller_screen_implementation = {
1371 controller_screen_destroy,
1372 controller_screen_clear,
1373 controller_screen_add_layer,
1374 controller_screen_screenshot,
1375 controller_screen_set_render_order
1379 controller_commit_changes(struct wl_client *client,
1380 struct wl_resource *resource)
1386 ans = ivi_layout_commitChanges();
1388 weston_log("Failed to commit changes at controller_commit_changes\n");
1393 controller_layer_create(struct wl_client *client,
1394 struct wl_resource *resource,
1400 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1401 struct ivishell *shell = ctrl->shell;
1402 struct ivi_layout_layer *layout_layer = NULL;
1403 struct ivicontroller_layer *ctrllayer = NULL;
1404 struct ivilayer *ivilayer = NULL;
1405 struct ivi_layout_LayerProperties prop;
1407 ivilayer = get_layer(&shell->list_layer, id_layer);
1408 if (ivilayer == NULL) {
1409 layout_layer = ivi_layout_layerCreateWithDimension(id_layer,
1410 (uint32_t)width, (uint32_t)height);
1411 if (layout_layer == NULL) {
1412 weston_log("id_layer is already created\n");
1416 /* ivilayer will be created by layer_event_create */
1417 ivilayer = get_layer(&shell->list_layer, id_layer);
1418 if (ivilayer == NULL) {
1419 weston_log("couldn't get layer object\n");
1424 ctrllayer = calloc(1, sizeof *ctrllayer);
1426 weston_log("no memory to allocate client layer\n");
1430 ++ivilayer->controller_layer_count;
1431 ivilayer->layer_canbe_removed = 0;
1433 ctrllayer->shell = shell;
1434 ctrllayer->client = client;
1436 ctrllayer->id_layer = id_layer;
1437 ctrllayer->resource = wl_resource_create(client,
1438 &ivi_controller_layer_interface, 1, id);
1439 if (ctrllayer->resource == NULL) {
1440 weston_log("couldn't get layer object\n");
1444 wl_list_init(&ctrllayer->link);
1445 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1447 wl_resource_set_implementation(ctrllayer->resource,
1448 &controller_layer_implementation,
1449 ivilayer, destroy_ivicontroller_layer);
1451 memset(&prop, 0, sizeof prop);
1453 ivi_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1454 send_layer_event(ctrllayer->resource, ivilayer,
1455 &prop, IVI_NOTIFICATION_ALL);
1459 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1461 struct ivishell *shell = userdata;
1462 struct ivicontroller_surface *ctrlsurf = NULL;
1463 uint32_t id_surface = 0;
1466 surface_event_remove(layout_surface, userdata);
1471 controller_surface_create(struct wl_client *client,
1472 struct wl_resource *resource,
1473 uint32_t id_surface,
1476 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1477 struct ivishell *shell = ctrl->shell;
1478 struct ivicontroller_surface *ctrlsurf = NULL;
1479 struct ivi_layout_SurfaceProperties prop;
1480 struct ivisurface *ivisurf = NULL;
1481 struct ivicontroller_surface *ctrl_link = NULL;
1483 ivisurf = get_surface(&shell->list_surface, id_surface);
1484 if (ivisurf == NULL) {
1488 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1490 weston_log("no memory to allocate controller surface\n");
1494 ctrlsurf->shell = shell;
1495 ctrlsurf->client = client;
1497 ctrlsurf->id_surface = id_surface;
1498 wl_list_init(&ctrlsurf->link);
1499 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1501 ctrlsurf->resource = wl_resource_create(client,
1502 &ivi_controller_surface_interface, 1, id);
1503 if (ctrlsurf->resource == NULL) {
1504 weston_log("couldn't surface object");
1508 wl_list_for_each(ctrl_link, &shell->list_controller_surface, link) {
1509 if ((ctrl_link->implementation_set == 0) &&
1510 (ctrl_link->id_surface == id_surface) &&
1511 (ctrl_link->shell == shell) &&
1512 (ctrl_link->client != client)) {
1513 ++ivisurf->controller_surface_count;
1514 wl_resource_set_implementation(ctrl_link->resource,
1515 &controller_surface_implementation,
1516 ivisurf, destroy_ivicontroller_surface);
1517 ctrl_link->implementation_set = 1;
1521 ++ivisurf->controller_surface_count;
1523 wl_resource_set_implementation(ctrlsurf->resource,
1524 &controller_surface_implementation,
1525 ivisurf, destroy_ivicontroller_surface);
1527 ctrlsurf->implementation_set = 1;
1529 memset(&prop, 0, sizeof prop);
1531 ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1532 ivi_layout_surfaceSetContentObserver(ivisurf->layout_surface, surface_event_content, shell);
1534 send_surface_event(ctrlsurf->resource, ivisurf,
1535 &prop, IVI_NOTIFICATION_ALL);
1538 static const struct ivi_controller_interface controller_implementation = {
1539 controller_commit_changes,
1540 controller_layer_create,
1541 controller_surface_create
1545 add_client_to_resources(struct ivishell *shell,
1546 struct wl_client *client,
1547 struct ivicontroller *controller)
1549 struct ivisurface* ivisurf = NULL;
1550 struct ivilayer* ivilayer = NULL;
1551 struct iviscreen* iviscrn = NULL;
1552 struct ivicontroller_screen *ctrlscrn = NULL;
1553 struct wl_resource *resource_output = NULL;
1554 uint32_t id_layout_surface = 0;
1555 uint32_t id_layout_layer = 0;
1557 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1558 resource_output = wl_resource_find_for_client(
1559 &iviscrn->output->resource_list, client);
1560 if (resource_output == NULL) {
1564 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1565 if (ctrlscrn == NULL) {
1569 ivi_controller_send_screen(controller->resource,
1570 wl_resource_get_id(resource_output),
1571 ctrlscrn->resource);
1573 wl_list_for_each_reverse(ivilayer, &shell->list_layer, link) {
1575 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1577 ivi_controller_send_layer(controller->resource,
1580 wl_list_for_each_reverse(ivisurf, &shell->list_surface, link) {
1582 ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1584 ivi_controller_send_surface(controller->resource,
1590 bind_ivi_controller(struct wl_client *client, void *data,
1591 uint32_t version, uint32_t id)
1593 struct ivishell *shell = data;
1594 struct ivicontroller *controller;
1597 controller = calloc(1, sizeof *controller);
1598 if (controller == NULL) {
1599 weston_log("no memory to allocate controller\n");
1603 controller->resource =
1604 wl_resource_create(client, &ivi_controller_interface, 1, id);
1605 wl_resource_set_implementation(controller->resource,
1606 &controller_implementation,
1607 controller, unbind_resource_controller);
1609 controller->shell = shell;
1610 controller->client = client;
1611 controller->id = id;
1613 wl_list_init(&controller->link);
1614 wl_list_insert(&shell->list_controller, &controller->link);
1616 add_client_to_resources(shell, client, controller);
1619 static struct iviscreen*
1620 create_screen(struct ivishell *shell, struct weston_output *output)
1622 struct iviscreen *iviscrn;
1623 iviscrn = calloc(1, sizeof *iviscrn);
1624 if (iviscrn == NULL) {
1625 weston_log("no memory to allocate client screen\n");
1629 iviscrn->shell = shell;
1630 iviscrn->output = output;
1632 // TODO : Only Single display
1633 iviscrn->layout_screen = ivi_layout_getScreenFromId(0);
1635 wl_list_init(&iviscrn->link);
1640 static struct ivilayer*
1641 create_layer(struct ivishell *shell,
1642 struct ivi_layout_layer *layout_layer,
1645 struct ivilayer *ivilayer = NULL;
1646 struct ivicontroller *controller = NULL;
1648 ivilayer = get_layer(&shell->list_layer, id_layer);
1649 if (ivilayer != NULL) {
1650 weston_log("id_layer is already created\n");
1654 ivilayer = calloc(1, sizeof *ivilayer);
1655 if (NULL == ivilayer) {
1656 weston_log("no memory to allocate client layer\n");
1660 ivilayer->shell = shell;
1661 wl_list_init(&ivilayer->list_screen);
1662 wl_list_init(&ivilayer->link);
1663 wl_list_insert(&shell->list_layer, &ivilayer->link);
1664 ivilayer->layout_layer = layout_layer;
1666 ivi_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1668 wl_list_for_each(controller, &shell->list_controller, link) {
1669 ivi_controller_send_layer(controller->resource, id_layer);
1675 static struct ivisurface*
1676 create_surface(struct ivishell *shell,
1677 struct ivi_layout_surface *layout_surface,
1678 uint32_t id_surface)
1680 struct ivisurface *ivisurf = NULL;
1681 struct ivicontroller *controller = NULL;
1683 ivisurf = get_surface(&shell->list_surface, id_surface);
1684 if (ivisurf != NULL) {
1685 weston_log("id_surface is already created\n");
1689 ivisurf = calloc(1, sizeof *ivisurf);
1690 if (ivisurf == NULL) {
1691 weston_log("no memory to allocate client surface\n");
1695 ivisurf->shell = shell;
1696 ivisurf->layout_surface = layout_surface;
1697 wl_list_init(&ivisurf->list_layer);
1698 wl_list_init(&ivisurf->link);
1699 wl_list_insert(&shell->list_surface, &ivisurf->link);
1701 wl_list_for_each(controller, &shell->list_controller, link) {
1702 ivi_controller_send_surface(controller->resource,
1706 ivi_layout_surfaceAddNotification(layout_surface,
1707 send_surface_prop, ivisurf);
1713 layer_event_create(struct ivi_layout_layer *layout_layer,
1716 struct ivishell *shell = userdata;
1717 struct ivilayer *ivilayer = NULL;
1718 uint32_t id_layer = 0;
1720 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1722 ivilayer = create_layer(shell, layout_layer, id_layer);
1723 if (ivilayer == NULL) {
1724 weston_log("failed to create layer");
1730 layer_event_remove(struct ivi_layout_layer *layout_layer,
1733 struct ivishell *shell = userdata;
1734 struct ivicontroller_layer *ctrllayer = NULL;
1735 struct ivilayer *ivilayer = NULL;
1736 struct ivilayer *next = NULL;
1737 uint32_t id_layer = 0;
1740 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1741 if (layout_layer != ivilayer->layout_layer) {
1745 wl_list_remove(&ivilayer->link);
1754 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1756 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1757 if (id_layer != ctrllayer->id_layer) {
1760 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1767 surface_event_create(struct ivi_layout_surface *layout_surface,
1770 struct ivishell *shell = userdata;
1771 struct ivisurface *ivisurf = NULL;
1772 uint32_t id_surface = 0;
1773 struct ivicontroller_surface *ctrlsurf = NULL;
1775 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1777 ivisurf = create_surface(shell, layout_surface, id_surface);
1778 if (ivisurf == NULL) {
1779 weston_log("failed to create surface");
1783 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1784 if (id_surface != ctrlsurf->id_surface) {
1787 ivi_controller_surface_send_content(ctrlsurf->resource, IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_AVAILABLE);
1792 surface_event_remove(struct ivi_layout_surface *layout_surface,
1795 struct ivishell *shell = userdata;
1796 struct ivicontroller_surface *ctrlsurf = NULL;
1797 struct ivisurface *ivisurf = NULL;
1798 struct ivisurface *next = NULL;
1799 uint32_t id_surface = 0;
1802 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1803 if (layout_surface != ivisurf->layout_surface) {
1807 wl_list_remove(&ivisurf->link);
1810 if (ivisurf->controller_surface_count == 0) {
1814 ivisurf->can_be_removed = 1;
1821 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1823 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1824 if (id_surface != ctrlsurf->id_surface) {
1827 ivi_controller_surface_send_content(ctrlsurf->resource, IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED);
1828 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1834 surface_event_configure(struct ivi_layout_surface *layout_surface,
1837 struct ivishell *shell = userdata;
1838 struct ivisurface *ivisurf = NULL;
1839 struct ivicontroller_surface *ctrlsurf = NULL;
1840 struct ivi_layout_SurfaceProperties prop;
1841 uint32_t id_surface = 0;
1843 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1845 ivisurf = get_surface(&shell->list_surface, id_surface);
1846 if (ivisurf == NULL) {
1847 weston_log("id_surface is not created yet\n");
1851 memset(&prop, 0, sizeof prop);
1852 ivi_layout_getPropertiesOfSurface(layout_surface, &prop);
1854 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1855 if (id_surface != ctrlsurf->id_surface) {
1858 send_surface_event(ctrlsurf->resource, ivisurf,
1859 &prop, IVI_NOTIFICATION_ALL);
1864 check_layout_layers(struct ivishell *shell)
1866 struct ivi_layout_layer **pArray = NULL;
1867 struct ivilayer *ivilayer = NULL;
1868 uint32_t id_layer = 0;
1869 uint32_t length = 0;
1873 ret = ivi_layout_getLayers(&length, &pArray);
1875 weston_log("failed to get layers at check_layout_layers\n");
1880 /* if length is 0, pArray doesn't need to free.*/
1884 for (i = 0; i < length; i++) {
1885 id_layer = ivi_layout_getIdOfLayer(pArray[i]);
1886 ivilayer = create_layer(shell, pArray[i], id_layer);
1887 if (ivilayer == NULL) {
1888 weston_log("failed to create layer");
1899 check_layout_surfaces(struct ivishell *shell)
1901 struct ivi_layout_surface **pArray = NULL;
1902 struct ivisurface *ivisurf = NULL;
1903 uint32_t id_surface = 0;
1904 uint32_t length = 0;
1908 ret = ivi_layout_getSurfaces(&length, &pArray);
1910 weston_log("failed to get surfaces at check_layout_surfaces\n");
1915 /* if length is 0, pArray doesn't need to free.*/
1919 for (i = 0; i < length; i++) {
1920 id_surface = ivi_layout_getIdOfSurface(pArray[i]);
1921 ivisurf = create_surface(shell, pArray[i], id_surface);
1922 if (ivisurf == NULL) {
1923 weston_log("failed to create surface");
1934 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1936 struct weston_output *output = NULL;
1937 struct iviscreen *iviscrn = NULL;
1940 shell->compositor = ec;
1942 wl_list_init(&shell->list_surface);
1943 wl_list_init(&shell->list_layer);
1944 wl_list_init(&shell->list_screen);
1945 wl_list_init(&shell->list_weston_surface);
1946 wl_list_init(&shell->list_controller);
1947 wl_list_init(&shell->list_controller_screen);
1948 wl_list_init(&shell->list_controller_layer);
1949 wl_list_init(&shell->list_controller_surface);
1950 shell->event_restriction = 0;
1952 wl_list_for_each(output, &ec->output_list, link) {
1953 iviscrn = create_screen(shell, output);
1954 if (iviscrn != NULL) {
1955 wl_list_insert(&shell->list_screen, &iviscrn->link);
1959 ret = check_layout_layers(shell);
1961 weston_log("failed to check_layout_layers");
1964 ret = check_layout_surfaces(shell);
1966 weston_log("failed to check_layout_surfaces");
1969 ivi_layout_addNotificationCreateLayer(layer_event_create, shell);
1970 ivi_layout_addNotificationRemoveLayer(layer_event_remove, shell);
1972 ivi_layout_addNotificationCreateSurface(surface_event_create, shell);
1973 ivi_layout_addNotificationRemoveSurface(surface_event_remove, shell);
1974 ivi_layout_addNotificationConfigureSurface(surface_event_configure, shell);
1978 module_init(struct weston_compositor *ec,
1979 int *argc, char *argv[])
1981 struct ivishell *shell;
1985 shell = malloc(sizeof *shell);
1989 memset(shell, 0, sizeof *shell);
1990 init_ivi_shell(ec, shell);
1992 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
1993 shell, bind_ivi_controller) == NULL) {