blob: 17a3fc99157e5ec5fabb152a715b18693148ad9a [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
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900170static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900171remove_all_notification(struct wl_list *listener_list)
172{
173 struct wl_listener *listener = NULL;
174 struct wl_listener *next = NULL;
175
176 wl_list_for_each_safe(listener, next, listener_list, link) {
177 struct listener_layout_notification *notification = NULL;
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000178 wl_list_remove(&listener->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900179
180 notification =
181 container_of(listener,
182 struct listener_layout_notification,
183 listener);
184
185 free(notification->userdata);
186 free(notification);
187 }
188}
189
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900190static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900191ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
192{
193 if (ivisurf == NULL) {
194 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
195 return;
196 }
197
198 remove_all_notification(&ivisurf->property_changed.listener_list);
199}
200
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900201static void
202ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
203 surface_property_notification_func callback,
204 void *userdata)
205{
206 if (ivisurf == NULL) {
207 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
208 return;
209 }
210
211 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
212}
213
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900214/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900215 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900216 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900217void
218ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900219{
220 struct ivi_layout *layout = get_instance();
221
222 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900223 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900224 return;
225 }
226
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900227 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900228 wl_list_remove(&ivisurf->pending.link);
229 wl_list_remove(&ivisurf->order.link);
230 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900231
232 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
233
Mateusz Polroladada6e32016-03-09 09:13:26 +0000234 ivi_layout_remove_all_surface_transitions(ivisurf);
235
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900236 ivi_layout_surface_remove_notification(ivisurf);
237
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900238 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900239}
240
241/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900242 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
243 * Called by ivi_layout_init_with_compositor.
244 */
245static void
246create_screen(struct weston_compositor *ec)
247{
248 struct ivi_layout *layout = get_instance();
249 struct ivi_layout_screen *iviscrn = NULL;
250 struct weston_output *output = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900251
252 wl_list_for_each(output, &ec->output_list, link) {
253 iviscrn = calloc(1, sizeof *iviscrn);
254 if (iviscrn == NULL) {
255 weston_log("fails to allocate memory\n");
256 continue;
257 }
258
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900259 iviscrn->layout = layout;
260
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900261 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900262
263 wl_list_init(&iviscrn->pending.layer_list);
264 wl_list_init(&iviscrn->pending.link);
265
266 wl_list_init(&iviscrn->order.layer_list);
267 wl_list_init(&iviscrn->order.link);
268
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900269 wl_list_insert(&layout->screen_list, &iviscrn->link);
270 }
271}
272
273/**
274 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
275 */
276static void
277init_layer_properties(struct ivi_layout_layer_properties *prop,
278 int32_t width, int32_t height)
279{
280 memset(prop, 0, sizeof *prop);
281 prop->opacity = wl_fixed_from_double(1.0);
282 prop->source_width = width;
283 prop->source_height = height;
284 prop->dest_width = width;
285 prop->dest_height = height;
286}
287
288static void
289init_surface_properties(struct ivi_layout_surface_properties *prop)
290{
291 memset(prop, 0, sizeof *prop);
292 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900293 /*
294 * FIXME: this shall be finxed by ivi-layout-transition.
295 */
296 prop->dest_width = 1;
297 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900298}
299
300/**
301 * Internal APIs to be called from ivi_layout_commit_changes.
302 */
303static void
304update_opacity(struct ivi_layout_layer *ivilayer,
305 struct ivi_layout_surface *ivisurf)
306{
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000307 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900308 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
309 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
310
Nobuhiko Tanibata90c27892015-12-26 23:52:51 +0900311 tmpview = get_weston_view(ivisurf);
312 assert(tmpview != NULL);
313 tmpview->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900314}
315
316static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900317get_rotate_values(enum wl_output_transform orientation,
318 float *v_sin,
319 float *v_cos)
320{
321 switch (orientation) {
322 case WL_OUTPUT_TRANSFORM_90:
323 *v_sin = 1.0f;
324 *v_cos = 0.0f;
325 break;
326 case WL_OUTPUT_TRANSFORM_180:
327 *v_sin = 0.0f;
328 *v_cos = -1.0f;
329 break;
330 case WL_OUTPUT_TRANSFORM_270:
331 *v_sin = -1.0f;
332 *v_cos = 0.0f;
333 break;
334 case WL_OUTPUT_TRANSFORM_NORMAL:
335 default:
336 *v_sin = 0.0f;
337 *v_cos = 1.0f;
338 break;
339 }
340}
341
342static void
343get_scale(enum wl_output_transform orientation,
344 float dest_width,
345 float dest_height,
346 float source_width,
347 float source_height,
348 float *scale_x,
349 float *scale_y)
350{
351 switch (orientation) {
352 case WL_OUTPUT_TRANSFORM_90:
353 *scale_x = dest_width / source_height;
354 *scale_y = dest_height / source_width;
355 break;
356 case WL_OUTPUT_TRANSFORM_180:
357 *scale_x = dest_width / source_width;
358 *scale_y = dest_height / source_height;
359 break;
360 case WL_OUTPUT_TRANSFORM_270:
361 *scale_x = dest_width / source_height;
362 *scale_y = dest_height / source_width;
363 break;
364 case WL_OUTPUT_TRANSFORM_NORMAL:
365 default:
366 *scale_x = dest_width / source_width;
367 *scale_y = dest_height / source_height;
368 break;
369 }
370}
371
372static void
373calc_transformation_matrix(struct ivi_rectangle *source_rect,
374 struct ivi_rectangle *dest_rect,
375 enum wl_output_transform orientation,
376 struct weston_matrix *m)
377{
378 float source_center_x;
379 float source_center_y;
380 float vsin;
381 float vcos;
382 float scale_x;
383 float scale_y;
384 float translate_x;
385 float translate_y;
386
387 source_center_x = source_rect->x + source_rect->width * 0.5f;
388 source_center_y = source_rect->y + source_rect->height * 0.5f;
389 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
390
391 get_rotate_values(orientation, &vsin, &vcos);
392 weston_matrix_rotate_xy(m, vcos, vsin);
393
394 get_scale(orientation,
395 dest_rect->width,
396 dest_rect->height,
397 source_rect->width,
398 source_rect->height,
399 &scale_x,
400 &scale_y);
401 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
402
403 translate_x = dest_rect->width * 0.5f + dest_rect->x;
404 translate_y = dest_rect->height * 0.5f + dest_rect->y;
405 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
406}
407
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900408/*
409 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900410 */
411static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900412ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
413 const struct ivi_rectangle *rect2,
414 struct ivi_rectangle *rect_output)
415{
416 int32_t rect1_right = rect1->x + rect1->width;
417 int32_t rect1_bottom = rect1->y + rect1->height;
418 int32_t rect2_right = rect2->x + rect2->width;
419 int32_t rect2_bottom = rect2->y + rect2->height;
420
421 rect_output->x = max(rect1->x, rect2->x);
422 rect_output->y = max(rect1->y, rect2->y);
423 rect_output->width = rect1_right < rect2_right ?
424 rect1_right - rect_output->x :
425 rect2_right - rect_output->x;
426 rect_output->height = rect1_bottom < rect2_bottom ?
427 rect1_bottom - rect_output->y :
428 rect2_bottom - rect_output->y;
429
430 if (rect_output->width < 0 || rect_output->height < 0) {
431 rect_output->width = 0;
432 rect_output->height = 0;
433 }
434}
435
436/*
437 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
438 * and store the result in rect_output.
439 * The boundingbox must be given in the same coordinate space as rect_output.
440 * Additionally, there are the following restrictions on the matrix:
441 * - no projective transformations
442 * - no skew
443 * - only multiples of 90-degree rotations supported
444 *
445 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
446 * as a fail-safe with log.
447 */
448static void
449calc_inverse_matrix_transform(const struct weston_matrix *matrix,
450 const struct ivi_rectangle *rect_input,
451 const struct ivi_rectangle *boundingbox,
452 struct ivi_rectangle *rect_output)
453{
454 struct weston_matrix m;
455 struct weston_vector top_left;
456 struct weston_vector bottom_right;
457
458 assert(boundingbox != rect_output);
459
460 if (weston_matrix_invert(&m, matrix) < 0) {
461 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
462 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
463 rect_output->x = boundingbox->x;
464 rect_output->y = boundingbox->y;
465 rect_output->width = boundingbox->width;
466 rect_output->height = boundingbox->height;
467 }
468
469 /* The vectors and matrices involved will always produce f[3] == 1.0. */
470 top_left.f[0] = rect_input->x;
471 top_left.f[1] = rect_input->y;
472 top_left.f[2] = 0.0f;
473 top_left.f[3] = 1.0f;
474
475 bottom_right.f[0] = rect_input->x + rect_input->width;
476 bottom_right.f[1] = rect_input->y + rect_input->height;
477 bottom_right.f[2] = 0.0f;
478 bottom_right.f[3] = 1.0f;
479
480 weston_matrix_transform(&m, &top_left);
481 weston_matrix_transform(&m, &bottom_right);
482
483 if (top_left.f[0] < bottom_right.f[0]) {
484 rect_output->x = top_left.f[0];
485 rect_output->width = bottom_right.f[0] - rect_output->x;
486 } else {
487 rect_output->x = bottom_right.f[0];
488 rect_output->width = top_left.f[0] - rect_output->x;
489 }
490
491 if (top_left.f[1] < bottom_right.f[1]) {
492 rect_output->y = top_left.f[1];
493 rect_output->height = bottom_right.f[1] - rect_output->y;
494 } else {
495 rect_output->y = bottom_right.f[1];
496 rect_output->height = top_left.f[1] - rect_output->y;
497 }
498
499 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
500}
501
502/**
503 * This computes the whole transformation matrix:m from surface-local
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900504 * coordinates to multi screens coordinate, which is global coordinates.
505 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900506 *
507 * Additionally, this computes the mask on surface-local coordinates as a
508 * ivi_rectangle. This can be set to weston_view_set_mask.
509 *
510 * The mask is computed by following steps
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900511 * - destination rectangle of layer is tansformed to multi screen coordinate,
512 * global coordinates. This is done by adding weston_output.{x,y} in simple
513 * because there is no scaled and rotated transformation.
514 * - destination rectangle of layer in multi screens coordinate needs to be
515 * intersected inside of a screen the layer is assigned to. This is because
516 * overlapped region of weston surface in another screen shall not be
517 * displayed according to ivi use case.
518 * - destination rectangle of layer
519 * - in multi screen coordinates,
520 * - and intersected inside of an assigned screen,
521 * is inversed to surface-local cooodinates by inversed matrix:m.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900522 * - the area is intersected by intersected area between weston_surface and
523 * source rectangle of ivi_surface.
524 */
525static void
526calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900527 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900528 struct ivi_layout_layer *ivilayer,
529 struct ivi_layout_surface *ivisurf,
530 struct weston_matrix *m,
531 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900532{
533 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
534 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900535 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900536 struct ivi_rectangle weston_surface_rect = { 0,
537 0,
538 ivisurf->surface->width,
539 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900540 struct ivi_rectangle surface_source_rect = { sp->source_x,
541 sp->source_y,
542 sp->source_width,
543 sp->source_height };
544 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
545 sp->dest_y,
546 sp->dest_width,
547 sp->dest_height };
548 struct ivi_rectangle layer_source_rect = { lp->source_x,
549 lp->source_y,
550 lp->source_width,
551 lp->source_height };
552 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
553 lp->dest_y,
554 lp->dest_width,
555 lp->dest_height };
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900556 struct ivi_rectangle screen_dest_rect = { output->x,
557 output->y,
558 output->width,
559 output->height };
560 struct ivi_rectangle layer_dest_rect_in_global =
561 { lp->dest_x + output->x,
562 lp->dest_y + output->y,
563 lp->dest_width,
564 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900565 struct ivi_rectangle surface_result;
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900566 struct ivi_rectangle layer_dest_rect_in_global_intersected;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900567
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900568 /*
569 * the whole transformation matrix:m from surface-local
570 * coordinates to global coordinates, which is computed by
571 * two steps,
572 * - surface-local coordinates to layer-local coordinates
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900573 * - layer-local coordinates to a single screen-local coordinates
574 * - a single screen-local coordinates to multi screen coordinates,
575 * which is global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900576 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900577 calc_transformation_matrix(&surface_source_rect,
578 &surface_dest_rect,
579 sp->orientation, m);
580
581 calc_transformation_matrix(&layer_source_rect,
582 &layer_dest_rect,
583 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900584
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900585 weston_matrix_translate(m, output->x, output->y, 0.0f);
586
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900587 /* this intersected ivi_rectangle would be used for masking
588 * weston_surface
589 */
590 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
591 &surface_result);
592
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900593 /*
594 * destination rectangle of layer in multi screens coordinate
595 * is intersected to avoid displaying outside of an assigned screen.
596 */
597 ivi_rectangle_intersect(&layer_dest_rect_in_global, &screen_dest_rect,
598 &layer_dest_rect_in_global_intersected);
599
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900600 /* calc masking area of weston_surface from m */
601 calc_inverse_matrix_transform(m,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900602 &layer_dest_rect_in_global_intersected,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900603 &surface_result,
604 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900605}
606
607static void
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900608update_prop(struct ivi_layout_screen *iviscrn,
609 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900610 struct ivi_layout_surface *ivisurf)
611{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900612 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900613 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900614 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900615
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900616 /*In case of no prop change, this just returns*/
617 if (!ivilayer->event_mask && !ivisurf->event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900618 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900619
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900620 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900621
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000622 tmpview = get_weston_view(ivisurf);
623 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900624
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900625 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
626 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
627 can_calc = false;
628 }
629
630 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
631 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
632 can_calc = false;
633 }
634
635 if (can_calc) {
636 wl_list_remove(&ivisurf->transform.link);
637 weston_matrix_init(&ivisurf->transform.matrix);
638
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900639 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900640 iviscrn, ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900641
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000642 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
643 wl_list_insert(&tmpview->geometry.transformation_list,
644 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900645
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000646 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900647 }
648
649 ivisurf->update_count++;
650
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000651 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900652
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000653 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900654}
655
656static void
657commit_changes(struct ivi_layout *layout)
658{
659 struct ivi_layout_screen *iviscrn = NULL;
660 struct ivi_layout_layer *ivilayer = NULL;
661 struct ivi_layout_surface *ivisurf = NULL;
662
663 wl_list_for_each(iviscrn, &layout->screen_list, link) {
664 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900665 /*
666 * If ivilayer is invisible, weston_view of ivisurf doesn't
667 * need to be modified.
668 */
669 if (ivilayer->prop.visibility == false)
670 continue;
671
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900672 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900673 /*
674 * If ivilayer is invisible, weston_view of ivisurf doesn't
675 * need to be modified.
676 */
677 if (ivisurf->prop.visibility == false)
678 continue;
679
680 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900681 }
682 }
683 }
684}
685
686static void
687commit_surface_list(struct ivi_layout *layout)
688{
689 struct ivi_layout_surface *ivisurf = NULL;
690 int32_t dest_x = 0;
691 int32_t dest_y = 0;
692 int32_t dest_width = 0;
693 int32_t dest_height = 0;
694 int32_t configured = 0;
695
696 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300697 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900698 dest_x = ivisurf->prop.dest_x;
699 dest_y = ivisurf->prop.dest_y;
700 dest_width = ivisurf->prop.dest_width;
701 dest_height = ivisurf->prop.dest_height;
702
703 ivi_layout_transition_move_resize_view(ivisurf,
704 ivisurf->pending.prop.dest_x,
705 ivisurf->pending.prop.dest_y,
706 ivisurf->pending.prop.dest_width,
707 ivisurf->pending.prop.dest_height,
708 ivisurf->pending.prop.transition_duration);
709
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300710 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900711 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
712 } else {
713 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
714 }
715
716 ivisurf->prop = ivisurf->pending.prop;
717 ivisurf->prop.dest_x = dest_x;
718 ivisurf->prop.dest_y = dest_y;
719 ivisurf->prop.dest_width = dest_width;
720 ivisurf->prop.dest_height = dest_height;
721 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
722 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
723
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300724 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900725 dest_x = ivisurf->prop.dest_x;
726 dest_y = ivisurf->prop.dest_y;
727 dest_width = ivisurf->prop.dest_width;
728 dest_height = ivisurf->prop.dest_height;
729
730 ivi_layout_transition_move_resize_view(ivisurf,
731 ivisurf->pending.prop.dest_x,
732 ivisurf->pending.prop.dest_y,
733 ivisurf->pending.prop.dest_width,
734 ivisurf->pending.prop.dest_height,
735 ivisurf->pending.prop.transition_duration);
736
737 ivisurf->prop = ivisurf->pending.prop;
738 ivisurf->prop.dest_x = dest_x;
739 ivisurf->prop.dest_y = dest_y;
740 ivisurf->prop.dest_width = dest_width;
741 ivisurf->prop.dest_height = dest_height;
742
743 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
744 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
745
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300746 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900747 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300748 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900749 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
750 } else {
751 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
752 }
753
754 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
755 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
756 configured = 1;
757 }
758
759 ivisurf->prop = ivisurf->pending.prop;
760 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
761 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
762
Pekka Paalanen1f821932016-03-15 16:57:51 +0200763 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200764 shell_surface_send_configure(ivisurf->surface,
765 ivisurf->prop.dest_width,
766 ivisurf->prop.dest_height);
767 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900768 } else {
769 configured = 0;
770 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
771 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
772 configured = 1;
773 }
774
775 ivisurf->prop = ivisurf->pending.prop;
776 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
777 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
778
Pekka Paalanen1f821932016-03-15 16:57:51 +0200779 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200780 shell_surface_send_configure(ivisurf->surface,
781 ivisurf->prop.dest_width,
782 ivisurf->prop.dest_height);
783 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900784 }
785 }
786}
787
788static void
789commit_layer_list(struct ivi_layout *layout)
790{
791 struct ivi_layout_layer *ivilayer = NULL;
792 struct ivi_layout_surface *ivisurf = NULL;
793 struct ivi_layout_surface *next = NULL;
794
795 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300796 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900797 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 -0300798 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900799 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
800 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
801 NULL, NULL,
802 ivilayer->pending.prop.transition_duration);
803 }
804 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
805
806 ivilayer->prop = ivilayer->pending.prop;
807
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000808 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900809 continue;
810 }
811
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000812 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
813 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000814 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000815 wl_list_remove(&ivisurf->order.link);
816 wl_list_init(&ivisurf->order.link);
817 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900818 }
819
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000820 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900821
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000822 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900823 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000824 wl_list_remove(&ivisurf->order.link);
825 wl_list_insert(&ivilayer->order.surface_list,
826 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000827 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000828 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900829 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000830
831 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900832 }
833}
834
835static void
836commit_screen_list(struct ivi_layout *layout)
837{
838 struct ivi_layout_screen *iviscrn = NULL;
839 struct ivi_layout_layer *ivilayer = NULL;
840 struct ivi_layout_layer *next = NULL;
841 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000842 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900843
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900844 /* Clear view list of layout ivi_layer */
845 wl_list_init(&layout->layout_layer.view_list.link);
846
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900847 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000848 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900849 wl_list_for_each_safe(ivilayer, next,
850 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000851 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000852 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900853 wl_list_init(&ivilayer->order.link);
854 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
855 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900856
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000857 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900858
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900859 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
860 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900861 /* FIXME: avoid to insert order.link to multiple screens */
862 wl_list_remove(&ivilayer->order.link);
863
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900864 wl_list_insert(&iviscrn->order.layer_list,
865 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000866 ivilayer->on_screen = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900867 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
868 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900869
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000870 iviscrn->order.dirty = 0;
871 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900872
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900873 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
874 if (ivilayer->prop.visibility == false)
875 continue;
876
877 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900878 if (ivisurf->prop.visibility == false)
879 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000880
881 tmpview = get_weston_view(ivisurf);
882 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900883
884 weston_layer_entry_insert(&layout->layout_layer.view_list,
885 &tmpview->layer_link);
886
887 ivisurf->surface->output = iviscrn->output;
888 }
889 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900890 }
891}
892
893static void
894commit_transition(struct ivi_layout* layout)
895{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300896 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900897 return;
898 }
899
900 wl_list_insert_list(&layout->transitions->transition_list,
901 &layout->pending_transition_list);
902
903 wl_list_init(&layout->pending_transition_list);
904
905 wl_event_source_timer_update(layout->transitions->event_source, 1);
906}
907
908static void
909send_surface_prop(struct ivi_layout_surface *ivisurf)
910{
911 wl_signal_emit(&ivisurf->property_changed, ivisurf);
912 ivisurf->event_mask = 0;
913}
914
915static void
916send_layer_prop(struct ivi_layout_layer *ivilayer)
917{
918 wl_signal_emit(&ivilayer->property_changed, ivilayer);
919 ivilayer->event_mask = 0;
920}
921
922static void
923send_prop(struct ivi_layout *layout)
924{
925 struct ivi_layout_layer *ivilayer = NULL;
926 struct ivi_layout_surface *ivisurf = NULL;
927
928 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900929 if (ivilayer->event_mask)
930 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900931 }
932
933 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900934 if (ivisurf->event_mask)
935 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900936 }
937}
938
939static void
940clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
941{
942 struct ivi_layout_surface *surface_link = NULL;
943 struct ivi_layout_surface *surface_next = NULL;
944
945 wl_list_for_each_safe(surface_link, surface_next,
946 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000947 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900948 wl_list_init(&surface_link->pending.link);
949 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900950}
951
952static void
953clear_surface_order_list(struct ivi_layout_layer *ivilayer)
954{
955 struct ivi_layout_surface *surface_link = NULL;
956 struct ivi_layout_surface *surface_next = NULL;
957
958 wl_list_for_each_safe(surface_link, surface_next,
959 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000960 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900961 wl_list_init(&surface_link->order.link);
962 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900963}
964
965static void
966layer_created(struct wl_listener *listener, void *data)
967{
968 struct ivi_layout_layer *ivilayer = data;
969
970 struct listener_layout_notification *notification =
971 container_of(listener,
972 struct listener_layout_notification,
973 listener);
974
975 struct ivi_layout_notification_callback *created_callback =
976 notification->userdata;
977
978 ((layer_create_notification_func)created_callback->callback)
979 (ivilayer, created_callback->data);
980}
981
982static void
983layer_removed(struct wl_listener *listener, void *data)
984{
985 struct ivi_layout_layer *ivilayer = data;
986
987 struct listener_layout_notification *notification =
988 container_of(listener,
989 struct listener_layout_notification,
990 listener);
991
992 struct ivi_layout_notification_callback *removed_callback =
993 notification->userdata;
994
995 ((layer_remove_notification_func)removed_callback->callback)
996 (ivilayer, removed_callback->data);
997}
998
999static void
1000layer_prop_changed(struct wl_listener *listener, void *data)
1001{
1002 struct ivi_layout_layer *ivilayer = data;
1003
1004 struct listener_layout_notification *layout_listener =
1005 container_of(listener,
1006 struct listener_layout_notification,
1007 listener);
1008
1009 struct ivi_layout_notification_callback *prop_callback =
1010 layout_listener->userdata;
1011
1012 ((layer_property_notification_func)prop_callback->callback)
1013 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1014}
1015
1016static void
1017surface_created(struct wl_listener *listener, void *data)
1018{
1019 struct ivi_layout_surface *ivisurface = data;
1020
1021 struct listener_layout_notification *notification =
1022 container_of(listener,
1023 struct listener_layout_notification,
1024 listener);
1025
1026 struct ivi_layout_notification_callback *created_callback =
1027 notification->userdata;
1028
1029 ((surface_create_notification_func)created_callback->callback)
1030 (ivisurface, created_callback->data);
1031}
1032
1033static void
1034surface_removed(struct wl_listener *listener, void *data)
1035{
1036 struct ivi_layout_surface *ivisurface = data;
1037
1038 struct listener_layout_notification *notification =
1039 container_of(listener,
1040 struct listener_layout_notification,
1041 listener);
1042
1043 struct ivi_layout_notification_callback *removed_callback =
1044 notification->userdata;
1045
1046 ((surface_remove_notification_func)removed_callback->callback)
1047 (ivisurface, removed_callback->data);
1048}
1049
1050static void
1051surface_prop_changed(struct wl_listener *listener, void *data)
1052{
1053 struct ivi_layout_surface *ivisurf = data;
1054
1055 struct listener_layout_notification *layout_listener =
1056 container_of(listener,
1057 struct listener_layout_notification,
1058 listener);
1059
1060 struct ivi_layout_notification_callback *prop_callback =
1061 layout_listener->userdata;
1062
1063 ((surface_property_notification_func)prop_callback->callback)
1064 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1065
1066 ivisurf->event_mask = 0;
1067}
1068
1069static void
1070surface_configure_changed(struct wl_listener *listener,
1071 void *data)
1072{
1073 struct ivi_layout_surface *ivisurface = data;
1074
1075 struct listener_layout_notification *notification =
1076 container_of(listener,
1077 struct listener_layout_notification,
1078 listener);
1079
1080 struct ivi_layout_notification_callback *configure_changed_callback =
1081 notification->userdata;
1082
1083 ((surface_configure_notification_func)configure_changed_callback->callback)
1084 (ivisurface, configure_changed_callback->data);
1085}
1086
1087static int32_t
1088add_notification(struct wl_signal *signal,
1089 wl_notify_func_t callback,
1090 void *userdata)
1091{
1092 struct listener_layout_notification *notification = NULL;
1093
1094 notification = malloc(sizeof *notification);
1095 if (notification == NULL) {
1096 weston_log("fails to allocate memory\n");
1097 free(userdata);
1098 return IVI_FAILED;
1099 }
1100
1101 notification->listener.notify = callback;
1102 notification->userdata = userdata;
1103
1104 wl_signal_add(signal, &notification->listener);
1105
1106 return IVI_SUCCEEDED;
1107}
1108
1109static void
1110remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1111{
1112 struct wl_listener *listener = NULL;
1113 struct wl_listener *next = NULL;
1114
1115 wl_list_for_each_safe(listener, next, listener_list, link) {
1116 struct listener_layout_notification *notification =
1117 container_of(listener,
1118 struct listener_layout_notification,
1119 listener);
1120
1121 struct ivi_layout_notification_callback *notification_callback =
1122 notification->userdata;
1123
1124 if ((notification_callback->callback != callback) ||
1125 (notification_callback->data != userdata)) {
1126 continue;
1127 }
1128
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001129 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001130
1131 free(notification->userdata);
1132 free(notification);
1133 }
1134}
1135
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001136/**
1137 * Exported APIs of ivi-layout library are implemented from here.
1138 * Brief of APIs is described in ivi-layout-export.h.
1139 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001140static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001141ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1142 void *userdata)
1143{
1144 struct ivi_layout *layout = get_instance();
1145 struct ivi_layout_notification_callback *created_callback = NULL;
1146
1147 if (callback == NULL) {
1148 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1149 return IVI_FAILED;
1150 }
1151
1152 created_callback = malloc(sizeof *created_callback);
1153 if (created_callback == NULL) {
1154 weston_log("fails to allocate memory\n");
1155 return IVI_FAILED;
1156 }
1157
1158 created_callback->callback = callback;
1159 created_callback->data = userdata;
1160
1161 return add_notification(&layout->layer_notification.created,
1162 layer_created,
1163 created_callback);
1164}
1165
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001166static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001167ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1168 void *userdata)
1169{
1170 struct ivi_layout *layout = get_instance();
1171 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1172}
1173
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001174static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001175ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1176 void *userdata)
1177{
1178 struct ivi_layout *layout = get_instance();
1179 struct ivi_layout_notification_callback *removed_callback = NULL;
1180
1181 if (callback == NULL) {
1182 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1183 return IVI_FAILED;
1184 }
1185
1186 removed_callback = malloc(sizeof *removed_callback);
1187 if (removed_callback == NULL) {
1188 weston_log("fails to allocate memory\n");
1189 return IVI_FAILED;
1190 }
1191
1192 removed_callback->callback = callback;
1193 removed_callback->data = userdata;
1194 return add_notification(&layout->layer_notification.removed,
1195 layer_removed,
1196 removed_callback);
1197}
1198
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001199static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001200ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1201 void *userdata)
1202{
1203 struct ivi_layout *layout = get_instance();
1204 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1205}
1206
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001207static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001208ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1209 void *userdata)
1210{
1211 struct ivi_layout *layout = get_instance();
1212 struct ivi_layout_notification_callback *created_callback = NULL;
1213
1214 if (callback == NULL) {
1215 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1216 return IVI_FAILED;
1217 }
1218
1219 created_callback = malloc(sizeof *created_callback);
1220 if (created_callback == NULL) {
1221 weston_log("fails to allocate memory\n");
1222 return IVI_FAILED;
1223 }
1224
1225 created_callback->callback = callback;
1226 created_callback->data = userdata;
1227
1228 return add_notification(&layout->surface_notification.created,
1229 surface_created,
1230 created_callback);
1231}
1232
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001233static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001234ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1235 void *userdata)
1236{
1237 struct ivi_layout *layout = get_instance();
1238 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1239}
1240
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001241static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001242ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1243 void *userdata)
1244{
1245 struct ivi_layout *layout = get_instance();
1246 struct ivi_layout_notification_callback *removed_callback = NULL;
1247
1248 if (callback == NULL) {
1249 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1250 return IVI_FAILED;
1251 }
1252
1253 removed_callback = malloc(sizeof *removed_callback);
1254 if (removed_callback == NULL) {
1255 weston_log("fails to allocate memory\n");
1256 return IVI_FAILED;
1257 }
1258
1259 removed_callback->callback = callback;
1260 removed_callback->data = userdata;
1261
1262 return add_notification(&layout->surface_notification.removed,
1263 surface_removed,
1264 removed_callback);
1265}
1266
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001267static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001268ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1269 void *userdata)
1270{
1271 struct ivi_layout *layout = get_instance();
1272 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1273}
1274
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001275static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001276ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1277 void *userdata)
1278{
1279 struct ivi_layout *layout = get_instance();
1280 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1281 if (callback == NULL) {
1282 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1283 return IVI_FAILED;
1284 }
1285
1286 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1287 if (configure_changed_callback == NULL) {
1288 weston_log("fails to allocate memory\n");
1289 return IVI_FAILED;
1290 }
1291
1292 configure_changed_callback->callback = callback;
1293 configure_changed_callback->data = userdata;
1294
1295 return add_notification(&layout->surface_notification.configure_changed,
1296 surface_configure_changed,
1297 configure_changed_callback);
1298}
1299
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001300static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001301ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1302 void *userdata)
1303{
1304 struct ivi_layout *layout = get_instance();
1305 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1306}
1307
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001308uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001309ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1310{
1311 return ivisurf->id_surface;
1312}
1313
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001314static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001315ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1316{
1317 return ivilayer->id_layer;
1318}
1319
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001320static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001321ivi_layout_get_layer_from_id(uint32_t id_layer)
1322{
1323 struct ivi_layout *layout = get_instance();
1324 struct ivi_layout_layer *ivilayer = NULL;
1325
1326 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1327 if (ivilayer->id_layer == id_layer) {
1328 return ivilayer;
1329 }
1330 }
1331
1332 return NULL;
1333}
1334
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001335struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001336ivi_layout_get_surface_from_id(uint32_t id_surface)
1337{
1338 struct ivi_layout *layout = get_instance();
1339 struct ivi_layout_surface *ivisurf = NULL;
1340
1341 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1342 if (ivisurf->id_surface == id_surface) {
1343 return ivisurf;
1344 }
1345 }
1346
1347 return NULL;
1348}
1349
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001350static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001351ivi_layout_get_screen_from_id(uint32_t id_screen)
1352{
1353 struct ivi_layout *layout = get_instance();
1354 struct ivi_layout_screen *iviscrn = NULL;
1355
1356 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)1e344dc2016-03-17 15:30:27 +00001357 if (iviscrn->output->id == id_screen)
Nobuhiko Tanibata3e710d12015-11-25 23:36:09 +09001358 return iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001359 }
1360
1361 return NULL;
1362}
1363
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001364static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001365ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1366 int32_t *pWidth, int32_t *pHeight)
1367{
1368 struct weston_output *output = NULL;
1369
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001370 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001371 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1372 return IVI_FAILED;
1373 }
1374
1375 output = iviscrn->output;
1376 *pWidth = output->current_mode->width;
1377 *pHeight = output->current_mode->height;
1378
1379 return IVI_SUCCEEDED;
1380}
1381
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001382static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001383ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1384 surface_property_notification_func callback,
1385 void *userdata)
1386{
1387 struct listener_layout_notification* notification = NULL;
1388 struct ivi_layout_notification_callback *prop_callback = NULL;
1389
1390 if (ivisurf == NULL || callback == NULL) {
1391 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1392 return IVI_FAILED;
1393 }
1394
1395 notification = malloc(sizeof *notification);
1396 if (notification == NULL) {
1397 weston_log("fails to allocate memory\n");
1398 return IVI_FAILED;
1399 }
1400
1401 prop_callback = malloc(sizeof *prop_callback);
1402 if (prop_callback == NULL) {
1403 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001404 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001405 return IVI_FAILED;
1406 }
1407
1408 prop_callback->callback = callback;
1409 prop_callback->data = userdata;
1410
1411 notification->listener.notify = surface_prop_changed;
1412 notification->userdata = prop_callback;
1413
1414 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1415
1416 return IVI_SUCCEEDED;
1417}
1418
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001419static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001420ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1421{
1422 if (ivilayer == NULL) {
1423 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1424 return NULL;
1425 }
1426
1427 return &ivilayer->prop;
1428}
1429
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001430static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001431ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1432{
1433 struct ivi_layout *layout = get_instance();
1434 struct ivi_layout_screen *iviscrn = NULL;
1435 int32_t length = 0;
1436 int32_t n = 0;
1437
1438 if (pLength == NULL || ppArray == NULL) {
1439 weston_log("ivi_layout_get_screens: invalid argument\n");
1440 return IVI_FAILED;
1441 }
1442
1443 length = wl_list_length(&layout->screen_list);
1444
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001445 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001446 /* the Array must be free by module which called this function */
1447 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1448 if (*ppArray == NULL) {
1449 weston_log("fails to allocate memory\n");
1450 return IVI_FAILED;
1451 }
1452
1453 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1454 (*ppArray)[n++] = iviscrn;
1455 }
1456 }
1457
1458 *pLength = length;
1459
1460 return IVI_SUCCEEDED;
1461}
1462
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001463static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001464ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1465 int32_t *pLength,
1466 struct ivi_layout_screen ***ppArray)
1467{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001468 int32_t length = 0;
1469 int32_t n = 0;
1470
1471 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1472 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1473 return IVI_FAILED;
1474 }
1475
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001476 if (ivilayer->on_screen != NULL)
1477 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001478
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001479 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001480 /* the Array must be free by module which called this function */
1481 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1482 if (*ppArray == NULL) {
1483 weston_log("fails to allocate memory\n");
1484 return IVI_FAILED;
1485 }
1486
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001487 (*ppArray)[n++] = ivilayer->on_screen;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001488 }
1489
1490 *pLength = length;
1491
1492 return IVI_SUCCEEDED;
1493}
1494
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001495static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001496ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1497{
1498 struct ivi_layout *layout = get_instance();
1499 struct ivi_layout_layer *ivilayer = NULL;
1500 int32_t length = 0;
1501 int32_t n = 0;
1502
1503 if (pLength == NULL || ppArray == NULL) {
1504 weston_log("ivi_layout_get_layers: invalid argument\n");
1505 return IVI_FAILED;
1506 }
1507
1508 length = wl_list_length(&layout->layer_list);
1509
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001510 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001511 /* the Array must be free by module which called this function */
1512 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1513 if (*ppArray == NULL) {
1514 weston_log("fails to allocate memory\n");
1515 return IVI_FAILED;
1516 }
1517
1518 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1519 (*ppArray)[n++] = ivilayer;
1520 }
1521 }
1522
1523 *pLength = length;
1524
1525 return IVI_SUCCEEDED;
1526}
1527
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001528static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001529ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1530 int32_t *pLength,
1531 struct ivi_layout_layer ***ppArray)
1532{
1533 struct ivi_layout_layer *ivilayer = NULL;
1534 int32_t length = 0;
1535 int32_t n = 0;
1536
1537 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1538 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1539 return IVI_FAILED;
1540 }
1541
1542 length = wl_list_length(&iviscrn->order.layer_list);
1543
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001544 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001545 /* the Array must be free by module which called this function */
1546 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1547 if (*ppArray == NULL) {
1548 weston_log("fails to allocate memory\n");
1549 return IVI_FAILED;
1550 }
1551
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001552 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001553 (*ppArray)[n++] = ivilayer;
1554 }
1555 }
1556
1557 *pLength = length;
1558
1559 return IVI_SUCCEEDED;
1560}
1561
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001562static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001563ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1564 int32_t *pLength,
1565 struct ivi_layout_layer ***ppArray)
1566{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001567 int32_t length = 0;
1568 int32_t n = 0;
1569
1570 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1571 weston_log("ivi_layout_getLayers: invalid argument\n");
1572 return IVI_FAILED;
1573 }
1574
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001575 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001576 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001577 length = 1;
1578 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001579 if (*ppArray == NULL) {
1580 weston_log("fails to allocate memory\n");
1581 return IVI_FAILED;
1582 }
1583
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001584 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001585 }
1586
1587 *pLength = length;
1588
1589 return IVI_SUCCEEDED;
1590}
1591
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001592static
1593int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001594ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1595{
1596 struct ivi_layout *layout = get_instance();
1597 struct ivi_layout_surface *ivisurf = NULL;
1598 int32_t length = 0;
1599 int32_t n = 0;
1600
1601 if (pLength == NULL || ppArray == NULL) {
1602 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1603 return IVI_FAILED;
1604 }
1605
1606 length = wl_list_length(&layout->surface_list);
1607
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001608 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001609 /* the Array must be free by module which called this function */
1610 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1611 if (*ppArray == NULL) {
1612 weston_log("fails to allocate memory\n");
1613 return IVI_FAILED;
1614 }
1615
1616 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1617 (*ppArray)[n++] = ivisurf;
1618 }
1619 }
1620
1621 *pLength = length;
1622
1623 return IVI_SUCCEEDED;
1624}
1625
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001626static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001627ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1628 int32_t *pLength,
1629 struct ivi_layout_surface ***ppArray)
1630{
1631 struct ivi_layout_surface *ivisurf = NULL;
1632 int32_t length = 0;
1633 int32_t n = 0;
1634
1635 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1636 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1637 return IVI_FAILED;
1638 }
1639
1640 length = wl_list_length(&ivilayer->order.surface_list);
1641
1642 if (length != 0) {
1643 /* the Array must be free by module which called this function */
1644 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1645 if (*ppArray == NULL) {
1646 weston_log("fails to allocate memory\n");
1647 return IVI_FAILED;
1648 }
1649
1650 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1651 (*ppArray)[n++] = ivisurf;
1652 }
1653 }
1654
1655 *pLength = length;
1656
1657 return IVI_SUCCEEDED;
1658}
1659
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001660static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001661ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1662 int32_t width, int32_t height)
1663{
1664 struct ivi_layout *layout = get_instance();
1665 struct ivi_layout_layer *ivilayer = NULL;
1666
1667 ivilayer = get_layer(&layout->layer_list, id_layer);
1668 if (ivilayer != NULL) {
1669 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001670 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001671 return ivilayer;
1672 }
1673
1674 ivilayer = calloc(1, sizeof *ivilayer);
1675 if (ivilayer == NULL) {
1676 weston_log("fails to allocate memory\n");
1677 return NULL;
1678 }
1679
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001680 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001681 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001682 ivilayer->layout = layout;
1683 ivilayer->id_layer = id_layer;
1684
1685 init_layer_properties(&ivilayer->prop, width, height);
1686 ivilayer->event_mask = 0;
1687
1688 wl_list_init(&ivilayer->pending.surface_list);
1689 wl_list_init(&ivilayer->pending.link);
1690 ivilayer->pending.prop = ivilayer->prop;
1691
1692 wl_list_init(&ivilayer->order.surface_list);
1693 wl_list_init(&ivilayer->order.link);
1694
1695 wl_list_insert(&layout->layer_list, &ivilayer->link);
1696
1697 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1698
1699 return ivilayer;
1700}
1701
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001702static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001703ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1704{
1705 if (ivilayer == NULL) {
1706 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1707 return;
1708 }
1709
1710 remove_all_notification(&ivilayer->property_changed.listener_list);
1711}
1712
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001713static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001714ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1715 layer_property_notification_func callback,
1716 void *userdata)
1717{
1718 if (ivilayer == NULL) {
1719 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1720 return;
1721 }
1722
1723 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1724}
1725
1726static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001727ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001728{
1729 struct ivi_layout *layout = get_instance();
1730
1731 if (ivilayer == NULL) {
1732 weston_log("ivi_layout_layer_remove: invalid argument\n");
1733 return;
1734 }
1735
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001736 if (--ivilayer->ref_count > 0)
1737 return;
1738
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001739 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1740
1741 clear_surface_pending_list(ivilayer);
1742 clear_surface_order_list(ivilayer);
1743
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001744 wl_list_remove(&ivilayer->pending.link);
1745 wl_list_remove(&ivilayer->order.link);
1746 wl_list_remove(&ivilayer->link);
1747
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001748 ivi_layout_layer_remove_notification(ivilayer);
1749
1750 free(ivilayer);
1751}
1752
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001753int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001754ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1755 bool newVisibility)
1756{
1757 struct ivi_layout_layer_properties *prop = NULL;
1758
1759 if (ivilayer == NULL) {
1760 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1761 return IVI_FAILED;
1762 }
1763
1764 prop = &ivilayer->pending.prop;
1765 prop->visibility = newVisibility;
1766
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001767 if (ivilayer->prop.visibility != newVisibility)
1768 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1769 else
1770 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001771
1772 return IVI_SUCCEEDED;
1773}
1774
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001775int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001776ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1777 wl_fixed_t opacity)
1778{
1779 struct ivi_layout_layer_properties *prop = NULL;
1780
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001781 if (ivilayer == NULL ||
1782 opacity < wl_fixed_from_double(0.0) ||
1783 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001784 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1785 return IVI_FAILED;
1786 }
1787
1788 prop = &ivilayer->pending.prop;
1789 prop->opacity = opacity;
1790
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001791 if (ivilayer->prop.opacity != opacity)
1792 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1793 else
1794 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001795
1796 return IVI_SUCCEEDED;
1797}
1798
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001799static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001800ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1801 int32_t x, int32_t y,
1802 int32_t width, int32_t height)
1803{
1804 struct ivi_layout_layer_properties *prop = NULL;
1805
1806 if (ivilayer == NULL) {
1807 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1808 return IVI_FAILED;
1809 }
1810
1811 prop = &ivilayer->pending.prop;
1812 prop->source_x = x;
1813 prop->source_y = y;
1814 prop->source_width = width;
1815 prop->source_height = height;
1816
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001817 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1818 ivilayer->prop.source_width != width ||
1819 ivilayer->prop.source_height != height)
1820 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1821 else
1822 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001823
1824 return IVI_SUCCEEDED;
1825}
1826
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001827int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001828ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1829 int32_t x, int32_t y,
1830 int32_t width, int32_t height)
1831{
1832 struct ivi_layout_layer_properties *prop = NULL;
1833
1834 if (ivilayer == NULL) {
1835 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1836 return IVI_FAILED;
1837 }
1838
1839 prop = &ivilayer->pending.prop;
1840 prop->dest_x = x;
1841 prop->dest_y = y;
1842 prop->dest_width = width;
1843 prop->dest_height = height;
1844
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001845 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1846 ivilayer->prop.dest_width != width ||
1847 ivilayer->prop.dest_height != height)
1848 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1849 else
1850 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001851
1852 return IVI_SUCCEEDED;
1853}
1854
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001855static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001856ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1857 enum wl_output_transform orientation)
1858{
1859 struct ivi_layout_layer_properties *prop = NULL;
1860
1861 if (ivilayer == NULL) {
1862 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1863 return IVI_FAILED;
1864 }
1865
1866 prop = &ivilayer->pending.prop;
1867 prop->orientation = orientation;
1868
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001869 if (ivilayer->prop.orientation != orientation)
1870 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1871 else
1872 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001873
1874 return IVI_SUCCEEDED;
1875}
1876
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001877int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001878ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1879 struct ivi_layout_surface **pSurface,
1880 int32_t number)
1881{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001882 int32_t i = 0;
1883
1884 if (ivilayer == NULL) {
1885 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1886 return IVI_FAILED;
1887 }
1888
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001889 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001890
1891 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)72ad1642016-03-16 13:37:05 +00001892 wl_list_remove(&pSurface[i]->pending.link);
1893 wl_list_insert(&ivilayer->pending.surface_list,
1894 &pSurface[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001895 }
1896
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001897 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001898
1899 return IVI_SUCCEEDED;
1900}
1901
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001902int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001903ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1904 bool newVisibility)
1905{
1906 struct ivi_layout_surface_properties *prop = NULL;
1907
1908 if (ivisurf == NULL) {
1909 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1910 return IVI_FAILED;
1911 }
1912
1913 prop = &ivisurf->pending.prop;
1914 prop->visibility = newVisibility;
1915
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001916 if (ivisurf->prop.visibility != newVisibility)
1917 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1918 else
1919 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001920
1921 return IVI_SUCCEEDED;
1922}
1923
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001924int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001925ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1926 wl_fixed_t opacity)
1927{
1928 struct ivi_layout_surface_properties *prop = NULL;
1929
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001930 if (ivisurf == NULL ||
1931 opacity < wl_fixed_from_double(0.0) ||
1932 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001933 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1934 return IVI_FAILED;
1935 }
1936
1937 prop = &ivisurf->pending.prop;
1938 prop->opacity = opacity;
1939
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001940 if (ivisurf->prop.opacity != opacity)
1941 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
1942 else
1943 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001944
1945 return IVI_SUCCEEDED;
1946}
1947
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001948int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001949ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1950 int32_t x, int32_t y,
1951 int32_t width, int32_t height)
1952{
1953 struct ivi_layout_surface_properties *prop = NULL;
1954
1955 if (ivisurf == NULL) {
1956 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1957 return IVI_FAILED;
1958 }
1959
1960 prop = &ivisurf->pending.prop;
1961 prop->start_x = prop->dest_x;
1962 prop->start_y = prop->dest_y;
1963 prop->dest_x = x;
1964 prop->dest_y = y;
1965 prop->start_width = prop->dest_width;
1966 prop->start_height = prop->dest_height;
1967 prop->dest_width = width;
1968 prop->dest_height = height;
1969
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001970 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
1971 ivisurf->prop.dest_width != width ||
1972 ivisurf->prop.dest_height != height)
1973 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1974 else
1975 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001976
1977 return IVI_SUCCEEDED;
1978}
1979
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001980static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001981ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
1982 enum wl_output_transform orientation)
1983{
1984 struct ivi_layout_surface_properties *prop = NULL;
1985
1986 if (ivisurf == NULL) {
1987 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
1988 return IVI_FAILED;
1989 }
1990
1991 prop = &ivisurf->pending.prop;
1992 prop->orientation = orientation;
1993
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001994 if (ivisurf->prop.orientation != orientation)
1995 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1996 else
1997 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001998
1999 return IVI_SUCCEEDED;
2000}
2001
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002002static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002003ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2004 struct ivi_layout_layer *addlayer)
2005{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002006 if (iviscrn == NULL || addlayer == NULL) {
2007 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2008 return IVI_FAILED;
2009 }
2010
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00002011 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002012 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2013 return IVI_SUCCEEDED;
2014 }
2015
Ucan, Emre (ADITG/SW1)f46306f2016-03-16 13:37:07 +00002016 wl_list_remove(&addlayer->pending.link);
2017 wl_list_insert(&iviscrn->pending.layer_list, &addlayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002018
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002019 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002020
2021 return IVI_SUCCEEDED;
2022}
2023
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002024static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002025ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2026 struct ivi_layout_layer **pLayer,
2027 const int32_t number)
2028{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002029 struct ivi_layout_layer *ivilayer = NULL;
2030 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002031 int32_t i = 0;
2032
2033 if (iviscrn == NULL) {
2034 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2035 return IVI_FAILED;
2036 }
2037
2038 wl_list_for_each_safe(ivilayer, next,
2039 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002040 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002041 wl_list_init(&ivilayer->pending.link);
2042 }
2043
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002044 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002045
2046 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)4e221f02016-03-16 13:37:08 +00002047 wl_list_remove(&pLayer[i]->pending.link);
2048 wl_list_insert(&iviscrn->pending.layer_list,
2049 &pLayer[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002050 }
2051
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002052 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002053
2054 return IVI_SUCCEEDED;
2055}
2056
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002057static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002058ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2059{
2060 return iviscrn->output;
2061}
2062
2063/**
2064 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2065 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2066 * This function is used to get the result of drawing by clients.
2067 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002068static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002069ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2070{
2071 return ivisurf != NULL ? ivisurf->surface : NULL;
2072}
2073
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002074static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002075ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2076 int32_t *width, int32_t *height,
2077 int32_t *stride)
2078{
2079 int32_t w;
2080 int32_t h;
2081 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2082
2083 if (ivisurf == NULL || ivisurf->surface == NULL) {
2084 weston_log("%s: invalid argument\n", __func__);
2085 return IVI_FAILED;
2086 }
2087
2088 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2089
2090 if (width != NULL)
2091 *width = w;
2092
2093 if (height != NULL)
2094 *height = h;
2095
2096 if (stride != NULL)
2097 *stride = w * bytespp;
2098
2099 return IVI_SUCCEEDED;
2100}
2101
2102static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002103ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2104 layer_property_notification_func callback,
2105 void *userdata)
2106{
2107 struct ivi_layout_notification_callback *prop_callback = NULL;
2108
2109 if (ivilayer == NULL || callback == NULL) {
2110 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2111 return IVI_FAILED;
2112 }
2113
2114 prop_callback = malloc(sizeof *prop_callback);
2115 if (prop_callback == NULL) {
2116 weston_log("fails to allocate memory\n");
2117 return IVI_FAILED;
2118 }
2119
2120 prop_callback->callback = callback;
2121 prop_callback->data = userdata;
2122
2123 return add_notification(&ivilayer->property_changed,
2124 layer_prop_changed,
2125 prop_callback);
2126}
2127
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002128static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002129ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2130{
2131 if (ivisurf == NULL) {
2132 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2133 return NULL;
2134 }
2135
2136 return &ivisurf->prop;
2137}
2138
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002139static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002140ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2141 struct ivi_layout_surface *addsurf)
2142{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002143 if (ivilayer == NULL || addsurf == NULL) {
2144 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2145 return IVI_FAILED;
2146 }
2147
Wataru Natsume9c926fe2016-03-03 19:56:09 +09002148 if (addsurf->on_layer == ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002149 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002150
Ucan, Emre (ADITG/SW1)10942372016-03-16 13:37:02 +00002151 wl_list_remove(&addsurf->pending.link);
2152 wl_list_insert(&ivilayer->pending.surface_list, &addsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002153
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002154 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002155
2156 return IVI_SUCCEEDED;
2157}
2158
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002159static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002160ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2161 struct ivi_layout_surface *remsurf)
2162{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002163 if (ivilayer == NULL || remsurf == NULL) {
2164 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2165 return;
2166 }
2167
Ucan, Emre (ADITG/SW1)536d8332016-03-16 13:36:59 +00002168 wl_list_remove(&remsurf->pending.link);
2169 wl_list_init(&remsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002170
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002171 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002172}
2173
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002174static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002175ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2176 int32_t x, int32_t y,
2177 int32_t width, int32_t height)
2178{
2179 struct ivi_layout_surface_properties *prop = NULL;
2180
2181 if (ivisurf == NULL) {
2182 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2183 return IVI_FAILED;
2184 }
2185
2186 prop = &ivisurf->pending.prop;
2187 prop->source_x = x;
2188 prop->source_y = y;
2189 prop->source_width = width;
2190 prop->source_height = height;
2191
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002192 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2193 ivisurf->prop.source_width != width ||
2194 ivisurf->prop.source_height != height)
2195 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2196 else
2197 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002198
2199 return IVI_SUCCEEDED;
2200}
2201
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002202int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002203ivi_layout_commit_changes(void)
2204{
2205 struct ivi_layout *layout = get_instance();
2206
2207 commit_surface_list(layout);
2208 commit_layer_list(layout);
2209 commit_screen_list(layout);
2210
2211 commit_transition(layout);
2212
2213 commit_changes(layout);
2214 send_prop(layout);
2215 weston_compositor_schedule_repaint(layout->compositor);
2216
2217 return IVI_SUCCEEDED;
2218}
2219
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002220static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002221ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2222 enum ivi_layout_transition_type type,
2223 uint32_t duration)
2224{
2225 if (ivilayer == NULL) {
2226 weston_log("%s: invalid argument\n", __func__);
2227 return -1;
2228 }
2229
2230 ivilayer->pending.prop.transition_type = type;
2231 ivilayer->pending.prop.transition_duration = duration;
2232
2233 return 0;
2234}
2235
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002236static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002237ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2238 uint32_t is_fade_in,
2239 double start_alpha, double end_alpha)
2240{
2241 if (ivilayer == NULL) {
2242 weston_log("%s: invalid argument\n", __func__);
2243 return -1;
2244 }
2245
2246 ivilayer->pending.prop.is_fade_in = is_fade_in;
2247 ivilayer->pending.prop.start_alpha = start_alpha;
2248 ivilayer->pending.prop.end_alpha = end_alpha;
2249
2250 return 0;
2251}
2252
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002253static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002254ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2255 uint32_t duration)
2256{
2257 struct ivi_layout_surface_properties *prop;
2258
2259 if (ivisurf == NULL) {
2260 weston_log("%s: invalid argument\n", __func__);
2261 return -1;
2262 }
2263
2264 prop = &ivisurf->pending.prop;
2265 prop->transition_duration = duration*10;
2266 return 0;
2267}
2268
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002269static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002270ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2271 enum ivi_layout_transition_type type,
2272 uint32_t duration)
2273{
2274 struct ivi_layout_surface_properties *prop;
2275
2276 if (ivisurf == NULL) {
2277 weston_log("%s: invalid argument\n", __func__);
2278 return -1;
2279 }
2280
2281 prop = &ivisurf->pending.prop;
2282 prop->transition_type = type;
2283 prop->transition_duration = duration;
2284 return 0;
2285}
2286
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002287static int32_t
2288ivi_layout_surface_dump(struct weston_surface *surface,
2289 void *target, size_t size,int32_t x, int32_t y,
2290 int32_t width, int32_t height)
2291{
2292 int result = 0;
2293
2294 if (surface == NULL) {
2295 weston_log("%s: invalid argument\n", __func__);
2296 return IVI_FAILED;
2297 }
2298
2299 result = weston_surface_copy_content(
2300 surface, target, size,
2301 x, y, width, height);
2302
2303 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2304}
2305
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002306/**
2307 * methods of interaction between ivi-shell with ivi-layout
2308 */
2309struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002310ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2311{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002312 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002313 return NULL;
2314
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002315 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002316}
2317
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002318void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002319ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2320 int32_t width, int32_t height)
2321{
2322 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002323
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002324 /* emit callback which is set by ivi-layout api user */
2325 wl_signal_emit(&layout->surface_notification.configure_changed,
2326 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002327}
2328
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002329struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002330ivi_layout_surface_create(struct weston_surface *wl_surface,
2331 uint32_t id_surface)
2332{
2333 struct ivi_layout *layout = get_instance();
2334 struct ivi_layout_surface *ivisurf = NULL;
2335 struct weston_view *tmpview = NULL;
2336
2337 if (wl_surface == NULL) {
2338 weston_log("ivi_layout_surface_create: invalid argument\n");
2339 return NULL;
2340 }
2341
2342 ivisurf = get_surface(&layout->surface_list, id_surface);
2343 if (ivisurf != NULL) {
2344 if (ivisurf->surface != NULL) {
2345 weston_log("id_surface(%d) is already created\n", id_surface);
2346 return NULL;
2347 }
2348 }
2349
2350 ivisurf = calloc(1, sizeof *ivisurf);
2351 if (ivisurf == NULL) {
2352 weston_log("fails to allocate memory\n");
2353 return NULL;
2354 }
2355
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002356 wl_signal_init(&ivisurf->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002357 ivisurf->id_surface = id_surface;
2358 ivisurf->layout = layout;
2359
2360 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002361
2362 tmpview = weston_view_create(wl_surface);
2363 if (tmpview == NULL) {
2364 weston_log("fails to allocate memory\n");
2365 }
2366
2367 ivisurf->surface->width_from_buffer = 0;
2368 ivisurf->surface->height_from_buffer = 0;
2369
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002370 weston_matrix_init(&ivisurf->transform.matrix);
2371 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002372
2373 init_surface_properties(&ivisurf->prop);
2374 ivisurf->event_mask = 0;
2375
2376 ivisurf->pending.prop = ivisurf->prop;
2377 wl_list_init(&ivisurf->pending.link);
2378
2379 wl_list_init(&ivisurf->order.link);
2380 wl_list_init(&ivisurf->order.layer_list);
2381
2382 wl_list_insert(&layout->surface_list, &ivisurf->link);
2383
2384 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2385
2386 return ivisurf;
2387}
2388
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002389void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002390ivi_layout_init_with_compositor(struct weston_compositor *ec)
2391{
2392 struct ivi_layout *layout = get_instance();
2393
2394 layout->compositor = ec;
2395
2396 wl_list_init(&layout->surface_list);
2397 wl_list_init(&layout->layer_list);
2398 wl_list_init(&layout->screen_list);
2399
2400 wl_signal_init(&layout->layer_notification.created);
2401 wl_signal_init(&layout->layer_notification.removed);
2402
2403 wl_signal_init(&layout->surface_notification.created);
2404 wl_signal_init(&layout->surface_notification.removed);
2405 wl_signal_init(&layout->surface_notification.configure_changed);
2406
2407 /* Add layout_layer at the last of weston_compositor.layer_list */
2408 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2409
2410 create_screen(ec);
2411
2412 layout->transitions = ivi_layout_transition_set_create(ec);
2413 wl_list_init(&layout->pending_transition_list);
2414}
2415
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002416static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002417 /**
2418 * commit all changes
2419 */
2420 .commit_changes = ivi_layout_commit_changes,
2421
2422 /**
2423 * surface controller interfaces
2424 */
2425 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2426 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2427 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2428 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2429 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2430 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2431 .get_surfaces = ivi_layout_get_surfaces,
2432 .get_id_of_surface = ivi_layout_get_id_of_surface,
2433 .get_surface_from_id = ivi_layout_get_surface_from_id,
2434 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2435 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2436 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002437 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002438 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2439 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002440 .surface_set_orientation = ivi_layout_surface_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002441 .surface_add_notification = ivi_layout_surface_add_notification,
2442 .surface_remove_notification = ivi_layout_surface_remove_notification,
2443 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2444 .surface_set_transition = ivi_layout_surface_set_transition,
2445 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2446
2447 /**
2448 * layer controller interfaces
2449 */
2450 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2451 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2452 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2453 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2454 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002455 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002456 .get_layers = ivi_layout_get_layers,
2457 .get_id_of_layer = ivi_layout_get_id_of_layer,
2458 .get_layer_from_id = ivi_layout_get_layer_from_id,
2459 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2460 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2461 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2462 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002463 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002464 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2465 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002466 .layer_set_orientation = ivi_layout_layer_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002467 .layer_add_surface = ivi_layout_layer_add_surface,
2468 .layer_remove_surface = ivi_layout_layer_remove_surface,
2469 .layer_set_render_order = ivi_layout_layer_set_render_order,
2470 .layer_add_notification = ivi_layout_layer_add_notification,
2471 .layer_remove_notification = ivi_layout_layer_remove_notification,
2472 .layer_set_transition = ivi_layout_layer_set_transition,
2473
2474 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002475 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002476 */
2477 .get_screen_from_id = ivi_layout_get_screen_from_id,
2478 .get_screen_resolution = ivi_layout_get_screen_resolution,
2479 .get_screens = ivi_layout_get_screens,
2480 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2481 .screen_add_layer = ivi_layout_screen_add_layer,
2482 .screen_set_render_order = ivi_layout_screen_set_render_order,
2483 .screen_get_output = ivi_layout_screen_get_output,
2484
2485 /**
2486 * animation
2487 */
2488 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002489 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2490
2491 /**
2492 * surface content dumping for debugging
2493 */
2494 .surface_get_size = ivi_layout_surface_get_size,
2495 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002496
2497 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002498 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002499 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002500 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Ucan, Emre (ADITG/SW1)d56b90d2016-03-17 15:30:32 +00002501 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002502};
2503
2504int
2505load_controller_modules(struct weston_compositor *compositor, const char *modules,
2506 int *argc, char *argv[])
2507{
2508 const char *p, *end;
2509 char buffer[256];
2510 int (*controller_module_init)(struct weston_compositor *compositor,
2511 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002512 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002513 size_t interface_version);
2514
2515 if (modules == NULL)
2516 return 0;
2517
2518 p = modules;
2519 while (*p) {
2520 end = strchrnul(p, ',');
2521 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2522
2523 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002524 if (!controller_module_init)
2525 return -1;
2526
2527 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002528 &ivi_layout_interface,
2529 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002530 weston_log("ivi-shell: Initialization of controller module fails");
2531 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002532 }
2533
2534 p = end;
2535 while (*p == ',')
2536 p++;
2537 }
2538
2539 return 0;
2540}