blob: 8a20e971436c1f9cab4f258d324c67e7149c1271 [file] [log] [blame]
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001/*
2 * Copyright (C) 2013 DENSO CORPORATION
3 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090011 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090024 */
25
26/**
27 * Implementation of ivi-layout library. The actual view on ivi_screen is
28 * not updated till calling ivi_layout_commit_changes. A overview from
29 * calling API for updating properties of ivi_surface/ivi_layer to asking
30 * compositor to compose them by using weston_compositor_schedule_repaint,
31 * 0/ initialize this library by ivi_layout_init_with_compositor
32 * with (struct weston_compositor *ec) from ivi-shell.
33 * 1/ When a API for updating properties of ivi_surface/ivi_layer, it updates
34 * pending prop of ivi_surface/ivi_layer/ivi_screen which are structure to
35 * store properties.
36 * 2/ Before calling commitChanges, in case of calling a API to get a property,
37 * return current property, not pending property.
38 * 3/ At the timing of calling ivi_layout_commitChanges, pending properties
39 * are applied to properties.
40 *
41 * *) ivi_layout_commitChanges is also called by transition animation
42 * per each frame. See ivi-layout-transition.c in details. Transition
43 * animation interpolates frames between previous properties of ivi_surface
44 * and new ones.
45 * For example, when a property of ivi_surface is changed from invisibility
46 * to visibility, it behaves like fade-in. When ivi_layout_commitChange is
47 * called during transition animation, it cancels the transition and
48 * re-start transition to new properties from current properties of final
49 * frame just before the the cancellation.
50 *
51 * 4/ According properties, set transformation by using weston_matrix and
52 * weston_view per ivi_surfaces and ivi_layers in while loop.
53 * 5/ Set damage and trigger transform by using weston_view_geometry_dirty.
54 * 6/ Notify update of properties.
55 * 7/ Trigger composition by weston_compositor_schedule_repaint.
56 *
57 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090058#include "config.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090059
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090060#include <string.h>
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +000061#include <assert.h>
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090062
63#include "compositor.h"
64#include "ivi-layout-export.h"
65#include "ivi-layout-private.h"
66
Jon Cruz867d50e2015-06-15 15:37:10 -070067#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070068#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090069
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090070struct link_layer {
71 struct ivi_layout_layer *ivilayer;
72 struct wl_list link;
73 struct wl_list link_to_layer;
74};
75
76struct link_screen {
77 struct ivi_layout_screen *iviscrn;
78 struct wl_list link;
79 struct wl_list link_to_screen;
80};
81
82struct listener_layout_notification {
83 void *userdata;
84 struct wl_listener listener;
85};
86
87struct ivi_layout;
88
89struct ivi_layout_screen {
90 struct wl_list link;
91 struct wl_list link_to_layer;
92 uint32_t id_screen;
93
94 struct ivi_layout *layout;
95 struct weston_output *output;
96
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090097 struct {
98 struct wl_list layer_list;
99 struct wl_list link;
100 } pending;
101
102 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000103 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900104 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;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900434
435 wl_list_init(&iviscrn->pending.layer_list);
436 wl_list_init(&iviscrn->pending.link);
437
438 wl_list_init(&iviscrn->order.layer_list);
439 wl_list_init(&iviscrn->order.link);
440
441 wl_list_init(&iviscrn->link_to_layer);
442
443 wl_list_insert(&layout->screen_list, &iviscrn->link);
444 }
445}
446
447/**
448 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
449 */
450static void
451init_layer_properties(struct ivi_layout_layer_properties *prop,
452 int32_t width, int32_t height)
453{
454 memset(prop, 0, sizeof *prop);
455 prop->opacity = wl_fixed_from_double(1.0);
456 prop->source_width = width;
457 prop->source_height = height;
458 prop->dest_width = width;
459 prop->dest_height = height;
460}
461
462static void
463init_surface_properties(struct ivi_layout_surface_properties *prop)
464{
465 memset(prop, 0, sizeof *prop);
466 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900467 /*
468 * FIXME: this shall be finxed by ivi-layout-transition.
469 */
470 prop->dest_width = 1;
471 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900472}
473
474/**
475 * Internal APIs to be called from ivi_layout_commit_changes.
476 */
477static void
478update_opacity(struct ivi_layout_layer *ivilayer,
479 struct ivi_layout_surface *ivisurf)
480{
481 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
482 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
483
484 if ((ivilayer->event_mask & IVI_NOTIFICATION_OPACITY) ||
485 (ivisurf->event_mask & IVI_NOTIFICATION_OPACITY)) {
486 struct weston_view *tmpview = NULL;
487 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
488 if (tmpview == NULL) {
489 continue;
490 }
491 tmpview->alpha = layer_alpha * surf_alpha;
492 }
493 }
494}
495
496static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900497get_rotate_values(enum wl_output_transform orientation,
498 float *v_sin,
499 float *v_cos)
500{
501 switch (orientation) {
502 case WL_OUTPUT_TRANSFORM_90:
503 *v_sin = 1.0f;
504 *v_cos = 0.0f;
505 break;
506 case WL_OUTPUT_TRANSFORM_180:
507 *v_sin = 0.0f;
508 *v_cos = -1.0f;
509 break;
510 case WL_OUTPUT_TRANSFORM_270:
511 *v_sin = -1.0f;
512 *v_cos = 0.0f;
513 break;
514 case WL_OUTPUT_TRANSFORM_NORMAL:
515 default:
516 *v_sin = 0.0f;
517 *v_cos = 1.0f;
518 break;
519 }
520}
521
522static void
523get_scale(enum wl_output_transform orientation,
524 float dest_width,
525 float dest_height,
526 float source_width,
527 float source_height,
528 float *scale_x,
529 float *scale_y)
530{
531 switch (orientation) {
532 case WL_OUTPUT_TRANSFORM_90:
533 *scale_x = dest_width / source_height;
534 *scale_y = dest_height / source_width;
535 break;
536 case WL_OUTPUT_TRANSFORM_180:
537 *scale_x = dest_width / source_width;
538 *scale_y = dest_height / source_height;
539 break;
540 case WL_OUTPUT_TRANSFORM_270:
541 *scale_x = dest_width / source_height;
542 *scale_y = dest_height / source_width;
543 break;
544 case WL_OUTPUT_TRANSFORM_NORMAL:
545 default:
546 *scale_x = dest_width / source_width;
547 *scale_y = dest_height / source_height;
548 break;
549 }
550}
551
552static void
553calc_transformation_matrix(struct ivi_rectangle *source_rect,
554 struct ivi_rectangle *dest_rect,
555 enum wl_output_transform orientation,
556 struct weston_matrix *m)
557{
558 float source_center_x;
559 float source_center_y;
560 float vsin;
561 float vcos;
562 float scale_x;
563 float scale_y;
564 float translate_x;
565 float translate_y;
566
567 source_center_x = source_rect->x + source_rect->width * 0.5f;
568 source_center_y = source_rect->y + source_rect->height * 0.5f;
569 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
570
571 get_rotate_values(orientation, &vsin, &vcos);
572 weston_matrix_rotate_xy(m, vcos, vsin);
573
574 get_scale(orientation,
575 dest_rect->width,
576 dest_rect->height,
577 source_rect->width,
578 source_rect->height,
579 &scale_x,
580 &scale_y);
581 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
582
583 translate_x = dest_rect->width * 0.5f + dest_rect->x;
584 translate_y = dest_rect->height * 0.5f + dest_rect->y;
585 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
586}
587
588/**
589 * This computes the whole transformation matrix from surface-local
590 * coordinates to global coordinates. It is assumed that
591 * weston_view::geometry.{x,y} are zero.
592 */
593static void
594calc_surface_to_global_matrix(struct ivi_layout_layer *ivilayer,
595 struct ivi_layout_surface *ivisurf,
596 struct weston_matrix *m)
597{
598 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
599 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
600 struct ivi_rectangle surface_source_rect = { sp->source_x,
601 sp->source_y,
602 sp->source_width,
603 sp->source_height };
604 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
605 sp->dest_y,
606 sp->dest_width,
607 sp->dest_height };
608 struct ivi_rectangle layer_source_rect = { lp->source_x,
609 lp->source_y,
610 lp->source_width,
611 lp->source_height };
612 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
613 lp->dest_y,
614 lp->dest_width,
615 lp->dest_height };
616
617 calc_transformation_matrix(&surface_source_rect,
618 &surface_dest_rect,
619 sp->orientation, m);
620
621 calc_transformation_matrix(&layer_source_rect,
622 &layer_dest_rect,
623 lp->orientation, m);
624}
625
626static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900627update_prop(struct ivi_layout_layer *ivilayer,
628 struct ivi_layout_surface *ivisurf)
629{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900630 struct weston_view *tmpview;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900631 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900632
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900633 if (!ivilayer->event_mask && !ivisurf->event_mask) {
634 return;
635 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900636
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900637 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900638
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900639 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900640 if (tmpview != NULL) {
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900641 break;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900642 }
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900643 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900644
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900645 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
646 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
647 can_calc = false;
648 }
649
650 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
651 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
652 can_calc = false;
653 }
654
655 if (can_calc) {
656 wl_list_remove(&ivisurf->transform.link);
657 weston_matrix_init(&ivisurf->transform.matrix);
658
659 calc_surface_to_global_matrix(ivilayer, ivisurf, &ivisurf->transform.matrix);
660
661 if (tmpview != NULL) {
662 wl_list_insert(&tmpview->geometry.transformation_list, &ivisurf->transform.link);
663
664 weston_view_set_transform_parent(tmpview, NULL);
665 }
666 }
667
668 ivisurf->update_count++;
669
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900670 if (tmpview != NULL) {
671 weston_view_geometry_dirty(tmpview);
672 }
673
674 if (ivisurf->surface != NULL) {
675 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900676 }
677}
678
679static void
680commit_changes(struct ivi_layout *layout)
681{
682 struct ivi_layout_screen *iviscrn = NULL;
683 struct ivi_layout_layer *ivilayer = NULL;
684 struct ivi_layout_surface *ivisurf = NULL;
685
686 wl_list_for_each(iviscrn, &layout->screen_list, link) {
687 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
688 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
689 update_prop(ivilayer, ivisurf);
690 }
691 }
692 }
693}
694
695static void
696commit_surface_list(struct ivi_layout *layout)
697{
698 struct ivi_layout_surface *ivisurf = NULL;
699 int32_t dest_x = 0;
700 int32_t dest_y = 0;
701 int32_t dest_width = 0;
702 int32_t dest_height = 0;
703 int32_t configured = 0;
704
705 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300706 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900707 dest_x = ivisurf->prop.dest_x;
708 dest_y = ivisurf->prop.dest_y;
709 dest_width = ivisurf->prop.dest_width;
710 dest_height = ivisurf->prop.dest_height;
711
712 ivi_layout_transition_move_resize_view(ivisurf,
713 ivisurf->pending.prop.dest_x,
714 ivisurf->pending.prop.dest_y,
715 ivisurf->pending.prop.dest_width,
716 ivisurf->pending.prop.dest_height,
717 ivisurf->pending.prop.transition_duration);
718
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300719 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900720 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
721 } else {
722 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
723 }
724
725 ivisurf->prop = ivisurf->pending.prop;
726 ivisurf->prop.dest_x = dest_x;
727 ivisurf->prop.dest_y = dest_y;
728 ivisurf->prop.dest_width = dest_width;
729 ivisurf->prop.dest_height = dest_height;
730 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
731 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
732
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300733 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900734 dest_x = ivisurf->prop.dest_x;
735 dest_y = ivisurf->prop.dest_y;
736 dest_width = ivisurf->prop.dest_width;
737 dest_height = ivisurf->prop.dest_height;
738
739 ivi_layout_transition_move_resize_view(ivisurf,
740 ivisurf->pending.prop.dest_x,
741 ivisurf->pending.prop.dest_y,
742 ivisurf->pending.prop.dest_width,
743 ivisurf->pending.prop.dest_height,
744 ivisurf->pending.prop.transition_duration);
745
746 ivisurf->prop = ivisurf->pending.prop;
747 ivisurf->prop.dest_x = dest_x;
748 ivisurf->prop.dest_y = dest_y;
749 ivisurf->prop.dest_width = dest_width;
750 ivisurf->prop.dest_height = dest_height;
751
752 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
753 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
754
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300755 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900756 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300757 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900758 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
759 } else {
760 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
761 }
762
763 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
764 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
765 configured = 1;
766 }
767
768 ivisurf->prop = ivisurf->pending.prop;
769 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
770 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
771
772 if (configured && !is_surface_transition(ivisurf))
773 wl_signal_emit(&ivisurf->configured, ivisurf);
774 } else {
775 configured = 0;
776 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
777 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
778 configured = 1;
779 }
780
781 ivisurf->prop = ivisurf->pending.prop;
782 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
783 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
784
785 if (configured && !is_surface_transition(ivisurf))
786 wl_signal_emit(&ivisurf->configured, ivisurf);
787 }
788 }
789}
790
791static void
792commit_layer_list(struct ivi_layout *layout)
793{
794 struct ivi_layout_layer *ivilayer = NULL;
795 struct ivi_layout_surface *ivisurf = NULL;
796 struct ivi_layout_surface *next = NULL;
797
798 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300799 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900800 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 -0300801 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900802 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
803 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
804 NULL, NULL,
805 ivilayer->pending.prop.transition_duration);
806 }
807 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
808
809 ivilayer->prop = ivilayer->pending.prop;
810
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000811 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900812 continue;
813 }
814
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000815 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
816 order.link) {
817 remove_ordersurface_from_layer(ivisurf);
818 wl_list_remove(&ivisurf->order.link);
819 wl_list_init(&ivisurf->order.link);
820 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900821 }
822
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000823 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900824
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000825 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900826 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000827 wl_list_remove(&ivisurf->order.link);
828 wl_list_insert(&ivilayer->order.surface_list,
829 &ivisurf->order.link);
830 add_ordersurface_to_layer(ivisurf, ivilayer);
831 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900832 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000833
834 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900835 }
836}
837
838static void
839commit_screen_list(struct ivi_layout *layout)
840{
841 struct ivi_layout_screen *iviscrn = NULL;
842 struct ivi_layout_layer *ivilayer = NULL;
843 struct ivi_layout_layer *next = NULL;
844 struct ivi_layout_surface *ivisurf = NULL;
845
846 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000847 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900848 wl_list_for_each_safe(ivilayer, next,
849 &iviscrn->order.layer_list, order.link) {
850 remove_orderlayer_from_screen(ivilayer);
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000851 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900852 wl_list_init(&ivilayer->order.link);
853 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
854 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900855
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000856 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900857
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900858 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
859 pending.link) {
860 wl_list_insert(&iviscrn->order.layer_list,
861 &ivilayer->order.link);
862 add_orderlayer_to_screen(ivilayer, iviscrn);
863 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
864 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900865
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000866 iviscrn->order.dirty = 0;
867 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900868
869 /* Clear view list of layout ivi_layer */
870 wl_list_init(&layout->layout_layer.view_list.link);
871
872 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
873 if (ivilayer->prop.visibility == false)
874 continue;
875
876 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
877 struct weston_view *tmpview = NULL;
878 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
879 if (tmpview != NULL) {
880 break;
881 }
882 }
883
884 if (ivisurf->prop.visibility == false)
885 continue;
886 if (ivisurf->surface == NULL || tmpview == NULL)
887 continue;
888
889 weston_layer_entry_insert(&layout->layout_layer.view_list,
890 &tmpview->layer_link);
891
892 ivisurf->surface->output = iviscrn->output;
893 }
894 }
895
896 break;
897 }
898}
899
900static void
901commit_transition(struct ivi_layout* layout)
902{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300903 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900904 return;
905 }
906
907 wl_list_insert_list(&layout->transitions->transition_list,
908 &layout->pending_transition_list);
909
910 wl_list_init(&layout->pending_transition_list);
911
912 wl_event_source_timer_update(layout->transitions->event_source, 1);
913}
914
915static void
916send_surface_prop(struct ivi_layout_surface *ivisurf)
917{
918 wl_signal_emit(&ivisurf->property_changed, ivisurf);
919 ivisurf->event_mask = 0;
920}
921
922static void
923send_layer_prop(struct ivi_layout_layer *ivilayer)
924{
925 wl_signal_emit(&ivilayer->property_changed, ivilayer);
926 ivilayer->event_mask = 0;
927}
928
929static void
930send_prop(struct ivi_layout *layout)
931{
932 struct ivi_layout_layer *ivilayer = NULL;
933 struct ivi_layout_surface *ivisurf = NULL;
934
935 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900936 if (ivilayer->event_mask)
937 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900938 }
939
940 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900941 if (ivisurf->event_mask)
942 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900943 }
944}
945
946static void
947clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
948{
949 struct ivi_layout_surface *surface_link = NULL;
950 struct ivi_layout_surface *surface_next = NULL;
951
952 wl_list_for_each_safe(surface_link, surface_next,
953 &ivilayer->pending.surface_list, pending.link) {
954 if (!wl_list_empty(&surface_link->pending.link)) {
955 wl_list_remove(&surface_link->pending.link);
956 }
957
958 wl_list_init(&surface_link->pending.link);
959 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900960}
961
962static void
963clear_surface_order_list(struct ivi_layout_layer *ivilayer)
964{
965 struct ivi_layout_surface *surface_link = NULL;
966 struct ivi_layout_surface *surface_next = NULL;
967
968 wl_list_for_each_safe(surface_link, surface_next,
969 &ivilayer->order.surface_list, order.link) {
970 if (!wl_list_empty(&surface_link->order.link)) {
971 wl_list_remove(&surface_link->order.link);
972 }
973
974 wl_list_init(&surface_link->order.link);
975 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900976}
977
978static void
979layer_created(struct wl_listener *listener, void *data)
980{
981 struct ivi_layout_layer *ivilayer = data;
982
983 struct listener_layout_notification *notification =
984 container_of(listener,
985 struct listener_layout_notification,
986 listener);
987
988 struct ivi_layout_notification_callback *created_callback =
989 notification->userdata;
990
991 ((layer_create_notification_func)created_callback->callback)
992 (ivilayer, created_callback->data);
993}
994
995static void
996layer_removed(struct wl_listener *listener, void *data)
997{
998 struct ivi_layout_layer *ivilayer = data;
999
1000 struct listener_layout_notification *notification =
1001 container_of(listener,
1002 struct listener_layout_notification,
1003 listener);
1004
1005 struct ivi_layout_notification_callback *removed_callback =
1006 notification->userdata;
1007
1008 ((layer_remove_notification_func)removed_callback->callback)
1009 (ivilayer, removed_callback->data);
1010}
1011
1012static void
1013layer_prop_changed(struct wl_listener *listener, void *data)
1014{
1015 struct ivi_layout_layer *ivilayer = data;
1016
1017 struct listener_layout_notification *layout_listener =
1018 container_of(listener,
1019 struct listener_layout_notification,
1020 listener);
1021
1022 struct ivi_layout_notification_callback *prop_callback =
1023 layout_listener->userdata;
1024
1025 ((layer_property_notification_func)prop_callback->callback)
1026 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1027}
1028
1029static void
1030surface_created(struct wl_listener *listener, void *data)
1031{
1032 struct ivi_layout_surface *ivisurface = data;
1033
1034 struct listener_layout_notification *notification =
1035 container_of(listener,
1036 struct listener_layout_notification,
1037 listener);
1038
1039 struct ivi_layout_notification_callback *created_callback =
1040 notification->userdata;
1041
1042 ((surface_create_notification_func)created_callback->callback)
1043 (ivisurface, created_callback->data);
1044}
1045
1046static void
1047surface_removed(struct wl_listener *listener, void *data)
1048{
1049 struct ivi_layout_surface *ivisurface = data;
1050
1051 struct listener_layout_notification *notification =
1052 container_of(listener,
1053 struct listener_layout_notification,
1054 listener);
1055
1056 struct ivi_layout_notification_callback *removed_callback =
1057 notification->userdata;
1058
1059 ((surface_remove_notification_func)removed_callback->callback)
1060 (ivisurface, removed_callback->data);
1061}
1062
1063static void
1064surface_prop_changed(struct wl_listener *listener, void *data)
1065{
1066 struct ivi_layout_surface *ivisurf = data;
1067
1068 struct listener_layout_notification *layout_listener =
1069 container_of(listener,
1070 struct listener_layout_notification,
1071 listener);
1072
1073 struct ivi_layout_notification_callback *prop_callback =
1074 layout_listener->userdata;
1075
1076 ((surface_property_notification_func)prop_callback->callback)
1077 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1078
1079 ivisurf->event_mask = 0;
1080}
1081
1082static void
1083surface_configure_changed(struct wl_listener *listener,
1084 void *data)
1085{
1086 struct ivi_layout_surface *ivisurface = data;
1087
1088 struct listener_layout_notification *notification =
1089 container_of(listener,
1090 struct listener_layout_notification,
1091 listener);
1092
1093 struct ivi_layout_notification_callback *configure_changed_callback =
1094 notification->userdata;
1095
1096 ((surface_configure_notification_func)configure_changed_callback->callback)
1097 (ivisurface, configure_changed_callback->data);
1098}
1099
1100static int32_t
1101add_notification(struct wl_signal *signal,
1102 wl_notify_func_t callback,
1103 void *userdata)
1104{
1105 struct listener_layout_notification *notification = NULL;
1106
1107 notification = malloc(sizeof *notification);
1108 if (notification == NULL) {
1109 weston_log("fails to allocate memory\n");
1110 free(userdata);
1111 return IVI_FAILED;
1112 }
1113
1114 notification->listener.notify = callback;
1115 notification->userdata = userdata;
1116
1117 wl_signal_add(signal, &notification->listener);
1118
1119 return IVI_SUCCEEDED;
1120}
1121
1122static void
1123remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1124{
1125 struct wl_listener *listener = NULL;
1126 struct wl_listener *next = NULL;
1127
1128 wl_list_for_each_safe(listener, next, listener_list, link) {
1129 struct listener_layout_notification *notification =
1130 container_of(listener,
1131 struct listener_layout_notification,
1132 listener);
1133
1134 struct ivi_layout_notification_callback *notification_callback =
1135 notification->userdata;
1136
1137 if ((notification_callback->callback != callback) ||
1138 (notification_callback->data != userdata)) {
1139 continue;
1140 }
1141
1142 if (!wl_list_empty(&listener->link)) {
1143 wl_list_remove(&listener->link);
1144 }
1145
1146 free(notification->userdata);
1147 free(notification);
1148 }
1149}
1150
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001151/**
1152 * Exported APIs of ivi-layout library are implemented from here.
1153 * Brief of APIs is described in ivi-layout-export.h.
1154 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001155static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001156ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1157 void *userdata)
1158{
1159 struct ivi_layout *layout = get_instance();
1160 struct ivi_layout_notification_callback *created_callback = NULL;
1161
1162 if (callback == NULL) {
1163 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1164 return IVI_FAILED;
1165 }
1166
1167 created_callback = malloc(sizeof *created_callback);
1168 if (created_callback == NULL) {
1169 weston_log("fails to allocate memory\n");
1170 return IVI_FAILED;
1171 }
1172
1173 created_callback->callback = callback;
1174 created_callback->data = userdata;
1175
1176 return add_notification(&layout->layer_notification.created,
1177 layer_created,
1178 created_callback);
1179}
1180
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001181static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001182ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1183 void *userdata)
1184{
1185 struct ivi_layout *layout = get_instance();
1186 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1187}
1188
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001189static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001190ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1191 void *userdata)
1192{
1193 struct ivi_layout *layout = get_instance();
1194 struct ivi_layout_notification_callback *removed_callback = NULL;
1195
1196 if (callback == NULL) {
1197 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1198 return IVI_FAILED;
1199 }
1200
1201 removed_callback = malloc(sizeof *removed_callback);
1202 if (removed_callback == NULL) {
1203 weston_log("fails to allocate memory\n");
1204 return IVI_FAILED;
1205 }
1206
1207 removed_callback->callback = callback;
1208 removed_callback->data = userdata;
1209 return add_notification(&layout->layer_notification.removed,
1210 layer_removed,
1211 removed_callback);
1212}
1213
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001214static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001215ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1216 void *userdata)
1217{
1218 struct ivi_layout *layout = get_instance();
1219 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1220}
1221
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001222static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001223ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1224 void *userdata)
1225{
1226 struct ivi_layout *layout = get_instance();
1227 struct ivi_layout_notification_callback *created_callback = NULL;
1228
1229 if (callback == NULL) {
1230 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1231 return IVI_FAILED;
1232 }
1233
1234 created_callback = malloc(sizeof *created_callback);
1235 if (created_callback == NULL) {
1236 weston_log("fails to allocate memory\n");
1237 return IVI_FAILED;
1238 }
1239
1240 created_callback->callback = callback;
1241 created_callback->data = userdata;
1242
1243 return add_notification(&layout->surface_notification.created,
1244 surface_created,
1245 created_callback);
1246}
1247
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001248static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001249ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1250 void *userdata)
1251{
1252 struct ivi_layout *layout = get_instance();
1253 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1254}
1255
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001256static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001257ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1258 void *userdata)
1259{
1260 struct ivi_layout *layout = get_instance();
1261 struct ivi_layout_notification_callback *removed_callback = NULL;
1262
1263 if (callback == NULL) {
1264 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1265 return IVI_FAILED;
1266 }
1267
1268 removed_callback = malloc(sizeof *removed_callback);
1269 if (removed_callback == NULL) {
1270 weston_log("fails to allocate memory\n");
1271 return IVI_FAILED;
1272 }
1273
1274 removed_callback->callback = callback;
1275 removed_callback->data = userdata;
1276
1277 return add_notification(&layout->surface_notification.removed,
1278 surface_removed,
1279 removed_callback);
1280}
1281
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001282static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001283ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1284 void *userdata)
1285{
1286 struct ivi_layout *layout = get_instance();
1287 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1288}
1289
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001290static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001291ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1292 void *userdata)
1293{
1294 struct ivi_layout *layout = get_instance();
1295 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1296 if (callback == NULL) {
1297 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1298 return IVI_FAILED;
1299 }
1300
1301 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1302 if (configure_changed_callback == NULL) {
1303 weston_log("fails to allocate memory\n");
1304 return IVI_FAILED;
1305 }
1306
1307 configure_changed_callback->callback = callback;
1308 configure_changed_callback->data = userdata;
1309
1310 return add_notification(&layout->surface_notification.configure_changed,
1311 surface_configure_changed,
1312 configure_changed_callback);
1313}
1314
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001315static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001316ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1317 void *userdata)
1318{
1319 struct ivi_layout *layout = get_instance();
1320 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1321}
1322
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001323uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001324ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1325{
1326 return ivisurf->id_surface;
1327}
1328
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001329static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001330ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1331{
1332 return ivilayer->id_layer;
1333}
1334
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001335static uint32_t
1336ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1337{
1338 return iviscrn->id_screen;
1339}
1340
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001341static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001342ivi_layout_get_layer_from_id(uint32_t id_layer)
1343{
1344 struct ivi_layout *layout = get_instance();
1345 struct ivi_layout_layer *ivilayer = NULL;
1346
1347 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1348 if (ivilayer->id_layer == id_layer) {
1349 return ivilayer;
1350 }
1351 }
1352
1353 return NULL;
1354}
1355
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001356struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001357ivi_layout_get_surface_from_id(uint32_t id_surface)
1358{
1359 struct ivi_layout *layout = get_instance();
1360 struct ivi_layout_surface *ivisurf = NULL;
1361
1362 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1363 if (ivisurf->id_surface == id_surface) {
1364 return ivisurf;
1365 }
1366 }
1367
1368 return NULL;
1369}
1370
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001371static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001372ivi_layout_get_screen_from_id(uint32_t id_screen)
1373{
1374 struct ivi_layout *layout = get_instance();
1375 struct ivi_layout_screen *iviscrn = NULL;
1376
1377 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1378/* FIXME : select iviscrn from screen_list by id_screen */
1379 return iviscrn;
1380 break;
1381 }
1382
1383 return NULL;
1384}
1385
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001386static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001387ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1388 int32_t *pWidth, int32_t *pHeight)
1389{
1390 struct weston_output *output = NULL;
1391
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001392 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001393 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1394 return IVI_FAILED;
1395 }
1396
1397 output = iviscrn->output;
1398 *pWidth = output->current_mode->width;
1399 *pHeight = output->current_mode->height;
1400
1401 return IVI_SUCCEEDED;
1402}
1403
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001404static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001405ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1406 surface_property_notification_func callback,
1407 void *userdata)
1408{
1409 struct listener_layout_notification* notification = NULL;
1410 struct ivi_layout_notification_callback *prop_callback = NULL;
1411
1412 if (ivisurf == NULL || callback == NULL) {
1413 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1414 return IVI_FAILED;
1415 }
1416
1417 notification = malloc(sizeof *notification);
1418 if (notification == NULL) {
1419 weston_log("fails to allocate memory\n");
1420 return IVI_FAILED;
1421 }
1422
1423 prop_callback = malloc(sizeof *prop_callback);
1424 if (prop_callback == NULL) {
1425 weston_log("fails to allocate memory\n");
1426 return IVI_FAILED;
1427 }
1428
1429 prop_callback->callback = callback;
1430 prop_callback->data = userdata;
1431
1432 notification->listener.notify = surface_prop_changed;
1433 notification->userdata = prop_callback;
1434
1435 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1436
1437 return IVI_SUCCEEDED;
1438}
1439
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001440static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001441ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1442{
1443 if (ivilayer == NULL) {
1444 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1445 return NULL;
1446 }
1447
1448 return &ivilayer->prop;
1449}
1450
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001451static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001452ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1453{
1454 struct ivi_layout *layout = get_instance();
1455 struct ivi_layout_screen *iviscrn = NULL;
1456 int32_t length = 0;
1457 int32_t n = 0;
1458
1459 if (pLength == NULL || ppArray == NULL) {
1460 weston_log("ivi_layout_get_screens: invalid argument\n");
1461 return IVI_FAILED;
1462 }
1463
1464 length = wl_list_length(&layout->screen_list);
1465
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001466 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001467 /* the Array must be free by module which called this function */
1468 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1469 if (*ppArray == NULL) {
1470 weston_log("fails to allocate memory\n");
1471 return IVI_FAILED;
1472 }
1473
1474 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1475 (*ppArray)[n++] = iviscrn;
1476 }
1477 }
1478
1479 *pLength = length;
1480
1481 return IVI_SUCCEEDED;
1482}
1483
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001484static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001485ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1486 int32_t *pLength,
1487 struct ivi_layout_screen ***ppArray)
1488{
1489 struct link_screen *link_scrn = NULL;
1490 int32_t length = 0;
1491 int32_t n = 0;
1492
1493 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1494 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1495 return IVI_FAILED;
1496 }
1497
1498 length = wl_list_length(&ivilayer->screen_list);
1499
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001500 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001501 /* the Array must be free by module which called this function */
1502 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1503 if (*ppArray == NULL) {
1504 weston_log("fails to allocate memory\n");
1505 return IVI_FAILED;
1506 }
1507
1508 wl_list_for_each(link_scrn, &ivilayer->screen_list, link) {
1509 (*ppArray)[n++] = link_scrn->iviscrn;
1510 }
1511 }
1512
1513 *pLength = length;
1514
1515 return IVI_SUCCEEDED;
1516}
1517
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001518static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001519ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1520{
1521 struct ivi_layout *layout = get_instance();
1522 struct ivi_layout_layer *ivilayer = NULL;
1523 int32_t length = 0;
1524 int32_t n = 0;
1525
1526 if (pLength == NULL || ppArray == NULL) {
1527 weston_log("ivi_layout_get_layers: invalid argument\n");
1528 return IVI_FAILED;
1529 }
1530
1531 length = wl_list_length(&layout->layer_list);
1532
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001533 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001534 /* the Array must be free by module which called this function */
1535 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1536 if (*ppArray == NULL) {
1537 weston_log("fails to allocate memory\n");
1538 return IVI_FAILED;
1539 }
1540
1541 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1542 (*ppArray)[n++] = ivilayer;
1543 }
1544 }
1545
1546 *pLength = length;
1547
1548 return IVI_SUCCEEDED;
1549}
1550
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001551static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001552ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1553 int32_t *pLength,
1554 struct ivi_layout_layer ***ppArray)
1555{
1556 struct ivi_layout_layer *ivilayer = NULL;
1557 int32_t length = 0;
1558 int32_t n = 0;
1559
1560 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1561 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1562 return IVI_FAILED;
1563 }
1564
1565 length = wl_list_length(&iviscrn->order.layer_list);
1566
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001567 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001568 /* the Array must be free by module which called this function */
1569 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1570 if (*ppArray == NULL) {
1571 weston_log("fails to allocate memory\n");
1572 return IVI_FAILED;
1573 }
1574
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001575 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001576 (*ppArray)[n++] = ivilayer;
1577 }
1578 }
1579
1580 *pLength = length;
1581
1582 return IVI_SUCCEEDED;
1583}
1584
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001585static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001586ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1587 int32_t *pLength,
1588 struct ivi_layout_layer ***ppArray)
1589{
1590 struct link_layer *link_layer = NULL;
1591 int32_t length = 0;
1592 int32_t n = 0;
1593
1594 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1595 weston_log("ivi_layout_getLayers: invalid argument\n");
1596 return IVI_FAILED;
1597 }
1598
1599 length = wl_list_length(&ivisurf->layer_list);
1600
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001601 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001602 /* the Array must be free by module which called this function */
1603 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1604 if (*ppArray == NULL) {
1605 weston_log("fails to allocate memory\n");
1606 return IVI_FAILED;
1607 }
1608
1609 wl_list_for_each(link_layer, &ivisurf->layer_list, link) {
1610 (*ppArray)[n++] = link_layer->ivilayer;
1611 }
1612 }
1613
1614 *pLength = length;
1615
1616 return IVI_SUCCEEDED;
1617}
1618
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001619static
1620int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001621ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1622{
1623 struct ivi_layout *layout = get_instance();
1624 struct ivi_layout_surface *ivisurf = NULL;
1625 int32_t length = 0;
1626 int32_t n = 0;
1627
1628 if (pLength == NULL || ppArray == NULL) {
1629 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1630 return IVI_FAILED;
1631 }
1632
1633 length = wl_list_length(&layout->surface_list);
1634
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001635 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001636 /* the Array must be free by module which called this function */
1637 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1638 if (*ppArray == NULL) {
1639 weston_log("fails to allocate memory\n");
1640 return IVI_FAILED;
1641 }
1642
1643 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1644 (*ppArray)[n++] = ivisurf;
1645 }
1646 }
1647
1648 *pLength = length;
1649
1650 return IVI_SUCCEEDED;
1651}
1652
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001653static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001654ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1655 int32_t *pLength,
1656 struct ivi_layout_surface ***ppArray)
1657{
1658 struct ivi_layout_surface *ivisurf = NULL;
1659 int32_t length = 0;
1660 int32_t n = 0;
1661
1662 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1663 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1664 return IVI_FAILED;
1665 }
1666
1667 length = wl_list_length(&ivilayer->order.surface_list);
1668
1669 if (length != 0) {
1670 /* the Array must be free by module which called this function */
1671 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1672 if (*ppArray == NULL) {
1673 weston_log("fails to allocate memory\n");
1674 return IVI_FAILED;
1675 }
1676
1677 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1678 (*ppArray)[n++] = ivisurf;
1679 }
1680 }
1681
1682 *pLength = length;
1683
1684 return IVI_SUCCEEDED;
1685}
1686
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001687static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001688ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1689 int32_t width, int32_t height)
1690{
1691 struct ivi_layout *layout = get_instance();
1692 struct ivi_layout_layer *ivilayer = NULL;
1693
1694 ivilayer = get_layer(&layout->layer_list, id_layer);
1695 if (ivilayer != NULL) {
1696 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001697 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001698 return ivilayer;
1699 }
1700
1701 ivilayer = calloc(1, sizeof *ivilayer);
1702 if (ivilayer == NULL) {
1703 weston_log("fails to allocate memory\n");
1704 return NULL;
1705 }
1706
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001707 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001708 wl_list_init(&ivilayer->link);
1709 wl_signal_init(&ivilayer->property_changed);
1710 wl_list_init(&ivilayer->screen_list);
1711 wl_list_init(&ivilayer->link_to_surface);
1712 ivilayer->layout = layout;
1713 ivilayer->id_layer = id_layer;
1714
1715 init_layer_properties(&ivilayer->prop, width, height);
1716 ivilayer->event_mask = 0;
1717
1718 wl_list_init(&ivilayer->pending.surface_list);
1719 wl_list_init(&ivilayer->pending.link);
1720 ivilayer->pending.prop = ivilayer->prop;
1721
1722 wl_list_init(&ivilayer->order.surface_list);
1723 wl_list_init(&ivilayer->order.link);
1724
1725 wl_list_insert(&layout->layer_list, &ivilayer->link);
1726
1727 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1728
1729 return ivilayer;
1730}
1731
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001732static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001733ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1734{
1735 if (ivilayer == NULL) {
1736 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1737 return;
1738 }
1739
1740 remove_all_notification(&ivilayer->property_changed.listener_list);
1741}
1742
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001743static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001744ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1745 layer_property_notification_func callback,
1746 void *userdata)
1747{
1748 if (ivilayer == NULL) {
1749 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1750 return;
1751 }
1752
1753 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1754}
1755
1756static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001757ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001758{
1759 struct ivi_layout *layout = get_instance();
1760
1761 if (ivilayer == NULL) {
1762 weston_log("ivi_layout_layer_remove: invalid argument\n");
1763 return;
1764 }
1765
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001766 if (--ivilayer->ref_count > 0)
1767 return;
1768
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001769 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1770
1771 clear_surface_pending_list(ivilayer);
1772 clear_surface_order_list(ivilayer);
1773
1774 if (!wl_list_empty(&ivilayer->pending.link)) {
1775 wl_list_remove(&ivilayer->pending.link);
1776 }
1777 if (!wl_list_empty(&ivilayer->order.link)) {
1778 wl_list_remove(&ivilayer->order.link);
1779 }
1780 if (!wl_list_empty(&ivilayer->link)) {
1781 wl_list_remove(&ivilayer->link);
1782 }
1783 remove_orderlayer_from_screen(ivilayer);
1784 remove_link_to_surface(ivilayer);
1785 ivi_layout_layer_remove_notification(ivilayer);
1786
1787 free(ivilayer);
1788}
1789
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001790int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001791ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1792 bool newVisibility)
1793{
1794 struct ivi_layout_layer_properties *prop = NULL;
1795
1796 if (ivilayer == NULL) {
1797 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1798 return IVI_FAILED;
1799 }
1800
1801 prop = &ivilayer->pending.prop;
1802 prop->visibility = newVisibility;
1803
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001804 if (ivilayer->prop.visibility != newVisibility)
1805 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1806 else
1807 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001808
1809 return IVI_SUCCEEDED;
1810}
1811
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001812static bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001813ivi_layout_layer_get_visibility(struct ivi_layout_layer *ivilayer)
1814{
1815 if (ivilayer == NULL) {
1816 weston_log("ivi_layout_layer_get_visibility: invalid argument\n");
1817 return false;
1818 }
1819
1820 return ivilayer->prop.visibility;
1821}
1822
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001823int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001824ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1825 wl_fixed_t opacity)
1826{
1827 struct ivi_layout_layer_properties *prop = NULL;
1828
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001829 if (ivilayer == NULL ||
1830 opacity < wl_fixed_from_double(0.0) ||
1831 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001832 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1833 return IVI_FAILED;
1834 }
1835
1836 prop = &ivilayer->pending.prop;
1837 prop->opacity = opacity;
1838
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001839 if (ivilayer->prop.opacity != opacity)
1840 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1841 else
1842 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001843
1844 return IVI_SUCCEEDED;
1845}
1846
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001847wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001848ivi_layout_layer_get_opacity(struct ivi_layout_layer *ivilayer)
1849{
1850 if (ivilayer == NULL) {
1851 weston_log("ivi_layout_layer_get_opacity: invalid argument\n");
1852 return wl_fixed_from_double(0.0);
1853 }
1854
1855 return ivilayer->prop.opacity;
1856}
1857
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001858static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001859ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1860 int32_t x, int32_t y,
1861 int32_t width, int32_t height)
1862{
1863 struct ivi_layout_layer_properties *prop = NULL;
1864
1865 if (ivilayer == NULL) {
1866 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1867 return IVI_FAILED;
1868 }
1869
1870 prop = &ivilayer->pending.prop;
1871 prop->source_x = x;
1872 prop->source_y = y;
1873 prop->source_width = width;
1874 prop->source_height = height;
1875
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001876 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1877 ivilayer->prop.source_width != width ||
1878 ivilayer->prop.source_height != height)
1879 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1880 else
1881 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001882
1883 return IVI_SUCCEEDED;
1884}
1885
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001886static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001887ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1888 int32_t x, int32_t y,
1889 int32_t width, int32_t height)
1890{
1891 struct ivi_layout_layer_properties *prop = NULL;
1892
1893 if (ivilayer == NULL) {
1894 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1895 return IVI_FAILED;
1896 }
1897
1898 prop = &ivilayer->pending.prop;
1899 prop->dest_x = x;
1900 prop->dest_y = y;
1901 prop->dest_width = width;
1902 prop->dest_height = height;
1903
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001904 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1905 ivilayer->prop.dest_width != width ||
1906 ivilayer->prop.dest_height != height)
1907 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1908 else
1909 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001910
1911 return IVI_SUCCEEDED;
1912}
1913
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001914static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001915ivi_layout_layer_get_dimension(struct ivi_layout_layer *ivilayer,
1916 int32_t *dest_width, int32_t *dest_height)
1917{
1918 if (ivilayer == NULL || dest_width == NULL || dest_height == NULL) {
1919 weston_log("ivi_layout_layer_get_dimension: invalid argument\n");
1920 return IVI_FAILED;
1921 }
1922
1923 *dest_width = ivilayer->prop.dest_width;
1924 *dest_height = ivilayer->prop.dest_height;
1925
1926 return IVI_SUCCEEDED;
1927}
1928
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001929static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001930ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
1931 int32_t dest_width, int32_t dest_height)
1932{
1933 struct ivi_layout_layer_properties *prop = NULL;
1934
1935 if (ivilayer == NULL) {
1936 weston_log("ivi_layout_layer_set_dimension: invalid argument\n");
1937 return IVI_FAILED;
1938 }
1939
1940 prop = &ivilayer->pending.prop;
1941
1942 prop->dest_width = dest_width;
1943 prop->dest_height = dest_height;
1944
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001945 if (ivilayer->prop.dest_width != dest_width ||
1946 ivilayer->prop.dest_height != dest_height)
1947 ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
1948 else
1949 ivilayer->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001950
1951 return IVI_SUCCEEDED;
1952}
1953
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001954int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001955ivi_layout_layer_get_position(struct ivi_layout_layer *ivilayer,
1956 int32_t *dest_x, int32_t *dest_y)
1957{
1958 if (ivilayer == NULL || dest_x == NULL || dest_y == NULL) {
1959 weston_log("ivi_layout_layer_get_position: invalid argument\n");
1960 return IVI_FAILED;
1961 }
1962
1963 *dest_x = ivilayer->prop.dest_x;
1964 *dest_y = ivilayer->prop.dest_y;
1965
1966 return IVI_SUCCEEDED;
1967}
1968
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001969int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001970ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
1971 int32_t dest_x, int32_t dest_y)
1972{
1973 struct ivi_layout_layer_properties *prop = NULL;
1974
1975 if (ivilayer == NULL) {
1976 weston_log("ivi_layout_layer_set_position: invalid argument\n");
1977 return IVI_FAILED;
1978 }
1979
1980 prop = &ivilayer->pending.prop;
1981 prop->dest_x = dest_x;
1982 prop->dest_y = dest_y;
1983
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001984 if (ivilayer->prop.dest_x != dest_x || ivilayer->prop.dest_y != dest_y)
1985 ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
1986 else
1987 ivilayer->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001988
1989 return IVI_SUCCEEDED;
1990}
1991
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001992static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001993ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1994 enum wl_output_transform orientation)
1995{
1996 struct ivi_layout_layer_properties *prop = NULL;
1997
1998 if (ivilayer == NULL) {
1999 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
2000 return IVI_FAILED;
2001 }
2002
2003 prop = &ivilayer->pending.prop;
2004 prop->orientation = orientation;
2005
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002006 if (ivilayer->prop.orientation != orientation)
2007 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2008 else
2009 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002010
2011 return IVI_SUCCEEDED;
2012}
2013
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002014static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002015ivi_layout_layer_get_orientation(struct ivi_layout_layer *ivilayer)
2016{
2017 if (ivilayer == NULL) {
2018 weston_log("ivi_layout_layer_get_orientation: invalid argument\n");
2019 return 0;
2020 }
2021
2022 return ivilayer->prop.orientation;
2023}
2024
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002025int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002026ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
2027 struct ivi_layout_surface **pSurface,
2028 int32_t number)
2029{
2030 struct ivi_layout *layout = get_instance();
2031 struct ivi_layout_surface *ivisurf = NULL;
2032 struct ivi_layout_surface *next = NULL;
2033 uint32_t *id_surface = NULL;
2034 int32_t i = 0;
2035
2036 if (ivilayer == NULL) {
2037 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
2038 return IVI_FAILED;
2039 }
2040
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00002041 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002042
2043 for (i = 0; i < number; i++) {
2044 id_surface = &pSurface[i]->id_surface;
2045
2046 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2047 if (*id_surface != ivisurf->id_surface) {
2048 continue;
2049 }
2050
2051 if (!wl_list_empty(&ivisurf->pending.link)) {
2052 wl_list_remove(&ivisurf->pending.link);
2053 }
2054 wl_list_init(&ivisurf->pending.link);
2055 wl_list_insert(&ivilayer->pending.surface_list,
2056 &ivisurf->pending.link);
2057 break;
2058 }
2059 }
2060
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002061 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002062
2063 return IVI_SUCCEEDED;
2064}
2065
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002066int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002067ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
2068 bool newVisibility)
2069{
2070 struct ivi_layout_surface_properties *prop = NULL;
2071
2072 if (ivisurf == NULL) {
2073 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
2074 return IVI_FAILED;
2075 }
2076
2077 prop = &ivisurf->pending.prop;
2078 prop->visibility = newVisibility;
2079
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002080 if (ivisurf->prop.visibility != newVisibility)
2081 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
2082 else
2083 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002084
2085 return IVI_SUCCEEDED;
2086}
2087
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002088bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002089ivi_layout_surface_get_visibility(struct ivi_layout_surface *ivisurf)
2090{
2091 if (ivisurf == NULL) {
2092 weston_log("ivi_layout_surface_get_visibility: invalid argument\n");
2093 return false;
2094 }
2095
2096 return ivisurf->prop.visibility;
2097}
2098
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002099int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002100ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
2101 wl_fixed_t opacity)
2102{
2103 struct ivi_layout_surface_properties *prop = NULL;
2104
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09002105 if (ivisurf == NULL ||
2106 opacity < wl_fixed_from_double(0.0) ||
2107 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002108 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
2109 return IVI_FAILED;
2110 }
2111
2112 prop = &ivisurf->pending.prop;
2113 prop->opacity = opacity;
2114
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002115 if (ivisurf->prop.opacity != opacity)
2116 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
2117 else
2118 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002119
2120 return IVI_SUCCEEDED;
2121}
2122
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002123wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002124ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
2125{
2126 if (ivisurf == NULL) {
2127 weston_log("ivi_layout_surface_get_opacity: invalid argument\n");
2128 return wl_fixed_from_double(0.0);
2129 }
2130
2131 return ivisurf->prop.opacity;
2132}
2133
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002134int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002135ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
2136 int32_t x, int32_t y,
2137 int32_t width, int32_t height)
2138{
2139 struct ivi_layout_surface_properties *prop = NULL;
2140
2141 if (ivisurf == NULL) {
2142 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
2143 return IVI_FAILED;
2144 }
2145
2146 prop = &ivisurf->pending.prop;
2147 prop->start_x = prop->dest_x;
2148 prop->start_y = prop->dest_y;
2149 prop->dest_x = x;
2150 prop->dest_y = y;
2151 prop->start_width = prop->dest_width;
2152 prop->start_height = prop->dest_height;
2153 prop->dest_width = width;
2154 prop->dest_height = height;
2155
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002156 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2157 ivisurf->prop.dest_width != width ||
2158 ivisurf->prop.dest_height != height)
2159 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2160 else
2161 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002162
2163 return IVI_SUCCEEDED;
2164}
2165
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002166static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002167ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
2168 int32_t dest_width, int32_t dest_height)
2169{
2170 struct ivi_layout_surface_properties *prop = NULL;
2171
2172 if (ivisurf == NULL) {
2173 weston_log("ivi_layout_surface_set_dimension: invalid argument\n");
2174 return IVI_FAILED;
2175 }
2176
2177 prop = &ivisurf->pending.prop;
2178 prop->dest_width = dest_width;
2179 prop->dest_height = dest_height;
2180
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002181 if (ivisurf->prop.dest_width != dest_width ||
2182 ivisurf->prop.dest_height != dest_height)
2183 ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
2184 else
2185 ivisurf->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002186
2187 return IVI_SUCCEEDED;
2188}
2189
2190int32_t
2191ivi_layout_surface_get_dimension(struct ivi_layout_surface *ivisurf,
2192 int32_t *dest_width, int32_t *dest_height)
2193{
2194 if (ivisurf == NULL || dest_width == NULL || dest_height == NULL) {
2195 weston_log("ivi_layout_surface_get_dimension: invalid argument\n");
2196 return IVI_FAILED;
2197 }
2198
2199 *dest_width = ivisurf->prop.dest_width;
2200 *dest_height = ivisurf->prop.dest_height;
2201
2202 return IVI_SUCCEEDED;
2203}
2204
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002205static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002206ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
2207 int32_t dest_x, int32_t dest_y)
2208{
2209 struct ivi_layout_surface_properties *prop = NULL;
2210
2211 if (ivisurf == NULL) {
2212 weston_log("ivi_layout_surface_set_position: invalid argument\n");
2213 return IVI_FAILED;
2214 }
2215
2216 prop = &ivisurf->pending.prop;
2217 prop->dest_x = dest_x;
2218 prop->dest_y = dest_y;
2219
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002220 if (ivisurf->prop.dest_x != dest_x || ivisurf->prop.dest_y != dest_y)
2221 ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
2222 else
2223 ivisurf->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002224
2225 return IVI_SUCCEEDED;
2226}
2227
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002228static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002229ivi_layout_surface_get_position(struct ivi_layout_surface *ivisurf,
2230 int32_t *dest_x, int32_t *dest_y)
2231{
2232 if (ivisurf == NULL || dest_x == NULL || dest_y == NULL) {
2233 weston_log("ivi_layout_surface_get_position: invalid argument\n");
2234 return IVI_FAILED;
2235 }
2236
2237 *dest_x = ivisurf->prop.dest_x;
2238 *dest_y = ivisurf->prop.dest_y;
2239
2240 return IVI_SUCCEEDED;
2241}
2242
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002243static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002244ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2245 enum wl_output_transform orientation)
2246{
2247 struct ivi_layout_surface_properties *prop = NULL;
2248
2249 if (ivisurf == NULL) {
2250 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2251 return IVI_FAILED;
2252 }
2253
2254 prop = &ivisurf->pending.prop;
2255 prop->orientation = orientation;
2256
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002257 if (ivisurf->prop.orientation != orientation)
2258 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2259 else
2260 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002261
2262 return IVI_SUCCEEDED;
2263}
2264
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002265static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002266ivi_layout_surface_get_orientation(struct ivi_layout_surface *ivisurf)
2267{
2268 if (ivisurf == NULL) {
2269 weston_log("ivi_layout_surface_get_orientation: invalid argument\n");
2270 return 0;
2271 }
2272
2273 return ivisurf->prop.orientation;
2274}
2275
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002276static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002277ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2278 struct ivi_layout_layer *addlayer)
2279{
2280 struct ivi_layout *layout = get_instance();
2281 struct ivi_layout_layer *ivilayer = NULL;
2282 struct ivi_layout_layer *next = NULL;
2283 int is_layer_in_scrn = 0;
2284
2285 if (iviscrn == NULL || addlayer == NULL) {
2286 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2287 return IVI_FAILED;
2288 }
2289
2290 is_layer_in_scrn = is_layer_in_screen(addlayer, iviscrn);
2291 if (is_layer_in_scrn == 1) {
2292 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2293 return IVI_SUCCEEDED;
2294 }
2295
2296 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2297 if (ivilayer->id_layer == addlayer->id_layer) {
2298 if (!wl_list_empty(&ivilayer->pending.link)) {
2299 wl_list_remove(&ivilayer->pending.link);
2300 }
2301 wl_list_init(&ivilayer->pending.link);
2302 wl_list_insert(&iviscrn->pending.layer_list,
2303 &ivilayer->pending.link);
2304 break;
2305 }
2306 }
2307
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002308 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002309
2310 return IVI_SUCCEEDED;
2311}
2312
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002313static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002314ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2315 struct ivi_layout_layer **pLayer,
2316 const int32_t number)
2317{
2318 struct ivi_layout *layout = get_instance();
2319 struct ivi_layout_layer *ivilayer = NULL;
2320 struct ivi_layout_layer *next = NULL;
2321 uint32_t *id_layer = NULL;
2322 int32_t i = 0;
2323
2324 if (iviscrn == NULL) {
2325 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2326 return IVI_FAILED;
2327 }
2328
2329 wl_list_for_each_safe(ivilayer, next,
2330 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002331 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002332 wl_list_init(&ivilayer->pending.link);
2333 }
2334
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002335 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002336
2337 for (i = 0; i < number; i++) {
2338 id_layer = &pLayer[i]->id_layer;
2339 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2340 if (*id_layer != ivilayer->id_layer) {
2341 continue;
2342 }
2343
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002344 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002345 wl_list_insert(&iviscrn->pending.layer_list,
2346 &ivilayer->pending.link);
2347 break;
2348 }
2349 }
2350
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002351 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002352
2353 return IVI_SUCCEEDED;
2354}
2355
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002356static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002357ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2358{
2359 return iviscrn->output;
2360}
2361
2362/**
2363 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2364 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2365 * This function is used to get the result of drawing by clients.
2366 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002367static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002368ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2369{
2370 return ivisurf != NULL ? ivisurf->surface : NULL;
2371}
2372
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002373static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002374ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2375 int32_t *width, int32_t *height,
2376 int32_t *stride)
2377{
2378 int32_t w;
2379 int32_t h;
2380 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2381
2382 if (ivisurf == NULL || ivisurf->surface == NULL) {
2383 weston_log("%s: invalid argument\n", __func__);
2384 return IVI_FAILED;
2385 }
2386
2387 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2388
2389 if (width != NULL)
2390 *width = w;
2391
2392 if (height != NULL)
2393 *height = h;
2394
2395 if (stride != NULL)
2396 *stride = w * bytespp;
2397
2398 return IVI_SUCCEEDED;
2399}
2400
2401static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002402ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2403 layer_property_notification_func callback,
2404 void *userdata)
2405{
2406 struct ivi_layout_notification_callback *prop_callback = NULL;
2407
2408 if (ivilayer == NULL || callback == NULL) {
2409 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2410 return IVI_FAILED;
2411 }
2412
2413 prop_callback = malloc(sizeof *prop_callback);
2414 if (prop_callback == NULL) {
2415 weston_log("fails to allocate memory\n");
2416 return IVI_FAILED;
2417 }
2418
2419 prop_callback->callback = callback;
2420 prop_callback->data = userdata;
2421
2422 return add_notification(&ivilayer->property_changed,
2423 layer_prop_changed,
2424 prop_callback);
2425}
2426
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002427static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002428ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2429{
2430 if (ivisurf == NULL) {
2431 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2432 return NULL;
2433 }
2434
2435 return &ivisurf->prop;
2436}
2437
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002438static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002439ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2440 struct ivi_layout_surface *addsurf)
2441{
2442 struct ivi_layout *layout = get_instance();
2443 struct ivi_layout_surface *ivisurf = NULL;
2444 struct ivi_layout_surface *next = NULL;
2445 int is_surf_in_layer = 0;
2446
2447 if (ivilayer == NULL || addsurf == NULL) {
2448 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2449 return IVI_FAILED;
2450 }
2451
2452 is_surf_in_layer = is_surface_in_layer(addsurf, ivilayer);
2453 if (is_surf_in_layer == 1) {
2454 weston_log("ivi_layout_layer_add_surface: addsurf is already available\n");
2455 return IVI_SUCCEEDED;
2456 }
2457
2458 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2459 if (ivisurf->id_surface == addsurf->id_surface) {
2460 if (!wl_list_empty(&ivisurf->pending.link)) {
2461 wl_list_remove(&ivisurf->pending.link);
2462 }
2463 wl_list_init(&ivisurf->pending.link);
2464 wl_list_insert(&ivilayer->pending.surface_list,
2465 &ivisurf->pending.link);
2466 break;
2467 }
2468 }
2469
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002470 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002471
2472 return IVI_SUCCEEDED;
2473}
2474
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002475static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002476ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2477 struct ivi_layout_surface *remsurf)
2478{
2479 struct ivi_layout_surface *ivisurf = NULL;
2480 struct ivi_layout_surface *next = NULL;
2481
2482 if (ivilayer == NULL || remsurf == NULL) {
2483 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2484 return;
2485 }
2486
2487 wl_list_for_each_safe(ivisurf, next,
2488 &ivilayer->pending.surface_list, pending.link) {
2489 if (ivisurf->id_surface == remsurf->id_surface) {
2490 if (!wl_list_empty(&ivisurf->pending.link)) {
2491 wl_list_remove(&ivisurf->pending.link);
2492 }
2493 wl_list_init(&ivisurf->pending.link);
2494 break;
2495 }
2496 }
2497
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002498 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002499}
2500
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002501static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002502ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2503 int32_t x, int32_t y,
2504 int32_t width, int32_t height)
2505{
2506 struct ivi_layout_surface_properties *prop = NULL;
2507
2508 if (ivisurf == NULL) {
2509 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2510 return IVI_FAILED;
2511 }
2512
2513 prop = &ivisurf->pending.prop;
2514 prop->source_x = x;
2515 prop->source_y = y;
2516 prop->source_width = width;
2517 prop->source_height = height;
2518
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002519 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2520 ivisurf->prop.source_width != width ||
2521 ivisurf->prop.source_height != height)
2522 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2523 else
2524 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002525
2526 return IVI_SUCCEEDED;
2527}
2528
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002529int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002530ivi_layout_commit_changes(void)
2531{
2532 struct ivi_layout *layout = get_instance();
2533
2534 commit_surface_list(layout);
2535 commit_layer_list(layout);
2536 commit_screen_list(layout);
2537
2538 commit_transition(layout);
2539
2540 commit_changes(layout);
2541 send_prop(layout);
2542 weston_compositor_schedule_repaint(layout->compositor);
2543
2544 return IVI_SUCCEEDED;
2545}
2546
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002547static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002548ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2549 enum ivi_layout_transition_type type,
2550 uint32_t duration)
2551{
2552 if (ivilayer == NULL) {
2553 weston_log("%s: invalid argument\n", __func__);
2554 return -1;
2555 }
2556
2557 ivilayer->pending.prop.transition_type = type;
2558 ivilayer->pending.prop.transition_duration = duration;
2559
2560 return 0;
2561}
2562
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002563static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002564ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2565 uint32_t is_fade_in,
2566 double start_alpha, double end_alpha)
2567{
2568 if (ivilayer == NULL) {
2569 weston_log("%s: invalid argument\n", __func__);
2570 return -1;
2571 }
2572
2573 ivilayer->pending.prop.is_fade_in = is_fade_in;
2574 ivilayer->pending.prop.start_alpha = start_alpha;
2575 ivilayer->pending.prop.end_alpha = end_alpha;
2576
2577 return 0;
2578}
2579
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002580static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002581ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2582 uint32_t duration)
2583{
2584 struct ivi_layout_surface_properties *prop;
2585
2586 if (ivisurf == NULL) {
2587 weston_log("%s: invalid argument\n", __func__);
2588 return -1;
2589 }
2590
2591 prop = &ivisurf->pending.prop;
2592 prop->transition_duration = duration*10;
2593 return 0;
2594}
2595
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002596static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002597ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2598 enum ivi_layout_transition_type type,
2599 uint32_t duration)
2600{
2601 struct ivi_layout_surface_properties *prop;
2602
2603 if (ivisurf == NULL) {
2604 weston_log("%s: invalid argument\n", __func__);
2605 return -1;
2606 }
2607
2608 prop = &ivisurf->pending.prop;
2609 prop->transition_type = type;
2610 prop->transition_duration = duration;
2611 return 0;
2612}
2613
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002614static int32_t
2615ivi_layout_surface_dump(struct weston_surface *surface,
2616 void *target, size_t size,int32_t x, int32_t y,
2617 int32_t width, int32_t height)
2618{
2619 int result = 0;
2620
2621 if (surface == NULL) {
2622 weston_log("%s: invalid argument\n", __func__);
2623 return IVI_FAILED;
2624 }
2625
2626 result = weston_surface_copy_content(
2627 surface, target, size,
2628 x, y, width, height);
2629
2630 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2631}
2632
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002633/**
2634 * methods of interaction between ivi-shell with ivi-layout
2635 */
2636struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002637ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2638{
2639 struct weston_view *tmpview = NULL;
2640
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002641 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002642 return NULL;
2643
2644 wl_list_for_each(tmpview, &surface->surface->views, surface_link)
2645 {
2646 if (tmpview != NULL) {
2647 break;
2648 }
2649 }
2650 return tmpview;
2651}
2652
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002653void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002654ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2655 int32_t width, int32_t height)
2656{
2657 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002658
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002659 /* emit callback which is set by ivi-layout api user */
2660 wl_signal_emit(&layout->surface_notification.configure_changed,
2661 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002662}
2663
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002664static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002665ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2666 ivi_controller_surface_content_callback callback,
2667 void* userdata)
2668{
2669 int32_t ret = IVI_FAILED;
2670
2671 if (ivisurf != NULL) {
2672 ivisurf->content_observer.callback = callback;
2673 ivisurf->content_observer.userdata = userdata;
2674 ret = IVI_SUCCEEDED;
2675 }
2676 return ret;
2677}
2678
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002679struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002680ivi_layout_surface_create(struct weston_surface *wl_surface,
2681 uint32_t id_surface)
2682{
2683 struct ivi_layout *layout = get_instance();
2684 struct ivi_layout_surface *ivisurf = NULL;
2685 struct weston_view *tmpview = NULL;
2686
2687 if (wl_surface == NULL) {
2688 weston_log("ivi_layout_surface_create: invalid argument\n");
2689 return NULL;
2690 }
2691
2692 ivisurf = get_surface(&layout->surface_list, id_surface);
2693 if (ivisurf != NULL) {
2694 if (ivisurf->surface != NULL) {
2695 weston_log("id_surface(%d) is already created\n", id_surface);
2696 return NULL;
2697 }
2698 }
2699
2700 ivisurf = calloc(1, sizeof *ivisurf);
2701 if (ivisurf == NULL) {
2702 weston_log("fails to allocate memory\n");
2703 return NULL;
2704 }
2705
2706 wl_list_init(&ivisurf->link);
2707 wl_signal_init(&ivisurf->property_changed);
2708 wl_signal_init(&ivisurf->configured);
2709 wl_list_init(&ivisurf->layer_list);
2710 ivisurf->id_surface = id_surface;
2711 ivisurf->layout = layout;
2712
2713 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002714
2715 tmpview = weston_view_create(wl_surface);
2716 if (tmpview == NULL) {
2717 weston_log("fails to allocate memory\n");
2718 }
2719
2720 ivisurf->surface->width_from_buffer = 0;
2721 ivisurf->surface->height_from_buffer = 0;
2722
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002723 weston_matrix_init(&ivisurf->transform.matrix);
2724 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002725
2726 init_surface_properties(&ivisurf->prop);
2727 ivisurf->event_mask = 0;
2728
2729 ivisurf->pending.prop = ivisurf->prop;
2730 wl_list_init(&ivisurf->pending.link);
2731
2732 wl_list_init(&ivisurf->order.link);
2733 wl_list_init(&ivisurf->order.layer_list);
2734
2735 wl_list_insert(&layout->surface_list, &ivisurf->link);
2736
2737 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2738
2739 return ivisurf;
2740}
2741
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002742void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002743ivi_layout_init_with_compositor(struct weston_compositor *ec)
2744{
2745 struct ivi_layout *layout = get_instance();
2746
2747 layout->compositor = ec;
2748
2749 wl_list_init(&layout->surface_list);
2750 wl_list_init(&layout->layer_list);
2751 wl_list_init(&layout->screen_list);
2752
2753 wl_signal_init(&layout->layer_notification.created);
2754 wl_signal_init(&layout->layer_notification.removed);
2755
2756 wl_signal_init(&layout->surface_notification.created);
2757 wl_signal_init(&layout->surface_notification.removed);
2758 wl_signal_init(&layout->surface_notification.configure_changed);
2759
2760 /* Add layout_layer at the last of weston_compositor.layer_list */
2761 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2762
2763 create_screen(ec);
2764
2765 layout->transitions = ivi_layout_transition_set_create(ec);
2766 wl_list_init(&layout->pending_transition_list);
2767}
2768
2769
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002770void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002771ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2772 struct wl_listener* listener)
2773{
2774 wl_signal_add(&ivisurf->configured, listener);
2775}
2776
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002777static struct ivi_controller_interface ivi_controller_interface = {
2778 /**
2779 * commit all changes
2780 */
2781 .commit_changes = ivi_layout_commit_changes,
2782
2783 /**
2784 * surface controller interfaces
2785 */
2786 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2787 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2788 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2789 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2790 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2791 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2792 .get_surfaces = ivi_layout_get_surfaces,
2793 .get_id_of_surface = ivi_layout_get_id_of_surface,
2794 .get_surface_from_id = ivi_layout_get_surface_from_id,
2795 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2796 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2797 .surface_set_visibility = ivi_layout_surface_set_visibility,
2798 .surface_get_visibility = ivi_layout_surface_get_visibility,
2799 .surface_set_opacity = ivi_layout_surface_set_opacity,
2800 .surface_get_opacity = ivi_layout_surface_get_opacity,
2801 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2802 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
2803 .surface_set_position = ivi_layout_surface_set_position,
2804 .surface_get_position = ivi_layout_surface_get_position,
2805 .surface_set_dimension = ivi_layout_surface_set_dimension,
2806 .surface_get_dimension = ivi_layout_surface_get_dimension,
2807 .surface_set_orientation = ivi_layout_surface_set_orientation,
2808 .surface_get_orientation = ivi_layout_surface_get_orientation,
2809 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2810 .surface_add_notification = ivi_layout_surface_add_notification,
2811 .surface_remove_notification = ivi_layout_surface_remove_notification,
2812 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2813 .surface_set_transition = ivi_layout_surface_set_transition,
2814 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2815
2816 /**
2817 * layer controller interfaces
2818 */
2819 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2820 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2821 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2822 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2823 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002824 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002825 .get_layers = ivi_layout_get_layers,
2826 .get_id_of_layer = ivi_layout_get_id_of_layer,
2827 .get_layer_from_id = ivi_layout_get_layer_from_id,
2828 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2829 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2830 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2831 .layer_set_visibility = ivi_layout_layer_set_visibility,
2832 .layer_get_visibility = ivi_layout_layer_get_visibility,
2833 .layer_set_opacity = ivi_layout_layer_set_opacity,
2834 .layer_get_opacity = ivi_layout_layer_get_opacity,
2835 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2836 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
2837 .layer_set_position = ivi_layout_layer_set_position,
2838 .layer_get_position = ivi_layout_layer_get_position,
2839 .layer_set_dimension = ivi_layout_layer_set_dimension,
2840 .layer_get_dimension = ivi_layout_layer_get_dimension,
2841 .layer_set_orientation = ivi_layout_layer_set_orientation,
2842 .layer_get_orientation = ivi_layout_layer_get_orientation,
2843 .layer_add_surface = ivi_layout_layer_add_surface,
2844 .layer_remove_surface = ivi_layout_layer_remove_surface,
2845 .layer_set_render_order = ivi_layout_layer_set_render_order,
2846 .layer_add_notification = ivi_layout_layer_add_notification,
2847 .layer_remove_notification = ivi_layout_layer_remove_notification,
2848 .layer_set_transition = ivi_layout_layer_set_transition,
2849
2850 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002851 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002852 */
2853 .get_screen_from_id = ivi_layout_get_screen_from_id,
2854 .get_screen_resolution = ivi_layout_get_screen_resolution,
2855 .get_screens = ivi_layout_get_screens,
2856 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2857 .screen_add_layer = ivi_layout_screen_add_layer,
2858 .screen_set_render_order = ivi_layout_screen_set_render_order,
2859 .screen_get_output = ivi_layout_screen_get_output,
2860
2861 /**
2862 * animation
2863 */
2864 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002865 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2866
2867 /**
2868 * surface content dumping for debugging
2869 */
2870 .surface_get_size = ivi_layout_surface_get_size,
2871 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002872
2873 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002874 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002875 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002876 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002877 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2878
2879 /**
2880 * screen controller interfaces part2
2881 */
2882 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002883};
2884
2885int
2886load_controller_modules(struct weston_compositor *compositor, const char *modules,
2887 int *argc, char *argv[])
2888{
2889 const char *p, *end;
2890 char buffer[256];
2891 int (*controller_module_init)(struct weston_compositor *compositor,
2892 int *argc, char *argv[],
2893 const struct ivi_controller_interface *interface,
2894 size_t interface_version);
2895
2896 if (modules == NULL)
2897 return 0;
2898
2899 p = modules;
2900 while (*p) {
2901 end = strchrnul(p, ',');
2902 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2903
2904 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002905 if (!controller_module_init)
2906 return -1;
2907
2908 if (controller_module_init(compositor, argc, argv,
2909 &ivi_controller_interface,
2910 sizeof(struct ivi_controller_interface)) != 0) {
2911 weston_log("ivi-shell: Initialization of controller module fails");
2912 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002913 }
2914
2915 p = end;
2916 while (*p == ',')
2917 p++;
2918 }
2919
2920 return 0;
2921}