blob: 6b2604e1f6c7719a30a99e20be9a6cebb54d4465 [file] [log] [blame]
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001/*
2 * Copyright (C) 2013 DENSO CORPORATION
3 *
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.
13 *
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.
21 */
22
23/**
24 * Implementation of ivi-layout library. The actual view on ivi_screen is
25 * not updated till calling ivi_layout_commit_changes. A overview from
26 * calling API for updating properties of ivi_surface/ivi_layer to asking
27 * compositor to compose them by using weston_compositor_schedule_repaint,
28 * 0/ initialize this library by ivi_layout_init_with_compositor
29 * with (struct weston_compositor *ec) from ivi-shell.
30 * 1/ When a API for updating properties of ivi_surface/ivi_layer, it updates
31 * pending prop of ivi_surface/ivi_layer/ivi_screen which are structure to
32 * store properties.
33 * 2/ Before calling commitChanges, in case of calling a API to get a property,
34 * return current property, not pending property.
35 * 3/ At the timing of calling ivi_layout_commitChanges, pending properties
36 * are applied to properties.
37 *
38 * *) ivi_layout_commitChanges is also called by transition animation
39 * per each frame. See ivi-layout-transition.c in details. Transition
40 * animation interpolates frames between previous properties of ivi_surface
41 * and new ones.
42 * For example, when a property of ivi_surface is changed from invisibility
43 * to visibility, it behaves like fade-in. When ivi_layout_commitChange is
44 * called during transition animation, it cancels the transition and
45 * re-start transition to new properties from current properties of final
46 * frame just before the the cancellation.
47 *
48 * 4/ According properties, set transformation by using weston_matrix and
49 * weston_view per ivi_surfaces and ivi_layers in while loop.
50 * 5/ Set damage and trigger transform by using weston_view_geometry_dirty.
51 * 6/ Notify update of properties.
52 * 7/ Trigger composition by weston_compositor_schedule_repaint.
53 *
54 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090055#include "config.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090056
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090057#include <string.h>
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090058
59#include "compositor.h"
60#include "ivi-layout-export.h"
61#include "ivi-layout-private.h"
62
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090063#include "../shared/os-compatibility.h"
64
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090065struct link_layer {
66 struct ivi_layout_layer *ivilayer;
67 struct wl_list link;
68 struct wl_list link_to_layer;
69};
70
71struct link_screen {
72 struct ivi_layout_screen *iviscrn;
73 struct wl_list link;
74 struct wl_list link_to_screen;
75};
76
77struct listener_layout_notification {
78 void *userdata;
79 struct wl_listener listener;
80};
81
82struct ivi_layout;
83
84struct ivi_layout_screen {
85 struct wl_list link;
86 struct wl_list link_to_layer;
87 uint32_t id_screen;
88
89 struct ivi_layout *layout;
90 struct weston_output *output;
91
92 uint32_t event_mask;
93
94 struct {
95 struct wl_list layer_list;
96 struct wl_list link;
97 } pending;
98
99 struct {
100 struct wl_list layer_list;
101 struct wl_list link;
102 } order;
103};
104
105struct ivi_layout_notification_callback {
106 void *callback;
107 void *data;
108};
109
110static struct ivi_layout ivilayout = {0};
111
112struct ivi_layout *
113get_instance(void)
114{
115 return &ivilayout;
116}
117
118/**
119 * Internal API to add/remove a link to ivi_surface from ivi_layer.
120 */
121static void
122add_link_to_surface(struct ivi_layout_layer *ivilayer,
123 struct link_layer *link_layer)
124{
125 struct link_layer *link = NULL;
126
127 wl_list_for_each(link, &ivilayer->link_to_surface, link_to_layer) {
128 if (link == link_layer)
129 return;
130 }
131
132 wl_list_insert(&ivilayer->link_to_surface, &link_layer->link_to_layer);
133}
134
135static void
136remove_link_to_surface(struct ivi_layout_layer *ivilayer)
137{
138 struct link_layer *link = NULL;
139 struct link_layer *next = NULL;
140
141 wl_list_for_each_safe(link, next, &ivilayer->link_to_surface, link_to_layer) {
142 if (!wl_list_empty(&link->link_to_layer)) {
143 wl_list_remove(&link->link_to_layer);
144 }
145 if (!wl_list_empty(&link->link)) {
146 wl_list_remove(&link->link);
147 }
148 free(link);
149 }
150
151 wl_list_init(&ivilayer->link_to_surface);
152}
153
154/**
155 * Internal API to add a link to ivi_layer from ivi_screen.
156 */
157static void
158add_link_to_layer(struct ivi_layout_screen *iviscrn,
159 struct link_screen *link_screen)
160{
161 wl_list_init(&link_screen->link_to_screen);
162 wl_list_insert(&iviscrn->link_to_layer, &link_screen->link_to_screen);
163}
164
165/**
166 * Internal API to add/remove a ivi_surface from ivi_layer.
167 */
168static void
169add_ordersurface_to_layer(struct ivi_layout_surface *ivisurf,
170 struct ivi_layout_layer *ivilayer)
171{
172 struct link_layer *link_layer = NULL;
173
174 link_layer = malloc(sizeof *link_layer);
175 if (link_layer == NULL) {
176 weston_log("fails to allocate memory\n");
177 return;
178 }
179
180 link_layer->ivilayer = ivilayer;
181 wl_list_init(&link_layer->link);
182 wl_list_insert(&ivisurf->layer_list, &link_layer->link);
183 add_link_to_surface(ivilayer, link_layer);
184}
185
186static void
187remove_ordersurface_from_layer(struct ivi_layout_surface *ivisurf)
188{
189 struct link_layer *link_layer = NULL;
190 struct link_layer *next = NULL;
191
192 wl_list_for_each_safe(link_layer, next, &ivisurf->layer_list, link) {
193 if (!wl_list_empty(&link_layer->link)) {
194 wl_list_remove(&link_layer->link);
195 }
196 if (!wl_list_empty(&link_layer->link_to_layer)) {
197 wl_list_remove(&link_layer->link_to_layer);
198 }
199 free(link_layer);
200 }
201 wl_list_init(&ivisurf->layer_list);
202}
203
204/**
205 * Internal API to add/remove a ivi_layer to/from ivi_screen.
206 */
207static void
208add_orderlayer_to_screen(struct ivi_layout_layer *ivilayer,
209 struct ivi_layout_screen *iviscrn)
210{
211 struct link_screen *link_scrn = NULL;
212
213 link_scrn = malloc(sizeof *link_scrn);
214 if (link_scrn == NULL) {
215 weston_log("fails to allocate memory\n");
216 return;
217 }
218
219 link_scrn->iviscrn = iviscrn;
220 wl_list_init(&link_scrn->link);
221 wl_list_insert(&ivilayer->screen_list, &link_scrn->link);
222 add_link_to_layer(iviscrn, link_scrn);
223}
224
225static void
226remove_orderlayer_from_screen(struct ivi_layout_layer *ivilayer)
227{
228 struct link_screen *link_scrn = NULL;
229 struct link_screen *next = NULL;
230
231 wl_list_for_each_safe(link_scrn, next, &ivilayer->screen_list, link) {
232 if (!wl_list_empty(&link_scrn->link)) {
233 wl_list_remove(&link_scrn->link);
234 }
235 if (!wl_list_empty(&link_scrn->link_to_screen)) {
236 wl_list_remove(&link_scrn->link_to_screen);
237 }
238 free(link_scrn);
239 }
240 wl_list_init(&ivilayer->screen_list);
241}
242
243/**
244 * Internal API to add/remove a ivi_layer to/from ivi_screen.
245 */
246static struct ivi_layout_surface *
247get_surface(struct wl_list *surf_list, uint32_t id_surface)
248{
249 struct ivi_layout_surface *ivisurf;
250
251 wl_list_for_each(ivisurf, surf_list, link) {
252 if (ivisurf->id_surface == id_surface) {
253 return ivisurf;
254 }
255 }
256
257 return NULL;
258}
259
260static struct ivi_layout_layer *
261get_layer(struct wl_list *layer_list, uint32_t id_layer)
262{
263 struct ivi_layout_layer *ivilayer;
264
265 wl_list_for_each(ivilayer, layer_list, link) {
266 if (ivilayer->id_layer == id_layer) {
267 return ivilayer;
268 }
269 }
270
271 return NULL;
272}
273
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900274static void
275remove_configured_listener(struct ivi_layout_surface *ivisurf)
276{
277 struct wl_listener *link = NULL;
278 struct wl_listener *next = NULL;
279
280 wl_list_for_each_safe(link, next, &ivisurf->configured.listener_list, link) {
281 wl_list_remove(&link->link);
282 }
283}
284
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900285static void
286remove_all_notification(struct wl_list *listener_list)
287{
288 struct wl_listener *listener = NULL;
289 struct wl_listener *next = NULL;
290
291 wl_list_for_each_safe(listener, next, listener_list, link) {
292 struct listener_layout_notification *notification = NULL;
293 if (!wl_list_empty(&listener->link)) {
294 wl_list_remove(&listener->link);
295 }
296
297 notification =
298 container_of(listener,
299 struct listener_layout_notification,
300 listener);
301
302 free(notification->userdata);
303 free(notification);
304 }
305}
306
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900307static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900308ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
309{
310 if (ivisurf == NULL) {
311 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
312 return;
313 }
314
315 remove_all_notification(&ivisurf->property_changed.listener_list);
316}
317
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900318/**
319 * this shall not be called from controller because this is triggered by ivi_surface.destroy
320 * This means that this is called from westonsurface_destroy_from_ivisurface.
321 */
322static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900323ivi_layout_surface_remove(struct ivi_layout_surface *ivisurf)
324{
325 struct ivi_layout *layout = get_instance();
326
327 if (ivisurf == NULL) {
328 weston_log("ivi_layout_surface_remove: invalid argument\n");
329 return;
330 }
331
332 if (!wl_list_empty(&ivisurf->pending.link)) {
333 wl_list_remove(&ivisurf->pending.link);
334 }
335 if (!wl_list_empty(&ivisurf->order.link)) {
336 wl_list_remove(&ivisurf->order.link);
337 }
338 if (!wl_list_empty(&ivisurf->link)) {
339 wl_list_remove(&ivisurf->link);
340 }
341 remove_ordersurface_from_layer(ivisurf);
342
343 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
344
345 remove_configured_listener(ivisurf);
346
347 ivi_layout_surface_remove_notification(ivisurf);
348
349 free(ivisurf);
350}
351
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900352/**
353 * Called at destruction of ivi_surface
354 */
355static void
356westonsurface_destroy_from_ivisurface(struct wl_listener *listener, void *data)
357{
358 struct ivi_layout_surface *ivisurf = NULL;
359
360 ivisurf = container_of(listener, struct ivi_layout_surface,
361 surface_destroy_listener);
362
363 wl_list_remove(&ivisurf->surface_rotation.link);
364 wl_list_remove(&ivisurf->layer_rotation.link);
365 wl_list_remove(&ivisurf->surface_pos.link);
366 wl_list_remove(&ivisurf->layer_pos.link);
367 wl_list_remove(&ivisurf->scaling.link);
368
369 ivisurf->surface = NULL;
370 ivi_layout_surface_remove(ivisurf);
371}
372
373/**
374 * Internal API to check ivi_layer/ivi_surface already added in ivi_layer/ivi_screen.
375 * Called by ivi_layout_layer_add_surface/ivi_layout_screenAddLayer
376 */
377static int
378is_surface_in_layer(struct ivi_layout_surface *ivisurf,
379 struct ivi_layout_layer *ivilayer)
380{
381 struct ivi_layout_surface *surf = NULL;
382
383 wl_list_for_each(surf, &ivilayer->pending.surface_list, pending.link) {
384 if (surf->id_surface == ivisurf->id_surface) {
385 return 1;
386 }
387 }
388
389 return 0;
390}
391
392static int
393is_layer_in_screen(struct ivi_layout_layer *ivilayer,
394 struct ivi_layout_screen *iviscrn)
395{
396 struct ivi_layout_layer *layer = NULL;
397
398 wl_list_for_each(layer, &iviscrn->pending.layer_list, pending.link) {
399 if (layer->id_layer == ivilayer->id_layer) {
400 return 1;
401 }
402 }
403
404 return 0;
405}
406
407/**
408 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
409 * Called by ivi_layout_init_with_compositor.
410 */
411static void
412create_screen(struct weston_compositor *ec)
413{
414 struct ivi_layout *layout = get_instance();
415 struct ivi_layout_screen *iviscrn = NULL;
416 struct weston_output *output = NULL;
417 int32_t count = 0;
418
419 wl_list_for_each(output, &ec->output_list, link) {
420 iviscrn = calloc(1, sizeof *iviscrn);
421 if (iviscrn == NULL) {
422 weston_log("fails to allocate memory\n");
423 continue;
424 }
425
426 wl_list_init(&iviscrn->link);
427 iviscrn->layout = layout;
428
429 iviscrn->id_screen = count;
430 count++;
431
432 iviscrn->output = output;
433 iviscrn->event_mask = 0;
434
435 wl_list_init(&iviscrn->pending.layer_list);
436 wl_list_init(&iviscrn->pending.link);
437
438 wl_list_init(&iviscrn->order.layer_list);
439 wl_list_init(&iviscrn->order.link);
440
441 wl_list_init(&iviscrn->link_to_layer);
442
443 wl_list_insert(&layout->screen_list, &iviscrn->link);
444 }
445}
446
447/**
448 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
449 */
450static void
451init_layer_properties(struct ivi_layout_layer_properties *prop,
452 int32_t width, int32_t height)
453{
454 memset(prop, 0, sizeof *prop);
455 prop->opacity = wl_fixed_from_double(1.0);
456 prop->source_width = width;
457 prop->source_height = height;
458 prop->dest_width = width;
459 prop->dest_height = height;
460}
461
462static void
463init_surface_properties(struct ivi_layout_surface_properties *prop)
464{
465 memset(prop, 0, sizeof *prop);
466 prop->opacity = wl_fixed_from_double(1.0);
467}
468
469/**
470 * Internal APIs to be called from ivi_layout_commit_changes.
471 */
472static void
473update_opacity(struct ivi_layout_layer *ivilayer,
474 struct ivi_layout_surface *ivisurf)
475{
476 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
477 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
478
479 if ((ivilayer->event_mask & IVI_NOTIFICATION_OPACITY) ||
480 (ivisurf->event_mask & IVI_NOTIFICATION_OPACITY)) {
481 struct weston_view *tmpview = NULL;
482 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
483 if (tmpview == NULL) {
484 continue;
485 }
486 tmpview->alpha = layer_alpha * surf_alpha;
487 }
488 }
489}
490
491static void
492update_surface_orientation(struct ivi_layout_layer *ivilayer,
493 struct ivi_layout_surface *ivisurf)
494{
495 struct weston_view *view;
496 struct weston_matrix *matrix = &ivisurf->surface_rotation.matrix;
497 float width = 0.0f;
498 float height = 0.0f;
499 float v_sin = 0.0f;
500 float v_cos = 0.0f;
501 float cx = 0.0f;
502 float cy = 0.0f;
503 float sx = 1.0f;
504 float sy = 1.0f;
505
506 wl_list_for_each(view, &ivisurf->surface->views, surface_link) {
507 if (view != NULL) {
508 break;
509 }
510 }
511
512 if (view == NULL) {
513 return;
514 }
515
516 if ((ivilayer->prop.dest_width == 0) ||
517 (ivilayer->prop.dest_height == 0)) {
518 return;
519 }
520 width = (float)ivilayer->prop.dest_width;
521 height = (float)ivilayer->prop.dest_height;
522
523 switch (ivisurf->prop.orientation) {
524 case WL_OUTPUT_TRANSFORM_NORMAL:
525 v_sin = 0.0f;
526 v_cos = 1.0f;
527 break;
528 case WL_OUTPUT_TRANSFORM_90:
529 v_sin = 1.0f;
530 v_cos = 0.0f;
531 sx = width / height;
532 sy = height / width;
533 break;
534 case WL_OUTPUT_TRANSFORM_180:
535 v_sin = 0.0f;
536 v_cos = -1.0f;
537 break;
538 case WL_OUTPUT_TRANSFORM_270:
539 default:
540 v_sin = -1.0f;
541 v_cos = 0.0f;
542 sx = width / height;
543 sy = height / width;
544 break;
545 }
546 wl_list_remove(&ivisurf->surface_rotation.link);
547 weston_view_geometry_dirty(view);
548
549 weston_matrix_init(matrix);
550 cx = 0.5f * width;
551 cy = 0.5f * height;
552 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
553 weston_matrix_rotate_xy(matrix, v_cos, v_sin);
554 weston_matrix_scale(matrix, sx, sy, 1.0);
555 weston_matrix_translate(matrix, cx, cy, 0.0f);
556 wl_list_insert(&view->geometry.transformation_list,
557 &ivisurf->surface_rotation.link);
558
559 weston_view_set_transform_parent(view, NULL);
560 weston_view_update_transform(view);
561}
562
563static void
564update_layer_orientation(struct ivi_layout_layer *ivilayer,
565 struct ivi_layout_surface *ivisurf)
566{
567 struct weston_surface *es = ivisurf->surface;
568 struct weston_view *view;
569 struct weston_matrix *matrix = &ivisurf->layer_rotation.matrix;
570 struct weston_output *output = NULL;
571 float width = 0.0f;
572 float height = 0.0f;
573 float v_sin = 0.0f;
574 float v_cos = 0.0f;
575 float cx = 0.0f;
576 float cy = 0.0f;
577 float sx = 1.0f;
578 float sy = 1.0f;
579
580 wl_list_for_each(view, &ivisurf->surface->views, surface_link) {
581 if (view != NULL) {
582 break;
583 }
584 }
585
586 if (es == NULL || view == NULL) {
587 return;
588 }
589
590 output = es->output;
591 if (output == NULL) {
592 return;
593 }
594 if ((output->width == 0) || (output->height == 0)) {
595 return;
596 }
597 width = (float)output->width;
598 height = (float)output->height;
599
600 switch (ivilayer->prop.orientation) {
601 case WL_OUTPUT_TRANSFORM_NORMAL:
602 v_sin = 0.0f;
603 v_cos = 1.0f;
604 break;
605 case WL_OUTPUT_TRANSFORM_90:
606 v_sin = 1.0f;
607 v_cos = 0.0f;
608 sx = width / height;
609 sy = height / width;
610 break;
611 case WL_OUTPUT_TRANSFORM_180:
612 v_sin = 0.0f;
613 v_cos = -1.0f;
614 break;
615 case WL_OUTPUT_TRANSFORM_270:
616 default:
617 v_sin = -1.0f;
618 v_cos = 0.0f;
619 sx = width / height;
620 sy = height / width;
621 break;
622 }
623 wl_list_remove(&ivisurf->layer_rotation.link);
624 weston_view_geometry_dirty(view);
625
626 weston_matrix_init(matrix);
627 cx = 0.5f * width;
628 cy = 0.5f * height;
629 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
630 weston_matrix_rotate_xy(matrix, v_cos, v_sin);
631 weston_matrix_scale(matrix, sx, sy, 1.0);
632 weston_matrix_translate(matrix, cx, cy, 0.0f);
633 wl_list_insert(&view->geometry.transformation_list,
634 &ivisurf->layer_rotation.link);
635
636 weston_view_set_transform_parent(view, NULL);
637 weston_view_update_transform(view);
638}
639
640static void
641update_surface_position(struct ivi_layout_surface *ivisurf)
642{
643 struct weston_view *view;
644 float tx = (float)ivisurf->prop.dest_x;
645 float ty = (float)ivisurf->prop.dest_y;
646 struct weston_matrix *matrix = &ivisurf->surface_pos.matrix;
647
648 wl_list_for_each(view, &ivisurf->surface->views, surface_link) {
649 if (view != NULL) {
650 break;
651 }
652 }
653
654 if (view == NULL) {
655 return;
656 }
657
658 wl_list_remove(&ivisurf->surface_pos.link);
659
660 weston_matrix_init(matrix);
661 weston_matrix_translate(matrix, tx, ty, 0.0f);
662 wl_list_insert(&view->geometry.transformation_list,
663 &ivisurf->surface_pos.link);
664
665 weston_view_set_transform_parent(view, NULL);
666 weston_view_update_transform(view);
667}
668
669static void
670update_layer_position(struct ivi_layout_layer *ivilayer,
671 struct ivi_layout_surface *ivisurf)
672{
673 struct weston_view *view;
674 struct weston_matrix *matrix = &ivisurf->layer_pos.matrix;
675 float tx = (float)ivilayer->prop.dest_x;
676 float ty = (float)ivilayer->prop.dest_y;
677
678 wl_list_for_each(view, &ivisurf->surface->views, surface_link) {
679 if (view != NULL) {
680 break;
681 }
682 }
683
684 if (view == NULL) {
685 return;
686 }
687
688 wl_list_remove(&ivisurf->layer_pos.link);
689
690 weston_matrix_init(matrix);
691 weston_matrix_translate(matrix, tx, ty, 0.0f);
692 wl_list_insert(&view->geometry.transformation_list,
693 &ivisurf->layer_pos.link);
694
695 weston_view_set_transform_parent(view, NULL);
696 weston_view_update_transform(view);
697}
698
699static void
700update_scale(struct ivi_layout_layer *ivilayer,
701 struct ivi_layout_surface *ivisurf)
702{
703 struct weston_view *view;
704 struct weston_matrix *matrix = &ivisurf->scaling.matrix;
705 float sx = 0.0f;
706 float sy = 0.0f;
707 float lw = 0.0f;
708 float sw = 0.0f;
709 float lh = 0.0f;
710 float sh = 0.0f;
711
712 wl_list_for_each(view, &ivisurf->surface->views, surface_link) {
713 if (view != NULL) {
714 break;
715 }
716 }
717
718 if (view == NULL) {
719 return;
720 }
721
722 if (ivisurf->prop.dest_width == 0 && ivisurf->prop.dest_height == 0) {
723 ivisurf->prop.dest_width = ivisurf->surface->width_from_buffer;
724 ivisurf->prop.dest_height = ivisurf->surface->height_from_buffer;
725 }
726
727 lw = ((float)ivilayer->prop.dest_width / (float)ivilayer->prop.source_width );
728 sw = ((float)ivisurf->prop.dest_width / (float)ivisurf->prop.source_width );
729 lh = ((float)ivilayer->prop.dest_height / (float)ivilayer->prop.source_height);
730 sh = ((float)ivisurf->prop.dest_height / (float)ivisurf->prop.source_height );
731 sx = sw * lw;
732 sy = sh * lh;
733
734 wl_list_remove(&ivisurf->scaling.link);
735 weston_matrix_init(matrix);
736 weston_matrix_scale(matrix, sx, sy, 1.0f);
737
738 wl_list_insert(&view->geometry.transformation_list,
739 &ivisurf->scaling.link);
740
741 weston_view_set_transform_parent(view, NULL);
742 weston_view_update_transform(view);
743}
744
745static void
746update_prop(struct ivi_layout_layer *ivilayer,
747 struct ivi_layout_surface *ivisurf)
748{
749 if (ivilayer->event_mask | ivisurf->event_mask) {
750 struct weston_view *tmpview;
751 update_opacity(ivilayer, ivisurf);
752 update_layer_orientation(ivilayer, ivisurf);
753 update_layer_position(ivilayer, ivisurf);
754 update_surface_position(ivisurf);
755 update_surface_orientation(ivilayer, ivisurf);
756 update_scale(ivilayer, ivisurf);
757
758 ivisurf->update_count++;
759
760 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
761 if (tmpview != NULL) {
762 break;
763 }
764 }
765
766 if (tmpview != NULL) {
767 weston_view_geometry_dirty(tmpview);
768 }
769
770 if (ivisurf->surface != NULL) {
771 weston_surface_damage(ivisurf->surface);
772 }
773 }
774}
775
776static void
777commit_changes(struct ivi_layout *layout)
778{
779 struct ivi_layout_screen *iviscrn = NULL;
780 struct ivi_layout_layer *ivilayer = NULL;
781 struct ivi_layout_surface *ivisurf = NULL;
782
783 wl_list_for_each(iviscrn, &layout->screen_list, link) {
784 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
785 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
786 update_prop(ivilayer, ivisurf);
787 }
788 }
789 }
790}
791
792static void
793commit_surface_list(struct ivi_layout *layout)
794{
795 struct ivi_layout_surface *ivisurf = NULL;
796 int32_t dest_x = 0;
797 int32_t dest_y = 0;
798 int32_t dest_width = 0;
799 int32_t dest_height = 0;
800 int32_t configured = 0;
801
802 wl_list_for_each(ivisurf, &layout->surface_list, link) {
803 if(ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
804 dest_x = ivisurf->prop.dest_x;
805 dest_y = ivisurf->prop.dest_y;
806 dest_width = ivisurf->prop.dest_width;
807 dest_height = ivisurf->prop.dest_height;
808
809 ivi_layout_transition_move_resize_view(ivisurf,
810 ivisurf->pending.prop.dest_x,
811 ivisurf->pending.prop.dest_y,
812 ivisurf->pending.prop.dest_width,
813 ivisurf->pending.prop.dest_height,
814 ivisurf->pending.prop.transition_duration);
815
816 if(ivisurf->pending.prop.visibility) {
817 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
818 } else {
819 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
820 }
821
822 ivisurf->prop = ivisurf->pending.prop;
823 ivisurf->prop.dest_x = dest_x;
824 ivisurf->prop.dest_y = dest_y;
825 ivisurf->prop.dest_width = dest_width;
826 ivisurf->prop.dest_height = dest_height;
827 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
828 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
829
830 } else if(ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY){
831 dest_x = ivisurf->prop.dest_x;
832 dest_y = ivisurf->prop.dest_y;
833 dest_width = ivisurf->prop.dest_width;
834 dest_height = ivisurf->prop.dest_height;
835
836 ivi_layout_transition_move_resize_view(ivisurf,
837 ivisurf->pending.prop.dest_x,
838 ivisurf->pending.prop.dest_y,
839 ivisurf->pending.prop.dest_width,
840 ivisurf->pending.prop.dest_height,
841 ivisurf->pending.prop.transition_duration);
842
843 ivisurf->prop = ivisurf->pending.prop;
844 ivisurf->prop.dest_x = dest_x;
845 ivisurf->prop.dest_y = dest_y;
846 ivisurf->prop.dest_width = dest_width;
847 ivisurf->prop.dest_height = dest_height;
848
849 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
850 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
851
852 } else if(ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY){
853 configured = 0;
854 if(ivisurf->pending.prop.visibility) {
855 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
856 } else {
857 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
858 }
859
860 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
861 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
862 configured = 1;
863 }
864
865 ivisurf->prop = ivisurf->pending.prop;
866 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
867 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
868
869 if (configured && !is_surface_transition(ivisurf))
870 wl_signal_emit(&ivisurf->configured, ivisurf);
871 } else {
872 configured = 0;
873 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
874 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
875 configured = 1;
876 }
877
878 ivisurf->prop = ivisurf->pending.prop;
879 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
880 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
881
882 if (configured && !is_surface_transition(ivisurf))
883 wl_signal_emit(&ivisurf->configured, ivisurf);
884 }
885 }
886}
887
888static void
889commit_layer_list(struct ivi_layout *layout)
890{
891 struct ivi_layout_layer *ivilayer = NULL;
892 struct ivi_layout_surface *ivisurf = NULL;
893 struct ivi_layout_surface *next = NULL;
894
895 wl_list_for_each(ivilayer, &layout->layer_list, link) {
896 if(ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
897 ivi_layout_transition_move_layer(ivilayer, ivilayer->pending.prop.dest_x, ivilayer->pending.prop.dest_y, ivilayer->pending.prop.transition_duration);
898 } else if(ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
899 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
900 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
901 NULL, NULL,
902 ivilayer->pending.prop.transition_duration);
903 }
904 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
905
906 ivilayer->prop = ivilayer->pending.prop;
907
908 if (!(ivilayer->event_mask &
909 (IVI_NOTIFICATION_ADD | IVI_NOTIFICATION_REMOVE)) ) {
910 continue;
911 }
912
913 if (ivilayer->event_mask & IVI_NOTIFICATION_REMOVE) {
914 wl_list_for_each_safe(ivisurf, next,
915 &ivilayer->order.surface_list, order.link) {
916 remove_ordersurface_from_layer(ivisurf);
917
918 if (!wl_list_empty(&ivisurf->order.link)) {
919 wl_list_remove(&ivisurf->order.link);
920 }
921
922 wl_list_init(&ivisurf->order.link);
923 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
924 }
925
926 wl_list_init(&ivilayer->order.surface_list);
927 }
928
929 if (ivilayer->event_mask & IVI_NOTIFICATION_ADD) {
930 wl_list_for_each_safe(ivisurf, next,
931 &ivilayer->order.surface_list, order.link) {
932 remove_ordersurface_from_layer(ivisurf);
933
934 if (!wl_list_empty(&ivisurf->order.link)) {
935 wl_list_remove(&ivisurf->order.link);
936 }
937
938 wl_list_init(&ivisurf->order.link);
939 }
940
941 wl_list_init(&ivilayer->order.surface_list);
942 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
943 pending.link) {
944 if(!wl_list_empty(&ivisurf->order.link)){
945 wl_list_remove(&ivisurf->order.link);
946 wl_list_init(&ivisurf->order.link);
947 }
948
949 wl_list_insert(&ivilayer->order.surface_list,
950 &ivisurf->order.link);
951 add_ordersurface_to_layer(ivisurf, ivilayer);
952 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
953 }
954 }
955 }
956}
957
958static void
959commit_screen_list(struct ivi_layout *layout)
960{
961 struct ivi_layout_screen *iviscrn = NULL;
962 struct ivi_layout_layer *ivilayer = NULL;
963 struct ivi_layout_layer *next = NULL;
964 struct ivi_layout_surface *ivisurf = NULL;
965
966 wl_list_for_each(iviscrn, &layout->screen_list, link) {
967 if (iviscrn->event_mask & IVI_NOTIFICATION_REMOVE) {
968 wl_list_for_each_safe(ivilayer, next,
969 &iviscrn->order.layer_list, order.link) {
970 remove_orderlayer_from_screen(ivilayer);
971
972 if (!wl_list_empty(&ivilayer->order.link)) {
973 wl_list_remove(&ivilayer->order.link);
974 }
975
976 wl_list_init(&ivilayer->order.link);
977 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
978 }
979 }
980
981 if (iviscrn->event_mask & IVI_NOTIFICATION_ADD) {
982 wl_list_for_each_safe(ivilayer, next,
983 &iviscrn->order.layer_list, order.link) {
984 remove_orderlayer_from_screen(ivilayer);
985
986 if (!wl_list_empty(&ivilayer->order.link)) {
987 wl_list_remove(&ivilayer->order.link);
988 }
989
990 wl_list_init(&ivilayer->order.link);
991 }
992
993 wl_list_init(&iviscrn->order.layer_list);
994 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
995 pending.link) {
996 wl_list_insert(&iviscrn->order.layer_list,
997 &ivilayer->order.link);
998 add_orderlayer_to_screen(ivilayer, iviscrn);
999 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
1000 }
1001 }
1002
1003 iviscrn->event_mask = 0;
1004
1005 /* Clear view list of layout ivi_layer */
1006 wl_list_init(&layout->layout_layer.view_list.link);
1007
1008 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
1009 if (ivilayer->prop.visibility == false)
1010 continue;
1011
1012 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1013 struct weston_view *tmpview = NULL;
1014 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
1015 if (tmpview != NULL) {
1016 break;
1017 }
1018 }
1019
1020 if (ivisurf->prop.visibility == false)
1021 continue;
1022 if (ivisurf->surface == NULL || tmpview == NULL)
1023 continue;
1024
1025 weston_layer_entry_insert(&layout->layout_layer.view_list,
1026 &tmpview->layer_link);
1027
1028 ivisurf->surface->output = iviscrn->output;
1029 }
1030 }
1031
1032 break;
1033 }
1034}
1035
1036static void
1037commit_transition(struct ivi_layout* layout)
1038{
1039 if(wl_list_empty(&layout->pending_transition_list)){
1040 return;
1041 }
1042
1043 wl_list_insert_list(&layout->transitions->transition_list,
1044 &layout->pending_transition_list);
1045
1046 wl_list_init(&layout->pending_transition_list);
1047
1048 wl_event_source_timer_update(layout->transitions->event_source, 1);
1049}
1050
1051static void
1052send_surface_prop(struct ivi_layout_surface *ivisurf)
1053{
1054 wl_signal_emit(&ivisurf->property_changed, ivisurf);
1055 ivisurf->event_mask = 0;
1056}
1057
1058static void
1059send_layer_prop(struct ivi_layout_layer *ivilayer)
1060{
1061 wl_signal_emit(&ivilayer->property_changed, ivilayer);
1062 ivilayer->event_mask = 0;
1063}
1064
1065static void
1066send_prop(struct ivi_layout *layout)
1067{
1068 struct ivi_layout_layer *ivilayer = NULL;
1069 struct ivi_layout_surface *ivisurf = NULL;
1070
1071 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
1072 send_layer_prop(ivilayer);
1073 }
1074
1075 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
1076 send_surface_prop(ivisurf);
1077 }
1078}
1079
1080static void
1081clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
1082{
1083 struct ivi_layout_surface *surface_link = NULL;
1084 struct ivi_layout_surface *surface_next = NULL;
1085
1086 wl_list_for_each_safe(surface_link, surface_next,
1087 &ivilayer->pending.surface_list, pending.link) {
1088 if (!wl_list_empty(&surface_link->pending.link)) {
1089 wl_list_remove(&surface_link->pending.link);
1090 }
1091
1092 wl_list_init(&surface_link->pending.link);
1093 }
1094
1095 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
1096}
1097
1098static void
1099clear_surface_order_list(struct ivi_layout_layer *ivilayer)
1100{
1101 struct ivi_layout_surface *surface_link = NULL;
1102 struct ivi_layout_surface *surface_next = NULL;
1103
1104 wl_list_for_each_safe(surface_link, surface_next,
1105 &ivilayer->order.surface_list, order.link) {
1106 if (!wl_list_empty(&surface_link->order.link)) {
1107 wl_list_remove(&surface_link->order.link);
1108 }
1109
1110 wl_list_init(&surface_link->order.link);
1111 }
1112
1113 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
1114}
1115
1116static void
1117layer_created(struct wl_listener *listener, void *data)
1118{
1119 struct ivi_layout_layer *ivilayer = data;
1120
1121 struct listener_layout_notification *notification =
1122 container_of(listener,
1123 struct listener_layout_notification,
1124 listener);
1125
1126 struct ivi_layout_notification_callback *created_callback =
1127 notification->userdata;
1128
1129 ((layer_create_notification_func)created_callback->callback)
1130 (ivilayer, created_callback->data);
1131}
1132
1133static void
1134layer_removed(struct wl_listener *listener, void *data)
1135{
1136 struct ivi_layout_layer *ivilayer = data;
1137
1138 struct listener_layout_notification *notification =
1139 container_of(listener,
1140 struct listener_layout_notification,
1141 listener);
1142
1143 struct ivi_layout_notification_callback *removed_callback =
1144 notification->userdata;
1145
1146 ((layer_remove_notification_func)removed_callback->callback)
1147 (ivilayer, removed_callback->data);
1148}
1149
1150static void
1151layer_prop_changed(struct wl_listener *listener, void *data)
1152{
1153 struct ivi_layout_layer *ivilayer = data;
1154
1155 struct listener_layout_notification *layout_listener =
1156 container_of(listener,
1157 struct listener_layout_notification,
1158 listener);
1159
1160 struct ivi_layout_notification_callback *prop_callback =
1161 layout_listener->userdata;
1162
1163 ((layer_property_notification_func)prop_callback->callback)
1164 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1165}
1166
1167static void
1168surface_created(struct wl_listener *listener, void *data)
1169{
1170 struct ivi_layout_surface *ivisurface = data;
1171
1172 struct listener_layout_notification *notification =
1173 container_of(listener,
1174 struct listener_layout_notification,
1175 listener);
1176
1177 struct ivi_layout_notification_callback *created_callback =
1178 notification->userdata;
1179
1180 ((surface_create_notification_func)created_callback->callback)
1181 (ivisurface, created_callback->data);
1182}
1183
1184static void
1185surface_removed(struct wl_listener *listener, void *data)
1186{
1187 struct ivi_layout_surface *ivisurface = data;
1188
1189 struct listener_layout_notification *notification =
1190 container_of(listener,
1191 struct listener_layout_notification,
1192 listener);
1193
1194 struct ivi_layout_notification_callback *removed_callback =
1195 notification->userdata;
1196
1197 ((surface_remove_notification_func)removed_callback->callback)
1198 (ivisurface, removed_callback->data);
1199}
1200
1201static void
1202surface_prop_changed(struct wl_listener *listener, void *data)
1203{
1204 struct ivi_layout_surface *ivisurf = data;
1205
1206 struct listener_layout_notification *layout_listener =
1207 container_of(listener,
1208 struct listener_layout_notification,
1209 listener);
1210
1211 struct ivi_layout_notification_callback *prop_callback =
1212 layout_listener->userdata;
1213
1214 ((surface_property_notification_func)prop_callback->callback)
1215 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1216
1217 ivisurf->event_mask = 0;
1218}
1219
1220static void
1221surface_configure_changed(struct wl_listener *listener,
1222 void *data)
1223{
1224 struct ivi_layout_surface *ivisurface = data;
1225
1226 struct listener_layout_notification *notification =
1227 container_of(listener,
1228 struct listener_layout_notification,
1229 listener);
1230
1231 struct ivi_layout_notification_callback *configure_changed_callback =
1232 notification->userdata;
1233
1234 ((surface_configure_notification_func)configure_changed_callback->callback)
1235 (ivisurface, configure_changed_callback->data);
1236}
1237
1238static int32_t
1239add_notification(struct wl_signal *signal,
1240 wl_notify_func_t callback,
1241 void *userdata)
1242{
1243 struct listener_layout_notification *notification = NULL;
1244
1245 notification = malloc(sizeof *notification);
1246 if (notification == NULL) {
1247 weston_log("fails to allocate memory\n");
1248 free(userdata);
1249 return IVI_FAILED;
1250 }
1251
1252 notification->listener.notify = callback;
1253 notification->userdata = userdata;
1254
1255 wl_signal_add(signal, &notification->listener);
1256
1257 return IVI_SUCCEEDED;
1258}
1259
1260static void
1261remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1262{
1263 struct wl_listener *listener = NULL;
1264 struct wl_listener *next = NULL;
1265
1266 wl_list_for_each_safe(listener, next, listener_list, link) {
1267 struct listener_layout_notification *notification =
1268 container_of(listener,
1269 struct listener_layout_notification,
1270 listener);
1271
1272 struct ivi_layout_notification_callback *notification_callback =
1273 notification->userdata;
1274
1275 if ((notification_callback->callback != callback) ||
1276 (notification_callback->data != userdata)) {
1277 continue;
1278 }
1279
1280 if (!wl_list_empty(&listener->link)) {
1281 wl_list_remove(&listener->link);
1282 }
1283
1284 free(notification->userdata);
1285 free(notification);
1286 }
1287}
1288
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001289/**
1290 * Exported APIs of ivi-layout library are implemented from here.
1291 * Brief of APIs is described in ivi-layout-export.h.
1292 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001293static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001294ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1295 void *userdata)
1296{
1297 struct ivi_layout *layout = get_instance();
1298 struct ivi_layout_notification_callback *created_callback = NULL;
1299
1300 if (callback == NULL) {
1301 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1302 return IVI_FAILED;
1303 }
1304
1305 created_callback = malloc(sizeof *created_callback);
1306 if (created_callback == NULL) {
1307 weston_log("fails to allocate memory\n");
1308 return IVI_FAILED;
1309 }
1310
1311 created_callback->callback = callback;
1312 created_callback->data = userdata;
1313
1314 return add_notification(&layout->layer_notification.created,
1315 layer_created,
1316 created_callback);
1317}
1318
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001319static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001320ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1321 void *userdata)
1322{
1323 struct ivi_layout *layout = get_instance();
1324 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1325}
1326
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001327static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001328ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1329 void *userdata)
1330{
1331 struct ivi_layout *layout = get_instance();
1332 struct ivi_layout_notification_callback *removed_callback = NULL;
1333
1334 if (callback == NULL) {
1335 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1336 return IVI_FAILED;
1337 }
1338
1339 removed_callback = malloc(sizeof *removed_callback);
1340 if (removed_callback == NULL) {
1341 weston_log("fails to allocate memory\n");
1342 return IVI_FAILED;
1343 }
1344
1345 removed_callback->callback = callback;
1346 removed_callback->data = userdata;
1347 return add_notification(&layout->layer_notification.removed,
1348 layer_removed,
1349 removed_callback);
1350}
1351
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001352static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001353ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1354 void *userdata)
1355{
1356 struct ivi_layout *layout = get_instance();
1357 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1358}
1359
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001360static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001361ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1362 void *userdata)
1363{
1364 struct ivi_layout *layout = get_instance();
1365 struct ivi_layout_notification_callback *created_callback = NULL;
1366
1367 if (callback == NULL) {
1368 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1369 return IVI_FAILED;
1370 }
1371
1372 created_callback = malloc(sizeof *created_callback);
1373 if (created_callback == NULL) {
1374 weston_log("fails to allocate memory\n");
1375 return IVI_FAILED;
1376 }
1377
1378 created_callback->callback = callback;
1379 created_callback->data = userdata;
1380
1381 return add_notification(&layout->surface_notification.created,
1382 surface_created,
1383 created_callback);
1384}
1385
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001386static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001387ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1388 void *userdata)
1389{
1390 struct ivi_layout *layout = get_instance();
1391 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1392}
1393
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001394static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001395ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1396 void *userdata)
1397{
1398 struct ivi_layout *layout = get_instance();
1399 struct ivi_layout_notification_callback *removed_callback = NULL;
1400
1401 if (callback == NULL) {
1402 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1403 return IVI_FAILED;
1404 }
1405
1406 removed_callback = malloc(sizeof *removed_callback);
1407 if (removed_callback == NULL) {
1408 weston_log("fails to allocate memory\n");
1409 return IVI_FAILED;
1410 }
1411
1412 removed_callback->callback = callback;
1413 removed_callback->data = userdata;
1414
1415 return add_notification(&layout->surface_notification.removed,
1416 surface_removed,
1417 removed_callback);
1418}
1419
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001420static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001421ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1422 void *userdata)
1423{
1424 struct ivi_layout *layout = get_instance();
1425 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1426}
1427
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001428static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001429ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1430 void *userdata)
1431{
1432 struct ivi_layout *layout = get_instance();
1433 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1434 if (callback == NULL) {
1435 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1436 return IVI_FAILED;
1437 }
1438
1439 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1440 if (configure_changed_callback == NULL) {
1441 weston_log("fails to allocate memory\n");
1442 return IVI_FAILED;
1443 }
1444
1445 configure_changed_callback->callback = callback;
1446 configure_changed_callback->data = userdata;
1447
1448 return add_notification(&layout->surface_notification.configure_changed,
1449 surface_configure_changed,
1450 configure_changed_callback);
1451}
1452
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001453static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001454ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1455 void *userdata)
1456{
1457 struct ivi_layout *layout = get_instance();
1458 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1459}
1460
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001461uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001462ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1463{
1464 return ivisurf->id_surface;
1465}
1466
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001467static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001468ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1469{
1470 return ivilayer->id_layer;
1471}
1472
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001473static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001474ivi_layout_get_layer_from_id(uint32_t id_layer)
1475{
1476 struct ivi_layout *layout = get_instance();
1477 struct ivi_layout_layer *ivilayer = NULL;
1478
1479 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1480 if (ivilayer->id_layer == id_layer) {
1481 return ivilayer;
1482 }
1483 }
1484
1485 return NULL;
1486}
1487
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001488struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001489ivi_layout_get_surface_from_id(uint32_t id_surface)
1490{
1491 struct ivi_layout *layout = get_instance();
1492 struct ivi_layout_surface *ivisurf = NULL;
1493
1494 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1495 if (ivisurf->id_surface == id_surface) {
1496 return ivisurf;
1497 }
1498 }
1499
1500 return NULL;
1501}
1502
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001503static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001504ivi_layout_get_screen_from_id(uint32_t id_screen)
1505{
1506 struct ivi_layout *layout = get_instance();
1507 struct ivi_layout_screen *iviscrn = NULL;
1508
1509 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1510/* FIXME : select iviscrn from screen_list by id_screen */
1511 return iviscrn;
1512 break;
1513 }
1514
1515 return NULL;
1516}
1517
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001518static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001519ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1520 int32_t *pWidth, int32_t *pHeight)
1521{
1522 struct weston_output *output = NULL;
1523
1524 if (pWidth == NULL || pHeight == NULL) {
1525 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1526 return IVI_FAILED;
1527 }
1528
1529 output = iviscrn->output;
1530 *pWidth = output->current_mode->width;
1531 *pHeight = output->current_mode->height;
1532
1533 return IVI_SUCCEEDED;
1534}
1535
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001536static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001537ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1538 surface_property_notification_func callback,
1539 void *userdata)
1540{
1541 struct listener_layout_notification* notification = NULL;
1542 struct ivi_layout_notification_callback *prop_callback = NULL;
1543
1544 if (ivisurf == NULL || callback == NULL) {
1545 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1546 return IVI_FAILED;
1547 }
1548
1549 notification = malloc(sizeof *notification);
1550 if (notification == NULL) {
1551 weston_log("fails to allocate memory\n");
1552 return IVI_FAILED;
1553 }
1554
1555 prop_callback = malloc(sizeof *prop_callback);
1556 if (prop_callback == NULL) {
1557 weston_log("fails to allocate memory\n");
1558 return IVI_FAILED;
1559 }
1560
1561 prop_callback->callback = callback;
1562 prop_callback->data = userdata;
1563
1564 notification->listener.notify = surface_prop_changed;
1565 notification->userdata = prop_callback;
1566
1567 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1568
1569 return IVI_SUCCEEDED;
1570}
1571
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001572static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001573ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1574{
1575 if (ivilayer == NULL) {
1576 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1577 return NULL;
1578 }
1579
1580 return &ivilayer->prop;
1581}
1582
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001583static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001584ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1585{
1586 struct ivi_layout *layout = get_instance();
1587 struct ivi_layout_screen *iviscrn = NULL;
1588 int32_t length = 0;
1589 int32_t n = 0;
1590
1591 if (pLength == NULL || ppArray == NULL) {
1592 weston_log("ivi_layout_get_screens: invalid argument\n");
1593 return IVI_FAILED;
1594 }
1595
1596 length = wl_list_length(&layout->screen_list);
1597
1598 if (length != 0){
1599 /* the Array must be free by module which called this function */
1600 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1601 if (*ppArray == NULL) {
1602 weston_log("fails to allocate memory\n");
1603 return IVI_FAILED;
1604 }
1605
1606 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1607 (*ppArray)[n++] = iviscrn;
1608 }
1609 }
1610
1611 *pLength = length;
1612
1613 return IVI_SUCCEEDED;
1614}
1615
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001616static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001617ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1618 int32_t *pLength,
1619 struct ivi_layout_screen ***ppArray)
1620{
1621 struct link_screen *link_scrn = NULL;
1622 int32_t length = 0;
1623 int32_t n = 0;
1624
1625 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1626 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1627 return IVI_FAILED;
1628 }
1629
1630 length = wl_list_length(&ivilayer->screen_list);
1631
1632 if (length != 0){
1633 /* the Array must be free by module which called this function */
1634 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1635 if (*ppArray == NULL) {
1636 weston_log("fails to allocate memory\n");
1637 return IVI_FAILED;
1638 }
1639
1640 wl_list_for_each(link_scrn, &ivilayer->screen_list, link) {
1641 (*ppArray)[n++] = link_scrn->iviscrn;
1642 }
1643 }
1644
1645 *pLength = length;
1646
1647 return IVI_SUCCEEDED;
1648}
1649
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001650static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001651ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1652{
1653 struct ivi_layout *layout = get_instance();
1654 struct ivi_layout_layer *ivilayer = NULL;
1655 int32_t length = 0;
1656 int32_t n = 0;
1657
1658 if (pLength == NULL || ppArray == NULL) {
1659 weston_log("ivi_layout_get_layers: invalid argument\n");
1660 return IVI_FAILED;
1661 }
1662
1663 length = wl_list_length(&layout->layer_list);
1664
1665 if (length != 0){
1666 /* the Array must be free by module which called this function */
1667 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1668 if (*ppArray == NULL) {
1669 weston_log("fails to allocate memory\n");
1670 return IVI_FAILED;
1671 }
1672
1673 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1674 (*ppArray)[n++] = ivilayer;
1675 }
1676 }
1677
1678 *pLength = length;
1679
1680 return IVI_SUCCEEDED;
1681}
1682
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001683static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001684ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1685 int32_t *pLength,
1686 struct ivi_layout_layer ***ppArray)
1687{
1688 struct ivi_layout_layer *ivilayer = NULL;
1689 int32_t length = 0;
1690 int32_t n = 0;
1691
1692 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1693 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1694 return IVI_FAILED;
1695 }
1696
1697 length = wl_list_length(&iviscrn->order.layer_list);
1698
1699 if (length != 0){
1700 /* the Array must be free by module which called this function */
1701 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1702 if (*ppArray == NULL) {
1703 weston_log("fails to allocate memory\n");
1704 return IVI_FAILED;
1705 }
1706
1707 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, link) {
1708 (*ppArray)[n++] = ivilayer;
1709 }
1710 }
1711
1712 *pLength = length;
1713
1714 return IVI_SUCCEEDED;
1715}
1716
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001717static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001718ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1719 int32_t *pLength,
1720 struct ivi_layout_layer ***ppArray)
1721{
1722 struct link_layer *link_layer = NULL;
1723 int32_t length = 0;
1724 int32_t n = 0;
1725
1726 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1727 weston_log("ivi_layout_getLayers: invalid argument\n");
1728 return IVI_FAILED;
1729 }
1730
1731 length = wl_list_length(&ivisurf->layer_list);
1732
1733 if (length != 0){
1734 /* the Array must be free by module which called this function */
1735 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1736 if (*ppArray == NULL) {
1737 weston_log("fails to allocate memory\n");
1738 return IVI_FAILED;
1739 }
1740
1741 wl_list_for_each(link_layer, &ivisurf->layer_list, link) {
1742 (*ppArray)[n++] = link_layer->ivilayer;
1743 }
1744 }
1745
1746 *pLength = length;
1747
1748 return IVI_SUCCEEDED;
1749}
1750
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001751static
1752int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001753ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1754{
1755 struct ivi_layout *layout = get_instance();
1756 struct ivi_layout_surface *ivisurf = NULL;
1757 int32_t length = 0;
1758 int32_t n = 0;
1759
1760 if (pLength == NULL || ppArray == NULL) {
1761 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1762 return IVI_FAILED;
1763 }
1764
1765 length = wl_list_length(&layout->surface_list);
1766
1767 if (length != 0){
1768 /* the Array must be free by module which called this function */
1769 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1770 if (*ppArray == NULL) {
1771 weston_log("fails to allocate memory\n");
1772 return IVI_FAILED;
1773 }
1774
1775 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1776 (*ppArray)[n++] = ivisurf;
1777 }
1778 }
1779
1780 *pLength = length;
1781
1782 return IVI_SUCCEEDED;
1783}
1784
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001785static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001786ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1787 int32_t *pLength,
1788 struct ivi_layout_surface ***ppArray)
1789{
1790 struct ivi_layout_surface *ivisurf = NULL;
1791 int32_t length = 0;
1792 int32_t n = 0;
1793
1794 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1795 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1796 return IVI_FAILED;
1797 }
1798
1799 length = wl_list_length(&ivilayer->order.surface_list);
1800
1801 if (length != 0) {
1802 /* the Array must be free by module which called this function */
1803 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1804 if (*ppArray == NULL) {
1805 weston_log("fails to allocate memory\n");
1806 return IVI_FAILED;
1807 }
1808
1809 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1810 (*ppArray)[n++] = ivisurf;
1811 }
1812 }
1813
1814 *pLength = length;
1815
1816 return IVI_SUCCEEDED;
1817}
1818
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001819static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001820ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1821 int32_t width, int32_t height)
1822{
1823 struct ivi_layout *layout = get_instance();
1824 struct ivi_layout_layer *ivilayer = NULL;
1825
1826 ivilayer = get_layer(&layout->layer_list, id_layer);
1827 if (ivilayer != NULL) {
1828 weston_log("id_layer is already created\n");
1829 return ivilayer;
1830 }
1831
1832 ivilayer = calloc(1, sizeof *ivilayer);
1833 if (ivilayer == NULL) {
1834 weston_log("fails to allocate memory\n");
1835 return NULL;
1836 }
1837
1838 wl_list_init(&ivilayer->link);
1839 wl_signal_init(&ivilayer->property_changed);
1840 wl_list_init(&ivilayer->screen_list);
1841 wl_list_init(&ivilayer->link_to_surface);
1842 ivilayer->layout = layout;
1843 ivilayer->id_layer = id_layer;
1844
1845 init_layer_properties(&ivilayer->prop, width, height);
1846 ivilayer->event_mask = 0;
1847
1848 wl_list_init(&ivilayer->pending.surface_list);
1849 wl_list_init(&ivilayer->pending.link);
1850 ivilayer->pending.prop = ivilayer->prop;
1851
1852 wl_list_init(&ivilayer->order.surface_list);
1853 wl_list_init(&ivilayer->order.link);
1854
1855 wl_list_insert(&layout->layer_list, &ivilayer->link);
1856
1857 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1858
1859 return ivilayer;
1860}
1861
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001862static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001863ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1864{
1865 if (ivilayer == NULL) {
1866 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1867 return;
1868 }
1869
1870 remove_all_notification(&ivilayer->property_changed.listener_list);
1871}
1872
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001873static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001874ivi_layout_layer_remove(struct ivi_layout_layer *ivilayer)
1875{
1876 struct ivi_layout *layout = get_instance();
1877
1878 if (ivilayer == NULL) {
1879 weston_log("ivi_layout_layer_remove: invalid argument\n");
1880 return;
1881 }
1882
1883 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1884
1885 clear_surface_pending_list(ivilayer);
1886 clear_surface_order_list(ivilayer);
1887
1888 if (!wl_list_empty(&ivilayer->pending.link)) {
1889 wl_list_remove(&ivilayer->pending.link);
1890 }
1891 if (!wl_list_empty(&ivilayer->order.link)) {
1892 wl_list_remove(&ivilayer->order.link);
1893 }
1894 if (!wl_list_empty(&ivilayer->link)) {
1895 wl_list_remove(&ivilayer->link);
1896 }
1897 remove_orderlayer_from_screen(ivilayer);
1898 remove_link_to_surface(ivilayer);
1899 ivi_layout_layer_remove_notification(ivilayer);
1900
1901 free(ivilayer);
1902}
1903
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001904int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001905ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1906 bool newVisibility)
1907{
1908 struct ivi_layout_layer_properties *prop = NULL;
1909
1910 if (ivilayer == NULL) {
1911 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1912 return IVI_FAILED;
1913 }
1914
1915 prop = &ivilayer->pending.prop;
1916 prop->visibility = newVisibility;
1917
1918 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1919
1920 return IVI_SUCCEEDED;
1921}
1922
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001923static bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001924ivi_layout_layer_get_visibility(struct ivi_layout_layer *ivilayer)
1925{
1926 if (ivilayer == NULL) {
1927 weston_log("ivi_layout_layer_get_visibility: invalid argument\n");
1928 return false;
1929 }
1930
1931 return ivilayer->prop.visibility;
1932}
1933
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001934int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001935ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1936 wl_fixed_t opacity)
1937{
1938 struct ivi_layout_layer_properties *prop = NULL;
1939
1940 if (ivilayer == NULL) {
1941 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1942 return IVI_FAILED;
1943 }
1944
1945 prop = &ivilayer->pending.prop;
1946 prop->opacity = opacity;
1947
1948 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1949
1950 return IVI_SUCCEEDED;
1951}
1952
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001953wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001954ivi_layout_layer_get_opacity(struct ivi_layout_layer *ivilayer)
1955{
1956 if (ivilayer == NULL) {
1957 weston_log("ivi_layout_layer_get_opacity: invalid argument\n");
1958 return wl_fixed_from_double(0.0);
1959 }
1960
1961 return ivilayer->prop.opacity;
1962}
1963
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001964static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001965ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1966 int32_t x, int32_t y,
1967 int32_t width, int32_t height)
1968{
1969 struct ivi_layout_layer_properties *prop = NULL;
1970
1971 if (ivilayer == NULL) {
1972 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1973 return IVI_FAILED;
1974 }
1975
1976 prop = &ivilayer->pending.prop;
1977 prop->source_x = x;
1978 prop->source_y = y;
1979 prop->source_width = width;
1980 prop->source_height = height;
1981
1982 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1983
1984 return IVI_SUCCEEDED;
1985}
1986
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001987static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001988ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1989 int32_t x, int32_t y,
1990 int32_t width, int32_t height)
1991{
1992 struct ivi_layout_layer_properties *prop = NULL;
1993
1994 if (ivilayer == NULL) {
1995 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1996 return IVI_FAILED;
1997 }
1998
1999 prop = &ivilayer->pending.prop;
2000 prop->dest_x = x;
2001 prop->dest_y = y;
2002 prop->dest_width = width;
2003 prop->dest_height = height;
2004
2005 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2006
2007 return IVI_SUCCEEDED;
2008}
2009
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002010static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002011ivi_layout_layer_get_dimension(struct ivi_layout_layer *ivilayer,
2012 int32_t *dest_width, int32_t *dest_height)
2013{
2014 if (ivilayer == NULL || dest_width == NULL || dest_height == NULL) {
2015 weston_log("ivi_layout_layer_get_dimension: invalid argument\n");
2016 return IVI_FAILED;
2017 }
2018
2019 *dest_width = ivilayer->prop.dest_width;
2020 *dest_height = ivilayer->prop.dest_height;
2021
2022 return IVI_SUCCEEDED;
2023}
2024
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002025static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002026ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
2027 int32_t dest_width, int32_t dest_height)
2028{
2029 struct ivi_layout_layer_properties *prop = NULL;
2030
2031 if (ivilayer == NULL) {
2032 weston_log("ivi_layout_layer_set_dimension: invalid argument\n");
2033 return IVI_FAILED;
2034 }
2035
2036 prop = &ivilayer->pending.prop;
2037
2038 prop->dest_width = dest_width;
2039 prop->dest_height = dest_height;
2040
2041 ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
2042
2043 return IVI_SUCCEEDED;
2044}
2045
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002046int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002047ivi_layout_layer_get_position(struct ivi_layout_layer *ivilayer,
2048 int32_t *dest_x, int32_t *dest_y)
2049{
2050 if (ivilayer == NULL || dest_x == NULL || dest_y == NULL) {
2051 weston_log("ivi_layout_layer_get_position: invalid argument\n");
2052 return IVI_FAILED;
2053 }
2054
2055 *dest_x = ivilayer->prop.dest_x;
2056 *dest_y = ivilayer->prop.dest_y;
2057
2058 return IVI_SUCCEEDED;
2059}
2060
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002061int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002062ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
2063 int32_t dest_x, int32_t dest_y)
2064{
2065 struct ivi_layout_layer_properties *prop = NULL;
2066
2067 if (ivilayer == NULL) {
2068 weston_log("ivi_layout_layer_set_position: invalid argument\n");
2069 return IVI_FAILED;
2070 }
2071
2072 prop = &ivilayer->pending.prop;
2073 prop->dest_x = dest_x;
2074 prop->dest_y = dest_y;
2075
2076 ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
2077
2078 return IVI_SUCCEEDED;
2079}
2080
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002081static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002082ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
2083 enum wl_output_transform orientation)
2084{
2085 struct ivi_layout_layer_properties *prop = NULL;
2086
2087 if (ivilayer == NULL) {
2088 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
2089 return IVI_FAILED;
2090 }
2091
2092 prop = &ivilayer->pending.prop;
2093 prop->orientation = orientation;
2094
2095 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2096
2097 return IVI_SUCCEEDED;
2098}
2099
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002100static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002101ivi_layout_layer_get_orientation(struct ivi_layout_layer *ivilayer)
2102{
2103 if (ivilayer == NULL) {
2104 weston_log("ivi_layout_layer_get_orientation: invalid argument\n");
2105 return 0;
2106 }
2107
2108 return ivilayer->prop.orientation;
2109}
2110
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002111int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002112ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
2113 struct ivi_layout_surface **pSurface,
2114 int32_t number)
2115{
2116 struct ivi_layout *layout = get_instance();
2117 struct ivi_layout_surface *ivisurf = NULL;
2118 struct ivi_layout_surface *next = NULL;
2119 uint32_t *id_surface = NULL;
2120 int32_t i = 0;
2121
2122 if (ivilayer == NULL) {
2123 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
2124 return IVI_FAILED;
2125 }
2126
2127 if (pSurface == NULL) {
2128 wl_list_for_each_safe(ivisurf, next, &ivilayer->pending.surface_list, pending.link) {
2129 if (!wl_list_empty(&ivisurf->pending.link)) {
2130 wl_list_remove(&ivisurf->pending.link);
2131 }
2132
2133 wl_list_init(&ivisurf->pending.link);
2134 }
2135 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
2136 return IVI_SUCCEEDED;
2137 }
2138
2139 for (i = 0; i < number; i++) {
2140 id_surface = &pSurface[i]->id_surface;
2141
2142 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2143 if (*id_surface != ivisurf->id_surface) {
2144 continue;
2145 }
2146
2147 if (!wl_list_empty(&ivisurf->pending.link)) {
2148 wl_list_remove(&ivisurf->pending.link);
2149 }
2150 wl_list_init(&ivisurf->pending.link);
2151 wl_list_insert(&ivilayer->pending.surface_list,
2152 &ivisurf->pending.link);
2153 break;
2154 }
2155 }
2156
2157 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
2158
2159 return IVI_SUCCEEDED;
2160}
2161
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002162int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002163ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
2164 bool newVisibility)
2165{
2166 struct ivi_layout_surface_properties *prop = NULL;
2167
2168 if (ivisurf == NULL) {
2169 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
2170 return IVI_FAILED;
2171 }
2172
2173 prop = &ivisurf->pending.prop;
2174 prop->visibility = newVisibility;
2175
2176 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
2177
2178 return IVI_SUCCEEDED;
2179}
2180
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002181bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002182ivi_layout_surface_get_visibility(struct ivi_layout_surface *ivisurf)
2183{
2184 if (ivisurf == NULL) {
2185 weston_log("ivi_layout_surface_get_visibility: invalid argument\n");
2186 return false;
2187 }
2188
2189 return ivisurf->prop.visibility;
2190}
2191
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002192int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002193ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
2194 wl_fixed_t opacity)
2195{
2196 struct ivi_layout_surface_properties *prop = NULL;
2197
2198 if (ivisurf == NULL) {
2199 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
2200 return IVI_FAILED;
2201 }
2202
2203 prop = &ivisurf->pending.prop;
2204 prop->opacity = opacity;
2205
2206 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
2207
2208 return IVI_SUCCEEDED;
2209}
2210
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002211wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002212ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
2213{
2214 if (ivisurf == NULL) {
2215 weston_log("ivi_layout_surface_get_opacity: invalid argument\n");
2216 return wl_fixed_from_double(0.0);
2217 }
2218
2219 return ivisurf->prop.opacity;
2220}
2221
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002222int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002223ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
2224 int32_t x, int32_t y,
2225 int32_t width, int32_t height)
2226{
2227 struct ivi_layout_surface_properties *prop = NULL;
2228
2229 if (ivisurf == NULL) {
2230 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
2231 return IVI_FAILED;
2232 }
2233
2234 prop = &ivisurf->pending.prop;
2235 prop->start_x = prop->dest_x;
2236 prop->start_y = prop->dest_y;
2237 prop->dest_x = x;
2238 prop->dest_y = y;
2239 prop->start_width = prop->dest_width;
2240 prop->start_height = prop->dest_height;
2241 prop->dest_width = width;
2242 prop->dest_height = height;
2243
2244 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2245
2246 return IVI_SUCCEEDED;
2247}
2248
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002249static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002250ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
2251 int32_t dest_width, int32_t dest_height)
2252{
2253 struct ivi_layout_surface_properties *prop = NULL;
2254
2255 if (ivisurf == NULL) {
2256 weston_log("ivi_layout_surface_set_dimension: invalid argument\n");
2257 return IVI_FAILED;
2258 }
2259
2260 prop = &ivisurf->pending.prop;
2261 prop->dest_width = dest_width;
2262 prop->dest_height = dest_height;
2263
2264 ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
2265
2266 return IVI_SUCCEEDED;
2267}
2268
2269int32_t
2270ivi_layout_surface_get_dimension(struct ivi_layout_surface *ivisurf,
2271 int32_t *dest_width, int32_t *dest_height)
2272{
2273 if (ivisurf == NULL || dest_width == NULL || dest_height == NULL) {
2274 weston_log("ivi_layout_surface_get_dimension: invalid argument\n");
2275 return IVI_FAILED;
2276 }
2277
2278 *dest_width = ivisurf->prop.dest_width;
2279 *dest_height = ivisurf->prop.dest_height;
2280
2281 return IVI_SUCCEEDED;
2282}
2283
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002284static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002285ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
2286 int32_t dest_x, int32_t dest_y)
2287{
2288 struct ivi_layout_surface_properties *prop = NULL;
2289
2290 if (ivisurf == NULL) {
2291 weston_log("ivi_layout_surface_set_position: invalid argument\n");
2292 return IVI_FAILED;
2293 }
2294
2295 prop = &ivisurf->pending.prop;
2296 prop->dest_x = dest_x;
2297 prop->dest_y = dest_y;
2298
2299 ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
2300
2301 return IVI_SUCCEEDED;
2302}
2303
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002304static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002305ivi_layout_surface_get_position(struct ivi_layout_surface *ivisurf,
2306 int32_t *dest_x, int32_t *dest_y)
2307{
2308 if (ivisurf == NULL || dest_x == NULL || dest_y == NULL) {
2309 weston_log("ivi_layout_surface_get_position: invalid argument\n");
2310 return IVI_FAILED;
2311 }
2312
2313 *dest_x = ivisurf->prop.dest_x;
2314 *dest_y = ivisurf->prop.dest_y;
2315
2316 return IVI_SUCCEEDED;
2317}
2318
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002319static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002320ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2321 enum wl_output_transform orientation)
2322{
2323 struct ivi_layout_surface_properties *prop = NULL;
2324
2325 if (ivisurf == NULL) {
2326 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2327 return IVI_FAILED;
2328 }
2329
2330 prop = &ivisurf->pending.prop;
2331 prop->orientation = orientation;
2332
2333 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2334
2335 return IVI_SUCCEEDED;
2336}
2337
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002338static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002339ivi_layout_surface_get_orientation(struct ivi_layout_surface *ivisurf)
2340{
2341 if (ivisurf == NULL) {
2342 weston_log("ivi_layout_surface_get_orientation: invalid argument\n");
2343 return 0;
2344 }
2345
2346 return ivisurf->prop.orientation;
2347}
2348
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002349static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002350ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2351 struct ivi_layout_layer *addlayer)
2352{
2353 struct ivi_layout *layout = get_instance();
2354 struct ivi_layout_layer *ivilayer = NULL;
2355 struct ivi_layout_layer *next = NULL;
2356 int is_layer_in_scrn = 0;
2357
2358 if (iviscrn == NULL || addlayer == NULL) {
2359 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2360 return IVI_FAILED;
2361 }
2362
2363 is_layer_in_scrn = is_layer_in_screen(addlayer, iviscrn);
2364 if (is_layer_in_scrn == 1) {
2365 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2366 return IVI_SUCCEEDED;
2367 }
2368
2369 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2370 if (ivilayer->id_layer == addlayer->id_layer) {
2371 if (!wl_list_empty(&ivilayer->pending.link)) {
2372 wl_list_remove(&ivilayer->pending.link);
2373 }
2374 wl_list_init(&ivilayer->pending.link);
2375 wl_list_insert(&iviscrn->pending.layer_list,
2376 &ivilayer->pending.link);
2377 break;
2378 }
2379 }
2380
2381 iviscrn->event_mask |= IVI_NOTIFICATION_ADD;
2382
2383 return IVI_SUCCEEDED;
2384}
2385
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002386static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002387ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2388 struct ivi_layout_layer **pLayer,
2389 const int32_t number)
2390{
2391 struct ivi_layout *layout = get_instance();
2392 struct ivi_layout_layer *ivilayer = NULL;
2393 struct ivi_layout_layer *next = NULL;
2394 uint32_t *id_layer = NULL;
2395 int32_t i = 0;
2396
2397 if (iviscrn == NULL) {
2398 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2399 return IVI_FAILED;
2400 }
2401
2402 wl_list_for_each_safe(ivilayer, next,
2403 &iviscrn->pending.layer_list, pending.link) {
2404 wl_list_init(&ivilayer->pending.link);
2405 }
2406
2407 wl_list_init(&iviscrn->pending.layer_list);
2408
2409 if (pLayer == NULL) {
2410 wl_list_for_each_safe(ivilayer, next, &iviscrn->pending.layer_list, pending.link) {
2411 if (!wl_list_empty(&ivilayer->pending.link)) {
2412 wl_list_remove(&ivilayer->pending.link);
2413 }
2414
2415 wl_list_init(&ivilayer->pending.link);
2416 }
2417
2418 iviscrn->event_mask |= IVI_NOTIFICATION_REMOVE;
2419 return IVI_SUCCEEDED;
2420 }
2421
2422 for (i = 0; i < number; i++) {
2423 id_layer = &pLayer[i]->id_layer;
2424 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2425 if (*id_layer != ivilayer->id_layer) {
2426 continue;
2427 }
2428
2429 if (!wl_list_empty(&ivilayer->pending.link)) {
2430 wl_list_remove(&ivilayer->pending.link);
2431 }
2432 wl_list_init(&ivilayer->pending.link);
2433 wl_list_insert(&iviscrn->pending.layer_list,
2434 &ivilayer->pending.link);
2435 break;
2436 }
2437 }
2438
2439 iviscrn->event_mask |= IVI_NOTIFICATION_ADD;
2440
2441 return IVI_SUCCEEDED;
2442}
2443
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002444static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002445ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2446{
2447 return iviscrn->output;
2448}
2449
2450/**
2451 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2452 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2453 * This function is used to get the result of drawing by clients.
2454 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002455static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002456ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2457{
2458 return ivisurf != NULL ? ivisurf->surface : NULL;
2459}
2460
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002461static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002462ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2463 layer_property_notification_func callback,
2464 void *userdata)
2465{
2466 struct ivi_layout_notification_callback *prop_callback = NULL;
2467
2468 if (ivilayer == NULL || callback == NULL) {
2469 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2470 return IVI_FAILED;
2471 }
2472
2473 prop_callback = malloc(sizeof *prop_callback);
2474 if (prop_callback == NULL) {
2475 weston_log("fails to allocate memory\n");
2476 return IVI_FAILED;
2477 }
2478
2479 prop_callback->callback = callback;
2480 prop_callback->data = userdata;
2481
2482 return add_notification(&ivilayer->property_changed,
2483 layer_prop_changed,
2484 prop_callback);
2485}
2486
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002487static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002488ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2489{
2490 if (ivisurf == NULL) {
2491 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2492 return NULL;
2493 }
2494
2495 return &ivisurf->prop;
2496}
2497
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002498static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002499ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2500 struct ivi_layout_surface *addsurf)
2501{
2502 struct ivi_layout *layout = get_instance();
2503 struct ivi_layout_surface *ivisurf = NULL;
2504 struct ivi_layout_surface *next = NULL;
2505 int is_surf_in_layer = 0;
2506
2507 if (ivilayer == NULL || addsurf == NULL) {
2508 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2509 return IVI_FAILED;
2510 }
2511
2512 is_surf_in_layer = is_surface_in_layer(addsurf, ivilayer);
2513 if (is_surf_in_layer == 1) {
2514 weston_log("ivi_layout_layer_add_surface: addsurf is already available\n");
2515 return IVI_SUCCEEDED;
2516 }
2517
2518 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2519 if (ivisurf->id_surface == addsurf->id_surface) {
2520 if (!wl_list_empty(&ivisurf->pending.link)) {
2521 wl_list_remove(&ivisurf->pending.link);
2522 }
2523 wl_list_init(&ivisurf->pending.link);
2524 wl_list_insert(&ivilayer->pending.surface_list,
2525 &ivisurf->pending.link);
2526 break;
2527 }
2528 }
2529
2530 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
2531
2532 return IVI_SUCCEEDED;
2533}
2534
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002535static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002536ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2537 struct ivi_layout_surface *remsurf)
2538{
2539 struct ivi_layout_surface *ivisurf = NULL;
2540 struct ivi_layout_surface *next = NULL;
2541
2542 if (ivilayer == NULL || remsurf == NULL) {
2543 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2544 return;
2545 }
2546
2547 wl_list_for_each_safe(ivisurf, next,
2548 &ivilayer->pending.surface_list, pending.link) {
2549 if (ivisurf->id_surface == remsurf->id_surface) {
2550 if (!wl_list_empty(&ivisurf->pending.link)) {
2551 wl_list_remove(&ivisurf->pending.link);
2552 }
2553 wl_list_init(&ivisurf->pending.link);
2554 break;
2555 }
2556 }
2557
2558 remsurf->event_mask |= IVI_NOTIFICATION_REMOVE;
2559}
2560
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002561static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002562ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2563 int32_t x, int32_t y,
2564 int32_t width, int32_t height)
2565{
2566 struct ivi_layout_surface_properties *prop = NULL;
2567
2568 if (ivisurf == NULL) {
2569 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2570 return IVI_FAILED;
2571 }
2572
2573 prop = &ivisurf->pending.prop;
2574 prop->source_x = x;
2575 prop->source_y = y;
2576 prop->source_width = width;
2577 prop->source_height = height;
2578
2579 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2580
2581 return IVI_SUCCEEDED;
2582}
2583
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002584int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002585ivi_layout_commit_changes(void)
2586{
2587 struct ivi_layout *layout = get_instance();
2588
2589 commit_surface_list(layout);
2590 commit_layer_list(layout);
2591 commit_screen_list(layout);
2592
2593 commit_transition(layout);
2594
2595 commit_changes(layout);
2596 send_prop(layout);
2597 weston_compositor_schedule_repaint(layout->compositor);
2598
2599 return IVI_SUCCEEDED;
2600}
2601
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002602static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002603ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2604 enum ivi_layout_transition_type type,
2605 uint32_t duration)
2606{
2607 if (ivilayer == NULL) {
2608 weston_log("%s: invalid argument\n", __func__);
2609 return -1;
2610 }
2611
2612 ivilayer->pending.prop.transition_type = type;
2613 ivilayer->pending.prop.transition_duration = duration;
2614
2615 return 0;
2616}
2617
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002618static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002619ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2620 uint32_t is_fade_in,
2621 double start_alpha, double end_alpha)
2622{
2623 if (ivilayer == NULL) {
2624 weston_log("%s: invalid argument\n", __func__);
2625 return -1;
2626 }
2627
2628 ivilayer->pending.prop.is_fade_in = is_fade_in;
2629 ivilayer->pending.prop.start_alpha = start_alpha;
2630 ivilayer->pending.prop.end_alpha = end_alpha;
2631
2632 return 0;
2633}
2634
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002635static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002636ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2637 uint32_t duration)
2638{
2639 struct ivi_layout_surface_properties *prop;
2640
2641 if (ivisurf == NULL) {
2642 weston_log("%s: invalid argument\n", __func__);
2643 return -1;
2644 }
2645
2646 prop = &ivisurf->pending.prop;
2647 prop->transition_duration = duration*10;
2648 return 0;
2649}
2650
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002651static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002652ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2653 enum ivi_layout_transition_type type,
2654 uint32_t duration)
2655{
2656 struct ivi_layout_surface_properties *prop;
2657
2658 if (ivisurf == NULL) {
2659 weston_log("%s: invalid argument\n", __func__);
2660 return -1;
2661 }
2662
2663 prop = &ivisurf->pending.prop;
2664 prop->transition_type = type;
2665 prop->transition_duration = duration;
2666 return 0;
2667}
2668
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002669/**
2670 * methods of interaction between ivi-shell with ivi-layout
2671 */
2672struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002673ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2674{
2675 struct weston_view *tmpview = NULL;
2676
2677 if(surface == NULL)
2678 return NULL;
2679
2680 wl_list_for_each(tmpview, &surface->surface->views, surface_link)
2681 {
2682 if (tmpview != NULL) {
2683 break;
2684 }
2685 }
2686 return tmpview;
2687}
2688
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002689void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002690ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2691 int32_t width, int32_t height)
2692{
2693 struct ivi_layout *layout = get_instance();
2694 int32_t in_init = 0;
2695 ivisurf->surface->width_from_buffer = width;
2696 ivisurf->surface->height_from_buffer = height;
2697
2698 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
2699 in_init = 1;
2700 }
2701
2702 /* FIXME: when sourceHeight/Width is used as clipping range in image buffer */
2703 /* if (ivisurf->prop.sourceWidth == 0 || ivisurf->prop.sourceHeight == 0) { */
2704 ivisurf->pending.prop.source_width = width;
2705 ivisurf->pending.prop.source_height = height;
2706 ivisurf->prop.source_width = width;
2707 ivisurf->prop.source_height = height;
2708 /* } */
2709
2710 ivisurf->event_mask |= IVI_NOTIFICATION_CONFIGURE;
2711
2712 if (in_init) {
2713 wl_signal_emit(&layout->surface_notification.configure_changed, ivisurf);
2714 } else {
2715 ivi_layout_commit_changes();
2716 }
2717}
2718
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002719static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002720ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2721 ivi_controller_surface_content_callback callback,
2722 void* userdata)
2723{
2724 int32_t ret = IVI_FAILED;
2725
2726 if (ivisurf != NULL) {
2727 ivisurf->content_observer.callback = callback;
2728 ivisurf->content_observer.userdata = userdata;
2729 ret = IVI_SUCCEEDED;
2730 }
2731 return ret;
2732}
2733
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002734struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002735ivi_layout_surface_create(struct weston_surface *wl_surface,
2736 uint32_t id_surface)
2737{
2738 struct ivi_layout *layout = get_instance();
2739 struct ivi_layout_surface *ivisurf = NULL;
2740 struct weston_view *tmpview = NULL;
2741
2742 if (wl_surface == NULL) {
2743 weston_log("ivi_layout_surface_create: invalid argument\n");
2744 return NULL;
2745 }
2746
2747 ivisurf = get_surface(&layout->surface_list, id_surface);
2748 if (ivisurf != NULL) {
2749 if (ivisurf->surface != NULL) {
2750 weston_log("id_surface(%d) is already created\n", id_surface);
2751 return NULL;
2752 }
2753 }
2754
2755 ivisurf = calloc(1, sizeof *ivisurf);
2756 if (ivisurf == NULL) {
2757 weston_log("fails to allocate memory\n");
2758 return NULL;
2759 }
2760
2761 wl_list_init(&ivisurf->link);
2762 wl_signal_init(&ivisurf->property_changed);
2763 wl_signal_init(&ivisurf->configured);
2764 wl_list_init(&ivisurf->layer_list);
2765 ivisurf->id_surface = id_surface;
2766 ivisurf->layout = layout;
2767
2768 ivisurf->surface = wl_surface;
2769 ivisurf->surface_destroy_listener.notify =
2770 westonsurface_destroy_from_ivisurface;
2771 wl_resource_add_destroy_listener(wl_surface->resource,
2772 &ivisurf->surface_destroy_listener);
2773
2774 tmpview = weston_view_create(wl_surface);
2775 if (tmpview == NULL) {
2776 weston_log("fails to allocate memory\n");
2777 }
2778
2779 ivisurf->surface->width_from_buffer = 0;
2780 ivisurf->surface->height_from_buffer = 0;
2781
2782 weston_matrix_init(&ivisurf->surface_rotation.matrix);
2783 weston_matrix_init(&ivisurf->layer_rotation.matrix);
2784 weston_matrix_init(&ivisurf->surface_pos.matrix);
2785 weston_matrix_init(&ivisurf->layer_pos.matrix);
2786 weston_matrix_init(&ivisurf->scaling.matrix);
2787
2788 wl_list_init(&ivisurf->surface_rotation.link);
2789 wl_list_init(&ivisurf->layer_rotation.link);
2790 wl_list_init(&ivisurf->surface_pos.link);
2791 wl_list_init(&ivisurf->layer_pos.link);
2792 wl_list_init(&ivisurf->scaling.link);
2793
2794 init_surface_properties(&ivisurf->prop);
2795 ivisurf->event_mask = 0;
2796
2797 ivisurf->pending.prop = ivisurf->prop;
2798 wl_list_init(&ivisurf->pending.link);
2799
2800 wl_list_init(&ivisurf->order.link);
2801 wl_list_init(&ivisurf->order.layer_list);
2802
2803 wl_list_insert(&layout->surface_list, &ivisurf->link);
2804
2805 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2806
2807 return ivisurf;
2808}
2809
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002810void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002811ivi_layout_init_with_compositor(struct weston_compositor *ec)
2812{
2813 struct ivi_layout *layout = get_instance();
2814
2815 layout->compositor = ec;
2816
2817 wl_list_init(&layout->surface_list);
2818 wl_list_init(&layout->layer_list);
2819 wl_list_init(&layout->screen_list);
2820
2821 wl_signal_init(&layout->layer_notification.created);
2822 wl_signal_init(&layout->layer_notification.removed);
2823
2824 wl_signal_init(&layout->surface_notification.created);
2825 wl_signal_init(&layout->surface_notification.removed);
2826 wl_signal_init(&layout->surface_notification.configure_changed);
2827
2828 /* Add layout_layer at the last of weston_compositor.layer_list */
2829 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2830
2831 create_screen(ec);
2832
2833 layout->transitions = ivi_layout_transition_set_create(ec);
2834 wl_list_init(&layout->pending_transition_list);
2835}
2836
2837
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002838void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002839ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2840 struct wl_listener* listener)
2841{
2842 wl_signal_add(&ivisurf->configured, listener);
2843}
2844
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002845static struct ivi_controller_interface ivi_controller_interface = {
2846 /**
2847 * commit all changes
2848 */
2849 .commit_changes = ivi_layout_commit_changes,
2850
2851 /**
2852 * surface controller interfaces
2853 */
2854 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2855 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2856 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2857 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2858 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2859 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2860 .get_surfaces = ivi_layout_get_surfaces,
2861 .get_id_of_surface = ivi_layout_get_id_of_surface,
2862 .get_surface_from_id = ivi_layout_get_surface_from_id,
2863 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2864 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2865 .surface_set_visibility = ivi_layout_surface_set_visibility,
2866 .surface_get_visibility = ivi_layout_surface_get_visibility,
2867 .surface_set_opacity = ivi_layout_surface_set_opacity,
2868 .surface_get_opacity = ivi_layout_surface_get_opacity,
2869 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2870 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
2871 .surface_set_position = ivi_layout_surface_set_position,
2872 .surface_get_position = ivi_layout_surface_get_position,
2873 .surface_set_dimension = ivi_layout_surface_set_dimension,
2874 .surface_get_dimension = ivi_layout_surface_get_dimension,
2875 .surface_set_orientation = ivi_layout_surface_set_orientation,
2876 .surface_get_orientation = ivi_layout_surface_get_orientation,
2877 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2878 .surface_add_notification = ivi_layout_surface_add_notification,
2879 .surface_remove_notification = ivi_layout_surface_remove_notification,
2880 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2881 .surface_set_transition = ivi_layout_surface_set_transition,
2882 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2883
2884 /**
2885 * layer controller interfaces
2886 */
2887 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2888 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2889 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2890 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2891 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
2892 .layer_remove = ivi_layout_layer_remove,
2893 .get_layers = ivi_layout_get_layers,
2894 .get_id_of_layer = ivi_layout_get_id_of_layer,
2895 .get_layer_from_id = ivi_layout_get_layer_from_id,
2896 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2897 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2898 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2899 .layer_set_visibility = ivi_layout_layer_set_visibility,
2900 .layer_get_visibility = ivi_layout_layer_get_visibility,
2901 .layer_set_opacity = ivi_layout_layer_set_opacity,
2902 .layer_get_opacity = ivi_layout_layer_get_opacity,
2903 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2904 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
2905 .layer_set_position = ivi_layout_layer_set_position,
2906 .layer_get_position = ivi_layout_layer_get_position,
2907 .layer_set_dimension = ivi_layout_layer_set_dimension,
2908 .layer_get_dimension = ivi_layout_layer_get_dimension,
2909 .layer_set_orientation = ivi_layout_layer_set_orientation,
2910 .layer_get_orientation = ivi_layout_layer_get_orientation,
2911 .layer_add_surface = ivi_layout_layer_add_surface,
2912 .layer_remove_surface = ivi_layout_layer_remove_surface,
2913 .layer_set_render_order = ivi_layout_layer_set_render_order,
2914 .layer_add_notification = ivi_layout_layer_add_notification,
2915 .layer_remove_notification = ivi_layout_layer_remove_notification,
2916 .layer_set_transition = ivi_layout_layer_set_transition,
2917
2918 /**
2919 * screen controller interfaces
2920 */
2921 .get_screen_from_id = ivi_layout_get_screen_from_id,
2922 .get_screen_resolution = ivi_layout_get_screen_resolution,
2923 .get_screens = ivi_layout_get_screens,
2924 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2925 .screen_add_layer = ivi_layout_screen_add_layer,
2926 .screen_set_render_order = ivi_layout_screen_set_render_order,
2927 .screen_get_output = ivi_layout_screen_get_output,
2928
2929 /**
2930 * animation
2931 */
2932 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
2933 .layer_set_fade_info = ivi_layout_layer_set_fade_info
2934};
2935
2936int
2937load_controller_modules(struct weston_compositor *compositor, const char *modules,
2938 int *argc, char *argv[])
2939{
2940 const char *p, *end;
2941 char buffer[256];
2942 int (*controller_module_init)(struct weston_compositor *compositor,
2943 int *argc, char *argv[],
2944 const struct ivi_controller_interface *interface,
2945 size_t interface_version);
2946
2947 if (modules == NULL)
2948 return 0;
2949
2950 p = modules;
2951 while (*p) {
2952 end = strchrnul(p, ',');
2953 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2954
2955 controller_module_init = weston_load_module(buffer, "controller_module_init");
2956 if (controller_module_init)
Nobuhiko Tanibata9d860212014-12-16 19:37:22 +09002957 if(controller_module_init(compositor, argc, argv,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002958 &ivi_controller_interface,
Nobuhiko Tanibata9d860212014-12-16 19:37:22 +09002959 sizeof(struct ivi_controller_interface)) != 0) {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002960 weston_log("ivi-shell: Initialization of controller module fails");
2961 return -1;
2962 }
2963
2964 p = end;
2965 while (*p == ',')
2966 p++;
2967 }
2968
2969 return 0;
2970}