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,
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,
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, (float)opacity);
725 controller_surface_set_source_rectangle(struct wl_client *client,
726 struct wl_resource *resource,
732 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
734 ivi_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
735 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
739 controller_surface_set_destination_rectangle(struct wl_client *client,
740 struct wl_resource *resource,
746 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
749 // TODO: create set transition type protocol
750 ivi_layout_surfaceSetTransition( ivisurf->layout_surface,
751 IVI_LAYOUT_TRANSITION_NONE,
754 ivi_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
755 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
759 controller_surface_set_visibility(struct wl_client *client,
760 struct wl_resource *resource,
763 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
765 ivi_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
769 controller_surface_set_configuration(struct wl_client *client,
770 struct wl_resource *resource,
771 int32_t width, int32_t height)
773 /* This interface has been supported yet. */
781 controller_surface_set_orientation(struct wl_client *client,
782 struct wl_resource *resource,
785 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
787 ivi_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
791 shm_surface_screenshot(struct weston_surface *surface,
795 const char *filename)
797 struct weston_buffer *weston_buffer = NULL;
798 struct wl_shm_buffer *shm_buffer = NULL;
799 cairo_surface_t *cairo_surf = NULL;
800 uint8_t *source_buffer = NULL;
801 uint8_t *dest_buffer = NULL;
803 weston_buffer = surface->buffer_ref.buffer;
804 if (weston_buffer == NULL) {
805 fprintf(stderr, "Failed to get weston buffer.\n");
809 shm_buffer = wl_shm_buffer_get(weston_buffer->resource);
810 if (shm_buffer == NULL) {
814 source_buffer = wl_shm_buffer_get_data(shm_buffer);
815 if (source_buffer == NULL) {
816 fprintf(stderr, "Failed to get data from shm buffer.\n");
820 dest_buffer = malloc(stride * height);
821 if (dest_buffer == NULL) {
822 fprintf(stderr, "Failed to allocate memory.\n");
826 memcpy(dest_buffer, source_buffer, stride * height);
828 cairo_surf = cairo_image_surface_create_for_data(
835 cairo_surface_write_to_png(cairo_surf, filename);
836 cairo_surface_destroy(cairo_surf);
843 bind_framebuffer(GLuint *fbo_id, GLuint *tex_id, GLsizei width, GLsizei height)
845 glGenTextures(1, tex_id);
846 glGenFramebuffers(1, fbo_id);
847 glBindTexture(GL_TEXTURE_2D, *tex_id);
848 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
849 glBindFramebuffer(GL_FRAMEBUFFER, *fbo_id);
850 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *tex_id, 0);
851 glClearColor(0, 0, 0, 0);
852 glClear(GL_COLOR_BUFFER_BIT);
856 unbind_framebuffer(GLuint fbo_id, GLuint tex_id)
858 glBindTexture(GL_TEXTURE_2D, 0);
859 glBindFramebuffer(GL_FRAMEBUFFER, 0);
860 glDeleteTextures(1, &tex_id);
861 glDeleteFramebuffers(1, &fbo_id);
865 dump_surface(struct weston_output *output,
866 struct weston_compositor *compositor,
867 const char *filename,
868 struct weston_view *view,
874 struct weston_renderer *renderer = compositor->renderer;
875 pixman_region32_t region;
876 struct wl_list backup_transformation_list;
877 struct weston_transform *link = NULL;
878 struct weston_transform *next = NULL;
879 uint8_t *readpixs = NULL;
880 int32_t stride = width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
881 GLuint fbo_id, tex_id;
883 readpixs = malloc(stride * height);
884 if (readpixs == NULL) {
885 fprintf(stderr, "Failed to allocate memory.\n");
889 pixman_region32_init_rect(®ion, x, y, width, height);
890 bind_framebuffer(&fbo_id, &tex_id, output->current_mode->width, output->current_mode->height);
892 wl_list_init(&backup_transformation_list);
893 wl_list_for_each_safe(link, next, &view->geometry.transformation_list, link) {
894 wl_list_remove(&link->link);
895 wl_list_insert(&backup_transformation_list, &link->link);
898 wl_list_init(&view->geometry.transformation_list);
899 weston_view_geometry_dirty(view);
900 weston_view_update_transform(view);
902 renderer->repaint_output(output, ®ion);
905 y = output->current_mode->height - (y + height);
906 int result = renderer->read_pixels(output,
907 compositor->read_format,
914 wl_list_for_each_safe(link, next, &backup_transformation_list, link) {
915 wl_list_remove(&link->link);
916 wl_list_insert(&view->geometry.transformation_list, &link->link);
919 weston_view_geometry_dirty(view);
920 weston_view_update_transform(view);
922 unbind_framebuffer(fbo_id, tex_id);
924 save_as_bitmap(filename, readpixs, stride * height, width, height, PIXMAN_FORMAT_BPP(compositor->read_format));
928 static struct weston_view *
929 clear_viewlist_but_specified_surface(struct weston_compositor *compositor,
930 struct weston_surface *surface)
932 struct weston_view *view = NULL;
933 wl_list_init(&compositor->view_list);
935 wl_list_for_each(view, &surface->views, surface_link) {
940 wl_list_insert(compositor->view_list.prev, &view->link);
948 get_gl_surface_rectangle(struct ivi_layout_SurfaceProperties *prop,
960 *width = prop->sourceWidth;
961 *height = prop->sourceHeight;
965 gl_surface_screenshot(struct ivisurface *ivisurf,
966 struct weston_surface *surface,
967 const char *filename)
969 struct weston_compositor *compositor = surface->compositor;
970 struct ivishell *shell = ivisurf->shell;
971 struct weston_view *view = NULL;
972 struct weston_output *output = NULL;
973 struct iviscreen *link_scrn = NULL;
974 struct ivi_layout_SurfaceProperties prop = {};
980 wl_list_for_each(link_scrn, &shell->list_screen, link) {
981 if (link_scrn != NULL) {
986 if (link_scrn == NULL) {
987 fprintf(stderr, "Failed to get iviscreen\n");
991 if (ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop) != 0) {
992 fprintf(stderr, "Failed to get surface properties.");
996 view = clear_viewlist_but_specified_surface(compositor, surface);
998 int32_t plane_is_null = 0;
999 if (view->plane == NULL) {
1001 view->plane = &compositor->primary_plane;
1004 get_gl_surface_rectangle(&prop, &x, &y, &width, &height);
1005 dump_surface(link_scrn->output,
1014 if (plane_is_null) {
1023 controller_surface_screenshot(struct wl_client *client,
1024 struct wl_resource *resource,
1025 const char *filename)
1027 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1028 struct weston_surface *weston_surface = NULL;
1033 weston_surface = ivi_layout_surfaceGetWestonSurface(ivisurf->layout_surface);
1034 if (weston_surface == NULL) {
1035 fprintf(stderr, "Failed to get weston surface.\n");
1039 if (ivi_layout_surfaceGetSize(ivisurf->layout_surface, &width, &height, &stride) != 0) {
1040 fprintf(stderr, "Failed to get surface size.\n");
1044 if (shm_surface_screenshot(weston_surface, width, height, stride, filename) != 0) {
1045 if (gl_surface_screenshot(ivisurf, weston_surface, filename) != 0) {
1046 fprintf(stderr, "Failed to capture surface.\n");
1053 controller_surface_send_stats(struct wl_client *client,
1054 struct wl_resource *resource)
1056 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1060 wl_client_get_credentials(client, &pid, &uid, &gid);
1062 ivi_controller_surface_send_stats(resource, 0, 0,
1063 ivisurf->update_count, pid, "");
1067 controller_surface_destroy(struct wl_client *client,
1068 struct wl_resource *resource,
1069 int32_t destroy_scene_object)
1072 (void)destroy_scene_object;
1073 wl_resource_destroy(resource);
1076 static void send_all_keyboard_focus(struct ivishell *shell)
1078 struct ivi_layout_SurfaceProperties props;
1079 struct ivicontroller_surface *ctrlsurf;
1080 struct ivisurface *current_surf;
1081 uint32_t id_surface;
1083 wl_list_for_each(current_surf, &shell->list_surface, link) {
1084 ivi_layout_getPropertiesOfSurface(current_surf->layout_surface,
1086 id_surface = ivi_layout_getIdOfSurface(current_surf->layout_surface);
1087 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1088 if (id_surface != ctrlsurf->id_surface) {
1091 ivi_controller_surface_send_input_focus(ctrlsurf->resource,
1092 IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD,
1093 props.hasKeyboardFocus);
1099 controller_surface_set_input_focus(struct wl_client *client,
1100 struct wl_resource *resource,
1105 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1107 if (device & IVI_CONTROLLER_SURFACE_INPUT_DEVICE_KEYBOARD) {
1109 uint32_t id = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1110 ivi_layout_SetKeyboardFocusOn(&id, 1);
1111 send_all_keyboard_focus(ivisurf->shell);
1117 struct ivi_controller_surface_interface controller_surface_implementation = {
1118 controller_surface_set_visibility,
1119 controller_surface_set_opacity,
1120 controller_surface_set_source_rectangle,
1121 controller_surface_set_destination_rectangle,
1122 controller_surface_set_configuration,
1123 controller_surface_set_orientation,
1124 controller_surface_screenshot,
1125 controller_surface_send_stats,
1126 controller_surface_destroy,
1127 controller_surface_set_input_focus
1131 controller_layer_set_source_rectangle(struct wl_client *client,
1132 struct wl_resource *resource,
1138 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1140 ivi_layout_layerSetSourceRectangle(ivilayer->layout_layer,
1141 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
1145 controller_layer_set_destination_rectangle(struct wl_client *client,
1146 struct wl_resource *resource,
1152 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1154 ivi_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
1155 (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
1159 controller_layer_set_visibility(struct wl_client *client,
1160 struct wl_resource *resource,
1161 uint32_t visibility)
1163 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1165 ivi_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
1169 controller_layer_set_opacity(struct wl_client *client,
1170 struct wl_resource *resource,
1173 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1175 ivi_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
1179 controller_layer_set_configuration(struct wl_client *client,
1180 struct wl_resource *resource,
1184 /* This interface has been supported yet. */
1192 controller_layer_set_orientation(struct wl_client *client,
1193 struct wl_resource *resource,
1194 int32_t orientation)
1196 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1198 ivi_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
1202 controller_layer_clear_surfaces(struct wl_client *client,
1203 struct wl_resource *resource)
1205 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1207 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
1211 controller_layer_add_surface(struct wl_client *client,
1212 struct wl_resource *resource,
1213 struct wl_resource *surface)
1215 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1216 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
1218 ivi_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
1222 controller_layer_remove_surface(struct wl_client *client,
1223 struct wl_resource *resource,
1224 struct wl_resource *surface)
1226 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1227 struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
1229 ivi_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
1233 controller_layer_screenshot(struct wl_client *client,
1234 struct wl_resource *resource,
1235 const char *filename)
1243 controller_layer_set_render_order(struct wl_client *client,
1244 struct wl_resource *resource,
1245 struct wl_array *id_surfaces)
1247 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1248 struct ivi_layout_surface **layoutsurf_array = NULL;
1249 struct ivisurface *ivisurf = NULL;
1250 uint32_t *id_surface = NULL;
1251 uint32_t id_layout_surface = 0;
1255 layoutsurf_array = (struct ivi_layout_surface**)calloc(
1256 id_surfaces->size, sizeof(void*));
1258 wl_array_for_each(id_surface, id_surfaces) {
1259 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
1260 id_layout_surface = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
1261 if (*id_surface == id_layout_surface) {
1262 layoutsurf_array[i] = ivisurf->layout_surface;
1269 ivi_layout_layerSetRenderOrder(ivilayer->layout_layer,
1270 layoutsurf_array, i);
1271 free(layoutsurf_array);
1275 controller_layer_destroy(struct wl_client *client,
1276 struct wl_resource *resource,
1277 int32_t destroy_scene_object)
1279 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1280 struct ivishell *shell = ivilayer->shell;
1281 struct ivicontroller_layer *ctrllayer = NULL;
1282 struct ivicontroller_layer *next = NULL;
1283 uint32_t id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1285 (void)destroy_scene_object;
1287 ivilayer->layer_canbe_removed = 1;
1288 wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
1289 if (ctrllayer->id_layer != id_layer) {
1293 wl_resource_destroy(ctrllayer->resource);
1298 struct ivi_controller_layer_interface controller_layer_implementation = {
1299 controller_layer_set_visibility,
1300 controller_layer_set_opacity,
1301 controller_layer_set_source_rectangle,
1302 controller_layer_set_destination_rectangle,
1303 controller_layer_set_configuration,
1304 controller_layer_set_orientation,
1305 controller_layer_screenshot,
1306 controller_layer_clear_surfaces,
1307 controller_layer_add_surface,
1308 controller_layer_remove_surface,
1309 controller_layer_set_render_order,
1310 controller_layer_destroy
1314 controller_screen_destroy(struct wl_client *client,
1315 struct wl_resource *resource)
1317 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1318 struct ivicontroller_screen *ctrlscrn = NULL;
1319 struct ivicontroller_screen *next = NULL;
1320 // uint32_t id_screen = ivi_layout_getIdOfScreen(iviscrn->layout_screen);
1323 wl_list_for_each_safe(ctrlscrn, next,
1324 &iviscrn->shell->list_controller_screen, link) {
1325 if (resource != ctrlscrn->resource) {
1329 wl_list_remove(&ctrlscrn->link);
1330 wl_resource_destroy(ctrlscrn->resource);
1338 controller_screen_clear(struct wl_client *client,
1339 struct wl_resource *resource)
1341 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1343 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
1347 controller_screen_add_layer(struct wl_client *client,
1348 struct wl_resource *resource,
1349 struct wl_resource *layer)
1351 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1352 struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
1354 ivi_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
1358 controller_screen_screenshot(struct wl_client *client,
1359 struct wl_resource *resource,
1360 const char *filename)
1362 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1365 struct weston_output *output = NULL;
1366 cairo_surface_t *cairo_surf = NULL;
1371 uint8_t *readpixs = NULL;
1373 output = ivi_layout_screenGetOutput(iviscrn->layout_screen);
1374 --output->disable_planes;
1376 width = output->current_mode->width;
1377 height = output->current_mode->height;
1378 stride = width * (PIXMAN_FORMAT_BPP(output->compositor->read_format) / 8);
1380 readpixs = malloc(stride * height);
1381 if (readpixs == NULL) {
1382 weston_log("fails to allocate memory\n");
1386 output->compositor->renderer->read_pixels(
1388 output->compositor->read_format,
1395 save_as_bitmap(filename, readpixs, stride * height, width, height, PIXMAN_FORMAT_BPP(output->compositor->read_format));
1400 controller_screen_set_render_order(struct wl_client *client,
1401 struct wl_resource *resource,
1402 struct wl_array *id_layers)
1404 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1405 struct ivi_layout_layer **layoutlayer_array = NULL;
1406 struct ivilayer *ivilayer = NULL;
1407 uint32_t *id_layer = NULL;
1408 uint32_t id_layout_layer = 0;
1412 layoutlayer_array = (struct ivi_layout_layer**)calloc(
1413 id_layers->size, sizeof(void*));
1415 wl_array_for_each(id_layer, id_layers) {
1416 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1417 id_layout_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1418 if (*id_layer == id_layout_layer) {
1419 layoutlayer_array[i] = ivilayer->layout_layer;
1426 ivi_layout_screenSetRenderOrder(iviscrn->layout_screen,
1427 layoutlayer_array, i);
1428 free(layoutlayer_array);
1432 struct ivi_controller_screen_interface controller_screen_implementation = {
1433 controller_screen_destroy,
1434 controller_screen_clear,
1435 controller_screen_add_layer,
1436 controller_screen_screenshot,
1437 controller_screen_set_render_order
1441 controller_commit_changes(struct wl_client *client,
1442 struct wl_resource *resource)
1448 ans = ivi_layout_commitChanges();
1450 weston_log("Failed to commit changes at controller_commit_changes\n");
1455 controller_layer_create(struct wl_client *client,
1456 struct wl_resource *resource,
1462 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1463 struct ivishell *shell = ctrl->shell;
1464 struct ivi_layout_layer *layout_layer = NULL;
1465 struct ivicontroller_layer *ctrllayer = NULL;
1466 struct ivilayer *ivilayer = NULL;
1467 struct ivi_layout_LayerProperties prop;
1469 ivilayer = get_layer(&shell->list_layer, id_layer);
1470 if (ivilayer == NULL) {
1471 layout_layer = ivi_layout_layerCreateWithDimension(id_layer,
1472 (uint32_t)width, (uint32_t)height);
1473 if (layout_layer == NULL) {
1474 weston_log("id_layer is already created\n");
1478 /* ivilayer will be created by layer_event_create */
1479 ivilayer = get_layer(&shell->list_layer, id_layer);
1480 if (ivilayer == NULL) {
1481 weston_log("couldn't get layer object\n");
1486 ctrllayer = calloc(1, sizeof *ctrllayer);
1488 weston_log("no memory to allocate client layer\n");
1492 ++ivilayer->controller_layer_count;
1493 ivilayer->layer_canbe_removed = 0;
1495 ctrllayer->shell = shell;
1496 ctrllayer->client = client;
1498 ctrllayer->id_layer = id_layer;
1499 ctrllayer->resource = wl_resource_create(client,
1500 &ivi_controller_layer_interface, 1, id);
1501 if (ctrllayer->resource == NULL) {
1502 weston_log("couldn't get layer object\n");
1506 wl_list_init(&ctrllayer->link);
1507 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1509 wl_resource_set_implementation(ctrllayer->resource,
1510 &controller_layer_implementation,
1511 ivilayer, destroy_ivicontroller_layer);
1513 memset(&prop, 0, sizeof prop);
1515 ivi_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1516 send_layer_event(ctrllayer->resource, ivilayer,
1517 &prop, IVI_NOTIFICATION_ALL);
1521 surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
1523 struct ivishell *shell = userdata;
1524 struct ivicontroller_surface *ctrlsurf = NULL;
1525 uint32_t id_surface = 0;
1528 surface_event_remove(layout_surface, userdata);
1533 controller_surface_create(struct wl_client *client,
1534 struct wl_resource *resource,
1535 uint32_t id_surface,
1538 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1539 struct ivishell *shell = ctrl->shell;
1540 struct ivicontroller_surface *ctrlsurf = NULL;
1541 struct ivi_layout_SurfaceProperties prop;
1542 struct ivisurface *ivisurf = NULL;
1543 struct ivicontroller_surface *ctrl_link = NULL;
1545 ivisurf = get_surface(&shell->list_surface, id_surface);
1546 if (ivisurf == NULL) {
1550 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1552 weston_log("no memory to allocate controller surface\n");
1556 ctrlsurf->shell = shell;
1557 ctrlsurf->client = client;
1559 ctrlsurf->id_surface = id_surface;
1560 wl_list_init(&ctrlsurf->link);
1561 wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1563 ctrlsurf->resource = wl_resource_create(client,
1564 &ivi_controller_surface_interface, 1, id);
1565 if (ctrlsurf->resource == NULL) {
1566 weston_log("couldn't surface object");
1570 wl_list_for_each(ctrl_link, &shell->list_controller_surface, link) {
1571 if ((ctrl_link->implementation_set == 0) &&
1572 (ctrl_link->id_surface == id_surface) &&
1573 (ctrl_link->shell == shell) &&
1574 (ctrl_link->client != client)) {
1575 ++ivisurf->controller_surface_count;
1576 wl_resource_set_implementation(ctrl_link->resource,
1577 &controller_surface_implementation,
1578 ivisurf, destroy_ivicontroller_surface);
1579 ctrl_link->implementation_set = 1;
1583 ++ivisurf->controller_surface_count;
1585 wl_resource_set_implementation(ctrlsurf->resource,
1586 &controller_surface_implementation,
1587 ivisurf, destroy_ivicontroller_surface);
1589 ctrlsurf->implementation_set = 1;
1591 memset(&prop, 0, sizeof prop);
1593 ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1594 ivi_layout_surfaceSetContentObserver(ivisurf->layout_surface, surface_event_content, shell);
1596 send_surface_event(ctrlsurf->resource, ivisurf,
1597 &prop, IVI_NOTIFICATION_ALL);
1601 controller_get_native_handle(struct wl_client *client,
1602 struct wl_resource *resource,
1603 uint32_t id_process,
1606 struct wl_array surfaces;
1607 ivi_shell_get_shell_surfaces(&surfaces);
1608 struct shell_surface ** surface;
1610 wl_array_for_each(surface, &surfaces) {
1612 uint32_t pid = shell_surface_get_process_id(*surface);
1613 if (pid != id_process) {
1618 char* surface_title = shell_surface_get_title(*surface);
1619 if (strcmp(title, surface_title)) {
1624 struct weston_surface *es = shell_surface_get_surface(*surface);
1626 struct wl_resource *res = wl_resource_create(client, &wl_surface_interface, 1, 0);
1627 wl_resource_set_user_data(res, es);
1629 ivi_controller_send_native_handle(resource, res);
1633 wl_array_release(&surfaces);
1635 int32_t id_object = 0;
1636 ivi_controller_send_error(
1637 resource, id_object, IVI_CONTROLLER_OBJECT_TYPE_SURFACE,
1638 IVI_CONTROLLER_ERROR_CODE_NATIVE_HANDLE_END, "");
1642 controller_set_keyboard_focus(struct wl_client *client,
1643 struct wl_resource *resource,
1644 struct wl_array *surfaces)
1646 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1647 ivi_layout_SetKeyboardFocusOn(surfaces->data, surfaces->size);
1648 send_all_keyboard_focus(ctrl->shell);
1651 static const struct ivi_controller_interface controller_implementation = {
1652 controller_commit_changes,
1653 controller_layer_create,
1654 controller_surface_create,
1655 controller_set_keyboard_focus,
1656 controller_get_native_handle
1660 add_client_to_resources(struct ivishell *shell,
1661 struct wl_client *client,
1662 struct ivicontroller *controller)
1664 struct ivisurface* ivisurf = NULL;
1665 struct ivilayer* ivilayer = NULL;
1666 struct iviscreen* iviscrn = NULL;
1667 struct ivicontroller_screen *ctrlscrn = NULL;
1668 struct wl_resource *resource_output = NULL;
1669 uint32_t id_layout_surface = 0;
1670 uint32_t id_layout_layer = 0;
1671 struct ivi_layout_surface *layout_surface;
1673 const char *window_title;
1675 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1676 resource_output = wl_resource_find_for_client(
1677 &iviscrn->output->resource_list, client);
1678 if (resource_output == NULL) {
1682 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1683 if (ctrlscrn == NULL) {
1687 ivi_controller_send_screen(controller->resource,
1688 wl_resource_get_id(resource_output),
1689 ctrlscrn->resource);
1691 wl_list_for_each_reverse(ivilayer, &shell->list_layer, link) {
1693 ivi_layout_getIdOfLayer(ivilayer->layout_layer);
1695 ivi_controller_send_layer(controller->resource,
1698 wl_list_for_each_reverse(ivisurf, &shell->list_surface, link) {
1699 layout_surface = ivisurf->layout_surface;
1700 id_layout_surface = ivi_layout_getIdOfSurface(layout_surface);
1702 get_wl_shell_info(layout_surface, id_layout_surface,
1703 &pid, &window_title);
1705 ivi_controller_send_surface(controller->resource,
1706 id_layout_surface, pid, window_title);
1711 bind_ivi_controller(struct wl_client *client, void *data,
1712 uint32_t version, uint32_t id)
1714 struct ivishell *shell = data;
1715 struct ivicontroller *controller;
1718 controller = calloc(1, sizeof *controller);
1719 if (controller == NULL) {
1720 weston_log("no memory to allocate controller\n");
1724 controller->resource =
1725 wl_resource_create(client, &ivi_controller_interface, 1, id);
1726 wl_resource_set_implementation(controller->resource,
1727 &controller_implementation,
1728 controller, unbind_resource_controller);
1730 controller->shell = shell;
1731 controller->client = client;
1732 controller->id = id;
1734 wl_list_init(&controller->link);
1735 wl_list_insert(&shell->list_controller, &controller->link);
1737 add_client_to_resources(shell, client, controller);
1740 static struct iviscreen*
1741 create_screen(struct ivishell *shell, struct weston_output *output)
1743 struct iviscreen *iviscrn;
1744 iviscrn = calloc(1, sizeof *iviscrn);
1745 if (iviscrn == NULL) {
1746 weston_log("no memory to allocate client screen\n");
1750 iviscrn->shell = shell;
1751 iviscrn->output = output;
1753 // TODO : Only Single display
1754 iviscrn->layout_screen = ivi_layout_getScreenFromId(0);
1756 wl_list_init(&iviscrn->link);
1761 static struct ivilayer*
1762 create_layer(struct ivishell *shell,
1763 struct ivi_layout_layer *layout_layer,
1766 struct ivilayer *ivilayer = NULL;
1767 struct ivicontroller *controller = NULL;
1769 ivilayer = get_layer(&shell->list_layer, id_layer);
1770 if (ivilayer != NULL) {
1771 weston_log("id_layer is already created\n");
1775 ivilayer = calloc(1, sizeof *ivilayer);
1776 if (NULL == ivilayer) {
1777 weston_log("no memory to allocate client layer\n");
1781 ivilayer->shell = shell;
1782 wl_list_init(&ivilayer->list_screen);
1783 wl_list_init(&ivilayer->link);
1784 wl_list_insert(&shell->list_layer, &ivilayer->link);
1785 ivilayer->layout_layer = layout_layer;
1787 ivi_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1789 wl_list_for_each(controller, &shell->list_controller, link) {
1790 ivi_controller_send_layer(controller->resource, id_layer);
1796 static struct ivisurface*
1797 create_surface(struct ivishell *shell,
1798 struct ivi_layout_surface *layout_surface,
1799 uint32_t id_surface)
1801 struct ivisurface *ivisurf = NULL;
1802 struct ivicontroller *controller = NULL;
1804 const char *window_title;
1806 ivisurf = get_surface(&shell->list_surface, id_surface);
1807 if (ivisurf != NULL) {
1808 weston_log("id_surface is already created\n");
1812 ivisurf = calloc(1, sizeof *ivisurf);
1813 if (ivisurf == NULL) {
1814 weston_log("no memory to allocate client surface\n");
1818 ivisurf->shell = shell;
1819 ivisurf->layout_surface = layout_surface;
1820 wl_list_init(&ivisurf->list_layer);
1821 wl_list_init(&ivisurf->link);
1822 wl_list_insert(&shell->list_surface, &ivisurf->link);
1824 get_wl_shell_info(layout_surface, id_surface, &pid, &window_title);
1826 wl_list_for_each(controller, &shell->list_controller, link) {
1827 ivi_controller_send_surface(controller->resource,
1828 id_surface, pid, window_title);
1831 ivi_layout_surfaceAddNotification(layout_surface,
1832 send_surface_prop, ivisurf);
1838 layer_event_create(struct ivi_layout_layer *layout_layer,
1841 struct ivishell *shell = userdata;
1842 struct ivilayer *ivilayer = NULL;
1843 uint32_t id_layer = 0;
1845 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1847 ivilayer = create_layer(shell, layout_layer, id_layer);
1848 if (ivilayer == NULL) {
1849 weston_log("failed to create layer");
1855 layer_event_remove(struct ivi_layout_layer *layout_layer,
1858 struct ivishell *shell = userdata;
1859 struct ivicontroller_layer *ctrllayer = NULL;
1860 struct ivilayer *ivilayer = NULL;
1861 struct ivilayer *next = NULL;
1862 uint32_t id_layer = 0;
1865 wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1866 if (layout_layer != ivilayer->layout_layer) {
1870 wl_list_remove(&ivilayer->link);
1879 id_layer = ivi_layout_getIdOfLayer(layout_layer);
1881 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1882 if (id_layer != ctrllayer->id_layer) {
1885 ivi_controller_layer_send_destroyed(ctrllayer->resource);
1892 surface_event_create(struct ivi_layout_surface *layout_surface,
1895 struct ivishell *shell = userdata;
1896 struct ivisurface *ivisurf = NULL;
1897 uint32_t id_surface = 0;
1898 struct ivicontroller_surface *ctrlsurf = NULL;
1900 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1902 ivisurf = create_surface(shell, layout_surface, id_surface);
1903 if (ivisurf == NULL) {
1904 weston_log("failed to create surface");
1908 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1909 if (id_surface != ctrlsurf->id_surface) {
1912 ivi_controller_surface_send_content(ctrlsurf->resource, IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_AVAILABLE);
1917 surface_event_remove(struct ivi_layout_surface *layout_surface,
1920 struct ivishell *shell = userdata;
1921 struct ivicontroller_surface *ctrlsurf = NULL;
1922 struct ivisurface *ivisurf = NULL;
1923 struct ivisurface *next = NULL;
1924 uint32_t id_surface = 0;
1927 wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
1928 if (layout_surface != ivisurf->layout_surface) {
1932 wl_list_remove(&ivisurf->link);
1935 if (ivisurf->controller_surface_count == 0) {
1939 ivisurf->can_be_removed = 1;
1946 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1948 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1949 if (id_surface != ctrlsurf->id_surface) {
1952 ivi_controller_surface_send_content(ctrlsurf->resource, IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED);
1953 ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1959 surface_event_configure(struct ivi_layout_surface *layout_surface,
1962 struct ivishell *shell = userdata;
1963 struct ivisurface *ivisurf = NULL;
1964 struct ivicontroller_surface *ctrlsurf = NULL;
1965 struct ivi_layout_SurfaceProperties prop;
1966 uint32_t id_surface = 0;
1968 id_surface = ivi_layout_getIdOfSurface(layout_surface);
1970 ivisurf = get_surface(&shell->list_surface, id_surface);
1971 if (ivisurf == NULL) {
1972 weston_log("id_surface is not created yet\n");
1976 memset(&prop, 0, sizeof prop);
1977 ivi_layout_getPropertiesOfSurface(layout_surface, &prop);
1979 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1980 if (id_surface != ctrlsurf->id_surface) {
1983 send_surface_event(ctrlsurf->resource, ivisurf,
1984 &prop, IVI_NOTIFICATION_ALL);
1989 check_layout_layers(struct ivishell *shell)
1991 struct ivi_layout_layer **pArray = NULL;
1992 struct ivilayer *ivilayer = NULL;
1993 uint32_t id_layer = 0;
1994 uint32_t length = 0;
1998 ret = ivi_layout_getLayers(&length, &pArray);
2000 weston_log("failed to get layers at check_layout_layers\n");
2005 /* if length is 0, pArray doesn't need to free.*/
2009 for (i = 0; i < length; i++) {
2010 id_layer = ivi_layout_getIdOfLayer(pArray[i]);
2011 ivilayer = create_layer(shell, pArray[i], id_layer);
2012 if (ivilayer == NULL) {
2013 weston_log("failed to create layer");
2024 check_layout_surfaces(struct ivishell *shell)
2026 struct ivi_layout_surface **pArray = NULL;
2027 struct ivisurface *ivisurf = NULL;
2028 uint32_t id_surface = 0;
2029 uint32_t length = 0;
2033 ret = ivi_layout_getSurfaces(&length, &pArray);
2035 weston_log("failed to get surfaces at check_layout_surfaces\n");
2040 /* if length is 0, pArray doesn't need to free.*/
2044 for (i = 0; i < length; i++) {
2045 id_surface = ivi_layout_getIdOfSurface(pArray[i]);
2046 ivisurf = create_surface(shell, pArray[i], id_surface);
2047 if (ivisurf == NULL) {
2048 weston_log("failed to create surface");
2059 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
2061 struct weston_output *output = NULL;
2062 struct iviscreen *iviscrn = NULL;
2065 shell->compositor = ec;
2067 wl_list_init(&shell->list_surface);
2068 wl_list_init(&shell->list_layer);
2069 wl_list_init(&shell->list_screen);
2070 wl_list_init(&shell->list_weston_surface);
2071 wl_list_init(&shell->list_controller);
2072 wl_list_init(&shell->list_controller_screen);
2073 wl_list_init(&shell->list_controller_layer);
2074 wl_list_init(&shell->list_controller_surface);
2075 shell->event_restriction = 0;
2077 wl_list_for_each(output, &ec->output_list, link) {
2078 iviscrn = create_screen(shell, output);
2079 if (iviscrn != NULL) {
2080 wl_list_insert(&shell->list_screen, &iviscrn->link);
2084 ret = check_layout_layers(shell);
2086 weston_log("failed to check_layout_layers");
2089 ret = check_layout_surfaces(shell);
2091 weston_log("failed to check_layout_surfaces");
2094 ivi_layout_addNotificationCreateLayer(layer_event_create, shell);
2095 ivi_layout_addNotificationRemoveLayer(layer_event_remove, shell);
2097 ivi_layout_addNotificationCreateSurface(surface_event_create, shell);
2098 ivi_layout_addNotificationRemoveSurface(surface_event_remove, shell);
2099 ivi_layout_addNotificationConfigureSurface(surface_event_configure, shell);
2103 module_init(struct weston_compositor *ec,
2104 int *argc, char *argv[])
2106 struct ivishell *shell;
2110 shell = malloc(sizeof *shell);
2114 memset(shell, 0, sizeof *shell);
2115 init_ivi_shell(ec, shell);
2117 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
2118 shell, bind_ivi_controller) == NULL) {