blob: 827359adb0669a2958dcf58cce9f0fc2fb12d134 [file] [log] [blame]
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001/*
2 * Copyright (C) 2013 DENSO CORPORATION
3 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090011 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090024 */
25
26/**
27 * Implementation of ivi-layout library. The actual view on ivi_screen is
28 * not updated till calling ivi_layout_commit_changes. A overview from
29 * calling API for updating properties of ivi_surface/ivi_layer to asking
30 * compositor to compose them by using weston_compositor_schedule_repaint,
31 * 0/ initialize this library by ivi_layout_init_with_compositor
32 * with (struct weston_compositor *ec) from ivi-shell.
33 * 1/ When a API for updating properties of ivi_surface/ivi_layer, it updates
34 * pending prop of ivi_surface/ivi_layer/ivi_screen which are structure to
35 * store properties.
36 * 2/ Before calling commitChanges, in case of calling a API to get a property,
37 * return current property, not pending property.
38 * 3/ At the timing of calling ivi_layout_commitChanges, pending properties
39 * are applied to properties.
40 *
41 * *) ivi_layout_commitChanges is also called by transition animation
42 * per each frame. See ivi-layout-transition.c in details. Transition
43 * animation interpolates frames between previous properties of ivi_surface
44 * and new ones.
45 * For example, when a property of ivi_surface is changed from invisibility
46 * to visibility, it behaves like fade-in. When ivi_layout_commitChange is
47 * called during transition animation, it cancels the transition and
48 * re-start transition to new properties from current properties of final
49 * frame just before the the cancellation.
50 *
51 * 4/ According properties, set transformation by using weston_matrix and
52 * weston_view per ivi_surfaces and ivi_layers in while loop.
53 * 5/ Set damage and trigger transform by using weston_view_geometry_dirty.
54 * 6/ Notify update of properties.
55 * 7/ Trigger composition by weston_compositor_schedule_repaint.
56 *
57 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090058#include "config.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090059
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090060#include <string.h>
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +000061#include <assert.h>
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090062
63#include "compositor.h"
64#include "ivi-layout-export.h"
65#include "ivi-layout-private.h"
66
Jon Cruz867d50e2015-06-15 15:37:10 -070067#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070068#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090069
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090070struct link_layer {
71 struct ivi_layout_layer *ivilayer;
72 struct wl_list link;
73 struct wl_list link_to_layer;
74};
75
76struct link_screen {
77 struct ivi_layout_screen *iviscrn;
78 struct wl_list link;
79 struct wl_list link_to_screen;
80};
81
82struct listener_layout_notification {
83 void *userdata;
84 struct wl_listener listener;
85};
86
87struct ivi_layout;
88
89struct ivi_layout_screen {
90 struct wl_list link;
91 struct wl_list link_to_layer;
92 uint32_t id_screen;
93
94 struct ivi_layout *layout;
95 struct weston_output *output;
96
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090097 struct {
98 struct wl_list layer_list;
99 struct wl_list link;
100 } pending;
101
102 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000103 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900104 struct wl_list layer_list;
105 struct wl_list link;
106 } order;
107};
108
109struct ivi_layout_notification_callback {
110 void *callback;
111 void *data;
112};
113
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900114struct ivi_rectangle
115{
116 int32_t x;
117 int32_t y;
118 int32_t width;
119 int32_t height;
120};
121
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900122static void
123remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
124
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900125static struct ivi_layout ivilayout = {0};
126
127struct ivi_layout *
128get_instance(void)
129{
130 return &ivilayout;
131}
132
133/**
134 * Internal API to add/remove a link to ivi_surface from ivi_layer.
135 */
136static void
137add_link_to_surface(struct ivi_layout_layer *ivilayer,
138 struct link_layer *link_layer)
139{
140 struct link_layer *link = NULL;
141
142 wl_list_for_each(link, &ivilayer->link_to_surface, link_to_layer) {
143 if (link == link_layer)
144 return;
145 }
146
147 wl_list_insert(&ivilayer->link_to_surface, &link_layer->link_to_layer);
148}
149
150static void
151remove_link_to_surface(struct ivi_layout_layer *ivilayer)
152{
153 struct link_layer *link = NULL;
154 struct link_layer *next = NULL;
155
156 wl_list_for_each_safe(link, next, &ivilayer->link_to_surface, link_to_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000157 wl_list_remove(&link->link_to_layer);
158 wl_list_remove(&link->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900159 free(link);
160 }
161
162 wl_list_init(&ivilayer->link_to_surface);
163}
164
165/**
166 * Internal API to add a link to ivi_layer from ivi_screen.
167 */
168static void
169add_link_to_layer(struct ivi_layout_screen *iviscrn,
170 struct link_screen *link_screen)
171{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900172 wl_list_insert(&iviscrn->link_to_layer, &link_screen->link_to_screen);
173}
174
175/**
176 * Internal API to add/remove a ivi_surface from ivi_layer.
177 */
178static void
179add_ordersurface_to_layer(struct ivi_layout_surface *ivisurf,
180 struct ivi_layout_layer *ivilayer)
181{
182 struct link_layer *link_layer = NULL;
183
184 link_layer = malloc(sizeof *link_layer);
185 if (link_layer == NULL) {
186 weston_log("fails to allocate memory\n");
187 return;
188 }
189
190 link_layer->ivilayer = ivilayer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900191 wl_list_insert(&ivisurf->layer_list, &link_layer->link);
192 add_link_to_surface(ivilayer, link_layer);
193}
194
195static void
196remove_ordersurface_from_layer(struct ivi_layout_surface *ivisurf)
197{
198 struct link_layer *link_layer = NULL;
199 struct link_layer *next = NULL;
200
201 wl_list_for_each_safe(link_layer, next, &ivisurf->layer_list, link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000202 wl_list_remove(&link_layer->link);
203 wl_list_remove(&link_layer->link_to_layer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900204 free(link_layer);
205 }
206 wl_list_init(&ivisurf->layer_list);
207}
208
209/**
210 * Internal API to add/remove a ivi_layer to/from ivi_screen.
211 */
212static void
213add_orderlayer_to_screen(struct ivi_layout_layer *ivilayer,
214 struct ivi_layout_screen *iviscrn)
215{
216 struct link_screen *link_scrn = NULL;
217
218 link_scrn = malloc(sizeof *link_scrn);
219 if (link_scrn == NULL) {
220 weston_log("fails to allocate memory\n");
221 return;
222 }
223
224 link_scrn->iviscrn = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900225 wl_list_insert(&ivilayer->screen_list, &link_scrn->link);
226 add_link_to_layer(iviscrn, link_scrn);
227}
228
229static void
230remove_orderlayer_from_screen(struct ivi_layout_layer *ivilayer)
231{
232 struct link_screen *link_scrn = NULL;
233 struct link_screen *next = NULL;
234
235 wl_list_for_each_safe(link_scrn, next, &ivilayer->screen_list, link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000236 wl_list_remove(&link_scrn->link);
237 wl_list_remove(&link_scrn->link_to_screen);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900238 free(link_scrn);
239 }
240 wl_list_init(&ivilayer->screen_list);
241}
242
243/**
244 * Internal API to add/remove a ivi_layer to/from ivi_screen.
245 */
246static struct ivi_layout_surface *
247get_surface(struct wl_list *surf_list, uint32_t id_surface)
248{
249 struct ivi_layout_surface *ivisurf;
250
251 wl_list_for_each(ivisurf, surf_list, link) {
252 if (ivisurf->id_surface == id_surface) {
253 return ivisurf;
254 }
255 }
256
257 return NULL;
258}
259
260static struct ivi_layout_layer *
261get_layer(struct wl_list *layer_list, uint32_t id_layer)
262{
263 struct ivi_layout_layer *ivilayer;
264
265 wl_list_for_each(ivilayer, layer_list, link) {
266 if (ivilayer->id_layer == id_layer) {
267 return ivilayer;
268 }
269 }
270
271 return NULL;
272}
273
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900274static void
275remove_configured_listener(struct ivi_layout_surface *ivisurf)
276{
277 struct wl_listener *link = NULL;
278 struct wl_listener *next = NULL;
279
280 wl_list_for_each_safe(link, next, &ivisurf->configured.listener_list, link) {
281 wl_list_remove(&link->link);
282 }
283}
284
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900285static void
286remove_all_notification(struct wl_list *listener_list)
287{
288 struct wl_listener *listener = NULL;
289 struct wl_listener *next = NULL;
290
291 wl_list_for_each_safe(listener, next, listener_list, link) {
292 struct listener_layout_notification *notification = NULL;
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000293 wl_list_remove(&listener->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900294
295 notification =
296 container_of(listener,
297 struct listener_layout_notification,
298 listener);
299
300 free(notification->userdata);
301 free(notification);
302 }
303}
304
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900305static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900306ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
307{
308 if (ivisurf == NULL) {
309 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
310 return;
311 }
312
313 remove_all_notification(&ivisurf->property_changed.listener_list);
314}
315
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900316static void
317ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
318 surface_property_notification_func callback,
319 void *userdata)
320{
321 if (ivisurf == NULL) {
322 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
323 return;
324 }
325
326 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
327}
328
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900329/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900330 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900331 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900332void
333ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900334{
335 struct ivi_layout *layout = get_instance();
336
337 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900338 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900339 return;
340 }
341
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900342 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900343 wl_list_remove(&ivisurf->pending.link);
344 wl_list_remove(&ivisurf->order.link);
345 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900346 remove_ordersurface_from_layer(ivisurf);
347
348 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
349
350 remove_configured_listener(ivisurf);
351
352 ivi_layout_surface_remove_notification(ivisurf);
353
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900354 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900355}
356
357/**
358 * Internal API to check ivi_layer/ivi_surface already added in ivi_layer/ivi_screen.
359 * Called by ivi_layout_layer_add_surface/ivi_layout_screenAddLayer
360 */
361static int
362is_surface_in_layer(struct ivi_layout_surface *ivisurf,
363 struct ivi_layout_layer *ivilayer)
364{
365 struct ivi_layout_surface *surf = NULL;
366
367 wl_list_for_each(surf, &ivilayer->pending.surface_list, pending.link) {
368 if (surf->id_surface == ivisurf->id_surface) {
369 return 1;
370 }
371 }
372
373 return 0;
374}
375
376static int
377is_layer_in_screen(struct ivi_layout_layer *ivilayer,
378 struct ivi_layout_screen *iviscrn)
379{
380 struct ivi_layout_layer *layer = NULL;
381
382 wl_list_for_each(layer, &iviscrn->pending.layer_list, pending.link) {
383 if (layer->id_layer == ivilayer->id_layer) {
384 return 1;
385 }
386 }
387
388 return 0;
389}
390
391/**
392 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
393 * Called by ivi_layout_init_with_compositor.
394 */
395static void
396create_screen(struct weston_compositor *ec)
397{
398 struct ivi_layout *layout = get_instance();
399 struct ivi_layout_screen *iviscrn = NULL;
400 struct weston_output *output = NULL;
401 int32_t count = 0;
402
403 wl_list_for_each(output, &ec->output_list, link) {
404 iviscrn = calloc(1, sizeof *iviscrn);
405 if (iviscrn == NULL) {
406 weston_log("fails to allocate memory\n");
407 continue;
408 }
409
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900410 iviscrn->layout = layout;
411
412 iviscrn->id_screen = count;
413 count++;
414
415 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900416
417 wl_list_init(&iviscrn->pending.layer_list);
418 wl_list_init(&iviscrn->pending.link);
419
420 wl_list_init(&iviscrn->order.layer_list);
421 wl_list_init(&iviscrn->order.link);
422
423 wl_list_init(&iviscrn->link_to_layer);
424
425 wl_list_insert(&layout->screen_list, &iviscrn->link);
426 }
427}
428
429/**
430 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
431 */
432static void
433init_layer_properties(struct ivi_layout_layer_properties *prop,
434 int32_t width, int32_t height)
435{
436 memset(prop, 0, sizeof *prop);
437 prop->opacity = wl_fixed_from_double(1.0);
438 prop->source_width = width;
439 prop->source_height = height;
440 prop->dest_width = width;
441 prop->dest_height = height;
442}
443
444static void
445init_surface_properties(struct ivi_layout_surface_properties *prop)
446{
447 memset(prop, 0, sizeof *prop);
448 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900449 /*
450 * FIXME: this shall be finxed by ivi-layout-transition.
451 */
452 prop->dest_width = 1;
453 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900454}
455
456/**
457 * Internal APIs to be called from ivi_layout_commit_changes.
458 */
459static void
460update_opacity(struct ivi_layout_layer *ivilayer,
461 struct ivi_layout_surface *ivisurf)
462{
463 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
464 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
465
466 if ((ivilayer->event_mask & IVI_NOTIFICATION_OPACITY) ||
467 (ivisurf->event_mask & IVI_NOTIFICATION_OPACITY)) {
468 struct weston_view *tmpview = NULL;
469 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
470 if (tmpview == NULL) {
471 continue;
472 }
473 tmpview->alpha = layer_alpha * surf_alpha;
474 }
475 }
476}
477
478static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900479get_rotate_values(enum wl_output_transform orientation,
480 float *v_sin,
481 float *v_cos)
482{
483 switch (orientation) {
484 case WL_OUTPUT_TRANSFORM_90:
485 *v_sin = 1.0f;
486 *v_cos = 0.0f;
487 break;
488 case WL_OUTPUT_TRANSFORM_180:
489 *v_sin = 0.0f;
490 *v_cos = -1.0f;
491 break;
492 case WL_OUTPUT_TRANSFORM_270:
493 *v_sin = -1.0f;
494 *v_cos = 0.0f;
495 break;
496 case WL_OUTPUT_TRANSFORM_NORMAL:
497 default:
498 *v_sin = 0.0f;
499 *v_cos = 1.0f;
500 break;
501 }
502}
503
504static void
505get_scale(enum wl_output_transform orientation,
506 float dest_width,
507 float dest_height,
508 float source_width,
509 float source_height,
510 float *scale_x,
511 float *scale_y)
512{
513 switch (orientation) {
514 case WL_OUTPUT_TRANSFORM_90:
515 *scale_x = dest_width / source_height;
516 *scale_y = dest_height / source_width;
517 break;
518 case WL_OUTPUT_TRANSFORM_180:
519 *scale_x = dest_width / source_width;
520 *scale_y = dest_height / source_height;
521 break;
522 case WL_OUTPUT_TRANSFORM_270:
523 *scale_x = dest_width / source_height;
524 *scale_y = dest_height / source_width;
525 break;
526 case WL_OUTPUT_TRANSFORM_NORMAL:
527 default:
528 *scale_x = dest_width / source_width;
529 *scale_y = dest_height / source_height;
530 break;
531 }
532}
533
534static void
535calc_transformation_matrix(struct ivi_rectangle *source_rect,
536 struct ivi_rectangle *dest_rect,
537 enum wl_output_transform orientation,
538 struct weston_matrix *m)
539{
540 float source_center_x;
541 float source_center_y;
542 float vsin;
543 float vcos;
544 float scale_x;
545 float scale_y;
546 float translate_x;
547 float translate_y;
548
549 source_center_x = source_rect->x + source_rect->width * 0.5f;
550 source_center_y = source_rect->y + source_rect->height * 0.5f;
551 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
552
553 get_rotate_values(orientation, &vsin, &vcos);
554 weston_matrix_rotate_xy(m, vcos, vsin);
555
556 get_scale(orientation,
557 dest_rect->width,
558 dest_rect->height,
559 source_rect->width,
560 source_rect->height,
561 &scale_x,
562 &scale_y);
563 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
564
565 translate_x = dest_rect->width * 0.5f + dest_rect->x;
566 translate_y = dest_rect->height * 0.5f + dest_rect->y;
567 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
568}
569
570/**
571 * This computes the whole transformation matrix from surface-local
572 * coordinates to global coordinates. It is assumed that
573 * weston_view::geometry.{x,y} are zero.
574 */
575static void
576calc_surface_to_global_matrix(struct ivi_layout_layer *ivilayer,
577 struct ivi_layout_surface *ivisurf,
578 struct weston_matrix *m)
579{
580 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
581 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
582 struct ivi_rectangle surface_source_rect = { sp->source_x,
583 sp->source_y,
584 sp->source_width,
585 sp->source_height };
586 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
587 sp->dest_y,
588 sp->dest_width,
589 sp->dest_height };
590 struct ivi_rectangle layer_source_rect = { lp->source_x,
591 lp->source_y,
592 lp->source_width,
593 lp->source_height };
594 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
595 lp->dest_y,
596 lp->dest_width,
597 lp->dest_height };
598
599 calc_transformation_matrix(&surface_source_rect,
600 &surface_dest_rect,
601 sp->orientation, m);
602
603 calc_transformation_matrix(&layer_source_rect,
604 &layer_dest_rect,
605 lp->orientation, m);
606}
607
608static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900609update_prop(struct ivi_layout_layer *ivilayer,
610 struct ivi_layout_surface *ivisurf)
611{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900612 struct weston_view *tmpview;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900613 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900614
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900615 if (!ivilayer->event_mask && !ivisurf->event_mask) {
616 return;
617 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900618
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900619 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900620
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900621 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900622 if (tmpview != NULL) {
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900623 break;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900624 }
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900625 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900626
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900627 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
628 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
629 can_calc = false;
630 }
631
632 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
633 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
634 can_calc = false;
635 }
636
637 if (can_calc) {
638 wl_list_remove(&ivisurf->transform.link);
639 weston_matrix_init(&ivisurf->transform.matrix);
640
641 calc_surface_to_global_matrix(ivilayer, ivisurf, &ivisurf->transform.matrix);
642
643 if (tmpview != NULL) {
644 wl_list_insert(&tmpview->geometry.transformation_list, &ivisurf->transform.link);
645
646 weston_view_set_transform_parent(tmpview, NULL);
647 }
648 }
649
650 ivisurf->update_count++;
651
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900652 if (tmpview != NULL) {
653 weston_view_geometry_dirty(tmpview);
654 }
655
656 if (ivisurf->surface != NULL) {
657 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900658 }
659}
660
661static void
662commit_changes(struct ivi_layout *layout)
663{
664 struct ivi_layout_screen *iviscrn = NULL;
665 struct ivi_layout_layer *ivilayer = NULL;
666 struct ivi_layout_surface *ivisurf = NULL;
667
668 wl_list_for_each(iviscrn, &layout->screen_list, link) {
669 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
670 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
671 update_prop(ivilayer, ivisurf);
672 }
673 }
674 }
675}
676
677static void
678commit_surface_list(struct ivi_layout *layout)
679{
680 struct ivi_layout_surface *ivisurf = NULL;
681 int32_t dest_x = 0;
682 int32_t dest_y = 0;
683 int32_t dest_width = 0;
684 int32_t dest_height = 0;
685 int32_t configured = 0;
686
687 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300688 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900689 dest_x = ivisurf->prop.dest_x;
690 dest_y = ivisurf->prop.dest_y;
691 dest_width = ivisurf->prop.dest_width;
692 dest_height = ivisurf->prop.dest_height;
693
694 ivi_layout_transition_move_resize_view(ivisurf,
695 ivisurf->pending.prop.dest_x,
696 ivisurf->pending.prop.dest_y,
697 ivisurf->pending.prop.dest_width,
698 ivisurf->pending.prop.dest_height,
699 ivisurf->pending.prop.transition_duration);
700
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300701 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900702 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
703 } else {
704 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
705 }
706
707 ivisurf->prop = ivisurf->pending.prop;
708 ivisurf->prop.dest_x = dest_x;
709 ivisurf->prop.dest_y = dest_y;
710 ivisurf->prop.dest_width = dest_width;
711 ivisurf->prop.dest_height = dest_height;
712 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
713 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
714
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300715 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900716 dest_x = ivisurf->prop.dest_x;
717 dest_y = ivisurf->prop.dest_y;
718 dest_width = ivisurf->prop.dest_width;
719 dest_height = ivisurf->prop.dest_height;
720
721 ivi_layout_transition_move_resize_view(ivisurf,
722 ivisurf->pending.prop.dest_x,
723 ivisurf->pending.prop.dest_y,
724 ivisurf->pending.prop.dest_width,
725 ivisurf->pending.prop.dest_height,
726 ivisurf->pending.prop.transition_duration);
727
728 ivisurf->prop = ivisurf->pending.prop;
729 ivisurf->prop.dest_x = dest_x;
730 ivisurf->prop.dest_y = dest_y;
731 ivisurf->prop.dest_width = dest_width;
732 ivisurf->prop.dest_height = dest_height;
733
734 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
735 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
736
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300737 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900738 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300739 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900740 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
741 } else {
742 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
743 }
744
745 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
746 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
747 configured = 1;
748 }
749
750 ivisurf->prop = ivisurf->pending.prop;
751 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
752 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
753
754 if (configured && !is_surface_transition(ivisurf))
755 wl_signal_emit(&ivisurf->configured, ivisurf);
756 } else {
757 configured = 0;
758 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
759 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
760 configured = 1;
761 }
762
763 ivisurf->prop = ivisurf->pending.prop;
764 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
765 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
766
767 if (configured && !is_surface_transition(ivisurf))
768 wl_signal_emit(&ivisurf->configured, ivisurf);
769 }
770 }
771}
772
773static void
774commit_layer_list(struct ivi_layout *layout)
775{
776 struct ivi_layout_layer *ivilayer = NULL;
777 struct ivi_layout_surface *ivisurf = NULL;
778 struct ivi_layout_surface *next = NULL;
779
780 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300781 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900782 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 -0300783 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900784 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
785 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
786 NULL, NULL,
787 ivilayer->pending.prop.transition_duration);
788 }
789 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
790
791 ivilayer->prop = ivilayer->pending.prop;
792
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000793 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900794 continue;
795 }
796
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000797 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
798 order.link) {
799 remove_ordersurface_from_layer(ivisurf);
800 wl_list_remove(&ivisurf->order.link);
801 wl_list_init(&ivisurf->order.link);
802 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900803 }
804
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000805 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900806
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000807 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900808 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000809 wl_list_remove(&ivisurf->order.link);
810 wl_list_insert(&ivilayer->order.surface_list,
811 &ivisurf->order.link);
812 add_ordersurface_to_layer(ivisurf, ivilayer);
813 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900814 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000815
816 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900817 }
818}
819
820static void
821commit_screen_list(struct ivi_layout *layout)
822{
823 struct ivi_layout_screen *iviscrn = NULL;
824 struct ivi_layout_layer *ivilayer = NULL;
825 struct ivi_layout_layer *next = NULL;
826 struct ivi_layout_surface *ivisurf = NULL;
827
828 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000829 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900830 wl_list_for_each_safe(ivilayer, next,
831 &iviscrn->order.layer_list, order.link) {
832 remove_orderlayer_from_screen(ivilayer);
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000833 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900834 wl_list_init(&ivilayer->order.link);
835 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
836 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900837
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000838 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900839
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900840 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
841 pending.link) {
842 wl_list_insert(&iviscrn->order.layer_list,
843 &ivilayer->order.link);
844 add_orderlayer_to_screen(ivilayer, iviscrn);
845 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
846 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900847
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000848 iviscrn->order.dirty = 0;
849 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900850
851 /* Clear view list of layout ivi_layer */
852 wl_list_init(&layout->layout_layer.view_list.link);
853
854 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
855 if (ivilayer->prop.visibility == false)
856 continue;
857
858 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
859 struct weston_view *tmpview = NULL;
860 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
861 if (tmpview != NULL) {
862 break;
863 }
864 }
865
866 if (ivisurf->prop.visibility == false)
867 continue;
868 if (ivisurf->surface == NULL || tmpview == NULL)
869 continue;
870
871 weston_layer_entry_insert(&layout->layout_layer.view_list,
872 &tmpview->layer_link);
873
874 ivisurf->surface->output = iviscrn->output;
875 }
876 }
877
878 break;
879 }
880}
881
882static void
883commit_transition(struct ivi_layout* layout)
884{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300885 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900886 return;
887 }
888
889 wl_list_insert_list(&layout->transitions->transition_list,
890 &layout->pending_transition_list);
891
892 wl_list_init(&layout->pending_transition_list);
893
894 wl_event_source_timer_update(layout->transitions->event_source, 1);
895}
896
897static void
898send_surface_prop(struct ivi_layout_surface *ivisurf)
899{
900 wl_signal_emit(&ivisurf->property_changed, ivisurf);
901 ivisurf->event_mask = 0;
902}
903
904static void
905send_layer_prop(struct ivi_layout_layer *ivilayer)
906{
907 wl_signal_emit(&ivilayer->property_changed, ivilayer);
908 ivilayer->event_mask = 0;
909}
910
911static void
912send_prop(struct ivi_layout *layout)
913{
914 struct ivi_layout_layer *ivilayer = NULL;
915 struct ivi_layout_surface *ivisurf = NULL;
916
917 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900918 if (ivilayer->event_mask)
919 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900920 }
921
922 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900923 if (ivisurf->event_mask)
924 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900925 }
926}
927
928static void
929clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
930{
931 struct ivi_layout_surface *surface_link = NULL;
932 struct ivi_layout_surface *surface_next = NULL;
933
934 wl_list_for_each_safe(surface_link, surface_next,
935 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000936 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900937 wl_list_init(&surface_link->pending.link);
938 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900939}
940
941static void
942clear_surface_order_list(struct ivi_layout_layer *ivilayer)
943{
944 struct ivi_layout_surface *surface_link = NULL;
945 struct ivi_layout_surface *surface_next = NULL;
946
947 wl_list_for_each_safe(surface_link, surface_next,
948 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000949 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900950 wl_list_init(&surface_link->order.link);
951 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900952}
953
954static void
955layer_created(struct wl_listener *listener, void *data)
956{
957 struct ivi_layout_layer *ivilayer = data;
958
959 struct listener_layout_notification *notification =
960 container_of(listener,
961 struct listener_layout_notification,
962 listener);
963
964 struct ivi_layout_notification_callback *created_callback =
965 notification->userdata;
966
967 ((layer_create_notification_func)created_callback->callback)
968 (ivilayer, created_callback->data);
969}
970
971static void
972layer_removed(struct wl_listener *listener, void *data)
973{
974 struct ivi_layout_layer *ivilayer = data;
975
976 struct listener_layout_notification *notification =
977 container_of(listener,
978 struct listener_layout_notification,
979 listener);
980
981 struct ivi_layout_notification_callback *removed_callback =
982 notification->userdata;
983
984 ((layer_remove_notification_func)removed_callback->callback)
985 (ivilayer, removed_callback->data);
986}
987
988static void
989layer_prop_changed(struct wl_listener *listener, void *data)
990{
991 struct ivi_layout_layer *ivilayer = data;
992
993 struct listener_layout_notification *layout_listener =
994 container_of(listener,
995 struct listener_layout_notification,
996 listener);
997
998 struct ivi_layout_notification_callback *prop_callback =
999 layout_listener->userdata;
1000
1001 ((layer_property_notification_func)prop_callback->callback)
1002 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1003}
1004
1005static void
1006surface_created(struct wl_listener *listener, void *data)
1007{
1008 struct ivi_layout_surface *ivisurface = data;
1009
1010 struct listener_layout_notification *notification =
1011 container_of(listener,
1012 struct listener_layout_notification,
1013 listener);
1014
1015 struct ivi_layout_notification_callback *created_callback =
1016 notification->userdata;
1017
1018 ((surface_create_notification_func)created_callback->callback)
1019 (ivisurface, created_callback->data);
1020}
1021
1022static void
1023surface_removed(struct wl_listener *listener, void *data)
1024{
1025 struct ivi_layout_surface *ivisurface = 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 *removed_callback =
1033 notification->userdata;
1034
1035 ((surface_remove_notification_func)removed_callback->callback)
1036 (ivisurface, removed_callback->data);
1037}
1038
1039static void
1040surface_prop_changed(struct wl_listener *listener, void *data)
1041{
1042 struct ivi_layout_surface *ivisurf = data;
1043
1044 struct listener_layout_notification *layout_listener =
1045 container_of(listener,
1046 struct listener_layout_notification,
1047 listener);
1048
1049 struct ivi_layout_notification_callback *prop_callback =
1050 layout_listener->userdata;
1051
1052 ((surface_property_notification_func)prop_callback->callback)
1053 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1054
1055 ivisurf->event_mask = 0;
1056}
1057
1058static void
1059surface_configure_changed(struct wl_listener *listener,
1060 void *data)
1061{
1062 struct ivi_layout_surface *ivisurface = data;
1063
1064 struct listener_layout_notification *notification =
1065 container_of(listener,
1066 struct listener_layout_notification,
1067 listener);
1068
1069 struct ivi_layout_notification_callback *configure_changed_callback =
1070 notification->userdata;
1071
1072 ((surface_configure_notification_func)configure_changed_callback->callback)
1073 (ivisurface, configure_changed_callback->data);
1074}
1075
1076static int32_t
1077add_notification(struct wl_signal *signal,
1078 wl_notify_func_t callback,
1079 void *userdata)
1080{
1081 struct listener_layout_notification *notification = NULL;
1082
1083 notification = malloc(sizeof *notification);
1084 if (notification == NULL) {
1085 weston_log("fails to allocate memory\n");
1086 free(userdata);
1087 return IVI_FAILED;
1088 }
1089
1090 notification->listener.notify = callback;
1091 notification->userdata = userdata;
1092
1093 wl_signal_add(signal, &notification->listener);
1094
1095 return IVI_SUCCEEDED;
1096}
1097
1098static void
1099remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1100{
1101 struct wl_listener *listener = NULL;
1102 struct wl_listener *next = NULL;
1103
1104 wl_list_for_each_safe(listener, next, listener_list, link) {
1105 struct listener_layout_notification *notification =
1106 container_of(listener,
1107 struct listener_layout_notification,
1108 listener);
1109
1110 struct ivi_layout_notification_callback *notification_callback =
1111 notification->userdata;
1112
1113 if ((notification_callback->callback != callback) ||
1114 (notification_callback->data != userdata)) {
1115 continue;
1116 }
1117
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001118 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001119
1120 free(notification->userdata);
1121 free(notification);
1122 }
1123}
1124
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001125/**
1126 * Exported APIs of ivi-layout library are implemented from here.
1127 * Brief of APIs is described in ivi-layout-export.h.
1128 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001129static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001130ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1131 void *userdata)
1132{
1133 struct ivi_layout *layout = get_instance();
1134 struct ivi_layout_notification_callback *created_callback = NULL;
1135
1136 if (callback == NULL) {
1137 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1138 return IVI_FAILED;
1139 }
1140
1141 created_callback = malloc(sizeof *created_callback);
1142 if (created_callback == NULL) {
1143 weston_log("fails to allocate memory\n");
1144 return IVI_FAILED;
1145 }
1146
1147 created_callback->callback = callback;
1148 created_callback->data = userdata;
1149
1150 return add_notification(&layout->layer_notification.created,
1151 layer_created,
1152 created_callback);
1153}
1154
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001155static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001156ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1157 void *userdata)
1158{
1159 struct ivi_layout *layout = get_instance();
1160 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1161}
1162
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001163static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001164ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1165 void *userdata)
1166{
1167 struct ivi_layout *layout = get_instance();
1168 struct ivi_layout_notification_callback *removed_callback = NULL;
1169
1170 if (callback == NULL) {
1171 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1172 return IVI_FAILED;
1173 }
1174
1175 removed_callback = malloc(sizeof *removed_callback);
1176 if (removed_callback == NULL) {
1177 weston_log("fails to allocate memory\n");
1178 return IVI_FAILED;
1179 }
1180
1181 removed_callback->callback = callback;
1182 removed_callback->data = userdata;
1183 return add_notification(&layout->layer_notification.removed,
1184 layer_removed,
1185 removed_callback);
1186}
1187
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001188static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001189ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1190 void *userdata)
1191{
1192 struct ivi_layout *layout = get_instance();
1193 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1194}
1195
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001196static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001197ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1198 void *userdata)
1199{
1200 struct ivi_layout *layout = get_instance();
1201 struct ivi_layout_notification_callback *created_callback = NULL;
1202
1203 if (callback == NULL) {
1204 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1205 return IVI_FAILED;
1206 }
1207
1208 created_callback = malloc(sizeof *created_callback);
1209 if (created_callback == NULL) {
1210 weston_log("fails to allocate memory\n");
1211 return IVI_FAILED;
1212 }
1213
1214 created_callback->callback = callback;
1215 created_callback->data = userdata;
1216
1217 return add_notification(&layout->surface_notification.created,
1218 surface_created,
1219 created_callback);
1220}
1221
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001222static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001223ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1224 void *userdata)
1225{
1226 struct ivi_layout *layout = get_instance();
1227 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1228}
1229
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001230static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001231ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1232 void *userdata)
1233{
1234 struct ivi_layout *layout = get_instance();
1235 struct ivi_layout_notification_callback *removed_callback = NULL;
1236
1237 if (callback == NULL) {
1238 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1239 return IVI_FAILED;
1240 }
1241
1242 removed_callback = malloc(sizeof *removed_callback);
1243 if (removed_callback == NULL) {
1244 weston_log("fails to allocate memory\n");
1245 return IVI_FAILED;
1246 }
1247
1248 removed_callback->callback = callback;
1249 removed_callback->data = userdata;
1250
1251 return add_notification(&layout->surface_notification.removed,
1252 surface_removed,
1253 removed_callback);
1254}
1255
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001256static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001257ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1258 void *userdata)
1259{
1260 struct ivi_layout *layout = get_instance();
1261 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1262}
1263
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001264static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001265ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1266 void *userdata)
1267{
1268 struct ivi_layout *layout = get_instance();
1269 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1270 if (callback == NULL) {
1271 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1272 return IVI_FAILED;
1273 }
1274
1275 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1276 if (configure_changed_callback == NULL) {
1277 weston_log("fails to allocate memory\n");
1278 return IVI_FAILED;
1279 }
1280
1281 configure_changed_callback->callback = callback;
1282 configure_changed_callback->data = userdata;
1283
1284 return add_notification(&layout->surface_notification.configure_changed,
1285 surface_configure_changed,
1286 configure_changed_callback);
1287}
1288
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001289static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001290ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1291 void *userdata)
1292{
1293 struct ivi_layout *layout = get_instance();
1294 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1295}
1296
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001297uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001298ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1299{
1300 return ivisurf->id_surface;
1301}
1302
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001303static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001304ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1305{
1306 return ivilayer->id_layer;
1307}
1308
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001309static uint32_t
1310ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1311{
1312 return iviscrn->id_screen;
1313}
1314
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001315static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001316ivi_layout_get_layer_from_id(uint32_t id_layer)
1317{
1318 struct ivi_layout *layout = get_instance();
1319 struct ivi_layout_layer *ivilayer = NULL;
1320
1321 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1322 if (ivilayer->id_layer == id_layer) {
1323 return ivilayer;
1324 }
1325 }
1326
1327 return NULL;
1328}
1329
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001330struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001331ivi_layout_get_surface_from_id(uint32_t id_surface)
1332{
1333 struct ivi_layout *layout = get_instance();
1334 struct ivi_layout_surface *ivisurf = NULL;
1335
1336 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1337 if (ivisurf->id_surface == id_surface) {
1338 return ivisurf;
1339 }
1340 }
1341
1342 return NULL;
1343}
1344
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001345static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001346ivi_layout_get_screen_from_id(uint32_t id_screen)
1347{
1348 struct ivi_layout *layout = get_instance();
1349 struct ivi_layout_screen *iviscrn = NULL;
1350
1351 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1352/* FIXME : select iviscrn from screen_list by id_screen */
1353 return iviscrn;
1354 break;
1355 }
1356
1357 return NULL;
1358}
1359
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001360static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001361ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1362 int32_t *pWidth, int32_t *pHeight)
1363{
1364 struct weston_output *output = NULL;
1365
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001366 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001367 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1368 return IVI_FAILED;
1369 }
1370
1371 output = iviscrn->output;
1372 *pWidth = output->current_mode->width;
1373 *pHeight = output->current_mode->height;
1374
1375 return IVI_SUCCEEDED;
1376}
1377
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001378static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001379ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1380 surface_property_notification_func callback,
1381 void *userdata)
1382{
1383 struct listener_layout_notification* notification = NULL;
1384 struct ivi_layout_notification_callback *prop_callback = NULL;
1385
1386 if (ivisurf == NULL || callback == NULL) {
1387 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1388 return IVI_FAILED;
1389 }
1390
1391 notification = malloc(sizeof *notification);
1392 if (notification == NULL) {
1393 weston_log("fails to allocate memory\n");
1394 return IVI_FAILED;
1395 }
1396
1397 prop_callback = malloc(sizeof *prop_callback);
1398 if (prop_callback == NULL) {
1399 weston_log("fails to allocate memory\n");
1400 return IVI_FAILED;
1401 }
1402
1403 prop_callback->callback = callback;
1404 prop_callback->data = userdata;
1405
1406 notification->listener.notify = surface_prop_changed;
1407 notification->userdata = prop_callback;
1408
1409 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1410
1411 return IVI_SUCCEEDED;
1412}
1413
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001414static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001415ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1416{
1417 if (ivilayer == NULL) {
1418 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1419 return NULL;
1420 }
1421
1422 return &ivilayer->prop;
1423}
1424
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001425static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001426ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1427{
1428 struct ivi_layout *layout = get_instance();
1429 struct ivi_layout_screen *iviscrn = NULL;
1430 int32_t length = 0;
1431 int32_t n = 0;
1432
1433 if (pLength == NULL || ppArray == NULL) {
1434 weston_log("ivi_layout_get_screens: invalid argument\n");
1435 return IVI_FAILED;
1436 }
1437
1438 length = wl_list_length(&layout->screen_list);
1439
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001440 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001441 /* the Array must be free by module which called this function */
1442 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1443 if (*ppArray == NULL) {
1444 weston_log("fails to allocate memory\n");
1445 return IVI_FAILED;
1446 }
1447
1448 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1449 (*ppArray)[n++] = iviscrn;
1450 }
1451 }
1452
1453 *pLength = length;
1454
1455 return IVI_SUCCEEDED;
1456}
1457
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001458static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001459ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1460 int32_t *pLength,
1461 struct ivi_layout_screen ***ppArray)
1462{
1463 struct link_screen *link_scrn = NULL;
1464 int32_t length = 0;
1465 int32_t n = 0;
1466
1467 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1468 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1469 return IVI_FAILED;
1470 }
1471
1472 length = wl_list_length(&ivilayer->screen_list);
1473
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001474 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001475 /* the Array must be free by module which called this function */
1476 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1477 if (*ppArray == NULL) {
1478 weston_log("fails to allocate memory\n");
1479 return IVI_FAILED;
1480 }
1481
1482 wl_list_for_each(link_scrn, &ivilayer->screen_list, link) {
1483 (*ppArray)[n++] = link_scrn->iviscrn;
1484 }
1485 }
1486
1487 *pLength = length;
1488
1489 return IVI_SUCCEEDED;
1490}
1491
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001492static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001493ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1494{
1495 struct ivi_layout *layout = get_instance();
1496 struct ivi_layout_layer *ivilayer = NULL;
1497 int32_t length = 0;
1498 int32_t n = 0;
1499
1500 if (pLength == NULL || ppArray == NULL) {
1501 weston_log("ivi_layout_get_layers: invalid argument\n");
1502 return IVI_FAILED;
1503 }
1504
1505 length = wl_list_length(&layout->layer_list);
1506
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001507 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001508 /* the Array must be free by module which called this function */
1509 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1510 if (*ppArray == NULL) {
1511 weston_log("fails to allocate memory\n");
1512 return IVI_FAILED;
1513 }
1514
1515 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1516 (*ppArray)[n++] = ivilayer;
1517 }
1518 }
1519
1520 *pLength = length;
1521
1522 return IVI_SUCCEEDED;
1523}
1524
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001525static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001526ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1527 int32_t *pLength,
1528 struct ivi_layout_layer ***ppArray)
1529{
1530 struct ivi_layout_layer *ivilayer = NULL;
1531 int32_t length = 0;
1532 int32_t n = 0;
1533
1534 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1535 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1536 return IVI_FAILED;
1537 }
1538
1539 length = wl_list_length(&iviscrn->order.layer_list);
1540
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001541 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001542 /* the Array must be free by module which called this function */
1543 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1544 if (*ppArray == NULL) {
1545 weston_log("fails to allocate memory\n");
1546 return IVI_FAILED;
1547 }
1548
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001549 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001550 (*ppArray)[n++] = ivilayer;
1551 }
1552 }
1553
1554 *pLength = length;
1555
1556 return IVI_SUCCEEDED;
1557}
1558
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001559static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001560ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1561 int32_t *pLength,
1562 struct ivi_layout_layer ***ppArray)
1563{
1564 struct link_layer *link_layer = NULL;
1565 int32_t length = 0;
1566 int32_t n = 0;
1567
1568 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1569 weston_log("ivi_layout_getLayers: invalid argument\n");
1570 return IVI_FAILED;
1571 }
1572
1573 length = wl_list_length(&ivisurf->layer_list);
1574
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001575 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001576 /* the Array must be free by module which called this function */
1577 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1578 if (*ppArray == NULL) {
1579 weston_log("fails to allocate memory\n");
1580 return IVI_FAILED;
1581 }
1582
1583 wl_list_for_each(link_layer, &ivisurf->layer_list, link) {
1584 (*ppArray)[n++] = link_layer->ivilayer;
1585 }
1586 }
1587
1588 *pLength = length;
1589
1590 return IVI_SUCCEEDED;
1591}
1592
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001593static
1594int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001595ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1596{
1597 struct ivi_layout *layout = get_instance();
1598 struct ivi_layout_surface *ivisurf = NULL;
1599 int32_t length = 0;
1600 int32_t n = 0;
1601
1602 if (pLength == NULL || ppArray == NULL) {
1603 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1604 return IVI_FAILED;
1605 }
1606
1607 length = wl_list_length(&layout->surface_list);
1608
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001609 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001610 /* the Array must be free by module which called this function */
1611 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1612 if (*ppArray == NULL) {
1613 weston_log("fails to allocate memory\n");
1614 return IVI_FAILED;
1615 }
1616
1617 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1618 (*ppArray)[n++] = ivisurf;
1619 }
1620 }
1621
1622 *pLength = length;
1623
1624 return IVI_SUCCEEDED;
1625}
1626
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001627static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001628ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1629 int32_t *pLength,
1630 struct ivi_layout_surface ***ppArray)
1631{
1632 struct ivi_layout_surface *ivisurf = NULL;
1633 int32_t length = 0;
1634 int32_t n = 0;
1635
1636 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1637 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1638 return IVI_FAILED;
1639 }
1640
1641 length = wl_list_length(&ivilayer->order.surface_list);
1642
1643 if (length != 0) {
1644 /* the Array must be free by module which called this function */
1645 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1646 if (*ppArray == NULL) {
1647 weston_log("fails to allocate memory\n");
1648 return IVI_FAILED;
1649 }
1650
1651 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1652 (*ppArray)[n++] = ivisurf;
1653 }
1654 }
1655
1656 *pLength = length;
1657
1658 return IVI_SUCCEEDED;
1659}
1660
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001661static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001662ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1663 int32_t width, int32_t height)
1664{
1665 struct ivi_layout *layout = get_instance();
1666 struct ivi_layout_layer *ivilayer = NULL;
1667
1668 ivilayer = get_layer(&layout->layer_list, id_layer);
1669 if (ivilayer != NULL) {
1670 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001671 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001672 return ivilayer;
1673 }
1674
1675 ivilayer = calloc(1, sizeof *ivilayer);
1676 if (ivilayer == NULL) {
1677 weston_log("fails to allocate memory\n");
1678 return NULL;
1679 }
1680
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001681 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001682 wl_signal_init(&ivilayer->property_changed);
1683 wl_list_init(&ivilayer->screen_list);
1684 wl_list_init(&ivilayer->link_to_surface);
1685 ivilayer->layout = layout;
1686 ivilayer->id_layer = id_layer;
1687
1688 init_layer_properties(&ivilayer->prop, width, height);
1689 ivilayer->event_mask = 0;
1690
1691 wl_list_init(&ivilayer->pending.surface_list);
1692 wl_list_init(&ivilayer->pending.link);
1693 ivilayer->pending.prop = ivilayer->prop;
1694
1695 wl_list_init(&ivilayer->order.surface_list);
1696 wl_list_init(&ivilayer->order.link);
1697
1698 wl_list_insert(&layout->layer_list, &ivilayer->link);
1699
1700 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1701
1702 return ivilayer;
1703}
1704
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001705static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001706ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1707{
1708 if (ivilayer == NULL) {
1709 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1710 return;
1711 }
1712
1713 remove_all_notification(&ivilayer->property_changed.listener_list);
1714}
1715
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001716static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001717ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1718 layer_property_notification_func callback,
1719 void *userdata)
1720{
1721 if (ivilayer == NULL) {
1722 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1723 return;
1724 }
1725
1726 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1727}
1728
1729static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001730ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001731{
1732 struct ivi_layout *layout = get_instance();
1733
1734 if (ivilayer == NULL) {
1735 weston_log("ivi_layout_layer_remove: invalid argument\n");
1736 return;
1737 }
1738
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001739 if (--ivilayer->ref_count > 0)
1740 return;
1741
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001742 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1743
1744 clear_surface_pending_list(ivilayer);
1745 clear_surface_order_list(ivilayer);
1746
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001747 wl_list_remove(&ivilayer->pending.link);
1748 wl_list_remove(&ivilayer->order.link);
1749 wl_list_remove(&ivilayer->link);
1750
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001751 remove_orderlayer_from_screen(ivilayer);
1752 remove_link_to_surface(ivilayer);
1753 ivi_layout_layer_remove_notification(ivilayer);
1754
1755 free(ivilayer);
1756}
1757
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001758int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001759ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1760 bool newVisibility)
1761{
1762 struct ivi_layout_layer_properties *prop = NULL;
1763
1764 if (ivilayer == NULL) {
1765 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1766 return IVI_FAILED;
1767 }
1768
1769 prop = &ivilayer->pending.prop;
1770 prop->visibility = newVisibility;
1771
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001772 if (ivilayer->prop.visibility != newVisibility)
1773 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1774 else
1775 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001776
1777 return IVI_SUCCEEDED;
1778}
1779
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001780static bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001781ivi_layout_layer_get_visibility(struct ivi_layout_layer *ivilayer)
1782{
1783 if (ivilayer == NULL) {
1784 weston_log("ivi_layout_layer_get_visibility: invalid argument\n");
1785 return false;
1786 }
1787
1788 return ivilayer->prop.visibility;
1789}
1790
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001791int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001792ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1793 wl_fixed_t opacity)
1794{
1795 struct ivi_layout_layer_properties *prop = NULL;
1796
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001797 if (ivilayer == NULL ||
1798 opacity < wl_fixed_from_double(0.0) ||
1799 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001800 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1801 return IVI_FAILED;
1802 }
1803
1804 prop = &ivilayer->pending.prop;
1805 prop->opacity = opacity;
1806
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001807 if (ivilayer->prop.opacity != opacity)
1808 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1809 else
1810 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001811
1812 return IVI_SUCCEEDED;
1813}
1814
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001815wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001816ivi_layout_layer_get_opacity(struct ivi_layout_layer *ivilayer)
1817{
1818 if (ivilayer == NULL) {
1819 weston_log("ivi_layout_layer_get_opacity: invalid argument\n");
1820 return wl_fixed_from_double(0.0);
1821 }
1822
1823 return ivilayer->prop.opacity;
1824}
1825
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001826static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001827ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1828 int32_t x, int32_t y,
1829 int32_t width, int32_t height)
1830{
1831 struct ivi_layout_layer_properties *prop = NULL;
1832
1833 if (ivilayer == NULL) {
1834 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1835 return IVI_FAILED;
1836 }
1837
1838 prop = &ivilayer->pending.prop;
1839 prop->source_x = x;
1840 prop->source_y = y;
1841 prop->source_width = width;
1842 prop->source_height = height;
1843
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001844 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1845 ivilayer->prop.source_width != width ||
1846 ivilayer->prop.source_height != height)
1847 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1848 else
1849 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001850
1851 return IVI_SUCCEEDED;
1852}
1853
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001854static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001855ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1856 int32_t x, int32_t y,
1857 int32_t width, int32_t height)
1858{
1859 struct ivi_layout_layer_properties *prop = NULL;
1860
1861 if (ivilayer == NULL) {
1862 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1863 return IVI_FAILED;
1864 }
1865
1866 prop = &ivilayer->pending.prop;
1867 prop->dest_x = x;
1868 prop->dest_y = y;
1869 prop->dest_width = width;
1870 prop->dest_height = height;
1871
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001872 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1873 ivilayer->prop.dest_width != width ||
1874 ivilayer->prop.dest_height != height)
1875 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1876 else
1877 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001878
1879 return IVI_SUCCEEDED;
1880}
1881
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001882static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001883ivi_layout_layer_get_dimension(struct ivi_layout_layer *ivilayer,
1884 int32_t *dest_width, int32_t *dest_height)
1885{
1886 if (ivilayer == NULL || dest_width == NULL || dest_height == NULL) {
1887 weston_log("ivi_layout_layer_get_dimension: invalid argument\n");
1888 return IVI_FAILED;
1889 }
1890
1891 *dest_width = ivilayer->prop.dest_width;
1892 *dest_height = ivilayer->prop.dest_height;
1893
1894 return IVI_SUCCEEDED;
1895}
1896
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001897static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001898ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
1899 int32_t dest_width, int32_t dest_height)
1900{
1901 struct ivi_layout_layer_properties *prop = NULL;
1902
1903 if (ivilayer == NULL) {
1904 weston_log("ivi_layout_layer_set_dimension: invalid argument\n");
1905 return IVI_FAILED;
1906 }
1907
1908 prop = &ivilayer->pending.prop;
1909
1910 prop->dest_width = dest_width;
1911 prop->dest_height = dest_height;
1912
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001913 if (ivilayer->prop.dest_width != dest_width ||
1914 ivilayer->prop.dest_height != dest_height)
1915 ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
1916 else
1917 ivilayer->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001918
1919 return IVI_SUCCEEDED;
1920}
1921
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001922int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001923ivi_layout_layer_get_position(struct ivi_layout_layer *ivilayer,
1924 int32_t *dest_x, int32_t *dest_y)
1925{
1926 if (ivilayer == NULL || dest_x == NULL || dest_y == NULL) {
1927 weston_log("ivi_layout_layer_get_position: invalid argument\n");
1928 return IVI_FAILED;
1929 }
1930
1931 *dest_x = ivilayer->prop.dest_x;
1932 *dest_y = ivilayer->prop.dest_y;
1933
1934 return IVI_SUCCEEDED;
1935}
1936
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001937int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001938ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
1939 int32_t dest_x, int32_t dest_y)
1940{
1941 struct ivi_layout_layer_properties *prop = NULL;
1942
1943 if (ivilayer == NULL) {
1944 weston_log("ivi_layout_layer_set_position: invalid argument\n");
1945 return IVI_FAILED;
1946 }
1947
1948 prop = &ivilayer->pending.prop;
1949 prop->dest_x = dest_x;
1950 prop->dest_y = dest_y;
1951
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001952 if (ivilayer->prop.dest_x != dest_x || ivilayer->prop.dest_y != dest_y)
1953 ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
1954 else
1955 ivilayer->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001956
1957 return IVI_SUCCEEDED;
1958}
1959
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001960static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001961ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1962 enum wl_output_transform orientation)
1963{
1964 struct ivi_layout_layer_properties *prop = NULL;
1965
1966 if (ivilayer == NULL) {
1967 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1968 return IVI_FAILED;
1969 }
1970
1971 prop = &ivilayer->pending.prop;
1972 prop->orientation = orientation;
1973
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001974 if (ivilayer->prop.orientation != orientation)
1975 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1976 else
1977 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001978
1979 return IVI_SUCCEEDED;
1980}
1981
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001982static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001983ivi_layout_layer_get_orientation(struct ivi_layout_layer *ivilayer)
1984{
1985 if (ivilayer == NULL) {
1986 weston_log("ivi_layout_layer_get_orientation: invalid argument\n");
1987 return 0;
1988 }
1989
1990 return ivilayer->prop.orientation;
1991}
1992
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001993int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001994ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1995 struct ivi_layout_surface **pSurface,
1996 int32_t number)
1997{
1998 struct ivi_layout *layout = get_instance();
1999 struct ivi_layout_surface *ivisurf = NULL;
2000 struct ivi_layout_surface *next = NULL;
2001 uint32_t *id_surface = NULL;
2002 int32_t i = 0;
2003
2004 if (ivilayer == NULL) {
2005 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
2006 return IVI_FAILED;
2007 }
2008
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00002009 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002010
2011 for (i = 0; i < number; i++) {
2012 id_surface = &pSurface[i]->id_surface;
2013
2014 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2015 if (*id_surface != ivisurf->id_surface) {
2016 continue;
2017 }
2018
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002019 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002020 wl_list_insert(&ivilayer->pending.surface_list,
2021 &ivisurf->pending.link);
2022 break;
2023 }
2024 }
2025
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002026 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002027
2028 return IVI_SUCCEEDED;
2029}
2030
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002031int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002032ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
2033 bool newVisibility)
2034{
2035 struct ivi_layout_surface_properties *prop = NULL;
2036
2037 if (ivisurf == NULL) {
2038 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
2039 return IVI_FAILED;
2040 }
2041
2042 prop = &ivisurf->pending.prop;
2043 prop->visibility = newVisibility;
2044
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002045 if (ivisurf->prop.visibility != newVisibility)
2046 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
2047 else
2048 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002049
2050 return IVI_SUCCEEDED;
2051}
2052
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002053bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002054ivi_layout_surface_get_visibility(struct ivi_layout_surface *ivisurf)
2055{
2056 if (ivisurf == NULL) {
2057 weston_log("ivi_layout_surface_get_visibility: invalid argument\n");
2058 return false;
2059 }
2060
2061 return ivisurf->prop.visibility;
2062}
2063
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002064int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002065ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
2066 wl_fixed_t opacity)
2067{
2068 struct ivi_layout_surface_properties *prop = NULL;
2069
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09002070 if (ivisurf == NULL ||
2071 opacity < wl_fixed_from_double(0.0) ||
2072 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002073 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
2074 return IVI_FAILED;
2075 }
2076
2077 prop = &ivisurf->pending.prop;
2078 prop->opacity = opacity;
2079
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002080 if (ivisurf->prop.opacity != opacity)
2081 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
2082 else
2083 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002084
2085 return IVI_SUCCEEDED;
2086}
2087
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002088wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002089ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
2090{
2091 if (ivisurf == NULL) {
2092 weston_log("ivi_layout_surface_get_opacity: invalid argument\n");
2093 return wl_fixed_from_double(0.0);
2094 }
2095
2096 return ivisurf->prop.opacity;
2097}
2098
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002099int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002100ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
2101 int32_t x, int32_t y,
2102 int32_t width, int32_t height)
2103{
2104 struct ivi_layout_surface_properties *prop = NULL;
2105
2106 if (ivisurf == NULL) {
2107 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
2108 return IVI_FAILED;
2109 }
2110
2111 prop = &ivisurf->pending.prop;
2112 prop->start_x = prop->dest_x;
2113 prop->start_y = prop->dest_y;
2114 prop->dest_x = x;
2115 prop->dest_y = y;
2116 prop->start_width = prop->dest_width;
2117 prop->start_height = prop->dest_height;
2118 prop->dest_width = width;
2119 prop->dest_height = height;
2120
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002121 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2122 ivisurf->prop.dest_width != width ||
2123 ivisurf->prop.dest_height != height)
2124 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2125 else
2126 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002127
2128 return IVI_SUCCEEDED;
2129}
2130
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002131static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002132ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
2133 int32_t dest_width, int32_t dest_height)
2134{
2135 struct ivi_layout_surface_properties *prop = NULL;
2136
2137 if (ivisurf == NULL) {
2138 weston_log("ivi_layout_surface_set_dimension: invalid argument\n");
2139 return IVI_FAILED;
2140 }
2141
2142 prop = &ivisurf->pending.prop;
2143 prop->dest_width = dest_width;
2144 prop->dest_height = dest_height;
2145
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002146 if (ivisurf->prop.dest_width != dest_width ||
2147 ivisurf->prop.dest_height != dest_height)
2148 ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
2149 else
2150 ivisurf->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002151
2152 return IVI_SUCCEEDED;
2153}
2154
2155int32_t
2156ivi_layout_surface_get_dimension(struct ivi_layout_surface *ivisurf,
2157 int32_t *dest_width, int32_t *dest_height)
2158{
2159 if (ivisurf == NULL || dest_width == NULL || dest_height == NULL) {
2160 weston_log("ivi_layout_surface_get_dimension: invalid argument\n");
2161 return IVI_FAILED;
2162 }
2163
2164 *dest_width = ivisurf->prop.dest_width;
2165 *dest_height = ivisurf->prop.dest_height;
2166
2167 return IVI_SUCCEEDED;
2168}
2169
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002170static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002171ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
2172 int32_t dest_x, int32_t dest_y)
2173{
2174 struct ivi_layout_surface_properties *prop = NULL;
2175
2176 if (ivisurf == NULL) {
2177 weston_log("ivi_layout_surface_set_position: invalid argument\n");
2178 return IVI_FAILED;
2179 }
2180
2181 prop = &ivisurf->pending.prop;
2182 prop->dest_x = dest_x;
2183 prop->dest_y = dest_y;
2184
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002185 if (ivisurf->prop.dest_x != dest_x || ivisurf->prop.dest_y != dest_y)
2186 ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
2187 else
2188 ivisurf->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002189
2190 return IVI_SUCCEEDED;
2191}
2192
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002193static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002194ivi_layout_surface_get_position(struct ivi_layout_surface *ivisurf,
2195 int32_t *dest_x, int32_t *dest_y)
2196{
2197 if (ivisurf == NULL || dest_x == NULL || dest_y == NULL) {
2198 weston_log("ivi_layout_surface_get_position: invalid argument\n");
2199 return IVI_FAILED;
2200 }
2201
2202 *dest_x = ivisurf->prop.dest_x;
2203 *dest_y = ivisurf->prop.dest_y;
2204
2205 return IVI_SUCCEEDED;
2206}
2207
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002208static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002209ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2210 enum wl_output_transform orientation)
2211{
2212 struct ivi_layout_surface_properties *prop = NULL;
2213
2214 if (ivisurf == NULL) {
2215 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2216 return IVI_FAILED;
2217 }
2218
2219 prop = &ivisurf->pending.prop;
2220 prop->orientation = orientation;
2221
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002222 if (ivisurf->prop.orientation != orientation)
2223 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2224 else
2225 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002226
2227 return IVI_SUCCEEDED;
2228}
2229
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002230static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002231ivi_layout_surface_get_orientation(struct ivi_layout_surface *ivisurf)
2232{
2233 if (ivisurf == NULL) {
2234 weston_log("ivi_layout_surface_get_orientation: invalid argument\n");
2235 return 0;
2236 }
2237
2238 return ivisurf->prop.orientation;
2239}
2240
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002241static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002242ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2243 struct ivi_layout_layer *addlayer)
2244{
2245 struct ivi_layout *layout = get_instance();
2246 struct ivi_layout_layer *ivilayer = NULL;
2247 struct ivi_layout_layer *next = NULL;
2248 int is_layer_in_scrn = 0;
2249
2250 if (iviscrn == NULL || addlayer == NULL) {
2251 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2252 return IVI_FAILED;
2253 }
2254
2255 is_layer_in_scrn = is_layer_in_screen(addlayer, iviscrn);
2256 if (is_layer_in_scrn == 1) {
2257 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2258 return IVI_SUCCEEDED;
2259 }
2260
2261 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2262 if (ivilayer->id_layer == addlayer->id_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002263 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002264 wl_list_insert(&iviscrn->pending.layer_list,
2265 &ivilayer->pending.link);
2266 break;
2267 }
2268 }
2269
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002270 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002271
2272 return IVI_SUCCEEDED;
2273}
2274
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002275static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002276ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2277 struct ivi_layout_layer **pLayer,
2278 const int32_t number)
2279{
2280 struct ivi_layout *layout = get_instance();
2281 struct ivi_layout_layer *ivilayer = NULL;
2282 struct ivi_layout_layer *next = NULL;
2283 uint32_t *id_layer = NULL;
2284 int32_t i = 0;
2285
2286 if (iviscrn == NULL) {
2287 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2288 return IVI_FAILED;
2289 }
2290
2291 wl_list_for_each_safe(ivilayer, next,
2292 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002293 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002294 wl_list_init(&ivilayer->pending.link);
2295 }
2296
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002297 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002298
2299 for (i = 0; i < number; i++) {
2300 id_layer = &pLayer[i]->id_layer;
2301 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2302 if (*id_layer != ivilayer->id_layer) {
2303 continue;
2304 }
2305
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002306 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002307 wl_list_insert(&iviscrn->pending.layer_list,
2308 &ivilayer->pending.link);
2309 break;
2310 }
2311 }
2312
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002313 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002314
2315 return IVI_SUCCEEDED;
2316}
2317
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002318static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002319ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2320{
2321 return iviscrn->output;
2322}
2323
2324/**
2325 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2326 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2327 * This function is used to get the result of drawing by clients.
2328 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002329static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002330ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2331{
2332 return ivisurf != NULL ? ivisurf->surface : NULL;
2333}
2334
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002335static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002336ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2337 int32_t *width, int32_t *height,
2338 int32_t *stride)
2339{
2340 int32_t w;
2341 int32_t h;
2342 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2343
2344 if (ivisurf == NULL || ivisurf->surface == NULL) {
2345 weston_log("%s: invalid argument\n", __func__);
2346 return IVI_FAILED;
2347 }
2348
2349 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2350
2351 if (width != NULL)
2352 *width = w;
2353
2354 if (height != NULL)
2355 *height = h;
2356
2357 if (stride != NULL)
2358 *stride = w * bytespp;
2359
2360 return IVI_SUCCEEDED;
2361}
2362
2363static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002364ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2365 layer_property_notification_func callback,
2366 void *userdata)
2367{
2368 struct ivi_layout_notification_callback *prop_callback = NULL;
2369
2370 if (ivilayer == NULL || callback == NULL) {
2371 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2372 return IVI_FAILED;
2373 }
2374
2375 prop_callback = malloc(sizeof *prop_callback);
2376 if (prop_callback == NULL) {
2377 weston_log("fails to allocate memory\n");
2378 return IVI_FAILED;
2379 }
2380
2381 prop_callback->callback = callback;
2382 prop_callback->data = userdata;
2383
2384 return add_notification(&ivilayer->property_changed,
2385 layer_prop_changed,
2386 prop_callback);
2387}
2388
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002389static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002390ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2391{
2392 if (ivisurf == NULL) {
2393 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2394 return NULL;
2395 }
2396
2397 return &ivisurf->prop;
2398}
2399
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002400static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002401ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2402 struct ivi_layout_surface *addsurf)
2403{
2404 struct ivi_layout *layout = get_instance();
2405 struct ivi_layout_surface *ivisurf = NULL;
2406 struct ivi_layout_surface *next = NULL;
2407 int is_surf_in_layer = 0;
2408
2409 if (ivilayer == NULL || addsurf == NULL) {
2410 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2411 return IVI_FAILED;
2412 }
2413
2414 is_surf_in_layer = is_surface_in_layer(addsurf, ivilayer);
2415 if (is_surf_in_layer == 1) {
2416 weston_log("ivi_layout_layer_add_surface: addsurf is already available\n");
2417 return IVI_SUCCEEDED;
2418 }
2419
2420 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2421 if (ivisurf->id_surface == addsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002422 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002423 wl_list_insert(&ivilayer->pending.surface_list,
2424 &ivisurf->pending.link);
2425 break;
2426 }
2427 }
2428
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002429 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002430
2431 return IVI_SUCCEEDED;
2432}
2433
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002434static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002435ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2436 struct ivi_layout_surface *remsurf)
2437{
2438 struct ivi_layout_surface *ivisurf = NULL;
2439 struct ivi_layout_surface *next = NULL;
2440
2441 if (ivilayer == NULL || remsurf == NULL) {
2442 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2443 return;
2444 }
2445
2446 wl_list_for_each_safe(ivisurf, next,
2447 &ivilayer->pending.surface_list, pending.link) {
2448 if (ivisurf->id_surface == remsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002449 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002450 wl_list_init(&ivisurf->pending.link);
2451 break;
2452 }
2453 }
2454
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002455 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002456}
2457
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002458static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002459ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2460 int32_t x, int32_t y,
2461 int32_t width, int32_t height)
2462{
2463 struct ivi_layout_surface_properties *prop = NULL;
2464
2465 if (ivisurf == NULL) {
2466 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2467 return IVI_FAILED;
2468 }
2469
2470 prop = &ivisurf->pending.prop;
2471 prop->source_x = x;
2472 prop->source_y = y;
2473 prop->source_width = width;
2474 prop->source_height = height;
2475
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002476 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2477 ivisurf->prop.source_width != width ||
2478 ivisurf->prop.source_height != height)
2479 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2480 else
2481 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002482
2483 return IVI_SUCCEEDED;
2484}
2485
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002486int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002487ivi_layout_commit_changes(void)
2488{
2489 struct ivi_layout *layout = get_instance();
2490
2491 commit_surface_list(layout);
2492 commit_layer_list(layout);
2493 commit_screen_list(layout);
2494
2495 commit_transition(layout);
2496
2497 commit_changes(layout);
2498 send_prop(layout);
2499 weston_compositor_schedule_repaint(layout->compositor);
2500
2501 return IVI_SUCCEEDED;
2502}
2503
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002504static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002505ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2506 enum ivi_layout_transition_type type,
2507 uint32_t duration)
2508{
2509 if (ivilayer == NULL) {
2510 weston_log("%s: invalid argument\n", __func__);
2511 return -1;
2512 }
2513
2514 ivilayer->pending.prop.transition_type = type;
2515 ivilayer->pending.prop.transition_duration = duration;
2516
2517 return 0;
2518}
2519
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002520static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002521ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2522 uint32_t is_fade_in,
2523 double start_alpha, double end_alpha)
2524{
2525 if (ivilayer == NULL) {
2526 weston_log("%s: invalid argument\n", __func__);
2527 return -1;
2528 }
2529
2530 ivilayer->pending.prop.is_fade_in = is_fade_in;
2531 ivilayer->pending.prop.start_alpha = start_alpha;
2532 ivilayer->pending.prop.end_alpha = end_alpha;
2533
2534 return 0;
2535}
2536
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002537static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002538ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2539 uint32_t duration)
2540{
2541 struct ivi_layout_surface_properties *prop;
2542
2543 if (ivisurf == NULL) {
2544 weston_log("%s: invalid argument\n", __func__);
2545 return -1;
2546 }
2547
2548 prop = &ivisurf->pending.prop;
2549 prop->transition_duration = duration*10;
2550 return 0;
2551}
2552
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002553static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002554ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2555 enum ivi_layout_transition_type type,
2556 uint32_t duration)
2557{
2558 struct ivi_layout_surface_properties *prop;
2559
2560 if (ivisurf == NULL) {
2561 weston_log("%s: invalid argument\n", __func__);
2562 return -1;
2563 }
2564
2565 prop = &ivisurf->pending.prop;
2566 prop->transition_type = type;
2567 prop->transition_duration = duration;
2568 return 0;
2569}
2570
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002571static int32_t
2572ivi_layout_surface_dump(struct weston_surface *surface,
2573 void *target, size_t size,int32_t x, int32_t y,
2574 int32_t width, int32_t height)
2575{
2576 int result = 0;
2577
2578 if (surface == NULL) {
2579 weston_log("%s: invalid argument\n", __func__);
2580 return IVI_FAILED;
2581 }
2582
2583 result = weston_surface_copy_content(
2584 surface, target, size,
2585 x, y, width, height);
2586
2587 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2588}
2589
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002590/**
2591 * methods of interaction between ivi-shell with ivi-layout
2592 */
2593struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002594ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2595{
2596 struct weston_view *tmpview = NULL;
2597
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002598 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002599 return NULL;
2600
2601 wl_list_for_each(tmpview, &surface->surface->views, surface_link)
2602 {
2603 if (tmpview != NULL) {
2604 break;
2605 }
2606 }
2607 return tmpview;
2608}
2609
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002610void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002611ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2612 int32_t width, int32_t height)
2613{
2614 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002615
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002616 /* emit callback which is set by ivi-layout api user */
2617 wl_signal_emit(&layout->surface_notification.configure_changed,
2618 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002619}
2620
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002621static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002622ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2623 ivi_controller_surface_content_callback callback,
2624 void* userdata)
2625{
2626 int32_t ret = IVI_FAILED;
2627
2628 if (ivisurf != NULL) {
2629 ivisurf->content_observer.callback = callback;
2630 ivisurf->content_observer.userdata = userdata;
2631 ret = IVI_SUCCEEDED;
2632 }
2633 return ret;
2634}
2635
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002636struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002637ivi_layout_surface_create(struct weston_surface *wl_surface,
2638 uint32_t id_surface)
2639{
2640 struct ivi_layout *layout = get_instance();
2641 struct ivi_layout_surface *ivisurf = NULL;
2642 struct weston_view *tmpview = NULL;
2643
2644 if (wl_surface == NULL) {
2645 weston_log("ivi_layout_surface_create: invalid argument\n");
2646 return NULL;
2647 }
2648
2649 ivisurf = get_surface(&layout->surface_list, id_surface);
2650 if (ivisurf != NULL) {
2651 if (ivisurf->surface != NULL) {
2652 weston_log("id_surface(%d) is already created\n", id_surface);
2653 return NULL;
2654 }
2655 }
2656
2657 ivisurf = calloc(1, sizeof *ivisurf);
2658 if (ivisurf == NULL) {
2659 weston_log("fails to allocate memory\n");
2660 return NULL;
2661 }
2662
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002663 wl_signal_init(&ivisurf->property_changed);
2664 wl_signal_init(&ivisurf->configured);
2665 wl_list_init(&ivisurf->layer_list);
2666 ivisurf->id_surface = id_surface;
2667 ivisurf->layout = layout;
2668
2669 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002670
2671 tmpview = weston_view_create(wl_surface);
2672 if (tmpview == NULL) {
2673 weston_log("fails to allocate memory\n");
2674 }
2675
2676 ivisurf->surface->width_from_buffer = 0;
2677 ivisurf->surface->height_from_buffer = 0;
2678
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002679 weston_matrix_init(&ivisurf->transform.matrix);
2680 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002681
2682 init_surface_properties(&ivisurf->prop);
2683 ivisurf->event_mask = 0;
2684
2685 ivisurf->pending.prop = ivisurf->prop;
2686 wl_list_init(&ivisurf->pending.link);
2687
2688 wl_list_init(&ivisurf->order.link);
2689 wl_list_init(&ivisurf->order.layer_list);
2690
2691 wl_list_insert(&layout->surface_list, &ivisurf->link);
2692
2693 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2694
2695 return ivisurf;
2696}
2697
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002698void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002699ivi_layout_init_with_compositor(struct weston_compositor *ec)
2700{
2701 struct ivi_layout *layout = get_instance();
2702
2703 layout->compositor = ec;
2704
2705 wl_list_init(&layout->surface_list);
2706 wl_list_init(&layout->layer_list);
2707 wl_list_init(&layout->screen_list);
2708
2709 wl_signal_init(&layout->layer_notification.created);
2710 wl_signal_init(&layout->layer_notification.removed);
2711
2712 wl_signal_init(&layout->surface_notification.created);
2713 wl_signal_init(&layout->surface_notification.removed);
2714 wl_signal_init(&layout->surface_notification.configure_changed);
2715
2716 /* Add layout_layer at the last of weston_compositor.layer_list */
2717 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2718
2719 create_screen(ec);
2720
2721 layout->transitions = ivi_layout_transition_set_create(ec);
2722 wl_list_init(&layout->pending_transition_list);
2723}
2724
2725
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002726void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002727ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2728 struct wl_listener* listener)
2729{
2730 wl_signal_add(&ivisurf->configured, listener);
2731}
2732
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002733static struct ivi_controller_interface ivi_controller_interface = {
2734 /**
2735 * commit all changes
2736 */
2737 .commit_changes = ivi_layout_commit_changes,
2738
2739 /**
2740 * surface controller interfaces
2741 */
2742 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2743 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2744 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2745 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2746 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2747 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2748 .get_surfaces = ivi_layout_get_surfaces,
2749 .get_id_of_surface = ivi_layout_get_id_of_surface,
2750 .get_surface_from_id = ivi_layout_get_surface_from_id,
2751 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2752 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2753 .surface_set_visibility = ivi_layout_surface_set_visibility,
2754 .surface_get_visibility = ivi_layout_surface_get_visibility,
2755 .surface_set_opacity = ivi_layout_surface_set_opacity,
2756 .surface_get_opacity = ivi_layout_surface_get_opacity,
2757 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2758 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
2759 .surface_set_position = ivi_layout_surface_set_position,
2760 .surface_get_position = ivi_layout_surface_get_position,
2761 .surface_set_dimension = ivi_layout_surface_set_dimension,
2762 .surface_get_dimension = ivi_layout_surface_get_dimension,
2763 .surface_set_orientation = ivi_layout_surface_set_orientation,
2764 .surface_get_orientation = ivi_layout_surface_get_orientation,
2765 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2766 .surface_add_notification = ivi_layout_surface_add_notification,
2767 .surface_remove_notification = ivi_layout_surface_remove_notification,
2768 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2769 .surface_set_transition = ivi_layout_surface_set_transition,
2770 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2771
2772 /**
2773 * layer controller interfaces
2774 */
2775 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2776 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2777 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2778 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2779 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002780 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002781 .get_layers = ivi_layout_get_layers,
2782 .get_id_of_layer = ivi_layout_get_id_of_layer,
2783 .get_layer_from_id = ivi_layout_get_layer_from_id,
2784 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2785 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2786 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2787 .layer_set_visibility = ivi_layout_layer_set_visibility,
2788 .layer_get_visibility = ivi_layout_layer_get_visibility,
2789 .layer_set_opacity = ivi_layout_layer_set_opacity,
2790 .layer_get_opacity = ivi_layout_layer_get_opacity,
2791 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2792 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
2793 .layer_set_position = ivi_layout_layer_set_position,
2794 .layer_get_position = ivi_layout_layer_get_position,
2795 .layer_set_dimension = ivi_layout_layer_set_dimension,
2796 .layer_get_dimension = ivi_layout_layer_get_dimension,
2797 .layer_set_orientation = ivi_layout_layer_set_orientation,
2798 .layer_get_orientation = ivi_layout_layer_get_orientation,
2799 .layer_add_surface = ivi_layout_layer_add_surface,
2800 .layer_remove_surface = ivi_layout_layer_remove_surface,
2801 .layer_set_render_order = ivi_layout_layer_set_render_order,
2802 .layer_add_notification = ivi_layout_layer_add_notification,
2803 .layer_remove_notification = ivi_layout_layer_remove_notification,
2804 .layer_set_transition = ivi_layout_layer_set_transition,
2805
2806 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002807 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002808 */
2809 .get_screen_from_id = ivi_layout_get_screen_from_id,
2810 .get_screen_resolution = ivi_layout_get_screen_resolution,
2811 .get_screens = ivi_layout_get_screens,
2812 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2813 .screen_add_layer = ivi_layout_screen_add_layer,
2814 .screen_set_render_order = ivi_layout_screen_set_render_order,
2815 .screen_get_output = ivi_layout_screen_get_output,
2816
2817 /**
2818 * animation
2819 */
2820 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002821 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2822
2823 /**
2824 * surface content dumping for debugging
2825 */
2826 .surface_get_size = ivi_layout_surface_get_size,
2827 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002828
2829 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002830 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002831 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002832 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002833 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2834
2835 /**
2836 * screen controller interfaces part2
2837 */
2838 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002839};
2840
2841int
2842load_controller_modules(struct weston_compositor *compositor, const char *modules,
2843 int *argc, char *argv[])
2844{
2845 const char *p, *end;
2846 char buffer[256];
2847 int (*controller_module_init)(struct weston_compositor *compositor,
2848 int *argc, char *argv[],
2849 const struct ivi_controller_interface *interface,
2850 size_t interface_version);
2851
2852 if (modules == NULL)
2853 return 0;
2854
2855 p = modules;
2856 while (*p) {
2857 end = strchrnul(p, ',');
2858 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2859
2860 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002861 if (!controller_module_init)
2862 return -1;
2863
2864 if (controller_module_init(compositor, argc, argv,
2865 &ivi_controller_interface,
2866 sizeof(struct ivi_controller_interface)) != 0) {
2867 weston_log("ivi-shell: Initialization of controller module fails");
2868 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002869 }
2870
2871 p = end;
2872 while (*p == ',')
2873 p++;
2874 }
2875
2876 return 0;
2877}