blob: d412069c845d54bd8686375a2c6354088d55ea89 [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>
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090061
62#include "compositor.h"
63#include "ivi-layout-export.h"
64#include "ivi-layout-private.h"
65
Jon Cruz867d50e2015-06-15 15:37:10 -070066#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070067#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090068
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090069struct link_layer {
70 struct ivi_layout_layer *ivilayer;
71 struct wl_list link;
72 struct wl_list link_to_layer;
73};
74
75struct link_screen {
76 struct ivi_layout_screen *iviscrn;
77 struct wl_list link;
78 struct wl_list link_to_screen;
79};
80
81struct listener_layout_notification {
82 void *userdata;
83 struct wl_listener listener;
84};
85
86struct ivi_layout;
87
88struct ivi_layout_screen {
89 struct wl_list link;
90 struct wl_list link_to_layer;
91 uint32_t id_screen;
92
93 struct ivi_layout *layout;
94 struct weston_output *output;
95
96 uint32_t event_mask;
97
98 struct {
99 struct wl_list layer_list;
100 struct wl_list link;
101 } pending;
102
103 struct {
104 struct wl_list layer_list;
105 struct wl_list link;
106 } order;
107};
108
109struct ivi_layout_notification_callback {
110 void *callback;
111 void *data;
112};
113
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900114struct ivi_rectangle
115{
116 int32_t x;
117 int32_t y;
118 int32_t width;
119 int32_t height;
120};
121
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900122static void
123remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
124
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900125static struct ivi_layout ivilayout = {0};
126
127struct ivi_layout *
128get_instance(void)
129{
130 return &ivilayout;
131}
132
133/**
134 * Internal API to add/remove a link to ivi_surface from ivi_layer.
135 */
136static void
137add_link_to_surface(struct ivi_layout_layer *ivilayer,
138 struct link_layer *link_layer)
139{
140 struct link_layer *link = NULL;
141
142 wl_list_for_each(link, &ivilayer->link_to_surface, link_to_layer) {
143 if (link == link_layer)
144 return;
145 }
146
147 wl_list_insert(&ivilayer->link_to_surface, &link_layer->link_to_layer);
148}
149
150static void
151remove_link_to_surface(struct ivi_layout_layer *ivilayer)
152{
153 struct link_layer *link = NULL;
154 struct link_layer *next = NULL;
155
156 wl_list_for_each_safe(link, next, &ivilayer->link_to_surface, link_to_layer) {
157 if (!wl_list_empty(&link->link_to_layer)) {
158 wl_list_remove(&link->link_to_layer);
159 }
160 if (!wl_list_empty(&link->link)) {
161 wl_list_remove(&link->link);
162 }
163 free(link);
164 }
165
166 wl_list_init(&ivilayer->link_to_surface);
167}
168
169/**
170 * Internal API to add a link to ivi_layer from ivi_screen.
171 */
172static void
173add_link_to_layer(struct ivi_layout_screen *iviscrn,
174 struct link_screen *link_screen)
175{
176 wl_list_init(&link_screen->link_to_screen);
177 wl_list_insert(&iviscrn->link_to_layer, &link_screen->link_to_screen);
178}
179
180/**
181 * Internal API to add/remove a ivi_surface from ivi_layer.
182 */
183static void
184add_ordersurface_to_layer(struct ivi_layout_surface *ivisurf,
185 struct ivi_layout_layer *ivilayer)
186{
187 struct link_layer *link_layer = NULL;
188
189 link_layer = malloc(sizeof *link_layer);
190 if (link_layer == NULL) {
191 weston_log("fails to allocate memory\n");
192 return;
193 }
194
195 link_layer->ivilayer = ivilayer;
196 wl_list_init(&link_layer->link);
197 wl_list_insert(&ivisurf->layer_list, &link_layer->link);
198 add_link_to_surface(ivilayer, link_layer);
199}
200
201static void
202remove_ordersurface_from_layer(struct ivi_layout_surface *ivisurf)
203{
204 struct link_layer *link_layer = NULL;
205 struct link_layer *next = NULL;
206
207 wl_list_for_each_safe(link_layer, next, &ivisurf->layer_list, link) {
208 if (!wl_list_empty(&link_layer->link)) {
209 wl_list_remove(&link_layer->link);
210 }
211 if (!wl_list_empty(&link_layer->link_to_layer)) {
212 wl_list_remove(&link_layer->link_to_layer);
213 }
214 free(link_layer);
215 }
216 wl_list_init(&ivisurf->layer_list);
217}
218
219/**
220 * Internal API to add/remove a ivi_layer to/from ivi_screen.
221 */
222static void
223add_orderlayer_to_screen(struct ivi_layout_layer *ivilayer,
224 struct ivi_layout_screen *iviscrn)
225{
226 struct link_screen *link_scrn = NULL;
227
228 link_scrn = malloc(sizeof *link_scrn);
229 if (link_scrn == NULL) {
230 weston_log("fails to allocate memory\n");
231 return;
232 }
233
234 link_scrn->iviscrn = iviscrn;
235 wl_list_init(&link_scrn->link);
236 wl_list_insert(&ivilayer->screen_list, &link_scrn->link);
237 add_link_to_layer(iviscrn, link_scrn);
238}
239
240static void
241remove_orderlayer_from_screen(struct ivi_layout_layer *ivilayer)
242{
243 struct link_screen *link_scrn = NULL;
244 struct link_screen *next = NULL;
245
246 wl_list_for_each_safe(link_scrn, next, &ivilayer->screen_list, link) {
247 if (!wl_list_empty(&link_scrn->link)) {
248 wl_list_remove(&link_scrn->link);
249 }
250 if (!wl_list_empty(&link_scrn->link_to_screen)) {
251 wl_list_remove(&link_scrn->link_to_screen);
252 }
253 free(link_scrn);
254 }
255 wl_list_init(&ivilayer->screen_list);
256}
257
258/**
259 * Internal API to add/remove a ivi_layer to/from ivi_screen.
260 */
261static struct ivi_layout_surface *
262get_surface(struct wl_list *surf_list, uint32_t id_surface)
263{
264 struct ivi_layout_surface *ivisurf;
265
266 wl_list_for_each(ivisurf, surf_list, link) {
267 if (ivisurf->id_surface == id_surface) {
268 return ivisurf;
269 }
270 }
271
272 return NULL;
273}
274
275static struct ivi_layout_layer *
276get_layer(struct wl_list *layer_list, uint32_t id_layer)
277{
278 struct ivi_layout_layer *ivilayer;
279
280 wl_list_for_each(ivilayer, layer_list, link) {
281 if (ivilayer->id_layer == id_layer) {
282 return ivilayer;
283 }
284 }
285
286 return NULL;
287}
288
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900289static void
290remove_configured_listener(struct ivi_layout_surface *ivisurf)
291{
292 struct wl_listener *link = NULL;
293 struct wl_listener *next = NULL;
294
295 wl_list_for_each_safe(link, next, &ivisurf->configured.listener_list, link) {
296 wl_list_remove(&link->link);
297 }
298}
299
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900300static void
301remove_all_notification(struct wl_list *listener_list)
302{
303 struct wl_listener *listener = NULL;
304 struct wl_listener *next = NULL;
305
306 wl_list_for_each_safe(listener, next, listener_list, link) {
307 struct listener_layout_notification *notification = NULL;
308 if (!wl_list_empty(&listener->link)) {
309 wl_list_remove(&listener->link);
310 }
311
312 notification =
313 container_of(listener,
314 struct listener_layout_notification,
315 listener);
316
317 free(notification->userdata);
318 free(notification);
319 }
320}
321
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900322static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900323ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
324{
325 if (ivisurf == NULL) {
326 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
327 return;
328 }
329
330 remove_all_notification(&ivisurf->property_changed.listener_list);
331}
332
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900333static void
334ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
335 surface_property_notification_func callback,
336 void *userdata)
337{
338 if (ivisurf == NULL) {
339 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
340 return;
341 }
342
343 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
344}
345
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900346/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900347 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900348 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900349void
350ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900351{
352 struct ivi_layout *layout = get_instance();
353
354 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900355 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900356 return;
357 }
358
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900359 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900360 wl_list_remove(&ivisurf->pending.link);
361 wl_list_remove(&ivisurf->order.link);
362 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900363 remove_ordersurface_from_layer(ivisurf);
364
365 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
366
367 remove_configured_listener(ivisurf);
368
369 ivi_layout_surface_remove_notification(ivisurf);
370
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900371 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900372}
373
374/**
375 * Internal API to check ivi_layer/ivi_surface already added in ivi_layer/ivi_screen.
376 * Called by ivi_layout_layer_add_surface/ivi_layout_screenAddLayer
377 */
378static int
379is_surface_in_layer(struct ivi_layout_surface *ivisurf,
380 struct ivi_layout_layer *ivilayer)
381{
382 struct ivi_layout_surface *surf = NULL;
383
384 wl_list_for_each(surf, &ivilayer->pending.surface_list, pending.link) {
385 if (surf->id_surface == ivisurf->id_surface) {
386 return 1;
387 }
388 }
389
390 return 0;
391}
392
393static int
394is_layer_in_screen(struct ivi_layout_layer *ivilayer,
395 struct ivi_layout_screen *iviscrn)
396{
397 struct ivi_layout_layer *layer = NULL;
398
399 wl_list_for_each(layer, &iviscrn->pending.layer_list, pending.link) {
400 if (layer->id_layer == ivilayer->id_layer) {
401 return 1;
402 }
403 }
404
405 return 0;
406}
407
408/**
409 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
410 * Called by ivi_layout_init_with_compositor.
411 */
412static void
413create_screen(struct weston_compositor *ec)
414{
415 struct ivi_layout *layout = get_instance();
416 struct ivi_layout_screen *iviscrn = NULL;
417 struct weston_output *output = NULL;
418 int32_t count = 0;
419
420 wl_list_for_each(output, &ec->output_list, link) {
421 iviscrn = calloc(1, sizeof *iviscrn);
422 if (iviscrn == NULL) {
423 weston_log("fails to allocate memory\n");
424 continue;
425 }
426
427 wl_list_init(&iviscrn->link);
428 iviscrn->layout = layout;
429
430 iviscrn->id_screen = count;
431 count++;
432
433 iviscrn->output = output;
434 iviscrn->event_mask = 0;
435
436 wl_list_init(&iviscrn->pending.layer_list);
437 wl_list_init(&iviscrn->pending.link);
438
439 wl_list_init(&iviscrn->order.layer_list);
440 wl_list_init(&iviscrn->order.link);
441
442 wl_list_init(&iviscrn->link_to_layer);
443
444 wl_list_insert(&layout->screen_list, &iviscrn->link);
445 }
446}
447
448/**
449 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
450 */
451static void
452init_layer_properties(struct ivi_layout_layer_properties *prop,
453 int32_t width, int32_t height)
454{
455 memset(prop, 0, sizeof *prop);
456 prop->opacity = wl_fixed_from_double(1.0);
457 prop->source_width = width;
458 prop->source_height = height;
459 prop->dest_width = width;
460 prop->dest_height = height;
461}
462
463static void
464init_surface_properties(struct ivi_layout_surface_properties *prop)
465{
466 memset(prop, 0, sizeof *prop);
467 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900468 /*
469 * FIXME: this shall be finxed by ivi-layout-transition.
470 */
471 prop->dest_width = 1;
472 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900473}
474
475/**
476 * Internal APIs to be called from ivi_layout_commit_changes.
477 */
478static void
479update_opacity(struct ivi_layout_layer *ivilayer,
480 struct ivi_layout_surface *ivisurf)
481{
482 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
483 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
484
485 if ((ivilayer->event_mask & IVI_NOTIFICATION_OPACITY) ||
486 (ivisurf->event_mask & IVI_NOTIFICATION_OPACITY)) {
487 struct weston_view *tmpview = NULL;
488 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
489 if (tmpview == NULL) {
490 continue;
491 }
492 tmpview->alpha = layer_alpha * surf_alpha;
493 }
494 }
495}
496
497static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900498get_rotate_values(enum wl_output_transform orientation,
499 float *v_sin,
500 float *v_cos)
501{
502 switch (orientation) {
503 case WL_OUTPUT_TRANSFORM_90:
504 *v_sin = 1.0f;
505 *v_cos = 0.0f;
506 break;
507 case WL_OUTPUT_TRANSFORM_180:
508 *v_sin = 0.0f;
509 *v_cos = -1.0f;
510 break;
511 case WL_OUTPUT_TRANSFORM_270:
512 *v_sin = -1.0f;
513 *v_cos = 0.0f;
514 break;
515 case WL_OUTPUT_TRANSFORM_NORMAL:
516 default:
517 *v_sin = 0.0f;
518 *v_cos = 1.0f;
519 break;
520 }
521}
522
523static void
524get_scale(enum wl_output_transform orientation,
525 float dest_width,
526 float dest_height,
527 float source_width,
528 float source_height,
529 float *scale_x,
530 float *scale_y)
531{
532 switch (orientation) {
533 case WL_OUTPUT_TRANSFORM_90:
534 *scale_x = dest_width / source_height;
535 *scale_y = dest_height / source_width;
536 break;
537 case WL_OUTPUT_TRANSFORM_180:
538 *scale_x = dest_width / source_width;
539 *scale_y = dest_height / source_height;
540 break;
541 case WL_OUTPUT_TRANSFORM_270:
542 *scale_x = dest_width / source_height;
543 *scale_y = dest_height / source_width;
544 break;
545 case WL_OUTPUT_TRANSFORM_NORMAL:
546 default:
547 *scale_x = dest_width / source_width;
548 *scale_y = dest_height / source_height;
549 break;
550 }
551}
552
553static void
554calc_transformation_matrix(struct ivi_rectangle *source_rect,
555 struct ivi_rectangle *dest_rect,
556 enum wl_output_transform orientation,
557 struct weston_matrix *m)
558{
559 float source_center_x;
560 float source_center_y;
561 float vsin;
562 float vcos;
563 float scale_x;
564 float scale_y;
565 float translate_x;
566 float translate_y;
567
568 source_center_x = source_rect->x + source_rect->width * 0.5f;
569 source_center_y = source_rect->y + source_rect->height * 0.5f;
570 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
571
572 get_rotate_values(orientation, &vsin, &vcos);
573 weston_matrix_rotate_xy(m, vcos, vsin);
574
575 get_scale(orientation,
576 dest_rect->width,
577 dest_rect->height,
578 source_rect->width,
579 source_rect->height,
580 &scale_x,
581 &scale_y);
582 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
583
584 translate_x = dest_rect->width * 0.5f + dest_rect->x;
585 translate_y = dest_rect->height * 0.5f + dest_rect->y;
586 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
587}
588
589/**
590 * This computes the whole transformation matrix from surface-local
591 * coordinates to global coordinates. It is assumed that
592 * weston_view::geometry.{x,y} are zero.
593 */
594static void
595calc_surface_to_global_matrix(struct ivi_layout_layer *ivilayer,
596 struct ivi_layout_surface *ivisurf,
597 struct weston_matrix *m)
598{
599 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
600 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
601 struct ivi_rectangle surface_source_rect = { sp->source_x,
602 sp->source_y,
603 sp->source_width,
604 sp->source_height };
605 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
606 sp->dest_y,
607 sp->dest_width,
608 sp->dest_height };
609 struct ivi_rectangle layer_source_rect = { lp->source_x,
610 lp->source_y,
611 lp->source_width,
612 lp->source_height };
613 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
614 lp->dest_y,
615 lp->dest_width,
616 lp->dest_height };
617
618 calc_transformation_matrix(&surface_source_rect,
619 &surface_dest_rect,
620 sp->orientation, m);
621
622 calc_transformation_matrix(&layer_source_rect,
623 &layer_dest_rect,
624 lp->orientation, m);
625}
626
627static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900628update_prop(struct ivi_layout_layer *ivilayer,
629 struct ivi_layout_surface *ivisurf)
630{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900631 struct weston_view *tmpview;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900632 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900633
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900634 if (!ivilayer->event_mask && !ivisurf->event_mask) {
635 return;
636 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900637
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900638 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900639
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900640 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900641 if (tmpview != NULL) {
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900642 break;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900643 }
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900644 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900645
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900646 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
647 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
648 can_calc = false;
649 }
650
651 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
652 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
653 can_calc = false;
654 }
655
656 if (can_calc) {
657 wl_list_remove(&ivisurf->transform.link);
658 weston_matrix_init(&ivisurf->transform.matrix);
659
660 calc_surface_to_global_matrix(ivilayer, ivisurf, &ivisurf->transform.matrix);
661
662 if (tmpview != NULL) {
663 wl_list_insert(&tmpview->geometry.transformation_list, &ivisurf->transform.link);
664
665 weston_view_set_transform_parent(tmpview, NULL);
666 }
667 }
668
669 ivisurf->update_count++;
670
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900671 if (tmpview != NULL) {
672 weston_view_geometry_dirty(tmpview);
673 }
674
675 if (ivisurf->surface != NULL) {
676 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900677 }
678}
679
680static void
681commit_changes(struct ivi_layout *layout)
682{
683 struct ivi_layout_screen *iviscrn = NULL;
684 struct ivi_layout_layer *ivilayer = NULL;
685 struct ivi_layout_surface *ivisurf = NULL;
686
687 wl_list_for_each(iviscrn, &layout->screen_list, link) {
688 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
689 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
690 update_prop(ivilayer, ivisurf);
691 }
692 }
693 }
694}
695
696static void
697commit_surface_list(struct ivi_layout *layout)
698{
699 struct ivi_layout_surface *ivisurf = NULL;
700 int32_t dest_x = 0;
701 int32_t dest_y = 0;
702 int32_t dest_width = 0;
703 int32_t dest_height = 0;
704 int32_t configured = 0;
705
706 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300707 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900708 dest_x = ivisurf->prop.dest_x;
709 dest_y = ivisurf->prop.dest_y;
710 dest_width = ivisurf->prop.dest_width;
711 dest_height = ivisurf->prop.dest_height;
712
713 ivi_layout_transition_move_resize_view(ivisurf,
714 ivisurf->pending.prop.dest_x,
715 ivisurf->pending.prop.dest_y,
716 ivisurf->pending.prop.dest_width,
717 ivisurf->pending.prop.dest_height,
718 ivisurf->pending.prop.transition_duration);
719
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300720 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900721 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
722 } else {
723 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
724 }
725
726 ivisurf->prop = ivisurf->pending.prop;
727 ivisurf->prop.dest_x = dest_x;
728 ivisurf->prop.dest_y = dest_y;
729 ivisurf->prop.dest_width = dest_width;
730 ivisurf->prop.dest_height = dest_height;
731 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
732 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
733
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300734 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900735 dest_x = ivisurf->prop.dest_x;
736 dest_y = ivisurf->prop.dest_y;
737 dest_width = ivisurf->prop.dest_width;
738 dest_height = ivisurf->prop.dest_height;
739
740 ivi_layout_transition_move_resize_view(ivisurf,
741 ivisurf->pending.prop.dest_x,
742 ivisurf->pending.prop.dest_y,
743 ivisurf->pending.prop.dest_width,
744 ivisurf->pending.prop.dest_height,
745 ivisurf->pending.prop.transition_duration);
746
747 ivisurf->prop = ivisurf->pending.prop;
748 ivisurf->prop.dest_x = dest_x;
749 ivisurf->prop.dest_y = dest_y;
750 ivisurf->prop.dest_width = dest_width;
751 ivisurf->prop.dest_height = dest_height;
752
753 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
754 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
755
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300756 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900757 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300758 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900759 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
760 } else {
761 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
762 }
763
764 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
765 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
766 configured = 1;
767 }
768
769 ivisurf->prop = ivisurf->pending.prop;
770 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
771 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
772
773 if (configured && !is_surface_transition(ivisurf))
774 wl_signal_emit(&ivisurf->configured, ivisurf);
775 } else {
776 configured = 0;
777 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
778 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
779 configured = 1;
780 }
781
782 ivisurf->prop = ivisurf->pending.prop;
783 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
784 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
785
786 if (configured && !is_surface_transition(ivisurf))
787 wl_signal_emit(&ivisurf->configured, ivisurf);
788 }
789 }
790}
791
792static void
793commit_layer_list(struct ivi_layout *layout)
794{
795 struct ivi_layout_layer *ivilayer = NULL;
796 struct ivi_layout_surface *ivisurf = NULL;
797 struct ivi_layout_surface *next = NULL;
798
799 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300800 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900801 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 -0300802 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900803 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
804 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
805 NULL, NULL,
806 ivilayer->pending.prop.transition_duration);
807 }
808 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
809
810 ivilayer->prop = ivilayer->pending.prop;
811
812 if (!(ivilayer->event_mask &
813 (IVI_NOTIFICATION_ADD | IVI_NOTIFICATION_REMOVE)) ) {
814 continue;
815 }
816
817 if (ivilayer->event_mask & IVI_NOTIFICATION_REMOVE) {
818 wl_list_for_each_safe(ivisurf, next,
819 &ivilayer->order.surface_list, order.link) {
820 remove_ordersurface_from_layer(ivisurf);
821
822 if (!wl_list_empty(&ivisurf->order.link)) {
823 wl_list_remove(&ivisurf->order.link);
824 }
825
826 wl_list_init(&ivisurf->order.link);
827 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
828 }
829
830 wl_list_init(&ivilayer->order.surface_list);
831 }
832
833 if (ivilayer->event_mask & IVI_NOTIFICATION_ADD) {
834 wl_list_for_each_safe(ivisurf, next,
835 &ivilayer->order.surface_list, order.link) {
836 remove_ordersurface_from_layer(ivisurf);
837
838 if (!wl_list_empty(&ivisurf->order.link)) {
839 wl_list_remove(&ivisurf->order.link);
840 }
841
842 wl_list_init(&ivisurf->order.link);
843 }
844
845 wl_list_init(&ivilayer->order.surface_list);
846 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
847 pending.link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300848 if (!wl_list_empty(&ivisurf->order.link)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900849 wl_list_remove(&ivisurf->order.link);
850 wl_list_init(&ivisurf->order.link);
851 }
852
853 wl_list_insert(&ivilayer->order.surface_list,
854 &ivisurf->order.link);
855 add_ordersurface_to_layer(ivisurf, ivilayer);
856 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
857 }
858 }
859 }
860}
861
862static void
863commit_screen_list(struct ivi_layout *layout)
864{
865 struct ivi_layout_screen *iviscrn = NULL;
866 struct ivi_layout_layer *ivilayer = NULL;
867 struct ivi_layout_layer *next = NULL;
868 struct ivi_layout_surface *ivisurf = NULL;
869
870 wl_list_for_each(iviscrn, &layout->screen_list, link) {
871 if (iviscrn->event_mask & IVI_NOTIFICATION_REMOVE) {
872 wl_list_for_each_safe(ivilayer, next,
873 &iviscrn->order.layer_list, order.link) {
874 remove_orderlayer_from_screen(ivilayer);
875
876 if (!wl_list_empty(&ivilayer->order.link)) {
877 wl_list_remove(&ivilayer->order.link);
878 }
879
880 wl_list_init(&ivilayer->order.link);
881 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
882 }
883 }
884
885 if (iviscrn->event_mask & IVI_NOTIFICATION_ADD) {
886 wl_list_for_each_safe(ivilayer, next,
887 &iviscrn->order.layer_list, order.link) {
888 remove_orderlayer_from_screen(ivilayer);
889
890 if (!wl_list_empty(&ivilayer->order.link)) {
891 wl_list_remove(&ivilayer->order.link);
892 }
893
894 wl_list_init(&ivilayer->order.link);
895 }
896
897 wl_list_init(&iviscrn->order.layer_list);
898 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
899 pending.link) {
900 wl_list_insert(&iviscrn->order.layer_list,
901 &ivilayer->order.link);
902 add_orderlayer_to_screen(ivilayer, iviscrn);
903 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
904 }
905 }
906
907 iviscrn->event_mask = 0;
908
909 /* Clear view list of layout ivi_layer */
910 wl_list_init(&layout->layout_layer.view_list.link);
911
912 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
913 if (ivilayer->prop.visibility == false)
914 continue;
915
916 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
917 struct weston_view *tmpview = NULL;
918 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
919 if (tmpview != NULL) {
920 break;
921 }
922 }
923
924 if (ivisurf->prop.visibility == false)
925 continue;
926 if (ivisurf->surface == NULL || tmpview == NULL)
927 continue;
928
929 weston_layer_entry_insert(&layout->layout_layer.view_list,
930 &tmpview->layer_link);
931
932 ivisurf->surface->output = iviscrn->output;
933 }
934 }
935
936 break;
937 }
938}
939
940static void
941commit_transition(struct ivi_layout* layout)
942{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300943 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900944 return;
945 }
946
947 wl_list_insert_list(&layout->transitions->transition_list,
948 &layout->pending_transition_list);
949
950 wl_list_init(&layout->pending_transition_list);
951
952 wl_event_source_timer_update(layout->transitions->event_source, 1);
953}
954
955static void
956send_surface_prop(struct ivi_layout_surface *ivisurf)
957{
958 wl_signal_emit(&ivisurf->property_changed, ivisurf);
959 ivisurf->event_mask = 0;
960}
961
962static void
963send_layer_prop(struct ivi_layout_layer *ivilayer)
964{
965 wl_signal_emit(&ivilayer->property_changed, ivilayer);
966 ivilayer->event_mask = 0;
967}
968
969static void
970send_prop(struct ivi_layout *layout)
971{
972 struct ivi_layout_layer *ivilayer = NULL;
973 struct ivi_layout_surface *ivisurf = NULL;
974
975 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900976 if (ivilayer->event_mask)
977 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900978 }
979
980 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900981 if (ivisurf->event_mask)
982 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900983 }
984}
985
986static void
987clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
988{
989 struct ivi_layout_surface *surface_link = NULL;
990 struct ivi_layout_surface *surface_next = NULL;
991
992 wl_list_for_each_safe(surface_link, surface_next,
993 &ivilayer->pending.surface_list, pending.link) {
994 if (!wl_list_empty(&surface_link->pending.link)) {
995 wl_list_remove(&surface_link->pending.link);
996 }
997
998 wl_list_init(&surface_link->pending.link);
999 }
1000
1001 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
1002}
1003
1004static void
1005clear_surface_order_list(struct ivi_layout_layer *ivilayer)
1006{
1007 struct ivi_layout_surface *surface_link = NULL;
1008 struct ivi_layout_surface *surface_next = NULL;
1009
1010 wl_list_for_each_safe(surface_link, surface_next,
1011 &ivilayer->order.surface_list, order.link) {
1012 if (!wl_list_empty(&surface_link->order.link)) {
1013 wl_list_remove(&surface_link->order.link);
1014 }
1015
1016 wl_list_init(&surface_link->order.link);
1017 }
1018
1019 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
1020}
1021
1022static void
1023layer_created(struct wl_listener *listener, void *data)
1024{
1025 struct ivi_layout_layer *ivilayer = data;
1026
1027 struct listener_layout_notification *notification =
1028 container_of(listener,
1029 struct listener_layout_notification,
1030 listener);
1031
1032 struct ivi_layout_notification_callback *created_callback =
1033 notification->userdata;
1034
1035 ((layer_create_notification_func)created_callback->callback)
1036 (ivilayer, created_callback->data);
1037}
1038
1039static void
1040layer_removed(struct wl_listener *listener, void *data)
1041{
1042 struct ivi_layout_layer *ivilayer = data;
1043
1044 struct listener_layout_notification *notification =
1045 container_of(listener,
1046 struct listener_layout_notification,
1047 listener);
1048
1049 struct ivi_layout_notification_callback *removed_callback =
1050 notification->userdata;
1051
1052 ((layer_remove_notification_func)removed_callback->callback)
1053 (ivilayer, removed_callback->data);
1054}
1055
1056static void
1057layer_prop_changed(struct wl_listener *listener, void *data)
1058{
1059 struct ivi_layout_layer *ivilayer = data;
1060
1061 struct listener_layout_notification *layout_listener =
1062 container_of(listener,
1063 struct listener_layout_notification,
1064 listener);
1065
1066 struct ivi_layout_notification_callback *prop_callback =
1067 layout_listener->userdata;
1068
1069 ((layer_property_notification_func)prop_callback->callback)
1070 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1071}
1072
1073static void
1074surface_created(struct wl_listener *listener, void *data)
1075{
1076 struct ivi_layout_surface *ivisurface = data;
1077
1078 struct listener_layout_notification *notification =
1079 container_of(listener,
1080 struct listener_layout_notification,
1081 listener);
1082
1083 struct ivi_layout_notification_callback *created_callback =
1084 notification->userdata;
1085
1086 ((surface_create_notification_func)created_callback->callback)
1087 (ivisurface, created_callback->data);
1088}
1089
1090static void
1091surface_removed(struct wl_listener *listener, void *data)
1092{
1093 struct ivi_layout_surface *ivisurface = data;
1094
1095 struct listener_layout_notification *notification =
1096 container_of(listener,
1097 struct listener_layout_notification,
1098 listener);
1099
1100 struct ivi_layout_notification_callback *removed_callback =
1101 notification->userdata;
1102
1103 ((surface_remove_notification_func)removed_callback->callback)
1104 (ivisurface, removed_callback->data);
1105}
1106
1107static void
1108surface_prop_changed(struct wl_listener *listener, void *data)
1109{
1110 struct ivi_layout_surface *ivisurf = data;
1111
1112 struct listener_layout_notification *layout_listener =
1113 container_of(listener,
1114 struct listener_layout_notification,
1115 listener);
1116
1117 struct ivi_layout_notification_callback *prop_callback =
1118 layout_listener->userdata;
1119
1120 ((surface_property_notification_func)prop_callback->callback)
1121 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1122
1123 ivisurf->event_mask = 0;
1124}
1125
1126static void
1127surface_configure_changed(struct wl_listener *listener,
1128 void *data)
1129{
1130 struct ivi_layout_surface *ivisurface = data;
1131
1132 struct listener_layout_notification *notification =
1133 container_of(listener,
1134 struct listener_layout_notification,
1135 listener);
1136
1137 struct ivi_layout_notification_callback *configure_changed_callback =
1138 notification->userdata;
1139
1140 ((surface_configure_notification_func)configure_changed_callback->callback)
1141 (ivisurface, configure_changed_callback->data);
1142}
1143
1144static int32_t
1145add_notification(struct wl_signal *signal,
1146 wl_notify_func_t callback,
1147 void *userdata)
1148{
1149 struct listener_layout_notification *notification = NULL;
1150
1151 notification = malloc(sizeof *notification);
1152 if (notification == NULL) {
1153 weston_log("fails to allocate memory\n");
1154 free(userdata);
1155 return IVI_FAILED;
1156 }
1157
1158 notification->listener.notify = callback;
1159 notification->userdata = userdata;
1160
1161 wl_signal_add(signal, &notification->listener);
1162
1163 return IVI_SUCCEEDED;
1164}
1165
1166static void
1167remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1168{
1169 struct wl_listener *listener = NULL;
1170 struct wl_listener *next = NULL;
1171
1172 wl_list_for_each_safe(listener, next, listener_list, link) {
1173 struct listener_layout_notification *notification =
1174 container_of(listener,
1175 struct listener_layout_notification,
1176 listener);
1177
1178 struct ivi_layout_notification_callback *notification_callback =
1179 notification->userdata;
1180
1181 if ((notification_callback->callback != callback) ||
1182 (notification_callback->data != userdata)) {
1183 continue;
1184 }
1185
1186 if (!wl_list_empty(&listener->link)) {
1187 wl_list_remove(&listener->link);
1188 }
1189
1190 free(notification->userdata);
1191 free(notification);
1192 }
1193}
1194
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001195/**
1196 * Exported APIs of ivi-layout library are implemented from here.
1197 * Brief of APIs is described in ivi-layout-export.h.
1198 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001199static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001200ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1201 void *userdata)
1202{
1203 struct ivi_layout *layout = get_instance();
1204 struct ivi_layout_notification_callback *created_callback = NULL;
1205
1206 if (callback == NULL) {
1207 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1208 return IVI_FAILED;
1209 }
1210
1211 created_callback = malloc(sizeof *created_callback);
1212 if (created_callback == NULL) {
1213 weston_log("fails to allocate memory\n");
1214 return IVI_FAILED;
1215 }
1216
1217 created_callback->callback = callback;
1218 created_callback->data = userdata;
1219
1220 return add_notification(&layout->layer_notification.created,
1221 layer_created,
1222 created_callback);
1223}
1224
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001225static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001226ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1227 void *userdata)
1228{
1229 struct ivi_layout *layout = get_instance();
1230 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1231}
1232
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001233static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001234ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1235 void *userdata)
1236{
1237 struct ivi_layout *layout = get_instance();
1238 struct ivi_layout_notification_callback *removed_callback = NULL;
1239
1240 if (callback == NULL) {
1241 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1242 return IVI_FAILED;
1243 }
1244
1245 removed_callback = malloc(sizeof *removed_callback);
1246 if (removed_callback == NULL) {
1247 weston_log("fails to allocate memory\n");
1248 return IVI_FAILED;
1249 }
1250
1251 removed_callback->callback = callback;
1252 removed_callback->data = userdata;
1253 return add_notification(&layout->layer_notification.removed,
1254 layer_removed,
1255 removed_callback);
1256}
1257
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001258static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001259ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1260 void *userdata)
1261{
1262 struct ivi_layout *layout = get_instance();
1263 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1264}
1265
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001266static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001267ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1268 void *userdata)
1269{
1270 struct ivi_layout *layout = get_instance();
1271 struct ivi_layout_notification_callback *created_callback = NULL;
1272
1273 if (callback == NULL) {
1274 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1275 return IVI_FAILED;
1276 }
1277
1278 created_callback = malloc(sizeof *created_callback);
1279 if (created_callback == NULL) {
1280 weston_log("fails to allocate memory\n");
1281 return IVI_FAILED;
1282 }
1283
1284 created_callback->callback = callback;
1285 created_callback->data = userdata;
1286
1287 return add_notification(&layout->surface_notification.created,
1288 surface_created,
1289 created_callback);
1290}
1291
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001292static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001293ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1294 void *userdata)
1295{
1296 struct ivi_layout *layout = get_instance();
1297 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1298}
1299
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001300static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001301ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1302 void *userdata)
1303{
1304 struct ivi_layout *layout = get_instance();
1305 struct ivi_layout_notification_callback *removed_callback = NULL;
1306
1307 if (callback == NULL) {
1308 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1309 return IVI_FAILED;
1310 }
1311
1312 removed_callback = malloc(sizeof *removed_callback);
1313 if (removed_callback == NULL) {
1314 weston_log("fails to allocate memory\n");
1315 return IVI_FAILED;
1316 }
1317
1318 removed_callback->callback = callback;
1319 removed_callback->data = userdata;
1320
1321 return add_notification(&layout->surface_notification.removed,
1322 surface_removed,
1323 removed_callback);
1324}
1325
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001326static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001327ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1328 void *userdata)
1329{
1330 struct ivi_layout *layout = get_instance();
1331 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1332}
1333
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001334static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001335ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1336 void *userdata)
1337{
1338 struct ivi_layout *layout = get_instance();
1339 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1340 if (callback == NULL) {
1341 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1342 return IVI_FAILED;
1343 }
1344
1345 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1346 if (configure_changed_callback == NULL) {
1347 weston_log("fails to allocate memory\n");
1348 return IVI_FAILED;
1349 }
1350
1351 configure_changed_callback->callback = callback;
1352 configure_changed_callback->data = userdata;
1353
1354 return add_notification(&layout->surface_notification.configure_changed,
1355 surface_configure_changed,
1356 configure_changed_callback);
1357}
1358
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001359static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001360ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1361 void *userdata)
1362{
1363 struct ivi_layout *layout = get_instance();
1364 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1365}
1366
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001367uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001368ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1369{
1370 return ivisurf->id_surface;
1371}
1372
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001373static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001374ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1375{
1376 return ivilayer->id_layer;
1377}
1378
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001379static uint32_t
1380ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1381{
1382 return iviscrn->id_screen;
1383}
1384
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001385static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001386ivi_layout_get_layer_from_id(uint32_t id_layer)
1387{
1388 struct ivi_layout *layout = get_instance();
1389 struct ivi_layout_layer *ivilayer = NULL;
1390
1391 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1392 if (ivilayer->id_layer == id_layer) {
1393 return ivilayer;
1394 }
1395 }
1396
1397 return NULL;
1398}
1399
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001400struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001401ivi_layout_get_surface_from_id(uint32_t id_surface)
1402{
1403 struct ivi_layout *layout = get_instance();
1404 struct ivi_layout_surface *ivisurf = NULL;
1405
1406 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1407 if (ivisurf->id_surface == id_surface) {
1408 return ivisurf;
1409 }
1410 }
1411
1412 return NULL;
1413}
1414
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001415static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001416ivi_layout_get_screen_from_id(uint32_t id_screen)
1417{
1418 struct ivi_layout *layout = get_instance();
1419 struct ivi_layout_screen *iviscrn = NULL;
1420
1421 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1422/* FIXME : select iviscrn from screen_list by id_screen */
1423 return iviscrn;
1424 break;
1425 }
1426
1427 return NULL;
1428}
1429
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001430static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001431ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1432 int32_t *pWidth, int32_t *pHeight)
1433{
1434 struct weston_output *output = NULL;
1435
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001436 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001437 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1438 return IVI_FAILED;
1439 }
1440
1441 output = iviscrn->output;
1442 *pWidth = output->current_mode->width;
1443 *pHeight = output->current_mode->height;
1444
1445 return IVI_SUCCEEDED;
1446}
1447
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001448static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001449ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1450 surface_property_notification_func callback,
1451 void *userdata)
1452{
1453 struct listener_layout_notification* notification = NULL;
1454 struct ivi_layout_notification_callback *prop_callback = NULL;
1455
1456 if (ivisurf == NULL || callback == NULL) {
1457 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1458 return IVI_FAILED;
1459 }
1460
1461 notification = malloc(sizeof *notification);
1462 if (notification == NULL) {
1463 weston_log("fails to allocate memory\n");
1464 return IVI_FAILED;
1465 }
1466
1467 prop_callback = malloc(sizeof *prop_callback);
1468 if (prop_callback == NULL) {
1469 weston_log("fails to allocate memory\n");
1470 return IVI_FAILED;
1471 }
1472
1473 prop_callback->callback = callback;
1474 prop_callback->data = userdata;
1475
1476 notification->listener.notify = surface_prop_changed;
1477 notification->userdata = prop_callback;
1478
1479 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1480
1481 return IVI_SUCCEEDED;
1482}
1483
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001484static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001485ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1486{
1487 if (ivilayer == NULL) {
1488 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1489 return NULL;
1490 }
1491
1492 return &ivilayer->prop;
1493}
1494
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001495static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001496ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1497{
1498 struct ivi_layout *layout = get_instance();
1499 struct ivi_layout_screen *iviscrn = NULL;
1500 int32_t length = 0;
1501 int32_t n = 0;
1502
1503 if (pLength == NULL || ppArray == NULL) {
1504 weston_log("ivi_layout_get_screens: invalid argument\n");
1505 return IVI_FAILED;
1506 }
1507
1508 length = wl_list_length(&layout->screen_list);
1509
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001510 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001511 /* the Array must be free by module which called this function */
1512 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1513 if (*ppArray == NULL) {
1514 weston_log("fails to allocate memory\n");
1515 return IVI_FAILED;
1516 }
1517
1518 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1519 (*ppArray)[n++] = iviscrn;
1520 }
1521 }
1522
1523 *pLength = length;
1524
1525 return IVI_SUCCEEDED;
1526}
1527
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001528static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001529ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1530 int32_t *pLength,
1531 struct ivi_layout_screen ***ppArray)
1532{
1533 struct link_screen *link_scrn = NULL;
1534 int32_t length = 0;
1535 int32_t n = 0;
1536
1537 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1538 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1539 return IVI_FAILED;
1540 }
1541
1542 length = wl_list_length(&ivilayer->screen_list);
1543
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001544 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001545 /* the Array must be free by module which called this function */
1546 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1547 if (*ppArray == NULL) {
1548 weston_log("fails to allocate memory\n");
1549 return IVI_FAILED;
1550 }
1551
1552 wl_list_for_each(link_scrn, &ivilayer->screen_list, link) {
1553 (*ppArray)[n++] = link_scrn->iviscrn;
1554 }
1555 }
1556
1557 *pLength = length;
1558
1559 return IVI_SUCCEEDED;
1560}
1561
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001562static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001563ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1564{
1565 struct ivi_layout *layout = get_instance();
1566 struct ivi_layout_layer *ivilayer = NULL;
1567 int32_t length = 0;
1568 int32_t n = 0;
1569
1570 if (pLength == NULL || ppArray == NULL) {
1571 weston_log("ivi_layout_get_layers: invalid argument\n");
1572 return IVI_FAILED;
1573 }
1574
1575 length = wl_list_length(&layout->layer_list);
1576
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001577 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001578 /* the Array must be free by module which called this function */
1579 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1580 if (*ppArray == NULL) {
1581 weston_log("fails to allocate memory\n");
1582 return IVI_FAILED;
1583 }
1584
1585 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1586 (*ppArray)[n++] = ivilayer;
1587 }
1588 }
1589
1590 *pLength = length;
1591
1592 return IVI_SUCCEEDED;
1593}
1594
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001595static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001596ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1597 int32_t *pLength,
1598 struct ivi_layout_layer ***ppArray)
1599{
1600 struct ivi_layout_layer *ivilayer = NULL;
1601 int32_t length = 0;
1602 int32_t n = 0;
1603
1604 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1605 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1606 return IVI_FAILED;
1607 }
1608
1609 length = wl_list_length(&iviscrn->order.layer_list);
1610
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001611 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001612 /* the Array must be free by module which called this function */
1613 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1614 if (*ppArray == NULL) {
1615 weston_log("fails to allocate memory\n");
1616 return IVI_FAILED;
1617 }
1618
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001619 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001620 (*ppArray)[n++] = ivilayer;
1621 }
1622 }
1623
1624 *pLength = length;
1625
1626 return IVI_SUCCEEDED;
1627}
1628
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001629static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001630ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1631 int32_t *pLength,
1632 struct ivi_layout_layer ***ppArray)
1633{
1634 struct link_layer *link_layer = NULL;
1635 int32_t length = 0;
1636 int32_t n = 0;
1637
1638 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1639 weston_log("ivi_layout_getLayers: invalid argument\n");
1640 return IVI_FAILED;
1641 }
1642
1643 length = wl_list_length(&ivisurf->layer_list);
1644
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001645 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001646 /* the Array must be free by module which called this function */
1647 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1648 if (*ppArray == NULL) {
1649 weston_log("fails to allocate memory\n");
1650 return IVI_FAILED;
1651 }
1652
1653 wl_list_for_each(link_layer, &ivisurf->layer_list, link) {
1654 (*ppArray)[n++] = link_layer->ivilayer;
1655 }
1656 }
1657
1658 *pLength = length;
1659
1660 return IVI_SUCCEEDED;
1661}
1662
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001663static
1664int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001665ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1666{
1667 struct ivi_layout *layout = get_instance();
1668 struct ivi_layout_surface *ivisurf = NULL;
1669 int32_t length = 0;
1670 int32_t n = 0;
1671
1672 if (pLength == NULL || ppArray == NULL) {
1673 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1674 return IVI_FAILED;
1675 }
1676
1677 length = wl_list_length(&layout->surface_list);
1678
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001679 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001680 /* the Array must be free by module which called this function */
1681 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1682 if (*ppArray == NULL) {
1683 weston_log("fails to allocate memory\n");
1684 return IVI_FAILED;
1685 }
1686
1687 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1688 (*ppArray)[n++] = ivisurf;
1689 }
1690 }
1691
1692 *pLength = length;
1693
1694 return IVI_SUCCEEDED;
1695}
1696
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001697static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001698ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1699 int32_t *pLength,
1700 struct ivi_layout_surface ***ppArray)
1701{
1702 struct ivi_layout_surface *ivisurf = NULL;
1703 int32_t length = 0;
1704 int32_t n = 0;
1705
1706 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1707 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1708 return IVI_FAILED;
1709 }
1710
1711 length = wl_list_length(&ivilayer->order.surface_list);
1712
1713 if (length != 0) {
1714 /* the Array must be free by module which called this function */
1715 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1716 if (*ppArray == NULL) {
1717 weston_log("fails to allocate memory\n");
1718 return IVI_FAILED;
1719 }
1720
1721 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1722 (*ppArray)[n++] = ivisurf;
1723 }
1724 }
1725
1726 *pLength = length;
1727
1728 return IVI_SUCCEEDED;
1729}
1730
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001731static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001732ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1733 int32_t width, int32_t height)
1734{
1735 struct ivi_layout *layout = get_instance();
1736 struct ivi_layout_layer *ivilayer = NULL;
1737
1738 ivilayer = get_layer(&layout->layer_list, id_layer);
1739 if (ivilayer != NULL) {
1740 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001741 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001742 return ivilayer;
1743 }
1744
1745 ivilayer = calloc(1, sizeof *ivilayer);
1746 if (ivilayer == NULL) {
1747 weston_log("fails to allocate memory\n");
1748 return NULL;
1749 }
1750
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001751 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001752 wl_list_init(&ivilayer->link);
1753 wl_signal_init(&ivilayer->property_changed);
1754 wl_list_init(&ivilayer->screen_list);
1755 wl_list_init(&ivilayer->link_to_surface);
1756 ivilayer->layout = layout;
1757 ivilayer->id_layer = id_layer;
1758
1759 init_layer_properties(&ivilayer->prop, width, height);
1760 ivilayer->event_mask = 0;
1761
1762 wl_list_init(&ivilayer->pending.surface_list);
1763 wl_list_init(&ivilayer->pending.link);
1764 ivilayer->pending.prop = ivilayer->prop;
1765
1766 wl_list_init(&ivilayer->order.surface_list);
1767 wl_list_init(&ivilayer->order.link);
1768
1769 wl_list_insert(&layout->layer_list, &ivilayer->link);
1770
1771 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1772
1773 return ivilayer;
1774}
1775
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001776static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001777ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1778{
1779 if (ivilayer == NULL) {
1780 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1781 return;
1782 }
1783
1784 remove_all_notification(&ivilayer->property_changed.listener_list);
1785}
1786
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001787static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001788ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1789 layer_property_notification_func callback,
1790 void *userdata)
1791{
1792 if (ivilayer == NULL) {
1793 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1794 return;
1795 }
1796
1797 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1798}
1799
1800static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001801ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001802{
1803 struct ivi_layout *layout = get_instance();
1804
1805 if (ivilayer == NULL) {
1806 weston_log("ivi_layout_layer_remove: invalid argument\n");
1807 return;
1808 }
1809
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001810 if (--ivilayer->ref_count > 0)
1811 return;
1812
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001813 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1814
1815 clear_surface_pending_list(ivilayer);
1816 clear_surface_order_list(ivilayer);
1817
1818 if (!wl_list_empty(&ivilayer->pending.link)) {
1819 wl_list_remove(&ivilayer->pending.link);
1820 }
1821 if (!wl_list_empty(&ivilayer->order.link)) {
1822 wl_list_remove(&ivilayer->order.link);
1823 }
1824 if (!wl_list_empty(&ivilayer->link)) {
1825 wl_list_remove(&ivilayer->link);
1826 }
1827 remove_orderlayer_from_screen(ivilayer);
1828 remove_link_to_surface(ivilayer);
1829 ivi_layout_layer_remove_notification(ivilayer);
1830
1831 free(ivilayer);
1832}
1833
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001834int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001835ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1836 bool newVisibility)
1837{
1838 struct ivi_layout_layer_properties *prop = NULL;
1839
1840 if (ivilayer == NULL) {
1841 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1842 return IVI_FAILED;
1843 }
1844
1845 prop = &ivilayer->pending.prop;
1846 prop->visibility = newVisibility;
1847
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001848 if (ivilayer->prop.visibility != newVisibility)
1849 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1850 else
1851 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001852
1853 return IVI_SUCCEEDED;
1854}
1855
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001856static bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001857ivi_layout_layer_get_visibility(struct ivi_layout_layer *ivilayer)
1858{
1859 if (ivilayer == NULL) {
1860 weston_log("ivi_layout_layer_get_visibility: invalid argument\n");
1861 return false;
1862 }
1863
1864 return ivilayer->prop.visibility;
1865}
1866
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001867int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001868ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1869 wl_fixed_t opacity)
1870{
1871 struct ivi_layout_layer_properties *prop = NULL;
1872
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001873 if (ivilayer == NULL ||
1874 opacity < wl_fixed_from_double(0.0) ||
1875 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001876 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1877 return IVI_FAILED;
1878 }
1879
1880 prop = &ivilayer->pending.prop;
1881 prop->opacity = opacity;
1882
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001883 if (ivilayer->prop.opacity != opacity)
1884 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1885 else
1886 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001887
1888 return IVI_SUCCEEDED;
1889}
1890
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001891wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001892ivi_layout_layer_get_opacity(struct ivi_layout_layer *ivilayer)
1893{
1894 if (ivilayer == NULL) {
1895 weston_log("ivi_layout_layer_get_opacity: invalid argument\n");
1896 return wl_fixed_from_double(0.0);
1897 }
1898
1899 return ivilayer->prop.opacity;
1900}
1901
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001902static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001903ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1904 int32_t x, int32_t y,
1905 int32_t width, int32_t height)
1906{
1907 struct ivi_layout_layer_properties *prop = NULL;
1908
1909 if (ivilayer == NULL) {
1910 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1911 return IVI_FAILED;
1912 }
1913
1914 prop = &ivilayer->pending.prop;
1915 prop->source_x = x;
1916 prop->source_y = y;
1917 prop->source_width = width;
1918 prop->source_height = height;
1919
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001920 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1921 ivilayer->prop.source_width != width ||
1922 ivilayer->prop.source_height != height)
1923 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1924 else
1925 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001926
1927 return IVI_SUCCEEDED;
1928}
1929
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001930static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001931ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1932 int32_t x, int32_t y,
1933 int32_t width, int32_t height)
1934{
1935 struct ivi_layout_layer_properties *prop = NULL;
1936
1937 if (ivilayer == NULL) {
1938 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1939 return IVI_FAILED;
1940 }
1941
1942 prop = &ivilayer->pending.prop;
1943 prop->dest_x = x;
1944 prop->dest_y = y;
1945 prop->dest_width = width;
1946 prop->dest_height = height;
1947
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001948 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1949 ivilayer->prop.dest_width != width ||
1950 ivilayer->prop.dest_height != height)
1951 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1952 else
1953 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001954
1955 return IVI_SUCCEEDED;
1956}
1957
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001958static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001959ivi_layout_layer_get_dimension(struct ivi_layout_layer *ivilayer,
1960 int32_t *dest_width, int32_t *dest_height)
1961{
1962 if (ivilayer == NULL || dest_width == NULL || dest_height == NULL) {
1963 weston_log("ivi_layout_layer_get_dimension: invalid argument\n");
1964 return IVI_FAILED;
1965 }
1966
1967 *dest_width = ivilayer->prop.dest_width;
1968 *dest_height = ivilayer->prop.dest_height;
1969
1970 return IVI_SUCCEEDED;
1971}
1972
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001973static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001974ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
1975 int32_t dest_width, int32_t dest_height)
1976{
1977 struct ivi_layout_layer_properties *prop = NULL;
1978
1979 if (ivilayer == NULL) {
1980 weston_log("ivi_layout_layer_set_dimension: invalid argument\n");
1981 return IVI_FAILED;
1982 }
1983
1984 prop = &ivilayer->pending.prop;
1985
1986 prop->dest_width = dest_width;
1987 prop->dest_height = dest_height;
1988
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001989 if (ivilayer->prop.dest_width != dest_width ||
1990 ivilayer->prop.dest_height != dest_height)
1991 ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
1992 else
1993 ivilayer->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001994
1995 return IVI_SUCCEEDED;
1996}
1997
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001998int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001999ivi_layout_layer_get_position(struct ivi_layout_layer *ivilayer,
2000 int32_t *dest_x, int32_t *dest_y)
2001{
2002 if (ivilayer == NULL || dest_x == NULL || dest_y == NULL) {
2003 weston_log("ivi_layout_layer_get_position: invalid argument\n");
2004 return IVI_FAILED;
2005 }
2006
2007 *dest_x = ivilayer->prop.dest_x;
2008 *dest_y = ivilayer->prop.dest_y;
2009
2010 return IVI_SUCCEEDED;
2011}
2012
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002013int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002014ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
2015 int32_t dest_x, int32_t dest_y)
2016{
2017 struct ivi_layout_layer_properties *prop = NULL;
2018
2019 if (ivilayer == NULL) {
2020 weston_log("ivi_layout_layer_set_position: invalid argument\n");
2021 return IVI_FAILED;
2022 }
2023
2024 prop = &ivilayer->pending.prop;
2025 prop->dest_x = dest_x;
2026 prop->dest_y = dest_y;
2027
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002028 if (ivilayer->prop.dest_x != dest_x || ivilayer->prop.dest_y != dest_y)
2029 ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
2030 else
2031 ivilayer->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002032
2033 return IVI_SUCCEEDED;
2034}
2035
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002036static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002037ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
2038 enum wl_output_transform orientation)
2039{
2040 struct ivi_layout_layer_properties *prop = NULL;
2041
2042 if (ivilayer == NULL) {
2043 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
2044 return IVI_FAILED;
2045 }
2046
2047 prop = &ivilayer->pending.prop;
2048 prop->orientation = orientation;
2049
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002050 if (ivilayer->prop.orientation != orientation)
2051 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2052 else
2053 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002054
2055 return IVI_SUCCEEDED;
2056}
2057
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002058static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002059ivi_layout_layer_get_orientation(struct ivi_layout_layer *ivilayer)
2060{
2061 if (ivilayer == NULL) {
2062 weston_log("ivi_layout_layer_get_orientation: invalid argument\n");
2063 return 0;
2064 }
2065
2066 return ivilayer->prop.orientation;
2067}
2068
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002069int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002070ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
2071 struct ivi_layout_surface **pSurface,
2072 int32_t number)
2073{
2074 struct ivi_layout *layout = get_instance();
2075 struct ivi_layout_surface *ivisurf = NULL;
2076 struct ivi_layout_surface *next = NULL;
2077 uint32_t *id_surface = NULL;
2078 int32_t i = 0;
2079
2080 if (ivilayer == NULL) {
2081 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
2082 return IVI_FAILED;
2083 }
2084
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00002085 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002086
2087 for (i = 0; i < number; i++) {
2088 id_surface = &pSurface[i]->id_surface;
2089
2090 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2091 if (*id_surface != ivisurf->id_surface) {
2092 continue;
2093 }
2094
2095 if (!wl_list_empty(&ivisurf->pending.link)) {
2096 wl_list_remove(&ivisurf->pending.link);
2097 }
2098 wl_list_init(&ivisurf->pending.link);
2099 wl_list_insert(&ivilayer->pending.surface_list,
2100 &ivisurf->pending.link);
2101 break;
2102 }
2103 }
2104
2105 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
2106
2107 return IVI_SUCCEEDED;
2108}
2109
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002110int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002111ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
2112 bool newVisibility)
2113{
2114 struct ivi_layout_surface_properties *prop = NULL;
2115
2116 if (ivisurf == NULL) {
2117 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
2118 return IVI_FAILED;
2119 }
2120
2121 prop = &ivisurf->pending.prop;
2122 prop->visibility = newVisibility;
2123
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002124 if (ivisurf->prop.visibility != newVisibility)
2125 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
2126 else
2127 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002128
2129 return IVI_SUCCEEDED;
2130}
2131
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002132bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002133ivi_layout_surface_get_visibility(struct ivi_layout_surface *ivisurf)
2134{
2135 if (ivisurf == NULL) {
2136 weston_log("ivi_layout_surface_get_visibility: invalid argument\n");
2137 return false;
2138 }
2139
2140 return ivisurf->prop.visibility;
2141}
2142
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002143int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002144ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
2145 wl_fixed_t opacity)
2146{
2147 struct ivi_layout_surface_properties *prop = NULL;
2148
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09002149 if (ivisurf == NULL ||
2150 opacity < wl_fixed_from_double(0.0) ||
2151 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002152 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
2153 return IVI_FAILED;
2154 }
2155
2156 prop = &ivisurf->pending.prop;
2157 prop->opacity = opacity;
2158
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002159 if (ivisurf->prop.opacity != opacity)
2160 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
2161 else
2162 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002163
2164 return IVI_SUCCEEDED;
2165}
2166
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002167wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002168ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
2169{
2170 if (ivisurf == NULL) {
2171 weston_log("ivi_layout_surface_get_opacity: invalid argument\n");
2172 return wl_fixed_from_double(0.0);
2173 }
2174
2175 return ivisurf->prop.opacity;
2176}
2177
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002178int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002179ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
2180 int32_t x, int32_t y,
2181 int32_t width, int32_t height)
2182{
2183 struct ivi_layout_surface_properties *prop = NULL;
2184
2185 if (ivisurf == NULL) {
2186 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
2187 return IVI_FAILED;
2188 }
2189
2190 prop = &ivisurf->pending.prop;
2191 prop->start_x = prop->dest_x;
2192 prop->start_y = prop->dest_y;
2193 prop->dest_x = x;
2194 prop->dest_y = y;
2195 prop->start_width = prop->dest_width;
2196 prop->start_height = prop->dest_height;
2197 prop->dest_width = width;
2198 prop->dest_height = height;
2199
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002200 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2201 ivisurf->prop.dest_width != width ||
2202 ivisurf->prop.dest_height != height)
2203 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2204 else
2205 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002206
2207 return IVI_SUCCEEDED;
2208}
2209
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002210static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002211ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
2212 int32_t dest_width, int32_t dest_height)
2213{
2214 struct ivi_layout_surface_properties *prop = NULL;
2215
2216 if (ivisurf == NULL) {
2217 weston_log("ivi_layout_surface_set_dimension: invalid argument\n");
2218 return IVI_FAILED;
2219 }
2220
2221 prop = &ivisurf->pending.prop;
2222 prop->dest_width = dest_width;
2223 prop->dest_height = dest_height;
2224
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002225 if (ivisurf->prop.dest_width != dest_width ||
2226 ivisurf->prop.dest_height != dest_height)
2227 ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
2228 else
2229 ivisurf->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002230
2231 return IVI_SUCCEEDED;
2232}
2233
2234int32_t
2235ivi_layout_surface_get_dimension(struct ivi_layout_surface *ivisurf,
2236 int32_t *dest_width, int32_t *dest_height)
2237{
2238 if (ivisurf == NULL || dest_width == NULL || dest_height == NULL) {
2239 weston_log("ivi_layout_surface_get_dimension: invalid argument\n");
2240 return IVI_FAILED;
2241 }
2242
2243 *dest_width = ivisurf->prop.dest_width;
2244 *dest_height = ivisurf->prop.dest_height;
2245
2246 return IVI_SUCCEEDED;
2247}
2248
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002249static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002250ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
2251 int32_t dest_x, int32_t dest_y)
2252{
2253 struct ivi_layout_surface_properties *prop = NULL;
2254
2255 if (ivisurf == NULL) {
2256 weston_log("ivi_layout_surface_set_position: invalid argument\n");
2257 return IVI_FAILED;
2258 }
2259
2260 prop = &ivisurf->pending.prop;
2261 prop->dest_x = dest_x;
2262 prop->dest_y = dest_y;
2263
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002264 if (ivisurf->prop.dest_x != dest_x || ivisurf->prop.dest_y != dest_y)
2265 ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
2266 else
2267 ivisurf->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002268
2269 return IVI_SUCCEEDED;
2270}
2271
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002272static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002273ivi_layout_surface_get_position(struct ivi_layout_surface *ivisurf,
2274 int32_t *dest_x, int32_t *dest_y)
2275{
2276 if (ivisurf == NULL || dest_x == NULL || dest_y == NULL) {
2277 weston_log("ivi_layout_surface_get_position: invalid argument\n");
2278 return IVI_FAILED;
2279 }
2280
2281 *dest_x = ivisurf->prop.dest_x;
2282 *dest_y = ivisurf->prop.dest_y;
2283
2284 return IVI_SUCCEEDED;
2285}
2286
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002287static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002288ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2289 enum wl_output_transform orientation)
2290{
2291 struct ivi_layout_surface_properties *prop = NULL;
2292
2293 if (ivisurf == NULL) {
2294 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2295 return IVI_FAILED;
2296 }
2297
2298 prop = &ivisurf->pending.prop;
2299 prop->orientation = orientation;
2300
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002301 if (ivisurf->prop.orientation != orientation)
2302 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2303 else
2304 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002305
2306 return IVI_SUCCEEDED;
2307}
2308
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002309static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002310ivi_layout_surface_get_orientation(struct ivi_layout_surface *ivisurf)
2311{
2312 if (ivisurf == NULL) {
2313 weston_log("ivi_layout_surface_get_orientation: invalid argument\n");
2314 return 0;
2315 }
2316
2317 return ivisurf->prop.orientation;
2318}
2319
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002320static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002321ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2322 struct ivi_layout_layer *addlayer)
2323{
2324 struct ivi_layout *layout = get_instance();
2325 struct ivi_layout_layer *ivilayer = NULL;
2326 struct ivi_layout_layer *next = NULL;
2327 int is_layer_in_scrn = 0;
2328
2329 if (iviscrn == NULL || addlayer == NULL) {
2330 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2331 return IVI_FAILED;
2332 }
2333
2334 is_layer_in_scrn = is_layer_in_screen(addlayer, iviscrn);
2335 if (is_layer_in_scrn == 1) {
2336 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2337 return IVI_SUCCEEDED;
2338 }
2339
2340 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2341 if (ivilayer->id_layer == addlayer->id_layer) {
2342 if (!wl_list_empty(&ivilayer->pending.link)) {
2343 wl_list_remove(&ivilayer->pending.link);
2344 }
2345 wl_list_init(&ivilayer->pending.link);
2346 wl_list_insert(&iviscrn->pending.layer_list,
2347 &ivilayer->pending.link);
2348 break;
2349 }
2350 }
2351
2352 iviscrn->event_mask |= IVI_NOTIFICATION_ADD;
2353
2354 return IVI_SUCCEEDED;
2355}
2356
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002357static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002358ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2359 struct ivi_layout_layer **pLayer,
2360 const int32_t number)
2361{
2362 struct ivi_layout *layout = get_instance();
2363 struct ivi_layout_layer *ivilayer = NULL;
2364 struct ivi_layout_layer *next = NULL;
2365 uint32_t *id_layer = NULL;
2366 int32_t i = 0;
2367
2368 if (iviscrn == NULL) {
2369 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2370 return IVI_FAILED;
2371 }
2372
2373 wl_list_for_each_safe(ivilayer, next,
2374 &iviscrn->pending.layer_list, pending.link) {
2375 wl_list_init(&ivilayer->pending.link);
2376 }
2377
2378 wl_list_init(&iviscrn->pending.layer_list);
2379
2380 if (pLayer == NULL) {
2381 wl_list_for_each_safe(ivilayer, next, &iviscrn->pending.layer_list, pending.link) {
2382 if (!wl_list_empty(&ivilayer->pending.link)) {
2383 wl_list_remove(&ivilayer->pending.link);
2384 }
2385
2386 wl_list_init(&ivilayer->pending.link);
2387 }
2388
2389 iviscrn->event_mask |= IVI_NOTIFICATION_REMOVE;
2390 return IVI_SUCCEEDED;
2391 }
2392
2393 for (i = 0; i < number; i++) {
2394 id_layer = &pLayer[i]->id_layer;
2395 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2396 if (*id_layer != ivilayer->id_layer) {
2397 continue;
2398 }
2399
2400 if (!wl_list_empty(&ivilayer->pending.link)) {
2401 wl_list_remove(&ivilayer->pending.link);
2402 }
2403 wl_list_init(&ivilayer->pending.link);
2404 wl_list_insert(&iviscrn->pending.layer_list,
2405 &ivilayer->pending.link);
2406 break;
2407 }
2408 }
2409
2410 iviscrn->event_mask |= IVI_NOTIFICATION_ADD;
2411
2412 return IVI_SUCCEEDED;
2413}
2414
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002415static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002416ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2417{
2418 return iviscrn->output;
2419}
2420
2421/**
2422 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2423 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2424 * This function is used to get the result of drawing by clients.
2425 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002426static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002427ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2428{
2429 return ivisurf != NULL ? ivisurf->surface : NULL;
2430}
2431
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002432static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002433ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2434 int32_t *width, int32_t *height,
2435 int32_t *stride)
2436{
2437 int32_t w;
2438 int32_t h;
2439 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2440
2441 if (ivisurf == NULL || ivisurf->surface == NULL) {
2442 weston_log("%s: invalid argument\n", __func__);
2443 return IVI_FAILED;
2444 }
2445
2446 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2447
2448 if (width != NULL)
2449 *width = w;
2450
2451 if (height != NULL)
2452 *height = h;
2453
2454 if (stride != NULL)
2455 *stride = w * bytespp;
2456
2457 return IVI_SUCCEEDED;
2458}
2459
2460static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002461ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2462 layer_property_notification_func callback,
2463 void *userdata)
2464{
2465 struct ivi_layout_notification_callback *prop_callback = NULL;
2466
2467 if (ivilayer == NULL || callback == NULL) {
2468 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2469 return IVI_FAILED;
2470 }
2471
2472 prop_callback = malloc(sizeof *prop_callback);
2473 if (prop_callback == NULL) {
2474 weston_log("fails to allocate memory\n");
2475 return IVI_FAILED;
2476 }
2477
2478 prop_callback->callback = callback;
2479 prop_callback->data = userdata;
2480
2481 return add_notification(&ivilayer->property_changed,
2482 layer_prop_changed,
2483 prop_callback);
2484}
2485
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002486static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002487ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2488{
2489 if (ivisurf == NULL) {
2490 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2491 return NULL;
2492 }
2493
2494 return &ivisurf->prop;
2495}
2496
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002497static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002498ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2499 struct ivi_layout_surface *addsurf)
2500{
2501 struct ivi_layout *layout = get_instance();
2502 struct ivi_layout_surface *ivisurf = NULL;
2503 struct ivi_layout_surface *next = NULL;
2504 int is_surf_in_layer = 0;
2505
2506 if (ivilayer == NULL || addsurf == NULL) {
2507 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2508 return IVI_FAILED;
2509 }
2510
2511 is_surf_in_layer = is_surface_in_layer(addsurf, ivilayer);
2512 if (is_surf_in_layer == 1) {
2513 weston_log("ivi_layout_layer_add_surface: addsurf is already available\n");
2514 return IVI_SUCCEEDED;
2515 }
2516
2517 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2518 if (ivisurf->id_surface == addsurf->id_surface) {
2519 if (!wl_list_empty(&ivisurf->pending.link)) {
2520 wl_list_remove(&ivisurf->pending.link);
2521 }
2522 wl_list_init(&ivisurf->pending.link);
2523 wl_list_insert(&ivilayer->pending.surface_list,
2524 &ivisurf->pending.link);
2525 break;
2526 }
2527 }
2528
2529 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
2530
2531 return IVI_SUCCEEDED;
2532}
2533
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002534static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002535ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2536 struct ivi_layout_surface *remsurf)
2537{
2538 struct ivi_layout_surface *ivisurf = NULL;
2539 struct ivi_layout_surface *next = NULL;
2540
2541 if (ivilayer == NULL || remsurf == NULL) {
2542 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2543 return;
2544 }
2545
2546 wl_list_for_each_safe(ivisurf, next,
2547 &ivilayer->pending.surface_list, pending.link) {
2548 if (ivisurf->id_surface == remsurf->id_surface) {
2549 if (!wl_list_empty(&ivisurf->pending.link)) {
2550 wl_list_remove(&ivisurf->pending.link);
2551 }
2552 wl_list_init(&ivisurf->pending.link);
2553 break;
2554 }
2555 }
2556
2557 remsurf->event_mask |= IVI_NOTIFICATION_REMOVE;
2558}
2559
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002560static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002561ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2562 int32_t x, int32_t y,
2563 int32_t width, int32_t height)
2564{
2565 struct ivi_layout_surface_properties *prop = NULL;
2566
2567 if (ivisurf == NULL) {
2568 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2569 return IVI_FAILED;
2570 }
2571
2572 prop = &ivisurf->pending.prop;
2573 prop->source_x = x;
2574 prop->source_y = y;
2575 prop->source_width = width;
2576 prop->source_height = height;
2577
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002578 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2579 ivisurf->prop.source_width != width ||
2580 ivisurf->prop.source_height != height)
2581 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2582 else
2583 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002584
2585 return IVI_SUCCEEDED;
2586}
2587
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002588int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002589ivi_layout_commit_changes(void)
2590{
2591 struct ivi_layout *layout = get_instance();
2592
2593 commit_surface_list(layout);
2594 commit_layer_list(layout);
2595 commit_screen_list(layout);
2596
2597 commit_transition(layout);
2598
2599 commit_changes(layout);
2600 send_prop(layout);
2601 weston_compositor_schedule_repaint(layout->compositor);
2602
2603 return IVI_SUCCEEDED;
2604}
2605
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002606static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002607ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2608 enum ivi_layout_transition_type type,
2609 uint32_t duration)
2610{
2611 if (ivilayer == NULL) {
2612 weston_log("%s: invalid argument\n", __func__);
2613 return -1;
2614 }
2615
2616 ivilayer->pending.prop.transition_type = type;
2617 ivilayer->pending.prop.transition_duration = duration;
2618
2619 return 0;
2620}
2621
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002622static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002623ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2624 uint32_t is_fade_in,
2625 double start_alpha, double end_alpha)
2626{
2627 if (ivilayer == NULL) {
2628 weston_log("%s: invalid argument\n", __func__);
2629 return -1;
2630 }
2631
2632 ivilayer->pending.prop.is_fade_in = is_fade_in;
2633 ivilayer->pending.prop.start_alpha = start_alpha;
2634 ivilayer->pending.prop.end_alpha = end_alpha;
2635
2636 return 0;
2637}
2638
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002639static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002640ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2641 uint32_t duration)
2642{
2643 struct ivi_layout_surface_properties *prop;
2644
2645 if (ivisurf == NULL) {
2646 weston_log("%s: invalid argument\n", __func__);
2647 return -1;
2648 }
2649
2650 prop = &ivisurf->pending.prop;
2651 prop->transition_duration = duration*10;
2652 return 0;
2653}
2654
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002655static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002656ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2657 enum ivi_layout_transition_type type,
2658 uint32_t duration)
2659{
2660 struct ivi_layout_surface_properties *prop;
2661
2662 if (ivisurf == NULL) {
2663 weston_log("%s: invalid argument\n", __func__);
2664 return -1;
2665 }
2666
2667 prop = &ivisurf->pending.prop;
2668 prop->transition_type = type;
2669 prop->transition_duration = duration;
2670 return 0;
2671}
2672
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002673static int32_t
2674ivi_layout_surface_dump(struct weston_surface *surface,
2675 void *target, size_t size,int32_t x, int32_t y,
2676 int32_t width, int32_t height)
2677{
2678 int result = 0;
2679
2680 if (surface == NULL) {
2681 weston_log("%s: invalid argument\n", __func__);
2682 return IVI_FAILED;
2683 }
2684
2685 result = weston_surface_copy_content(
2686 surface, target, size,
2687 x, y, width, height);
2688
2689 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2690}
2691
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002692/**
2693 * methods of interaction between ivi-shell with ivi-layout
2694 */
2695struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002696ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2697{
2698 struct weston_view *tmpview = NULL;
2699
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002700 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002701 return NULL;
2702
2703 wl_list_for_each(tmpview, &surface->surface->views, surface_link)
2704 {
2705 if (tmpview != NULL) {
2706 break;
2707 }
2708 }
2709 return tmpview;
2710}
2711
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002712void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002713ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2714 int32_t width, int32_t height)
2715{
2716 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002717
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002718 /* emit callback which is set by ivi-layout api user */
2719 wl_signal_emit(&layout->surface_notification.configure_changed,
2720 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002721}
2722
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002723static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002724ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2725 ivi_controller_surface_content_callback callback,
2726 void* userdata)
2727{
2728 int32_t ret = IVI_FAILED;
2729
2730 if (ivisurf != NULL) {
2731 ivisurf->content_observer.callback = callback;
2732 ivisurf->content_observer.userdata = userdata;
2733 ret = IVI_SUCCEEDED;
2734 }
2735 return ret;
2736}
2737
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002738struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002739ivi_layout_surface_create(struct weston_surface *wl_surface,
2740 uint32_t id_surface)
2741{
2742 struct ivi_layout *layout = get_instance();
2743 struct ivi_layout_surface *ivisurf = NULL;
2744 struct weston_view *tmpview = NULL;
2745
2746 if (wl_surface == NULL) {
2747 weston_log("ivi_layout_surface_create: invalid argument\n");
2748 return NULL;
2749 }
2750
2751 ivisurf = get_surface(&layout->surface_list, id_surface);
2752 if (ivisurf != NULL) {
2753 if (ivisurf->surface != NULL) {
2754 weston_log("id_surface(%d) is already created\n", id_surface);
2755 return NULL;
2756 }
2757 }
2758
2759 ivisurf = calloc(1, sizeof *ivisurf);
2760 if (ivisurf == NULL) {
2761 weston_log("fails to allocate memory\n");
2762 return NULL;
2763 }
2764
2765 wl_list_init(&ivisurf->link);
2766 wl_signal_init(&ivisurf->property_changed);
2767 wl_signal_init(&ivisurf->configured);
2768 wl_list_init(&ivisurf->layer_list);
2769 ivisurf->id_surface = id_surface;
2770 ivisurf->layout = layout;
2771
2772 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002773
2774 tmpview = weston_view_create(wl_surface);
2775 if (tmpview == NULL) {
2776 weston_log("fails to allocate memory\n");
2777 }
2778
2779 ivisurf->surface->width_from_buffer = 0;
2780 ivisurf->surface->height_from_buffer = 0;
2781
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002782 weston_matrix_init(&ivisurf->transform.matrix);
2783 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002784
2785 init_surface_properties(&ivisurf->prop);
2786 ivisurf->event_mask = 0;
2787
2788 ivisurf->pending.prop = ivisurf->prop;
2789 wl_list_init(&ivisurf->pending.link);
2790
2791 wl_list_init(&ivisurf->order.link);
2792 wl_list_init(&ivisurf->order.layer_list);
2793
2794 wl_list_insert(&layout->surface_list, &ivisurf->link);
2795
2796 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2797
2798 return ivisurf;
2799}
2800
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002801void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002802ivi_layout_init_with_compositor(struct weston_compositor *ec)
2803{
2804 struct ivi_layout *layout = get_instance();
2805
2806 layout->compositor = ec;
2807
2808 wl_list_init(&layout->surface_list);
2809 wl_list_init(&layout->layer_list);
2810 wl_list_init(&layout->screen_list);
2811
2812 wl_signal_init(&layout->layer_notification.created);
2813 wl_signal_init(&layout->layer_notification.removed);
2814
2815 wl_signal_init(&layout->surface_notification.created);
2816 wl_signal_init(&layout->surface_notification.removed);
2817 wl_signal_init(&layout->surface_notification.configure_changed);
2818
2819 /* Add layout_layer at the last of weston_compositor.layer_list */
2820 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2821
2822 create_screen(ec);
2823
2824 layout->transitions = ivi_layout_transition_set_create(ec);
2825 wl_list_init(&layout->pending_transition_list);
2826}
2827
2828
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002829void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002830ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2831 struct wl_listener* listener)
2832{
2833 wl_signal_add(&ivisurf->configured, listener);
2834}
2835
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002836static struct ivi_controller_interface ivi_controller_interface = {
2837 /**
2838 * commit all changes
2839 */
2840 .commit_changes = ivi_layout_commit_changes,
2841
2842 /**
2843 * surface controller interfaces
2844 */
2845 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2846 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2847 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2848 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2849 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2850 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2851 .get_surfaces = ivi_layout_get_surfaces,
2852 .get_id_of_surface = ivi_layout_get_id_of_surface,
2853 .get_surface_from_id = ivi_layout_get_surface_from_id,
2854 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2855 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2856 .surface_set_visibility = ivi_layout_surface_set_visibility,
2857 .surface_get_visibility = ivi_layout_surface_get_visibility,
2858 .surface_set_opacity = ivi_layout_surface_set_opacity,
2859 .surface_get_opacity = ivi_layout_surface_get_opacity,
2860 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2861 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
2862 .surface_set_position = ivi_layout_surface_set_position,
2863 .surface_get_position = ivi_layout_surface_get_position,
2864 .surface_set_dimension = ivi_layout_surface_set_dimension,
2865 .surface_get_dimension = ivi_layout_surface_get_dimension,
2866 .surface_set_orientation = ivi_layout_surface_set_orientation,
2867 .surface_get_orientation = ivi_layout_surface_get_orientation,
2868 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2869 .surface_add_notification = ivi_layout_surface_add_notification,
2870 .surface_remove_notification = ivi_layout_surface_remove_notification,
2871 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2872 .surface_set_transition = ivi_layout_surface_set_transition,
2873 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2874
2875 /**
2876 * layer controller interfaces
2877 */
2878 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2879 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2880 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2881 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2882 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002883 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002884 .get_layers = ivi_layout_get_layers,
2885 .get_id_of_layer = ivi_layout_get_id_of_layer,
2886 .get_layer_from_id = ivi_layout_get_layer_from_id,
2887 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2888 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2889 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2890 .layer_set_visibility = ivi_layout_layer_set_visibility,
2891 .layer_get_visibility = ivi_layout_layer_get_visibility,
2892 .layer_set_opacity = ivi_layout_layer_set_opacity,
2893 .layer_get_opacity = ivi_layout_layer_get_opacity,
2894 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2895 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
2896 .layer_set_position = ivi_layout_layer_set_position,
2897 .layer_get_position = ivi_layout_layer_get_position,
2898 .layer_set_dimension = ivi_layout_layer_set_dimension,
2899 .layer_get_dimension = ivi_layout_layer_get_dimension,
2900 .layer_set_orientation = ivi_layout_layer_set_orientation,
2901 .layer_get_orientation = ivi_layout_layer_get_orientation,
2902 .layer_add_surface = ivi_layout_layer_add_surface,
2903 .layer_remove_surface = ivi_layout_layer_remove_surface,
2904 .layer_set_render_order = ivi_layout_layer_set_render_order,
2905 .layer_add_notification = ivi_layout_layer_add_notification,
2906 .layer_remove_notification = ivi_layout_layer_remove_notification,
2907 .layer_set_transition = ivi_layout_layer_set_transition,
2908
2909 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002910 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002911 */
2912 .get_screen_from_id = ivi_layout_get_screen_from_id,
2913 .get_screen_resolution = ivi_layout_get_screen_resolution,
2914 .get_screens = ivi_layout_get_screens,
2915 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2916 .screen_add_layer = ivi_layout_screen_add_layer,
2917 .screen_set_render_order = ivi_layout_screen_set_render_order,
2918 .screen_get_output = ivi_layout_screen_get_output,
2919
2920 /**
2921 * animation
2922 */
2923 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002924 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2925
2926 /**
2927 * surface content dumping for debugging
2928 */
2929 .surface_get_size = ivi_layout_surface_get_size,
2930 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002931
2932 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002933 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002934 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002935 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002936 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2937
2938 /**
2939 * screen controller interfaces part2
2940 */
2941 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002942};
2943
2944int
2945load_controller_modules(struct weston_compositor *compositor, const char *modules,
2946 int *argc, char *argv[])
2947{
2948 const char *p, *end;
2949 char buffer[256];
2950 int (*controller_module_init)(struct weston_compositor *compositor,
2951 int *argc, char *argv[],
2952 const struct ivi_controller_interface *interface,
2953 size_t interface_version);
2954
2955 if (modules == NULL)
2956 return 0;
2957
2958 p = modules;
2959 while (*p) {
2960 end = strchrnul(p, ',');
2961 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2962
2963 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002964 if (!controller_module_init)
2965 return -1;
2966
2967 if (controller_module_init(compositor, argc, argv,
2968 &ivi_controller_interface,
2969 sizeof(struct ivi_controller_interface)) != 0) {
2970 weston_log("ivi-shell: Initialization of controller module fails");
2971 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002972 }
2973
2974 p = end;
2975 while (*p == ',')
2976 p++;
2977 }
2978
2979 return 0;
2980}