blob: 34bb221064a1791f257686c3a8c878fe653455aa [file] [log] [blame]
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001/*
2 * Copyright (C) 2013 DENSO CORPORATION
3 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090011 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090024 */
25
26/**
27 * Implementation of ivi-layout library. The actual view on ivi_screen is
28 * not updated till calling ivi_layout_commit_changes. A overview from
29 * calling API for updating properties of ivi_surface/ivi_layer to asking
30 * compositor to compose them by using weston_compositor_schedule_repaint,
31 * 0/ initialize this library by ivi_layout_init_with_compositor
32 * with (struct weston_compositor *ec) from ivi-shell.
33 * 1/ When a API for updating properties of ivi_surface/ivi_layer, it updates
34 * pending prop of ivi_surface/ivi_layer/ivi_screen which are structure to
35 * store properties.
36 * 2/ Before calling commitChanges, in case of calling a API to get a property,
37 * return current property, not pending property.
38 * 3/ At the timing of calling ivi_layout_commitChanges, pending properties
39 * are applied to properties.
40 *
41 * *) ivi_layout_commitChanges is also called by transition animation
42 * per each frame. See ivi-layout-transition.c in details. Transition
43 * animation interpolates frames between previous properties of ivi_surface
44 * and new ones.
45 * For example, when a property of ivi_surface is changed from invisibility
46 * to visibility, it behaves like fade-in. When ivi_layout_commitChange is
47 * called during transition animation, it cancels the transition and
48 * re-start transition to new properties from current properties of final
49 * frame just before the the cancellation.
50 *
51 * 4/ According properties, set transformation by using weston_matrix and
52 * weston_view per ivi_surfaces and ivi_layers in while loop.
53 * 5/ Set damage and trigger transform by using weston_view_geometry_dirty.
54 * 6/ Notify update of properties.
55 * 7/ Trigger composition by weston_compositor_schedule_repaint.
56 *
57 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090058#include "config.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090059
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090060#include <string.h>
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +000061#include <assert.h>
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090062
63#include "compositor.h"
64#include "ivi-layout-export.h"
65#include "ivi-layout-private.h"
66
Jon Cruz867d50e2015-06-15 15:37:10 -070067#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070068#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090069
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090070struct link_layer {
71 struct ivi_layout_layer *ivilayer;
72 struct wl_list link;
73 struct wl_list link_to_layer;
74};
75
76struct link_screen {
77 struct ivi_layout_screen *iviscrn;
78 struct wl_list link;
79 struct wl_list link_to_screen;
80};
81
82struct listener_layout_notification {
83 void *userdata;
84 struct wl_listener listener;
85};
86
87struct ivi_layout;
88
89struct ivi_layout_screen {
90 struct wl_list link;
91 struct wl_list link_to_layer;
92 uint32_t id_screen;
93
94 struct ivi_layout *layout;
95 struct weston_output *output;
96
97 uint32_t event_mask;
98
99 struct {
100 struct wl_list layer_list;
101 struct wl_list link;
102 } pending;
103
104 struct {
105 struct wl_list layer_list;
106 struct wl_list link;
107 } order;
108};
109
110struct ivi_layout_notification_callback {
111 void *callback;
112 void *data;
113};
114
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900115struct ivi_rectangle
116{
117 int32_t x;
118 int32_t y;
119 int32_t width;
120 int32_t height;
121};
122
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900123static void
124remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
125
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900126static struct ivi_layout ivilayout = {0};
127
128struct ivi_layout *
129get_instance(void)
130{
131 return &ivilayout;
132}
133
134/**
135 * Internal API to add/remove a link to ivi_surface from ivi_layer.
136 */
137static void
138add_link_to_surface(struct ivi_layout_layer *ivilayer,
139 struct link_layer *link_layer)
140{
141 struct link_layer *link = NULL;
142
143 wl_list_for_each(link, &ivilayer->link_to_surface, link_to_layer) {
144 if (link == link_layer)
145 return;
146 }
147
148 wl_list_insert(&ivilayer->link_to_surface, &link_layer->link_to_layer);
149}
150
151static void
152remove_link_to_surface(struct ivi_layout_layer *ivilayer)
153{
154 struct link_layer *link = NULL;
155 struct link_layer *next = NULL;
156
157 wl_list_for_each_safe(link, next, &ivilayer->link_to_surface, link_to_layer) {
158 if (!wl_list_empty(&link->link_to_layer)) {
159 wl_list_remove(&link->link_to_layer);
160 }
161 if (!wl_list_empty(&link->link)) {
162 wl_list_remove(&link->link);
163 }
164 free(link);
165 }
166
167 wl_list_init(&ivilayer->link_to_surface);
168}
169
170/**
171 * Internal API to add a link to ivi_layer from ivi_screen.
172 */
173static void
174add_link_to_layer(struct ivi_layout_screen *iviscrn,
175 struct link_screen *link_screen)
176{
177 wl_list_init(&link_screen->link_to_screen);
178 wl_list_insert(&iviscrn->link_to_layer, &link_screen->link_to_screen);
179}
180
181/**
182 * Internal API to add/remove a ivi_surface from ivi_layer.
183 */
184static void
185add_ordersurface_to_layer(struct ivi_layout_surface *ivisurf,
186 struct ivi_layout_layer *ivilayer)
187{
188 struct link_layer *link_layer = NULL;
189
190 link_layer = malloc(sizeof *link_layer);
191 if (link_layer == NULL) {
192 weston_log("fails to allocate memory\n");
193 return;
194 }
195
196 link_layer->ivilayer = ivilayer;
197 wl_list_init(&link_layer->link);
198 wl_list_insert(&ivisurf->layer_list, &link_layer->link);
199 add_link_to_surface(ivilayer, link_layer);
200}
201
202static void
203remove_ordersurface_from_layer(struct ivi_layout_surface *ivisurf)
204{
205 struct link_layer *link_layer = NULL;
206 struct link_layer *next = NULL;
207
208 wl_list_for_each_safe(link_layer, next, &ivisurf->layer_list, link) {
209 if (!wl_list_empty(&link_layer->link)) {
210 wl_list_remove(&link_layer->link);
211 }
212 if (!wl_list_empty(&link_layer->link_to_layer)) {
213 wl_list_remove(&link_layer->link_to_layer);
214 }
215 free(link_layer);
216 }
217 wl_list_init(&ivisurf->layer_list);
218}
219
220/**
221 * Internal API to add/remove a ivi_layer to/from ivi_screen.
222 */
223static void
224add_orderlayer_to_screen(struct ivi_layout_layer *ivilayer,
225 struct ivi_layout_screen *iviscrn)
226{
227 struct link_screen *link_scrn = NULL;
228
229 link_scrn = malloc(sizeof *link_scrn);
230 if (link_scrn == NULL) {
231 weston_log("fails to allocate memory\n");
232 return;
233 }
234
235 link_scrn->iviscrn = iviscrn;
236 wl_list_init(&link_scrn->link);
237 wl_list_insert(&ivilayer->screen_list, &link_scrn->link);
238 add_link_to_layer(iviscrn, link_scrn);
239}
240
241static void
242remove_orderlayer_from_screen(struct ivi_layout_layer *ivilayer)
243{
244 struct link_screen *link_scrn = NULL;
245 struct link_screen *next = NULL;
246
247 wl_list_for_each_safe(link_scrn, next, &ivilayer->screen_list, link) {
248 if (!wl_list_empty(&link_scrn->link)) {
249 wl_list_remove(&link_scrn->link);
250 }
251 if (!wl_list_empty(&link_scrn->link_to_screen)) {
252 wl_list_remove(&link_scrn->link_to_screen);
253 }
254 free(link_scrn);
255 }
256 wl_list_init(&ivilayer->screen_list);
257}
258
259/**
260 * Internal API to add/remove a ivi_layer to/from ivi_screen.
261 */
262static struct ivi_layout_surface *
263get_surface(struct wl_list *surf_list, uint32_t id_surface)
264{
265 struct ivi_layout_surface *ivisurf;
266
267 wl_list_for_each(ivisurf, surf_list, link) {
268 if (ivisurf->id_surface == id_surface) {
269 return ivisurf;
270 }
271 }
272
273 return NULL;
274}
275
276static struct ivi_layout_layer *
277get_layer(struct wl_list *layer_list, uint32_t id_layer)
278{
279 struct ivi_layout_layer *ivilayer;
280
281 wl_list_for_each(ivilayer, layer_list, link) {
282 if (ivilayer->id_layer == id_layer) {
283 return ivilayer;
284 }
285 }
286
287 return NULL;
288}
289
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900290static void
291remove_configured_listener(struct ivi_layout_surface *ivisurf)
292{
293 struct wl_listener *link = NULL;
294 struct wl_listener *next = NULL;
295
296 wl_list_for_each_safe(link, next, &ivisurf->configured.listener_list, link) {
297 wl_list_remove(&link->link);
298 }
299}
300
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900301static void
302remove_all_notification(struct wl_list *listener_list)
303{
304 struct wl_listener *listener = NULL;
305 struct wl_listener *next = NULL;
306
307 wl_list_for_each_safe(listener, next, listener_list, link) {
308 struct listener_layout_notification *notification = NULL;
309 if (!wl_list_empty(&listener->link)) {
310 wl_list_remove(&listener->link);
311 }
312
313 notification =
314 container_of(listener,
315 struct listener_layout_notification,
316 listener);
317
318 free(notification->userdata);
319 free(notification);
320 }
321}
322
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900323static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900324ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
325{
326 if (ivisurf == NULL) {
327 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
328 return;
329 }
330
331 remove_all_notification(&ivisurf->property_changed.listener_list);
332}
333
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900334static void
335ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
336 surface_property_notification_func callback,
337 void *userdata)
338{
339 if (ivisurf == NULL) {
340 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
341 return;
342 }
343
344 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
345}
346
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900347/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900348 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900349 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900350void
351ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900352{
353 struct ivi_layout *layout = get_instance();
354
355 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900356 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900357 return;
358 }
359
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900360 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900361 wl_list_remove(&ivisurf->pending.link);
362 wl_list_remove(&ivisurf->order.link);
363 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900364 remove_ordersurface_from_layer(ivisurf);
365
366 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
367
368 remove_configured_listener(ivisurf);
369
370 ivi_layout_surface_remove_notification(ivisurf);
371
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900372 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900373}
374
375/**
376 * Internal API to check ivi_layer/ivi_surface already added in ivi_layer/ivi_screen.
377 * Called by ivi_layout_layer_add_surface/ivi_layout_screenAddLayer
378 */
379static int
380is_surface_in_layer(struct ivi_layout_surface *ivisurf,
381 struct ivi_layout_layer *ivilayer)
382{
383 struct ivi_layout_surface *surf = NULL;
384
385 wl_list_for_each(surf, &ivilayer->pending.surface_list, pending.link) {
386 if (surf->id_surface == ivisurf->id_surface) {
387 return 1;
388 }
389 }
390
391 return 0;
392}
393
394static int
395is_layer_in_screen(struct ivi_layout_layer *ivilayer,
396 struct ivi_layout_screen *iviscrn)
397{
398 struct ivi_layout_layer *layer = NULL;
399
400 wl_list_for_each(layer, &iviscrn->pending.layer_list, pending.link) {
401 if (layer->id_layer == ivilayer->id_layer) {
402 return 1;
403 }
404 }
405
406 return 0;
407}
408
409/**
410 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
411 * Called by ivi_layout_init_with_compositor.
412 */
413static void
414create_screen(struct weston_compositor *ec)
415{
416 struct ivi_layout *layout = get_instance();
417 struct ivi_layout_screen *iviscrn = NULL;
418 struct weston_output *output = NULL;
419 int32_t count = 0;
420
421 wl_list_for_each(output, &ec->output_list, link) {
422 iviscrn = calloc(1, sizeof *iviscrn);
423 if (iviscrn == NULL) {
424 weston_log("fails to allocate memory\n");
425 continue;
426 }
427
428 wl_list_init(&iviscrn->link);
429 iviscrn->layout = layout;
430
431 iviscrn->id_screen = count;
432 count++;
433
434 iviscrn->output = output;
435 iviscrn->event_mask = 0;
436
437 wl_list_init(&iviscrn->pending.layer_list);
438 wl_list_init(&iviscrn->pending.link);
439
440 wl_list_init(&iviscrn->order.layer_list);
441 wl_list_init(&iviscrn->order.link);
442
443 wl_list_init(&iviscrn->link_to_layer);
444
445 wl_list_insert(&layout->screen_list, &iviscrn->link);
446 }
447}
448
449/**
450 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
451 */
452static void
453init_layer_properties(struct ivi_layout_layer_properties *prop,
454 int32_t width, int32_t height)
455{
456 memset(prop, 0, sizeof *prop);
457 prop->opacity = wl_fixed_from_double(1.0);
458 prop->source_width = width;
459 prop->source_height = height;
460 prop->dest_width = width;
461 prop->dest_height = height;
462}
463
464static void
465init_surface_properties(struct ivi_layout_surface_properties *prop)
466{
467 memset(prop, 0, sizeof *prop);
468 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900469 /*
470 * FIXME: this shall be finxed by ivi-layout-transition.
471 */
472 prop->dest_width = 1;
473 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900474}
475
476/**
477 * Internal APIs to be called from ivi_layout_commit_changes.
478 */
479static void
480update_opacity(struct ivi_layout_layer *ivilayer,
481 struct ivi_layout_surface *ivisurf)
482{
483 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
484 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
485
486 if ((ivilayer->event_mask & IVI_NOTIFICATION_OPACITY) ||
487 (ivisurf->event_mask & IVI_NOTIFICATION_OPACITY)) {
488 struct weston_view *tmpview = NULL;
489 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
490 if (tmpview == NULL) {
491 continue;
492 }
493 tmpview->alpha = layer_alpha * surf_alpha;
494 }
495 }
496}
497
498static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900499get_rotate_values(enum wl_output_transform orientation,
500 float *v_sin,
501 float *v_cos)
502{
503 switch (orientation) {
504 case WL_OUTPUT_TRANSFORM_90:
505 *v_sin = 1.0f;
506 *v_cos = 0.0f;
507 break;
508 case WL_OUTPUT_TRANSFORM_180:
509 *v_sin = 0.0f;
510 *v_cos = -1.0f;
511 break;
512 case WL_OUTPUT_TRANSFORM_270:
513 *v_sin = -1.0f;
514 *v_cos = 0.0f;
515 break;
516 case WL_OUTPUT_TRANSFORM_NORMAL:
517 default:
518 *v_sin = 0.0f;
519 *v_cos = 1.0f;
520 break;
521 }
522}
523
524static void
525get_scale(enum wl_output_transform orientation,
526 float dest_width,
527 float dest_height,
528 float source_width,
529 float source_height,
530 float *scale_x,
531 float *scale_y)
532{
533 switch (orientation) {
534 case WL_OUTPUT_TRANSFORM_90:
535 *scale_x = dest_width / source_height;
536 *scale_y = dest_height / source_width;
537 break;
538 case WL_OUTPUT_TRANSFORM_180:
539 *scale_x = dest_width / source_width;
540 *scale_y = dest_height / source_height;
541 break;
542 case WL_OUTPUT_TRANSFORM_270:
543 *scale_x = dest_width / source_height;
544 *scale_y = dest_height / source_width;
545 break;
546 case WL_OUTPUT_TRANSFORM_NORMAL:
547 default:
548 *scale_x = dest_width / source_width;
549 *scale_y = dest_height / source_height;
550 break;
551 }
552}
553
554static void
555calc_transformation_matrix(struct ivi_rectangle *source_rect,
556 struct ivi_rectangle *dest_rect,
557 enum wl_output_transform orientation,
558 struct weston_matrix *m)
559{
560 float source_center_x;
561 float source_center_y;
562 float vsin;
563 float vcos;
564 float scale_x;
565 float scale_y;
566 float translate_x;
567 float translate_y;
568
569 source_center_x = source_rect->x + source_rect->width * 0.5f;
570 source_center_y = source_rect->y + source_rect->height * 0.5f;
571 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
572
573 get_rotate_values(orientation, &vsin, &vcos);
574 weston_matrix_rotate_xy(m, vcos, vsin);
575
576 get_scale(orientation,
577 dest_rect->width,
578 dest_rect->height,
579 source_rect->width,
580 source_rect->height,
581 &scale_x,
582 &scale_y);
583 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
584
585 translate_x = dest_rect->width * 0.5f + dest_rect->x;
586 translate_y = dest_rect->height * 0.5f + dest_rect->y;
587 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
588}
589
590/**
591 * This computes the whole transformation matrix from surface-local
592 * coordinates to global coordinates. It is assumed that
593 * weston_view::geometry.{x,y} are zero.
594 */
595static void
596calc_surface_to_global_matrix(struct ivi_layout_layer *ivilayer,
597 struct ivi_layout_surface *ivisurf,
598 struct weston_matrix *m)
599{
600 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
601 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
602 struct ivi_rectangle surface_source_rect = { sp->source_x,
603 sp->source_y,
604 sp->source_width,
605 sp->source_height };
606 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
607 sp->dest_y,
608 sp->dest_width,
609 sp->dest_height };
610 struct ivi_rectangle layer_source_rect = { lp->source_x,
611 lp->source_y,
612 lp->source_width,
613 lp->source_height };
614 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
615 lp->dest_y,
616 lp->dest_width,
617 lp->dest_height };
618
619 calc_transformation_matrix(&surface_source_rect,
620 &surface_dest_rect,
621 sp->orientation, m);
622
623 calc_transformation_matrix(&layer_source_rect,
624 &layer_dest_rect,
625 lp->orientation, m);
626}
627
628static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900629update_prop(struct ivi_layout_layer *ivilayer,
630 struct ivi_layout_surface *ivisurf)
631{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900632 struct weston_view *tmpview;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900633 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900634
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900635 if (!ivilayer->event_mask && !ivisurf->event_mask) {
636 return;
637 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900638
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900639 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900640
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900641 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900642 if (tmpview != NULL) {
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900643 break;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900644 }
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900645 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900646
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900647 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
648 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
649 can_calc = false;
650 }
651
652 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
653 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
654 can_calc = false;
655 }
656
657 if (can_calc) {
658 wl_list_remove(&ivisurf->transform.link);
659 weston_matrix_init(&ivisurf->transform.matrix);
660
661 calc_surface_to_global_matrix(ivilayer, ivisurf, &ivisurf->transform.matrix);
662
663 if (tmpview != NULL) {
664 wl_list_insert(&tmpview->geometry.transformation_list, &ivisurf->transform.link);
665
666 weston_view_set_transform_parent(tmpview, NULL);
667 }
668 }
669
670 ivisurf->update_count++;
671
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900672 if (tmpview != NULL) {
673 weston_view_geometry_dirty(tmpview);
674 }
675
676 if (ivisurf->surface != NULL) {
677 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900678 }
679}
680
681static void
682commit_changes(struct ivi_layout *layout)
683{
684 struct ivi_layout_screen *iviscrn = NULL;
685 struct ivi_layout_layer *ivilayer = NULL;
686 struct ivi_layout_surface *ivisurf = NULL;
687
688 wl_list_for_each(iviscrn, &layout->screen_list, link) {
689 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
690 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
691 update_prop(ivilayer, ivisurf);
692 }
693 }
694 }
695}
696
697static void
698commit_surface_list(struct ivi_layout *layout)
699{
700 struct ivi_layout_surface *ivisurf = NULL;
701 int32_t dest_x = 0;
702 int32_t dest_y = 0;
703 int32_t dest_width = 0;
704 int32_t dest_height = 0;
705 int32_t configured = 0;
706
707 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300708 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900709 dest_x = ivisurf->prop.dest_x;
710 dest_y = ivisurf->prop.dest_y;
711 dest_width = ivisurf->prop.dest_width;
712 dest_height = ivisurf->prop.dest_height;
713
714 ivi_layout_transition_move_resize_view(ivisurf,
715 ivisurf->pending.prop.dest_x,
716 ivisurf->pending.prop.dest_y,
717 ivisurf->pending.prop.dest_width,
718 ivisurf->pending.prop.dest_height,
719 ivisurf->pending.prop.transition_duration);
720
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300721 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900722 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
723 } else {
724 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
725 }
726
727 ivisurf->prop = ivisurf->pending.prop;
728 ivisurf->prop.dest_x = dest_x;
729 ivisurf->prop.dest_y = dest_y;
730 ivisurf->prop.dest_width = dest_width;
731 ivisurf->prop.dest_height = dest_height;
732 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
733 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
734
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300735 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900736 dest_x = ivisurf->prop.dest_x;
737 dest_y = ivisurf->prop.dest_y;
738 dest_width = ivisurf->prop.dest_width;
739 dest_height = ivisurf->prop.dest_height;
740
741 ivi_layout_transition_move_resize_view(ivisurf,
742 ivisurf->pending.prop.dest_x,
743 ivisurf->pending.prop.dest_y,
744 ivisurf->pending.prop.dest_width,
745 ivisurf->pending.prop.dest_height,
746 ivisurf->pending.prop.transition_duration);
747
748 ivisurf->prop = ivisurf->pending.prop;
749 ivisurf->prop.dest_x = dest_x;
750 ivisurf->prop.dest_y = dest_y;
751 ivisurf->prop.dest_width = dest_width;
752 ivisurf->prop.dest_height = dest_height;
753
754 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
755 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
756
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300757 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900758 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300759 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900760 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
761 } else {
762 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
763 }
764
765 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
766 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
767 configured = 1;
768 }
769
770 ivisurf->prop = ivisurf->pending.prop;
771 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
772 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
773
774 if (configured && !is_surface_transition(ivisurf))
775 wl_signal_emit(&ivisurf->configured, ivisurf);
776 } else {
777 configured = 0;
778 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
779 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
780 configured = 1;
781 }
782
783 ivisurf->prop = ivisurf->pending.prop;
784 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
785 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
786
787 if (configured && !is_surface_transition(ivisurf))
788 wl_signal_emit(&ivisurf->configured, ivisurf);
789 }
790 }
791}
792
793static void
794commit_layer_list(struct ivi_layout *layout)
795{
796 struct ivi_layout_layer *ivilayer = NULL;
797 struct ivi_layout_surface *ivisurf = NULL;
798 struct ivi_layout_surface *next = NULL;
799
800 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300801 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900802 ivi_layout_transition_move_layer(ivilayer, ivilayer->pending.prop.dest_x, ivilayer->pending.prop.dest_y, ivilayer->pending.prop.transition_duration);
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300803 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900804 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
805 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
806 NULL, NULL,
807 ivilayer->pending.prop.transition_duration);
808 }
809 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
810
811 ivilayer->prop = ivilayer->pending.prop;
812
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000813 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900814 continue;
815 }
816
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000817 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
818 order.link) {
819 remove_ordersurface_from_layer(ivisurf);
820 wl_list_remove(&ivisurf->order.link);
821 wl_list_init(&ivisurf->order.link);
822 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900823 }
824
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000825 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900826
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000827 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900828 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000829 wl_list_remove(&ivisurf->order.link);
830 wl_list_insert(&ivilayer->order.surface_list,
831 &ivisurf->order.link);
832 add_ordersurface_to_layer(ivisurf, ivilayer);
833 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900834 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000835
836 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900837 }
838}
839
840static void
841commit_screen_list(struct ivi_layout *layout)
842{
843 struct ivi_layout_screen *iviscrn = NULL;
844 struct ivi_layout_layer *ivilayer = NULL;
845 struct ivi_layout_layer *next = NULL;
846 struct ivi_layout_surface *ivisurf = NULL;
847
848 wl_list_for_each(iviscrn, &layout->screen_list, link) {
849 if (iviscrn->event_mask & IVI_NOTIFICATION_REMOVE) {
850 wl_list_for_each_safe(ivilayer, next,
851 &iviscrn->order.layer_list, order.link) {
852 remove_orderlayer_from_screen(ivilayer);
853
854 if (!wl_list_empty(&ivilayer->order.link)) {
855 wl_list_remove(&ivilayer->order.link);
856 }
857
858 wl_list_init(&ivilayer->order.link);
859 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
860 }
861 }
862
863 if (iviscrn->event_mask & IVI_NOTIFICATION_ADD) {
864 wl_list_for_each_safe(ivilayer, next,
865 &iviscrn->order.layer_list, order.link) {
866 remove_orderlayer_from_screen(ivilayer);
867
868 if (!wl_list_empty(&ivilayer->order.link)) {
869 wl_list_remove(&ivilayer->order.link);
870 }
871
872 wl_list_init(&ivilayer->order.link);
873 }
874
875 wl_list_init(&iviscrn->order.layer_list);
876 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
877 pending.link) {
878 wl_list_insert(&iviscrn->order.layer_list,
879 &ivilayer->order.link);
880 add_orderlayer_to_screen(ivilayer, iviscrn);
881 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
882 }
883 }
884
885 iviscrn->event_mask = 0;
886
887 /* Clear view list of layout ivi_layer */
888 wl_list_init(&layout->layout_layer.view_list.link);
889
890 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
891 if (ivilayer->prop.visibility == false)
892 continue;
893
894 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
895 struct weston_view *tmpview = NULL;
896 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
897 if (tmpview != NULL) {
898 break;
899 }
900 }
901
902 if (ivisurf->prop.visibility == false)
903 continue;
904 if (ivisurf->surface == NULL || tmpview == NULL)
905 continue;
906
907 weston_layer_entry_insert(&layout->layout_layer.view_list,
908 &tmpview->layer_link);
909
910 ivisurf->surface->output = iviscrn->output;
911 }
912 }
913
914 break;
915 }
916}
917
918static void
919commit_transition(struct ivi_layout* layout)
920{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300921 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900922 return;
923 }
924
925 wl_list_insert_list(&layout->transitions->transition_list,
926 &layout->pending_transition_list);
927
928 wl_list_init(&layout->pending_transition_list);
929
930 wl_event_source_timer_update(layout->transitions->event_source, 1);
931}
932
933static void
934send_surface_prop(struct ivi_layout_surface *ivisurf)
935{
936 wl_signal_emit(&ivisurf->property_changed, ivisurf);
937 ivisurf->event_mask = 0;
938}
939
940static void
941send_layer_prop(struct ivi_layout_layer *ivilayer)
942{
943 wl_signal_emit(&ivilayer->property_changed, ivilayer);
944 ivilayer->event_mask = 0;
945}
946
947static void
948send_prop(struct ivi_layout *layout)
949{
950 struct ivi_layout_layer *ivilayer = NULL;
951 struct ivi_layout_surface *ivisurf = NULL;
952
953 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900954 if (ivilayer->event_mask)
955 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900956 }
957
958 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900959 if (ivisurf->event_mask)
960 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900961 }
962}
963
964static void
965clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
966{
967 struct ivi_layout_surface *surface_link = NULL;
968 struct ivi_layout_surface *surface_next = NULL;
969
970 wl_list_for_each_safe(surface_link, surface_next,
971 &ivilayer->pending.surface_list, pending.link) {
972 if (!wl_list_empty(&surface_link->pending.link)) {
973 wl_list_remove(&surface_link->pending.link);
974 }
975
976 wl_list_init(&surface_link->pending.link);
977 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900978}
979
980static void
981clear_surface_order_list(struct ivi_layout_layer *ivilayer)
982{
983 struct ivi_layout_surface *surface_link = NULL;
984 struct ivi_layout_surface *surface_next = NULL;
985
986 wl_list_for_each_safe(surface_link, surface_next,
987 &ivilayer->order.surface_list, order.link) {
988 if (!wl_list_empty(&surface_link->order.link)) {
989 wl_list_remove(&surface_link->order.link);
990 }
991
992 wl_list_init(&surface_link->order.link);
993 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900994}
995
996static void
997layer_created(struct wl_listener *listener, void *data)
998{
999 struct ivi_layout_layer *ivilayer = data;
1000
1001 struct listener_layout_notification *notification =
1002 container_of(listener,
1003 struct listener_layout_notification,
1004 listener);
1005
1006 struct ivi_layout_notification_callback *created_callback =
1007 notification->userdata;
1008
1009 ((layer_create_notification_func)created_callback->callback)
1010 (ivilayer, created_callback->data);
1011}
1012
1013static void
1014layer_removed(struct wl_listener *listener, void *data)
1015{
1016 struct ivi_layout_layer *ivilayer = data;
1017
1018 struct listener_layout_notification *notification =
1019 container_of(listener,
1020 struct listener_layout_notification,
1021 listener);
1022
1023 struct ivi_layout_notification_callback *removed_callback =
1024 notification->userdata;
1025
1026 ((layer_remove_notification_func)removed_callback->callback)
1027 (ivilayer, removed_callback->data);
1028}
1029
1030static void
1031layer_prop_changed(struct wl_listener *listener, void *data)
1032{
1033 struct ivi_layout_layer *ivilayer = data;
1034
1035 struct listener_layout_notification *layout_listener =
1036 container_of(listener,
1037 struct listener_layout_notification,
1038 listener);
1039
1040 struct ivi_layout_notification_callback *prop_callback =
1041 layout_listener->userdata;
1042
1043 ((layer_property_notification_func)prop_callback->callback)
1044 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1045}
1046
1047static void
1048surface_created(struct wl_listener *listener, void *data)
1049{
1050 struct ivi_layout_surface *ivisurface = data;
1051
1052 struct listener_layout_notification *notification =
1053 container_of(listener,
1054 struct listener_layout_notification,
1055 listener);
1056
1057 struct ivi_layout_notification_callback *created_callback =
1058 notification->userdata;
1059
1060 ((surface_create_notification_func)created_callback->callback)
1061 (ivisurface, created_callback->data);
1062}
1063
1064static void
1065surface_removed(struct wl_listener *listener, void *data)
1066{
1067 struct ivi_layout_surface *ivisurface = data;
1068
1069 struct listener_layout_notification *notification =
1070 container_of(listener,
1071 struct listener_layout_notification,
1072 listener);
1073
1074 struct ivi_layout_notification_callback *removed_callback =
1075 notification->userdata;
1076
1077 ((surface_remove_notification_func)removed_callback->callback)
1078 (ivisurface, removed_callback->data);
1079}
1080
1081static void
1082surface_prop_changed(struct wl_listener *listener, void *data)
1083{
1084 struct ivi_layout_surface *ivisurf = data;
1085
1086 struct listener_layout_notification *layout_listener =
1087 container_of(listener,
1088 struct listener_layout_notification,
1089 listener);
1090
1091 struct ivi_layout_notification_callback *prop_callback =
1092 layout_listener->userdata;
1093
1094 ((surface_property_notification_func)prop_callback->callback)
1095 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1096
1097 ivisurf->event_mask = 0;
1098}
1099
1100static void
1101surface_configure_changed(struct wl_listener *listener,
1102 void *data)
1103{
1104 struct ivi_layout_surface *ivisurface = data;
1105
1106 struct listener_layout_notification *notification =
1107 container_of(listener,
1108 struct listener_layout_notification,
1109 listener);
1110
1111 struct ivi_layout_notification_callback *configure_changed_callback =
1112 notification->userdata;
1113
1114 ((surface_configure_notification_func)configure_changed_callback->callback)
1115 (ivisurface, configure_changed_callback->data);
1116}
1117
1118static int32_t
1119add_notification(struct wl_signal *signal,
1120 wl_notify_func_t callback,
1121 void *userdata)
1122{
1123 struct listener_layout_notification *notification = NULL;
1124
1125 notification = malloc(sizeof *notification);
1126 if (notification == NULL) {
1127 weston_log("fails to allocate memory\n");
1128 free(userdata);
1129 return IVI_FAILED;
1130 }
1131
1132 notification->listener.notify = callback;
1133 notification->userdata = userdata;
1134
1135 wl_signal_add(signal, &notification->listener);
1136
1137 return IVI_SUCCEEDED;
1138}
1139
1140static void
1141remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1142{
1143 struct wl_listener *listener = NULL;
1144 struct wl_listener *next = NULL;
1145
1146 wl_list_for_each_safe(listener, next, listener_list, link) {
1147 struct listener_layout_notification *notification =
1148 container_of(listener,
1149 struct listener_layout_notification,
1150 listener);
1151
1152 struct ivi_layout_notification_callback *notification_callback =
1153 notification->userdata;
1154
1155 if ((notification_callback->callback != callback) ||
1156 (notification_callback->data != userdata)) {
1157 continue;
1158 }
1159
1160 if (!wl_list_empty(&listener->link)) {
1161 wl_list_remove(&listener->link);
1162 }
1163
1164 free(notification->userdata);
1165 free(notification);
1166 }
1167}
1168
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001169/**
1170 * Exported APIs of ivi-layout library are implemented from here.
1171 * Brief of APIs is described in ivi-layout-export.h.
1172 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001173static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001174ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1175 void *userdata)
1176{
1177 struct ivi_layout *layout = get_instance();
1178 struct ivi_layout_notification_callback *created_callback = NULL;
1179
1180 if (callback == NULL) {
1181 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1182 return IVI_FAILED;
1183 }
1184
1185 created_callback = malloc(sizeof *created_callback);
1186 if (created_callback == NULL) {
1187 weston_log("fails to allocate memory\n");
1188 return IVI_FAILED;
1189 }
1190
1191 created_callback->callback = callback;
1192 created_callback->data = userdata;
1193
1194 return add_notification(&layout->layer_notification.created,
1195 layer_created,
1196 created_callback);
1197}
1198
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001199static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001200ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1201 void *userdata)
1202{
1203 struct ivi_layout *layout = get_instance();
1204 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1205}
1206
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001207static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001208ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1209 void *userdata)
1210{
1211 struct ivi_layout *layout = get_instance();
1212 struct ivi_layout_notification_callback *removed_callback = NULL;
1213
1214 if (callback == NULL) {
1215 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1216 return IVI_FAILED;
1217 }
1218
1219 removed_callback = malloc(sizeof *removed_callback);
1220 if (removed_callback == NULL) {
1221 weston_log("fails to allocate memory\n");
1222 return IVI_FAILED;
1223 }
1224
1225 removed_callback->callback = callback;
1226 removed_callback->data = userdata;
1227 return add_notification(&layout->layer_notification.removed,
1228 layer_removed,
1229 removed_callback);
1230}
1231
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001232static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001233ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1234 void *userdata)
1235{
1236 struct ivi_layout *layout = get_instance();
1237 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1238}
1239
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001240static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001241ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1242 void *userdata)
1243{
1244 struct ivi_layout *layout = get_instance();
1245 struct ivi_layout_notification_callback *created_callback = NULL;
1246
1247 if (callback == NULL) {
1248 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1249 return IVI_FAILED;
1250 }
1251
1252 created_callback = malloc(sizeof *created_callback);
1253 if (created_callback == NULL) {
1254 weston_log("fails to allocate memory\n");
1255 return IVI_FAILED;
1256 }
1257
1258 created_callback->callback = callback;
1259 created_callback->data = userdata;
1260
1261 return add_notification(&layout->surface_notification.created,
1262 surface_created,
1263 created_callback);
1264}
1265
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001266static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001267ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1268 void *userdata)
1269{
1270 struct ivi_layout *layout = get_instance();
1271 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1272}
1273
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001274static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001275ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1276 void *userdata)
1277{
1278 struct ivi_layout *layout = get_instance();
1279 struct ivi_layout_notification_callback *removed_callback = NULL;
1280
1281 if (callback == NULL) {
1282 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1283 return IVI_FAILED;
1284 }
1285
1286 removed_callback = malloc(sizeof *removed_callback);
1287 if (removed_callback == NULL) {
1288 weston_log("fails to allocate memory\n");
1289 return IVI_FAILED;
1290 }
1291
1292 removed_callback->callback = callback;
1293 removed_callback->data = userdata;
1294
1295 return add_notification(&layout->surface_notification.removed,
1296 surface_removed,
1297 removed_callback);
1298}
1299
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001300static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001301ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1302 void *userdata)
1303{
1304 struct ivi_layout *layout = get_instance();
1305 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1306}
1307
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001308static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001309ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1310 void *userdata)
1311{
1312 struct ivi_layout *layout = get_instance();
1313 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1314 if (callback == NULL) {
1315 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1316 return IVI_FAILED;
1317 }
1318
1319 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1320 if (configure_changed_callback == NULL) {
1321 weston_log("fails to allocate memory\n");
1322 return IVI_FAILED;
1323 }
1324
1325 configure_changed_callback->callback = callback;
1326 configure_changed_callback->data = userdata;
1327
1328 return add_notification(&layout->surface_notification.configure_changed,
1329 surface_configure_changed,
1330 configure_changed_callback);
1331}
1332
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001333static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001334ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1335 void *userdata)
1336{
1337 struct ivi_layout *layout = get_instance();
1338 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1339}
1340
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001341uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001342ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1343{
1344 return ivisurf->id_surface;
1345}
1346
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001347static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001348ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1349{
1350 return ivilayer->id_layer;
1351}
1352
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001353static uint32_t
1354ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1355{
1356 return iviscrn->id_screen;
1357}
1358
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001359static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001360ivi_layout_get_layer_from_id(uint32_t id_layer)
1361{
1362 struct ivi_layout *layout = get_instance();
1363 struct ivi_layout_layer *ivilayer = NULL;
1364
1365 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1366 if (ivilayer->id_layer == id_layer) {
1367 return ivilayer;
1368 }
1369 }
1370
1371 return NULL;
1372}
1373
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001374struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001375ivi_layout_get_surface_from_id(uint32_t id_surface)
1376{
1377 struct ivi_layout *layout = get_instance();
1378 struct ivi_layout_surface *ivisurf = NULL;
1379
1380 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1381 if (ivisurf->id_surface == id_surface) {
1382 return ivisurf;
1383 }
1384 }
1385
1386 return NULL;
1387}
1388
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001389static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001390ivi_layout_get_screen_from_id(uint32_t id_screen)
1391{
1392 struct ivi_layout *layout = get_instance();
1393 struct ivi_layout_screen *iviscrn = NULL;
1394
1395 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1396/* FIXME : select iviscrn from screen_list by id_screen */
1397 return iviscrn;
1398 break;
1399 }
1400
1401 return NULL;
1402}
1403
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001404static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001405ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1406 int32_t *pWidth, int32_t *pHeight)
1407{
1408 struct weston_output *output = NULL;
1409
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001410 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001411 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1412 return IVI_FAILED;
1413 }
1414
1415 output = iviscrn->output;
1416 *pWidth = output->current_mode->width;
1417 *pHeight = output->current_mode->height;
1418
1419 return IVI_SUCCEEDED;
1420}
1421
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001422static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001423ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1424 surface_property_notification_func callback,
1425 void *userdata)
1426{
1427 struct listener_layout_notification* notification = NULL;
1428 struct ivi_layout_notification_callback *prop_callback = NULL;
1429
1430 if (ivisurf == NULL || callback == NULL) {
1431 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1432 return IVI_FAILED;
1433 }
1434
1435 notification = malloc(sizeof *notification);
1436 if (notification == NULL) {
1437 weston_log("fails to allocate memory\n");
1438 return IVI_FAILED;
1439 }
1440
1441 prop_callback = malloc(sizeof *prop_callback);
1442 if (prop_callback == NULL) {
1443 weston_log("fails to allocate memory\n");
1444 return IVI_FAILED;
1445 }
1446
1447 prop_callback->callback = callback;
1448 prop_callback->data = userdata;
1449
1450 notification->listener.notify = surface_prop_changed;
1451 notification->userdata = prop_callback;
1452
1453 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1454
1455 return IVI_SUCCEEDED;
1456}
1457
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001458static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001459ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1460{
1461 if (ivilayer == NULL) {
1462 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1463 return NULL;
1464 }
1465
1466 return &ivilayer->prop;
1467}
1468
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001469static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001470ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1471{
1472 struct ivi_layout *layout = get_instance();
1473 struct ivi_layout_screen *iviscrn = NULL;
1474 int32_t length = 0;
1475 int32_t n = 0;
1476
1477 if (pLength == NULL || ppArray == NULL) {
1478 weston_log("ivi_layout_get_screens: invalid argument\n");
1479 return IVI_FAILED;
1480 }
1481
1482 length = wl_list_length(&layout->screen_list);
1483
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001484 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001485 /* the Array must be free by module which called this function */
1486 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1487 if (*ppArray == NULL) {
1488 weston_log("fails to allocate memory\n");
1489 return IVI_FAILED;
1490 }
1491
1492 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1493 (*ppArray)[n++] = iviscrn;
1494 }
1495 }
1496
1497 *pLength = length;
1498
1499 return IVI_SUCCEEDED;
1500}
1501
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001502static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001503ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1504 int32_t *pLength,
1505 struct ivi_layout_screen ***ppArray)
1506{
1507 struct link_screen *link_scrn = NULL;
1508 int32_t length = 0;
1509 int32_t n = 0;
1510
1511 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1512 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1513 return IVI_FAILED;
1514 }
1515
1516 length = wl_list_length(&ivilayer->screen_list);
1517
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001518 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001519 /* the Array must be free by module which called this function */
1520 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1521 if (*ppArray == NULL) {
1522 weston_log("fails to allocate memory\n");
1523 return IVI_FAILED;
1524 }
1525
1526 wl_list_for_each(link_scrn, &ivilayer->screen_list, link) {
1527 (*ppArray)[n++] = link_scrn->iviscrn;
1528 }
1529 }
1530
1531 *pLength = length;
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_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1538{
1539 struct ivi_layout *layout = get_instance();
1540 struct ivi_layout_layer *ivilayer = NULL;
1541 int32_t length = 0;
1542 int32_t n = 0;
1543
1544 if (pLength == NULL || ppArray == NULL) {
1545 weston_log("ivi_layout_get_layers: invalid argument\n");
1546 return IVI_FAILED;
1547 }
1548
1549 length = wl_list_length(&layout->layer_list);
1550
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001551 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001552 /* the Array must be free by module which called this function */
1553 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1554 if (*ppArray == NULL) {
1555 weston_log("fails to allocate memory\n");
1556 return IVI_FAILED;
1557 }
1558
1559 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1560 (*ppArray)[n++] = ivilayer;
1561 }
1562 }
1563
1564 *pLength = length;
1565
1566 return IVI_SUCCEEDED;
1567}
1568
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001569static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001570ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1571 int32_t *pLength,
1572 struct ivi_layout_layer ***ppArray)
1573{
1574 struct ivi_layout_layer *ivilayer = NULL;
1575 int32_t length = 0;
1576 int32_t n = 0;
1577
1578 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1579 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1580 return IVI_FAILED;
1581 }
1582
1583 length = wl_list_length(&iviscrn->order.layer_list);
1584
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001585 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001586 /* the Array must be free by module which called this function */
1587 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1588 if (*ppArray == NULL) {
1589 weston_log("fails to allocate memory\n");
1590 return IVI_FAILED;
1591 }
1592
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001593 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001594 (*ppArray)[n++] = ivilayer;
1595 }
1596 }
1597
1598 *pLength = length;
1599
1600 return IVI_SUCCEEDED;
1601}
1602
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001603static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001604ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1605 int32_t *pLength,
1606 struct ivi_layout_layer ***ppArray)
1607{
1608 struct link_layer *link_layer = NULL;
1609 int32_t length = 0;
1610 int32_t n = 0;
1611
1612 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1613 weston_log("ivi_layout_getLayers: invalid argument\n");
1614 return IVI_FAILED;
1615 }
1616
1617 length = wl_list_length(&ivisurf->layer_list);
1618
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001619 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001620 /* the Array must be free by module which called this function */
1621 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1622 if (*ppArray == NULL) {
1623 weston_log("fails to allocate memory\n");
1624 return IVI_FAILED;
1625 }
1626
1627 wl_list_for_each(link_layer, &ivisurf->layer_list, link) {
1628 (*ppArray)[n++] = link_layer->ivilayer;
1629 }
1630 }
1631
1632 *pLength = length;
1633
1634 return IVI_SUCCEEDED;
1635}
1636
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001637static
1638int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001639ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1640{
1641 struct ivi_layout *layout = get_instance();
1642 struct ivi_layout_surface *ivisurf = NULL;
1643 int32_t length = 0;
1644 int32_t n = 0;
1645
1646 if (pLength == NULL || ppArray == NULL) {
1647 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1648 return IVI_FAILED;
1649 }
1650
1651 length = wl_list_length(&layout->surface_list);
1652
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001653 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001654 /* the Array must be free by module which called this function */
1655 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1656 if (*ppArray == NULL) {
1657 weston_log("fails to allocate memory\n");
1658 return IVI_FAILED;
1659 }
1660
1661 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1662 (*ppArray)[n++] = ivisurf;
1663 }
1664 }
1665
1666 *pLength = length;
1667
1668 return IVI_SUCCEEDED;
1669}
1670
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001671static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001672ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1673 int32_t *pLength,
1674 struct ivi_layout_surface ***ppArray)
1675{
1676 struct ivi_layout_surface *ivisurf = NULL;
1677 int32_t length = 0;
1678 int32_t n = 0;
1679
1680 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1681 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1682 return IVI_FAILED;
1683 }
1684
1685 length = wl_list_length(&ivilayer->order.surface_list);
1686
1687 if (length != 0) {
1688 /* the Array must be free by module which called this function */
1689 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1690 if (*ppArray == NULL) {
1691 weston_log("fails to allocate memory\n");
1692 return IVI_FAILED;
1693 }
1694
1695 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1696 (*ppArray)[n++] = ivisurf;
1697 }
1698 }
1699
1700 *pLength = length;
1701
1702 return IVI_SUCCEEDED;
1703}
1704
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001705static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001706ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1707 int32_t width, int32_t height)
1708{
1709 struct ivi_layout *layout = get_instance();
1710 struct ivi_layout_layer *ivilayer = NULL;
1711
1712 ivilayer = get_layer(&layout->layer_list, id_layer);
1713 if (ivilayer != NULL) {
1714 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001715 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001716 return ivilayer;
1717 }
1718
1719 ivilayer = calloc(1, sizeof *ivilayer);
1720 if (ivilayer == NULL) {
1721 weston_log("fails to allocate memory\n");
1722 return NULL;
1723 }
1724
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001725 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001726 wl_list_init(&ivilayer->link);
1727 wl_signal_init(&ivilayer->property_changed);
1728 wl_list_init(&ivilayer->screen_list);
1729 wl_list_init(&ivilayer->link_to_surface);
1730 ivilayer->layout = layout;
1731 ivilayer->id_layer = id_layer;
1732
1733 init_layer_properties(&ivilayer->prop, width, height);
1734 ivilayer->event_mask = 0;
1735
1736 wl_list_init(&ivilayer->pending.surface_list);
1737 wl_list_init(&ivilayer->pending.link);
1738 ivilayer->pending.prop = ivilayer->prop;
1739
1740 wl_list_init(&ivilayer->order.surface_list);
1741 wl_list_init(&ivilayer->order.link);
1742
1743 wl_list_insert(&layout->layer_list, &ivilayer->link);
1744
1745 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1746
1747 return ivilayer;
1748}
1749
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001750static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001751ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1752{
1753 if (ivilayer == NULL) {
1754 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1755 return;
1756 }
1757
1758 remove_all_notification(&ivilayer->property_changed.listener_list);
1759}
1760
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001761static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001762ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1763 layer_property_notification_func callback,
1764 void *userdata)
1765{
1766 if (ivilayer == NULL) {
1767 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1768 return;
1769 }
1770
1771 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1772}
1773
1774static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001775ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001776{
1777 struct ivi_layout *layout = get_instance();
1778
1779 if (ivilayer == NULL) {
1780 weston_log("ivi_layout_layer_remove: invalid argument\n");
1781 return;
1782 }
1783
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001784 if (--ivilayer->ref_count > 0)
1785 return;
1786
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001787 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1788
1789 clear_surface_pending_list(ivilayer);
1790 clear_surface_order_list(ivilayer);
1791
1792 if (!wl_list_empty(&ivilayer->pending.link)) {
1793 wl_list_remove(&ivilayer->pending.link);
1794 }
1795 if (!wl_list_empty(&ivilayer->order.link)) {
1796 wl_list_remove(&ivilayer->order.link);
1797 }
1798 if (!wl_list_empty(&ivilayer->link)) {
1799 wl_list_remove(&ivilayer->link);
1800 }
1801 remove_orderlayer_from_screen(ivilayer);
1802 remove_link_to_surface(ivilayer);
1803 ivi_layout_layer_remove_notification(ivilayer);
1804
1805 free(ivilayer);
1806}
1807
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001808int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001809ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1810 bool newVisibility)
1811{
1812 struct ivi_layout_layer_properties *prop = NULL;
1813
1814 if (ivilayer == NULL) {
1815 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1816 return IVI_FAILED;
1817 }
1818
1819 prop = &ivilayer->pending.prop;
1820 prop->visibility = newVisibility;
1821
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001822 if (ivilayer->prop.visibility != newVisibility)
1823 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1824 else
1825 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001826
1827 return IVI_SUCCEEDED;
1828}
1829
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001830static bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001831ivi_layout_layer_get_visibility(struct ivi_layout_layer *ivilayer)
1832{
1833 if (ivilayer == NULL) {
1834 weston_log("ivi_layout_layer_get_visibility: invalid argument\n");
1835 return false;
1836 }
1837
1838 return ivilayer->prop.visibility;
1839}
1840
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001841int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001842ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1843 wl_fixed_t opacity)
1844{
1845 struct ivi_layout_layer_properties *prop = NULL;
1846
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001847 if (ivilayer == NULL ||
1848 opacity < wl_fixed_from_double(0.0) ||
1849 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001850 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1851 return IVI_FAILED;
1852 }
1853
1854 prop = &ivilayer->pending.prop;
1855 prop->opacity = opacity;
1856
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001857 if (ivilayer->prop.opacity != opacity)
1858 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1859 else
1860 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001861
1862 return IVI_SUCCEEDED;
1863}
1864
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001865wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001866ivi_layout_layer_get_opacity(struct ivi_layout_layer *ivilayer)
1867{
1868 if (ivilayer == NULL) {
1869 weston_log("ivi_layout_layer_get_opacity: invalid argument\n");
1870 return wl_fixed_from_double(0.0);
1871 }
1872
1873 return ivilayer->prop.opacity;
1874}
1875
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001876static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001877ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1878 int32_t x, int32_t y,
1879 int32_t width, int32_t height)
1880{
1881 struct ivi_layout_layer_properties *prop = NULL;
1882
1883 if (ivilayer == NULL) {
1884 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1885 return IVI_FAILED;
1886 }
1887
1888 prop = &ivilayer->pending.prop;
1889 prop->source_x = x;
1890 prop->source_y = y;
1891 prop->source_width = width;
1892 prop->source_height = height;
1893
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001894 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1895 ivilayer->prop.source_width != width ||
1896 ivilayer->prop.source_height != height)
1897 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1898 else
1899 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001900
1901 return IVI_SUCCEEDED;
1902}
1903
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001904static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001905ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1906 int32_t x, int32_t y,
1907 int32_t width, int32_t height)
1908{
1909 struct ivi_layout_layer_properties *prop = NULL;
1910
1911 if (ivilayer == NULL) {
1912 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1913 return IVI_FAILED;
1914 }
1915
1916 prop = &ivilayer->pending.prop;
1917 prop->dest_x = x;
1918 prop->dest_y = y;
1919 prop->dest_width = width;
1920 prop->dest_height = height;
1921
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001922 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1923 ivilayer->prop.dest_width != width ||
1924 ivilayer->prop.dest_height != height)
1925 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1926 else
1927 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001928
1929 return IVI_SUCCEEDED;
1930}
1931
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001932static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001933ivi_layout_layer_get_dimension(struct ivi_layout_layer *ivilayer,
1934 int32_t *dest_width, int32_t *dest_height)
1935{
1936 if (ivilayer == NULL || dest_width == NULL || dest_height == NULL) {
1937 weston_log("ivi_layout_layer_get_dimension: invalid argument\n");
1938 return IVI_FAILED;
1939 }
1940
1941 *dest_width = ivilayer->prop.dest_width;
1942 *dest_height = ivilayer->prop.dest_height;
1943
1944 return IVI_SUCCEEDED;
1945}
1946
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001947static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001948ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
1949 int32_t dest_width, int32_t dest_height)
1950{
1951 struct ivi_layout_layer_properties *prop = NULL;
1952
1953 if (ivilayer == NULL) {
1954 weston_log("ivi_layout_layer_set_dimension: invalid argument\n");
1955 return IVI_FAILED;
1956 }
1957
1958 prop = &ivilayer->pending.prop;
1959
1960 prop->dest_width = dest_width;
1961 prop->dest_height = dest_height;
1962
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001963 if (ivilayer->prop.dest_width != dest_width ||
1964 ivilayer->prop.dest_height != dest_height)
1965 ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
1966 else
1967 ivilayer->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001968
1969 return IVI_SUCCEEDED;
1970}
1971
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001972int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001973ivi_layout_layer_get_position(struct ivi_layout_layer *ivilayer,
1974 int32_t *dest_x, int32_t *dest_y)
1975{
1976 if (ivilayer == NULL || dest_x == NULL || dest_y == NULL) {
1977 weston_log("ivi_layout_layer_get_position: invalid argument\n");
1978 return IVI_FAILED;
1979 }
1980
1981 *dest_x = ivilayer->prop.dest_x;
1982 *dest_y = ivilayer->prop.dest_y;
1983
1984 return IVI_SUCCEEDED;
1985}
1986
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001987int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001988ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
1989 int32_t dest_x, int32_t dest_y)
1990{
1991 struct ivi_layout_layer_properties *prop = NULL;
1992
1993 if (ivilayer == NULL) {
1994 weston_log("ivi_layout_layer_set_position: invalid argument\n");
1995 return IVI_FAILED;
1996 }
1997
1998 prop = &ivilayer->pending.prop;
1999 prop->dest_x = dest_x;
2000 prop->dest_y = dest_y;
2001
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002002 if (ivilayer->prop.dest_x != dest_x || ivilayer->prop.dest_y != dest_y)
2003 ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
2004 else
2005 ivilayer->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002006
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_set_orientation(struct ivi_layout_layer *ivilayer,
2012 enum wl_output_transform orientation)
2013{
2014 struct ivi_layout_layer_properties *prop = NULL;
2015
2016 if (ivilayer == NULL) {
2017 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
2018 return IVI_FAILED;
2019 }
2020
2021 prop = &ivilayer->pending.prop;
2022 prop->orientation = orientation;
2023
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002024 if (ivilayer->prop.orientation != orientation)
2025 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2026 else
2027 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002028
2029 return IVI_SUCCEEDED;
2030}
2031
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002032static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002033ivi_layout_layer_get_orientation(struct ivi_layout_layer *ivilayer)
2034{
2035 if (ivilayer == NULL) {
2036 weston_log("ivi_layout_layer_get_orientation: invalid argument\n");
2037 return 0;
2038 }
2039
2040 return ivilayer->prop.orientation;
2041}
2042
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002043int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002044ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
2045 struct ivi_layout_surface **pSurface,
2046 int32_t number)
2047{
2048 struct ivi_layout *layout = get_instance();
2049 struct ivi_layout_surface *ivisurf = NULL;
2050 struct ivi_layout_surface *next = NULL;
2051 uint32_t *id_surface = NULL;
2052 int32_t i = 0;
2053
2054 if (ivilayer == NULL) {
2055 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
2056 return IVI_FAILED;
2057 }
2058
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00002059 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002060
2061 for (i = 0; i < number; i++) {
2062 id_surface = &pSurface[i]->id_surface;
2063
2064 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2065 if (*id_surface != ivisurf->id_surface) {
2066 continue;
2067 }
2068
2069 if (!wl_list_empty(&ivisurf->pending.link)) {
2070 wl_list_remove(&ivisurf->pending.link);
2071 }
2072 wl_list_init(&ivisurf->pending.link);
2073 wl_list_insert(&ivilayer->pending.surface_list,
2074 &ivisurf->pending.link);
2075 break;
2076 }
2077 }
2078
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002079 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002080
2081 return IVI_SUCCEEDED;
2082}
2083
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002084int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002085ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
2086 bool newVisibility)
2087{
2088 struct ivi_layout_surface_properties *prop = NULL;
2089
2090 if (ivisurf == NULL) {
2091 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
2092 return IVI_FAILED;
2093 }
2094
2095 prop = &ivisurf->pending.prop;
2096 prop->visibility = newVisibility;
2097
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002098 if (ivisurf->prop.visibility != newVisibility)
2099 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
2100 else
2101 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002102
2103 return IVI_SUCCEEDED;
2104}
2105
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002106bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002107ivi_layout_surface_get_visibility(struct ivi_layout_surface *ivisurf)
2108{
2109 if (ivisurf == NULL) {
2110 weston_log("ivi_layout_surface_get_visibility: invalid argument\n");
2111 return false;
2112 }
2113
2114 return ivisurf->prop.visibility;
2115}
2116
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002117int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002118ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
2119 wl_fixed_t opacity)
2120{
2121 struct ivi_layout_surface_properties *prop = NULL;
2122
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09002123 if (ivisurf == NULL ||
2124 opacity < wl_fixed_from_double(0.0) ||
2125 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002126 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
2127 return IVI_FAILED;
2128 }
2129
2130 prop = &ivisurf->pending.prop;
2131 prop->opacity = opacity;
2132
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002133 if (ivisurf->prop.opacity != opacity)
2134 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
2135 else
2136 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002137
2138 return IVI_SUCCEEDED;
2139}
2140
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002141wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002142ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
2143{
2144 if (ivisurf == NULL) {
2145 weston_log("ivi_layout_surface_get_opacity: invalid argument\n");
2146 return wl_fixed_from_double(0.0);
2147 }
2148
2149 return ivisurf->prop.opacity;
2150}
2151
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002152int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002153ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
2154 int32_t x, int32_t y,
2155 int32_t width, int32_t height)
2156{
2157 struct ivi_layout_surface_properties *prop = NULL;
2158
2159 if (ivisurf == NULL) {
2160 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
2161 return IVI_FAILED;
2162 }
2163
2164 prop = &ivisurf->pending.prop;
2165 prop->start_x = prop->dest_x;
2166 prop->start_y = prop->dest_y;
2167 prop->dest_x = x;
2168 prop->dest_y = y;
2169 prop->start_width = prop->dest_width;
2170 prop->start_height = prop->dest_height;
2171 prop->dest_width = width;
2172 prop->dest_height = height;
2173
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002174 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2175 ivisurf->prop.dest_width != width ||
2176 ivisurf->prop.dest_height != height)
2177 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2178 else
2179 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002180
2181 return IVI_SUCCEEDED;
2182}
2183
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002184static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002185ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
2186 int32_t dest_width, int32_t dest_height)
2187{
2188 struct ivi_layout_surface_properties *prop = NULL;
2189
2190 if (ivisurf == NULL) {
2191 weston_log("ivi_layout_surface_set_dimension: invalid argument\n");
2192 return IVI_FAILED;
2193 }
2194
2195 prop = &ivisurf->pending.prop;
2196 prop->dest_width = dest_width;
2197 prop->dest_height = dest_height;
2198
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002199 if (ivisurf->prop.dest_width != dest_width ||
2200 ivisurf->prop.dest_height != dest_height)
2201 ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
2202 else
2203 ivisurf->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002204
2205 return IVI_SUCCEEDED;
2206}
2207
2208int32_t
2209ivi_layout_surface_get_dimension(struct ivi_layout_surface *ivisurf,
2210 int32_t *dest_width, int32_t *dest_height)
2211{
2212 if (ivisurf == NULL || dest_width == NULL || dest_height == NULL) {
2213 weston_log("ivi_layout_surface_get_dimension: invalid argument\n");
2214 return IVI_FAILED;
2215 }
2216
2217 *dest_width = ivisurf->prop.dest_width;
2218 *dest_height = ivisurf->prop.dest_height;
2219
2220 return IVI_SUCCEEDED;
2221}
2222
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002223static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002224ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
2225 int32_t dest_x, int32_t dest_y)
2226{
2227 struct ivi_layout_surface_properties *prop = NULL;
2228
2229 if (ivisurf == NULL) {
2230 weston_log("ivi_layout_surface_set_position: invalid argument\n");
2231 return IVI_FAILED;
2232 }
2233
2234 prop = &ivisurf->pending.prop;
2235 prop->dest_x = dest_x;
2236 prop->dest_y = dest_y;
2237
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002238 if (ivisurf->prop.dest_x != dest_x || ivisurf->prop.dest_y != dest_y)
2239 ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
2240 else
2241 ivisurf->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002242
2243 return IVI_SUCCEEDED;
2244}
2245
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002246static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002247ivi_layout_surface_get_position(struct ivi_layout_surface *ivisurf,
2248 int32_t *dest_x, int32_t *dest_y)
2249{
2250 if (ivisurf == NULL || dest_x == NULL || dest_y == NULL) {
2251 weston_log("ivi_layout_surface_get_position: invalid argument\n");
2252 return IVI_FAILED;
2253 }
2254
2255 *dest_x = ivisurf->prop.dest_x;
2256 *dest_y = ivisurf->prop.dest_y;
2257
2258 return IVI_SUCCEEDED;
2259}
2260
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002261static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002262ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2263 enum wl_output_transform orientation)
2264{
2265 struct ivi_layout_surface_properties *prop = NULL;
2266
2267 if (ivisurf == NULL) {
2268 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2269 return IVI_FAILED;
2270 }
2271
2272 prop = &ivisurf->pending.prop;
2273 prop->orientation = orientation;
2274
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002275 if (ivisurf->prop.orientation != orientation)
2276 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2277 else
2278 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002279
2280 return IVI_SUCCEEDED;
2281}
2282
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002283static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002284ivi_layout_surface_get_orientation(struct ivi_layout_surface *ivisurf)
2285{
2286 if (ivisurf == NULL) {
2287 weston_log("ivi_layout_surface_get_orientation: invalid argument\n");
2288 return 0;
2289 }
2290
2291 return ivisurf->prop.orientation;
2292}
2293
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002294static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002295ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2296 struct ivi_layout_layer *addlayer)
2297{
2298 struct ivi_layout *layout = get_instance();
2299 struct ivi_layout_layer *ivilayer = NULL;
2300 struct ivi_layout_layer *next = NULL;
2301 int is_layer_in_scrn = 0;
2302
2303 if (iviscrn == NULL || addlayer == NULL) {
2304 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2305 return IVI_FAILED;
2306 }
2307
2308 is_layer_in_scrn = is_layer_in_screen(addlayer, iviscrn);
2309 if (is_layer_in_scrn == 1) {
2310 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2311 return IVI_SUCCEEDED;
2312 }
2313
2314 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2315 if (ivilayer->id_layer == addlayer->id_layer) {
2316 if (!wl_list_empty(&ivilayer->pending.link)) {
2317 wl_list_remove(&ivilayer->pending.link);
2318 }
2319 wl_list_init(&ivilayer->pending.link);
2320 wl_list_insert(&iviscrn->pending.layer_list,
2321 &ivilayer->pending.link);
2322 break;
2323 }
2324 }
2325
2326 iviscrn->event_mask |= IVI_NOTIFICATION_ADD;
2327
2328 return IVI_SUCCEEDED;
2329}
2330
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002331static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002332ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2333 struct ivi_layout_layer **pLayer,
2334 const int32_t number)
2335{
2336 struct ivi_layout *layout = get_instance();
2337 struct ivi_layout_layer *ivilayer = NULL;
2338 struct ivi_layout_layer *next = NULL;
2339 uint32_t *id_layer = NULL;
2340 int32_t i = 0;
2341
2342 if (iviscrn == NULL) {
2343 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2344 return IVI_FAILED;
2345 }
2346
2347 wl_list_for_each_safe(ivilayer, next,
2348 &iviscrn->pending.layer_list, pending.link) {
2349 wl_list_init(&ivilayer->pending.link);
2350 }
2351
2352 wl_list_init(&iviscrn->pending.layer_list);
2353
2354 if (pLayer == NULL) {
2355 wl_list_for_each_safe(ivilayer, next, &iviscrn->pending.layer_list, pending.link) {
2356 if (!wl_list_empty(&ivilayer->pending.link)) {
2357 wl_list_remove(&ivilayer->pending.link);
2358 }
2359
2360 wl_list_init(&ivilayer->pending.link);
2361 }
2362
2363 iviscrn->event_mask |= IVI_NOTIFICATION_REMOVE;
2364 return IVI_SUCCEEDED;
2365 }
2366
2367 for (i = 0; i < number; i++) {
2368 id_layer = &pLayer[i]->id_layer;
2369 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2370 if (*id_layer != ivilayer->id_layer) {
2371 continue;
2372 }
2373
2374 if (!wl_list_empty(&ivilayer->pending.link)) {
2375 wl_list_remove(&ivilayer->pending.link);
2376 }
2377 wl_list_init(&ivilayer->pending.link);
2378 wl_list_insert(&iviscrn->pending.layer_list,
2379 &ivilayer->pending.link);
2380 break;
2381 }
2382 }
2383
2384 iviscrn->event_mask |= IVI_NOTIFICATION_ADD;
2385
2386 return IVI_SUCCEEDED;
2387}
2388
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002389static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002390ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2391{
2392 return iviscrn->output;
2393}
2394
2395/**
2396 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2397 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2398 * This function is used to get the result of drawing by clients.
2399 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002400static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002401ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2402{
2403 return ivisurf != NULL ? ivisurf->surface : NULL;
2404}
2405
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002406static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002407ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2408 int32_t *width, int32_t *height,
2409 int32_t *stride)
2410{
2411 int32_t w;
2412 int32_t h;
2413 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2414
2415 if (ivisurf == NULL || ivisurf->surface == NULL) {
2416 weston_log("%s: invalid argument\n", __func__);
2417 return IVI_FAILED;
2418 }
2419
2420 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2421
2422 if (width != NULL)
2423 *width = w;
2424
2425 if (height != NULL)
2426 *height = h;
2427
2428 if (stride != NULL)
2429 *stride = w * bytespp;
2430
2431 return IVI_SUCCEEDED;
2432}
2433
2434static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002435ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2436 layer_property_notification_func callback,
2437 void *userdata)
2438{
2439 struct ivi_layout_notification_callback *prop_callback = NULL;
2440
2441 if (ivilayer == NULL || callback == NULL) {
2442 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2443 return IVI_FAILED;
2444 }
2445
2446 prop_callback = malloc(sizeof *prop_callback);
2447 if (prop_callback == NULL) {
2448 weston_log("fails to allocate memory\n");
2449 return IVI_FAILED;
2450 }
2451
2452 prop_callback->callback = callback;
2453 prop_callback->data = userdata;
2454
2455 return add_notification(&ivilayer->property_changed,
2456 layer_prop_changed,
2457 prop_callback);
2458}
2459
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002460static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002461ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2462{
2463 if (ivisurf == NULL) {
2464 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2465 return NULL;
2466 }
2467
2468 return &ivisurf->prop;
2469}
2470
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002471static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002472ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2473 struct ivi_layout_surface *addsurf)
2474{
2475 struct ivi_layout *layout = get_instance();
2476 struct ivi_layout_surface *ivisurf = NULL;
2477 struct ivi_layout_surface *next = NULL;
2478 int is_surf_in_layer = 0;
2479
2480 if (ivilayer == NULL || addsurf == NULL) {
2481 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2482 return IVI_FAILED;
2483 }
2484
2485 is_surf_in_layer = is_surface_in_layer(addsurf, ivilayer);
2486 if (is_surf_in_layer == 1) {
2487 weston_log("ivi_layout_layer_add_surface: addsurf is already available\n");
2488 return IVI_SUCCEEDED;
2489 }
2490
2491 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2492 if (ivisurf->id_surface == addsurf->id_surface) {
2493 if (!wl_list_empty(&ivisurf->pending.link)) {
2494 wl_list_remove(&ivisurf->pending.link);
2495 }
2496 wl_list_init(&ivisurf->pending.link);
2497 wl_list_insert(&ivilayer->pending.surface_list,
2498 &ivisurf->pending.link);
2499 break;
2500 }
2501 }
2502
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002503 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002504
2505 return IVI_SUCCEEDED;
2506}
2507
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002508static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002509ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2510 struct ivi_layout_surface *remsurf)
2511{
2512 struct ivi_layout_surface *ivisurf = NULL;
2513 struct ivi_layout_surface *next = NULL;
2514
2515 if (ivilayer == NULL || remsurf == NULL) {
2516 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2517 return;
2518 }
2519
2520 wl_list_for_each_safe(ivisurf, next,
2521 &ivilayer->pending.surface_list, pending.link) {
2522 if (ivisurf->id_surface == remsurf->id_surface) {
2523 if (!wl_list_empty(&ivisurf->pending.link)) {
2524 wl_list_remove(&ivisurf->pending.link);
2525 }
2526 wl_list_init(&ivisurf->pending.link);
2527 break;
2528 }
2529 }
2530
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002531 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002532}
2533
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002534static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002535ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2536 int32_t x, int32_t y,
2537 int32_t width, int32_t height)
2538{
2539 struct ivi_layout_surface_properties *prop = NULL;
2540
2541 if (ivisurf == NULL) {
2542 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2543 return IVI_FAILED;
2544 }
2545
2546 prop = &ivisurf->pending.prop;
2547 prop->source_x = x;
2548 prop->source_y = y;
2549 prop->source_width = width;
2550 prop->source_height = height;
2551
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002552 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2553 ivisurf->prop.source_width != width ||
2554 ivisurf->prop.source_height != height)
2555 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2556 else
2557 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002558
2559 return IVI_SUCCEEDED;
2560}
2561
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002562int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002563ivi_layout_commit_changes(void)
2564{
2565 struct ivi_layout *layout = get_instance();
2566
2567 commit_surface_list(layout);
2568 commit_layer_list(layout);
2569 commit_screen_list(layout);
2570
2571 commit_transition(layout);
2572
2573 commit_changes(layout);
2574 send_prop(layout);
2575 weston_compositor_schedule_repaint(layout->compositor);
2576
2577 return IVI_SUCCEEDED;
2578}
2579
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002580static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002581ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2582 enum ivi_layout_transition_type type,
2583 uint32_t duration)
2584{
2585 if (ivilayer == NULL) {
2586 weston_log("%s: invalid argument\n", __func__);
2587 return -1;
2588 }
2589
2590 ivilayer->pending.prop.transition_type = type;
2591 ivilayer->pending.prop.transition_duration = duration;
2592
2593 return 0;
2594}
2595
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002596static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002597ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2598 uint32_t is_fade_in,
2599 double start_alpha, double end_alpha)
2600{
2601 if (ivilayer == NULL) {
2602 weston_log("%s: invalid argument\n", __func__);
2603 return -1;
2604 }
2605
2606 ivilayer->pending.prop.is_fade_in = is_fade_in;
2607 ivilayer->pending.prop.start_alpha = start_alpha;
2608 ivilayer->pending.prop.end_alpha = end_alpha;
2609
2610 return 0;
2611}
2612
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002613static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002614ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2615 uint32_t duration)
2616{
2617 struct ivi_layout_surface_properties *prop;
2618
2619 if (ivisurf == NULL) {
2620 weston_log("%s: invalid argument\n", __func__);
2621 return -1;
2622 }
2623
2624 prop = &ivisurf->pending.prop;
2625 prop->transition_duration = duration*10;
2626 return 0;
2627}
2628
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002629static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002630ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2631 enum ivi_layout_transition_type type,
2632 uint32_t duration)
2633{
2634 struct ivi_layout_surface_properties *prop;
2635
2636 if (ivisurf == NULL) {
2637 weston_log("%s: invalid argument\n", __func__);
2638 return -1;
2639 }
2640
2641 prop = &ivisurf->pending.prop;
2642 prop->transition_type = type;
2643 prop->transition_duration = duration;
2644 return 0;
2645}
2646
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002647static int32_t
2648ivi_layout_surface_dump(struct weston_surface *surface,
2649 void *target, size_t size,int32_t x, int32_t y,
2650 int32_t width, int32_t height)
2651{
2652 int result = 0;
2653
2654 if (surface == NULL) {
2655 weston_log("%s: invalid argument\n", __func__);
2656 return IVI_FAILED;
2657 }
2658
2659 result = weston_surface_copy_content(
2660 surface, target, size,
2661 x, y, width, height);
2662
2663 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2664}
2665
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002666/**
2667 * methods of interaction between ivi-shell with ivi-layout
2668 */
2669struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002670ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2671{
2672 struct weston_view *tmpview = NULL;
2673
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002674 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002675 return NULL;
2676
2677 wl_list_for_each(tmpview, &surface->surface->views, surface_link)
2678 {
2679 if (tmpview != NULL) {
2680 break;
2681 }
2682 }
2683 return tmpview;
2684}
2685
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002686void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002687ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2688 int32_t width, int32_t height)
2689{
2690 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002691
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002692 /* emit callback which is set by ivi-layout api user */
2693 wl_signal_emit(&layout->surface_notification.configure_changed,
2694 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002695}
2696
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002697static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002698ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2699 ivi_controller_surface_content_callback callback,
2700 void* userdata)
2701{
2702 int32_t ret = IVI_FAILED;
2703
2704 if (ivisurf != NULL) {
2705 ivisurf->content_observer.callback = callback;
2706 ivisurf->content_observer.userdata = userdata;
2707 ret = IVI_SUCCEEDED;
2708 }
2709 return ret;
2710}
2711
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002712struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002713ivi_layout_surface_create(struct weston_surface *wl_surface,
2714 uint32_t id_surface)
2715{
2716 struct ivi_layout *layout = get_instance();
2717 struct ivi_layout_surface *ivisurf = NULL;
2718 struct weston_view *tmpview = NULL;
2719
2720 if (wl_surface == NULL) {
2721 weston_log("ivi_layout_surface_create: invalid argument\n");
2722 return NULL;
2723 }
2724
2725 ivisurf = get_surface(&layout->surface_list, id_surface);
2726 if (ivisurf != NULL) {
2727 if (ivisurf->surface != NULL) {
2728 weston_log("id_surface(%d) is already created\n", id_surface);
2729 return NULL;
2730 }
2731 }
2732
2733 ivisurf = calloc(1, sizeof *ivisurf);
2734 if (ivisurf == NULL) {
2735 weston_log("fails to allocate memory\n");
2736 return NULL;
2737 }
2738
2739 wl_list_init(&ivisurf->link);
2740 wl_signal_init(&ivisurf->property_changed);
2741 wl_signal_init(&ivisurf->configured);
2742 wl_list_init(&ivisurf->layer_list);
2743 ivisurf->id_surface = id_surface;
2744 ivisurf->layout = layout;
2745
2746 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002747
2748 tmpview = weston_view_create(wl_surface);
2749 if (tmpview == NULL) {
2750 weston_log("fails to allocate memory\n");
2751 }
2752
2753 ivisurf->surface->width_from_buffer = 0;
2754 ivisurf->surface->height_from_buffer = 0;
2755
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002756 weston_matrix_init(&ivisurf->transform.matrix);
2757 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002758
2759 init_surface_properties(&ivisurf->prop);
2760 ivisurf->event_mask = 0;
2761
2762 ivisurf->pending.prop = ivisurf->prop;
2763 wl_list_init(&ivisurf->pending.link);
2764
2765 wl_list_init(&ivisurf->order.link);
2766 wl_list_init(&ivisurf->order.layer_list);
2767
2768 wl_list_insert(&layout->surface_list, &ivisurf->link);
2769
2770 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2771
2772 return ivisurf;
2773}
2774
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002775void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002776ivi_layout_init_with_compositor(struct weston_compositor *ec)
2777{
2778 struct ivi_layout *layout = get_instance();
2779
2780 layout->compositor = ec;
2781
2782 wl_list_init(&layout->surface_list);
2783 wl_list_init(&layout->layer_list);
2784 wl_list_init(&layout->screen_list);
2785
2786 wl_signal_init(&layout->layer_notification.created);
2787 wl_signal_init(&layout->layer_notification.removed);
2788
2789 wl_signal_init(&layout->surface_notification.created);
2790 wl_signal_init(&layout->surface_notification.removed);
2791 wl_signal_init(&layout->surface_notification.configure_changed);
2792
2793 /* Add layout_layer at the last of weston_compositor.layer_list */
2794 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2795
2796 create_screen(ec);
2797
2798 layout->transitions = ivi_layout_transition_set_create(ec);
2799 wl_list_init(&layout->pending_transition_list);
2800}
2801
2802
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002803void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002804ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2805 struct wl_listener* listener)
2806{
2807 wl_signal_add(&ivisurf->configured, listener);
2808}
2809
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002810static struct ivi_controller_interface ivi_controller_interface = {
2811 /**
2812 * commit all changes
2813 */
2814 .commit_changes = ivi_layout_commit_changes,
2815
2816 /**
2817 * surface controller interfaces
2818 */
2819 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2820 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2821 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2822 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2823 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2824 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2825 .get_surfaces = ivi_layout_get_surfaces,
2826 .get_id_of_surface = ivi_layout_get_id_of_surface,
2827 .get_surface_from_id = ivi_layout_get_surface_from_id,
2828 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2829 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2830 .surface_set_visibility = ivi_layout_surface_set_visibility,
2831 .surface_get_visibility = ivi_layout_surface_get_visibility,
2832 .surface_set_opacity = ivi_layout_surface_set_opacity,
2833 .surface_get_opacity = ivi_layout_surface_get_opacity,
2834 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2835 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
2836 .surface_set_position = ivi_layout_surface_set_position,
2837 .surface_get_position = ivi_layout_surface_get_position,
2838 .surface_set_dimension = ivi_layout_surface_set_dimension,
2839 .surface_get_dimension = ivi_layout_surface_get_dimension,
2840 .surface_set_orientation = ivi_layout_surface_set_orientation,
2841 .surface_get_orientation = ivi_layout_surface_get_orientation,
2842 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2843 .surface_add_notification = ivi_layout_surface_add_notification,
2844 .surface_remove_notification = ivi_layout_surface_remove_notification,
2845 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2846 .surface_set_transition = ivi_layout_surface_set_transition,
2847 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2848
2849 /**
2850 * layer controller interfaces
2851 */
2852 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2853 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2854 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2855 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2856 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002857 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002858 .get_layers = ivi_layout_get_layers,
2859 .get_id_of_layer = ivi_layout_get_id_of_layer,
2860 .get_layer_from_id = ivi_layout_get_layer_from_id,
2861 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2862 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2863 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2864 .layer_set_visibility = ivi_layout_layer_set_visibility,
2865 .layer_get_visibility = ivi_layout_layer_get_visibility,
2866 .layer_set_opacity = ivi_layout_layer_set_opacity,
2867 .layer_get_opacity = ivi_layout_layer_get_opacity,
2868 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2869 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
2870 .layer_set_position = ivi_layout_layer_set_position,
2871 .layer_get_position = ivi_layout_layer_get_position,
2872 .layer_set_dimension = ivi_layout_layer_set_dimension,
2873 .layer_get_dimension = ivi_layout_layer_get_dimension,
2874 .layer_set_orientation = ivi_layout_layer_set_orientation,
2875 .layer_get_orientation = ivi_layout_layer_get_orientation,
2876 .layer_add_surface = ivi_layout_layer_add_surface,
2877 .layer_remove_surface = ivi_layout_layer_remove_surface,
2878 .layer_set_render_order = ivi_layout_layer_set_render_order,
2879 .layer_add_notification = ivi_layout_layer_add_notification,
2880 .layer_remove_notification = ivi_layout_layer_remove_notification,
2881 .layer_set_transition = ivi_layout_layer_set_transition,
2882
2883 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002884 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002885 */
2886 .get_screen_from_id = ivi_layout_get_screen_from_id,
2887 .get_screen_resolution = ivi_layout_get_screen_resolution,
2888 .get_screens = ivi_layout_get_screens,
2889 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2890 .screen_add_layer = ivi_layout_screen_add_layer,
2891 .screen_set_render_order = ivi_layout_screen_set_render_order,
2892 .screen_get_output = ivi_layout_screen_get_output,
2893
2894 /**
2895 * animation
2896 */
2897 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002898 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2899
2900 /**
2901 * surface content dumping for debugging
2902 */
2903 .surface_get_size = ivi_layout_surface_get_size,
2904 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002905
2906 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002907 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002908 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002909 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002910 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2911
2912 /**
2913 * screen controller interfaces part2
2914 */
2915 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002916};
2917
2918int
2919load_controller_modules(struct weston_compositor *compositor, const char *modules,
2920 int *argc, char *argv[])
2921{
2922 const char *p, *end;
2923 char buffer[256];
2924 int (*controller_module_init)(struct weston_compositor *compositor,
2925 int *argc, char *argv[],
2926 const struct ivi_controller_interface *interface,
2927 size_t interface_version);
2928
2929 if (modules == NULL)
2930 return 0;
2931
2932 p = modules;
2933 while (*p) {
2934 end = strchrnul(p, ',');
2935 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2936
2937 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002938 if (!controller_module_init)
2939 return -1;
2940
2941 if (controller_module_init(compositor, argc, argv,
2942 &ivi_controller_interface,
2943 sizeof(struct ivi_controller_interface)) != 0) {
2944 weston_log("ivi-shell: Initialization of controller module fails");
2945 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002946 }
2947
2948 p = end;
2949 while (*p == ',')
2950 p++;
2951 }
2952
2953 return 0;
2954}