blob: 24bd8dd6711335ccc303d009245381424cd8fdc3 [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");
1535 return IVI_FAILED;
1536 }
1537
1538 prop_callback->callback = callback;
1539 prop_callback->data = userdata;
1540
1541 notification->listener.notify = surface_prop_changed;
1542 notification->userdata = prop_callback;
1543
1544 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1545
1546 return IVI_SUCCEEDED;
1547}
1548
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001549static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001550ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1551{
1552 if (ivilayer == NULL) {
1553 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1554 return NULL;
1555 }
1556
1557 return &ivilayer->prop;
1558}
1559
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001560static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001561ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1562{
1563 struct ivi_layout *layout = get_instance();
1564 struct ivi_layout_screen *iviscrn = NULL;
1565 int32_t length = 0;
1566 int32_t n = 0;
1567
1568 if (pLength == NULL || ppArray == NULL) {
1569 weston_log("ivi_layout_get_screens: invalid argument\n");
1570 return IVI_FAILED;
1571 }
1572
1573 length = wl_list_length(&layout->screen_list);
1574
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001575 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001576 /* the Array must be free by module which called this function */
1577 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1578 if (*ppArray == NULL) {
1579 weston_log("fails to allocate memory\n");
1580 return IVI_FAILED;
1581 }
1582
1583 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1584 (*ppArray)[n++] = iviscrn;
1585 }
1586 }
1587
1588 *pLength = length;
1589
1590 return IVI_SUCCEEDED;
1591}
1592
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001593static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001594ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1595 int32_t *pLength,
1596 struct ivi_layout_screen ***ppArray)
1597{
1598 struct link_screen *link_scrn = NULL;
1599 int32_t length = 0;
1600 int32_t n = 0;
1601
1602 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1603 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1604 return IVI_FAILED;
1605 }
1606
1607 length = wl_list_length(&ivilayer->screen_list);
1608
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001609 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001610 /* the Array must be free by module which called this function */
1611 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1612 if (*ppArray == NULL) {
1613 weston_log("fails to allocate memory\n");
1614 return IVI_FAILED;
1615 }
1616
1617 wl_list_for_each(link_scrn, &ivilayer->screen_list, link) {
1618 (*ppArray)[n++] = link_scrn->iviscrn;
1619 }
1620 }
1621
1622 *pLength = length;
1623
1624 return IVI_SUCCEEDED;
1625}
1626
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001627static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001628ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1629{
1630 struct ivi_layout *layout = get_instance();
1631 struct ivi_layout_layer *ivilayer = NULL;
1632 int32_t length = 0;
1633 int32_t n = 0;
1634
1635 if (pLength == NULL || ppArray == NULL) {
1636 weston_log("ivi_layout_get_layers: invalid argument\n");
1637 return IVI_FAILED;
1638 }
1639
1640 length = wl_list_length(&layout->layer_list);
1641
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001642 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001643 /* the Array must be free by module which called this function */
1644 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1645 if (*ppArray == NULL) {
1646 weston_log("fails to allocate memory\n");
1647 return IVI_FAILED;
1648 }
1649
1650 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1651 (*ppArray)[n++] = ivilayer;
1652 }
1653 }
1654
1655 *pLength = length;
1656
1657 return IVI_SUCCEEDED;
1658}
1659
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001660static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001661ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1662 int32_t *pLength,
1663 struct ivi_layout_layer ***ppArray)
1664{
1665 struct ivi_layout_layer *ivilayer = NULL;
1666 int32_t length = 0;
1667 int32_t n = 0;
1668
1669 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1670 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1671 return IVI_FAILED;
1672 }
1673
1674 length = wl_list_length(&iviscrn->order.layer_list);
1675
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001676 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001677 /* the Array must be free by module which called this function */
1678 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1679 if (*ppArray == NULL) {
1680 weston_log("fails to allocate memory\n");
1681 return IVI_FAILED;
1682 }
1683
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001684 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001685 (*ppArray)[n++] = ivilayer;
1686 }
1687 }
1688
1689 *pLength = length;
1690
1691 return IVI_SUCCEEDED;
1692}
1693
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001694static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001695ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1696 int32_t *pLength,
1697 struct ivi_layout_layer ***ppArray)
1698{
1699 struct link_layer *link_layer = NULL;
1700 int32_t length = 0;
1701 int32_t n = 0;
1702
1703 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1704 weston_log("ivi_layout_getLayers: invalid argument\n");
1705 return IVI_FAILED;
1706 }
1707
1708 length = wl_list_length(&ivisurf->layer_list);
1709
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001710 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001711 /* the Array must be free by module which called this function */
1712 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1713 if (*ppArray == NULL) {
1714 weston_log("fails to allocate memory\n");
1715 return IVI_FAILED;
1716 }
1717
1718 wl_list_for_each(link_layer, &ivisurf->layer_list, link) {
1719 (*ppArray)[n++] = link_layer->ivilayer;
1720 }
1721 }
1722
1723 *pLength = length;
1724
1725 return IVI_SUCCEEDED;
1726}
1727
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001728static
1729int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001730ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1731{
1732 struct ivi_layout *layout = get_instance();
1733 struct ivi_layout_surface *ivisurf = NULL;
1734 int32_t length = 0;
1735 int32_t n = 0;
1736
1737 if (pLength == NULL || ppArray == NULL) {
1738 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1739 return IVI_FAILED;
1740 }
1741
1742 length = wl_list_length(&layout->surface_list);
1743
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001744 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001745 /* the Array must be free by module which called this function */
1746 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1747 if (*ppArray == NULL) {
1748 weston_log("fails to allocate memory\n");
1749 return IVI_FAILED;
1750 }
1751
1752 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1753 (*ppArray)[n++] = ivisurf;
1754 }
1755 }
1756
1757 *pLength = length;
1758
1759 return IVI_SUCCEEDED;
1760}
1761
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001762static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001763ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1764 int32_t *pLength,
1765 struct ivi_layout_surface ***ppArray)
1766{
1767 struct ivi_layout_surface *ivisurf = NULL;
1768 int32_t length = 0;
1769 int32_t n = 0;
1770
1771 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1772 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1773 return IVI_FAILED;
1774 }
1775
1776 length = wl_list_length(&ivilayer->order.surface_list);
1777
1778 if (length != 0) {
1779 /* the Array must be free by module which called this function */
1780 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1781 if (*ppArray == NULL) {
1782 weston_log("fails to allocate memory\n");
1783 return IVI_FAILED;
1784 }
1785
1786 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1787 (*ppArray)[n++] = ivisurf;
1788 }
1789 }
1790
1791 *pLength = length;
1792
1793 return IVI_SUCCEEDED;
1794}
1795
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001796static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001797ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1798 int32_t width, int32_t height)
1799{
1800 struct ivi_layout *layout = get_instance();
1801 struct ivi_layout_layer *ivilayer = NULL;
1802
1803 ivilayer = get_layer(&layout->layer_list, id_layer);
1804 if (ivilayer != NULL) {
1805 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001806 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001807 return ivilayer;
1808 }
1809
1810 ivilayer = calloc(1, sizeof *ivilayer);
1811 if (ivilayer == NULL) {
1812 weston_log("fails to allocate memory\n");
1813 return NULL;
1814 }
1815
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001816 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001817 wl_signal_init(&ivilayer->property_changed);
1818 wl_list_init(&ivilayer->screen_list);
1819 wl_list_init(&ivilayer->link_to_surface);
1820 ivilayer->layout = layout;
1821 ivilayer->id_layer = id_layer;
1822
1823 init_layer_properties(&ivilayer->prop, width, height);
1824 ivilayer->event_mask = 0;
1825
1826 wl_list_init(&ivilayer->pending.surface_list);
1827 wl_list_init(&ivilayer->pending.link);
1828 ivilayer->pending.prop = ivilayer->prop;
1829
1830 wl_list_init(&ivilayer->order.surface_list);
1831 wl_list_init(&ivilayer->order.link);
1832
1833 wl_list_insert(&layout->layer_list, &ivilayer->link);
1834
1835 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1836
1837 return ivilayer;
1838}
1839
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001840static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001841ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1842{
1843 if (ivilayer == NULL) {
1844 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1845 return;
1846 }
1847
1848 remove_all_notification(&ivilayer->property_changed.listener_list);
1849}
1850
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001851static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001852ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1853 layer_property_notification_func callback,
1854 void *userdata)
1855{
1856 if (ivilayer == NULL) {
1857 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1858 return;
1859 }
1860
1861 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1862}
1863
1864static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001865ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001866{
1867 struct ivi_layout *layout = get_instance();
1868
1869 if (ivilayer == NULL) {
1870 weston_log("ivi_layout_layer_remove: invalid argument\n");
1871 return;
1872 }
1873
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001874 if (--ivilayer->ref_count > 0)
1875 return;
1876
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001877 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1878
1879 clear_surface_pending_list(ivilayer);
1880 clear_surface_order_list(ivilayer);
1881
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001882 wl_list_remove(&ivilayer->pending.link);
1883 wl_list_remove(&ivilayer->order.link);
1884 wl_list_remove(&ivilayer->link);
1885
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001886 remove_orderlayer_from_screen(ivilayer);
1887 remove_link_to_surface(ivilayer);
1888 ivi_layout_layer_remove_notification(ivilayer);
1889
1890 free(ivilayer);
1891}
1892
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001893int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001894ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1895 bool newVisibility)
1896{
1897 struct ivi_layout_layer_properties *prop = NULL;
1898
1899 if (ivilayer == NULL) {
1900 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1901 return IVI_FAILED;
1902 }
1903
1904 prop = &ivilayer->pending.prop;
1905 prop->visibility = newVisibility;
1906
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001907 if (ivilayer->prop.visibility != newVisibility)
1908 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1909 else
1910 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001911
1912 return IVI_SUCCEEDED;
1913}
1914
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001915static bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001916ivi_layout_layer_get_visibility(struct ivi_layout_layer *ivilayer)
1917{
1918 if (ivilayer == NULL) {
1919 weston_log("ivi_layout_layer_get_visibility: invalid argument\n");
1920 return false;
1921 }
1922
1923 return ivilayer->prop.visibility;
1924}
1925
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001926int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001927ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1928 wl_fixed_t opacity)
1929{
1930 struct ivi_layout_layer_properties *prop = NULL;
1931
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001932 if (ivilayer == NULL ||
1933 opacity < wl_fixed_from_double(0.0) ||
1934 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001935 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1936 return IVI_FAILED;
1937 }
1938
1939 prop = &ivilayer->pending.prop;
1940 prop->opacity = opacity;
1941
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001942 if (ivilayer->prop.opacity != opacity)
1943 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1944 else
1945 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001946
1947 return IVI_SUCCEEDED;
1948}
1949
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001950wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001951ivi_layout_layer_get_opacity(struct ivi_layout_layer *ivilayer)
1952{
1953 if (ivilayer == NULL) {
1954 weston_log("ivi_layout_layer_get_opacity: invalid argument\n");
1955 return wl_fixed_from_double(0.0);
1956 }
1957
1958 return ivilayer->prop.opacity;
1959}
1960
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001961static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001962ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1963 int32_t x, int32_t y,
1964 int32_t width, int32_t height)
1965{
1966 struct ivi_layout_layer_properties *prop = NULL;
1967
1968 if (ivilayer == NULL) {
1969 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1970 return IVI_FAILED;
1971 }
1972
1973 prop = &ivilayer->pending.prop;
1974 prop->source_x = x;
1975 prop->source_y = y;
1976 prop->source_width = width;
1977 prop->source_height = height;
1978
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001979 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1980 ivilayer->prop.source_width != width ||
1981 ivilayer->prop.source_height != height)
1982 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1983 else
1984 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001985
1986 return IVI_SUCCEEDED;
1987}
1988
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001989static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001990ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1991 int32_t x, int32_t y,
1992 int32_t width, int32_t height)
1993{
1994 struct ivi_layout_layer_properties *prop = NULL;
1995
1996 if (ivilayer == NULL) {
1997 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1998 return IVI_FAILED;
1999 }
2000
2001 prop = &ivilayer->pending.prop;
2002 prop->dest_x = x;
2003 prop->dest_y = y;
2004 prop->dest_width = width;
2005 prop->dest_height = height;
2006
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002007 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
2008 ivilayer->prop.dest_width != width ||
2009 ivilayer->prop.dest_height != height)
2010 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2011 else
2012 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002013
2014 return IVI_SUCCEEDED;
2015}
2016
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002017static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002018ivi_layout_layer_get_dimension(struct ivi_layout_layer *ivilayer,
2019 int32_t *dest_width, int32_t *dest_height)
2020{
2021 if (ivilayer == NULL || dest_width == NULL || dest_height == NULL) {
2022 weston_log("ivi_layout_layer_get_dimension: invalid argument\n");
2023 return IVI_FAILED;
2024 }
2025
2026 *dest_width = ivilayer->prop.dest_width;
2027 *dest_height = ivilayer->prop.dest_height;
2028
2029 return IVI_SUCCEEDED;
2030}
2031
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002032static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002033ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
2034 int32_t dest_width, int32_t dest_height)
2035{
2036 struct ivi_layout_layer_properties *prop = NULL;
2037
2038 if (ivilayer == NULL) {
2039 weston_log("ivi_layout_layer_set_dimension: invalid argument\n");
2040 return IVI_FAILED;
2041 }
2042
2043 prop = &ivilayer->pending.prop;
2044
2045 prop->dest_width = dest_width;
2046 prop->dest_height = dest_height;
2047
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002048 if (ivilayer->prop.dest_width != dest_width ||
2049 ivilayer->prop.dest_height != dest_height)
2050 ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
2051 else
2052 ivilayer->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002053
2054 return IVI_SUCCEEDED;
2055}
2056
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002057int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002058ivi_layout_layer_get_position(struct ivi_layout_layer *ivilayer,
2059 int32_t *dest_x, int32_t *dest_y)
2060{
2061 if (ivilayer == NULL || dest_x == NULL || dest_y == NULL) {
2062 weston_log("ivi_layout_layer_get_position: invalid argument\n");
2063 return IVI_FAILED;
2064 }
2065
2066 *dest_x = ivilayer->prop.dest_x;
2067 *dest_y = ivilayer->prop.dest_y;
2068
2069 return IVI_SUCCEEDED;
2070}
2071
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002072int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002073ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
2074 int32_t dest_x, int32_t dest_y)
2075{
2076 struct ivi_layout_layer_properties *prop = NULL;
2077
2078 if (ivilayer == NULL) {
2079 weston_log("ivi_layout_layer_set_position: invalid argument\n");
2080 return IVI_FAILED;
2081 }
2082
2083 prop = &ivilayer->pending.prop;
2084 prop->dest_x = dest_x;
2085 prop->dest_y = dest_y;
2086
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002087 if (ivilayer->prop.dest_x != dest_x || ivilayer->prop.dest_y != dest_y)
2088 ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
2089 else
2090 ivilayer->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002091
2092 return IVI_SUCCEEDED;
2093}
2094
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002095static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002096ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
2097 enum wl_output_transform orientation)
2098{
2099 struct ivi_layout_layer_properties *prop = NULL;
2100
2101 if (ivilayer == NULL) {
2102 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
2103 return IVI_FAILED;
2104 }
2105
2106 prop = &ivilayer->pending.prop;
2107 prop->orientation = orientation;
2108
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002109 if (ivilayer->prop.orientation != orientation)
2110 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2111 else
2112 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002113
2114 return IVI_SUCCEEDED;
2115}
2116
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002117static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002118ivi_layout_layer_get_orientation(struct ivi_layout_layer *ivilayer)
2119{
2120 if (ivilayer == NULL) {
2121 weston_log("ivi_layout_layer_get_orientation: invalid argument\n");
2122 return 0;
2123 }
2124
2125 return ivilayer->prop.orientation;
2126}
2127
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002128int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002129ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
2130 struct ivi_layout_surface **pSurface,
2131 int32_t number)
2132{
2133 struct ivi_layout *layout = get_instance();
2134 struct ivi_layout_surface *ivisurf = NULL;
2135 struct ivi_layout_surface *next = NULL;
2136 uint32_t *id_surface = NULL;
2137 int32_t i = 0;
2138
2139 if (ivilayer == NULL) {
2140 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
2141 return IVI_FAILED;
2142 }
2143
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00002144 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002145
2146 for (i = 0; i < number; i++) {
2147 id_surface = &pSurface[i]->id_surface;
2148
2149 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2150 if (*id_surface != ivisurf->id_surface) {
2151 continue;
2152 }
2153
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002154 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002155 wl_list_insert(&ivilayer->pending.surface_list,
2156 &ivisurf->pending.link);
2157 break;
2158 }
2159 }
2160
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002161 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002162
2163 return IVI_SUCCEEDED;
2164}
2165
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002166int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002167ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
2168 bool newVisibility)
2169{
2170 struct ivi_layout_surface_properties *prop = NULL;
2171
2172 if (ivisurf == NULL) {
2173 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
2174 return IVI_FAILED;
2175 }
2176
2177 prop = &ivisurf->pending.prop;
2178 prop->visibility = newVisibility;
2179
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002180 if (ivisurf->prop.visibility != newVisibility)
2181 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
2182 else
2183 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002184
2185 return IVI_SUCCEEDED;
2186}
2187
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002188bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002189ivi_layout_surface_get_visibility(struct ivi_layout_surface *ivisurf)
2190{
2191 if (ivisurf == NULL) {
2192 weston_log("ivi_layout_surface_get_visibility: invalid argument\n");
2193 return false;
2194 }
2195
2196 return ivisurf->prop.visibility;
2197}
2198
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002199int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002200ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
2201 wl_fixed_t opacity)
2202{
2203 struct ivi_layout_surface_properties *prop = NULL;
2204
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09002205 if (ivisurf == NULL ||
2206 opacity < wl_fixed_from_double(0.0) ||
2207 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002208 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
2209 return IVI_FAILED;
2210 }
2211
2212 prop = &ivisurf->pending.prop;
2213 prop->opacity = opacity;
2214
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002215 if (ivisurf->prop.opacity != opacity)
2216 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
2217 else
2218 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002219
2220 return IVI_SUCCEEDED;
2221}
2222
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002223wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002224ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
2225{
2226 if (ivisurf == NULL) {
2227 weston_log("ivi_layout_surface_get_opacity: invalid argument\n");
2228 return wl_fixed_from_double(0.0);
2229 }
2230
2231 return ivisurf->prop.opacity;
2232}
2233
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002234int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002235ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
2236 int32_t x, int32_t y,
2237 int32_t width, int32_t height)
2238{
2239 struct ivi_layout_surface_properties *prop = NULL;
2240
2241 if (ivisurf == NULL) {
2242 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
2243 return IVI_FAILED;
2244 }
2245
2246 prop = &ivisurf->pending.prop;
2247 prop->start_x = prop->dest_x;
2248 prop->start_y = prop->dest_y;
2249 prop->dest_x = x;
2250 prop->dest_y = y;
2251 prop->start_width = prop->dest_width;
2252 prop->start_height = prop->dest_height;
2253 prop->dest_width = width;
2254 prop->dest_height = height;
2255
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002256 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2257 ivisurf->prop.dest_width != width ||
2258 ivisurf->prop.dest_height != height)
2259 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2260 else
2261 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002262
2263 return IVI_SUCCEEDED;
2264}
2265
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002266static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002267ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
2268 int32_t dest_width, int32_t dest_height)
2269{
2270 struct ivi_layout_surface_properties *prop = NULL;
2271
2272 if (ivisurf == NULL) {
2273 weston_log("ivi_layout_surface_set_dimension: invalid argument\n");
2274 return IVI_FAILED;
2275 }
2276
2277 prop = &ivisurf->pending.prop;
2278 prop->dest_width = dest_width;
2279 prop->dest_height = dest_height;
2280
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002281 if (ivisurf->prop.dest_width != dest_width ||
2282 ivisurf->prop.dest_height != dest_height)
2283 ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
2284 else
2285 ivisurf->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002286
2287 return IVI_SUCCEEDED;
2288}
2289
2290int32_t
2291ivi_layout_surface_get_dimension(struct ivi_layout_surface *ivisurf,
2292 int32_t *dest_width, int32_t *dest_height)
2293{
2294 if (ivisurf == NULL || dest_width == NULL || dest_height == NULL) {
2295 weston_log("ivi_layout_surface_get_dimension: invalid argument\n");
2296 return IVI_FAILED;
2297 }
2298
2299 *dest_width = ivisurf->prop.dest_width;
2300 *dest_height = ivisurf->prop.dest_height;
2301
2302 return IVI_SUCCEEDED;
2303}
2304
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002305static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002306ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
2307 int32_t dest_x, int32_t dest_y)
2308{
2309 struct ivi_layout_surface_properties *prop = NULL;
2310
2311 if (ivisurf == NULL) {
2312 weston_log("ivi_layout_surface_set_position: invalid argument\n");
2313 return IVI_FAILED;
2314 }
2315
2316 prop = &ivisurf->pending.prop;
2317 prop->dest_x = dest_x;
2318 prop->dest_y = dest_y;
2319
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002320 if (ivisurf->prop.dest_x != dest_x || ivisurf->prop.dest_y != dest_y)
2321 ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
2322 else
2323 ivisurf->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002324
2325 return IVI_SUCCEEDED;
2326}
2327
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002328static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002329ivi_layout_surface_get_position(struct ivi_layout_surface *ivisurf,
2330 int32_t *dest_x, int32_t *dest_y)
2331{
2332 if (ivisurf == NULL || dest_x == NULL || dest_y == NULL) {
2333 weston_log("ivi_layout_surface_get_position: invalid argument\n");
2334 return IVI_FAILED;
2335 }
2336
2337 *dest_x = ivisurf->prop.dest_x;
2338 *dest_y = ivisurf->prop.dest_y;
2339
2340 return IVI_SUCCEEDED;
2341}
2342
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002343static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002344ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2345 enum wl_output_transform orientation)
2346{
2347 struct ivi_layout_surface_properties *prop = NULL;
2348
2349 if (ivisurf == NULL) {
2350 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2351 return IVI_FAILED;
2352 }
2353
2354 prop = &ivisurf->pending.prop;
2355 prop->orientation = orientation;
2356
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002357 if (ivisurf->prop.orientation != orientation)
2358 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2359 else
2360 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002361
2362 return IVI_SUCCEEDED;
2363}
2364
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002365static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002366ivi_layout_surface_get_orientation(struct ivi_layout_surface *ivisurf)
2367{
2368 if (ivisurf == NULL) {
2369 weston_log("ivi_layout_surface_get_orientation: invalid argument\n");
2370 return 0;
2371 }
2372
2373 return ivisurf->prop.orientation;
2374}
2375
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002376static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002377ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2378 struct ivi_layout_layer *addlayer)
2379{
2380 struct ivi_layout *layout = get_instance();
2381 struct ivi_layout_layer *ivilayer = NULL;
2382 struct ivi_layout_layer *next = NULL;
2383 int is_layer_in_scrn = 0;
2384
2385 if (iviscrn == NULL || addlayer == NULL) {
2386 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2387 return IVI_FAILED;
2388 }
2389
2390 is_layer_in_scrn = is_layer_in_screen(addlayer, iviscrn);
2391 if (is_layer_in_scrn == 1) {
2392 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2393 return IVI_SUCCEEDED;
2394 }
2395
2396 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2397 if (ivilayer->id_layer == addlayer->id_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002398 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002399 wl_list_insert(&iviscrn->pending.layer_list,
2400 &ivilayer->pending.link);
2401 break;
2402 }
2403 }
2404
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002405 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002406
2407 return IVI_SUCCEEDED;
2408}
2409
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002410static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002411ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2412 struct ivi_layout_layer **pLayer,
2413 const int32_t number)
2414{
2415 struct ivi_layout *layout = get_instance();
2416 struct ivi_layout_layer *ivilayer = NULL;
2417 struct ivi_layout_layer *next = NULL;
2418 uint32_t *id_layer = NULL;
2419 int32_t i = 0;
2420
2421 if (iviscrn == NULL) {
2422 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2423 return IVI_FAILED;
2424 }
2425
2426 wl_list_for_each_safe(ivilayer, next,
2427 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002428 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002429 wl_list_init(&ivilayer->pending.link);
2430 }
2431
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002432 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002433
2434 for (i = 0; i < number; i++) {
2435 id_layer = &pLayer[i]->id_layer;
2436 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2437 if (*id_layer != ivilayer->id_layer) {
2438 continue;
2439 }
2440
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002441 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002442 wl_list_insert(&iviscrn->pending.layer_list,
2443 &ivilayer->pending.link);
2444 break;
2445 }
2446 }
2447
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002448 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002449
2450 return IVI_SUCCEEDED;
2451}
2452
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002453static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002454ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2455{
2456 return iviscrn->output;
2457}
2458
2459/**
2460 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2461 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2462 * This function is used to get the result of drawing by clients.
2463 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002464static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002465ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2466{
2467 return ivisurf != NULL ? ivisurf->surface : NULL;
2468}
2469
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002470static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002471ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2472 int32_t *width, int32_t *height,
2473 int32_t *stride)
2474{
2475 int32_t w;
2476 int32_t h;
2477 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2478
2479 if (ivisurf == NULL || ivisurf->surface == NULL) {
2480 weston_log("%s: invalid argument\n", __func__);
2481 return IVI_FAILED;
2482 }
2483
2484 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2485
2486 if (width != NULL)
2487 *width = w;
2488
2489 if (height != NULL)
2490 *height = h;
2491
2492 if (stride != NULL)
2493 *stride = w * bytespp;
2494
2495 return IVI_SUCCEEDED;
2496}
2497
2498static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002499ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2500 layer_property_notification_func callback,
2501 void *userdata)
2502{
2503 struct ivi_layout_notification_callback *prop_callback = NULL;
2504
2505 if (ivilayer == NULL || callback == NULL) {
2506 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2507 return IVI_FAILED;
2508 }
2509
2510 prop_callback = malloc(sizeof *prop_callback);
2511 if (prop_callback == NULL) {
2512 weston_log("fails to allocate memory\n");
2513 return IVI_FAILED;
2514 }
2515
2516 prop_callback->callback = callback;
2517 prop_callback->data = userdata;
2518
2519 return add_notification(&ivilayer->property_changed,
2520 layer_prop_changed,
2521 prop_callback);
2522}
2523
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002524static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002525ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2526{
2527 if (ivisurf == NULL) {
2528 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2529 return NULL;
2530 }
2531
2532 return &ivisurf->prop;
2533}
2534
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002535static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002536ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2537 struct ivi_layout_surface *addsurf)
2538{
2539 struct ivi_layout *layout = get_instance();
2540 struct ivi_layout_surface *ivisurf = NULL;
2541 struct ivi_layout_surface *next = NULL;
2542 int is_surf_in_layer = 0;
2543
2544 if (ivilayer == NULL || addsurf == NULL) {
2545 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2546 return IVI_FAILED;
2547 }
2548
2549 is_surf_in_layer = is_surface_in_layer(addsurf, ivilayer);
2550 if (is_surf_in_layer == 1) {
2551 weston_log("ivi_layout_layer_add_surface: addsurf is already available\n");
2552 return IVI_SUCCEEDED;
2553 }
2554
2555 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2556 if (ivisurf->id_surface == addsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002557 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002558 wl_list_insert(&ivilayer->pending.surface_list,
2559 &ivisurf->pending.link);
2560 break;
2561 }
2562 }
2563
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002564 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002565
2566 return IVI_SUCCEEDED;
2567}
2568
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002569static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002570ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2571 struct ivi_layout_surface *remsurf)
2572{
2573 struct ivi_layout_surface *ivisurf = NULL;
2574 struct ivi_layout_surface *next = NULL;
2575
2576 if (ivilayer == NULL || remsurf == NULL) {
2577 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2578 return;
2579 }
2580
2581 wl_list_for_each_safe(ivisurf, next,
2582 &ivilayer->pending.surface_list, pending.link) {
2583 if (ivisurf->id_surface == remsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002584 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002585 wl_list_init(&ivisurf->pending.link);
2586 break;
2587 }
2588 }
2589
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002590 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002591}
2592
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002593static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002594ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2595 int32_t x, int32_t y,
2596 int32_t width, int32_t height)
2597{
2598 struct ivi_layout_surface_properties *prop = NULL;
2599
2600 if (ivisurf == NULL) {
2601 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2602 return IVI_FAILED;
2603 }
2604
2605 prop = &ivisurf->pending.prop;
2606 prop->source_x = x;
2607 prop->source_y = y;
2608 prop->source_width = width;
2609 prop->source_height = height;
2610
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002611 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2612 ivisurf->prop.source_width != width ||
2613 ivisurf->prop.source_height != height)
2614 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2615 else
2616 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002617
2618 return IVI_SUCCEEDED;
2619}
2620
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002621int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002622ivi_layout_commit_changes(void)
2623{
2624 struct ivi_layout *layout = get_instance();
2625
2626 commit_surface_list(layout);
2627 commit_layer_list(layout);
2628 commit_screen_list(layout);
2629
2630 commit_transition(layout);
2631
2632 commit_changes(layout);
2633 send_prop(layout);
2634 weston_compositor_schedule_repaint(layout->compositor);
2635
2636 return IVI_SUCCEEDED;
2637}
2638
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002639static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002640ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2641 enum ivi_layout_transition_type type,
2642 uint32_t duration)
2643{
2644 if (ivilayer == NULL) {
2645 weston_log("%s: invalid argument\n", __func__);
2646 return -1;
2647 }
2648
2649 ivilayer->pending.prop.transition_type = type;
2650 ivilayer->pending.prop.transition_duration = duration;
2651
2652 return 0;
2653}
2654
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002655static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002656ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2657 uint32_t is_fade_in,
2658 double start_alpha, double end_alpha)
2659{
2660 if (ivilayer == NULL) {
2661 weston_log("%s: invalid argument\n", __func__);
2662 return -1;
2663 }
2664
2665 ivilayer->pending.prop.is_fade_in = is_fade_in;
2666 ivilayer->pending.prop.start_alpha = start_alpha;
2667 ivilayer->pending.prop.end_alpha = end_alpha;
2668
2669 return 0;
2670}
2671
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002672static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002673ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2674 uint32_t duration)
2675{
2676 struct ivi_layout_surface_properties *prop;
2677
2678 if (ivisurf == NULL) {
2679 weston_log("%s: invalid argument\n", __func__);
2680 return -1;
2681 }
2682
2683 prop = &ivisurf->pending.prop;
2684 prop->transition_duration = duration*10;
2685 return 0;
2686}
2687
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002688static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002689ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2690 enum ivi_layout_transition_type type,
2691 uint32_t duration)
2692{
2693 struct ivi_layout_surface_properties *prop;
2694
2695 if (ivisurf == NULL) {
2696 weston_log("%s: invalid argument\n", __func__);
2697 return -1;
2698 }
2699
2700 prop = &ivisurf->pending.prop;
2701 prop->transition_type = type;
2702 prop->transition_duration = duration;
2703 return 0;
2704}
2705
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002706static int32_t
2707ivi_layout_surface_dump(struct weston_surface *surface,
2708 void *target, size_t size,int32_t x, int32_t y,
2709 int32_t width, int32_t height)
2710{
2711 int result = 0;
2712
2713 if (surface == NULL) {
2714 weston_log("%s: invalid argument\n", __func__);
2715 return IVI_FAILED;
2716 }
2717
2718 result = weston_surface_copy_content(
2719 surface, target, size,
2720 x, y, width, height);
2721
2722 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2723}
2724
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002725/**
2726 * methods of interaction between ivi-shell with ivi-layout
2727 */
2728struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002729ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2730{
2731 struct weston_view *tmpview = NULL;
2732
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002733 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002734 return NULL;
2735
2736 wl_list_for_each(tmpview, &surface->surface->views, surface_link)
2737 {
2738 if (tmpview != NULL) {
2739 break;
2740 }
2741 }
2742 return tmpview;
2743}
2744
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002745void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002746ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2747 int32_t width, int32_t height)
2748{
2749 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002750
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002751 /* emit callback which is set by ivi-layout api user */
2752 wl_signal_emit(&layout->surface_notification.configure_changed,
2753 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002754}
2755
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002756static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002757ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2758 ivi_controller_surface_content_callback callback,
2759 void* userdata)
2760{
2761 int32_t ret = IVI_FAILED;
2762
2763 if (ivisurf != NULL) {
2764 ivisurf->content_observer.callback = callback;
2765 ivisurf->content_observer.userdata = userdata;
2766 ret = IVI_SUCCEEDED;
2767 }
2768 return ret;
2769}
2770
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002771struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002772ivi_layout_surface_create(struct weston_surface *wl_surface,
2773 uint32_t id_surface)
2774{
2775 struct ivi_layout *layout = get_instance();
2776 struct ivi_layout_surface *ivisurf = NULL;
2777 struct weston_view *tmpview = NULL;
2778
2779 if (wl_surface == NULL) {
2780 weston_log("ivi_layout_surface_create: invalid argument\n");
2781 return NULL;
2782 }
2783
2784 ivisurf = get_surface(&layout->surface_list, id_surface);
2785 if (ivisurf != NULL) {
2786 if (ivisurf->surface != NULL) {
2787 weston_log("id_surface(%d) is already created\n", id_surface);
2788 return NULL;
2789 }
2790 }
2791
2792 ivisurf = calloc(1, sizeof *ivisurf);
2793 if (ivisurf == NULL) {
2794 weston_log("fails to allocate memory\n");
2795 return NULL;
2796 }
2797
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002798 wl_signal_init(&ivisurf->property_changed);
2799 wl_signal_init(&ivisurf->configured);
2800 wl_list_init(&ivisurf->layer_list);
2801 ivisurf->id_surface = id_surface;
2802 ivisurf->layout = layout;
2803
2804 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002805
2806 tmpview = weston_view_create(wl_surface);
2807 if (tmpview == NULL) {
2808 weston_log("fails to allocate memory\n");
2809 }
2810
2811 ivisurf->surface->width_from_buffer = 0;
2812 ivisurf->surface->height_from_buffer = 0;
2813
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002814 weston_matrix_init(&ivisurf->transform.matrix);
2815 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002816
2817 init_surface_properties(&ivisurf->prop);
2818 ivisurf->event_mask = 0;
2819
2820 ivisurf->pending.prop = ivisurf->prop;
2821 wl_list_init(&ivisurf->pending.link);
2822
2823 wl_list_init(&ivisurf->order.link);
2824 wl_list_init(&ivisurf->order.layer_list);
2825
2826 wl_list_insert(&layout->surface_list, &ivisurf->link);
2827
2828 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2829
2830 return ivisurf;
2831}
2832
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002833void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002834ivi_layout_init_with_compositor(struct weston_compositor *ec)
2835{
2836 struct ivi_layout *layout = get_instance();
2837
2838 layout->compositor = ec;
2839
2840 wl_list_init(&layout->surface_list);
2841 wl_list_init(&layout->layer_list);
2842 wl_list_init(&layout->screen_list);
2843
2844 wl_signal_init(&layout->layer_notification.created);
2845 wl_signal_init(&layout->layer_notification.removed);
2846
2847 wl_signal_init(&layout->surface_notification.created);
2848 wl_signal_init(&layout->surface_notification.removed);
2849 wl_signal_init(&layout->surface_notification.configure_changed);
2850
2851 /* Add layout_layer at the last of weston_compositor.layer_list */
2852 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2853
2854 create_screen(ec);
2855
2856 layout->transitions = ivi_layout_transition_set_create(ec);
2857 wl_list_init(&layout->pending_transition_list);
2858}
2859
2860
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002861void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002862ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2863 struct wl_listener* listener)
2864{
2865 wl_signal_add(&ivisurf->configured, listener);
2866}
2867
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002868static struct ivi_controller_interface ivi_controller_interface = {
2869 /**
2870 * commit all changes
2871 */
2872 .commit_changes = ivi_layout_commit_changes,
2873
2874 /**
2875 * surface controller interfaces
2876 */
2877 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2878 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2879 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2880 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2881 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2882 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2883 .get_surfaces = ivi_layout_get_surfaces,
2884 .get_id_of_surface = ivi_layout_get_id_of_surface,
2885 .get_surface_from_id = ivi_layout_get_surface_from_id,
2886 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2887 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2888 .surface_set_visibility = ivi_layout_surface_set_visibility,
2889 .surface_get_visibility = ivi_layout_surface_get_visibility,
2890 .surface_set_opacity = ivi_layout_surface_set_opacity,
2891 .surface_get_opacity = ivi_layout_surface_get_opacity,
2892 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2893 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
2894 .surface_set_position = ivi_layout_surface_set_position,
2895 .surface_get_position = ivi_layout_surface_get_position,
2896 .surface_set_dimension = ivi_layout_surface_set_dimension,
2897 .surface_get_dimension = ivi_layout_surface_get_dimension,
2898 .surface_set_orientation = ivi_layout_surface_set_orientation,
2899 .surface_get_orientation = ivi_layout_surface_get_orientation,
2900 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2901 .surface_add_notification = ivi_layout_surface_add_notification,
2902 .surface_remove_notification = ivi_layout_surface_remove_notification,
2903 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2904 .surface_set_transition = ivi_layout_surface_set_transition,
2905 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2906
2907 /**
2908 * layer controller interfaces
2909 */
2910 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2911 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2912 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2913 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2914 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002915 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002916 .get_layers = ivi_layout_get_layers,
2917 .get_id_of_layer = ivi_layout_get_id_of_layer,
2918 .get_layer_from_id = ivi_layout_get_layer_from_id,
2919 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2920 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2921 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2922 .layer_set_visibility = ivi_layout_layer_set_visibility,
2923 .layer_get_visibility = ivi_layout_layer_get_visibility,
2924 .layer_set_opacity = ivi_layout_layer_set_opacity,
2925 .layer_get_opacity = ivi_layout_layer_get_opacity,
2926 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2927 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
2928 .layer_set_position = ivi_layout_layer_set_position,
2929 .layer_get_position = ivi_layout_layer_get_position,
2930 .layer_set_dimension = ivi_layout_layer_set_dimension,
2931 .layer_get_dimension = ivi_layout_layer_get_dimension,
2932 .layer_set_orientation = ivi_layout_layer_set_orientation,
2933 .layer_get_orientation = ivi_layout_layer_get_orientation,
2934 .layer_add_surface = ivi_layout_layer_add_surface,
2935 .layer_remove_surface = ivi_layout_layer_remove_surface,
2936 .layer_set_render_order = ivi_layout_layer_set_render_order,
2937 .layer_add_notification = ivi_layout_layer_add_notification,
2938 .layer_remove_notification = ivi_layout_layer_remove_notification,
2939 .layer_set_transition = ivi_layout_layer_set_transition,
2940
2941 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002942 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002943 */
2944 .get_screen_from_id = ivi_layout_get_screen_from_id,
2945 .get_screen_resolution = ivi_layout_get_screen_resolution,
2946 .get_screens = ivi_layout_get_screens,
2947 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2948 .screen_add_layer = ivi_layout_screen_add_layer,
2949 .screen_set_render_order = ivi_layout_screen_set_render_order,
2950 .screen_get_output = ivi_layout_screen_get_output,
2951
2952 /**
2953 * animation
2954 */
2955 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002956 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2957
2958 /**
2959 * surface content dumping for debugging
2960 */
2961 .surface_get_size = ivi_layout_surface_get_size,
2962 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002963
2964 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002965 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002966 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002967 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002968 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2969
2970 /**
2971 * screen controller interfaces part2
2972 */
2973 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002974};
2975
2976int
2977load_controller_modules(struct weston_compositor *compositor, const char *modules,
2978 int *argc, char *argv[])
2979{
2980 const char *p, *end;
2981 char buffer[256];
2982 int (*controller_module_init)(struct weston_compositor *compositor,
2983 int *argc, char *argv[],
2984 const struct ivi_controller_interface *interface,
2985 size_t interface_version);
2986
2987 if (modules == NULL)
2988 return 0;
2989
2990 p = modules;
2991 while (*p) {
2992 end = strchrnul(p, ',');
2993 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2994
2995 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002996 if (!controller_module_init)
2997 return -1;
2998
2999 if (controller_module_init(compositor, argc, argv,
3000 &ivi_controller_interface,
3001 sizeof(struct ivi_controller_interface)) != 0) {
3002 weston_log("ivi-shell: Initialization of controller module fails");
3003 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09003004 }
3005
3006 p = end;
3007 while (*p == ',')
3008 p++;
3009 }
3010
3011 return 0;
3012}