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 "ivi-controller-server-protocol.h"
38 #include "ivi-layout-export.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 *);
167 destroy_ivicontroller_surface(struct wl_resource *resource)
169 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
170 struct ivishell *shell = ivisurf->shell;
171 struct ivicontroller_surface *ctrlsurf = NULL;
172 struct ivicontroller_surface *next = NULL;
175 wl_list_for_each_safe(ctrlsurf, next,
176 &shell->list_controller_surface, link) {
178 if (resource != ctrlsurf->resource) {
182 if (!wl_list_empty(&ctrlsurf->link)) {
183 wl_list_remove(&ctrlsurf->link);
189 --ivisurf->controller_surface_count;
193 if ((is_removed) && (ivisurf->controller_surface_count == 0)) {
194 if (ivisurf->can_be_removed) {
201 destroy_ivicontroller_layer(struct wl_resource *resource)
203 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
204 struct ivishell *shell = ivilayer->shell;
205 struct ivicontroller_layer *ctrllayer = NULL;
206 struct ivicontroller_layer *next = NULL;
207 uint32_t id_layer = 0;
209 id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
211 wl_list_for_each_safe(ctrllayer, next,
212 &shell->list_controller_layer, link) {
214 if (resource != ctrllayer->resource) {
218 wl_list_remove(&ctrllayer->link);
219 --ivilayer->controller_layer_count;
220 ivi_controller_layer_send_destroyed(ctrllayer->resource);
226 if ((ivilayer->layout_layer != NULL) &&
227 (ivilayer->controller_layer_count == 0) &&
228 (ivilayer->layer_canbe_removed == 1)) {
229 ivi_layout_layerRemove(ivilayer->layout_layer);
234 destroy_ivicontroller_screen(struct wl_resource *resource)
236 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
237 struct ivicontroller_screen *ctrlscrn = NULL;
238 struct ivicontroller_screen *next = NULL;
240 wl_list_for_each_safe(ctrlscrn, next,
241 &iviscrn->shell->list_controller_screen, link) {
242 // TODO : Only Single display
244 if (iviscrn->output->id != ctrlscrn->id_screen) {
249 if (resource != ctrlscrn->resource) {
253 wl_list_remove(&ctrlscrn->link);
261 unbind_resource_controller(struct wl_resource *resource)
263 struct ivicontroller *controller = wl_resource_get_user_data(resource);
265 wl_list_remove(&controller->link);
271 static struct ivisurface*
272 get_surface(struct wl_list *list_surf, uint32_t id_surface)
274 struct ivisurface *ivisurf = NULL;
275 uint32_t ivisurf_id = 0;
277 wl_list_for_each(ivisurf, list_surf, link) {
278 ivisurf_id = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
279 if (ivisurf_id == id_surface) {
287 static struct ivilayer*
288 get_layer(struct wl_list *list_layer, uint32_t id_layer)
290 struct ivilayer *ivilayer = NULL;
291 uint32_t ivilayer_id = 0;
293 wl_list_for_each(ivilayer, list_layer, link) {
294 ivilayer_id = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
295 if (ivilayer_id == id_layer) {
304 struct ivi_controller_screen_interface controller_screen_implementation;
306 static struct ivicontroller_screen*
307 controller_screen_create(struct ivishell *shell,
308 struct wl_client *client,
309 struct iviscreen *iviscrn)
311 struct ivicontroller_screen *ctrlscrn = NULL;
313 ctrlscrn = calloc(1, sizeof *ctrlscrn);
314 if (ctrlscrn == NULL) {
315 weston_log("no memory to allocate controller screen\n");
319 ctrlscrn->client = client;
320 ctrlscrn->shell = shell;
322 // TODO : Only Single display
324 /* ctrlscrn->id_screen = iviscrn->id_screen; */
326 ctrlscrn->id_screen = 0;
330 wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
331 if (ctrlscrn->resource == NULL) {
332 weston_log("couldn't new screen controller object");
340 wl_resource_set_implementation(ctrlscrn->resource,
341 &controller_screen_implementation,
342 iviscrn, destroy_ivicontroller_screen);
344 wl_list_init(&ctrlscrn->link);
345 wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
351 send_surface_add_event(struct ivisurface *ivisurf,
352 struct wl_resource *resource,
353 enum ivi_layout_notification_mask mask)
355 struct ivi_layout_layer **pArray = NULL;
359 struct link_layer *link_layer = NULL;
360 struct link_layer *next = NULL;
361 struct ivicontroller_layer *ctrllayer = NULL;
362 struct ivilayer *ivilayer = NULL;
363 struct ivishell *shell = ivisurf->shell;
364 uint32_t id_layout_layer = 0;
365 struct wl_client *surface_client = wl_resource_get_client(resource);
368 ans = ivi_layout_getLayersUnderSurface(ivisurf->layout_surface,
371 weston_log("failed to get layers at send_surface_add_event\n");
375 /* Send Null to cancel added surface */
376 if (mask & IVI_NOTIFICATION_REMOVE) {
377 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
378 ivi_controller_surface_send_layer(resource, NULL);
381 else if (mask & IVI_NOTIFICATION_ADD) {
382 for (i = 0; i < (int)length; i++) {
383 /* Send new surface event */
385 wl_list_for_each(ivilayer, &shell->list_layer, link) {
386 if (ivilayer->layout_layer == pArray[i]) {
391 if (ivilayer == NULL) {
396 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
397 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
398 if (id_layout_layer != ctrllayer->id_layer) {
402 struct wl_client *layer_client = wl_resource_get_client(ctrllayer->resource);
403 if (surface_client != layer_client) {
407 ivi_controller_surface_send_layer(resource, ctrllayer->resource);
417 send_surface_event(struct wl_resource *resource,
418 struct ivisurface *ivisurf,
419 struct ivi_layout_SurfaceProperties *prop,
422 if (mask & IVI_NOTIFICATION_OPACITY) {
423 ivi_controller_surface_send_opacity(resource,
424 wl_fixed_from_double(prop->opacity));
426 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
427 ivi_controller_surface_send_source_rectangle(resource,
428 prop->sourceX, prop->sourceY,
429 prop->sourceWidth, prop->sourceHeight);
431 if (mask & IVI_NOTIFICATION_DEST_RECT) {
432 ivi_controller_surface_send_destination_rectangle(resource,
433 prop->destX, prop->destY,
434 prop->destWidth, prop->destHeight);
436 if (mask & IVI_NOTIFICATION_ORIENTATION) {
437 ivi_controller_surface_send_orientation(resource,
440 if (mask & IVI_NOTIFICATION_VISIBILITY) {
441 ivi_controller_surface_send_visibility(resource,
444 if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
445 ivi_controller_surface_send_pixelformat(resource,
448 if (mask & IVI_NOTIFICATION_KEYBOARD_FOCUS) {
449 ivi_controller_surface_send_input_focus(resource,
450 IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD,
451 prop->hasKeyboardFocus);
453 if (mask & IVI_NOTIFICATION_REMOVE) {
454 send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_REMOVE);
456 if (mask & IVI_NOTIFICATION_ADD) {
457 send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_ADD);
462 update_surface_prop(struct ivisurface *ivisurf,
465 struct ivi_layout_layer **pArray = NULL;
469 struct ivishell *shell = ivisurf->shell;
471 ans = ivi_layout_getLayersUnderSurface(ivisurf->layout_surface,
474 weston_log("failed to get layers at send_surface_add_event\n");
478 if (mask & IVI_NOTIFICATION_REMOVE) {
479 struct link_layer *link_layer = NULL;
480 struct link_layer *next = NULL;
482 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
483 wl_list_remove(&link_layer->link);
488 if (mask & IVI_NOTIFICATION_ADD) {
489 for (i = 0; i < (int)length; ++i) {
490 /* Create list_layer */
491 struct ivilayer *ivilayer = NULL;
492 struct link_layer *link_layer = calloc(1, sizeof(*link_layer));
493 if (NULL == link_layer) {
496 wl_list_init(&link_layer->link);
497 link_layer->layer = NULL;
498 wl_list_for_each(ivilayer, &shell->list_layer, link) {
499 if (ivilayer->layout_layer == pArray[i]) {
500 link_layer->layer = ivilayer;
505 if (link_layer->layer == NULL) {
511 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
517 send_surface_prop(struct ivi_layout_surface *layout_surface,
518 struct ivi_layout_SurfaceProperties *prop,
519 enum ivi_layout_notification_mask mask,
522 struct ivisurface *ivisurf = userdata;
523 struct ivishell *shell = ivisurf->shell;
524 struct ivicontroller_surface *ctrlsurf = NULL;
525 uint32_t id_surface = 0;
527 id_surface = ivi_layout_getIdOfSurface(layout_surface);
529 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
530 if (id_surface != ctrlsurf->id_surface) {
533 send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
536 update_surface_prop(ivisurf, mask);
540 send_layer_add_event(struct ivilayer *ivilayer,
541 struct wl_resource *resource,
542 enum ivi_layout_notification_mask mask)
544 struct ivi_layout_screen **pArray = NULL;
548 struct link_screen *link_scrn = NULL;
549 struct link_screen *next = NULL;
550 struct iviscreen *iviscrn = NULL;
551 struct ivishell *shell = ivilayer->shell;
552 struct wl_client *client = wl_resource_get_client(resource);
553 struct wl_resource *resource_output = NULL;
555 ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
558 weston_log("failed to get screens at send_layer_add_event\n");
562 /* Send Null to cancel added layer */
563 if (mask & IVI_NOTIFICATION_REMOVE) {
564 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
565 ivi_controller_layer_send_screen(resource, NULL);
568 else if (mask & IVI_NOTIFICATION_ADD) {
569 for (i = 0; i < (int)length; i++) {
570 /* Send new layer event */
572 wl_list_for_each(iviscrn, &shell->list_screen, link) {
573 if (iviscrn->layout_screen == pArray[i]) {
578 if (iviscrn == NULL) {
583 wl_resource_find_for_client(&iviscrn->output->resource_list,
585 if (resource_output != NULL) {
586 ivi_controller_layer_send_screen(resource, resource_output);
596 send_layer_event(struct wl_resource *resource,
597 struct ivilayer *ivilayer,
598 struct ivi_layout_LayerProperties *prop,
601 if (mask & IVI_NOTIFICATION_OPACITY) {
602 ivi_controller_layer_send_opacity(resource,
603 wl_fixed_from_double(prop->opacity));
605 if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
606 ivi_controller_layer_send_source_rectangle(resource,
612 if (mask & IVI_NOTIFICATION_DEST_RECT) {
613 ivi_controller_layer_send_destination_rectangle(resource,
619 if (mask & IVI_NOTIFICATION_ORIENTATION) {
620 ivi_controller_layer_send_orientation(resource,
623 if (mask & IVI_NOTIFICATION_VISIBILITY) {
624 ivi_controller_layer_send_visibility(resource,
627 if (mask & IVI_NOTIFICATION_REMOVE) {
628 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_REMOVE);
630 if (mask & IVI_NOTIFICATION_ADD) {
631 send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_ADD);
636 update_layer_prop(struct ivilayer *ivilayer,
637 enum ivi_layout_notification_mask mask)
639 struct ivi_layout_screen **pArray = NULL;
642 struct link_screen *link_scrn = NULL;
643 struct link_screen *next = NULL;
645 ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
648 weston_log("failed to get screens at send_layer_add_event\n");
652 /* Send Null to cancel added layer */
653 if (mask & IVI_NOTIFICATION_REMOVE) {
654 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
655 wl_list_remove(&link_scrn->link);
660 if (mask & IVI_NOTIFICATION_ADD) {
662 for (i = 0; i < (int)length; i++) {
663 struct ivishell *shell = ivilayer->shell;
664 struct iviscreen *iviscrn = NULL;
665 /* Create list_screen */
666 link_scrn = calloc(1, sizeof(*link_scrn));
667 if (NULL == link_scrn) {
670 wl_list_init(&link_scrn->link);
671 link_scrn->screen = NULL;
672 wl_list_for_each(iviscrn, &shell->list_screen, link) {
673 if (iviscrn->layout_screen == pArray[i]) {
674 link_scrn->screen = iviscrn;
679 if (link_scrn->screen == NULL) {
684 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
693 send_layer_prop(struct ivi_layout_layer *layer,
694 struct ivi_layout_LayerProperties *prop,
695 enum ivi_layout_notification_mask mask,
698 struct ivilayer *ivilayer = userdata;
699 struct ivicontroller_layer *ctrllayer = NULL;
700 struct ivishell *shell = ivilayer->shell;
701 uint32_t id_layout_layer = 0;
703 id_layout_layer = ivi_layout_getIdOfLayer(layer);
704 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
705 if (id_layout_layer != ctrllayer->id_layer) {
708 send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
711 update_layer_prop(ivilayer, mask);
715 controller_surface_set_opacity(struct wl_client *client,
716 struct wl_resource *resource,
719 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
721 ivi_layout_surfaceSetOpacity(ivisurf->layout_surface,
722 wl_fixed_to_double(opacity));
726 controller_surface_set_source_rectangle(struct wl_client *client,
727 struct wl_resource *resource,
733 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
735 ivi_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
736 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
740 controller_surface_set_destination_rectangle(struct wl_client *client,
741 struct wl_resource *resource,
747 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
750 // TODO: create set transition type protocol
751 ivi_layout_surfaceSetTransition( ivisurf->layout_surface,
752 IVI_LAYOUT_TRANSITION_NONE,
755 ivi_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
756 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
760 controller_surface_set_visibility(struct wl_client *client,
761 struct wl_resource *resource,
764 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
766 ivi_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
770 controller_surface_set_configuration(struct wl_client *client,
771 struct wl_resource *resource,
772 int32_t width, int32_t height)
774 /* This interface has been supported yet. */
782 controller_surface_set_orientation(struct wl_client *client,
783 struct wl_resource *resource,
786 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
788 ivi_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
792 shm_surface_screenshot(struct weston_surface *surface,
796 const char *filename)
798 struct weston_buffer *weston_buffer = NULL;
799 struct wl_shm_buffer *shm_buffer = NULL;
800 cairo_surface_t *cairo_surf = NULL;
801 uint8_t *source_buffer = NULL;
802 uint8_t *dest_buffer = NULL;
804 weston_buffer = surface->buffer_ref.buffer;
805 if (weston_buffer == NULL) {
806 fprintf(stderr, "Failed to get weston buffer.\n");
810 shm_buffer = wl_shm_buffer_get(weston_buffer->resource);
811 if (shm_buffer == NULL) {
815 source_buffer = wl_shm_buffer_get_data(shm_buffer);
816 if (source_buffer == NULL) {
817 fprintf(stderr, "Failed to get data from shm buffer.\n");
821 dest_buffer = malloc(stride * height);
822 if (dest_buffer == NULL) {
823 fprintf(stderr, "Failed to allocate memory.\n");
827 memcpy(dest_buffer, source_buffer, stride * height);
829 cairo_surf = cairo_image_surface_create_for_data(
836 cairo_surface_write_to_png(cairo_surf, filename);
837 cairo_surface_destroy(cairo_surf);
844 bind_framebuffer(GLuint *fbo_id, GLuint *tex_id, GLsizei width, GLsizei height)
846 glGenTextures(1, tex_id);
847 glGenFramebuffers(1, fbo_id);
848 glBindTexture(GL_TEXTURE_2D, *tex_id);
849 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
850 glBindFramebuffer(GL_FRAMEBUFFER, *fbo_id);
851 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *tex_id, 0);
852 glClearColor(0, 0, 0, 0);
853 glClear(GL_COLOR_BUFFER_BIT);
857 unbind_framebuffer(GLuint fbo_id, GLuint tex_id)
859 glBindTexture(GL_TEXTURE_2D, 0);
860 glBindFramebuffer(GL_FRAMEBUFFER, 0);
861 glDeleteTextures(1, &tex_id);
862 glDeleteFramebuffers(1, &fbo_id);
866 dump_surface(struct weston_output *output,
867 struct weston_compositor *compositor,
868 const char *filename,
869 struct weston_view *view,
875 struct weston_renderer *renderer = compositor->renderer;
876 pixman_region32_t region;
877 struct wl_list backup_transformation_list;
878 struct weston_transform *link = NULL;
879 struct weston_transform *next = NULL;
880 uint8_t *readpixs = NULL;
881 int32_t stride = width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
882 GLuint fbo_id, tex_id;
884 readpixs = malloc(stride * height);
885 if (readpixs == NULL) {
886 fprintf(stderr, "Failed to allocate memory.\n");
890 pixman_region32_init_rect(®ion, x, y, width, height);
891 bind_framebuffer(&fbo_id, &tex_id, output->current_mode->width, output->current_mode->height);
893 wl_list_init(&backup_transformation_list);
894 wl_list_for_each_safe(link, next, &view->geometry.transformation_list, link) {
895 wl_list_remove(&link->link);
896 wl_list_insert(&backup_transformation_list, &link->link);
899 wl_list_init(&view->geometry.transformation_list);
900 weston_view_geometry_dirty(view);
901 weston_view_update_transform(view);
903 renderer->repaint_output(output, ®ion);
906 y = output->current_mode->height - (y + height);
907 int result = renderer->read_pixels(output,
908 compositor->read_format,
915 wl_list_for_each_safe(link, next, &backup_transformation_list, link) {
916 wl_list_remove(&link->link);
917 wl_list_insert(&view->geometry.transformation_list, &link->link);
920 weston_view_geometry_dirty(view);
921 weston_view_update_transform(view);
923 unbind_framebuffer(fbo_id, tex_id);
925 save_as_bitmap(filename, readpixs, stride * height, width, height, PIXMAN_FORMAT_BPP(compositor->read_format));
929 static struct weston_view *
930 clear_viewlist_but_specified_surface(struct weston_compositor *compositor,
931 struct weston_surface *surface)
933 struct weston_view *view = NULL;
934 wl_list_init(&compositor->view_list);
936 wl_list_for_each(view, &surface->views, surface_link) {
941 wl_list_insert(compositor->view_list.prev, &view->link);
949 get_gl_surface_rectangle(struct ivi_layout_SurfaceProperties *prop,
961 *width = prop->sourceWidth;
962 *height = prop->sourceHeight;
966 gl_surface_screenshot(struct ivisurface *ivisurf,
967 struct weston_surface *surface,
968 const char *filename)
970 struct weston_compositor *compositor = surface->compositor;
971 struct ivishell *shell = ivisurf->shell;
972 struct weston_view *view = NULL;
973 struct weston_output *output = NULL;
974 struct iviscreen *link_scrn = NULL;
975 struct ivi_layout_SurfaceProperties prop = {};
981 wl_list_for_each(link_scrn, &shell->list_screen, link) {
982 if (link_scrn != NULL) {
987 if (link_scrn == NULL) {
988 fprintf(stderr, "Failed to get iviscreen\n");
992 if (ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop) != 0) {
993 fprintf(stderr, "Failed to get surface properties.");
997 view = clear_viewlist_but_specified_surface(compositor, surface);
999 int32_t plane_is_null = 0;
1000 if (view->plane == NULL) {
1002 view->plane = &compositor->primary_plane;
1005 get_gl_surface_rectangle(&prop, &x, &y, &width, &height);
1006 dump_surface(link_scrn->output,
1015 if (plane_is_null) {
1024 controller_surface_screenshot(struct wl_client *client,
1025 struct wl_resource *resource,
1026 const char *filename)
1028 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1029 struct weston_surface *weston_surface = NULL;
1034 weston_surface = ivi_layout_surfaceGetWestonSurface(ivisurf->layout_surface);
1035 if (weston_surface == NULL) {
1036 fprintf(stderr, "Failed to get weston surface.\n");
1040 if (ivi_layout_surfaceGetSize(ivisurf->layout_surface, &width, &height, &stride) != 0) {
1041 fprintf(stderr, "Failed to get surface size.\n");
1045 if (shm_surface_screenshot(weston_surface, width, height, stride, filename) != 0) {
1046 if (gl_surface_screenshot(ivisurf, weston_surface, filename) != 0) {
1047 fprintf(stderr, "Failed to capture surface.\n");
1054 controller_surface_send_stats(struct wl_client *client,
1055 struct wl_resource *resource)
1057 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1061 wl_client_get_credentials(client, &pid, &uid, &gid);
1063 ivi_controller_surface_send_stats(resource, 0, 0,
1064 ivisurf->update_count, pid, "");
1068 controller_surface_destroy(struct wl_client *client,
1069 struct wl_resource *resource,
1070 int32_t destroy_scene_object)
1073 (void)destroy_scene_object;
1074 wl_resource_destroy(resource);
1077 static void send_all_keyboard_focus(struct ivishell *shell)
1079 struct ivi_layout_SurfaceProperties props;
1080 struct ivicontroller_surface *ctrlsurf;
1081 struct ivisurface *current_surf;
1082 uint32_t id_surface;
1084 wl_list_for_each(current_surf, &shell->list_surface, link) {
1085 ivi_layout_getPropertiesOfSurface(current_surf->layout_surface,
1087 id_surface = ivi_layout_getIdOfSurface(current_surf->layout_surface);
1088 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1089 if (id_surface != ctrlsurf->id_surface) {
1092 ivi_controller_surface_send_input_focus(ctrlsurf->resource,
1093 IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD,
1094 props.hasKeyboardFocus);
1100 controller_surface_set_input_focus(struct wl_client *client,
1101 struct wl_resource *resource,
1106 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1108 if (device & IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD) {
1110 uint32_t id = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1111 ivi_layout_SetKeyboardFocusOn(&id, 1);
1112 send_all_keyboard_focus(ivisurf->shell);
1118 struct ivi_controller_surface_interface controller_surface_implementation = {
1119 controller_surface_set_visibility,
1120 controller_surface_set_opacity,
1121 controller_surface_set_source_rectangle,
1122 controller_surface_set_destination_rectangle,
1123 controller_surface_set_configuration,
1124 controller_surface_set_orientation,
1125 controller_surface_screenshot,
1126 controller_surface_send_stats,
1127 controller_surface_destroy,
1128 controller_surface_set_input_focus
1132 controller_layer_set_source_rectangle(struct wl_client *client,
1133 struct wl_resource *resource,
1139 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1141 ivi_layout_layerSetSourceRectangle(ivilayer->layout_layer,
1142 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
1146 controller_layer_set_destination_rectangle(struct wl_client *client,
1147 struct wl_resource *resource,
1153 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1155 ivi_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
1156 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
1160 controller_layer_set_visibility(struct wl_client *client,
1161 struct wl_resource *resource,
1162 uint32_t visibility)
1164 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1166 ivi_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
1170 controller_layer_set_opacity(struct wl_client *client,
1171 struct wl_resource *resource,
1174 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1176 ivi_layout_layerSetOpacity(ivilayer->layout_layer,
1177 wl_fixed_to_double(opacity));
1181 controller_layer_set_configuration(struct wl_client *client,
1182 struct wl_resource *resource,
1186 /* This interface has been supported yet. */
1194 controller_layer_set_orientation(struct wl_client *client,
1195 struct wl_resource *resource,
1196 int32_t orientation)
1198 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1200 ivi_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
1204 controller_layer_clear_surfaces(struct wl_client *client,
1205 struct wl_resource *resource)
1207 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1209 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
1213 controller_layer_add_surface(struct wl_client *client,
1214 struct wl_resource *resource,
1215 struct wl_resource *surface)
1217 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1218 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
1220 ivi_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
1224 controller_layer_remove_surface(struct wl_client *client,
1225 struct wl_resource *resource,
1226 struct wl_resource *surface)
1228 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1229 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
1231 ivi_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
1235 controller_layer_screenshot(struct wl_client *client,
1236 struct wl_resource *resource,
1237 const char *filename)
1245 controller_layer_set_render_order(struct wl_client *client,
1246 struct wl_resource *resource,
1247 struct wl_array *id_surfaces)
1249 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1250 struct ivi_layout_surface **layoutsurf_array = NULL;
1251 struct ivisurface *ivisurf = NULL;
1252 uint32_t *id_surface = NULL;
1253 uint32_t id_layout_surface = 0;
1257 layoutsurf_array = (struct ivi_layout_surface**)calloc(
1258 id_surfaces->size, sizeof(void*));
1260 wl_array_for_each(id_surface, id_surfaces) {
1261 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
1262 id_layout_surface = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1263 if (*id_surface == id_layout_surface) {
1264 layoutsurf_array[i] = ivisurf->layout_surface;
1271 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer,
1272 layoutsurf_array, i);
1273 free(layoutsurf_array);
1277 controller_layer_destroy(struct wl_client *client,
1278 struct wl_resource *resource,
1279 int32_t destroy_scene_object)
1281 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1282 struct ivishell *shell = ivilayer->shell;
1283 struct ivicontroller_layer *ctrllayer = NULL;
1284 struct ivicontroller_layer *next = NULL;
1285 uint32_t id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1287 (void)destroy_scene_object;
1289 ivilayer->layer_canbe_removed = 1;
1290 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
1291 if (ctrllayer->id_layer != id_layer) {
1295 wl_resource_destroy(ctrllayer->resource);
1300 struct ivi_controller_layer_interface controller_layer_implementation = {
1301 controller_layer_set_visibility,
1302 controller_layer_set_opacity,
1303 controller_layer_set_source_rectangle,
1304 controller_layer_set_destination_rectangle,
1305 controller_layer_set_configuration,
1306 controller_layer_set_orientation,
1307 controller_layer_screenshot,
1308 controller_layer_clear_surfaces,
1309 controller_layer_add_surface,
1310 controller_layer_remove_surface,
1311 controller_layer_set_render_order,
1312 controller_layer_destroy
1316 controller_screen_destroy(struct wl_client *client,
1317 struct wl_resource *resource)
1319 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1320 struct ivicontroller_screen *ctrlscrn = NULL;
1321 struct ivicontroller_screen *next = NULL;
1322 // uint32_t id_screen = ivi_layout_getIdOfScreen(iviscrn->layout_screen);
1325 wl_list_for_each_safe(ctrlscrn, next,
1326 &iviscrn->shell->list_controller_screen, link) {
1327 if (resource != ctrlscrn->resource) {
1331 wl_list_remove(&ctrlscrn->link);
1332 wl_resource_destroy(ctrlscrn->resource);
1340 controller_screen_clear(struct wl_client *client,
1341 struct wl_resource *resource)
1343 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1345 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
1349 controller_screen_add_layer(struct wl_client *client,
1350 struct wl_resource *resource,
1351 struct wl_resource *layer)
1353 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1354 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
1356 ivi_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
1360 controller_screen_screenshot(struct wl_client *client,
1361 struct wl_resource *resource,
1362 const char *filename)
1364 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1367 struct weston_output *output = NULL;
1368 cairo_surface_t *cairo_surf = NULL;
1373 uint8_t *readpixs = NULL;
1375 output = ivi_layout_screenGetOutput(iviscrn->layout_screen);
1376 --output->disable_planes;
1378 width = output->current_mode->width;
1379 height = output->current_mode->height;
1380 stride = width * (PIXMAN_FORMAT_BPP(output->compositor->read_format) / 8);
1382 readpixs = malloc(stride * height);
1383 if (readpixs == NULL) {
1384 weston_log("fails to allocate memory\n");
1388 output->compositor->renderer->read_pixels(
1390 output->compositor->read_format,
1397 save_as_bitmap(filename, readpixs, stride * height, width, height, PIXMAN_FORMAT_BPP(output->compositor->read_format));
1402 controller_screen_set_render_order(struct wl_client *client,
1403 struct wl_resource *resource,
1404 struct wl_array *id_layers)
1406 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1407 struct ivi_layout_layer **layoutlayer_array = NULL;
1408 struct ivilayer *ivilayer = NULL;
1409 uint32_t *id_layer = NULL;
1410 uint32_t id_layout_layer = 0;
1414 layoutlayer_array = (struct ivi_layout_layer**)calloc(
1415 id_layers->size, sizeof(void*));
1417 wl_array_for_each(id_layer, id_layers) {
1418 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1419 id_layout_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1420 if (*id_layer == id_layout_layer) {
1421 layoutlayer_array[i] = ivilayer->layout_layer;
1428 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen,
1429 layoutlayer_array, i);
1430 free(layoutlayer_array);
1434 struct ivi_controller_screen_interface controller_screen_implementation = {
1435 controller_screen_destroy,
1436 controller_screen_clear,
1437 controller_screen_add_layer,
1438 controller_screen_screenshot,
1439 controller_screen_set_render_order
1443 controller_commit_changes(struct wl_client *client,
1444 struct wl_resource *resource)
1450 ans = ivi_layout_commitChanges();
1452 weston_log("Failed to commit changes at controller_commit_changes\n");
1457 controller_layer_create(struct wl_client *client,
1458 struct wl_resource *resource,
1464 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1465 struct ivishell *shell = ctrl->shell;
1466 struct ivi_layout_layer *layout_layer = NULL;
1467 struct ivicontroller_layer *ctrllayer = NULL;
1468 struct ivilayer *ivilayer = NULL;
1469 struct ivi_layout_LayerProperties prop;
1471 ivilayer = get_layer(&shell->list_layer, id_layer);
1472 if (ivilayer == NULL) {
1473 layout_layer = ivi_layout_layerCreateWithDimension(id_layer,
1474 (uint32_t)width, (uint32_t)height);
1475 if (layout_layer == NULL) {
1476 weston_log("id_layer is already created\n");
1480 /* ivilayer will be created by layer_event_create */
1481 ivilayer = get_layer(&shell->list_layer, id_layer);
1482 if (ivilayer == NULL) {
1483 weston_log("couldn't get layer object\n");
1488 ctrllayer = calloc(1, sizeof *ctrllayer);
1490 weston_log("no memory to allocate client layer\n");
1494 ++ivilayer->controller_layer_count;
1495 ivilayer->layer_canbe_removed = 0;
1497 ctrllayer->shell = shell;
1498 ctrllayer->client = client;
1500 ctrllayer->id_layer = id_layer;
1501 ctrllayer->resource = wl_resource_create(client,
1502 &ivi_controller_layer_interface, 1, id);
1503 if (ctrllayer->resource == NULL) {
1504 weston_log("couldn't get layer object\n");
1508 wl_list_init(&ctrllayer->link);
1509 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1511 wl_resource_set_implementation(ctrllayer->resource,
1512 &controller_layer_implementation,
1513 ivilayer, destroy_ivicontroller_layer);
1515 memset(&prop, 0, sizeof prop);
1517 ivi_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1518 send_layer_event(ctrllayer->resource, ivilayer,
1519 &prop, IVI_NOTIFICATION_ALL);
1523 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1525 struct ivishell *shell = userdata;
1526 struct ivicontroller_surface *ctrlsurf = NULL;
1527 uint32_t id_surface = 0;
1530 surface_event_remove(layout_surface, userdata);
1535 controller_surface_create(struct wl_client *client,
1536 struct wl_resource *resource,
1537 uint32_t id_surface,
1540 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1541 struct ivishell *shell = ctrl->shell;
1542 struct ivicontroller_surface *ctrlsurf = NULL;
1543 struct ivi_layout_SurfaceProperties prop;
1544 struct ivisurface *ivisurf = NULL;
1545 struct ivicontroller_surface *ctrl_link = NULL;
1547 ivisurf = get_surface(&shell->list_surface, id_surface);
1548 if (ivisurf == NULL) {
1552 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1554 weston_log("no memory to allocate controller surface\n");
1558 ctrlsurf->shell = shell;
1559 ctrlsurf->client = client;
1561 ctrlsurf->id_surface = id_surface;
1562 wl_list_init(&ctrlsurf->link);
1563 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1565 ctrlsurf->resource = wl_resource_create(client,
1566 &ivi_controller_surface_interface, 1, id);
1567 if (ctrlsurf->resource == NULL) {
1568 weston_log("couldn't surface object");
1572 wl_list_for_each(ctrl_link, &shell->list_controller_surface, link) {
1573 if ((ctrl_link->implementation_set == 0) &&
1574 (ctrl_link->id_surface == id_surface) &&
1575 (ctrl_link->shell == shell) &&
1576 (ctrl_link->client != client)) {
1577 ++ivisurf->controller_surface_count;
1578 wl_resource_set_implementation(ctrl_link->resource,
1579 &controller_surface_implementation,
1580 ivisurf, destroy_ivicontroller_surface);
1581 ctrl_link->implementation_set = 1;
1585 ++ivisurf->controller_surface_count;
1587 wl_resource_set_implementation(ctrlsurf->resource,
1588 &controller_surface_implementation,
1589 ivisurf, destroy_ivicontroller_surface);
1591 ctrlsurf->implementation_set = 1;
1593 memset(&prop, 0, sizeof prop);
1595 ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1596 ivi_layout_surfaceSetContentObserver(ivisurf->layout_surface, surface_event_content, shell);
1598 send_surface_event(ctrlsurf->resource, ivisurf,
1599 &prop, IVI_NOTIFICATION_ALL);
1603 controller_get_native_handle(struct wl_client *client,
1604 struct wl_resource *resource,
1605 uint32_t id_process,
1608 struct wl_array surfaces;
1609 ivi_shell_get_shell_surfaces(&surfaces);
1610 struct shell_surface ** surface;
1612 wl_array_for_each(surface, &surfaces) {
1614 uint32_t pid = shell_surface_get_process_id(*surface);
1615 if (pid != id_process) {
1620 char* surface_title = shell_surface_get_title(*surface);
1621 if (strcmp(title, surface_title)) {
1626 struct weston_surface *es = shell_surface_get_surface(*surface);
1628 struct wl_resource *res = wl_resource_create(client, &wl_surface_interface, 1, 0);
1629 wl_resource_set_user_data(res, es);
1631 ivi_controller_send_native_handle(resource, res);
1635 wl_array_release(&surfaces);
1637 int32_t id_object = 0;
1638 ivi_controller_send_error(
1639 resource, id_object, IVI_CONTROLLER_OBJECT_TYPE_SURFACE,
1640 IVI_CONTROLLER_ERROR_CODE_NATIVE_HANDLE_END, "");
1644 controller_set_keyboard_focus(struct wl_client *client,
1645 struct wl_resource *resource,
1646 struct wl_array *surfaces)
1648 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1649 ivi_layout_SetKeyboardFocusOn(surfaces->data, surfaces->size);
1650 send_all_keyboard_focus(ctrl->shell);
1653 static const struct ivi_controller_interface controller_implementation = {
1654 controller_commit_changes,
1655 controller_layer_create,
1656 controller_surface_create,
1657 controller_set_keyboard_focus,
1658 controller_get_native_handle
1662 add_client_to_resources(struct ivishell *shell,
1663 struct wl_client *client,
1664 struct ivicontroller *controller)
1666 struct ivisurface* ivisurf = NULL;
1667 struct ivilayer* ivilayer = NULL;
1668 struct iviscreen* iviscrn = NULL;
1669 struct ivicontroller_screen *ctrlscrn = NULL;
1670 struct wl_resource *resource_output = NULL;
1671 uint32_t id_layout_surface = 0;
1672 uint32_t id_layout_layer = 0;
1673 struct ivi_layout_surface *layout_surface;
1675 const char *window_title;
1677 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1678 resource_output = wl_resource_find_for_client(
1679 &iviscrn->output->resource_list, client);
1680 if (resource_output == NULL) {
1684 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1685 if (ctrlscrn == NULL) {
1689 ivi_controller_send_screen(controller->resource,
1690 wl_resource_get_id(resource_output),
1691 ctrlscrn->resource);
1693 wl_list_for_each_reverse(ivilayer, &shell->list_layer, link) {
1695 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1697 ivi_controller_send_layer(controller->resource,
1700 wl_list_for_each_reverse(ivisurf, &shell->list_surface, link) {
1701 layout_surface = ivisurf->layout_surface;
1702 id_layout_surface = ivi_layout_getIdOfSurface(layout_surface);
1704 get_wl_shell_info(layout_surface, id_layout_surface,
1705 &pid, &window_title);
1707 ivi_controller_send_surface(controller->resource,
1708 id_layout_surface, pid, window_title);
1713 bind_ivi_controller(struct wl_client *client, void *data,
1714 uint32_t version, uint32_t id)
1716 struct ivishell *shell = data;
1717 struct ivicontroller *controller;
1720 controller = calloc(1, sizeof *controller);
1721 if (controller == NULL) {
1722 weston_log("no memory to allocate controller\n");
1726 controller->resource =
1727 wl_resource_create(client, &ivi_controller_interface, 1, id);
1728 wl_resource_set_implementation(controller->resource,
1729 &controller_implementation,
1730 controller, unbind_resource_controller);
1732 controller->shell = shell;
1733 controller->client = client;
1734 controller->id = id;
1736 wl_list_init(&controller->link);
1737 wl_list_insert(&shell->list_controller, &controller->link);
1739 add_client_to_resources(shell, client, controller);
1742 static struct iviscreen*
1743 create_screen(struct ivishell *shell, struct weston_output *output)
1745 struct iviscreen *iviscrn;
1746 iviscrn = calloc(1, sizeof *iviscrn);
1747 if (iviscrn == NULL) {
1748 weston_log("no memory to allocate client screen\n");
1752 iviscrn->shell = shell;
1753 iviscrn->output = output;
1755 // TODO : Only Single display
1756 iviscrn->layout_screen = ivi_layout_getScreenFromId(0);
1758 wl_list_init(&iviscrn->link);
1763 static struct ivilayer*
1764 create_layer(struct ivishell *shell,
1765 struct ivi_layout_layer *layout_layer,
1768 struct ivilayer *ivilayer = NULL;
1769 struct ivicontroller *controller = NULL;
1771 ivilayer = get_layer(&shell->list_layer, id_layer);
1772 if (ivilayer != NULL) {
1773 weston_log("id_layer is already created\n");
1777 ivilayer = calloc(1, sizeof *ivilayer);
1778 if (NULL == ivilayer) {
1779 weston_log("no memory to allocate client layer\n");
1783 ivilayer->shell = shell;
1784 wl_list_init(&ivilayer->list_screen);
1785 wl_list_init(&ivilayer->link);
1786 wl_list_insert(&shell->list_layer, &ivilayer->link);
1787 ivilayer->layout_layer = layout_layer;
1789 ivi_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1791 wl_list_for_each(controller, &shell->list_controller, link) {
1792 ivi_controller_send_layer(controller->resource, id_layer);
1798 static struct ivisurface*
1799 create_surface(struct ivishell *shell,
1800 struct ivi_layout_surface *layout_surface,
1801 uint32_t id_surface)
1803 struct ivisurface *ivisurf = NULL;
1804 struct ivicontroller *controller = NULL;
1806 const char *window_title;
1808 ivisurf = get_surface(&shell->list_surface, id_surface);
1809 if (ivisurf != NULL) {
1810 weston_log("id_surface is already created\n");
1814 ivisurf = calloc(1, sizeof *ivisurf);
1815 if (ivisurf == NULL) {
1816 weston_log("no memory to allocate client surface\n");
1820 ivisurf->shell = shell;
1821 ivisurf->layout_surface = layout_surface;
1822 wl_list_init(&ivisurf->list_layer);
1823 wl_list_init(&ivisurf->link);
1824 wl_list_insert(&shell->list_surface, &ivisurf->link);
1826 get_wl_shell_info(layout_surface, id_surface, &pid, &window_title);
1828 wl_list_for_each(controller, &shell->list_controller, link) {
1829 ivi_controller_send_surface(controller->resource,
1830 id_surface, pid, window_title);
1833 ivi_layout_surfaceAddNotification(layout_surface,
1834 send_surface_prop, ivisurf);
1840 layer_event_create(struct ivi_layout_layer *layout_layer,
1843 struct ivishell *shell = userdata;
1844 struct ivilayer *ivilayer = NULL;
1845 uint32_t id_layer = 0;
1847 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1849 ivilayer = create_layer(shell, layout_layer, id_layer);
1850 if (ivilayer == NULL) {
1851 weston_log("failed to create layer");
1857 layer_event_remove(struct ivi_layout_layer *layout_layer,
1860 struct ivishell *shell = userdata;
1861 struct ivicontroller_layer *ctrllayer = NULL;
1862 struct ivilayer *ivilayer = NULL;
1863 struct ivilayer *next = NULL;
1864 uint32_t id_layer = 0;
1867 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1868 if (layout_layer != ivilayer->layout_layer) {
1872 wl_list_remove(&ivilayer->link);
1881 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1883 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1884 if (id_layer != ctrllayer->id_layer) {
1887 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1894 surface_event_create(struct ivi_layout_surface *layout_surface,
1897 struct ivishell *shell = userdata;
1898 struct ivisurface *ivisurf = NULL;
1899 uint32_t id_surface = 0;
1900 struct ivicontroller_surface *ctrlsurf = NULL;
1902 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1904 ivisurf = create_surface(shell, layout_surface, id_surface);
1905 if (ivisurf == NULL) {
1906 weston_log("failed to create surface");
1910 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1911 if (id_surface != ctrlsurf->id_surface) {
1914 ivi_controller_surface_send_content(ctrlsurf->resource, IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_AVAILABLE);
1919 surface_event_remove(struct ivi_layout_surface *layout_surface,
1922 struct ivishell *shell = userdata;
1923 struct ivicontroller_surface *ctrlsurf = NULL;
1924 struct ivisurface *ivisurf = NULL;
1925 struct ivisurface *next = NULL;
1926 uint32_t id_surface = 0;
1929 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1930 if (layout_surface != ivisurf->layout_surface) {
1934 wl_list_remove(&ivisurf->link);
1937 if (ivisurf->controller_surface_count == 0) {
1941 ivisurf->can_be_removed = 1;
1948 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1950 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1951 if (id_surface != ctrlsurf->id_surface) {
1954 ivi_controller_surface_send_content(ctrlsurf->resource, IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED);
1955 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1961 surface_event_configure(struct ivi_layout_surface *layout_surface,
1964 struct ivishell *shell = userdata;
1965 struct ivisurface *ivisurf = NULL;
1966 struct ivicontroller_surface *ctrlsurf = NULL;
1967 struct ivi_layout_SurfaceProperties prop;
1968 uint32_t id_surface = 0;
1970 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1972 ivisurf = get_surface(&shell->list_surface, id_surface);
1973 if (ivisurf == NULL) {
1974 weston_log("id_surface is not created yet\n");
1978 memset(&prop, 0, sizeof prop);
1979 ivi_layout_getPropertiesOfSurface(layout_surface, &prop);
1981 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1982 if (id_surface != ctrlsurf->id_surface) {
1985 send_surface_event(ctrlsurf->resource, ivisurf,
1986 &prop, IVI_NOTIFICATION_ALL);
1991 check_layout_layers(struct ivishell *shell)
1993 struct ivi_layout_layer **pArray = NULL;
1994 struct ivilayer *ivilayer = NULL;
1995 uint32_t id_layer = 0;
1996 uint32_t length = 0;
2000 ret = ivi_layout_getLayers(&length, &pArray);
2002 weston_log("failed to get layers at check_layout_layers\n");
2007 /* if length is 0, pArray doesn't need to free.*/
2011 for (i = 0; i < length; i++) {
2012 id_layer = ivi_layout_getIdOfLayer(pArray[i]);
2013 ivilayer = create_layer(shell, pArray[i], id_layer);
2014 if (ivilayer == NULL) {
2015 weston_log("failed to create layer");
2026 check_layout_surfaces(struct ivishell *shell)
2028 struct ivi_layout_surface **pArray = NULL;
2029 struct ivisurface *ivisurf = NULL;
2030 uint32_t id_surface = 0;
2031 uint32_t length = 0;
2035 ret = ivi_layout_getSurfaces(&length, &pArray);
2037 weston_log("failed to get surfaces at check_layout_surfaces\n");
2042 /* if length is 0, pArray doesn't need to free.*/
2046 for (i = 0; i < length; i++) {
2047 id_surface = ivi_layout_getIdOfSurface(pArray[i]);
2048 ivisurf = create_surface(shell, pArray[i], id_surface);
2049 if (ivisurf == NULL) {
2050 weston_log("failed to create surface");
2061 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
2063 struct weston_output *output = NULL;
2064 struct iviscreen *iviscrn = NULL;
2067 shell->compositor = ec;
2069 wl_list_init(&shell->list_surface);
2070 wl_list_init(&shell->list_layer);
2071 wl_list_init(&shell->list_screen);
2072 wl_list_init(&shell->list_weston_surface);
2073 wl_list_init(&shell->list_controller);
2074 wl_list_init(&shell->list_controller_screen);
2075 wl_list_init(&shell->list_controller_layer);
2076 wl_list_init(&shell->list_controller_surface);
2077 shell->event_restriction = 0;
2079 wl_list_for_each(output, &ec->output_list, link) {
2080 iviscrn = create_screen(shell, output);
2081 if (iviscrn != NULL) {
2082 wl_list_insert(&shell->list_screen, &iviscrn->link);
2086 ret = check_layout_layers(shell);
2088 weston_log("failed to check_layout_layers");
2091 ret = check_layout_surfaces(shell);
2093 weston_log("failed to check_layout_surfaces");
2096 ivi_layout_addNotificationCreateLayer(layer_event_create, shell);
2097 ivi_layout_addNotificationRemoveLayer(layer_event_remove, shell);
2099 ivi_layout_addNotificationCreateSurface(surface_event_create, shell);
2100 ivi_layout_addNotificationRemoveSurface(surface_event_remove, shell);
2101 ivi_layout_addNotificationConfigureSurface(surface_event_configure, shell);
2105 module_init(struct weston_compositor *ec,
2106 int *argc, char *argv[])
2108 struct ivishell *shell;
2112 shell = malloc(sizeof *shell);
2116 memset(shell, 0, sizeof *shell);
2117 init_ivi_shell(ec, shell);
2119 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
2120 shell, bind_ivi_controller) == NULL) {