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>
31 #include "compositor.h"
32 #include "ivi-application-server-protocol.h"
33 #include "ivi-controller-server-protocol.h"
36 PROP_EVENT_OPACITY = 0x00000001,
37 PROP_EVENT_SRC_RECT = 0x00000002,
38 PROP_EVENT_DST_RECT = 0x00000004,
39 PROP_EVENT_ORIENTATION = 0x00000008,
40 PROP_EVENT_VISIBILITY = 0x00000010,
41 PROP_EVENT_PIXELFORMAT = 0x00000020,
42 PROP_EVENT_ADD = 0x00000040,
43 PROP_EVENT_ALL = 0x7FFFFFFF
48 struct ivi_properties {
66 struct ivilayer *layer;
71 struct iviscreen *screen;
77 struct wl_list list_layer;
78 struct wl_client *client;
80 struct ivishell *shell;
81 uint32_t update_count;
83 struct weston_surface *surface;
84 struct wl_listener surface_destroy_listener;
85 struct weston_transform surface_rotation;
86 struct weston_transform layer_rotation;
87 struct weston_transform surface_pos;
88 struct weston_transform layer_pos;
89 struct weston_transform scaling;
90 struct ivi_properties prop;
95 struct ivi_properties prop;
101 struct wl_list list_layer;
107 struct wl_list list_screen;
108 struct ivishell *shell;
109 struct weston_layer el;
112 struct ivi_properties prop;
116 struct wl_list list_surface;
118 struct ivi_properties prop;
122 struct wl_list list_surface;
129 struct ivishell *shell;
130 struct wl_list list_resource;
133 struct weston_output *output;
134 struct wl_list list_layer;
138 struct wl_list list_layer;
143 struct wl_list list_layer;
148 struct ivicontroller_surface {
149 struct wl_resource *resource;
152 struct wl_client *client;
154 struct ivishell *shell;
157 struct ivicontroller_layer {
158 struct wl_resource *resource;
161 struct wl_client *client;
163 struct ivishell *shell;
166 struct ivicontroller_screen {
167 struct wl_resource *resource;
170 struct wl_client *client;
172 struct ivishell *shell;
175 struct ivicontroller {
176 struct wl_resource *resource;
178 struct wl_client *client;
180 struct ivishell *shell;
183 struct link_shell_weston_surface
185 struct wl_resource *resource;
186 struct wl_listener destroy_listener;
187 struct weston_surface *surface;
192 struct wl_event_source *source;
196 struct shell_surface {
197 struct wl_resource *resource;
199 struct weston_surface *surface;
200 struct wl_listener surface_destroy_listener;
202 struct ivishell *shell;
203 struct ping_timer *ping_timer;
211 const struct weston_shell_client *client;
212 struct weston_output *output;
216 struct wl_resource *resource;
218 struct wl_listener destroy_listener;
220 struct weston_compositor *compositor;
222 struct weston_surface *surface;
224 struct weston_process process;
226 struct weston_seat *seat;
228 struct wl_list list_surface;
229 struct wl_list list_layer;
230 struct wl_list list_screen;
232 struct wl_list list_weston_surface;
234 struct wl_list list_controller;
235 struct wl_list list_controller_surface;
236 struct wl_list list_controller_layer;
237 struct wl_list list_controller_screen;
240 struct weston_process process;
241 struct wl_client *client;
242 struct wl_resource *desktop_shell;
250 int event_restriction;
254 struct ivi_surface_interface surface_implementation;
257 add_ordersurface_to_layer(struct ivisurface *ivisurf,
258 struct ivilayer *ivilayer)
260 struct link_layer *link_layer = NULL;
262 link_layer = malloc(sizeof *link_layer);
263 if (link_layer == NULL) {
264 weston_log("memory insufficient for link_layer\n");
268 link_layer->layer = ivilayer;
269 wl_list_init(&link_layer->link);
270 wl_list_insert(&ivisurf->list_layer, &link_layer->link);
274 remove_ordersurface_from_layer(struct ivisurface *ivisurf)
276 struct link_layer *link_layer = NULL;
277 struct link_layer *next = NULL;
279 wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
280 if (!wl_list_empty(&link_layer->link)) {
281 wl_list_remove(&link_layer->link);
285 wl_list_init(&ivisurf->list_layer);
289 add_orderlayer_to_screen(struct ivilayer *ivilayer,
290 struct iviscreen *iviscreen)
292 struct link_screen *link_scrn = NULL;
294 link_scrn = malloc(sizeof *link_scrn);
295 if (link_scrn == NULL) {
296 weston_log("memory insufficient for link_screen\n");
300 link_scrn->screen = iviscreen;
301 wl_list_init(&link_scrn->link);
302 wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
306 remove_orderlayer_from_screen(struct ivilayer *ivilayer)
308 struct link_screen *link_scrn = NULL;
309 struct link_screen *next = NULL;
311 wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
312 if (!wl_list_empty(&link_scrn->link)) {
313 wl_list_remove(&link_scrn->link);
317 wl_list_init(&ivilayer->list_screen);
321 destroy_ivicontroller_surface(struct wl_resource *resource)
323 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
324 struct ivishell *shell = ivisurf->shell;
326 struct ivicontroller_surface *ctrlsurf = NULL;
327 struct ivicontroller_surface *next = NULL;
329 wl_list_for_each_safe(ctrlsurf, next,
330 &shell->list_controller_surface, link) {
331 if (ivisurf->id_surface != ctrlsurf->id_surface) {
334 wl_list_remove(&ctrlsurf->link);
341 destroy_ivicontroller_layer(struct wl_resource *resource)
343 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
344 struct ivishell *shell = ivilayer->shell;
345 struct ivicontroller_layer *ctrllayer = NULL;
346 struct ivicontroller_layer *next = NULL;
348 wl_list_for_each_safe(ctrllayer, next,
349 &shell->list_controller_layer, link) {
350 if (ivilayer->id_layer != ctrllayer->id_layer) {
353 wl_list_remove(&ctrllayer->link);
360 destroy_ivicontroller_screen(struct wl_resource *resource)
362 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
363 struct ivicontroller_screen *ctrlscrn = NULL;
364 struct ivicontroller_screen *next = NULL;
366 wl_list_for_each_safe(ctrlscrn, next,
367 &iviscrn->shell->list_controller_screen, link) {
368 if (iviscrn->id_screen != ctrlscrn->id_screen) {
371 wl_list_remove(&ctrlscrn->link);
378 unbind_resource_controller(struct wl_resource *resource)
380 struct ivicontroller *controller = wl_resource_get_user_data(resource);
382 wl_list_remove(&controller->link);
387 static struct ivisurface*
388 get_surface(struct wl_list *list_surf, uint32_t id_surface)
390 struct ivisurface *ivisurf;
391 wl_list_for_each(ivisurf, list_surf, link) {
392 if (ivisurf->id_surface == id_surface) {
400 static struct ivilayer*
401 get_layer(struct wl_list *list_layer, uint32_t id_layer)
403 struct ivilayer *ivilayer;
404 wl_list_for_each(ivilayer, list_layer, link) {
405 if (ivilayer->id_layer == id_layer) {
414 init_properties(struct ivi_properties *prop)
416 memset(prop, 0, sizeof *prop);
417 prop->opacity = wl_fixed_from_double(1.0);
421 struct ivi_controller_screen_interface controller_screen_implementation;
423 static struct ivicontroller_screen*
424 controller_screen_create(struct ivishell *shell,
425 struct wl_client *client,
426 struct iviscreen *iviscrn)
428 struct ivicontroller_screen *ctrlscrn;
430 ctrlscrn = calloc(1, sizeof *ctrlscrn);
431 if (ctrlscrn == NULL) {
432 weston_log("no memory to allocate controller screen\n");
436 ctrlscrn->client = client;
437 ctrlscrn->shell = shell;
438 ctrlscrn->id_screen = iviscrn->id_screen;
441 wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
442 if (ctrlscrn->resource == NULL) {
443 weston_log("couldn't new screen controller object");
448 wl_resource_set_implementation(ctrlscrn->resource,
449 &controller_screen_implementation,
450 iviscrn, destroy_ivicontroller_screen);
452 wl_list_init(&ctrlscrn->link);
453 wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
459 update_opacity(struct ivilayer *ivilayer,
460 struct ivisurface *ivisurf)
462 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
463 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
465 if ((ivilayer->event_mask & PROP_EVENT_OPACITY) ||
466 (ivisurf->event_mask & PROP_EVENT_OPACITY)) {
467 if (ivisurf->surface == NULL) {
470 ivisurf->surface->alpha = layer_alpha * surf_alpha;
475 shell_surface_configure(struct weston_surface *,
476 int32_t, int32_t, int32_t, int32_t);
478 static struct shell_surface *
479 get_shell_surface(struct weston_surface *surface)
481 if (surface->configure == shell_surface_configure) {
482 return surface->configure_private;
489 update_surface_orientation(struct ivilayer *ivilayer,
490 struct ivisurface *ivisurf)
494 struct weston_surface *es = ivisurf->surface;
501 struct weston_matrix *matrix = &ivisurf->surface_rotation.matrix;
502 struct shell_surface *shsurf = NULL;
508 shsurf = get_shell_surface(es);
509 if (shsurf == NULL) {
513 if ((shsurf->width == 0) || (shsurf->height == 0)) {
517 if ((ivilayer->prop.dest_width == 0) ||
518 (ivilayer->prop.dest_height == 0)) {
521 width = (float)ivilayer->prop.dest_width;
522 height = (float)ivilayer->prop.dest_height;
524 switch (ivisurf->prop.orientation) {
525 case IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES:
529 case IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES:
535 case IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES:
539 case IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES:
547 wl_list_remove(&ivisurf->surface_rotation.link);
548 weston_surface_geometry_dirty(es);
550 weston_matrix_init(matrix);
553 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
554 weston_matrix_rotate_xy(matrix, v_cos, v_sin);
555 weston_matrix_scale(matrix, sx, sy, 1.0);
556 weston_matrix_translate(matrix, cx, cy, 0.0f);
557 wl_list_insert(&es->geometry.transformation_list,
558 &ivisurf->surface_rotation.link);
560 weston_surface_set_transform_parent(es, NULL);
561 weston_surface_update_transform(es);
565 update_layer_orientation(struct ivilayer *ivilayer,
566 struct ivisurface *ivisurf)
570 struct weston_surface *es = ivisurf->surface;
571 struct weston_output *output = NULL;
578 struct weston_matrix *matrix = &ivisurf->layer_rotation.matrix;
579 struct shell_surface *shsurf = NULL;
585 shsurf = get_shell_surface(es);
586 if (shsurf == NULL) {
590 if ((shsurf->width == 0) || (shsurf->height == 0)) {
595 if (output == NULL) {
598 if ((output->width == 0) || (output->height == 0)) {
601 width = (float)output->width;
602 height = (float)output->height;
604 switch (ivilayer->prop.orientation) {
605 case IVI_CONTROLLER_SURFACE_ORIENTATION_0_DEGREES:
609 case IVI_CONTROLLER_SURFACE_ORIENTATION_90_DEGREES:
615 case IVI_CONTROLLER_SURFACE_ORIENTATION_180_DEGREES:
619 case IVI_CONTROLLER_SURFACE_ORIENTATION_270_DEGREES:
627 wl_list_remove(&ivisurf->layer_rotation.link);
628 weston_surface_geometry_dirty(es);
630 weston_matrix_init(matrix);
633 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
634 weston_matrix_rotate_xy(matrix, v_cos, v_sin);
635 weston_matrix_scale(matrix, sx, sy, 1.0);
636 weston_matrix_translate(matrix, cx, cy, 0.0f);
637 wl_list_insert(&es->geometry.transformation_list,
638 &ivisurf->layer_rotation.link);
640 weston_surface_set_transform_parent(es, NULL);
641 weston_surface_update_transform(es);
645 update_surface_position(struct ivisurface *ivisurf)
647 struct weston_surface *es = ivisurf->surface;
648 float tx = (float)ivisurf->prop.dest_x;
649 float ty = (float)ivisurf->prop.dest_y;
650 struct weston_matrix *matrix = &ivisurf->surface_pos.matrix;
651 struct shell_surface *shsurf = NULL;
657 shsurf = get_shell_surface(es);
658 if (shsurf == NULL) {
662 if ((shsurf->width == 0) || (shsurf->height == 0)) {
666 wl_list_remove(&ivisurf->surface_pos.link);
668 weston_matrix_init(matrix);
669 weston_matrix_translate(matrix, tx, ty, 0.0f);
670 wl_list_insert(&es->geometry.transformation_list,
671 &ivisurf->surface_pos.link);
673 weston_surface_set_transform_parent(es, NULL);
674 weston_surface_update_transform(es);
676 //weston_zoom_run(es, 0.0, 1.0, NULL, NULL);
680 update_layer_position(struct ivilayer *ivilayer,
681 struct ivisurface *ivisurf)
683 struct weston_surface *es = ivisurf->surface;
684 float tx = (float)ivilayer->prop.dest_x;
685 float ty = (float)ivilayer->prop.dest_y;
686 struct weston_matrix *matrix = &ivisurf->layer_pos.matrix;
687 struct shell_surface *shsurf = NULL;
693 shsurf = get_shell_surface(es);
694 if (shsurf == NULL) {
698 if ((shsurf->width == 0) || (shsurf->height == 0)) {
702 wl_list_remove(&ivisurf->layer_pos.link);
704 weston_matrix_init(matrix);
705 weston_matrix_translate(matrix, tx, ty, 0.0f);
707 &es->geometry.transformation_list,
708 &ivisurf->layer_pos.link);
710 weston_surface_set_transform_parent(es, NULL);
711 weston_surface_update_transform(es);
715 update_scale(struct ivilayer *ivilayer,
716 struct ivisurface *ivisurf)
718 struct weston_surface *es = ivisurf->surface;
725 struct weston_matrix *matrix = &ivisurf->scaling.matrix;
726 struct shell_surface *shsurf = NULL;
732 shsurf = get_shell_surface(es);
733 if (shsurf == NULL) {
737 if ((shsurf->width == 0) || (shsurf->height == 0)) {
741 lw = ((float)ivilayer->prop.dest_width / shsurf->width);
742 sw = ((float)ivisurf->prop.dest_width / shsurf->width);
743 lh = ((float)ivilayer->prop.dest_height / shsurf->height);
744 sh = ((float)ivisurf->prop.dest_height / shsurf->height);
748 wl_list_remove(&ivisurf->scaling.link);
749 weston_matrix_init(matrix);
750 weston_matrix_scale(matrix, sx, sy, 1.0f);
752 wl_list_insert(&es->geometry.transformation_list,
753 &ivisurf->scaling.link);
755 weston_surface_set_transform_parent(es, NULL);
756 weston_surface_update_transform(es);
760 update_prop(struct ivilayer *ivilayer,
761 struct ivisurface *ivisurf)
763 if (ivilayer->event_mask | ivisurf->event_mask) {
764 update_opacity(ivilayer, ivisurf);
765 update_layer_orientation(ivilayer, ivisurf);
766 update_layer_position(ivilayer, ivisurf);
767 update_surface_position(ivisurf);
768 update_surface_orientation(ivilayer, ivisurf);
769 update_scale(ivilayer, ivisurf);
771 ivisurf->update_count++;
773 if (ivisurf->surface == NULL) {
776 weston_surface_geometry_dirty(ivisurf->surface);
777 weston_surface_damage(ivisurf->surface);
782 send_surface_add_event(struct ivisurface *ivisurf,
783 struct wl_resource *res_surf)
785 struct ivishell *shell = ivisurf->shell;
786 struct link_layer* link_layer = NULL;
787 struct ivicontroller_layer *ctrllayer = NULL;
788 struct wl_client *client_surf = NULL;
790 client_surf = wl_resource_get_client(res_surf);
791 wl_list_for_each(link_layer, &ivisurf->list_layer, link) {
792 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
794 if (ctrllayer->client != client_surf) {
798 if (ctrllayer->id_layer != link_layer->layer->id_layer) {
802 ivi_controller_surface_send_layer(res_surf, NULL);
803 ivi_controller_surface_send_layer(res_surf, ctrllayer->resource);
809 send_surface_event(struct ivisurface *ivisurf,
810 struct wl_resource *resource, uint32_t mask)
812 if (mask & PROP_EVENT_OPACITY) {
813 ivi_controller_surface_send_opacity(resource,
814 ivisurf->prop.opacity);
816 if (mask & PROP_EVENT_SRC_RECT) {
817 ivi_controller_surface_send_source_rectangle(resource,
818 ivisurf->prop.src_x, ivisurf->prop.src_y,
819 ivisurf->prop.src_width, ivisurf->prop.src_height);
821 if (mask & PROP_EVENT_DST_RECT) {
822 ivi_controller_surface_send_destination_rectangle(resource,
823 ivisurf->prop.dest_x, ivisurf->prop.dest_y,
824 ivisurf->prop.dest_width, ivisurf->prop.dest_height);
826 if (mask & PROP_EVENT_ORIENTATION) {
827 ivi_controller_surface_send_orientation(resource,
828 ivisurf->prop.orientation);
830 if (mask & PROP_EVENT_VISIBILITY) {
831 ivi_controller_surface_send_visibility(resource,
832 ivisurf->prop.visibility);
834 if (mask & PROP_EVENT_PIXELFORMAT) {
835 ivi_controller_surface_send_pixelformat(resource,
836 ivisurf->pixelformat);
838 if (mask & PROP_EVENT_ADD) {
839 send_surface_add_event(ivisurf, resource);
844 send_layer_add_event(struct ivilayer *ivilayer,
845 struct wl_resource *res_layer)
847 struct link_screen *link_scrn = NULL;
848 struct wl_client *client_layer = NULL;
849 struct wl_resource *resource_output = NULL;
851 client_layer = wl_resource_get_client(res_layer);
852 wl_list_for_each(link_scrn, &ivilayer->list_screen, link) {
854 resource_output = wl_resource_find_for_client(
855 &link_scrn->screen->output->resource_list,
857 if (resource_output == NULL) {
861 ivi_controller_layer_send_screen(res_layer, resource_output);
866 send_layer_event(struct ivilayer *ivilayer,
867 struct wl_resource *resource, uint32_t mask)
869 if (mask & PROP_EVENT_OPACITY) {
870 ivi_controller_layer_send_opacity(resource,
871 ivilayer->prop.opacity);
873 if (mask & PROP_EVENT_SRC_RECT) {
874 ivi_controller_layer_send_source_rectangle(resource,
875 ivilayer->prop.src_x,
876 ivilayer->prop.src_y,
877 ivilayer->prop.src_width,
878 ivilayer->prop.src_height);
880 if (mask & PROP_EVENT_DST_RECT) {
881 ivi_controller_layer_send_destination_rectangle(resource,
882 ivilayer->prop.dest_x,
883 ivilayer->prop.dest_y,
884 ivilayer->prop.dest_width,
885 ivilayer->prop.dest_height);
887 if (mask & PROP_EVENT_ORIENTATION) {
888 ivi_controller_layer_send_orientation(resource,
889 ivilayer->prop.orientation);
891 if (mask & PROP_EVENT_VISIBILITY) {
892 ivi_controller_layer_send_visibility(resource,
893 ivilayer->prop.visibility);
895 if (mask & PROP_EVENT_ADD) {
896 send_layer_add_event(ivilayer, resource);
901 send_surface_prop(struct ivisurface *ivisurf)
903 struct ivicontroller_surface *ctrlsurf = 0;
904 struct ivishell *shell = ivisurf->shell;
905 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
906 if (ivisurf->id_surface != ctrlsurf->id_surface) {
909 send_surface_event(ivisurf, ctrlsurf->resource, ivisurf->event_mask);
911 ivisurf->event_mask = 0;
915 send_layer_prop(struct ivilayer *ivilayer)
917 struct ivicontroller_layer *ctrllayer = 0;
918 struct ivishell *shell = ivilayer->shell;
919 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
920 if (ivilayer->id_layer != ctrllayer->id_layer) {
923 send_layer_event(ivilayer, ctrllayer->resource, ivilayer->event_mask);
925 ivilayer->event_mask = 0;
929 commit_changes(struct ivishell *shell)
931 struct iviscreen *iviscrn;
932 struct ivilayer *ivilayer;
933 struct ivisurface *ivisurf;
934 wl_list_for_each(iviscrn, &shell->list_screen, link) {
935 wl_list_for_each(ivilayer,
936 &iviscrn->order.list_layer,
938 wl_list_for_each(ivisurf,
939 &ivilayer->order.list_surface,
941 update_prop(ivilayer, ivisurf);
948 send_prop(struct ivishell *shell)
950 struct ivilayer *ivilayer;
951 struct ivisurface *ivisurf;
952 wl_list_for_each(ivilayer, &shell->list_layer, link) {
953 send_layer_prop(ivilayer);
956 wl_list_for_each(ivisurf, &shell->list_surface, link) {
957 send_surface_prop(ivisurf);
962 surface_destroy(struct wl_client *client,
963 struct wl_resource *resource)
965 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
968 if (!wl_list_empty(&ivisurf->pending.link)) {
969 wl_list_remove(&ivisurf->pending.link);
971 if (!wl_list_empty(&ivisurf->order.link)) {
972 wl_list_remove(&ivisurf->order.link);
974 if (!wl_list_empty(&ivisurf->link)) {
975 wl_list_remove(&ivisurf->link);
977 remove_ordersurface_from_layer(ivisurf);
978 wl_list_remove(&ivisurf->surface_destroy_listener.link);
983 static const struct ivi_surface_interface surface_implementation = {
988 controller_surface_set_opacity(struct wl_client *client,
989 struct wl_resource *resource,
992 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
993 struct ivi_properties *prop = &ivisurf->pending.prop;
996 prop->opacity = opacity;
997 ivisurf->event_mask |= PROP_EVENT_OPACITY;
1001 controller_surface_set_source_rectangle(struct wl_client *client,
1002 struct wl_resource *resource,
1008 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1009 struct ivi_properties *prop = &ivisurf->pending.prop;
1014 prop->src_width = width;
1015 prop->src_height = height;
1016 ivisurf->event_mask |= PROP_EVENT_SRC_RECT;
1020 controller_surface_set_destination_rectangle(struct wl_client *client,
1021 struct wl_resource *resource,
1027 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1028 struct ivi_properties *prop = &ivisurf->pending.prop;
1033 prop->dest_width = width;
1034 prop->dest_height = height;
1036 ivisurf->event_mask |= PROP_EVENT_DST_RECT;
1040 controller_surface_set_visibility(struct wl_client *client,
1041 struct wl_resource *resource,
1042 uint32_t visibility)
1044 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1045 struct ivi_properties *prop = &ivisurf->pending.prop;
1048 prop->visibility = visibility;
1049 ivisurf->event_mask |= PROP_EVENT_VISIBILITY;
1053 controller_surface_set_configuration(struct wl_client *client,
1054 struct wl_resource *resource,
1055 int32_t width, int32_t height)
1057 /* This interface has been supported yet. */
1065 controller_surface_set_orientation(struct wl_client *client,
1066 struct wl_resource *resource,
1067 int32_t orientation)
1069 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1070 struct ivi_properties *prop = &ivisurf->pending.prop;
1073 prop->orientation = orientation;
1074 ivisurf->event_mask |= PROP_EVENT_ORIENTATION;
1078 controller_surface_screenshot(struct wl_client *client,
1079 struct wl_resource *resource,
1080 const char *filename)
1082 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1083 struct weston_compositor *compositor = ivisurf->shell->compositor;
1084 cairo_surface_t *surface;
1091 width = ivisurf->prop.dest_width;
1092 height = ivisurf->prop.dest_height;
1094 (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
1095 pixels = malloc(stride * height);
1096 if (pixels == NULL) {
1100 compositor->renderer->read_surface_pixels(ivisurf->surface,
1101 compositor->read_format, pixels,
1102 0, 0, width, height);
1104 surface = cairo_image_surface_create_for_data(pixels,
1105 CAIRO_FORMAT_ARGB32,
1106 width, height, stride);
1107 cairo_surface_write_to_png(surface, filename);
1108 cairo_surface_destroy(surface);
1113 controller_surface_send_stats(struct wl_client *client,
1114 struct wl_resource *resource)
1116 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1120 wl_client_get_credentials(client, &pid, &uid, &gid);
1122 ivi_controller_surface_send_stats(resource, 0, 0,
1123 ivisurf->update_count, pid, "");
1127 controller_surface_destroy(struct wl_client *client,
1128 struct wl_resource *resource,
1129 int32_t destroy_scene_object)
1131 struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
1132 struct ivishell *shell = ivisurf->shell;
1133 struct ivicontroller_surface *ctrlsurf = NULL;
1135 (void)destroy_scene_object;
1137 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1138 if (ctrlsurf->id_surface != ivisurf->id_surface) {
1142 if (!wl_list_empty(&ctrlsurf->link)) {
1143 wl_list_remove(&ctrlsurf->link);
1145 wl_resource_destroy(resource);
1151 controller_surface_set_input_focus(struct wl_client *client,
1152 struct wl_resource *resource,
1161 struct ivi_controller_surface_interface controller_surface_implementation = {
1162 controller_surface_set_visibility,
1163 controller_surface_set_opacity,
1164 controller_surface_set_source_rectangle,
1165 controller_surface_set_destination_rectangle,
1166 controller_surface_set_configuration,
1167 controller_surface_set_orientation,
1168 controller_surface_screenshot,
1169 controller_surface_send_stats,
1170 controller_surface_destroy,
1171 controller_surface_set_input_focus
1175 controller_layer_set_source_rectangle(struct wl_client *client,
1176 struct wl_resource *resource,
1182 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1183 struct ivi_properties *prop = &ivilayer->pending.prop;
1188 prop->src_width = width;
1189 prop->src_height = height;
1190 ivilayer->event_mask |= PROP_EVENT_SRC_RECT;
1194 controller_layer_set_destination_rectangle(struct wl_client *client,
1195 struct wl_resource *resource,
1201 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1202 struct ivi_properties *prop = &ivilayer->pending.prop;
1207 prop->dest_width = width;
1208 prop->dest_height = height;
1209 ivilayer->event_mask |= PROP_EVENT_DST_RECT;
1213 controller_layer_set_visibility(struct wl_client *client,
1214 struct wl_resource *resource,
1215 uint32_t visibility)
1217 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1218 struct ivi_properties *prop = &ivilayer->pending.prop;
1221 prop->visibility = visibility;
1222 ivilayer->event_mask |= PROP_EVENT_VISIBILITY;
1226 controller_layer_set_opacity(struct wl_client *client,
1227 struct wl_resource *resource,
1230 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1231 struct ivi_properties *prop = &ivilayer->pending.prop;
1234 prop->opacity = opacity;
1235 ivilayer->event_mask |= PROP_EVENT_OPACITY;
1239 controller_layer_set_configuration(struct wl_client *client,
1240 struct wl_resource *resource,
1244 /* This interface has been supported yet. */
1252 controller_layer_set_orientation(struct wl_client *client,
1253 struct wl_resource *resource,
1254 int32_t orientation)
1256 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1257 struct ivi_properties *prop = &ivilayer->pending.prop;
1260 prop->orientation = orientation;
1261 ivilayer->event_mask |= PROP_EVENT_ORIENTATION;
1265 controller_layer_clear_surfaces(struct wl_client *client,
1266 struct wl_resource *resource)
1268 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1271 wl_list_init(&ivilayer->pending.list_surface);
1273 ivilayer->event_mask |= PROP_EVENT_ADD;
1277 is_surface_in_layer(struct ivisurface *ivisurf,
1278 struct ivilayer *ivilayer)
1280 struct ivisurface *surf = NULL;
1282 wl_list_for_each(surf, &ivilayer->pending.list_surface, pending.link) {
1283 if (surf->id_surface == ivisurf->id_surface) {
1292 controller_layer_add_surface(struct wl_client *client,
1293 struct wl_resource *resource,
1294 struct wl_resource *surface)
1296 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1297 struct ivisurface *addsurf = wl_resource_get_user_data(surface);
1298 struct ivisurface *ivisurf;
1299 int is_surf_in_layer = 0;
1302 if (addsurf == NULL) {
1303 weston_log("invalid surface in layer_add_surface\n");
1306 is_surf_in_layer = is_surface_in_layer(addsurf, ivilayer);
1307 if (is_surf_in_layer == 1) {
1311 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
1312 if (ivisurf->id_surface == addsurf->id_surface) {
1313 if (!wl_list_empty(&ivisurf->pending.link)) {
1314 wl_list_remove(&ivisurf->pending.link);
1316 wl_list_init(&ivisurf->pending.link);
1317 wl_list_insert(&ivilayer->pending.list_surface,
1318 &ivisurf->pending.link);
1323 ivilayer->event_mask |= PROP_EVENT_ADD;
1327 controller_layer_remove_surface(struct wl_client *client,
1328 struct wl_resource *resource,
1329 struct wl_resource *surface)
1331 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1332 struct ivisurface *remsurf = wl_resource_get_user_data(surface);
1333 struct ivisurface *ivisurf = NULL;
1334 struct ivisurface *next = NULL;
1339 wl_list_for_each_safe(ivisurf, next,
1340 &ivilayer->pending.list_surface, pending.link) {
1341 if (ivisurf->id_surface == remsurf->id_surface) {
1342 if (!wl_list_empty(&ivisurf->pending.link)) {
1343 wl_list_remove(&ivisurf->pending.link);
1345 wl_list_init(&ivisurf->pending.link);
1352 controller_layer_screenshot(struct wl_client *client,
1353 struct wl_resource *resource,
1354 const char *filename)
1362 controller_layer_set_render_order(struct wl_client *client,
1363 struct wl_resource *resource,
1364 struct wl_array *id_surfaces)
1366 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1367 struct ivisurface *ivisurf = NULL;
1368 uint32_t *id_surface = NULL;
1371 wl_list_init(&ivilayer->pending.list_surface);
1372 wl_array_for_each(id_surface, id_surfaces) {
1373 wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
1374 if (*id_surface != ivisurf->id_surface) {
1378 if (!wl_list_empty(&ivisurf->pending.link)) {
1379 wl_list_remove(&ivisurf->pending.link);
1381 wl_list_init(&ivisurf->pending.link);
1382 wl_list_insert(&ivilayer->pending.list_surface,
1383 &ivisurf->pending.link);
1388 ivilayer->event_mask |= PROP_EVENT_ADD;
1392 layer_destroy(struct ivilayer *ivilayer)
1394 if (!wl_list_empty(&ivilayer->pending.link)) {
1395 wl_list_remove(&ivilayer->pending.link);
1397 if (!wl_list_empty(&ivilayer->order.link)) {
1398 wl_list_remove(&ivilayer->order.link);
1400 if (!wl_list_empty(&ivilayer->link)) {
1401 wl_list_remove(&ivilayer->link);
1403 remove_orderlayer_from_screen(ivilayer);
1409 controller_layer_destroy(struct wl_client *client,
1410 struct wl_resource *resource,
1411 int32_t destroy_scene_object)
1413 struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
1414 struct ivishell *shell = ivilayer->shell;
1415 struct ivicontroller_layer *ctrllayer = NULL;
1417 (void)destroy_scene_object;
1419 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1420 if (ctrllayer->id_layer != ivilayer->id_layer) {
1424 if (!wl_list_empty(&ctrllayer->link)) {
1425 wl_list_remove(&ctrllayer->link);
1427 wl_resource_destroy(resource);
1431 layer_destroy(ivilayer);
1435 struct ivi_controller_layer_interface controller_layer_implementation = {
1436 controller_layer_set_visibility,
1437 controller_layer_set_opacity,
1438 controller_layer_set_source_rectangle,
1439 controller_layer_set_destination_rectangle,
1440 controller_layer_set_configuration,
1441 controller_layer_set_orientation,
1442 controller_layer_screenshot,
1443 controller_layer_clear_surfaces,
1444 controller_layer_add_surface,
1445 controller_layer_remove_surface,
1446 controller_layer_set_render_order,
1447 controller_layer_destroy
1451 controller_screen_destroy(struct wl_client *client,
1452 struct wl_resource *resource)
1454 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1455 struct ivicontroller_screen *ctrlscrn = NULL;
1456 struct ivicontroller_screen *next = NULL;
1459 wl_list_for_each_safe(ctrlscrn, next,
1460 &iviscrn->shell->list_controller_screen, link) {
1461 if (iviscrn->id_screen != ctrlscrn->id_screen) {
1464 destroy_ivicontroller_screen(ctrlscrn->resource);
1465 wl_resource_destroy(ctrlscrn->resource);
1471 controller_screen_clear(struct wl_client *client,
1472 struct wl_resource *resource)
1474 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1477 wl_list_init(&iviscrn->pending.list_layer);
1479 iviscrn->event_mask |= PROP_EVENT_ADD;
1483 is_layer_in_screen(struct ivilayer *ivilayer,
1484 struct iviscreen *iviscrn)
1486 struct ivilayer *layer = NULL;
1488 wl_list_for_each(layer, &iviscrn->pending.list_layer, pending.link) {
1489 if (layer->id_layer == ivilayer->id_layer) {
1498 controller_screen_add_layer(struct wl_client *client,
1499 struct wl_resource *resource,
1500 struct wl_resource *layer)
1502 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1503 struct ivilayer *addlayer = wl_resource_get_user_data(layer);
1504 struct ivilayer *ivilayer;
1505 int is_layer_in_scrn = 0;
1508 is_layer_in_scrn = is_layer_in_screen(addlayer, iviscrn);
1509 if (is_layer_in_scrn == 1) {
1513 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1514 if (ivilayer->id_layer == addlayer->id_layer) {
1515 if (!wl_list_empty(&ivilayer->pending.link)) {
1516 wl_list_remove(&ivilayer->pending.link);
1518 wl_list_init(&ivilayer->pending.link);
1519 wl_list_insert(&iviscrn->pending.list_layer,
1520 &ivilayer->pending.link);
1525 iviscrn->event_mask |= PROP_EVENT_ADD;
1529 controller_screen_screenshot(struct wl_client *client,
1530 struct wl_resource *resource,
1531 const char *filename)
1533 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1534 struct weston_output *output = iviscrn->output;
1535 cairo_surface_t *surface = NULL;
1540 uint8_t *readpixs = NULL;
1541 uint8_t *writepixs = NULL;
1546 output->disable_planes--;
1548 width = output->current_mode->width;
1549 height = output->current_mode->height;
1551 (PIXMAN_FORMAT_BPP(output->compositor->read_format) / 8);
1552 readpixs = malloc(stride * height);
1553 if (readpixs == NULL) {
1556 writepixs = malloc(stride * height);
1557 if (writepixs == NULL) {
1561 output->compositor->renderer->read_pixels(output,
1562 output->compositor->read_format, readpixs,
1563 0, 0, width, height);
1566 d = writepixs + stride * (height - 1);
1568 for (i = 0; i < height; i++) {
1569 memcpy(d, s, stride);
1574 surface = cairo_image_surface_create_for_data(writepixs,
1575 CAIRO_FORMAT_ARGB32,
1576 width, height, stride);
1577 cairo_surface_write_to_png(surface, filename);
1578 cairo_surface_destroy(surface);
1584 controller_screen_set_render_order(struct wl_client *client,
1585 struct wl_resource *resource,
1586 struct wl_array *id_layers)
1588 struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1589 uint32_t *id_layer = NULL;
1590 struct ivilayer *ivilayer;
1593 wl_list_init(&iviscrn->pending.list_layer);
1594 wl_array_for_each(id_layer, id_layers) {
1595 wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1596 if (*id_layer == ivilayer->id_layer) {
1600 if (!wl_list_empty(&ivilayer->pending.link)) {
1601 wl_list_remove(&ivilayer->pending.link);
1603 wl_list_init(&ivilayer->pending.link);
1604 wl_list_insert(&iviscrn->pending.list_layer,
1605 &ivilayer->pending.link);
1610 iviscrn->event_mask |= PROP_EVENT_ADD;
1614 struct ivi_controller_screen_interface controller_screen_implementation = {
1615 controller_screen_destroy,
1616 controller_screen_clear,
1617 controller_screen_add_layer,
1618 controller_screen_screenshot,
1619 controller_screen_set_render_order
1623 commit_list_surface(struct ivishell *shell)
1625 struct ivisurface *ivisurf;
1626 wl_list_for_each(ivisurf, &shell->list_surface, link) {
1627 ivisurf->prop = ivisurf->pending.prop;
1632 commit_list_layer(struct ivishell *shell)
1634 struct ivilayer *ivilayer;
1635 struct ivisurface *ivisurf;
1637 wl_list_for_each(ivilayer, &shell->list_layer, link) {
1638 ivilayer->prop = ivilayer->pending.prop;
1640 if (!(ivilayer->event_mask & PROP_EVENT_ADD)) {
1643 wl_list_init(&ivilayer->order.list_surface);
1644 wl_list_for_each(ivisurf, &ivilayer->pending.list_surface,
1646 remove_ordersurface_from_layer(ivisurf);
1648 if (!wl_list_empty(&ivisurf->order.link)) {
1649 wl_list_remove(&ivisurf->order.link);
1651 wl_list_init(&ivisurf->order.link);
1652 wl_list_insert(&ivilayer->order.list_surface,
1653 &ivisurf->order.link);
1654 add_ordersurface_to_layer(ivisurf, ivilayer);
1660 commit_list_screen(struct ivishell *shell)
1662 struct weston_compositor *ec = shell->compositor;
1663 struct iviscreen *iviscrn;
1664 struct ivilayer *ivilayer;
1665 struct ivisurface *ivisurf;
1666 wl_list_for_each(iviscrn, &shell->list_screen, link) {
1667 if (iviscrn->event_mask & PROP_EVENT_ADD) {
1668 wl_list_init(&iviscrn->order.list_layer);
1670 wl_list_for_each(ivilayer, &iviscrn->pending.list_layer,
1672 remove_orderlayer_from_screen(ivilayer);
1674 wl_list_insert(&iviscrn->order.list_layer,
1675 &ivilayer->order.link);
1676 add_orderlayer_to_screen(ivilayer, iviscrn);
1678 iviscrn->event_mask = 0;
1682 wl_list_init(&ec->layer_list);
1683 wl_list_for_each(ivilayer, &iviscrn->order.list_layer, order.link) {
1684 if (ivilayer->prop.visibility == 0) {
1688 wl_list_insert(&ec->layer_list, &ivilayer->el.link);
1689 wl_list_init(&ivilayer->el.surface_list);
1691 wl_list_for_each(ivisurf, &ivilayer->order.list_surface,
1693 if (ivisurf->prop.visibility == 0) {
1697 if (ivisurf->surface == NULL) {
1701 wl_list_insert(&ivilayer->el.surface_list,
1702 &ivisurf->surface->layer_link);
1703 ivisurf->surface->output = iviscrn->output;
1711 controller_commit_changes(struct wl_client *client,
1712 struct wl_resource *resource)
1714 struct ivicontroller *controller = wl_resource_get_user_data(resource);
1717 commit_list_surface(controller->shell);
1718 commit_list_layer(controller->shell);
1719 commit_list_screen(controller->shell);
1721 commit_changes(controller->shell);
1722 send_prop(controller->shell);
1723 weston_compositor_schedule_repaint(controller->shell->compositor);
1726 static struct ivilayer*
1727 layer_create(struct wl_client *client,
1728 struct ivicontroller *ctrl,
1734 struct ivishell *shell = ctrl->shell;
1735 struct ivilayer *ivilayer = NULL;
1736 struct ivicontroller *controller = NULL;
1737 struct ivicontroller_layer *ctrllayer = NULL;
1743 ivilayer = get_layer(&shell->list_layer, id_layer);
1744 if (ivilayer != NULL)
1749 ivilayer = calloc(1, sizeof *ivilayer);
1751 weston_log("no memory to allocate client layer\n");
1755 init_properties(&ivilayer->prop);
1756 ivilayer->pending.prop = ivilayer->prop;
1757 ivilayer->id_layer = id_layer;
1758 ivilayer->shell = shell;
1759 ivilayer->event_mask = 0;
1760 wl_list_init(&ivilayer->link);
1761 wl_list_init(&ivilayer->pending.link);
1762 wl_list_init(&ivilayer->order.link);
1763 wl_list_init(&ivilayer->list_screen);
1765 wl_list_init(&ivilayer->pending.list_surface);
1766 wl_list_init(&ivilayer->order.list_surface);
1767 wl_list_insert(&shell->list_layer, &ivilayer->link);
1769 wl_list_for_each(controller, &shell->list_controller, link) {
1770 ivi_controller_send_layer(controller->resource,
1771 ivilayer->id_layer);
1773 wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1774 if (ivilayer->id_layer != ctrllayer->id_layer) {
1777 send_layer_event(ivilayer, ctrllayer->resource, PROP_EVENT_ALL);
1785 controller_layer_create(struct wl_client *client,
1786 struct wl_resource *resource,
1792 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1793 struct ivishell *shell = ctrl->shell;
1794 struct ivicontroller_layer *ctrllayer = NULL;
1795 struct ivilayer *ivilayer = NULL;
1797 weston_log("controller_layer_create is called\n");
1798 ctrllayer = calloc(1, sizeof *ctrllayer);
1800 weston_log("no memory to allocate client layer\n");
1804 ctrllayer->shell = shell;
1805 ctrllayer->client = client;
1807 ctrllayer->id_layer = id_layer;
1808 ctrllayer->resource = wl_resource_create(client,
1809 &ivi_controller_layer_interface, 1, id);
1810 if (ctrllayer->resource == NULL) {
1811 weston_log("couldn't layer object\n");
1815 weston_log("controller_layer_create is called\n");
1816 wl_list_init(&ctrllayer->link);
1817 wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1819 ivilayer = layer_create(client, ctrl, id_layer, width, height, id);
1821 if (ivilayer != NULL) {
1822 wl_resource_set_implementation(ctrllayer->resource,
1823 &controller_layer_implementation,
1824 ivilayer, destroy_ivicontroller_layer);
1829 controller_surface_create(struct wl_client *client,
1830 struct wl_resource *resource,
1831 uint32_t id_surface,
1834 struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1835 struct ivishell *shell = ctrl->shell;
1836 struct ivisurface *ivisurf = NULL;
1837 struct ivicontroller_surface *ctrlsurf = NULL;
1839 ctrlsurf = calloc(1, sizeof *ctrlsurf);
1841 weston_log("no memory to allocate controller surface\n");
1845 ctrlsurf->shell = shell;
1846 ctrlsurf->client = client;
1848 ctrlsurf->id_surface = id_surface;
1849 wl_list_init(&ctrlsurf->link);
1850 ctrlsurf->resource = wl_resource_create(client,
1851 &ivi_controller_surface_interface, 1, id);
1852 if (ctrlsurf->resource == NULL) {
1853 weston_log("couldn't surface object");
1857 wl_list_for_each(ivisurf, &shell->list_surface, link) {
1858 if (ivisurf->id_surface == ctrlsurf->id_surface) {
1859 wl_resource_set_implementation(ctrlsurf->resource,
1860 &controller_surface_implementation,
1861 ivisurf, destroy_ivicontroller_surface);
1867 static const struct ivi_controller_interface controller_implementation = {
1868 controller_commit_changes,
1869 controller_layer_create,
1870 controller_surface_create
1874 westonsurface_destroy_from_ivisurface(struct wl_listener *listener, void *data)
1876 struct ivisurface *ivisurf = container_of(listener,
1878 surface_destroy_listener);
1880 ivisurf->surface = NULL;
1884 application_surface_create(struct wl_client *client,
1885 struct wl_resource *resource,
1886 uint32_t id_surface,
1887 struct wl_resource *surface_resource,
1890 weston_log("application_surface_create\n");
1891 struct ivishell *shell = wl_resource_get_user_data(resource);
1892 struct weston_surface *es = NULL;
1893 struct ivisurface *ivisurf = NULL;
1894 struct ivicontroller *controller = NULL;
1895 struct ivicontroller_surface *ctrlsurf = NULL;
1897 es = wl_resource_get_user_data(surface_resource);
1899 weston_log("application_surface_create: invalid surface\n");
1902 ivisurf = get_surface(&shell->list_surface, id_surface);
1903 if (ivisurf != NULL)
1905 weston_log("id_surface is already created\n");
1907 resource = wl_resource_create(client, &ivi_surface_interface, 1, id);
1908 ivisurf->surface = es;
1910 ivisurf->surface_destroy_listener.notify =
1911 westonsurface_destroy_from_ivisurface;
1912 wl_resource_add_destroy_listener(es->resource,
1913 &ivisurf->surface_destroy_listener);
1918 ivisurf = calloc(1, sizeof *ivisurf);
1919 if (ivisurf == NULL) {
1920 weston_log("no memory to allocate client surface\n");
1924 init_properties(&ivisurf->prop);
1925 ivisurf->pixelformat = IVI_CONTROLLER_SURFACE_PIXELFORMAT_RGBA_8888;
1926 ivisurf->pending.prop = ivisurf->prop;
1927 ivisurf->surface = es;
1929 ivisurf->surface_destroy_listener.notify =
1930 westonsurface_destroy_from_ivisurface;
1931 wl_resource_add_destroy_listener(es->resource,
1932 &ivisurf->surface_destroy_listener);
1934 ivisurf->id_surface = id_surface;
1935 ivisurf->shell = shell;
1936 ivisurf->event_mask = 0;
1938 wl_list_init(&ivisurf->surface_rotation.link);
1939 wl_list_init(&ivisurf->layer_rotation.link);
1940 wl_list_init(&ivisurf->surface_pos.link);
1941 wl_list_init(&ivisurf->layer_pos.link);
1942 wl_list_init(&ivisurf->scaling.link);
1944 wl_list_init(&ivisurf->link);
1945 wl_list_init(&ivisurf->pending.link);
1946 wl_list_init(&ivisurf->order.link);
1947 wl_list_init(&ivisurf->list_layer);
1948 wl_list_insert(&shell->list_surface, &ivisurf->link);
1950 wl_list_for_each(controller, &shell->list_controller, link) {
1951 ivi_controller_send_surface(controller->resource,
1952 ivisurf->id_surface);
1954 wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1955 if (ivisurf->id_surface != ctrlsurf->id_surface) {
1958 send_surface_event(ivisurf, ctrlsurf->resource, PROP_EVENT_ALL);
1962 resource = wl_resource_create(client, &ivi_surface_interface, 1, id);
1963 if (resource == NULL) {
1964 weston_log("couldn't surface object");
1967 wl_resource_set_implementation(resource,
1968 &surface_implementation,
1972 static const struct ivi_application_interface application_implementation = {
1973 application_surface_create
1977 bind_ivi_application(struct wl_client *client, void *data,
1978 uint32_t version, uint32_t id)
1980 struct ivishell *shell = data;
1981 struct wl_resource *resource = NULL;
1984 resource = wl_resource_create(client, &ivi_application_interface, 1, id);
1985 wl_resource_set_implementation(resource,
1986 &application_implementation,
1991 add_client_to_resources(struct ivishell *shell,
1992 struct wl_client *client,
1993 struct ivicontroller *controller)
1995 struct ivisurface* ivisurf = NULL;
1996 struct ivilayer* ivilayer = NULL;
1997 struct iviscreen* iviscrn = NULL;
1998 struct ivicontroller_screen *ctrlscrn = NULL;
1999 struct wl_resource *resource_output = NULL;
2001 wl_list_for_each(ivisurf, &shell->list_surface, link) {
2002 ivi_controller_send_surface(controller->resource,
2003 ivisurf->id_surface);
2006 wl_list_for_each(ivilayer, &shell->list_layer, link) {
2007 ivi_controller_send_layer(controller->resource,
2008 ivilayer->id_layer);
2011 wl_list_for_each(iviscrn, &shell->list_screen, link) {
2013 wl_resource_find_for_client(&iviscrn->output->resource_list,
2015 if (resource_output == NULL) {
2019 ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
2020 if (ctrlscrn == NULL) {
2024 ivi_controller_send_screen(controller->resource,
2025 wl_resource_get_id(resource_output),
2026 ctrlscrn->resource);
2031 bind_ivi_controller(struct wl_client *client, void *data,
2032 uint32_t version, uint32_t id)
2034 struct ivishell *shell = data;
2035 struct ivicontroller *controller;
2038 controller = calloc(1, sizeof *controller);
2039 if (controller == NULL) {
2040 weston_log("no memory to allocate controller\n");
2044 controller->resource =
2045 wl_resource_create(client, &ivi_controller_interface, 1, id);
2046 wl_resource_set_implementation(controller->resource,
2047 &controller_implementation,
2048 controller, unbind_resource_controller);
2050 controller->shell = shell;
2051 controller->client = client;
2052 controller->id = id;
2054 wl_list_init(&controller->link);
2055 wl_list_insert(&shell->list_controller, &controller->link);
2057 add_client_to_resources(shell, client, controller);
2060 static struct iviscreen*
2061 create_screen(struct ivishell *shell, struct weston_output *output)
2063 struct iviscreen *iviscrn;
2064 iviscrn = calloc(1, sizeof *iviscrn);
2065 if (iviscrn == NULL) {
2066 weston_log("no memory to allocate client screen\n");
2069 iviscrn->shell = shell;
2070 iviscrn->output = output;
2071 iviscrn->event_mask = 0;
2073 wl_list_init(&iviscrn->link);
2074 wl_list_init(&iviscrn->list_layer);
2075 wl_list_init(&iviscrn->pending.list_layer);
2076 wl_list_init(&iviscrn->order.list_layer);
2077 wl_list_init(&iviscrn->list_resource);
2083 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
2085 struct weston_output *output = NULL;
2086 struct iviscreen *iviscrn = NULL;
2087 shell->compositor = ec;
2089 wl_list_init(&ec->layer_list);
2090 wl_list_init(&shell->list_surface);
2091 wl_list_init(&shell->list_layer);
2092 wl_list_init(&shell->list_screen);
2093 wl_list_init(&shell->list_weston_surface);
2094 wl_list_init(&shell->list_controller);
2095 wl_list_init(&shell->list_controller_screen);
2096 wl_list_init(&shell->list_controller_layer);
2097 wl_list_init(&shell->list_controller_surface);
2098 shell->event_restriction = 0;
2100 wl_list_for_each(output, &ec->output_list, link) {
2101 iviscrn = create_screen(shell, output);
2102 if (iviscrn != NULL) {
2103 wl_list_insert(&shell->list_screen, &iviscrn->link);
2105 wl_list_init(&iviscrn->order.list_layer);
2110 shell_destroy(struct wl_listener *listener, void *data)
2112 struct ivishell *shell =
2113 container_of(listener, struct ivishell, destroy_listener);
2120 ping_timer_destroy(struct shell_surface *shsurf)
2122 if (!shsurf || !shsurf->ping_timer) {
2126 if (shsurf->ping_timer->source) {
2127 wl_event_source_remove(shsurf->ping_timer->source);
2130 free(shsurf->ping_timer);
2131 shsurf->ping_timer = NULL;
2135 destroy_shell_surface(struct shell_surface *shsurf)
2137 wl_list_remove(&shsurf->surface_destroy_listener.link);
2138 shsurf->surface->configure = NULL;
2139 ping_timer_destroy(shsurf);
2140 free(shsurf->title);
2142 wl_list_remove(&shsurf->link);
2147 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
2149 struct shell_surface *shsurf = container_of(listener,
2150 struct shell_surface,
2151 surface_destroy_listener);
2154 if (wl_resource_get_client(shsurf->resource)) {
2155 wl_resource_destroy(shsurf->resource);
2157 wl_resource_destroy(shsurf->resource);
2158 destroy_shell_surface(shsurf);
2163 configure(struct weston_surface *surface,
2164 float x, float y, int32_t width, int32_t height)
2166 weston_surface_configure(surface, x, y, width, height);
2167 if (surface->output) {
2168 weston_surface_update_transform(surface);
2173 shell_surface_configure(struct weston_surface *es,
2174 int32_t sx, int32_t sy,
2175 int32_t width, int32_t height)
2177 float from_x = 0.0f;
2178 float from_y = 0.0f;
2181 struct shell_surface *shsurf = get_shell_surface(es);
2183 if ((width == 0) || (height == 0) || (shsurf == NULL)) {
2187 if (shsurf->width != width || shsurf->height != height) {
2189 shsurf->width = width;
2190 shsurf->height = height;
2192 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
2193 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
2195 es->geometry.x + to_x - from_x,
2196 es->geometry.y + to_y - from_y,
2199 commit_changes(shsurf->shell);
2203 static struct shell_surface *
2204 create_shell_surface(void *shell, struct weston_surface *surface,
2205 const struct weston_shell_client *client)
2207 struct shell_surface *shsurf;
2209 if (surface->configure) {
2210 weston_log("surface->configure already set\n");
2214 shsurf = calloc(1, sizeof *shsurf);
2215 if (shsurf == NULL) {
2216 weston_log("no memory to allocate shell surface\n");
2220 surface->configure = shell_surface_configure;
2221 surface->configure_private = shsurf;
2223 shsurf->shell = (struct ivishell *)shell;
2224 shsurf->surface = surface;
2225 shsurf->ping_timer = NULL;
2226 shsurf->title = strdup("");
2228 /* init link so its safe to always remove it in destroy_shell_surface */
2229 wl_list_init(&shsurf->link);
2231 shsurf->client = client;
2237 send_configure(struct weston_surface *surface,
2238 uint32_t edges, int32_t width, int32_t height)
2240 struct shell_surface *shsurf = get_shell_surface(surface);
2242 wl_shell_surface_send_configure(shsurf->resource,
2243 edges, width, height);
2246 static const struct weston_shell_client shell_client = {
2251 shell_destroy_shell_surface(struct wl_resource *resource)
2253 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2255 destroy_shell_surface(shsurf);
2259 shell_surface_pong(struct wl_client *client,
2260 struct wl_resource *resource, uint32_t serial)
2262 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2265 if (shsurf->ping_timer == NULL) {
2269 if (shsurf->ping_timer->serial == serial) {
2270 ping_timer_destroy(shsurf);
2275 shell_surface_move(struct wl_client *client, struct wl_resource *resource,
2276 struct wl_resource *seat_resource, uint32_t serial)
2280 (void)seat_resource;
2285 shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
2286 struct wl_resource *seat_resource, uint32_t serial,
2291 (void)seat_resource;
2297 shell_surface_set_toplevel(struct wl_client *client,
2298 struct wl_resource *resource)
2305 shell_surface_set_transient(struct wl_client *client,
2306 struct wl_resource *resource,
2307 struct wl_resource *parent_resource,
2308 int x, int y, uint32_t flags)
2312 (void)parent_resource;
2319 shell_surface_set_fullscreen(struct wl_client *client,
2320 struct wl_resource *resource,
2323 struct wl_resource *output_resource)
2329 (void)output_resource;
2333 shell_surface_set_popup(struct wl_client *client,
2334 struct wl_resource *resource,
2335 struct wl_resource *seat_resource,
2337 struct wl_resource *parent_resource,
2338 int32_t x, int32_t y, uint32_t flags)
2342 (void)seat_resource;
2344 (void)parent_resource;
2351 shell_surface_set_maximized(struct wl_client *client,
2352 struct wl_resource *resource,
2353 struct wl_resource *output_resource)
2357 (void)output_resource;
2361 shell_surface_set_title(struct wl_client *client,
2362 struct wl_resource *resource, const char *title)
2370 shell_surface_set_class(struct wl_client *client,
2371 struct wl_resource *resource, const char *class)
2373 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2376 free(shsurf->class);
2377 shsurf->class = strdup(class);
2380 static const struct wl_shell_surface_interface
2381 shell_surface_implementation = {
2384 shell_surface_resize,
2385 shell_surface_set_toplevel,
2386 shell_surface_set_transient,
2387 shell_surface_set_fullscreen,
2388 shell_surface_set_popup,
2389 shell_surface_set_maximized,
2390 shell_surface_set_title,
2391 shell_surface_set_class
2395 shell_weston_surface_destroy(struct wl_listener *listener, void *data)
2397 struct link_shell_weston_surface *lsurf =
2398 container_of(listener,
2399 struct link_shell_weston_surface,
2403 wl_list_remove(&lsurf->link);
2409 shell_get_shell_surface(struct wl_client *client,
2410 struct wl_resource *resource,
2412 struct wl_resource *surface_resource)
2414 struct weston_surface *surface =
2415 wl_resource_get_user_data(surface_resource);
2416 struct ivishell *shell = wl_resource_get_user_data(resource);
2417 struct shell_surface *shsurf;
2418 struct link_shell_weston_surface *lsurf;
2423 if (get_shell_surface(surface)) {
2424 wl_resource_post_error(surface_resource,
2425 WL_DISPLAY_ERROR_INVALID_OBJECT,
2426 "ivishell::get_shell_surface already requested");
2430 shsurf = create_shell_surface(shell, surface, &shell_client);
2432 wl_resource_post_error(surface_resource,
2433 WL_DISPLAY_ERROR_INVALID_OBJECT,
2434 "surface->configure already set");
2438 shsurf->resource = wl_resource_create(client,
2439 &wl_shell_surface_interface,
2441 wl_resource_set_implementation(shsurf->resource,
2442 &shell_surface_implementation,
2443 shsurf, shell_destroy_shell_surface);
2445 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
2446 wl_resource_add_destroy_listener(surface->resource,
2447 &shsurf->surface_destroy_listener);
2449 lsurf = (struct link_shell_weston_surface*)malloc(sizeof *lsurf);
2450 lsurf->surface = surface;
2451 wl_list_init(&lsurf->link);
2452 wl_list_insert(&shell->list_weston_surface, &lsurf->link);
2454 lsurf->destroy_listener.notify = shell_weston_surface_destroy;
2455 wl_resource_add_destroy_listener(surface->resource,
2456 &lsurf->destroy_listener);
2458 wl_client_get_credentials(client, &pid, &uid, &gid);
2462 static const struct wl_shell_interface shell_implementation = {
2463 shell_get_shell_surface
2467 bind_shell(struct wl_client *client, void *data,
2468 uint32_t version, uint32_t id)
2470 struct ivishell *shell = data;
2471 struct wl_resource *resource = NULL;
2474 resource = wl_resource_create(client, &wl_shell_interface, 1, id);
2475 wl_resource_set_implementation(resource,
2476 &shell_implementation,
2481 module_init(struct weston_compositor *ec,
2482 int *argc, char *argv[])
2484 struct weston_seat *seat;
2485 struct ivishell *shell;
2489 shell = malloc(sizeof *shell);
2493 memset(shell, 0, sizeof *shell);
2494 init_ivi_shell(ec, shell);
2496 shell->destroy_listener.notify = shell_destroy;
2497 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
2499 if (wl_global_create(ec->wl_display, &wl_shell_interface, 1,
2500 shell, bind_shell) == NULL) {
2504 if (wl_global_create(ec->wl_display, &ivi_application_interface, 1,
2505 shell, bind_ivi_application) == NULL)
2508 if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
2509 shell, bind_ivi_controller) == NULL)
2512 wl_list_for_each(seat, &ec->seat_list, link) {