blob: 798049ad53a53dc5874f10bb659ca6c2de3b62b0 [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"
Pekka Paalanen1f821932016-03-15 16:57:51 +020064#include "ivi-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090065#include "ivi-layout-export.h"
66#include "ivi-layout-private.h"
Pekka Paalanen32ca7912016-03-15 17:21:00 +020067#include "ivi-layout-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090068
Jon Cruz867d50e2015-06-15 15:37:10 -070069#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070070#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090071
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +090072#define max(a, b) ((a) > (b) ? (a) : (b))
73
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090074struct listener_layout_notification {
75 void *userdata;
76 struct wl_listener listener;
77};
78
79struct ivi_layout;
80
81struct ivi_layout_screen {
82 struct wl_list link;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090083
84 struct ivi_layout *layout;
85 struct weston_output *output;
86
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090087 struct {
88 struct wl_list layer_list;
89 struct wl_list link;
90 } pending;
91
92 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +000093 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090094 struct wl_list layer_list;
95 struct wl_list link;
96 } order;
97};
98
99struct ivi_layout_notification_callback {
100 void *callback;
101 void *data;
102};
103
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900104struct ivi_rectangle
105{
106 int32_t x;
107 int32_t y;
108 int32_t width;
109 int32_t height;
110};
111
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900112static void
113remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
114
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900115static struct ivi_layout ivilayout = {0};
116
117struct ivi_layout *
118get_instance(void)
119{
120 return &ivilayout;
121}
122
123/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900124 * Internal API to add/remove a ivi_layer to/from ivi_screen.
125 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900126static struct ivi_layout_surface *
127get_surface(struct wl_list *surf_list, uint32_t id_surface)
128{
129 struct ivi_layout_surface *ivisurf;
130
131 wl_list_for_each(ivisurf, surf_list, link) {
132 if (ivisurf->id_surface == id_surface) {
133 return ivisurf;
134 }
135 }
136
137 return NULL;
138}
139
140static struct ivi_layout_layer *
141get_layer(struct wl_list *layer_list, uint32_t id_layer)
142{
143 struct ivi_layout_layer *ivilayer;
144
145 wl_list_for_each(ivilayer, layer_list, link) {
146 if (ivilayer->id_layer == id_layer) {
147 return ivilayer;
148 }
149 }
150
151 return NULL;
152}
153
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000154static struct weston_view *
155get_weston_view(struct ivi_layout_surface *ivisurf)
156{
157 struct weston_view *view = NULL;
158
159 assert(ivisurf->surface != NULL);
160
161 /* One view per surface */
162 if(wl_list_empty(&ivisurf->surface->views))
163 view = NULL;
164 else
165 view = wl_container_of(ivisurf->surface->views.next, view, surface_link);
166
167 return view;
168}
169
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +0000170static struct ivi_layout_screen *
171get_screen_from_output(struct weston_output *output)
172{
173 struct ivi_layout *layout = get_instance();
174 struct ivi_layout_screen *iviscrn = NULL;
175
176 wl_list_for_each(iviscrn, &layout->screen_list, link) {
177 if (iviscrn->output == output)
178 return iviscrn;
179 }
180
181 return NULL;
182}
183
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900184static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900185remove_all_notification(struct wl_list *listener_list)
186{
187 struct wl_listener *listener = NULL;
188 struct wl_listener *next = NULL;
189
190 wl_list_for_each_safe(listener, next, listener_list, link) {
191 struct listener_layout_notification *notification = NULL;
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000192 wl_list_remove(&listener->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900193
194 notification =
195 container_of(listener,
196 struct listener_layout_notification,
197 listener);
198
199 free(notification->userdata);
200 free(notification);
201 }
202}
203
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900204static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900205ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
206{
207 if (ivisurf == NULL) {
208 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
209 return;
210 }
211
212 remove_all_notification(&ivisurf->property_changed.listener_list);
213}
214
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900215static void
216ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
217 surface_property_notification_func callback,
218 void *userdata)
219{
220 if (ivisurf == NULL) {
221 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
222 return;
223 }
224
225 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
226}
227
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900228/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900229 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900230 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900231void
232ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900233{
234 struct ivi_layout *layout = get_instance();
235
236 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900237 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900238 return;
239 }
240
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900241 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900242 wl_list_remove(&ivisurf->pending.link);
243 wl_list_remove(&ivisurf->order.link);
244 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900245
246 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
247
Mateusz Polroladada6e32016-03-09 09:13:26 +0000248 ivi_layout_remove_all_surface_transitions(ivisurf);
249
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900250 ivi_layout_surface_remove_notification(ivisurf);
251
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900252 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900253}
254
255/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900256 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
257 * Called by ivi_layout_init_with_compositor.
258 */
259static void
260create_screen(struct weston_compositor *ec)
261{
262 struct ivi_layout *layout = get_instance();
263 struct ivi_layout_screen *iviscrn = NULL;
264 struct weston_output *output = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900265
266 wl_list_for_each(output, &ec->output_list, link) {
267 iviscrn = calloc(1, sizeof *iviscrn);
268 if (iviscrn == NULL) {
269 weston_log("fails to allocate memory\n");
270 continue;
271 }
272
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900273 iviscrn->layout = layout;
274
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900275 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900276
277 wl_list_init(&iviscrn->pending.layer_list);
278 wl_list_init(&iviscrn->pending.link);
279
280 wl_list_init(&iviscrn->order.layer_list);
281 wl_list_init(&iviscrn->order.link);
282
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900283 wl_list_insert(&layout->screen_list, &iviscrn->link);
284 }
285}
286
287/**
288 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
289 */
290static void
291init_layer_properties(struct ivi_layout_layer_properties *prop,
292 int32_t width, int32_t height)
293{
294 memset(prop, 0, sizeof *prop);
295 prop->opacity = wl_fixed_from_double(1.0);
296 prop->source_width = width;
297 prop->source_height = height;
298 prop->dest_width = width;
299 prop->dest_height = height;
300}
301
302static void
303init_surface_properties(struct ivi_layout_surface_properties *prop)
304{
305 memset(prop, 0, sizeof *prop);
306 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900307 /*
308 * FIXME: this shall be finxed by ivi-layout-transition.
309 */
310 prop->dest_width = 1;
311 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900312}
313
314/**
315 * Internal APIs to be called from ivi_layout_commit_changes.
316 */
317static void
318update_opacity(struct ivi_layout_layer *ivilayer,
319 struct ivi_layout_surface *ivisurf)
320{
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000321 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900322 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
323 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
324
Nobuhiko Tanibata90c27892015-12-26 23:52:51 +0900325 tmpview = get_weston_view(ivisurf);
326 assert(tmpview != NULL);
327 tmpview->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900328}
329
330static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900331get_rotate_values(enum wl_output_transform orientation,
332 float *v_sin,
333 float *v_cos)
334{
335 switch (orientation) {
336 case WL_OUTPUT_TRANSFORM_90:
337 *v_sin = 1.0f;
338 *v_cos = 0.0f;
339 break;
340 case WL_OUTPUT_TRANSFORM_180:
341 *v_sin = 0.0f;
342 *v_cos = -1.0f;
343 break;
344 case WL_OUTPUT_TRANSFORM_270:
345 *v_sin = -1.0f;
346 *v_cos = 0.0f;
347 break;
348 case WL_OUTPUT_TRANSFORM_NORMAL:
349 default:
350 *v_sin = 0.0f;
351 *v_cos = 1.0f;
352 break;
353 }
354}
355
356static void
357get_scale(enum wl_output_transform orientation,
358 float dest_width,
359 float dest_height,
360 float source_width,
361 float source_height,
362 float *scale_x,
363 float *scale_y)
364{
365 switch (orientation) {
366 case WL_OUTPUT_TRANSFORM_90:
367 *scale_x = dest_width / source_height;
368 *scale_y = dest_height / source_width;
369 break;
370 case WL_OUTPUT_TRANSFORM_180:
371 *scale_x = dest_width / source_width;
372 *scale_y = dest_height / source_height;
373 break;
374 case WL_OUTPUT_TRANSFORM_270:
375 *scale_x = dest_width / source_height;
376 *scale_y = dest_height / source_width;
377 break;
378 case WL_OUTPUT_TRANSFORM_NORMAL:
379 default:
380 *scale_x = dest_width / source_width;
381 *scale_y = dest_height / source_height;
382 break;
383 }
384}
385
386static void
387calc_transformation_matrix(struct ivi_rectangle *source_rect,
388 struct ivi_rectangle *dest_rect,
389 enum wl_output_transform orientation,
390 struct weston_matrix *m)
391{
392 float source_center_x;
393 float source_center_y;
394 float vsin;
395 float vcos;
396 float scale_x;
397 float scale_y;
398 float translate_x;
399 float translate_y;
400
401 source_center_x = source_rect->x + source_rect->width * 0.5f;
402 source_center_y = source_rect->y + source_rect->height * 0.5f;
403 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
404
405 get_rotate_values(orientation, &vsin, &vcos);
406 weston_matrix_rotate_xy(m, vcos, vsin);
407
408 get_scale(orientation,
409 dest_rect->width,
410 dest_rect->height,
411 source_rect->width,
412 source_rect->height,
413 &scale_x,
414 &scale_y);
415 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
416
417 translate_x = dest_rect->width * 0.5f + dest_rect->x;
418 translate_y = dest_rect->height * 0.5f + dest_rect->y;
419 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
420}
421
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900422/*
423 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900424 */
425static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900426ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
427 const struct ivi_rectangle *rect2,
428 struct ivi_rectangle *rect_output)
429{
430 int32_t rect1_right = rect1->x + rect1->width;
431 int32_t rect1_bottom = rect1->y + rect1->height;
432 int32_t rect2_right = rect2->x + rect2->width;
433 int32_t rect2_bottom = rect2->y + rect2->height;
434
435 rect_output->x = max(rect1->x, rect2->x);
436 rect_output->y = max(rect1->y, rect2->y);
437 rect_output->width = rect1_right < rect2_right ?
438 rect1_right - rect_output->x :
439 rect2_right - rect_output->x;
440 rect_output->height = rect1_bottom < rect2_bottom ?
441 rect1_bottom - rect_output->y :
442 rect2_bottom - rect_output->y;
443
444 if (rect_output->width < 0 || rect_output->height < 0) {
445 rect_output->width = 0;
446 rect_output->height = 0;
447 }
448}
449
450/*
451 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
452 * and store the result in rect_output.
453 * The boundingbox must be given in the same coordinate space as rect_output.
454 * Additionally, there are the following restrictions on the matrix:
455 * - no projective transformations
456 * - no skew
457 * - only multiples of 90-degree rotations supported
458 *
459 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
460 * as a fail-safe with log.
461 */
462static void
463calc_inverse_matrix_transform(const struct weston_matrix *matrix,
464 const struct ivi_rectangle *rect_input,
465 const struct ivi_rectangle *boundingbox,
466 struct ivi_rectangle *rect_output)
467{
468 struct weston_matrix m;
469 struct weston_vector top_left;
470 struct weston_vector bottom_right;
471
472 assert(boundingbox != rect_output);
473
474 if (weston_matrix_invert(&m, matrix) < 0) {
475 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
476 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
477 rect_output->x = boundingbox->x;
478 rect_output->y = boundingbox->y;
479 rect_output->width = boundingbox->width;
480 rect_output->height = boundingbox->height;
481 }
482
483 /* The vectors and matrices involved will always produce f[3] == 1.0. */
484 top_left.f[0] = rect_input->x;
485 top_left.f[1] = rect_input->y;
486 top_left.f[2] = 0.0f;
487 top_left.f[3] = 1.0f;
488
489 bottom_right.f[0] = rect_input->x + rect_input->width;
490 bottom_right.f[1] = rect_input->y + rect_input->height;
491 bottom_right.f[2] = 0.0f;
492 bottom_right.f[3] = 1.0f;
493
494 weston_matrix_transform(&m, &top_left);
495 weston_matrix_transform(&m, &bottom_right);
496
497 if (top_left.f[0] < bottom_right.f[0]) {
498 rect_output->x = top_left.f[0];
499 rect_output->width = bottom_right.f[0] - rect_output->x;
500 } else {
501 rect_output->x = bottom_right.f[0];
502 rect_output->width = top_left.f[0] - rect_output->x;
503 }
504
505 if (top_left.f[1] < bottom_right.f[1]) {
506 rect_output->y = top_left.f[1];
507 rect_output->height = bottom_right.f[1] - rect_output->y;
508 } else {
509 rect_output->y = bottom_right.f[1];
510 rect_output->height = top_left.f[1] - rect_output->y;
511 }
512
513 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
514}
515
516/**
517 * This computes the whole transformation matrix:m from surface-local
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900518 * coordinates to multi screens coordinate, which is global coordinates.
519 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900520 *
521 * Additionally, this computes the mask on surface-local coordinates as a
522 * ivi_rectangle. This can be set to weston_view_set_mask.
523 *
524 * The mask is computed by following steps
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900525 * - destination rectangle of layer is tansformed to multi screen coordinate,
526 * global coordinates. This is done by adding weston_output.{x,y} in simple
527 * because there is no scaled and rotated transformation.
528 * - destination rectangle of layer in multi screens coordinate needs to be
529 * intersected inside of a screen the layer is assigned to. This is because
530 * overlapped region of weston surface in another screen shall not be
531 * displayed according to ivi use case.
532 * - destination rectangle of layer
533 * - in multi screen coordinates,
534 * - and intersected inside of an assigned screen,
535 * is inversed to surface-local cooodinates by inversed matrix:m.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900536 * - the area is intersected by intersected area between weston_surface and
537 * source rectangle of ivi_surface.
538 */
539static void
540calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900541 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900542 struct ivi_layout_layer *ivilayer,
543 struct ivi_layout_surface *ivisurf,
544 struct weston_matrix *m,
545 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900546{
547 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
548 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900549 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900550 struct ivi_rectangle weston_surface_rect = { 0,
551 0,
552 ivisurf->surface->width,
553 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900554 struct ivi_rectangle surface_source_rect = { sp->source_x,
555 sp->source_y,
556 sp->source_width,
557 sp->source_height };
558 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
559 sp->dest_y,
560 sp->dest_width,
561 sp->dest_height };
562 struct ivi_rectangle layer_source_rect = { lp->source_x,
563 lp->source_y,
564 lp->source_width,
565 lp->source_height };
566 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
567 lp->dest_y,
568 lp->dest_width,
569 lp->dest_height };
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900570 struct ivi_rectangle screen_dest_rect = { output->x,
571 output->y,
572 output->width,
573 output->height };
574 struct ivi_rectangle layer_dest_rect_in_global =
575 { lp->dest_x + output->x,
576 lp->dest_y + output->y,
577 lp->dest_width,
578 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900579 struct ivi_rectangle surface_result;
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900580 struct ivi_rectangle layer_dest_rect_in_global_intersected;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900581
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900582 /*
583 * the whole transformation matrix:m from surface-local
584 * coordinates to global coordinates, which is computed by
585 * two steps,
586 * - surface-local coordinates to layer-local coordinates
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900587 * - layer-local coordinates to a single screen-local coordinates
588 * - a single screen-local coordinates to multi screen coordinates,
589 * which is global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900590 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900591 calc_transformation_matrix(&surface_source_rect,
592 &surface_dest_rect,
593 sp->orientation, m);
594
595 calc_transformation_matrix(&layer_source_rect,
596 &layer_dest_rect,
597 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900598
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900599 weston_matrix_translate(m, output->x, output->y, 0.0f);
600
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900601 /* this intersected ivi_rectangle would be used for masking
602 * weston_surface
603 */
604 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
605 &surface_result);
606
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900607 /*
608 * destination rectangle of layer in multi screens coordinate
609 * is intersected to avoid displaying outside of an assigned screen.
610 */
611 ivi_rectangle_intersect(&layer_dest_rect_in_global, &screen_dest_rect,
612 &layer_dest_rect_in_global_intersected);
613
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900614 /* calc masking area of weston_surface from m */
615 calc_inverse_matrix_transform(m,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900616 &layer_dest_rect_in_global_intersected,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900617 &surface_result,
618 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900619}
620
621static void
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900622update_prop(struct ivi_layout_screen *iviscrn,
623 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900624 struct ivi_layout_surface *ivisurf)
625{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900626 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900627 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900628 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900629
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900630 /*In case of no prop change, this just returns*/
631 if (!ivilayer->event_mask && !ivisurf->event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900632 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900633
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900634 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900635
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000636 tmpview = get_weston_view(ivisurf);
637 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900638
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900639 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
640 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
641 can_calc = false;
642 }
643
644 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
645 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
646 can_calc = false;
647 }
648
649 if (can_calc) {
650 wl_list_remove(&ivisurf->transform.link);
651 weston_matrix_init(&ivisurf->transform.matrix);
652
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900653 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900654 iviscrn, ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900655
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000656 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
657 wl_list_insert(&tmpview->geometry.transformation_list,
658 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900659
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000660 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900661 }
662
663 ivisurf->update_count++;
664
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000665 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900666
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000667 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900668}
669
670static void
671commit_changes(struct ivi_layout *layout)
672{
673 struct ivi_layout_screen *iviscrn = NULL;
674 struct ivi_layout_layer *ivilayer = NULL;
675 struct ivi_layout_surface *ivisurf = NULL;
676
677 wl_list_for_each(iviscrn, &layout->screen_list, link) {
678 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900679 /*
680 * If ivilayer is invisible, weston_view of ivisurf doesn't
681 * need to be modified.
682 */
683 if (ivilayer->prop.visibility == false)
684 continue;
685
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900686 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900687 /*
688 * If ivilayer is invisible, weston_view of ivisurf doesn't
689 * need to be modified.
690 */
691 if (ivisurf->prop.visibility == false)
692 continue;
693
694 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900695 }
696 }
697 }
698}
699
700static void
701commit_surface_list(struct ivi_layout *layout)
702{
703 struct ivi_layout_surface *ivisurf = NULL;
704 int32_t dest_x = 0;
705 int32_t dest_y = 0;
706 int32_t dest_width = 0;
707 int32_t dest_height = 0;
708 int32_t configured = 0;
709
710 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300711 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900712 dest_x = ivisurf->prop.dest_x;
713 dest_y = ivisurf->prop.dest_y;
714 dest_width = ivisurf->prop.dest_width;
715 dest_height = ivisurf->prop.dest_height;
716
717 ivi_layout_transition_move_resize_view(ivisurf,
718 ivisurf->pending.prop.dest_x,
719 ivisurf->pending.prop.dest_y,
720 ivisurf->pending.prop.dest_width,
721 ivisurf->pending.prop.dest_height,
722 ivisurf->pending.prop.transition_duration);
723
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300724 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900725 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
726 } else {
727 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
728 }
729
730 ivisurf->prop = ivisurf->pending.prop;
731 ivisurf->prop.dest_x = dest_x;
732 ivisurf->prop.dest_y = dest_y;
733 ivisurf->prop.dest_width = dest_width;
734 ivisurf->prop.dest_height = dest_height;
735 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
736 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
737
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300738 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900739 dest_x = ivisurf->prop.dest_x;
740 dest_y = ivisurf->prop.dest_y;
741 dest_width = ivisurf->prop.dest_width;
742 dest_height = ivisurf->prop.dest_height;
743
744 ivi_layout_transition_move_resize_view(ivisurf,
745 ivisurf->pending.prop.dest_x,
746 ivisurf->pending.prop.dest_y,
747 ivisurf->pending.prop.dest_width,
748 ivisurf->pending.prop.dest_height,
749 ivisurf->pending.prop.transition_duration);
750
751 ivisurf->prop = ivisurf->pending.prop;
752 ivisurf->prop.dest_x = dest_x;
753 ivisurf->prop.dest_y = dest_y;
754 ivisurf->prop.dest_width = dest_width;
755 ivisurf->prop.dest_height = dest_height;
756
757 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
758 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
759
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300760 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900761 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300762 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900763 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
764 } else {
765 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
766 }
767
768 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
769 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
770 configured = 1;
771 }
772
773 ivisurf->prop = ivisurf->pending.prop;
774 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
775 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
776
Pekka Paalanen1f821932016-03-15 16:57:51 +0200777 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200778 shell_surface_send_configure(ivisurf->surface,
779 ivisurf->prop.dest_width,
780 ivisurf->prop.dest_height);
781 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900782 } else {
783 configured = 0;
784 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
785 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
786 configured = 1;
787 }
788
789 ivisurf->prop = ivisurf->pending.prop;
790 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
791 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
792
Pekka Paalanen1f821932016-03-15 16:57:51 +0200793 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200794 shell_surface_send_configure(ivisurf->surface,
795 ivisurf->prop.dest_width,
796 ivisurf->prop.dest_height);
797 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900798 }
799 }
800}
801
802static void
803commit_layer_list(struct ivi_layout *layout)
804{
805 struct ivi_layout_layer *ivilayer = NULL;
806 struct ivi_layout_surface *ivisurf = NULL;
807 struct ivi_layout_surface *next = NULL;
808
809 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300810 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900811 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 -0300812 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900813 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
814 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
815 NULL, NULL,
816 ivilayer->pending.prop.transition_duration);
817 }
818 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
819
820 ivilayer->prop = ivilayer->pending.prop;
821
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000822 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900823 continue;
824 }
825
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000826 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
827 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000828 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000829 wl_list_remove(&ivisurf->order.link);
830 wl_list_init(&ivisurf->order.link);
831 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900832 }
833
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000834 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900835
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000836 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900837 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000838 wl_list_remove(&ivisurf->order.link);
839 wl_list_insert(&ivilayer->order.surface_list,
840 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000841 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000842 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900843 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000844
845 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900846 }
847}
848
849static void
850commit_screen_list(struct ivi_layout *layout)
851{
852 struct ivi_layout_screen *iviscrn = NULL;
853 struct ivi_layout_layer *ivilayer = NULL;
854 struct ivi_layout_layer *next = NULL;
855 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000856 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900857
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900858 /* Clear view list of layout ivi_layer */
859 wl_list_init(&layout->layout_layer.view_list.link);
860
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900861 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000862 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900863 wl_list_for_each_safe(ivilayer, next,
864 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000865 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000866 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900867 wl_list_init(&ivilayer->order.link);
868 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
869 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900870
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000871 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900872
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900873 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
874 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900875 /* FIXME: avoid to insert order.link to multiple screens */
876 wl_list_remove(&ivilayer->order.link);
877
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900878 wl_list_insert(&iviscrn->order.layer_list,
879 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000880 ivilayer->on_screen = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900881 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
882 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900883
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000884 iviscrn->order.dirty = 0;
885 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900886
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900887 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
888 if (ivilayer->prop.visibility == false)
889 continue;
890
891 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900892 if (ivisurf->prop.visibility == false)
893 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000894
895 tmpview = get_weston_view(ivisurf);
896 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900897
898 weston_layer_entry_insert(&layout->layout_layer.view_list,
899 &tmpview->layer_link);
900
901 ivisurf->surface->output = iviscrn->output;
902 }
903 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900904 }
905}
906
907static void
908commit_transition(struct ivi_layout* layout)
909{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300910 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900911 return;
912 }
913
914 wl_list_insert_list(&layout->transitions->transition_list,
915 &layout->pending_transition_list);
916
917 wl_list_init(&layout->pending_transition_list);
918
919 wl_event_source_timer_update(layout->transitions->event_source, 1);
920}
921
922static void
923send_surface_prop(struct ivi_layout_surface *ivisurf)
924{
925 wl_signal_emit(&ivisurf->property_changed, ivisurf);
926 ivisurf->event_mask = 0;
927}
928
929static void
930send_layer_prop(struct ivi_layout_layer *ivilayer)
931{
932 wl_signal_emit(&ivilayer->property_changed, ivilayer);
933 ivilayer->event_mask = 0;
934}
935
936static void
937send_prop(struct ivi_layout *layout)
938{
939 struct ivi_layout_layer *ivilayer = NULL;
940 struct ivi_layout_surface *ivisurf = NULL;
941
942 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900943 if (ivilayer->event_mask)
944 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900945 }
946
947 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900948 if (ivisurf->event_mask)
949 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900950 }
951}
952
953static void
954clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
955{
956 struct ivi_layout_surface *surface_link = NULL;
957 struct ivi_layout_surface *surface_next = NULL;
958
959 wl_list_for_each_safe(surface_link, surface_next,
960 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000961 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900962 wl_list_init(&surface_link->pending.link);
963 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900964}
965
966static void
967clear_surface_order_list(struct ivi_layout_layer *ivilayer)
968{
969 struct ivi_layout_surface *surface_link = NULL;
970 struct ivi_layout_surface *surface_next = NULL;
971
972 wl_list_for_each_safe(surface_link, surface_next,
973 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000974 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900975 wl_list_init(&surface_link->order.link);
976 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900977}
978
979static void
980layer_created(struct wl_listener *listener, void *data)
981{
982 struct ivi_layout_layer *ivilayer = data;
983
984 struct listener_layout_notification *notification =
985 container_of(listener,
986 struct listener_layout_notification,
987 listener);
988
989 struct ivi_layout_notification_callback *created_callback =
990 notification->userdata;
991
992 ((layer_create_notification_func)created_callback->callback)
993 (ivilayer, created_callback->data);
994}
995
996static void
997layer_removed(struct wl_listener *listener, void *data)
998{
999 struct ivi_layout_layer *ivilayer = data;
1000
1001 struct listener_layout_notification *notification =
1002 container_of(listener,
1003 struct listener_layout_notification,
1004 listener);
1005
1006 struct ivi_layout_notification_callback *removed_callback =
1007 notification->userdata;
1008
1009 ((layer_remove_notification_func)removed_callback->callback)
1010 (ivilayer, removed_callback->data);
1011}
1012
1013static void
1014layer_prop_changed(struct wl_listener *listener, void *data)
1015{
1016 struct ivi_layout_layer *ivilayer = data;
1017
1018 struct listener_layout_notification *layout_listener =
1019 container_of(listener,
1020 struct listener_layout_notification,
1021 listener);
1022
1023 struct ivi_layout_notification_callback *prop_callback =
1024 layout_listener->userdata;
1025
1026 ((layer_property_notification_func)prop_callback->callback)
1027 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1028}
1029
1030static void
1031surface_created(struct wl_listener *listener, void *data)
1032{
1033 struct ivi_layout_surface *ivisurface = data;
1034
1035 struct listener_layout_notification *notification =
1036 container_of(listener,
1037 struct listener_layout_notification,
1038 listener);
1039
1040 struct ivi_layout_notification_callback *created_callback =
1041 notification->userdata;
1042
1043 ((surface_create_notification_func)created_callback->callback)
1044 (ivisurface, created_callback->data);
1045}
1046
1047static void
1048surface_removed(struct wl_listener *listener, void *data)
1049{
1050 struct ivi_layout_surface *ivisurface = data;
1051
1052 struct listener_layout_notification *notification =
1053 container_of(listener,
1054 struct listener_layout_notification,
1055 listener);
1056
1057 struct ivi_layout_notification_callback *removed_callback =
1058 notification->userdata;
1059
1060 ((surface_remove_notification_func)removed_callback->callback)
1061 (ivisurface, removed_callback->data);
1062}
1063
1064static void
1065surface_prop_changed(struct wl_listener *listener, void *data)
1066{
1067 struct ivi_layout_surface *ivisurf = data;
1068
1069 struct listener_layout_notification *layout_listener =
1070 container_of(listener,
1071 struct listener_layout_notification,
1072 listener);
1073
1074 struct ivi_layout_notification_callback *prop_callback =
1075 layout_listener->userdata;
1076
1077 ((surface_property_notification_func)prop_callback->callback)
1078 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1079
1080 ivisurf->event_mask = 0;
1081}
1082
1083static void
1084surface_configure_changed(struct wl_listener *listener,
1085 void *data)
1086{
1087 struct ivi_layout_surface *ivisurface = data;
1088
1089 struct listener_layout_notification *notification =
1090 container_of(listener,
1091 struct listener_layout_notification,
1092 listener);
1093
1094 struct ivi_layout_notification_callback *configure_changed_callback =
1095 notification->userdata;
1096
1097 ((surface_configure_notification_func)configure_changed_callback->callback)
1098 (ivisurface, configure_changed_callback->data);
1099}
1100
1101static int32_t
1102add_notification(struct wl_signal *signal,
1103 wl_notify_func_t callback,
1104 void *userdata)
1105{
1106 struct listener_layout_notification *notification = NULL;
1107
1108 notification = malloc(sizeof *notification);
1109 if (notification == NULL) {
1110 weston_log("fails to allocate memory\n");
1111 free(userdata);
1112 return IVI_FAILED;
1113 }
1114
1115 notification->listener.notify = callback;
1116 notification->userdata = userdata;
1117
1118 wl_signal_add(signal, &notification->listener);
1119
1120 return IVI_SUCCEEDED;
1121}
1122
1123static void
1124remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1125{
1126 struct wl_listener *listener = NULL;
1127 struct wl_listener *next = NULL;
1128
1129 wl_list_for_each_safe(listener, next, listener_list, link) {
1130 struct listener_layout_notification *notification =
1131 container_of(listener,
1132 struct listener_layout_notification,
1133 listener);
1134
1135 struct ivi_layout_notification_callback *notification_callback =
1136 notification->userdata;
1137
1138 if ((notification_callback->callback != callback) ||
1139 (notification_callback->data != userdata)) {
1140 continue;
1141 }
1142
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001143 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001144
1145 free(notification->userdata);
1146 free(notification);
1147 }
1148}
1149
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001150/**
1151 * Exported APIs of ivi-layout library are implemented from here.
1152 * Brief of APIs is described in ivi-layout-export.h.
1153 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001154static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001155ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1156 void *userdata)
1157{
1158 struct ivi_layout *layout = get_instance();
1159 struct ivi_layout_notification_callback *created_callback = NULL;
1160
1161 if (callback == NULL) {
1162 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1163 return IVI_FAILED;
1164 }
1165
1166 created_callback = malloc(sizeof *created_callback);
1167 if (created_callback == NULL) {
1168 weston_log("fails to allocate memory\n");
1169 return IVI_FAILED;
1170 }
1171
1172 created_callback->callback = callback;
1173 created_callback->data = userdata;
1174
1175 return add_notification(&layout->layer_notification.created,
1176 layer_created,
1177 created_callback);
1178}
1179
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001180static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001181ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1182 void *userdata)
1183{
1184 struct ivi_layout *layout = get_instance();
1185 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1186}
1187
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001188static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001189ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1190 void *userdata)
1191{
1192 struct ivi_layout *layout = get_instance();
1193 struct ivi_layout_notification_callback *removed_callback = NULL;
1194
1195 if (callback == NULL) {
1196 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1197 return IVI_FAILED;
1198 }
1199
1200 removed_callback = malloc(sizeof *removed_callback);
1201 if (removed_callback == NULL) {
1202 weston_log("fails to allocate memory\n");
1203 return IVI_FAILED;
1204 }
1205
1206 removed_callback->callback = callback;
1207 removed_callback->data = userdata;
1208 return add_notification(&layout->layer_notification.removed,
1209 layer_removed,
1210 removed_callback);
1211}
1212
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001213static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001214ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1215 void *userdata)
1216{
1217 struct ivi_layout *layout = get_instance();
1218 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1219}
1220
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001221static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001222ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1223 void *userdata)
1224{
1225 struct ivi_layout *layout = get_instance();
1226 struct ivi_layout_notification_callback *created_callback = NULL;
1227
1228 if (callback == NULL) {
1229 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1230 return IVI_FAILED;
1231 }
1232
1233 created_callback = malloc(sizeof *created_callback);
1234 if (created_callback == NULL) {
1235 weston_log("fails to allocate memory\n");
1236 return IVI_FAILED;
1237 }
1238
1239 created_callback->callback = callback;
1240 created_callback->data = userdata;
1241
1242 return add_notification(&layout->surface_notification.created,
1243 surface_created,
1244 created_callback);
1245}
1246
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001247static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001248ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1249 void *userdata)
1250{
1251 struct ivi_layout *layout = get_instance();
1252 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1253}
1254
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001255static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001256ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1257 void *userdata)
1258{
1259 struct ivi_layout *layout = get_instance();
1260 struct ivi_layout_notification_callback *removed_callback = NULL;
1261
1262 if (callback == NULL) {
1263 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1264 return IVI_FAILED;
1265 }
1266
1267 removed_callback = malloc(sizeof *removed_callback);
1268 if (removed_callback == NULL) {
1269 weston_log("fails to allocate memory\n");
1270 return IVI_FAILED;
1271 }
1272
1273 removed_callback->callback = callback;
1274 removed_callback->data = userdata;
1275
1276 return add_notification(&layout->surface_notification.removed,
1277 surface_removed,
1278 removed_callback);
1279}
1280
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001281static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001282ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1283 void *userdata)
1284{
1285 struct ivi_layout *layout = get_instance();
1286 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1287}
1288
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001289static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001290ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1291 void *userdata)
1292{
1293 struct ivi_layout *layout = get_instance();
1294 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1295 if (callback == NULL) {
1296 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1297 return IVI_FAILED;
1298 }
1299
1300 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1301 if (configure_changed_callback == NULL) {
1302 weston_log("fails to allocate memory\n");
1303 return IVI_FAILED;
1304 }
1305
1306 configure_changed_callback->callback = callback;
1307 configure_changed_callback->data = userdata;
1308
1309 return add_notification(&layout->surface_notification.configure_changed,
1310 surface_configure_changed,
1311 configure_changed_callback);
1312}
1313
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001314static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001315ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1316 void *userdata)
1317{
1318 struct ivi_layout *layout = get_instance();
1319 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1320}
1321
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001322uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001323ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1324{
1325 return ivisurf->id_surface;
1326}
1327
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001328static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001329ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1330{
1331 return ivilayer->id_layer;
1332}
1333
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001334static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001335ivi_layout_get_layer_from_id(uint32_t id_layer)
1336{
1337 struct ivi_layout *layout = get_instance();
1338 struct ivi_layout_layer *ivilayer = NULL;
1339
1340 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1341 if (ivilayer->id_layer == id_layer) {
1342 return ivilayer;
1343 }
1344 }
1345
1346 return NULL;
1347}
1348
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001349struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001350ivi_layout_get_surface_from_id(uint32_t id_surface)
1351{
1352 struct ivi_layout *layout = get_instance();
1353 struct ivi_layout_surface *ivisurf = NULL;
1354
1355 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1356 if (ivisurf->id_surface == id_surface) {
1357 return ivisurf;
1358 }
1359 }
1360
1361 return NULL;
1362}
1363
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001364static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001365ivi_layout_get_screen_from_id(uint32_t id_screen)
1366{
1367 struct ivi_layout *layout = get_instance();
1368 struct ivi_layout_screen *iviscrn = NULL;
1369
1370 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)1e344dc2016-03-17 15:30:27 +00001371 if (iviscrn->output->id == id_screen)
Nobuhiko Tanibata3e710d12015-11-25 23:36:09 +09001372 return iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001373 }
1374
1375 return NULL;
1376}
1377
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001378static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001379ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1380 surface_property_notification_func callback,
1381 void *userdata)
1382{
1383 struct listener_layout_notification* notification = NULL;
1384 struct ivi_layout_notification_callback *prop_callback = NULL;
1385
1386 if (ivisurf == NULL || callback == NULL) {
1387 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1388 return IVI_FAILED;
1389 }
1390
1391 notification = malloc(sizeof *notification);
1392 if (notification == NULL) {
1393 weston_log("fails to allocate memory\n");
1394 return IVI_FAILED;
1395 }
1396
1397 prop_callback = malloc(sizeof *prop_callback);
1398 if (prop_callback == NULL) {
1399 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001400 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001401 return IVI_FAILED;
1402 }
1403
1404 prop_callback->callback = callback;
1405 prop_callback->data = userdata;
1406
1407 notification->listener.notify = surface_prop_changed;
1408 notification->userdata = prop_callback;
1409
1410 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1411
1412 return IVI_SUCCEEDED;
1413}
1414
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001415static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001416ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1417{
1418 if (ivilayer == NULL) {
1419 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1420 return NULL;
1421 }
1422
1423 return &ivilayer->prop;
1424}
1425
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001426static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001427ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1428 int32_t *pLength,
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001429 struct weston_output ***ppArray)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001430{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001431 int32_t length = 0;
1432 int32_t n = 0;
1433
1434 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1435 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1436 return IVI_FAILED;
1437 }
1438
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001439 if (ivilayer->on_screen != NULL)
1440 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001441
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001442 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001443 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001444 *ppArray = calloc(length, sizeof(struct weston_output *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001445 if (*ppArray == NULL) {
1446 weston_log("fails to allocate memory\n");
1447 return IVI_FAILED;
1448 }
1449
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001450 (*ppArray)[n++] = ivilayer->on_screen->output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001451 }
1452
1453 *pLength = length;
1454
1455 return IVI_SUCCEEDED;
1456}
1457
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001458static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001459ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1460{
1461 struct ivi_layout *layout = get_instance();
1462 struct ivi_layout_layer *ivilayer = NULL;
1463 int32_t length = 0;
1464 int32_t n = 0;
1465
1466 if (pLength == NULL || ppArray == NULL) {
1467 weston_log("ivi_layout_get_layers: invalid argument\n");
1468 return IVI_FAILED;
1469 }
1470
1471 length = wl_list_length(&layout->layer_list);
1472
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001473 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001474 /* the Array must be free by module which called this function */
1475 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1476 if (*ppArray == NULL) {
1477 weston_log("fails to allocate memory\n");
1478 return IVI_FAILED;
1479 }
1480
1481 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1482 (*ppArray)[n++] = ivilayer;
1483 }
1484 }
1485
1486 *pLength = length;
1487
1488 return IVI_SUCCEEDED;
1489}
1490
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001491static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001492ivi_layout_get_layers_on_screen(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001493 int32_t *pLength,
1494 struct ivi_layout_layer ***ppArray)
1495{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001496 struct ivi_layout_screen *iviscrn = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001497 struct ivi_layout_layer *ivilayer = NULL;
1498 int32_t length = 0;
1499 int32_t n = 0;
1500
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001501 if (output == NULL || pLength == NULL || ppArray == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001502 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1503 return IVI_FAILED;
1504 }
1505
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001506 iviscrn = get_screen_from_output(output);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001507 length = wl_list_length(&iviscrn->order.layer_list);
1508
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001509 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001510 /* the Array must be free by module which called this function */
1511 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1512 if (*ppArray == NULL) {
1513 weston_log("fails to allocate memory\n");
1514 return IVI_FAILED;
1515 }
1516
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001517 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001518 (*ppArray)[n++] = ivilayer;
1519 }
1520 }
1521
1522 *pLength = length;
1523
1524 return IVI_SUCCEEDED;
1525}
1526
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001527static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001528ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1529 int32_t *pLength,
1530 struct ivi_layout_layer ***ppArray)
1531{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001532 int32_t length = 0;
1533 int32_t n = 0;
1534
1535 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1536 weston_log("ivi_layout_getLayers: invalid argument\n");
1537 return IVI_FAILED;
1538 }
1539
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001540 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001541 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001542 length = 1;
1543 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001544 if (*ppArray == NULL) {
1545 weston_log("fails to allocate memory\n");
1546 return IVI_FAILED;
1547 }
1548
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001549 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001550 }
1551
1552 *pLength = length;
1553
1554 return IVI_SUCCEEDED;
1555}
1556
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001557static
1558int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001559ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1560{
1561 struct ivi_layout *layout = get_instance();
1562 struct ivi_layout_surface *ivisurf = NULL;
1563 int32_t length = 0;
1564 int32_t n = 0;
1565
1566 if (pLength == NULL || ppArray == NULL) {
1567 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1568 return IVI_FAILED;
1569 }
1570
1571 length = wl_list_length(&layout->surface_list);
1572
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001573 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001574 /* the Array must be free by module which called this function */
1575 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1576 if (*ppArray == NULL) {
1577 weston_log("fails to allocate memory\n");
1578 return IVI_FAILED;
1579 }
1580
1581 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1582 (*ppArray)[n++] = ivisurf;
1583 }
1584 }
1585
1586 *pLength = length;
1587
1588 return IVI_SUCCEEDED;
1589}
1590
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001591static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001592ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1593 int32_t *pLength,
1594 struct ivi_layout_surface ***ppArray)
1595{
1596 struct ivi_layout_surface *ivisurf = NULL;
1597 int32_t length = 0;
1598 int32_t n = 0;
1599
1600 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1601 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1602 return IVI_FAILED;
1603 }
1604
1605 length = wl_list_length(&ivilayer->order.surface_list);
1606
1607 if (length != 0) {
1608 /* the Array must be free by module which called this function */
1609 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1610 if (*ppArray == NULL) {
1611 weston_log("fails to allocate memory\n");
1612 return IVI_FAILED;
1613 }
1614
1615 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1616 (*ppArray)[n++] = ivisurf;
1617 }
1618 }
1619
1620 *pLength = length;
1621
1622 return IVI_SUCCEEDED;
1623}
1624
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001625static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001626ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1627 int32_t width, int32_t height)
1628{
1629 struct ivi_layout *layout = get_instance();
1630 struct ivi_layout_layer *ivilayer = NULL;
1631
1632 ivilayer = get_layer(&layout->layer_list, id_layer);
1633 if (ivilayer != NULL) {
1634 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001635 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001636 return ivilayer;
1637 }
1638
1639 ivilayer = calloc(1, sizeof *ivilayer);
1640 if (ivilayer == NULL) {
1641 weston_log("fails to allocate memory\n");
1642 return NULL;
1643 }
1644
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001645 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001646 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001647 ivilayer->layout = layout;
1648 ivilayer->id_layer = id_layer;
1649
1650 init_layer_properties(&ivilayer->prop, width, height);
1651 ivilayer->event_mask = 0;
1652
1653 wl_list_init(&ivilayer->pending.surface_list);
1654 wl_list_init(&ivilayer->pending.link);
1655 ivilayer->pending.prop = ivilayer->prop;
1656
1657 wl_list_init(&ivilayer->order.surface_list);
1658 wl_list_init(&ivilayer->order.link);
1659
1660 wl_list_insert(&layout->layer_list, &ivilayer->link);
1661
1662 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1663
1664 return ivilayer;
1665}
1666
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001667static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001668ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1669{
1670 if (ivilayer == NULL) {
1671 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1672 return;
1673 }
1674
1675 remove_all_notification(&ivilayer->property_changed.listener_list);
1676}
1677
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001678static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001679ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1680 layer_property_notification_func callback,
1681 void *userdata)
1682{
1683 if (ivilayer == NULL) {
1684 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1685 return;
1686 }
1687
1688 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1689}
1690
1691static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001692ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001693{
1694 struct ivi_layout *layout = get_instance();
1695
1696 if (ivilayer == NULL) {
1697 weston_log("ivi_layout_layer_remove: invalid argument\n");
1698 return;
1699 }
1700
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001701 if (--ivilayer->ref_count > 0)
1702 return;
1703
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001704 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1705
1706 clear_surface_pending_list(ivilayer);
1707 clear_surface_order_list(ivilayer);
1708
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001709 wl_list_remove(&ivilayer->pending.link);
1710 wl_list_remove(&ivilayer->order.link);
1711 wl_list_remove(&ivilayer->link);
1712
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001713 ivi_layout_layer_remove_notification(ivilayer);
1714
1715 free(ivilayer);
1716}
1717
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001718int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001719ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1720 bool newVisibility)
1721{
1722 struct ivi_layout_layer_properties *prop = NULL;
1723
1724 if (ivilayer == NULL) {
1725 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1726 return IVI_FAILED;
1727 }
1728
1729 prop = &ivilayer->pending.prop;
1730 prop->visibility = newVisibility;
1731
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001732 if (ivilayer->prop.visibility != newVisibility)
1733 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1734 else
1735 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001736
1737 return IVI_SUCCEEDED;
1738}
1739
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001740int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001741ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1742 wl_fixed_t opacity)
1743{
1744 struct ivi_layout_layer_properties *prop = NULL;
1745
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001746 if (ivilayer == NULL ||
1747 opacity < wl_fixed_from_double(0.0) ||
1748 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001749 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1750 return IVI_FAILED;
1751 }
1752
1753 prop = &ivilayer->pending.prop;
1754 prop->opacity = opacity;
1755
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001756 if (ivilayer->prop.opacity != opacity)
1757 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1758 else
1759 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001760
1761 return IVI_SUCCEEDED;
1762}
1763
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001764static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001765ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1766 int32_t x, int32_t y,
1767 int32_t width, int32_t height)
1768{
1769 struct ivi_layout_layer_properties *prop = NULL;
1770
1771 if (ivilayer == NULL) {
1772 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1773 return IVI_FAILED;
1774 }
1775
1776 prop = &ivilayer->pending.prop;
1777 prop->source_x = x;
1778 prop->source_y = y;
1779 prop->source_width = width;
1780 prop->source_height = height;
1781
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001782 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1783 ivilayer->prop.source_width != width ||
1784 ivilayer->prop.source_height != height)
1785 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1786 else
1787 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001788
1789 return IVI_SUCCEEDED;
1790}
1791
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001792int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001793ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1794 int32_t x, int32_t y,
1795 int32_t width, int32_t height)
1796{
1797 struct ivi_layout_layer_properties *prop = NULL;
1798
1799 if (ivilayer == NULL) {
1800 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1801 return IVI_FAILED;
1802 }
1803
1804 prop = &ivilayer->pending.prop;
1805 prop->dest_x = x;
1806 prop->dest_y = y;
1807 prop->dest_width = width;
1808 prop->dest_height = height;
1809
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001810 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1811 ivilayer->prop.dest_width != width ||
1812 ivilayer->prop.dest_height != height)
1813 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1814 else
1815 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001816
1817 return IVI_SUCCEEDED;
1818}
1819
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001820static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001821ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1822 enum wl_output_transform orientation)
1823{
1824 struct ivi_layout_layer_properties *prop = NULL;
1825
1826 if (ivilayer == NULL) {
1827 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1828 return IVI_FAILED;
1829 }
1830
1831 prop = &ivilayer->pending.prop;
1832 prop->orientation = orientation;
1833
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001834 if (ivilayer->prop.orientation != orientation)
1835 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1836 else
1837 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001838
1839 return IVI_SUCCEEDED;
1840}
1841
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001842int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001843ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1844 struct ivi_layout_surface **pSurface,
1845 int32_t number)
1846{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001847 int32_t i = 0;
1848
1849 if (ivilayer == NULL) {
1850 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1851 return IVI_FAILED;
1852 }
1853
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001854 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001855
1856 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)72ad1642016-03-16 13:37:05 +00001857 wl_list_remove(&pSurface[i]->pending.link);
1858 wl_list_insert(&ivilayer->pending.surface_list,
1859 &pSurface[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001860 }
1861
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001862 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001863
1864 return IVI_SUCCEEDED;
1865}
1866
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001867int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001868ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1869 bool newVisibility)
1870{
1871 struct ivi_layout_surface_properties *prop = NULL;
1872
1873 if (ivisurf == NULL) {
1874 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1875 return IVI_FAILED;
1876 }
1877
1878 prop = &ivisurf->pending.prop;
1879 prop->visibility = newVisibility;
1880
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001881 if (ivisurf->prop.visibility != newVisibility)
1882 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1883 else
1884 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001885
1886 return IVI_SUCCEEDED;
1887}
1888
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001889int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001890ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1891 wl_fixed_t opacity)
1892{
1893 struct ivi_layout_surface_properties *prop = NULL;
1894
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001895 if (ivisurf == NULL ||
1896 opacity < wl_fixed_from_double(0.0) ||
1897 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001898 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1899 return IVI_FAILED;
1900 }
1901
1902 prop = &ivisurf->pending.prop;
1903 prop->opacity = opacity;
1904
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001905 if (ivisurf->prop.opacity != opacity)
1906 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
1907 else
1908 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001909
1910 return IVI_SUCCEEDED;
1911}
1912
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001913int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001914ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1915 int32_t x, int32_t y,
1916 int32_t width, int32_t height)
1917{
1918 struct ivi_layout_surface_properties *prop = NULL;
1919
1920 if (ivisurf == NULL) {
1921 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1922 return IVI_FAILED;
1923 }
1924
1925 prop = &ivisurf->pending.prop;
1926 prop->start_x = prop->dest_x;
1927 prop->start_y = prop->dest_y;
1928 prop->dest_x = x;
1929 prop->dest_y = y;
1930 prop->start_width = prop->dest_width;
1931 prop->start_height = prop->dest_height;
1932 prop->dest_width = width;
1933 prop->dest_height = height;
1934
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001935 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
1936 ivisurf->prop.dest_width != width ||
1937 ivisurf->prop.dest_height != height)
1938 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1939 else
1940 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001941
1942 return IVI_SUCCEEDED;
1943}
1944
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001945static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001946ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
1947 enum wl_output_transform orientation)
1948{
1949 struct ivi_layout_surface_properties *prop = NULL;
1950
1951 if (ivisurf == NULL) {
1952 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
1953 return IVI_FAILED;
1954 }
1955
1956 prop = &ivisurf->pending.prop;
1957 prop->orientation = orientation;
1958
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001959 if (ivisurf->prop.orientation != orientation)
1960 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1961 else
1962 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001963
1964 return IVI_SUCCEEDED;
1965}
1966
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001967static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001968ivi_layout_screen_add_layer(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001969 struct ivi_layout_layer *addlayer)
1970{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001971 struct ivi_layout_screen *iviscrn;
1972
1973 if (output == NULL || addlayer == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001974 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
1975 return IVI_FAILED;
1976 }
1977
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001978 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001979
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00001980 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001981 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
1982 return IVI_SUCCEEDED;
1983 }
1984
Ucan, Emre (ADITG/SW1)f46306f2016-03-16 13:37:07 +00001985 wl_list_remove(&addlayer->pending.link);
1986 wl_list_insert(&iviscrn->pending.layer_list, &addlayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001987
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001988 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001989
1990 return IVI_SUCCEEDED;
1991}
1992
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001993static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001994ivi_layout_screen_set_render_order(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001995 struct ivi_layout_layer **pLayer,
1996 const int32_t number)
1997{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001998 struct ivi_layout_screen *iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001999 struct ivi_layout_layer *ivilayer = NULL;
2000 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002001 int32_t i = 0;
2002
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00002003 if (output == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002004 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2005 return IVI_FAILED;
2006 }
2007
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00002008 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00002009
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002010 wl_list_for_each_safe(ivilayer, next,
2011 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002012 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002013 wl_list_init(&ivilayer->pending.link);
2014 }
2015
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002016 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002017
2018 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)4e221f02016-03-16 13:37:08 +00002019 wl_list_remove(&pLayer[i]->pending.link);
2020 wl_list_insert(&iviscrn->pending.layer_list,
2021 &pLayer[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002022 }
2023
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002024 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002025
2026 return IVI_SUCCEEDED;
2027}
2028
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002029static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002030ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2031{
2032 return iviscrn->output;
2033}
2034
2035/**
2036 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2037 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2038 * This function is used to get the result of drawing by clients.
2039 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002040static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002041ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2042{
2043 return ivisurf != NULL ? ivisurf->surface : NULL;
2044}
2045
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002046static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002047ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2048 int32_t *width, int32_t *height,
2049 int32_t *stride)
2050{
2051 int32_t w;
2052 int32_t h;
2053 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2054
2055 if (ivisurf == NULL || ivisurf->surface == NULL) {
2056 weston_log("%s: invalid argument\n", __func__);
2057 return IVI_FAILED;
2058 }
2059
2060 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2061
2062 if (width != NULL)
2063 *width = w;
2064
2065 if (height != NULL)
2066 *height = h;
2067
2068 if (stride != NULL)
2069 *stride = w * bytespp;
2070
2071 return IVI_SUCCEEDED;
2072}
2073
2074static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002075ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2076 layer_property_notification_func callback,
2077 void *userdata)
2078{
2079 struct ivi_layout_notification_callback *prop_callback = NULL;
2080
2081 if (ivilayer == NULL || callback == NULL) {
2082 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2083 return IVI_FAILED;
2084 }
2085
2086 prop_callback = malloc(sizeof *prop_callback);
2087 if (prop_callback == NULL) {
2088 weston_log("fails to allocate memory\n");
2089 return IVI_FAILED;
2090 }
2091
2092 prop_callback->callback = callback;
2093 prop_callback->data = userdata;
2094
2095 return add_notification(&ivilayer->property_changed,
2096 layer_prop_changed,
2097 prop_callback);
2098}
2099
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002100static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002101ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2102{
2103 if (ivisurf == NULL) {
2104 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2105 return NULL;
2106 }
2107
2108 return &ivisurf->prop;
2109}
2110
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002111static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002112ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2113 struct ivi_layout_surface *addsurf)
2114{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002115 if (ivilayer == NULL || addsurf == NULL) {
2116 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2117 return IVI_FAILED;
2118 }
2119
Wataru Natsume9c926fe2016-03-03 19:56:09 +09002120 if (addsurf->on_layer == ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002121 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002122
Ucan, Emre (ADITG/SW1)10942372016-03-16 13:37:02 +00002123 wl_list_remove(&addsurf->pending.link);
2124 wl_list_insert(&ivilayer->pending.surface_list, &addsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002125
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002126 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002127
2128 return IVI_SUCCEEDED;
2129}
2130
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002131static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002132ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2133 struct ivi_layout_surface *remsurf)
2134{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002135 if (ivilayer == NULL || remsurf == NULL) {
2136 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2137 return;
2138 }
2139
Ucan, Emre (ADITG/SW1)536d8332016-03-16 13:36:59 +00002140 wl_list_remove(&remsurf->pending.link);
2141 wl_list_init(&remsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002142
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002143 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002144}
2145
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002146static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002147ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2148 int32_t x, int32_t y,
2149 int32_t width, int32_t height)
2150{
2151 struct ivi_layout_surface_properties *prop = NULL;
2152
2153 if (ivisurf == NULL) {
2154 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2155 return IVI_FAILED;
2156 }
2157
2158 prop = &ivisurf->pending.prop;
2159 prop->source_x = x;
2160 prop->source_y = y;
2161 prop->source_width = width;
2162 prop->source_height = height;
2163
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002164 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2165 ivisurf->prop.source_width != width ||
2166 ivisurf->prop.source_height != height)
2167 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2168 else
2169 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002170
2171 return IVI_SUCCEEDED;
2172}
2173
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002174int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002175ivi_layout_commit_changes(void)
2176{
2177 struct ivi_layout *layout = get_instance();
2178
2179 commit_surface_list(layout);
2180 commit_layer_list(layout);
2181 commit_screen_list(layout);
2182
2183 commit_transition(layout);
2184
2185 commit_changes(layout);
2186 send_prop(layout);
2187 weston_compositor_schedule_repaint(layout->compositor);
2188
2189 return IVI_SUCCEEDED;
2190}
2191
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002192static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002193ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2194 enum ivi_layout_transition_type type,
2195 uint32_t duration)
2196{
2197 if (ivilayer == NULL) {
2198 weston_log("%s: invalid argument\n", __func__);
2199 return -1;
2200 }
2201
2202 ivilayer->pending.prop.transition_type = type;
2203 ivilayer->pending.prop.transition_duration = duration;
2204
2205 return 0;
2206}
2207
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002208static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002209ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2210 uint32_t is_fade_in,
2211 double start_alpha, double end_alpha)
2212{
2213 if (ivilayer == NULL) {
2214 weston_log("%s: invalid argument\n", __func__);
2215 return -1;
2216 }
2217
2218 ivilayer->pending.prop.is_fade_in = is_fade_in;
2219 ivilayer->pending.prop.start_alpha = start_alpha;
2220 ivilayer->pending.prop.end_alpha = end_alpha;
2221
2222 return 0;
2223}
2224
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002225static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002226ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2227 uint32_t duration)
2228{
2229 struct ivi_layout_surface_properties *prop;
2230
2231 if (ivisurf == NULL) {
2232 weston_log("%s: invalid argument\n", __func__);
2233 return -1;
2234 }
2235
2236 prop = &ivisurf->pending.prop;
2237 prop->transition_duration = duration*10;
2238 return 0;
2239}
2240
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002241static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002242ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2243 enum ivi_layout_transition_type type,
2244 uint32_t duration)
2245{
2246 struct ivi_layout_surface_properties *prop;
2247
2248 if (ivisurf == NULL) {
2249 weston_log("%s: invalid argument\n", __func__);
2250 return -1;
2251 }
2252
2253 prop = &ivisurf->pending.prop;
2254 prop->transition_type = type;
2255 prop->transition_duration = duration;
2256 return 0;
2257}
2258
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002259static int32_t
2260ivi_layout_surface_dump(struct weston_surface *surface,
2261 void *target, size_t size,int32_t x, int32_t y,
2262 int32_t width, int32_t height)
2263{
2264 int result = 0;
2265
2266 if (surface == NULL) {
2267 weston_log("%s: invalid argument\n", __func__);
2268 return IVI_FAILED;
2269 }
2270
2271 result = weston_surface_copy_content(
2272 surface, target, size,
2273 x, y, width, height);
2274
2275 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2276}
2277
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002278/**
2279 * methods of interaction between ivi-shell with ivi-layout
2280 */
2281struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002282ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2283{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002284 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002285 return NULL;
2286
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002287 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002288}
2289
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002290void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002291ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2292 int32_t width, int32_t height)
2293{
2294 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002295
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002296 /* emit callback which is set by ivi-layout api user */
2297 wl_signal_emit(&layout->surface_notification.configure_changed,
2298 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002299}
2300
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002301struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002302ivi_layout_surface_create(struct weston_surface *wl_surface,
2303 uint32_t id_surface)
2304{
2305 struct ivi_layout *layout = get_instance();
2306 struct ivi_layout_surface *ivisurf = NULL;
2307 struct weston_view *tmpview = NULL;
2308
2309 if (wl_surface == NULL) {
2310 weston_log("ivi_layout_surface_create: invalid argument\n");
2311 return NULL;
2312 }
2313
2314 ivisurf = get_surface(&layout->surface_list, id_surface);
2315 if (ivisurf != NULL) {
2316 if (ivisurf->surface != NULL) {
2317 weston_log("id_surface(%d) is already created\n", id_surface);
2318 return NULL;
2319 }
2320 }
2321
2322 ivisurf = calloc(1, sizeof *ivisurf);
2323 if (ivisurf == NULL) {
2324 weston_log("fails to allocate memory\n");
2325 return NULL;
2326 }
2327
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002328 wl_signal_init(&ivisurf->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002329 ivisurf->id_surface = id_surface;
2330 ivisurf->layout = layout;
2331
2332 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002333
2334 tmpview = weston_view_create(wl_surface);
2335 if (tmpview == NULL) {
2336 weston_log("fails to allocate memory\n");
2337 }
2338
2339 ivisurf->surface->width_from_buffer = 0;
2340 ivisurf->surface->height_from_buffer = 0;
2341
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002342 weston_matrix_init(&ivisurf->transform.matrix);
2343 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002344
2345 init_surface_properties(&ivisurf->prop);
2346 ivisurf->event_mask = 0;
2347
2348 ivisurf->pending.prop = ivisurf->prop;
2349 wl_list_init(&ivisurf->pending.link);
2350
2351 wl_list_init(&ivisurf->order.link);
2352 wl_list_init(&ivisurf->order.layer_list);
2353
2354 wl_list_insert(&layout->surface_list, &ivisurf->link);
2355
2356 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2357
2358 return ivisurf;
2359}
2360
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002361void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002362ivi_layout_init_with_compositor(struct weston_compositor *ec)
2363{
2364 struct ivi_layout *layout = get_instance();
2365
2366 layout->compositor = ec;
2367
2368 wl_list_init(&layout->surface_list);
2369 wl_list_init(&layout->layer_list);
2370 wl_list_init(&layout->screen_list);
2371
2372 wl_signal_init(&layout->layer_notification.created);
2373 wl_signal_init(&layout->layer_notification.removed);
2374
2375 wl_signal_init(&layout->surface_notification.created);
2376 wl_signal_init(&layout->surface_notification.removed);
2377 wl_signal_init(&layout->surface_notification.configure_changed);
2378
2379 /* Add layout_layer at the last of weston_compositor.layer_list */
2380 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2381
2382 create_screen(ec);
2383
2384 layout->transitions = ivi_layout_transition_set_create(ec);
2385 wl_list_init(&layout->pending_transition_list);
2386}
2387
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002388static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002389 /**
2390 * commit all changes
2391 */
2392 .commit_changes = ivi_layout_commit_changes,
2393
2394 /**
2395 * surface controller interfaces
2396 */
2397 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2398 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2399 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2400 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2401 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2402 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2403 .get_surfaces = ivi_layout_get_surfaces,
2404 .get_id_of_surface = ivi_layout_get_id_of_surface,
2405 .get_surface_from_id = ivi_layout_get_surface_from_id,
2406 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2407 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2408 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002409 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002410 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2411 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002412 .surface_set_orientation = ivi_layout_surface_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002413 .surface_add_notification = ivi_layout_surface_add_notification,
2414 .surface_remove_notification = ivi_layout_surface_remove_notification,
2415 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2416 .surface_set_transition = ivi_layout_surface_set_transition,
2417 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2418
2419 /**
2420 * layer controller interfaces
2421 */
2422 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2423 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2424 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2425 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2426 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002427 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002428 .get_layers = ivi_layout_get_layers,
2429 .get_id_of_layer = ivi_layout_get_id_of_layer,
2430 .get_layer_from_id = ivi_layout_get_layer_from_id,
2431 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2432 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2433 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2434 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002435 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002436 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2437 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002438 .layer_set_orientation = ivi_layout_layer_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002439 .layer_add_surface = ivi_layout_layer_add_surface,
2440 .layer_remove_surface = ivi_layout_layer_remove_surface,
2441 .layer_set_render_order = ivi_layout_layer_set_render_order,
2442 .layer_add_notification = ivi_layout_layer_add_notification,
2443 .layer_remove_notification = ivi_layout_layer_remove_notification,
2444 .layer_set_transition = ivi_layout_layer_set_transition,
2445
2446 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002447 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002448 */
2449 .get_screen_from_id = ivi_layout_get_screen_from_id,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002450 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2451 .screen_add_layer = ivi_layout_screen_add_layer,
2452 .screen_set_render_order = ivi_layout_screen_set_render_order,
2453 .screen_get_output = ivi_layout_screen_get_output,
2454
2455 /**
2456 * animation
2457 */
2458 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002459 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2460
2461 /**
2462 * surface content dumping for debugging
2463 */
2464 .surface_get_size = ivi_layout_surface_get_size,
2465 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002466
2467 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002468 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002469 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002470 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Ucan, Emre (ADITG/SW1)d56b90d2016-03-17 15:30:32 +00002471 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002472};
2473
2474int
2475load_controller_modules(struct weston_compositor *compositor, const char *modules,
2476 int *argc, char *argv[])
2477{
2478 const char *p, *end;
2479 char buffer[256];
2480 int (*controller_module_init)(struct weston_compositor *compositor,
2481 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002482 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002483 size_t interface_version);
2484
2485 if (modules == NULL)
2486 return 0;
2487
2488 p = modules;
2489 while (*p) {
2490 end = strchrnul(p, ',');
2491 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2492
2493 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002494 if (!controller_module_init)
2495 return -1;
2496
2497 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002498 &ivi_layout_interface,
2499 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002500 weston_log("ivi-shell: Initialization of controller module fails");
2501 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002502 }
2503
2504 p = end;
2505 while (*p == ',')
2506 p++;
2507 }
2508
2509 return 0;
2510}