blob: 061f15636bda74f89c459a72d64054245434ca49 [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 Tanibataacbcc6c2015-08-24 10:24:15 +090070#define max(a, b) ((a) > (b) ? (a) : (b))
71
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090072struct link_layer {
73 struct ivi_layout_layer *ivilayer;
74 struct wl_list link;
75 struct wl_list link_to_layer;
76};
77
78struct link_screen {
79 struct ivi_layout_screen *iviscrn;
80 struct wl_list link;
81 struct wl_list link_to_screen;
82};
83
84struct listener_layout_notification {
85 void *userdata;
86 struct wl_listener listener;
87};
88
89struct ivi_layout;
90
91struct ivi_layout_screen {
92 struct wl_list link;
93 struct wl_list link_to_layer;
94 uint32_t id_screen;
95
96 struct ivi_layout *layout;
97 struct weston_output *output;
98
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090099 struct {
100 struct wl_list layer_list;
101 struct wl_list link;
102 } pending;
103
104 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000105 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900106 struct wl_list layer_list;
107 struct wl_list link;
108 } order;
109};
110
111struct ivi_layout_notification_callback {
112 void *callback;
113 void *data;
114};
115
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900116struct ivi_rectangle
117{
118 int32_t x;
119 int32_t y;
120 int32_t width;
121 int32_t height;
122};
123
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900124static void
125remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
126
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900127static struct ivi_layout ivilayout = {0};
128
129struct ivi_layout *
130get_instance(void)
131{
132 return &ivilayout;
133}
134
135/**
136 * Internal API to add/remove a link to ivi_surface from ivi_layer.
137 */
138static void
139add_link_to_surface(struct ivi_layout_layer *ivilayer,
140 struct link_layer *link_layer)
141{
142 struct link_layer *link = NULL;
143
144 wl_list_for_each(link, &ivilayer->link_to_surface, link_to_layer) {
145 if (link == link_layer)
146 return;
147 }
148
149 wl_list_insert(&ivilayer->link_to_surface, &link_layer->link_to_layer);
150}
151
152static void
153remove_link_to_surface(struct ivi_layout_layer *ivilayer)
154{
155 struct link_layer *link = NULL;
156 struct link_layer *next = NULL;
157
158 wl_list_for_each_safe(link, next, &ivilayer->link_to_surface, link_to_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000159 wl_list_remove(&link->link_to_layer);
160 wl_list_remove(&link->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900161 free(link);
162 }
163
164 wl_list_init(&ivilayer->link_to_surface);
165}
166
167/**
168 * Internal API to add a link to ivi_layer from ivi_screen.
169 */
170static void
171add_link_to_layer(struct ivi_layout_screen *iviscrn,
172 struct link_screen *link_screen)
173{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900174 wl_list_insert(&iviscrn->link_to_layer, &link_screen->link_to_screen);
175}
176
177/**
178 * Internal API to add/remove a ivi_surface from ivi_layer.
179 */
180static void
181add_ordersurface_to_layer(struct ivi_layout_surface *ivisurf,
182 struct ivi_layout_layer *ivilayer)
183{
184 struct link_layer *link_layer = NULL;
185
186 link_layer = malloc(sizeof *link_layer);
187 if (link_layer == NULL) {
188 weston_log("fails to allocate memory\n");
189 return;
190 }
191
192 link_layer->ivilayer = ivilayer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900193 wl_list_insert(&ivisurf->layer_list, &link_layer->link);
194 add_link_to_surface(ivilayer, link_layer);
195}
196
197static void
198remove_ordersurface_from_layer(struct ivi_layout_surface *ivisurf)
199{
200 struct link_layer *link_layer = NULL;
201 struct link_layer *next = NULL;
202
203 wl_list_for_each_safe(link_layer, next, &ivisurf->layer_list, link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000204 wl_list_remove(&link_layer->link);
205 wl_list_remove(&link_layer->link_to_layer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900206 free(link_layer);
207 }
208 wl_list_init(&ivisurf->layer_list);
209}
210
211/**
212 * Internal API to add/remove a ivi_layer to/from ivi_screen.
213 */
214static void
215add_orderlayer_to_screen(struct ivi_layout_layer *ivilayer,
216 struct ivi_layout_screen *iviscrn)
217{
218 struct link_screen *link_scrn = NULL;
219
220 link_scrn = malloc(sizeof *link_scrn);
221 if (link_scrn == NULL) {
222 weston_log("fails to allocate memory\n");
223 return;
224 }
225
226 link_scrn->iviscrn = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900227 wl_list_insert(&ivilayer->screen_list, &link_scrn->link);
228 add_link_to_layer(iviscrn, link_scrn);
229}
230
231static void
232remove_orderlayer_from_screen(struct ivi_layout_layer *ivilayer)
233{
234 struct link_screen *link_scrn = NULL;
235 struct link_screen *next = NULL;
236
237 wl_list_for_each_safe(link_scrn, next, &ivilayer->screen_list, link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000238 wl_list_remove(&link_scrn->link);
239 wl_list_remove(&link_scrn->link_to_screen);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900240 free(link_scrn);
241 }
242 wl_list_init(&ivilayer->screen_list);
243}
244
245/**
246 * Internal API to add/remove a ivi_layer to/from ivi_screen.
247 */
248static struct ivi_layout_surface *
249get_surface(struct wl_list *surf_list, uint32_t id_surface)
250{
251 struct ivi_layout_surface *ivisurf;
252
253 wl_list_for_each(ivisurf, surf_list, link) {
254 if (ivisurf->id_surface == id_surface) {
255 return ivisurf;
256 }
257 }
258
259 return NULL;
260}
261
262static struct ivi_layout_layer *
263get_layer(struct wl_list *layer_list, uint32_t id_layer)
264{
265 struct ivi_layout_layer *ivilayer;
266
267 wl_list_for_each(ivilayer, layer_list, link) {
268 if (ivilayer->id_layer == id_layer) {
269 return ivilayer;
270 }
271 }
272
273 return NULL;
274}
275
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900276static void
277remove_configured_listener(struct ivi_layout_surface *ivisurf)
278{
279 struct wl_listener *link = NULL;
280 struct wl_listener *next = NULL;
281
282 wl_list_for_each_safe(link, next, &ivisurf->configured.listener_list, link) {
283 wl_list_remove(&link->link);
284 }
285}
286
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900287static void
288remove_all_notification(struct wl_list *listener_list)
289{
290 struct wl_listener *listener = NULL;
291 struct wl_listener *next = NULL;
292
293 wl_list_for_each_safe(listener, next, listener_list, link) {
294 struct listener_layout_notification *notification = NULL;
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000295 wl_list_remove(&listener->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900296
297 notification =
298 container_of(listener,
299 struct listener_layout_notification,
300 listener);
301
302 free(notification->userdata);
303 free(notification);
304 }
305}
306
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900307static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900308ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
309{
310 if (ivisurf == NULL) {
311 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
312 return;
313 }
314
315 remove_all_notification(&ivisurf->property_changed.listener_list);
316}
317
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900318static void
319ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
320 surface_property_notification_func callback,
321 void *userdata)
322{
323 if (ivisurf == NULL) {
324 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
325 return;
326 }
327
328 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
329}
330
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900331/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900332 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900333 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900334void
335ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900336{
337 struct ivi_layout *layout = get_instance();
338
339 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900340 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900341 return;
342 }
343
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900344 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900345 wl_list_remove(&ivisurf->pending.link);
346 wl_list_remove(&ivisurf->order.link);
347 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900348 remove_ordersurface_from_layer(ivisurf);
349
350 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
351
352 remove_configured_listener(ivisurf);
353
354 ivi_layout_surface_remove_notification(ivisurf);
355
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900356 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900357}
358
359/**
360 * Internal API to check ivi_layer/ivi_surface already added in ivi_layer/ivi_screen.
361 * Called by ivi_layout_layer_add_surface/ivi_layout_screenAddLayer
362 */
363static int
364is_surface_in_layer(struct ivi_layout_surface *ivisurf,
365 struct ivi_layout_layer *ivilayer)
366{
367 struct ivi_layout_surface *surf = NULL;
368
369 wl_list_for_each(surf, &ivilayer->pending.surface_list, pending.link) {
370 if (surf->id_surface == ivisurf->id_surface) {
371 return 1;
372 }
373 }
374
375 return 0;
376}
377
378static int
379is_layer_in_screen(struct ivi_layout_layer *ivilayer,
380 struct ivi_layout_screen *iviscrn)
381{
382 struct ivi_layout_layer *layer = NULL;
383
384 wl_list_for_each(layer, &iviscrn->pending.layer_list, pending.link) {
385 if (layer->id_layer == ivilayer->id_layer) {
386 return 1;
387 }
388 }
389
390 return 0;
391}
392
393/**
394 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
395 * Called by ivi_layout_init_with_compositor.
396 */
397static void
398create_screen(struct weston_compositor *ec)
399{
400 struct ivi_layout *layout = get_instance();
401 struct ivi_layout_screen *iviscrn = NULL;
402 struct weston_output *output = NULL;
403 int32_t count = 0;
404
405 wl_list_for_each(output, &ec->output_list, link) {
406 iviscrn = calloc(1, sizeof *iviscrn);
407 if (iviscrn == NULL) {
408 weston_log("fails to allocate memory\n");
409 continue;
410 }
411
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900412 iviscrn->layout = layout;
413
414 iviscrn->id_screen = count;
415 count++;
416
417 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900418
419 wl_list_init(&iviscrn->pending.layer_list);
420 wl_list_init(&iviscrn->pending.link);
421
422 wl_list_init(&iviscrn->order.layer_list);
423 wl_list_init(&iviscrn->order.link);
424
425 wl_list_init(&iviscrn->link_to_layer);
426
427 wl_list_insert(&layout->screen_list, &iviscrn->link);
428 }
429}
430
431/**
432 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
433 */
434static void
435init_layer_properties(struct ivi_layout_layer_properties *prop,
436 int32_t width, int32_t height)
437{
438 memset(prop, 0, sizeof *prop);
439 prop->opacity = wl_fixed_from_double(1.0);
440 prop->source_width = width;
441 prop->source_height = height;
442 prop->dest_width = width;
443 prop->dest_height = height;
444}
445
446static void
447init_surface_properties(struct ivi_layout_surface_properties *prop)
448{
449 memset(prop, 0, sizeof *prop);
450 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900451 /*
452 * FIXME: this shall be finxed by ivi-layout-transition.
453 */
454 prop->dest_width = 1;
455 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900456}
457
458/**
459 * Internal APIs to be called from ivi_layout_commit_changes.
460 */
461static void
462update_opacity(struct ivi_layout_layer *ivilayer,
463 struct ivi_layout_surface *ivisurf)
464{
465 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
466 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
467
468 if ((ivilayer->event_mask & IVI_NOTIFICATION_OPACITY) ||
469 (ivisurf->event_mask & IVI_NOTIFICATION_OPACITY)) {
470 struct weston_view *tmpview = NULL;
471 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
472 if (tmpview == NULL) {
473 continue;
474 }
475 tmpview->alpha = layer_alpha * surf_alpha;
476 }
477 }
478}
479
480static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900481get_rotate_values(enum wl_output_transform orientation,
482 float *v_sin,
483 float *v_cos)
484{
485 switch (orientation) {
486 case WL_OUTPUT_TRANSFORM_90:
487 *v_sin = 1.0f;
488 *v_cos = 0.0f;
489 break;
490 case WL_OUTPUT_TRANSFORM_180:
491 *v_sin = 0.0f;
492 *v_cos = -1.0f;
493 break;
494 case WL_OUTPUT_TRANSFORM_270:
495 *v_sin = -1.0f;
496 *v_cos = 0.0f;
497 break;
498 case WL_OUTPUT_TRANSFORM_NORMAL:
499 default:
500 *v_sin = 0.0f;
501 *v_cos = 1.0f;
502 break;
503 }
504}
505
506static void
507get_scale(enum wl_output_transform orientation,
508 float dest_width,
509 float dest_height,
510 float source_width,
511 float source_height,
512 float *scale_x,
513 float *scale_y)
514{
515 switch (orientation) {
516 case WL_OUTPUT_TRANSFORM_90:
517 *scale_x = dest_width / source_height;
518 *scale_y = dest_height / source_width;
519 break;
520 case WL_OUTPUT_TRANSFORM_180:
521 *scale_x = dest_width / source_width;
522 *scale_y = dest_height / source_height;
523 break;
524 case WL_OUTPUT_TRANSFORM_270:
525 *scale_x = dest_width / source_height;
526 *scale_y = dest_height / source_width;
527 break;
528 case WL_OUTPUT_TRANSFORM_NORMAL:
529 default:
530 *scale_x = dest_width / source_width;
531 *scale_y = dest_height / source_height;
532 break;
533 }
534}
535
536static void
537calc_transformation_matrix(struct ivi_rectangle *source_rect,
538 struct ivi_rectangle *dest_rect,
539 enum wl_output_transform orientation,
540 struct weston_matrix *m)
541{
542 float source_center_x;
543 float source_center_y;
544 float vsin;
545 float vcos;
546 float scale_x;
547 float scale_y;
548 float translate_x;
549 float translate_y;
550
551 source_center_x = source_rect->x + source_rect->width * 0.5f;
552 source_center_y = source_rect->y + source_rect->height * 0.5f;
553 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
554
555 get_rotate_values(orientation, &vsin, &vcos);
556 weston_matrix_rotate_xy(m, vcos, vsin);
557
558 get_scale(orientation,
559 dest_rect->width,
560 dest_rect->height,
561 source_rect->width,
562 source_rect->height,
563 &scale_x,
564 &scale_y);
565 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
566
567 translate_x = dest_rect->width * 0.5f + dest_rect->x;
568 translate_y = dest_rect->height * 0.5f + dest_rect->y;
569 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
570}
571
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900572/*
573 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900574 */
575static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900576ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
577 const struct ivi_rectangle *rect2,
578 struct ivi_rectangle *rect_output)
579{
580 int32_t rect1_right = rect1->x + rect1->width;
581 int32_t rect1_bottom = rect1->y + rect1->height;
582 int32_t rect2_right = rect2->x + rect2->width;
583 int32_t rect2_bottom = rect2->y + rect2->height;
584
585 rect_output->x = max(rect1->x, rect2->x);
586 rect_output->y = max(rect1->y, rect2->y);
587 rect_output->width = rect1_right < rect2_right ?
588 rect1_right - rect_output->x :
589 rect2_right - rect_output->x;
590 rect_output->height = rect1_bottom < rect2_bottom ?
591 rect1_bottom - rect_output->y :
592 rect2_bottom - rect_output->y;
593
594 if (rect_output->width < 0 || rect_output->height < 0) {
595 rect_output->width = 0;
596 rect_output->height = 0;
597 }
598}
599
600/*
601 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
602 * and store the result in rect_output.
603 * The boundingbox must be given in the same coordinate space as rect_output.
604 * Additionally, there are the following restrictions on the matrix:
605 * - no projective transformations
606 * - no skew
607 * - only multiples of 90-degree rotations supported
608 *
609 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
610 * as a fail-safe with log.
611 */
612static void
613calc_inverse_matrix_transform(const struct weston_matrix *matrix,
614 const struct ivi_rectangle *rect_input,
615 const struct ivi_rectangle *boundingbox,
616 struct ivi_rectangle *rect_output)
617{
618 struct weston_matrix m;
619 struct weston_vector top_left;
620 struct weston_vector bottom_right;
621
622 assert(boundingbox != rect_output);
623
624 if (weston_matrix_invert(&m, matrix) < 0) {
625 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
626 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
627 rect_output->x = boundingbox->x;
628 rect_output->y = boundingbox->y;
629 rect_output->width = boundingbox->width;
630 rect_output->height = boundingbox->height;
631 }
632
633 /* The vectors and matrices involved will always produce f[3] == 1.0. */
634 top_left.f[0] = rect_input->x;
635 top_left.f[1] = rect_input->y;
636 top_left.f[2] = 0.0f;
637 top_left.f[3] = 1.0f;
638
639 bottom_right.f[0] = rect_input->x + rect_input->width;
640 bottom_right.f[1] = rect_input->y + rect_input->height;
641 bottom_right.f[2] = 0.0f;
642 bottom_right.f[3] = 1.0f;
643
644 weston_matrix_transform(&m, &top_left);
645 weston_matrix_transform(&m, &bottom_right);
646
647 if (top_left.f[0] < bottom_right.f[0]) {
648 rect_output->x = top_left.f[0];
649 rect_output->width = bottom_right.f[0] - rect_output->x;
650 } else {
651 rect_output->x = bottom_right.f[0];
652 rect_output->width = top_left.f[0] - rect_output->x;
653 }
654
655 if (top_left.f[1] < bottom_right.f[1]) {
656 rect_output->y = top_left.f[1];
657 rect_output->height = bottom_right.f[1] - rect_output->y;
658 } else {
659 rect_output->y = bottom_right.f[1];
660 rect_output->height = top_left.f[1] - rect_output->y;
661 }
662
663 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
664}
665
666/**
667 * This computes the whole transformation matrix:m from surface-local
668 * coordinates to global coordinates. It is assumed that
669 * weston_view::geometry.{x,y} are zero.
670 *
671 * Additionally, this computes the mask on surface-local coordinates as a
672 * ivi_rectangle. This can be set to weston_view_set_mask.
673 *
674 * The mask is computed by following steps
675 * - destination rectangle of layer is inversed to surface-local cooodinates
676 * by inversed matrix:m.
677 * - the area is intersected by intersected area between weston_surface and
678 * source rectangle of ivi_surface.
679 */
680static void
681calc_surface_to_global_matrix_and_mask_to_weston_surface(
682 struct ivi_layout_layer *ivilayer,
683 struct ivi_layout_surface *ivisurf,
684 struct weston_matrix *m,
685 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900686{
687 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
688 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900689 struct ivi_rectangle weston_surface_rect = { 0,
690 0,
691 ivisurf->surface->width,
692 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900693 struct ivi_rectangle surface_source_rect = { sp->source_x,
694 sp->source_y,
695 sp->source_width,
696 sp->source_height };
697 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
698 sp->dest_y,
699 sp->dest_width,
700 sp->dest_height };
701 struct ivi_rectangle layer_source_rect = { lp->source_x,
702 lp->source_y,
703 lp->source_width,
704 lp->source_height };
705 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
706 lp->dest_y,
707 lp->dest_width,
708 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900709 struct ivi_rectangle surface_result;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900710
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900711 /*
712 * the whole transformation matrix:m from surface-local
713 * coordinates to global coordinates, which is computed by
714 * two steps,
715 * - surface-local coordinates to layer-local coordinates
716 * - layer-local coordinates to global coordinates
717 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900718 calc_transformation_matrix(&surface_source_rect,
719 &surface_dest_rect,
720 sp->orientation, m);
721
722 calc_transformation_matrix(&layer_source_rect,
723 &layer_dest_rect,
724 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900725
726 /* this intersected ivi_rectangle would be used for masking
727 * weston_surface
728 */
729 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
730 &surface_result);
731
732 /* calc masking area of weston_surface from m */
733 calc_inverse_matrix_transform(m,
734 &layer_dest_rect,
735 &surface_result,
736 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900737}
738
739static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900740update_prop(struct ivi_layout_layer *ivilayer,
741 struct ivi_layout_surface *ivisurf)
742{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900743 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900744 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900745 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900746
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900747 if (!ivilayer->event_mask && !ivisurf->event_mask) {
748 return;
749 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900750
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900751 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900752
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900753 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900754 if (tmpview != NULL) {
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900755 break;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900756 }
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900757 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900758
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900759 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
760 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
761 can_calc = false;
762 }
763
764 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
765 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
766 can_calc = false;
767 }
768
769 if (can_calc) {
770 wl_list_remove(&ivisurf->transform.link);
771 weston_matrix_init(&ivisurf->transform.matrix);
772
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900773 calc_surface_to_global_matrix_and_mask_to_weston_surface(
774 ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900775
776 if (tmpview != NULL) {
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900777 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
778 wl_list_insert(&tmpview->geometry.transformation_list,
779 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900780
781 weston_view_set_transform_parent(tmpview, NULL);
782 }
783 }
784
785 ivisurf->update_count++;
786
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900787 if (tmpview != NULL) {
788 weston_view_geometry_dirty(tmpview);
789 }
790
791 if (ivisurf->surface != NULL) {
792 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900793 }
794}
795
796static void
797commit_changes(struct ivi_layout *layout)
798{
799 struct ivi_layout_screen *iviscrn = NULL;
800 struct ivi_layout_layer *ivilayer = NULL;
801 struct ivi_layout_surface *ivisurf = NULL;
802
803 wl_list_for_each(iviscrn, &layout->screen_list, link) {
804 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
805 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
806 update_prop(ivilayer, ivisurf);
807 }
808 }
809 }
810}
811
812static void
813commit_surface_list(struct ivi_layout *layout)
814{
815 struct ivi_layout_surface *ivisurf = NULL;
816 int32_t dest_x = 0;
817 int32_t dest_y = 0;
818 int32_t dest_width = 0;
819 int32_t dest_height = 0;
820 int32_t configured = 0;
821
822 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300823 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900824 dest_x = ivisurf->prop.dest_x;
825 dest_y = ivisurf->prop.dest_y;
826 dest_width = ivisurf->prop.dest_width;
827 dest_height = ivisurf->prop.dest_height;
828
829 ivi_layout_transition_move_resize_view(ivisurf,
830 ivisurf->pending.prop.dest_x,
831 ivisurf->pending.prop.dest_y,
832 ivisurf->pending.prop.dest_width,
833 ivisurf->pending.prop.dest_height,
834 ivisurf->pending.prop.transition_duration);
835
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300836 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900837 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
838 } else {
839 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
840 }
841
842 ivisurf->prop = ivisurf->pending.prop;
843 ivisurf->prop.dest_x = dest_x;
844 ivisurf->prop.dest_y = dest_y;
845 ivisurf->prop.dest_width = dest_width;
846 ivisurf->prop.dest_height = dest_height;
847 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
848 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
849
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300850 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900851 dest_x = ivisurf->prop.dest_x;
852 dest_y = ivisurf->prop.dest_y;
853 dest_width = ivisurf->prop.dest_width;
854 dest_height = ivisurf->prop.dest_height;
855
856 ivi_layout_transition_move_resize_view(ivisurf,
857 ivisurf->pending.prop.dest_x,
858 ivisurf->pending.prop.dest_y,
859 ivisurf->pending.prop.dest_width,
860 ivisurf->pending.prop.dest_height,
861 ivisurf->pending.prop.transition_duration);
862
863 ivisurf->prop = ivisurf->pending.prop;
864 ivisurf->prop.dest_x = dest_x;
865 ivisurf->prop.dest_y = dest_y;
866 ivisurf->prop.dest_width = dest_width;
867 ivisurf->prop.dest_height = dest_height;
868
869 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
870 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
871
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300872 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900873 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300874 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900875 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
876 } else {
877 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
878 }
879
880 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
881 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
882 configured = 1;
883 }
884
885 ivisurf->prop = ivisurf->pending.prop;
886 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
887 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
888
889 if (configured && !is_surface_transition(ivisurf))
890 wl_signal_emit(&ivisurf->configured, ivisurf);
891 } else {
892 configured = 0;
893 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
894 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
895 configured = 1;
896 }
897
898 ivisurf->prop = ivisurf->pending.prop;
899 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
900 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
901
902 if (configured && !is_surface_transition(ivisurf))
903 wl_signal_emit(&ivisurf->configured, ivisurf);
904 }
905 }
906}
907
908static void
909commit_layer_list(struct ivi_layout *layout)
910{
911 struct ivi_layout_layer *ivilayer = NULL;
912 struct ivi_layout_surface *ivisurf = NULL;
913 struct ivi_layout_surface *next = NULL;
914
915 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300916 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900917 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 -0300918 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900919 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
920 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
921 NULL, NULL,
922 ivilayer->pending.prop.transition_duration);
923 }
924 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
925
926 ivilayer->prop = ivilayer->pending.prop;
927
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000928 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900929 continue;
930 }
931
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000932 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
933 order.link) {
934 remove_ordersurface_from_layer(ivisurf);
935 wl_list_remove(&ivisurf->order.link);
936 wl_list_init(&ivisurf->order.link);
937 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900938 }
939
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000940 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900941
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000942 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900943 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000944 wl_list_remove(&ivisurf->order.link);
945 wl_list_insert(&ivilayer->order.surface_list,
946 &ivisurf->order.link);
947 add_ordersurface_to_layer(ivisurf, ivilayer);
948 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900949 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000950
951 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900952 }
953}
954
955static void
956commit_screen_list(struct ivi_layout *layout)
957{
958 struct ivi_layout_screen *iviscrn = NULL;
959 struct ivi_layout_layer *ivilayer = NULL;
960 struct ivi_layout_layer *next = NULL;
961 struct ivi_layout_surface *ivisurf = NULL;
962
963 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000964 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900965 wl_list_for_each_safe(ivilayer, next,
966 &iviscrn->order.layer_list, order.link) {
967 remove_orderlayer_from_screen(ivilayer);
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000968 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900969 wl_list_init(&ivilayer->order.link);
970 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
971 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900972
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000973 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900974
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900975 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
976 pending.link) {
977 wl_list_insert(&iviscrn->order.layer_list,
978 &ivilayer->order.link);
979 add_orderlayer_to_screen(ivilayer, iviscrn);
980 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
981 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900982
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000983 iviscrn->order.dirty = 0;
984 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900985
986 /* Clear view list of layout ivi_layer */
987 wl_list_init(&layout->layout_layer.view_list.link);
988
989 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
990 if (ivilayer->prop.visibility == false)
991 continue;
992
993 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
994 struct weston_view *tmpview = NULL;
995 wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
996 if (tmpview != NULL) {
997 break;
998 }
999 }
1000
1001 if (ivisurf->prop.visibility == false)
1002 continue;
1003 if (ivisurf->surface == NULL || tmpview == NULL)
1004 continue;
1005
1006 weston_layer_entry_insert(&layout->layout_layer.view_list,
1007 &tmpview->layer_link);
1008
1009 ivisurf->surface->output = iviscrn->output;
1010 }
1011 }
1012
1013 break;
1014 }
1015}
1016
1017static void
1018commit_transition(struct ivi_layout* layout)
1019{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001020 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001021 return;
1022 }
1023
1024 wl_list_insert_list(&layout->transitions->transition_list,
1025 &layout->pending_transition_list);
1026
1027 wl_list_init(&layout->pending_transition_list);
1028
1029 wl_event_source_timer_update(layout->transitions->event_source, 1);
1030}
1031
1032static void
1033send_surface_prop(struct ivi_layout_surface *ivisurf)
1034{
1035 wl_signal_emit(&ivisurf->property_changed, ivisurf);
1036 ivisurf->event_mask = 0;
1037}
1038
1039static void
1040send_layer_prop(struct ivi_layout_layer *ivilayer)
1041{
1042 wl_signal_emit(&ivilayer->property_changed, ivilayer);
1043 ivilayer->event_mask = 0;
1044}
1045
1046static void
1047send_prop(struct ivi_layout *layout)
1048{
1049 struct ivi_layout_layer *ivilayer = NULL;
1050 struct ivi_layout_surface *ivisurf = NULL;
1051
1052 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +09001053 if (ivilayer->event_mask)
1054 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001055 }
1056
1057 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +09001058 if (ivisurf->event_mask)
1059 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001060 }
1061}
1062
1063static void
1064clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
1065{
1066 struct ivi_layout_surface *surface_link = NULL;
1067 struct ivi_layout_surface *surface_next = NULL;
1068
1069 wl_list_for_each_safe(surface_link, surface_next,
1070 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001071 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001072 wl_list_init(&surface_link->pending.link);
1073 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001074}
1075
1076static void
1077clear_surface_order_list(struct ivi_layout_layer *ivilayer)
1078{
1079 struct ivi_layout_surface *surface_link = NULL;
1080 struct ivi_layout_surface *surface_next = NULL;
1081
1082 wl_list_for_each_safe(surface_link, surface_next,
1083 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001084 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001085 wl_list_init(&surface_link->order.link);
1086 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001087}
1088
1089static void
1090layer_created(struct wl_listener *listener, void *data)
1091{
1092 struct ivi_layout_layer *ivilayer = data;
1093
1094 struct listener_layout_notification *notification =
1095 container_of(listener,
1096 struct listener_layout_notification,
1097 listener);
1098
1099 struct ivi_layout_notification_callback *created_callback =
1100 notification->userdata;
1101
1102 ((layer_create_notification_func)created_callback->callback)
1103 (ivilayer, created_callback->data);
1104}
1105
1106static void
1107layer_removed(struct wl_listener *listener, void *data)
1108{
1109 struct ivi_layout_layer *ivilayer = data;
1110
1111 struct listener_layout_notification *notification =
1112 container_of(listener,
1113 struct listener_layout_notification,
1114 listener);
1115
1116 struct ivi_layout_notification_callback *removed_callback =
1117 notification->userdata;
1118
1119 ((layer_remove_notification_func)removed_callback->callback)
1120 (ivilayer, removed_callback->data);
1121}
1122
1123static void
1124layer_prop_changed(struct wl_listener *listener, void *data)
1125{
1126 struct ivi_layout_layer *ivilayer = data;
1127
1128 struct listener_layout_notification *layout_listener =
1129 container_of(listener,
1130 struct listener_layout_notification,
1131 listener);
1132
1133 struct ivi_layout_notification_callback *prop_callback =
1134 layout_listener->userdata;
1135
1136 ((layer_property_notification_func)prop_callback->callback)
1137 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1138}
1139
1140static void
1141surface_created(struct wl_listener *listener, void *data)
1142{
1143 struct ivi_layout_surface *ivisurface = data;
1144
1145 struct listener_layout_notification *notification =
1146 container_of(listener,
1147 struct listener_layout_notification,
1148 listener);
1149
1150 struct ivi_layout_notification_callback *created_callback =
1151 notification->userdata;
1152
1153 ((surface_create_notification_func)created_callback->callback)
1154 (ivisurface, created_callback->data);
1155}
1156
1157static void
1158surface_removed(struct wl_listener *listener, void *data)
1159{
1160 struct ivi_layout_surface *ivisurface = data;
1161
1162 struct listener_layout_notification *notification =
1163 container_of(listener,
1164 struct listener_layout_notification,
1165 listener);
1166
1167 struct ivi_layout_notification_callback *removed_callback =
1168 notification->userdata;
1169
1170 ((surface_remove_notification_func)removed_callback->callback)
1171 (ivisurface, removed_callback->data);
1172}
1173
1174static void
1175surface_prop_changed(struct wl_listener *listener, void *data)
1176{
1177 struct ivi_layout_surface *ivisurf = data;
1178
1179 struct listener_layout_notification *layout_listener =
1180 container_of(listener,
1181 struct listener_layout_notification,
1182 listener);
1183
1184 struct ivi_layout_notification_callback *prop_callback =
1185 layout_listener->userdata;
1186
1187 ((surface_property_notification_func)prop_callback->callback)
1188 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1189
1190 ivisurf->event_mask = 0;
1191}
1192
1193static void
1194surface_configure_changed(struct wl_listener *listener,
1195 void *data)
1196{
1197 struct ivi_layout_surface *ivisurface = data;
1198
1199 struct listener_layout_notification *notification =
1200 container_of(listener,
1201 struct listener_layout_notification,
1202 listener);
1203
1204 struct ivi_layout_notification_callback *configure_changed_callback =
1205 notification->userdata;
1206
1207 ((surface_configure_notification_func)configure_changed_callback->callback)
1208 (ivisurface, configure_changed_callback->data);
1209}
1210
1211static int32_t
1212add_notification(struct wl_signal *signal,
1213 wl_notify_func_t callback,
1214 void *userdata)
1215{
1216 struct listener_layout_notification *notification = NULL;
1217
1218 notification = malloc(sizeof *notification);
1219 if (notification == NULL) {
1220 weston_log("fails to allocate memory\n");
1221 free(userdata);
1222 return IVI_FAILED;
1223 }
1224
1225 notification->listener.notify = callback;
1226 notification->userdata = userdata;
1227
1228 wl_signal_add(signal, &notification->listener);
1229
1230 return IVI_SUCCEEDED;
1231}
1232
1233static void
1234remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1235{
1236 struct wl_listener *listener = NULL;
1237 struct wl_listener *next = NULL;
1238
1239 wl_list_for_each_safe(listener, next, listener_list, link) {
1240 struct listener_layout_notification *notification =
1241 container_of(listener,
1242 struct listener_layout_notification,
1243 listener);
1244
1245 struct ivi_layout_notification_callback *notification_callback =
1246 notification->userdata;
1247
1248 if ((notification_callback->callback != callback) ||
1249 (notification_callback->data != userdata)) {
1250 continue;
1251 }
1252
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001253 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001254
1255 free(notification->userdata);
1256 free(notification);
1257 }
1258}
1259
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001260/**
1261 * Exported APIs of ivi-layout library are implemented from here.
1262 * Brief of APIs is described in ivi-layout-export.h.
1263 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001264static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001265ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1266 void *userdata)
1267{
1268 struct ivi_layout *layout = get_instance();
1269 struct ivi_layout_notification_callback *created_callback = NULL;
1270
1271 if (callback == NULL) {
1272 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1273 return IVI_FAILED;
1274 }
1275
1276 created_callback = malloc(sizeof *created_callback);
1277 if (created_callback == NULL) {
1278 weston_log("fails to allocate memory\n");
1279 return IVI_FAILED;
1280 }
1281
1282 created_callback->callback = callback;
1283 created_callback->data = userdata;
1284
1285 return add_notification(&layout->layer_notification.created,
1286 layer_created,
1287 created_callback);
1288}
1289
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001290static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001291ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1292 void *userdata)
1293{
1294 struct ivi_layout *layout = get_instance();
1295 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1296}
1297
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001298static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001299ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1300 void *userdata)
1301{
1302 struct ivi_layout *layout = get_instance();
1303 struct ivi_layout_notification_callback *removed_callback = NULL;
1304
1305 if (callback == NULL) {
1306 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1307 return IVI_FAILED;
1308 }
1309
1310 removed_callback = malloc(sizeof *removed_callback);
1311 if (removed_callback == NULL) {
1312 weston_log("fails to allocate memory\n");
1313 return IVI_FAILED;
1314 }
1315
1316 removed_callback->callback = callback;
1317 removed_callback->data = userdata;
1318 return add_notification(&layout->layer_notification.removed,
1319 layer_removed,
1320 removed_callback);
1321}
1322
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001323static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001324ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1325 void *userdata)
1326{
1327 struct ivi_layout *layout = get_instance();
1328 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1329}
1330
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001331static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001332ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1333 void *userdata)
1334{
1335 struct ivi_layout *layout = get_instance();
1336 struct ivi_layout_notification_callback *created_callback = NULL;
1337
1338 if (callback == NULL) {
1339 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1340 return IVI_FAILED;
1341 }
1342
1343 created_callback = malloc(sizeof *created_callback);
1344 if (created_callback == NULL) {
1345 weston_log("fails to allocate memory\n");
1346 return IVI_FAILED;
1347 }
1348
1349 created_callback->callback = callback;
1350 created_callback->data = userdata;
1351
1352 return add_notification(&layout->surface_notification.created,
1353 surface_created,
1354 created_callback);
1355}
1356
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001357static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001358ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1359 void *userdata)
1360{
1361 struct ivi_layout *layout = get_instance();
1362 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1363}
1364
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001365static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001366ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1367 void *userdata)
1368{
1369 struct ivi_layout *layout = get_instance();
1370 struct ivi_layout_notification_callback *removed_callback = NULL;
1371
1372 if (callback == NULL) {
1373 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1374 return IVI_FAILED;
1375 }
1376
1377 removed_callback = malloc(sizeof *removed_callback);
1378 if (removed_callback == NULL) {
1379 weston_log("fails to allocate memory\n");
1380 return IVI_FAILED;
1381 }
1382
1383 removed_callback->callback = callback;
1384 removed_callback->data = userdata;
1385
1386 return add_notification(&layout->surface_notification.removed,
1387 surface_removed,
1388 removed_callback);
1389}
1390
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001391static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001392ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1393 void *userdata)
1394{
1395 struct ivi_layout *layout = get_instance();
1396 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1397}
1398
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001399static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001400ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1401 void *userdata)
1402{
1403 struct ivi_layout *layout = get_instance();
1404 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1405 if (callback == NULL) {
1406 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1407 return IVI_FAILED;
1408 }
1409
1410 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1411 if (configure_changed_callback == NULL) {
1412 weston_log("fails to allocate memory\n");
1413 return IVI_FAILED;
1414 }
1415
1416 configure_changed_callback->callback = callback;
1417 configure_changed_callback->data = userdata;
1418
1419 return add_notification(&layout->surface_notification.configure_changed,
1420 surface_configure_changed,
1421 configure_changed_callback);
1422}
1423
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001424static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001425ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1426 void *userdata)
1427{
1428 struct ivi_layout *layout = get_instance();
1429 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1430}
1431
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001432uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001433ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1434{
1435 return ivisurf->id_surface;
1436}
1437
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001438static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001439ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1440{
1441 return ivilayer->id_layer;
1442}
1443
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001444static uint32_t
1445ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1446{
1447 return iviscrn->id_screen;
1448}
1449
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001450static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001451ivi_layout_get_layer_from_id(uint32_t id_layer)
1452{
1453 struct ivi_layout *layout = get_instance();
1454 struct ivi_layout_layer *ivilayer = NULL;
1455
1456 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1457 if (ivilayer->id_layer == id_layer) {
1458 return ivilayer;
1459 }
1460 }
1461
1462 return NULL;
1463}
1464
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001465struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001466ivi_layout_get_surface_from_id(uint32_t id_surface)
1467{
1468 struct ivi_layout *layout = get_instance();
1469 struct ivi_layout_surface *ivisurf = NULL;
1470
1471 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1472 if (ivisurf->id_surface == id_surface) {
1473 return ivisurf;
1474 }
1475 }
1476
1477 return NULL;
1478}
1479
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001480static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001481ivi_layout_get_screen_from_id(uint32_t id_screen)
1482{
1483 struct ivi_layout *layout = get_instance();
1484 struct ivi_layout_screen *iviscrn = NULL;
1485
1486 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1487/* FIXME : select iviscrn from screen_list by id_screen */
1488 return iviscrn;
1489 break;
1490 }
1491
1492 return NULL;
1493}
1494
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001495static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001496ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1497 int32_t *pWidth, int32_t *pHeight)
1498{
1499 struct weston_output *output = NULL;
1500
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001501 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001502 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1503 return IVI_FAILED;
1504 }
1505
1506 output = iviscrn->output;
1507 *pWidth = output->current_mode->width;
1508 *pHeight = output->current_mode->height;
1509
1510 return IVI_SUCCEEDED;
1511}
1512
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001513static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001514ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1515 surface_property_notification_func callback,
1516 void *userdata)
1517{
1518 struct listener_layout_notification* notification = NULL;
1519 struct ivi_layout_notification_callback *prop_callback = NULL;
1520
1521 if (ivisurf == NULL || callback == NULL) {
1522 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1523 return IVI_FAILED;
1524 }
1525
1526 notification = malloc(sizeof *notification);
1527 if (notification == NULL) {
1528 weston_log("fails to allocate memory\n");
1529 return IVI_FAILED;
1530 }
1531
1532 prop_callback = malloc(sizeof *prop_callback);
1533 if (prop_callback == NULL) {
1534 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001535 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001536 return IVI_FAILED;
1537 }
1538
1539 prop_callback->callback = callback;
1540 prop_callback->data = userdata;
1541
1542 notification->listener.notify = surface_prop_changed;
1543 notification->userdata = prop_callback;
1544
1545 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1546
1547 return IVI_SUCCEEDED;
1548}
1549
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001550static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001551ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1552{
1553 if (ivilayer == NULL) {
1554 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1555 return NULL;
1556 }
1557
1558 return &ivilayer->prop;
1559}
1560
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001561static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001562ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1563{
1564 struct ivi_layout *layout = get_instance();
1565 struct ivi_layout_screen *iviscrn = NULL;
1566 int32_t length = 0;
1567 int32_t n = 0;
1568
1569 if (pLength == NULL || ppArray == NULL) {
1570 weston_log("ivi_layout_get_screens: invalid argument\n");
1571 return IVI_FAILED;
1572 }
1573
1574 length = wl_list_length(&layout->screen_list);
1575
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001576 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001577 /* the Array must be free by module which called this function */
1578 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1579 if (*ppArray == NULL) {
1580 weston_log("fails to allocate memory\n");
1581 return IVI_FAILED;
1582 }
1583
1584 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1585 (*ppArray)[n++] = iviscrn;
1586 }
1587 }
1588
1589 *pLength = length;
1590
1591 return IVI_SUCCEEDED;
1592}
1593
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001594static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001595ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1596 int32_t *pLength,
1597 struct ivi_layout_screen ***ppArray)
1598{
1599 struct link_screen *link_scrn = NULL;
1600 int32_t length = 0;
1601 int32_t n = 0;
1602
1603 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1604 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1605 return IVI_FAILED;
1606 }
1607
1608 length = wl_list_length(&ivilayer->screen_list);
1609
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001610 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001611 /* the Array must be free by module which called this function */
1612 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1613 if (*ppArray == NULL) {
1614 weston_log("fails to allocate memory\n");
1615 return IVI_FAILED;
1616 }
1617
1618 wl_list_for_each(link_scrn, &ivilayer->screen_list, link) {
1619 (*ppArray)[n++] = link_scrn->iviscrn;
1620 }
1621 }
1622
1623 *pLength = length;
1624
1625 return IVI_SUCCEEDED;
1626}
1627
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001628static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001629ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1630{
1631 struct ivi_layout *layout = get_instance();
1632 struct ivi_layout_layer *ivilayer = NULL;
1633 int32_t length = 0;
1634 int32_t n = 0;
1635
1636 if (pLength == NULL || ppArray == NULL) {
1637 weston_log("ivi_layout_get_layers: invalid argument\n");
1638 return IVI_FAILED;
1639 }
1640
1641 length = wl_list_length(&layout->layer_list);
1642
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001643 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001644 /* the Array must be free by module which called this function */
1645 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1646 if (*ppArray == NULL) {
1647 weston_log("fails to allocate memory\n");
1648 return IVI_FAILED;
1649 }
1650
1651 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1652 (*ppArray)[n++] = ivilayer;
1653 }
1654 }
1655
1656 *pLength = length;
1657
1658 return IVI_SUCCEEDED;
1659}
1660
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001661static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001662ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1663 int32_t *pLength,
1664 struct ivi_layout_layer ***ppArray)
1665{
1666 struct ivi_layout_layer *ivilayer = NULL;
1667 int32_t length = 0;
1668 int32_t n = 0;
1669
1670 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1671 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1672 return IVI_FAILED;
1673 }
1674
1675 length = wl_list_length(&iviscrn->order.layer_list);
1676
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001677 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001678 /* the Array must be free by module which called this function */
1679 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1680 if (*ppArray == NULL) {
1681 weston_log("fails to allocate memory\n");
1682 return IVI_FAILED;
1683 }
1684
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001685 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001686 (*ppArray)[n++] = ivilayer;
1687 }
1688 }
1689
1690 *pLength = length;
1691
1692 return IVI_SUCCEEDED;
1693}
1694
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001695static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001696ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1697 int32_t *pLength,
1698 struct ivi_layout_layer ***ppArray)
1699{
1700 struct link_layer *link_layer = NULL;
1701 int32_t length = 0;
1702 int32_t n = 0;
1703
1704 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1705 weston_log("ivi_layout_getLayers: invalid argument\n");
1706 return IVI_FAILED;
1707 }
1708
1709 length = wl_list_length(&ivisurf->layer_list);
1710
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001711 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001712 /* the Array must be free by module which called this function */
1713 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1714 if (*ppArray == NULL) {
1715 weston_log("fails to allocate memory\n");
1716 return IVI_FAILED;
1717 }
1718
1719 wl_list_for_each(link_layer, &ivisurf->layer_list, link) {
1720 (*ppArray)[n++] = link_layer->ivilayer;
1721 }
1722 }
1723
1724 *pLength = length;
1725
1726 return IVI_SUCCEEDED;
1727}
1728
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001729static
1730int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001731ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1732{
1733 struct ivi_layout *layout = get_instance();
1734 struct ivi_layout_surface *ivisurf = NULL;
1735 int32_t length = 0;
1736 int32_t n = 0;
1737
1738 if (pLength == NULL || ppArray == NULL) {
1739 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1740 return IVI_FAILED;
1741 }
1742
1743 length = wl_list_length(&layout->surface_list);
1744
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001745 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001746 /* the Array must be free by module which called this function */
1747 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1748 if (*ppArray == NULL) {
1749 weston_log("fails to allocate memory\n");
1750 return IVI_FAILED;
1751 }
1752
1753 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1754 (*ppArray)[n++] = ivisurf;
1755 }
1756 }
1757
1758 *pLength = length;
1759
1760 return IVI_SUCCEEDED;
1761}
1762
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001763static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001764ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1765 int32_t *pLength,
1766 struct ivi_layout_surface ***ppArray)
1767{
1768 struct ivi_layout_surface *ivisurf = NULL;
1769 int32_t length = 0;
1770 int32_t n = 0;
1771
1772 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1773 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1774 return IVI_FAILED;
1775 }
1776
1777 length = wl_list_length(&ivilayer->order.surface_list);
1778
1779 if (length != 0) {
1780 /* the Array must be free by module which called this function */
1781 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1782 if (*ppArray == NULL) {
1783 weston_log("fails to allocate memory\n");
1784 return IVI_FAILED;
1785 }
1786
1787 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1788 (*ppArray)[n++] = ivisurf;
1789 }
1790 }
1791
1792 *pLength = length;
1793
1794 return IVI_SUCCEEDED;
1795}
1796
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001797static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001798ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1799 int32_t width, int32_t height)
1800{
1801 struct ivi_layout *layout = get_instance();
1802 struct ivi_layout_layer *ivilayer = NULL;
1803
1804 ivilayer = get_layer(&layout->layer_list, id_layer);
1805 if (ivilayer != NULL) {
1806 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001807 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001808 return ivilayer;
1809 }
1810
1811 ivilayer = calloc(1, sizeof *ivilayer);
1812 if (ivilayer == NULL) {
1813 weston_log("fails to allocate memory\n");
1814 return NULL;
1815 }
1816
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001817 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001818 wl_signal_init(&ivilayer->property_changed);
1819 wl_list_init(&ivilayer->screen_list);
1820 wl_list_init(&ivilayer->link_to_surface);
1821 ivilayer->layout = layout;
1822 ivilayer->id_layer = id_layer;
1823
1824 init_layer_properties(&ivilayer->prop, width, height);
1825 ivilayer->event_mask = 0;
1826
1827 wl_list_init(&ivilayer->pending.surface_list);
1828 wl_list_init(&ivilayer->pending.link);
1829 ivilayer->pending.prop = ivilayer->prop;
1830
1831 wl_list_init(&ivilayer->order.surface_list);
1832 wl_list_init(&ivilayer->order.link);
1833
1834 wl_list_insert(&layout->layer_list, &ivilayer->link);
1835
1836 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1837
1838 return ivilayer;
1839}
1840
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001841static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001842ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1843{
1844 if (ivilayer == NULL) {
1845 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1846 return;
1847 }
1848
1849 remove_all_notification(&ivilayer->property_changed.listener_list);
1850}
1851
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001852static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001853ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1854 layer_property_notification_func callback,
1855 void *userdata)
1856{
1857 if (ivilayer == NULL) {
1858 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1859 return;
1860 }
1861
1862 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1863}
1864
1865static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001866ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001867{
1868 struct ivi_layout *layout = get_instance();
1869
1870 if (ivilayer == NULL) {
1871 weston_log("ivi_layout_layer_remove: invalid argument\n");
1872 return;
1873 }
1874
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001875 if (--ivilayer->ref_count > 0)
1876 return;
1877
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001878 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1879
1880 clear_surface_pending_list(ivilayer);
1881 clear_surface_order_list(ivilayer);
1882
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001883 wl_list_remove(&ivilayer->pending.link);
1884 wl_list_remove(&ivilayer->order.link);
1885 wl_list_remove(&ivilayer->link);
1886
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001887 remove_orderlayer_from_screen(ivilayer);
1888 remove_link_to_surface(ivilayer);
1889 ivi_layout_layer_remove_notification(ivilayer);
1890
1891 free(ivilayer);
1892}
1893
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001894int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001895ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1896 bool newVisibility)
1897{
1898 struct ivi_layout_layer_properties *prop = NULL;
1899
1900 if (ivilayer == NULL) {
1901 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1902 return IVI_FAILED;
1903 }
1904
1905 prop = &ivilayer->pending.prop;
1906 prop->visibility = newVisibility;
1907
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001908 if (ivilayer->prop.visibility != newVisibility)
1909 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1910 else
1911 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001912
1913 return IVI_SUCCEEDED;
1914}
1915
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001916static bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001917ivi_layout_layer_get_visibility(struct ivi_layout_layer *ivilayer)
1918{
1919 if (ivilayer == NULL) {
1920 weston_log("ivi_layout_layer_get_visibility: invalid argument\n");
1921 return false;
1922 }
1923
1924 return ivilayer->prop.visibility;
1925}
1926
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001927int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001928ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1929 wl_fixed_t opacity)
1930{
1931 struct ivi_layout_layer_properties *prop = NULL;
1932
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001933 if (ivilayer == NULL ||
1934 opacity < wl_fixed_from_double(0.0) ||
1935 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001936 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1937 return IVI_FAILED;
1938 }
1939
1940 prop = &ivilayer->pending.prop;
1941 prop->opacity = opacity;
1942
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001943 if (ivilayer->prop.opacity != opacity)
1944 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1945 else
1946 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001947
1948 return IVI_SUCCEEDED;
1949}
1950
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001951wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001952ivi_layout_layer_get_opacity(struct ivi_layout_layer *ivilayer)
1953{
1954 if (ivilayer == NULL) {
1955 weston_log("ivi_layout_layer_get_opacity: invalid argument\n");
1956 return wl_fixed_from_double(0.0);
1957 }
1958
1959 return ivilayer->prop.opacity;
1960}
1961
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001962static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001963ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1964 int32_t x, int32_t y,
1965 int32_t width, int32_t height)
1966{
1967 struct ivi_layout_layer_properties *prop = NULL;
1968
1969 if (ivilayer == NULL) {
1970 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1971 return IVI_FAILED;
1972 }
1973
1974 prop = &ivilayer->pending.prop;
1975 prop->source_x = x;
1976 prop->source_y = y;
1977 prop->source_width = width;
1978 prop->source_height = height;
1979
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001980 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1981 ivilayer->prop.source_width != width ||
1982 ivilayer->prop.source_height != height)
1983 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1984 else
1985 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001986
1987 return IVI_SUCCEEDED;
1988}
1989
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001990static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001991ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1992 int32_t x, int32_t y,
1993 int32_t width, int32_t height)
1994{
1995 struct ivi_layout_layer_properties *prop = NULL;
1996
1997 if (ivilayer == NULL) {
1998 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1999 return IVI_FAILED;
2000 }
2001
2002 prop = &ivilayer->pending.prop;
2003 prop->dest_x = x;
2004 prop->dest_y = y;
2005 prop->dest_width = width;
2006 prop->dest_height = height;
2007
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002008 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
2009 ivilayer->prop.dest_width != width ||
2010 ivilayer->prop.dest_height != height)
2011 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2012 else
2013 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002014
2015 return IVI_SUCCEEDED;
2016}
2017
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002018static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002019ivi_layout_layer_get_dimension(struct ivi_layout_layer *ivilayer,
2020 int32_t *dest_width, int32_t *dest_height)
2021{
2022 if (ivilayer == NULL || dest_width == NULL || dest_height == NULL) {
2023 weston_log("ivi_layout_layer_get_dimension: invalid argument\n");
2024 return IVI_FAILED;
2025 }
2026
2027 *dest_width = ivilayer->prop.dest_width;
2028 *dest_height = ivilayer->prop.dest_height;
2029
2030 return IVI_SUCCEEDED;
2031}
2032
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002033static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002034ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
2035 int32_t dest_width, int32_t dest_height)
2036{
2037 struct ivi_layout_layer_properties *prop = NULL;
2038
2039 if (ivilayer == NULL) {
2040 weston_log("ivi_layout_layer_set_dimension: invalid argument\n");
2041 return IVI_FAILED;
2042 }
2043
2044 prop = &ivilayer->pending.prop;
2045
2046 prop->dest_width = dest_width;
2047 prop->dest_height = dest_height;
2048
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002049 if (ivilayer->prop.dest_width != dest_width ||
2050 ivilayer->prop.dest_height != dest_height)
2051 ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
2052 else
2053 ivilayer->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002054
2055 return IVI_SUCCEEDED;
2056}
2057
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002058int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002059ivi_layout_layer_get_position(struct ivi_layout_layer *ivilayer,
2060 int32_t *dest_x, int32_t *dest_y)
2061{
2062 if (ivilayer == NULL || dest_x == NULL || dest_y == NULL) {
2063 weston_log("ivi_layout_layer_get_position: invalid argument\n");
2064 return IVI_FAILED;
2065 }
2066
2067 *dest_x = ivilayer->prop.dest_x;
2068 *dest_y = ivilayer->prop.dest_y;
2069
2070 return IVI_SUCCEEDED;
2071}
2072
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002073int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002074ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
2075 int32_t dest_x, int32_t dest_y)
2076{
2077 struct ivi_layout_layer_properties *prop = NULL;
2078
2079 if (ivilayer == NULL) {
2080 weston_log("ivi_layout_layer_set_position: invalid argument\n");
2081 return IVI_FAILED;
2082 }
2083
2084 prop = &ivilayer->pending.prop;
2085 prop->dest_x = dest_x;
2086 prop->dest_y = dest_y;
2087
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002088 if (ivilayer->prop.dest_x != dest_x || ivilayer->prop.dest_y != dest_y)
2089 ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
2090 else
2091 ivilayer->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002092
2093 return IVI_SUCCEEDED;
2094}
2095
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002096static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002097ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
2098 enum wl_output_transform orientation)
2099{
2100 struct ivi_layout_layer_properties *prop = NULL;
2101
2102 if (ivilayer == NULL) {
2103 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
2104 return IVI_FAILED;
2105 }
2106
2107 prop = &ivilayer->pending.prop;
2108 prop->orientation = orientation;
2109
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002110 if (ivilayer->prop.orientation != orientation)
2111 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2112 else
2113 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002114
2115 return IVI_SUCCEEDED;
2116}
2117
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002118static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002119ivi_layout_layer_get_orientation(struct ivi_layout_layer *ivilayer)
2120{
2121 if (ivilayer == NULL) {
2122 weston_log("ivi_layout_layer_get_orientation: invalid argument\n");
2123 return 0;
2124 }
2125
2126 return ivilayer->prop.orientation;
2127}
2128
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002129int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002130ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
2131 struct ivi_layout_surface **pSurface,
2132 int32_t number)
2133{
2134 struct ivi_layout *layout = get_instance();
2135 struct ivi_layout_surface *ivisurf = NULL;
2136 struct ivi_layout_surface *next = NULL;
2137 uint32_t *id_surface = NULL;
2138 int32_t i = 0;
2139
2140 if (ivilayer == NULL) {
2141 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
2142 return IVI_FAILED;
2143 }
2144
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00002145 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002146
2147 for (i = 0; i < number; i++) {
2148 id_surface = &pSurface[i]->id_surface;
2149
2150 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2151 if (*id_surface != ivisurf->id_surface) {
2152 continue;
2153 }
2154
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002155 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002156 wl_list_insert(&ivilayer->pending.surface_list,
2157 &ivisurf->pending.link);
2158 break;
2159 }
2160 }
2161
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002162 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002163
2164 return IVI_SUCCEEDED;
2165}
2166
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002167int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002168ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
2169 bool newVisibility)
2170{
2171 struct ivi_layout_surface_properties *prop = NULL;
2172
2173 if (ivisurf == NULL) {
2174 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
2175 return IVI_FAILED;
2176 }
2177
2178 prop = &ivisurf->pending.prop;
2179 prop->visibility = newVisibility;
2180
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002181 if (ivisurf->prop.visibility != newVisibility)
2182 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
2183 else
2184 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002185
2186 return IVI_SUCCEEDED;
2187}
2188
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002189bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002190ivi_layout_surface_get_visibility(struct ivi_layout_surface *ivisurf)
2191{
2192 if (ivisurf == NULL) {
2193 weston_log("ivi_layout_surface_get_visibility: invalid argument\n");
2194 return false;
2195 }
2196
2197 return ivisurf->prop.visibility;
2198}
2199
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002200int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002201ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
2202 wl_fixed_t opacity)
2203{
2204 struct ivi_layout_surface_properties *prop = NULL;
2205
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09002206 if (ivisurf == NULL ||
2207 opacity < wl_fixed_from_double(0.0) ||
2208 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002209 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
2210 return IVI_FAILED;
2211 }
2212
2213 prop = &ivisurf->pending.prop;
2214 prop->opacity = opacity;
2215
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002216 if (ivisurf->prop.opacity != opacity)
2217 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
2218 else
2219 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002220
2221 return IVI_SUCCEEDED;
2222}
2223
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002224wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002225ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
2226{
2227 if (ivisurf == NULL) {
2228 weston_log("ivi_layout_surface_get_opacity: invalid argument\n");
2229 return wl_fixed_from_double(0.0);
2230 }
2231
2232 return ivisurf->prop.opacity;
2233}
2234
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002235int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002236ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
2237 int32_t x, int32_t y,
2238 int32_t width, int32_t height)
2239{
2240 struct ivi_layout_surface_properties *prop = NULL;
2241
2242 if (ivisurf == NULL) {
2243 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
2244 return IVI_FAILED;
2245 }
2246
2247 prop = &ivisurf->pending.prop;
2248 prop->start_x = prop->dest_x;
2249 prop->start_y = prop->dest_y;
2250 prop->dest_x = x;
2251 prop->dest_y = y;
2252 prop->start_width = prop->dest_width;
2253 prop->start_height = prop->dest_height;
2254 prop->dest_width = width;
2255 prop->dest_height = height;
2256
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002257 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2258 ivisurf->prop.dest_width != width ||
2259 ivisurf->prop.dest_height != height)
2260 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2261 else
2262 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002263
2264 return IVI_SUCCEEDED;
2265}
2266
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002267static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002268ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
2269 int32_t dest_width, int32_t dest_height)
2270{
2271 struct ivi_layout_surface_properties *prop = NULL;
2272
2273 if (ivisurf == NULL) {
2274 weston_log("ivi_layout_surface_set_dimension: invalid argument\n");
2275 return IVI_FAILED;
2276 }
2277
2278 prop = &ivisurf->pending.prop;
2279 prop->dest_width = dest_width;
2280 prop->dest_height = dest_height;
2281
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002282 if (ivisurf->prop.dest_width != dest_width ||
2283 ivisurf->prop.dest_height != dest_height)
2284 ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
2285 else
2286 ivisurf->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002287
2288 return IVI_SUCCEEDED;
2289}
2290
2291int32_t
2292ivi_layout_surface_get_dimension(struct ivi_layout_surface *ivisurf,
2293 int32_t *dest_width, int32_t *dest_height)
2294{
2295 if (ivisurf == NULL || dest_width == NULL || dest_height == NULL) {
2296 weston_log("ivi_layout_surface_get_dimension: invalid argument\n");
2297 return IVI_FAILED;
2298 }
2299
2300 *dest_width = ivisurf->prop.dest_width;
2301 *dest_height = ivisurf->prop.dest_height;
2302
2303 return IVI_SUCCEEDED;
2304}
2305
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002306static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002307ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
2308 int32_t dest_x, int32_t dest_y)
2309{
2310 struct ivi_layout_surface_properties *prop = NULL;
2311
2312 if (ivisurf == NULL) {
2313 weston_log("ivi_layout_surface_set_position: invalid argument\n");
2314 return IVI_FAILED;
2315 }
2316
2317 prop = &ivisurf->pending.prop;
2318 prop->dest_x = dest_x;
2319 prop->dest_y = dest_y;
2320
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002321 if (ivisurf->prop.dest_x != dest_x || ivisurf->prop.dest_y != dest_y)
2322 ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
2323 else
2324 ivisurf->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002325
2326 return IVI_SUCCEEDED;
2327}
2328
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002329static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002330ivi_layout_surface_get_position(struct ivi_layout_surface *ivisurf,
2331 int32_t *dest_x, int32_t *dest_y)
2332{
2333 if (ivisurf == NULL || dest_x == NULL || dest_y == NULL) {
2334 weston_log("ivi_layout_surface_get_position: invalid argument\n");
2335 return IVI_FAILED;
2336 }
2337
2338 *dest_x = ivisurf->prop.dest_x;
2339 *dest_y = ivisurf->prop.dest_y;
2340
2341 return IVI_SUCCEEDED;
2342}
2343
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002344static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002345ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2346 enum wl_output_transform orientation)
2347{
2348 struct ivi_layout_surface_properties *prop = NULL;
2349
2350 if (ivisurf == NULL) {
2351 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2352 return IVI_FAILED;
2353 }
2354
2355 prop = &ivisurf->pending.prop;
2356 prop->orientation = orientation;
2357
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002358 if (ivisurf->prop.orientation != orientation)
2359 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2360 else
2361 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002362
2363 return IVI_SUCCEEDED;
2364}
2365
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002366static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002367ivi_layout_surface_get_orientation(struct ivi_layout_surface *ivisurf)
2368{
2369 if (ivisurf == NULL) {
2370 weston_log("ivi_layout_surface_get_orientation: invalid argument\n");
2371 return 0;
2372 }
2373
2374 return ivisurf->prop.orientation;
2375}
2376
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002377static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002378ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2379 struct ivi_layout_layer *addlayer)
2380{
2381 struct ivi_layout *layout = get_instance();
2382 struct ivi_layout_layer *ivilayer = NULL;
2383 struct ivi_layout_layer *next = NULL;
2384 int is_layer_in_scrn = 0;
2385
2386 if (iviscrn == NULL || addlayer == NULL) {
2387 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2388 return IVI_FAILED;
2389 }
2390
2391 is_layer_in_scrn = is_layer_in_screen(addlayer, iviscrn);
2392 if (is_layer_in_scrn == 1) {
2393 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2394 return IVI_SUCCEEDED;
2395 }
2396
2397 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2398 if (ivilayer->id_layer == addlayer->id_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002399 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002400 wl_list_insert(&iviscrn->pending.layer_list,
2401 &ivilayer->pending.link);
2402 break;
2403 }
2404 }
2405
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002406 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002407
2408 return IVI_SUCCEEDED;
2409}
2410
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002411static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002412ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2413 struct ivi_layout_layer **pLayer,
2414 const int32_t number)
2415{
2416 struct ivi_layout *layout = get_instance();
2417 struct ivi_layout_layer *ivilayer = NULL;
2418 struct ivi_layout_layer *next = NULL;
2419 uint32_t *id_layer = NULL;
2420 int32_t i = 0;
2421
2422 if (iviscrn == NULL) {
2423 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2424 return IVI_FAILED;
2425 }
2426
2427 wl_list_for_each_safe(ivilayer, next,
2428 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002429 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002430 wl_list_init(&ivilayer->pending.link);
2431 }
2432
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002433 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002434
2435 for (i = 0; i < number; i++) {
2436 id_layer = &pLayer[i]->id_layer;
2437 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2438 if (*id_layer != ivilayer->id_layer) {
2439 continue;
2440 }
2441
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002442 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002443 wl_list_insert(&iviscrn->pending.layer_list,
2444 &ivilayer->pending.link);
2445 break;
2446 }
2447 }
2448
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002449 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002450
2451 return IVI_SUCCEEDED;
2452}
2453
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002454static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002455ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2456{
2457 return iviscrn->output;
2458}
2459
2460/**
2461 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2462 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2463 * This function is used to get the result of drawing by clients.
2464 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002465static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002466ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2467{
2468 return ivisurf != NULL ? ivisurf->surface : NULL;
2469}
2470
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002471static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002472ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2473 int32_t *width, int32_t *height,
2474 int32_t *stride)
2475{
2476 int32_t w;
2477 int32_t h;
2478 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2479
2480 if (ivisurf == NULL || ivisurf->surface == NULL) {
2481 weston_log("%s: invalid argument\n", __func__);
2482 return IVI_FAILED;
2483 }
2484
2485 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2486
2487 if (width != NULL)
2488 *width = w;
2489
2490 if (height != NULL)
2491 *height = h;
2492
2493 if (stride != NULL)
2494 *stride = w * bytespp;
2495
2496 return IVI_SUCCEEDED;
2497}
2498
2499static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002500ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2501 layer_property_notification_func callback,
2502 void *userdata)
2503{
2504 struct ivi_layout_notification_callback *prop_callback = NULL;
2505
2506 if (ivilayer == NULL || callback == NULL) {
2507 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2508 return IVI_FAILED;
2509 }
2510
2511 prop_callback = malloc(sizeof *prop_callback);
2512 if (prop_callback == NULL) {
2513 weston_log("fails to allocate memory\n");
2514 return IVI_FAILED;
2515 }
2516
2517 prop_callback->callback = callback;
2518 prop_callback->data = userdata;
2519
2520 return add_notification(&ivilayer->property_changed,
2521 layer_prop_changed,
2522 prop_callback);
2523}
2524
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002525static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002526ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2527{
2528 if (ivisurf == NULL) {
2529 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2530 return NULL;
2531 }
2532
2533 return &ivisurf->prop;
2534}
2535
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002536static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002537ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2538 struct ivi_layout_surface *addsurf)
2539{
2540 struct ivi_layout *layout = get_instance();
2541 struct ivi_layout_surface *ivisurf = NULL;
2542 struct ivi_layout_surface *next = NULL;
2543 int is_surf_in_layer = 0;
2544
2545 if (ivilayer == NULL || addsurf == NULL) {
2546 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2547 return IVI_FAILED;
2548 }
2549
2550 is_surf_in_layer = is_surface_in_layer(addsurf, ivilayer);
2551 if (is_surf_in_layer == 1) {
2552 weston_log("ivi_layout_layer_add_surface: addsurf is already available\n");
2553 return IVI_SUCCEEDED;
2554 }
2555
2556 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2557 if (ivisurf->id_surface == addsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002558 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002559 wl_list_insert(&ivilayer->pending.surface_list,
2560 &ivisurf->pending.link);
2561 break;
2562 }
2563 }
2564
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002565 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002566
2567 return IVI_SUCCEEDED;
2568}
2569
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002570static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002571ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2572 struct ivi_layout_surface *remsurf)
2573{
2574 struct ivi_layout_surface *ivisurf = NULL;
2575 struct ivi_layout_surface *next = NULL;
2576
2577 if (ivilayer == NULL || remsurf == NULL) {
2578 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2579 return;
2580 }
2581
2582 wl_list_for_each_safe(ivisurf, next,
2583 &ivilayer->pending.surface_list, pending.link) {
2584 if (ivisurf->id_surface == remsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002585 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002586 wl_list_init(&ivisurf->pending.link);
2587 break;
2588 }
2589 }
2590
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002591 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002592}
2593
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002594static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002595ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2596 int32_t x, int32_t y,
2597 int32_t width, int32_t height)
2598{
2599 struct ivi_layout_surface_properties *prop = NULL;
2600
2601 if (ivisurf == NULL) {
2602 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2603 return IVI_FAILED;
2604 }
2605
2606 prop = &ivisurf->pending.prop;
2607 prop->source_x = x;
2608 prop->source_y = y;
2609 prop->source_width = width;
2610 prop->source_height = height;
2611
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002612 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2613 ivisurf->prop.source_width != width ||
2614 ivisurf->prop.source_height != height)
2615 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2616 else
2617 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002618
2619 return IVI_SUCCEEDED;
2620}
2621
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002622int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002623ivi_layout_commit_changes(void)
2624{
2625 struct ivi_layout *layout = get_instance();
2626
2627 commit_surface_list(layout);
2628 commit_layer_list(layout);
2629 commit_screen_list(layout);
2630
2631 commit_transition(layout);
2632
2633 commit_changes(layout);
2634 send_prop(layout);
2635 weston_compositor_schedule_repaint(layout->compositor);
2636
2637 return IVI_SUCCEEDED;
2638}
2639
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002640static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002641ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2642 enum ivi_layout_transition_type type,
2643 uint32_t duration)
2644{
2645 if (ivilayer == NULL) {
2646 weston_log("%s: invalid argument\n", __func__);
2647 return -1;
2648 }
2649
2650 ivilayer->pending.prop.transition_type = type;
2651 ivilayer->pending.prop.transition_duration = duration;
2652
2653 return 0;
2654}
2655
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002656static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002657ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2658 uint32_t is_fade_in,
2659 double start_alpha, double end_alpha)
2660{
2661 if (ivilayer == NULL) {
2662 weston_log("%s: invalid argument\n", __func__);
2663 return -1;
2664 }
2665
2666 ivilayer->pending.prop.is_fade_in = is_fade_in;
2667 ivilayer->pending.prop.start_alpha = start_alpha;
2668 ivilayer->pending.prop.end_alpha = end_alpha;
2669
2670 return 0;
2671}
2672
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002673static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002674ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2675 uint32_t duration)
2676{
2677 struct ivi_layout_surface_properties *prop;
2678
2679 if (ivisurf == NULL) {
2680 weston_log("%s: invalid argument\n", __func__);
2681 return -1;
2682 }
2683
2684 prop = &ivisurf->pending.prop;
2685 prop->transition_duration = duration*10;
2686 return 0;
2687}
2688
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002689static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002690ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2691 enum ivi_layout_transition_type type,
2692 uint32_t duration)
2693{
2694 struct ivi_layout_surface_properties *prop;
2695
2696 if (ivisurf == NULL) {
2697 weston_log("%s: invalid argument\n", __func__);
2698 return -1;
2699 }
2700
2701 prop = &ivisurf->pending.prop;
2702 prop->transition_type = type;
2703 prop->transition_duration = duration;
2704 return 0;
2705}
2706
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002707static int32_t
2708ivi_layout_surface_dump(struct weston_surface *surface,
2709 void *target, size_t size,int32_t x, int32_t y,
2710 int32_t width, int32_t height)
2711{
2712 int result = 0;
2713
2714 if (surface == NULL) {
2715 weston_log("%s: invalid argument\n", __func__);
2716 return IVI_FAILED;
2717 }
2718
2719 result = weston_surface_copy_content(
2720 surface, target, size,
2721 x, y, width, height);
2722
2723 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2724}
2725
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002726/**
2727 * methods of interaction between ivi-shell with ivi-layout
2728 */
2729struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002730ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2731{
2732 struct weston_view *tmpview = NULL;
2733
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002734 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002735 return NULL;
2736
2737 wl_list_for_each(tmpview, &surface->surface->views, surface_link)
2738 {
2739 if (tmpview != NULL) {
2740 break;
2741 }
2742 }
2743 return tmpview;
2744}
2745
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002746void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002747ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2748 int32_t width, int32_t height)
2749{
2750 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002751
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002752 /* emit callback which is set by ivi-layout api user */
2753 wl_signal_emit(&layout->surface_notification.configure_changed,
2754 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002755}
2756
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002757static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002758ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2759 ivi_controller_surface_content_callback callback,
2760 void* userdata)
2761{
2762 int32_t ret = IVI_FAILED;
2763
2764 if (ivisurf != NULL) {
2765 ivisurf->content_observer.callback = callback;
2766 ivisurf->content_observer.userdata = userdata;
2767 ret = IVI_SUCCEEDED;
2768 }
2769 return ret;
2770}
2771
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002772struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002773ivi_layout_surface_create(struct weston_surface *wl_surface,
2774 uint32_t id_surface)
2775{
2776 struct ivi_layout *layout = get_instance();
2777 struct ivi_layout_surface *ivisurf = NULL;
2778 struct weston_view *tmpview = NULL;
2779
2780 if (wl_surface == NULL) {
2781 weston_log("ivi_layout_surface_create: invalid argument\n");
2782 return NULL;
2783 }
2784
2785 ivisurf = get_surface(&layout->surface_list, id_surface);
2786 if (ivisurf != NULL) {
2787 if (ivisurf->surface != NULL) {
2788 weston_log("id_surface(%d) is already created\n", id_surface);
2789 return NULL;
2790 }
2791 }
2792
2793 ivisurf = calloc(1, sizeof *ivisurf);
2794 if (ivisurf == NULL) {
2795 weston_log("fails to allocate memory\n");
2796 return NULL;
2797 }
2798
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002799 wl_signal_init(&ivisurf->property_changed);
2800 wl_signal_init(&ivisurf->configured);
2801 wl_list_init(&ivisurf->layer_list);
2802 ivisurf->id_surface = id_surface;
2803 ivisurf->layout = layout;
2804
2805 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002806
2807 tmpview = weston_view_create(wl_surface);
2808 if (tmpview == NULL) {
2809 weston_log("fails to allocate memory\n");
2810 }
2811
2812 ivisurf->surface->width_from_buffer = 0;
2813 ivisurf->surface->height_from_buffer = 0;
2814
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002815 weston_matrix_init(&ivisurf->transform.matrix);
2816 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002817
2818 init_surface_properties(&ivisurf->prop);
2819 ivisurf->event_mask = 0;
2820
2821 ivisurf->pending.prop = ivisurf->prop;
2822 wl_list_init(&ivisurf->pending.link);
2823
2824 wl_list_init(&ivisurf->order.link);
2825 wl_list_init(&ivisurf->order.layer_list);
2826
2827 wl_list_insert(&layout->surface_list, &ivisurf->link);
2828
2829 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2830
2831 return ivisurf;
2832}
2833
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002834void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002835ivi_layout_init_with_compositor(struct weston_compositor *ec)
2836{
2837 struct ivi_layout *layout = get_instance();
2838
2839 layout->compositor = ec;
2840
2841 wl_list_init(&layout->surface_list);
2842 wl_list_init(&layout->layer_list);
2843 wl_list_init(&layout->screen_list);
2844
2845 wl_signal_init(&layout->layer_notification.created);
2846 wl_signal_init(&layout->layer_notification.removed);
2847
2848 wl_signal_init(&layout->surface_notification.created);
2849 wl_signal_init(&layout->surface_notification.removed);
2850 wl_signal_init(&layout->surface_notification.configure_changed);
2851
2852 /* Add layout_layer at the last of weston_compositor.layer_list */
2853 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2854
2855 create_screen(ec);
2856
2857 layout->transitions = ivi_layout_transition_set_create(ec);
2858 wl_list_init(&layout->pending_transition_list);
2859}
2860
2861
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002862void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002863ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2864 struct wl_listener* listener)
2865{
2866 wl_signal_add(&ivisurf->configured, listener);
2867}
2868
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002869static struct ivi_controller_interface ivi_controller_interface = {
2870 /**
2871 * commit all changes
2872 */
2873 .commit_changes = ivi_layout_commit_changes,
2874
2875 /**
2876 * surface controller interfaces
2877 */
2878 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2879 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2880 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2881 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2882 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2883 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2884 .get_surfaces = ivi_layout_get_surfaces,
2885 .get_id_of_surface = ivi_layout_get_id_of_surface,
2886 .get_surface_from_id = ivi_layout_get_surface_from_id,
2887 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2888 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2889 .surface_set_visibility = ivi_layout_surface_set_visibility,
2890 .surface_get_visibility = ivi_layout_surface_get_visibility,
2891 .surface_set_opacity = ivi_layout_surface_set_opacity,
2892 .surface_get_opacity = ivi_layout_surface_get_opacity,
2893 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2894 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
2895 .surface_set_position = ivi_layout_surface_set_position,
2896 .surface_get_position = ivi_layout_surface_get_position,
2897 .surface_set_dimension = ivi_layout_surface_set_dimension,
2898 .surface_get_dimension = ivi_layout_surface_get_dimension,
2899 .surface_set_orientation = ivi_layout_surface_set_orientation,
2900 .surface_get_orientation = ivi_layout_surface_get_orientation,
2901 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2902 .surface_add_notification = ivi_layout_surface_add_notification,
2903 .surface_remove_notification = ivi_layout_surface_remove_notification,
2904 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2905 .surface_set_transition = ivi_layout_surface_set_transition,
2906 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2907
2908 /**
2909 * layer controller interfaces
2910 */
2911 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2912 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2913 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2914 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2915 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002916 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002917 .get_layers = ivi_layout_get_layers,
2918 .get_id_of_layer = ivi_layout_get_id_of_layer,
2919 .get_layer_from_id = ivi_layout_get_layer_from_id,
2920 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2921 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2922 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2923 .layer_set_visibility = ivi_layout_layer_set_visibility,
2924 .layer_get_visibility = ivi_layout_layer_get_visibility,
2925 .layer_set_opacity = ivi_layout_layer_set_opacity,
2926 .layer_get_opacity = ivi_layout_layer_get_opacity,
2927 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2928 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
2929 .layer_set_position = ivi_layout_layer_set_position,
2930 .layer_get_position = ivi_layout_layer_get_position,
2931 .layer_set_dimension = ivi_layout_layer_set_dimension,
2932 .layer_get_dimension = ivi_layout_layer_get_dimension,
2933 .layer_set_orientation = ivi_layout_layer_set_orientation,
2934 .layer_get_orientation = ivi_layout_layer_get_orientation,
2935 .layer_add_surface = ivi_layout_layer_add_surface,
2936 .layer_remove_surface = ivi_layout_layer_remove_surface,
2937 .layer_set_render_order = ivi_layout_layer_set_render_order,
2938 .layer_add_notification = ivi_layout_layer_add_notification,
2939 .layer_remove_notification = ivi_layout_layer_remove_notification,
2940 .layer_set_transition = ivi_layout_layer_set_transition,
2941
2942 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002943 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002944 */
2945 .get_screen_from_id = ivi_layout_get_screen_from_id,
2946 .get_screen_resolution = ivi_layout_get_screen_resolution,
2947 .get_screens = ivi_layout_get_screens,
2948 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2949 .screen_add_layer = ivi_layout_screen_add_layer,
2950 .screen_set_render_order = ivi_layout_screen_set_render_order,
2951 .screen_get_output = ivi_layout_screen_get_output,
2952
2953 /**
2954 * animation
2955 */
2956 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002957 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2958
2959 /**
2960 * surface content dumping for debugging
2961 */
2962 .surface_get_size = ivi_layout_surface_get_size,
2963 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002964
2965 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002966 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002967 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002968 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002969 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2970
2971 /**
2972 * screen controller interfaces part2
2973 */
2974 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002975};
2976
2977int
2978load_controller_modules(struct weston_compositor *compositor, const char *modules,
2979 int *argc, char *argv[])
2980{
2981 const char *p, *end;
2982 char buffer[256];
2983 int (*controller_module_init)(struct weston_compositor *compositor,
2984 int *argc, char *argv[],
2985 const struct ivi_controller_interface *interface,
2986 size_t interface_version);
2987
2988 if (modules == NULL)
2989 return 0;
2990
2991 p = modules;
2992 while (*p) {
2993 end = strchrnul(p, ',');
2994 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2995
2996 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002997 if (!controller_module_init)
2998 return -1;
2999
3000 if (controller_module_init(compositor, argc, argv,
3001 &ivi_controller_interface,
3002 sizeof(struct ivi_controller_interface)) != 0) {
3003 weston_log("ivi-shell: Initialization of controller module fails");
3004 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09003005 }
3006
3007 p = end;
3008 while (*p == ',')
3009 p++;
3010 }
3011
3012 return 0;
3013}