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