blob: 60e381c3e98072745d572621f3241b2617f345ac [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
Bryce Harringtone6da35d2016-05-19 17:35:02 -070028 * not updated until ivi_layout_commit_changes is called. An overview from
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090029 * 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.
Bryce Harringtone6da35d2016-05-19 17:35:02 -070033 * 1/ When an API for updating properties of ivi_surface/ivi_layer, it updates
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090034 * pending prop of ivi_surface/ivi_layer/ivi_screen which are structure to
35 * store properties.
Bryce Harringtone6da35d2016-05-19 17:35:02 -070036 * 2/ Before calling commitChanges, in case of calling an API to get a property,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090037 * 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.
Bryce Harringtone6da35d2016-05-19 17:35:02 -070045 * For example, when a property of ivi_surface is changed from invisibile
46 * to visibile, it behaves like fade-in. When ivi_layout_commitChange is
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090047 * called during transition animation, it cancels the transition and
48 * re-start transition to new properties from current properties of final
Bryce Harringtone6da35d2016-05-19 17:35:02 -070049 * frame just before the cancellation.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090050 *
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>
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030062#include <stdint.h>
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090063
Pekka Paalanen58f98c92016-06-03 16:45:21 +030064#include "compositor/weston.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090065#include "compositor.h"
Pekka Paalanen1f821932016-03-15 16:57:51 +020066#include "ivi-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090067#include "ivi-layout-export.h"
68#include "ivi-layout-private.h"
Pekka Paalanen32ca7912016-03-15 17:21:00 +020069#include "ivi-layout-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090070
Jon Cruz867d50e2015-06-15 15:37:10 -070071#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070072#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090073
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +090074#define max(a, b) ((a) > (b) ? (a) : (b))
75
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090076struct ivi_layout;
77
78struct ivi_layout_screen {
Ucan, Emre (ADITG/SW1)7da38232016-07-01 09:34:50 +000079 struct wl_list link; /* ivi_layout::screen_list */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090080
81 struct ivi_layout *layout;
82 struct weston_output *output;
83
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090084 struct {
Ucan, Emre (ADITG/SW1)7da38232016-07-01 09:34:50 +000085 struct wl_list layer_list; /* ivi_layout_layer::pending.link */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090086 } pending;
87
88 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +000089 int dirty;
Ucan, Emre (ADITG/SW1)7da38232016-07-01 09:34:50 +000090 struct wl_list layer_list; /* ivi_layout_layer::order.link */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090091 } order;
92};
93
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +090094struct ivi_rectangle
95{
96 int32_t x;
97 int32_t y;
98 int32_t width;
99 int32_t height;
100};
101
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900102static struct ivi_layout ivilayout = {0};
103
104struct ivi_layout *
105get_instance(void)
106{
107 return &ivilayout;
108}
109
110/**
Bryce Harringtone6da35d2016-05-19 17:35:02 -0700111 * Internal API to add/remove an ivi_layer to/from ivi_screen.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900112 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900113static struct ivi_layout_surface *
114get_surface(struct wl_list *surf_list, uint32_t id_surface)
115{
116 struct ivi_layout_surface *ivisurf;
117
118 wl_list_for_each(ivisurf, surf_list, link) {
119 if (ivisurf->id_surface == id_surface) {
120 return ivisurf;
121 }
122 }
123
124 return NULL;
125}
126
127static struct ivi_layout_layer *
128get_layer(struct wl_list *layer_list, uint32_t id_layer)
129{
130 struct ivi_layout_layer *ivilayer;
131
132 wl_list_for_each(ivilayer, layer_list, link) {
133 if (ivilayer->id_layer == id_layer) {
134 return ivilayer;
135 }
136 }
137
138 return NULL;
139}
140
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000141static bool
142ivi_view_is_rendered(struct ivi_layout_view *view)
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000143{
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000144 return !wl_list_empty(&view->order_link);
145}
146
147static void
148ivi_view_destroy(struct ivi_layout_view *ivi_view)
149{
150 wl_list_remove(&ivi_view->transform.link);
151 wl_list_remove(&ivi_view->link);
152 wl_list_remove(&ivi_view->surf_link);
153 wl_list_remove(&ivi_view->pending_link);
154 wl_list_remove(&ivi_view->order_link);
155
156 weston_view_destroy(ivi_view->view);
157
158 free(ivi_view);
159}
160
161static struct ivi_layout_view*
162ivi_view_create(struct ivi_layout_layer *ivilayer,
163 struct ivi_layout_surface *ivisurf)
164{
165 struct ivi_layout_view *ivi_view;
166
167 ivi_view = calloc(1, sizeof *ivi_view);
168 if (ivi_view == NULL) {
169 weston_log("fails to allocate memory\n");
170 return NULL;
171 }
172
173 ivi_view->view = weston_view_create(ivisurf->surface);
174 if (ivi_view->view == NULL) {
175 weston_log("fails to allocate memory\n");
Raúl Peñacobabd8dc0a2017-03-29 18:13:36 +0200176 free(ivi_view);
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000177 return NULL;
178 }
179
180 weston_matrix_init(&ivi_view->transform.matrix);
181 wl_list_init(&ivi_view->transform.link);
182
183 ivi_view->ivisurf = ivisurf;
184 ivi_view->on_layer = ivilayer;
185 wl_list_insert(&ivilayer->layout->view_list,
186 &ivi_view->link);
187 wl_list_insert(&ivisurf->view_list,
188 &ivi_view->surf_link);
189
190 wl_list_init(&ivi_view->pending_link);
191 wl_list_init(&ivi_view->order_link);
192
193 return ivi_view;
194}
195
196static struct ivi_layout_view *
197get_ivi_view(struct ivi_layout_layer *ivilayer,
198 struct ivi_layout_surface *ivisurf)
199{
200 struct ivi_layout_view *ivi_view;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000201
202 assert(ivisurf->surface != NULL);
203
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000204 wl_list_for_each(ivi_view, &ivisurf->view_list, surf_link) {
205 if (ivi_view->on_layer == ivilayer)
206 return ivi_view;
207 }
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000208
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000209 return NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000210}
211
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +0000212static struct ivi_layout_screen *
213get_screen_from_output(struct weston_output *output)
214{
215 struct ivi_layout *layout = get_instance();
216 struct ivi_layout_screen *iviscrn = NULL;
217
218 wl_list_for_each(iviscrn, &layout->screen_list, link) {
219 if (iviscrn->output == output)
220 return iviscrn;
221 }
222
223 return NULL;
224}
225
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900226/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900227 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900228 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900229void
230ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900231{
232 struct ivi_layout *layout = get_instance();
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000233 struct ivi_layout_view *ivi_view ,*next;
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900234
235 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900236 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900237 return;
238 }
239
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900240 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900241
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000242 wl_list_for_each_safe(ivi_view, next, &ivisurf->view_list, surf_link) {
243 ivi_view_destroy(ivi_view);
244 }
245
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900246 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
247
Mateusz Polroladada6e32016-03-09 09:13:26 +0000248 ivi_layout_remove_all_surface_transitions(ivisurf);
249
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900250 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900251}
252
253/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900254 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
255 * Called by ivi_layout_init_with_compositor.
256 */
257static void
258create_screen(struct weston_compositor *ec)
259{
260 struct ivi_layout *layout = get_instance();
261 struct ivi_layout_screen *iviscrn = NULL;
262 struct weston_output *output = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900263
264 wl_list_for_each(output, &ec->output_list, link) {
265 iviscrn = calloc(1, sizeof *iviscrn);
266 if (iviscrn == NULL) {
267 weston_log("fails to allocate memory\n");
268 continue;
269 }
270
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900271 iviscrn->layout = layout;
272
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900273 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900274
275 wl_list_init(&iviscrn->pending.layer_list);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900276
277 wl_list_init(&iviscrn->order.layer_list);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900278
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900279 wl_list_insert(&layout->screen_list, &iviscrn->link);
280 }
281}
282
283/**
284 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
285 */
286static void
287init_layer_properties(struct ivi_layout_layer_properties *prop,
288 int32_t width, int32_t height)
289{
290 memset(prop, 0, sizeof *prop);
291 prop->opacity = wl_fixed_from_double(1.0);
292 prop->source_width = width;
293 prop->source_height = height;
294 prop->dest_width = width;
295 prop->dest_height = height;
296}
297
298static void
299init_surface_properties(struct ivi_layout_surface_properties *prop)
300{
301 memset(prop, 0, sizeof *prop);
302 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900303 /*
Bryce Harringtone6da35d2016-05-19 17:35:02 -0700304 * FIXME: this shall be fixed by ivi-layout-transition.
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900305 */
306 prop->dest_width = 1;
307 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900308}
309
310/**
311 * Internal APIs to be called from ivi_layout_commit_changes.
312 */
313static void
314update_opacity(struct ivi_layout_layer *ivilayer,
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000315 struct ivi_layout_surface *ivisurf,
316 struct weston_view *view)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900317{
318 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
319 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
320
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000321 view->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900322}
323
324static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900325get_rotate_values(enum wl_output_transform orientation,
326 float *v_sin,
327 float *v_cos)
328{
329 switch (orientation) {
330 case WL_OUTPUT_TRANSFORM_90:
331 *v_sin = 1.0f;
332 *v_cos = 0.0f;
333 break;
334 case WL_OUTPUT_TRANSFORM_180:
335 *v_sin = 0.0f;
336 *v_cos = -1.0f;
337 break;
338 case WL_OUTPUT_TRANSFORM_270:
339 *v_sin = -1.0f;
340 *v_cos = 0.0f;
341 break;
342 case WL_OUTPUT_TRANSFORM_NORMAL:
343 default:
344 *v_sin = 0.0f;
345 *v_cos = 1.0f;
346 break;
347 }
348}
349
350static void
351get_scale(enum wl_output_transform orientation,
352 float dest_width,
353 float dest_height,
354 float source_width,
355 float source_height,
356 float *scale_x,
357 float *scale_y)
358{
359 switch (orientation) {
360 case WL_OUTPUT_TRANSFORM_90:
361 *scale_x = dest_width / source_height;
362 *scale_y = dest_height / source_width;
363 break;
364 case WL_OUTPUT_TRANSFORM_180:
365 *scale_x = dest_width / source_width;
366 *scale_y = dest_height / source_height;
367 break;
368 case WL_OUTPUT_TRANSFORM_270:
369 *scale_x = dest_width / source_height;
370 *scale_y = dest_height / source_width;
371 break;
372 case WL_OUTPUT_TRANSFORM_NORMAL:
373 default:
374 *scale_x = dest_width / source_width;
375 *scale_y = dest_height / source_height;
376 break;
377 }
378}
379
380static void
381calc_transformation_matrix(struct ivi_rectangle *source_rect,
382 struct ivi_rectangle *dest_rect,
383 enum wl_output_transform orientation,
384 struct weston_matrix *m)
385{
386 float source_center_x;
387 float source_center_y;
388 float vsin;
389 float vcos;
390 float scale_x;
391 float scale_y;
392 float translate_x;
393 float translate_y;
394
395 source_center_x = source_rect->x + source_rect->width * 0.5f;
396 source_center_y = source_rect->y + source_rect->height * 0.5f;
397 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
398
399 get_rotate_values(orientation, &vsin, &vcos);
400 weston_matrix_rotate_xy(m, vcos, vsin);
401
402 get_scale(orientation,
403 dest_rect->width,
404 dest_rect->height,
405 source_rect->width,
406 source_rect->height,
407 &scale_x,
408 &scale_y);
409 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
410
411 translate_x = dest_rect->width * 0.5f + dest_rect->x;
412 translate_y = dest_rect->height * 0.5f + dest_rect->y;
413 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
414}
415
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900416/*
417 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900418 */
419static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900420ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
421 const struct ivi_rectangle *rect2,
422 struct ivi_rectangle *rect_output)
423{
424 int32_t rect1_right = rect1->x + rect1->width;
425 int32_t rect1_bottom = rect1->y + rect1->height;
426 int32_t rect2_right = rect2->x + rect2->width;
427 int32_t rect2_bottom = rect2->y + rect2->height;
428
429 rect_output->x = max(rect1->x, rect2->x);
430 rect_output->y = max(rect1->y, rect2->y);
431 rect_output->width = rect1_right < rect2_right ?
432 rect1_right - rect_output->x :
433 rect2_right - rect_output->x;
434 rect_output->height = rect1_bottom < rect2_bottom ?
435 rect1_bottom - rect_output->y :
436 rect2_bottom - rect_output->y;
437
438 if (rect_output->width < 0 || rect_output->height < 0) {
439 rect_output->width = 0;
440 rect_output->height = 0;
441 }
442}
443
444/*
445 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
446 * and store the result in rect_output.
447 * The boundingbox must be given in the same coordinate space as rect_output.
448 * Additionally, there are the following restrictions on the matrix:
449 * - no projective transformations
450 * - no skew
451 * - only multiples of 90-degree rotations supported
452 *
453 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
454 * as a fail-safe with log.
455 */
456static void
457calc_inverse_matrix_transform(const struct weston_matrix *matrix,
458 const struct ivi_rectangle *rect_input,
459 const struct ivi_rectangle *boundingbox,
460 struct ivi_rectangle *rect_output)
461{
462 struct weston_matrix m;
463 struct weston_vector top_left;
464 struct weston_vector bottom_right;
465
466 assert(boundingbox != rect_output);
467
468 if (weston_matrix_invert(&m, matrix) < 0) {
469 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
470 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
471 rect_output->x = boundingbox->x;
472 rect_output->y = boundingbox->y;
473 rect_output->width = boundingbox->width;
474 rect_output->height = boundingbox->height;
475 }
476
477 /* The vectors and matrices involved will always produce f[3] == 1.0. */
478 top_left.f[0] = rect_input->x;
479 top_left.f[1] = rect_input->y;
480 top_left.f[2] = 0.0f;
481 top_left.f[3] = 1.0f;
482
483 bottom_right.f[0] = rect_input->x + rect_input->width;
484 bottom_right.f[1] = rect_input->y + rect_input->height;
485 bottom_right.f[2] = 0.0f;
486 bottom_right.f[3] = 1.0f;
487
488 weston_matrix_transform(&m, &top_left);
489 weston_matrix_transform(&m, &bottom_right);
490
491 if (top_left.f[0] < bottom_right.f[0]) {
492 rect_output->x = top_left.f[0];
493 rect_output->width = bottom_right.f[0] - rect_output->x;
494 } else {
495 rect_output->x = bottom_right.f[0];
496 rect_output->width = top_left.f[0] - rect_output->x;
497 }
498
499 if (top_left.f[1] < bottom_right.f[1]) {
500 rect_output->y = top_left.f[1];
501 rect_output->height = bottom_right.f[1] - rect_output->y;
502 } else {
503 rect_output->y = bottom_right.f[1];
504 rect_output->height = top_left.f[1] - rect_output->y;
505 }
506
507 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
508}
509
510/**
511 * This computes the whole transformation matrix:m from surface-local
Yong Bakose0698712016-04-28 11:59:08 -0500512 * coordinates to multi-screen coordinates, which are global coordinates.
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900513 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900514 *
Bryce Harringtone6da35d2016-05-19 17:35:02 -0700515 * Additionally, this computes the mask on surface-local coordinates as an
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900516 * ivi_rectangle. This can be set to weston_view_set_mask.
517 *
518 * The mask is computed by following steps
Yong Bakose0698712016-04-28 11:59:08 -0500519 * - destination rectangle of layer is transformed to multi-screen coordinates,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900520 * global coordinates. This is done by adding weston_output.{x,y} in simple
521 * because there is no scaled and rotated transformation.
Yong Bakose0698712016-04-28 11:59:08 -0500522 * - destination rectangle of layer in multi-screen coordinates needs to be
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900523 * intersected inside of a screen the layer is assigned to. This is because
524 * overlapped region of weston surface in another screen shall not be
525 * displayed according to ivi use case.
526 * - destination rectangle of layer
Yong Bakose0698712016-04-28 11:59:08 -0500527 * - in multi-screen coordinates,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900528 * - and intersected inside of an assigned screen,
Yong Bakose0698712016-04-28 11:59:08 -0500529 * is inversed to surface-local coordinates by inversed matrix:m.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900530 * - the area is intersected by intersected area between weston_surface and
531 * source rectangle of ivi_surface.
532 */
533static void
534calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900535 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900536 struct ivi_layout_layer *ivilayer,
537 struct ivi_layout_surface *ivisurf,
538 struct weston_matrix *m,
539 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900540{
541 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
542 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900543 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900544 struct ivi_rectangle weston_surface_rect = { 0,
545 0,
546 ivisurf->surface->width,
547 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900548 struct ivi_rectangle surface_source_rect = { sp->source_x,
549 sp->source_y,
550 sp->source_width,
551 sp->source_height };
552 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
553 sp->dest_y,
554 sp->dest_width,
555 sp->dest_height };
556 struct ivi_rectangle layer_source_rect = { lp->source_x,
557 lp->source_y,
558 lp->source_width,
559 lp->source_height };
560 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
561 lp->dest_y,
562 lp->dest_width,
563 lp->dest_height };
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900564 struct ivi_rectangle screen_dest_rect = { output->x,
565 output->y,
566 output->width,
567 output->height };
568 struct ivi_rectangle layer_dest_rect_in_global =
569 { lp->dest_x + output->x,
570 lp->dest_y + output->y,
571 lp->dest_width,
572 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900573 struct ivi_rectangle surface_result;
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900574 struct ivi_rectangle layer_dest_rect_in_global_intersected;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900575
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900576 /*
577 * the whole transformation matrix:m from surface-local
578 * coordinates to global coordinates, which is computed by
579 * two steps,
580 * - surface-local coordinates to layer-local coordinates
Yong Bakose0698712016-04-28 11:59:08 -0500581 * - layer-local coordinates to single screen-local coordinates
582 * - single screen-local coordinates to multi-screen coordinates,
583 * which are global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900584 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900585 calc_transformation_matrix(&surface_source_rect,
586 &surface_dest_rect,
587 sp->orientation, m);
588
589 calc_transformation_matrix(&layer_source_rect,
590 &layer_dest_rect,
591 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900592
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900593 weston_matrix_translate(m, output->x, output->y, 0.0f);
594
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900595 /* this intersected ivi_rectangle would be used for masking
596 * weston_surface
597 */
598 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
599 &surface_result);
600
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900601 /*
602 * destination rectangle of layer in multi screens coordinate
603 * is intersected to avoid displaying outside of an assigned screen.
604 */
605 ivi_rectangle_intersect(&layer_dest_rect_in_global, &screen_dest_rect,
606 &layer_dest_rect_in_global_intersected);
607
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900608 /* calc masking area of weston_surface from m */
609 calc_inverse_matrix_transform(m,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900610 &layer_dest_rect_in_global_intersected,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900611 &surface_result,
612 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900613}
614
615static void
Ucan, Emre (ADITG/SW1)1b92ba22017-01-30 13:36:05 +0000616update_prop(struct ivi_layout_view *ivi_view)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900617{
Ucan, Emre (ADITG/SW1)1b92ba22017-01-30 13:36:05 +0000618 struct ivi_layout_surface *ivisurf = ivi_view->ivisurf;
619 struct ivi_layout_layer *ivilayer = ivi_view->on_layer;
620 struct ivi_layout_screen *iviscrn = ivilayer->on_screen;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900621 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900622 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900623
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900624 /*In case of no prop change, this just returns*/
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000625 if (!ivilayer->prop.event_mask && !ivisurf->prop.event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900626 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900627
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000628 update_opacity(ivilayer, ivisurf, ivi_view->view);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900629
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900630 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
631 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
632 can_calc = false;
633 }
634
635 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
636 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
637 can_calc = false;
638 }
639
640 if (can_calc) {
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000641 wl_list_remove(&ivi_view->transform.link);
642 weston_matrix_init(&ivi_view->transform.matrix);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900643
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900644 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000645 iviscrn, ivilayer, ivisurf, &ivi_view->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900646
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000647 weston_view_set_mask(ivi_view->view, r.x, r.y, r.width, r.height);
648 wl_list_insert(&ivi_view->view->geometry.transformation_list,
649 &ivi_view->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900650
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000651 weston_view_set_transform_parent(ivi_view->view, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900652 }
653
654 ivisurf->update_count++;
655
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000656 weston_view_geometry_dirty(ivi_view->view);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900657
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000658 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900659}
660
661static void
662commit_changes(struct ivi_layout *layout)
663{
Ucan, Emre (ADITG/SW1)27799352017-01-30 13:36:07 +0000664 struct ivi_layout_screen *iviscrn = NULL;
665 struct ivi_layout_layer *ivilayer = NULL;
666 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000667 struct ivi_layout_view *ivi_view = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900668
Ucan, Emre (ADITG/SW1)27799352017-01-30 13:36:07 +0000669 wl_list_for_each(ivi_view, &layout->view_list, link) {
670 ivisurf = ivi_view->ivisurf;
671 ivilayer = ivi_view->on_layer;
672 iviscrn = ivilayer->on_screen;
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900673
Ucan, Emre (ADITG/SW1)27799352017-01-30 13:36:07 +0000674 /*
675 * If the view is not on the currently rendered scenegraph,
676 * we do not need to update its properties.
677 */
678 if (wl_list_empty(&ivi_view->order_link) || !iviscrn)
679 continue;
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900680
Ucan, Emre (ADITG/SW1)27799352017-01-30 13:36:07 +0000681 /*
682 * If the view's layer or surface is invisible, we do not need
683 * to update its properties.
684 */
Ucan, Emre (ADITG/SW1)7fe0bb22017-02-07 12:55:59 +0000685 if (!ivilayer->prop.visibility || !ivisurf->prop.visibility) {
686 /*
687 * If ivilayer or ivisurf of ivi_view is made invisible
688 * in this commit_changes call, we have to damage
689 * the weston_view below this ivi_view. Otherwise content
690 * of this ivi_view will stay visible.
691 */
692 if ((ivilayer->prop.event_mask | ivisurf->prop.event_mask) &&
693 IVI_NOTIFICATION_VISIBILITY)
694 weston_view_damage_below(ivi_view->view);
695
Ucan, Emre (ADITG/SW1)27799352017-01-30 13:36:07 +0000696 continue;
Ucan, Emre (ADITG/SW1)7fe0bb22017-02-07 12:55:59 +0000697 }
Ucan, Emre (ADITG/SW1)27799352017-01-30 13:36:07 +0000698
699 update_prop(ivi_view);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900700 }
701}
702
703static void
704commit_surface_list(struct ivi_layout *layout)
705{
706 struct ivi_layout_surface *ivisurf = NULL;
707 int32_t dest_x = 0;
708 int32_t dest_y = 0;
709 int32_t dest_width = 0;
710 int32_t dest_height = 0;
711 int32_t configured = 0;
712
713 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300714 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900715 dest_x = ivisurf->prop.dest_x;
716 dest_y = ivisurf->prop.dest_y;
717 dest_width = ivisurf->prop.dest_width;
718 dest_height = ivisurf->prop.dest_height;
719
720 ivi_layout_transition_move_resize_view(ivisurf,
721 ivisurf->pending.prop.dest_x,
722 ivisurf->pending.prop.dest_y,
723 ivisurf->pending.prop.dest_width,
724 ivisurf->pending.prop.dest_height,
725 ivisurf->pending.prop.transition_duration);
726
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300727 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900728 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
729 } else {
730 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
731 }
732
733 ivisurf->prop = ivisurf->pending.prop;
734 ivisurf->prop.dest_x = dest_x;
735 ivisurf->prop.dest_y = dest_y;
736 ivisurf->prop.dest_width = dest_width;
737 ivisurf->prop.dest_height = dest_height;
738 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
739 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
740
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300741 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900742 dest_x = ivisurf->prop.dest_x;
743 dest_y = ivisurf->prop.dest_y;
744 dest_width = ivisurf->prop.dest_width;
745 dest_height = ivisurf->prop.dest_height;
746
747 ivi_layout_transition_move_resize_view(ivisurf,
748 ivisurf->pending.prop.dest_x,
749 ivisurf->pending.prop.dest_y,
750 ivisurf->pending.prop.dest_width,
751 ivisurf->pending.prop.dest_height,
752 ivisurf->pending.prop.transition_duration);
753
754 ivisurf->prop = ivisurf->pending.prop;
755 ivisurf->prop.dest_x = dest_x;
756 ivisurf->prop.dest_y = dest_y;
757 ivisurf->prop.dest_width = dest_width;
758 ivisurf->prop.dest_height = dest_height;
759
760 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
761 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
762
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300763 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900764 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300765 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900766 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
767 } else {
768 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
769 }
770
771 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
772 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
773 configured = 1;
774 }
775
776 ivisurf->prop = ivisurf->pending.prop;
777 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
778 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
779
Pekka Paalanen1f821932016-03-15 16:57:51 +0200780 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200781 shell_surface_send_configure(ivisurf->surface,
782 ivisurf->prop.dest_width,
783 ivisurf->prop.dest_height);
784 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900785 } else {
786 configured = 0;
787 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
788 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
789 configured = 1;
790 }
791
792 ivisurf->prop = ivisurf->pending.prop;
793 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
794 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
795
Pekka Paalanen1f821932016-03-15 16:57:51 +0200796 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200797 shell_surface_send_configure(ivisurf->surface,
798 ivisurf->prop.dest_width,
799 ivisurf->prop.dest_height);
800 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900801 }
802 }
803}
804
805static void
806commit_layer_list(struct ivi_layout *layout)
807{
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000808 struct ivi_layout_view *ivi_view = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900809 struct ivi_layout_layer *ivilayer = NULL;
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000810 struct ivi_layout_view *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900811
812 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300813 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900814 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 -0300815 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900816 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
817 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
818 NULL, NULL,
819 ivilayer->pending.prop.transition_duration);
820 }
821 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
822
823 ivilayer->prop = ivilayer->pending.prop;
824
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000825 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900826 continue;
827 }
828
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000829 wl_list_for_each_safe(ivi_view, next, &ivilayer->order.view_list,
830 order_link) {
831 wl_list_remove(&ivi_view->order_link);
832 wl_list_init(&ivi_view->order_link);
833 ivi_view->ivisurf->prop.event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900834 }
835
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000836 assert(wl_list_empty(&ivilayer->order.view_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900837
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000838 wl_list_for_each(ivi_view, &ivilayer->pending.view_list,
839 pending_link) {
840 wl_list_remove(&ivi_view->order_link);
841 wl_list_insert(&ivilayer->order.view_list, &ivi_view->order_link);
842 ivi_view->ivisurf->prop.event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900843 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000844
845 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900846 }
847}
848
849static void
850commit_screen_list(struct ivi_layout *layout)
851{
852 struct ivi_layout_screen *iviscrn = NULL;
853 struct ivi_layout_layer *ivilayer = NULL;
854 struct ivi_layout_layer *next = NULL;
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000855 struct ivi_layout_view *ivi_view = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900856
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900857 /* Clear view list of layout ivi_layer */
858 wl_list_init(&layout->layout_layer.view_list.link);
859
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900860 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000861 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900862 wl_list_for_each_safe(ivilayer, next,
863 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000864 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000865 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900866 wl_list_init(&ivilayer->order.link);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000867 ivilayer->prop.event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900868 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900869
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000870 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900871
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900872 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
873 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900874 /* FIXME: avoid to insert order.link to multiple screens */
875 wl_list_remove(&ivilayer->order.link);
876
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900877 wl_list_insert(&iviscrn->order.layer_list,
878 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000879 ivilayer->on_screen = iviscrn;
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000880 ivilayer->prop.event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900881 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900882
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000883 iviscrn->order.dirty = 0;
884 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900885
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900886 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
887 if (ivilayer->prop.visibility == false)
888 continue;
889
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000890 wl_list_for_each(ivi_view, &ivilayer->order.view_list, order_link) {
891 if (ivi_view->ivisurf->prop.visibility == false)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900892 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000893
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900894 weston_layer_entry_insert(&layout->layout_layer.view_list,
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000895 &ivi_view->view->layer_link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900896
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000897 ivi_view->view->output = iviscrn->output;
Armin Krezović50ff4bf2016-06-30 06:04:31 +0200898 ivi_view->ivisurf->surface->is_mapped = true;
899 ivi_view->view->is_mapped = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900900 }
901 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900902 }
903}
904
905static void
906commit_transition(struct ivi_layout* layout)
907{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300908 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900909 return;
910 }
911
912 wl_list_insert_list(&layout->transitions->transition_list,
913 &layout->pending_transition_list);
914
915 wl_list_init(&layout->pending_transition_list);
916
917 wl_event_source_timer_update(layout->transitions->event_source, 1);
918}
919
920static void
921send_surface_prop(struct ivi_layout_surface *ivisurf)
922{
923 wl_signal_emit(&ivisurf->property_changed, ivisurf);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000924 ivisurf->pending.prop.event_mask = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900925}
926
927static void
928send_layer_prop(struct ivi_layout_layer *ivilayer)
929{
930 wl_signal_emit(&ivilayer->property_changed, ivilayer);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000931 ivilayer->pending.prop.event_mask = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900932}
933
934static void
935send_prop(struct ivi_layout *layout)
936{
937 struct ivi_layout_layer *ivilayer = NULL;
938 struct ivi_layout_surface *ivisurf = NULL;
939
940 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000941 if (ivilayer->prop.event_mask)
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900942 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900943 }
944
945 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000946 if (ivisurf->prop.event_mask)
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900947 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900948 }
949}
950
951static void
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000952clear_view_pending_list(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900953{
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000954 struct ivi_layout_view *view_link = NULL;
955 struct ivi_layout_view *view_next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900956
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +0000957 wl_list_for_each_safe(view_link, view_next,
958 &ivilayer->pending.view_list, pending_link) {
959 wl_list_remove(&view_link->pending_link);
960 wl_list_init(&view_link->pending_link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900961 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900962}
963
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900964/**
965 * Exported APIs of ivi-layout library are implemented from here.
966 * Brief of APIs is described in ivi-layout-export.h.
967 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900968static int32_t
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000969ivi_layout_add_listener_create_layer(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900970{
971 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900972
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000973 if (listener == NULL) {
974 weston_log("ivi_layout_add_listener_create_layer: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900975 return IVI_FAILED;
976 }
977
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000978 wl_signal_add(&layout->layer_notification.created, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900979
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000980 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900981}
982
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900983static int32_t
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000984ivi_layout_add_listener_remove_layer(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900985{
986 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900987
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000988 if (listener == NULL) {
989 weston_log("ivi_layout_add_listener_remove_layer: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900990 return IVI_FAILED;
991 }
992
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000993 wl_signal_add(&layout->layer_notification.removed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900994
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000995 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900996}
997
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900998static int32_t
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000999ivi_layout_add_listener_create_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001000{
1001 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001002
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001003 if (listener == NULL) {
1004 weston_log("ivi_layout_add_listener_create_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001005 return IVI_FAILED;
1006 }
1007
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001008 wl_signal_add(&layout->surface_notification.created, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001009
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001010 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001011}
1012
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001013static int32_t
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +00001014ivi_layout_add_listener_remove_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001015{
1016 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001017
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +00001018 if (listener == NULL) {
1019 weston_log("ivi_layout_add_listener_remove_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001020 return IVI_FAILED;
1021 }
1022
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +00001023 wl_signal_add(&layout->surface_notification.removed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001024
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +00001025 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001026}
1027
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001028static int32_t
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +00001029ivi_layout_add_listener_configure_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001030{
1031 struct ivi_layout *layout = get_instance();
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +00001032
1033 if (listener == NULL) {
1034 weston_log("ivi_layout_add_listener_configure_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001035 return IVI_FAILED;
1036 }
1037
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +00001038 wl_signal_add(&layout->surface_notification.configure_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001039
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +00001040 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001041}
1042
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001043uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001044ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1045{
1046 return ivisurf->id_surface;
1047}
1048
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001049static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001050ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1051{
1052 return ivilayer->id_layer;
1053}
1054
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001055static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001056ivi_layout_get_layer_from_id(uint32_t id_layer)
1057{
1058 struct ivi_layout *layout = get_instance();
1059 struct ivi_layout_layer *ivilayer = NULL;
1060
1061 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1062 if (ivilayer->id_layer == id_layer) {
1063 return ivilayer;
1064 }
1065 }
1066
1067 return NULL;
1068}
1069
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001070struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001071ivi_layout_get_surface_from_id(uint32_t id_surface)
1072{
1073 struct ivi_layout *layout = get_instance();
1074 struct ivi_layout_surface *ivisurf = NULL;
1075
1076 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1077 if (ivisurf->id_surface == id_surface) {
1078 return ivisurf;
1079 }
1080 }
1081
1082 return NULL;
1083}
1084
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001085static int32_t
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001086ivi_layout_surface_add_listener(struct ivi_layout_surface *ivisurf,
1087 struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001088{
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001089 if (ivisurf == NULL || listener == NULL) {
1090 weston_log("ivi_layout_surface_add_listener: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001091 return IVI_FAILED;
1092 }
1093
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001094 wl_signal_add(&ivisurf->property_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001095
1096 return IVI_SUCCEEDED;
1097}
1098
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001099static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001100ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1101{
1102 if (ivilayer == NULL) {
1103 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1104 return NULL;
1105 }
1106
1107 return &ivilayer->prop;
1108}
1109
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001110static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001111ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1112 int32_t *pLength,
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001113 struct weston_output ***ppArray)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001114{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001115 int32_t length = 0;
1116 int32_t n = 0;
1117
1118 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1119 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1120 return IVI_FAILED;
1121 }
1122
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001123 if (ivilayer->on_screen != NULL)
1124 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001125
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001126 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001127 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001128 *ppArray = calloc(length, sizeof(struct weston_output *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001129 if (*ppArray == NULL) {
1130 weston_log("fails to allocate memory\n");
1131 return IVI_FAILED;
1132 }
1133
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001134 (*ppArray)[n++] = ivilayer->on_screen->output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001135 }
1136
1137 *pLength = length;
1138
1139 return IVI_SUCCEEDED;
1140}
1141
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001142static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001143ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1144{
1145 struct ivi_layout *layout = get_instance();
1146 struct ivi_layout_layer *ivilayer = NULL;
1147 int32_t length = 0;
1148 int32_t n = 0;
1149
1150 if (pLength == NULL || ppArray == NULL) {
1151 weston_log("ivi_layout_get_layers: invalid argument\n");
1152 return IVI_FAILED;
1153 }
1154
1155 length = wl_list_length(&layout->layer_list);
1156
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001157 if (length != 0) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001158 /* the Array must be freed by module which called this function */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001159 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1160 if (*ppArray == NULL) {
1161 weston_log("fails to allocate memory\n");
1162 return IVI_FAILED;
1163 }
1164
1165 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1166 (*ppArray)[n++] = ivilayer;
1167 }
1168 }
1169
1170 *pLength = length;
1171
1172 return IVI_SUCCEEDED;
1173}
1174
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001175static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001176ivi_layout_get_layers_on_screen(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001177 int32_t *pLength,
1178 struct ivi_layout_layer ***ppArray)
1179{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001180 struct ivi_layout_screen *iviscrn = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001181 struct ivi_layout_layer *ivilayer = NULL;
1182 int32_t length = 0;
1183 int32_t n = 0;
1184
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001185 if (output == NULL || pLength == NULL || ppArray == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001186 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1187 return IVI_FAILED;
1188 }
1189
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001190 iviscrn = get_screen_from_output(output);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001191 length = wl_list_length(&iviscrn->order.layer_list);
1192
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001193 if (length != 0) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001194 /* the Array must be freed by module which called this function */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001195 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1196 if (*ppArray == NULL) {
1197 weston_log("fails to allocate memory\n");
1198 return IVI_FAILED;
1199 }
1200
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001201 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001202 (*ppArray)[n++] = ivilayer;
1203 }
1204 }
1205
1206 *pLength = length;
1207
1208 return IVI_SUCCEEDED;
1209}
1210
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001211static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001212ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1213 int32_t *pLength,
1214 struct ivi_layout_layer ***ppArray)
1215{
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001216 struct ivi_layout_view *ivi_view;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001217 int32_t length = 0;
1218 int32_t n = 0;
1219
1220 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1221 weston_log("ivi_layout_getLayers: invalid argument\n");
1222 return IVI_FAILED;
1223 }
1224
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001225 if (!wl_list_empty(&ivisurf->view_list)) {
1226 /* the Array must be free by module which called this function */
1227 length = wl_list_length(&ivisurf->view_list);
1228 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001229 if (*ppArray == NULL) {
1230 weston_log("fails to allocate memory\n");
1231 return IVI_FAILED;
1232 }
1233
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001234 wl_list_for_each_reverse(ivi_view, &ivisurf->view_list, surf_link) {
1235 if (ivi_view_is_rendered(ivi_view))
1236 (*ppArray)[n++] = ivi_view->on_layer;
1237 else
1238 length--;
1239 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001240 }
1241
1242 *pLength = length;
1243
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001244 if (!length) {
1245 free(*ppArray);
1246 *ppArray = NULL;
1247 }
1248
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001249 return IVI_SUCCEEDED;
1250}
1251
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001252static
1253int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001254ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1255{
1256 struct ivi_layout *layout = get_instance();
1257 struct ivi_layout_surface *ivisurf = NULL;
1258 int32_t length = 0;
1259 int32_t n = 0;
1260
1261 if (pLength == NULL || ppArray == NULL) {
1262 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1263 return IVI_FAILED;
1264 }
1265
1266 length = wl_list_length(&layout->surface_list);
1267
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001268 if (length != 0) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001269 /* the Array must be freed by module which called this function */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001270 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1271 if (*ppArray == NULL) {
1272 weston_log("fails to allocate memory\n");
1273 return IVI_FAILED;
1274 }
1275
1276 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1277 (*ppArray)[n++] = ivisurf;
1278 }
1279 }
1280
1281 *pLength = length;
1282
1283 return IVI_SUCCEEDED;
1284}
1285
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001286static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001287ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1288 int32_t *pLength,
1289 struct ivi_layout_surface ***ppArray)
1290{
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001291 struct ivi_layout_view *ivi_view = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001292 int32_t length = 0;
1293 int32_t n = 0;
1294
1295 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1296 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1297 return IVI_FAILED;
1298 }
1299
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001300 length = wl_list_length(&ivilayer->order.view_list);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001301
1302 if (length != 0) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001303 /* the Array must be freed by module which called this function */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001304 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1305 if (*ppArray == NULL) {
1306 weston_log("fails to allocate memory\n");
1307 return IVI_FAILED;
1308 }
1309
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001310 wl_list_for_each(ivi_view, &ivilayer->order.view_list, order_link) {
1311 (*ppArray)[n++] = ivi_view->ivisurf;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001312 }
1313 }
1314
1315 *pLength = length;
1316
1317 return IVI_SUCCEEDED;
1318}
1319
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001320static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001321ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1322 int32_t width, int32_t height)
1323{
1324 struct ivi_layout *layout = get_instance();
1325 struct ivi_layout_layer *ivilayer = NULL;
1326
1327 ivilayer = get_layer(&layout->layer_list, id_layer);
1328 if (ivilayer != NULL) {
1329 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001330 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001331 return ivilayer;
1332 }
1333
1334 ivilayer = calloc(1, sizeof *ivilayer);
1335 if (ivilayer == NULL) {
1336 weston_log("fails to allocate memory\n");
1337 return NULL;
1338 }
1339
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001340 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001341 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001342 ivilayer->layout = layout;
1343 ivilayer->id_layer = id_layer;
1344
1345 init_layer_properties(&ivilayer->prop, width, height);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001346
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001347 wl_list_init(&ivilayer->pending.view_list);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001348 wl_list_init(&ivilayer->pending.link);
1349 ivilayer->pending.prop = ivilayer->prop;
1350
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001351 wl_list_init(&ivilayer->order.view_list);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001352 wl_list_init(&ivilayer->order.link);
1353
1354 wl_list_insert(&layout->layer_list, &ivilayer->link);
1355
1356 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1357
1358 return ivilayer;
1359}
1360
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001361static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001362ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001363{
1364 struct ivi_layout *layout = get_instance();
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001365 struct ivi_layout_view *ivi_view, *next;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001366
1367 if (ivilayer == NULL) {
Ucan, Emre (ADITG/SW1)66602522017-01-17 12:35:20 +00001368 weston_log("ivi_layout_layer_destroy: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001369 return;
1370 }
1371
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001372 if (--ivilayer->ref_count > 0)
1373 return;
1374
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001375 /*Destroy all ivi_views*/
1376 wl_list_for_each_safe(ivi_view, next, &layout->view_list, link) {
1377 if (ivi_view->on_layer == ivilayer)
1378 ivi_view_destroy(ivi_view);
1379 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001380
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001381 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001382
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001383 wl_list_remove(&ivilayer->pending.link);
1384 wl_list_remove(&ivilayer->order.link);
1385 wl_list_remove(&ivilayer->link);
1386
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001387 free(ivilayer);
1388}
1389
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001390int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001391ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1392 bool newVisibility)
1393{
1394 struct ivi_layout_layer_properties *prop = NULL;
1395
1396 if (ivilayer == NULL) {
1397 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1398 return IVI_FAILED;
1399 }
1400
1401 prop = &ivilayer->pending.prop;
1402 prop->visibility = newVisibility;
1403
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001404 if (ivilayer->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001405 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001406 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001407 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001408
1409 return IVI_SUCCEEDED;
1410}
1411
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001412int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001413ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1414 wl_fixed_t opacity)
1415{
1416 struct ivi_layout_layer_properties *prop = NULL;
1417
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001418 if (ivilayer == NULL ||
1419 opacity < wl_fixed_from_double(0.0) ||
1420 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001421 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1422 return IVI_FAILED;
1423 }
1424
1425 prop = &ivilayer->pending.prop;
1426 prop->opacity = opacity;
1427
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001428 if (ivilayer->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001429 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001430 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001431 prop->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001432
1433 return IVI_SUCCEEDED;
1434}
1435
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001436static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001437ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1438 int32_t x, int32_t y,
1439 int32_t width, int32_t height)
1440{
1441 struct ivi_layout_layer_properties *prop = NULL;
1442
1443 if (ivilayer == NULL) {
1444 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1445 return IVI_FAILED;
1446 }
1447
1448 prop = &ivilayer->pending.prop;
1449 prop->source_x = x;
1450 prop->source_y = y;
1451 prop->source_width = width;
1452 prop->source_height = height;
1453
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001454 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1455 ivilayer->prop.source_width != width ||
1456 ivilayer->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001457 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001458 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001459 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001460
1461 return IVI_SUCCEEDED;
1462}
1463
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001464int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001465ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1466 int32_t x, int32_t y,
1467 int32_t width, int32_t height)
1468{
1469 struct ivi_layout_layer_properties *prop = NULL;
1470
1471 if (ivilayer == NULL) {
1472 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1473 return IVI_FAILED;
1474 }
1475
1476 prop = &ivilayer->pending.prop;
1477 prop->dest_x = x;
1478 prop->dest_y = y;
1479 prop->dest_width = width;
1480 prop->dest_height = height;
1481
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001482 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1483 ivilayer->prop.dest_width != width ||
1484 ivilayer->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001485 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001486 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001487 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001488
1489 return IVI_SUCCEEDED;
1490}
1491
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001492int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001493ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1494 struct ivi_layout_surface **pSurface,
1495 int32_t number)
1496{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001497 int32_t i = 0;
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001498 struct ivi_layout_view * ivi_view;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001499
1500 if (ivilayer == NULL) {
1501 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1502 return IVI_FAILED;
1503 }
1504
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001505 clear_view_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001506
1507 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001508 ivi_view = get_ivi_view(ivilayer, pSurface[i]);
1509 if (!ivi_view)
1510 ivi_view = ivi_view_create(ivilayer, pSurface[i]);
1511
1512 assert(ivi_view != NULL);
1513
1514 wl_list_remove(&ivi_view->pending_link);
1515 wl_list_insert(&ivilayer->pending.view_list, &ivi_view->pending_link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001516 }
1517
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001518 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001519
1520 return IVI_SUCCEEDED;
1521}
1522
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001523int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001524ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1525 bool newVisibility)
1526{
1527 struct ivi_layout_surface_properties *prop = NULL;
1528
1529 if (ivisurf == NULL) {
1530 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1531 return IVI_FAILED;
1532 }
1533
1534 prop = &ivisurf->pending.prop;
1535 prop->visibility = newVisibility;
1536
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001537 if (ivisurf->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001538 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001539 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001540 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001541
1542 return IVI_SUCCEEDED;
1543}
1544
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001545int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001546ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1547 wl_fixed_t opacity)
1548{
1549 struct ivi_layout_surface_properties *prop = NULL;
1550
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001551 if (ivisurf == NULL ||
1552 opacity < wl_fixed_from_double(0.0) ||
1553 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001554 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1555 return IVI_FAILED;
1556 }
1557
1558 prop = &ivisurf->pending.prop;
1559 prop->opacity = opacity;
1560
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001561 if (ivisurf->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001562 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001563 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001564 prop->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001565
1566 return IVI_SUCCEEDED;
1567}
1568
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001569int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001570ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1571 int32_t x, int32_t y,
1572 int32_t width, int32_t height)
1573{
1574 struct ivi_layout_surface_properties *prop = NULL;
1575
1576 if (ivisurf == NULL) {
1577 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1578 return IVI_FAILED;
1579 }
1580
1581 prop = &ivisurf->pending.prop;
1582 prop->start_x = prop->dest_x;
1583 prop->start_y = prop->dest_y;
1584 prop->dest_x = x;
1585 prop->dest_y = y;
1586 prop->start_width = prop->dest_width;
1587 prop->start_height = prop->dest_height;
1588 prop->dest_width = width;
1589 prop->dest_height = height;
1590
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001591 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
1592 ivisurf->prop.dest_width != width ||
1593 ivisurf->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001594 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001595 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001596 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001597
1598 return IVI_SUCCEEDED;
1599}
1600
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001601static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001602ivi_layout_screen_add_layer(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001603 struct ivi_layout_layer *addlayer)
1604{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001605 struct ivi_layout_screen *iviscrn;
1606
1607 if (output == NULL || addlayer == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001608 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
1609 return IVI_FAILED;
1610 }
1611
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001612 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001613
Ucan, Emre (ADITG/SW1)f46306f2016-03-16 13:37:07 +00001614 wl_list_remove(&addlayer->pending.link);
1615 wl_list_insert(&iviscrn->pending.layer_list, &addlayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001616
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001617 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001618
1619 return IVI_SUCCEEDED;
1620}
1621
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001622static int32_t
Ucan, Emre (ADITG/SW1)deee8582017-03-02 08:47:33 +00001623ivi_layout_screen_remove_layer(struct weston_output *output,
1624 struct ivi_layout_layer *removelayer)
1625{
1626 struct ivi_layout_screen *iviscrn;
1627
1628 if (output == NULL || removelayer == NULL) {
1629 weston_log("ivi_layout_screen_remove_layer: invalid argument\n");
1630 return IVI_FAILED;
1631 }
1632
1633 iviscrn = get_screen_from_output(output);
1634
1635 wl_list_remove(&removelayer->pending.link);
1636 wl_list_init(&removelayer->pending.link);
1637
1638 iviscrn->order.dirty = 1;
1639
1640 return IVI_SUCCEEDED;
1641}
1642
1643static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001644ivi_layout_screen_set_render_order(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001645 struct ivi_layout_layer **pLayer,
1646 const int32_t number)
1647{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001648 struct ivi_layout_screen *iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001649 struct ivi_layout_layer *ivilayer = NULL;
1650 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001651 int32_t i = 0;
1652
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001653 if (output == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001654 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
1655 return IVI_FAILED;
1656 }
1657
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001658 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001659
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001660 wl_list_for_each_safe(ivilayer, next,
1661 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001662 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001663 wl_list_init(&ivilayer->pending.link);
1664 }
1665
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001666 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001667
1668 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)4e221f02016-03-16 13:37:08 +00001669 wl_list_remove(&pLayer[i]->pending.link);
1670 wl_list_insert(&iviscrn->pending.layer_list,
1671 &pLayer[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001672 }
1673
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001674 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001675
1676 return IVI_SUCCEEDED;
1677}
1678
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001679/**
1680 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
1681 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
1682 * This function is used to get the result of drawing by clients.
1683 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001684static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001685ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
1686{
1687 return ivisurf != NULL ? ivisurf->surface : NULL;
1688}
1689
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001690static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09001691ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
1692 int32_t *width, int32_t *height,
1693 int32_t *stride)
1694{
1695 int32_t w;
1696 int32_t h;
1697 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
1698
1699 if (ivisurf == NULL || ivisurf->surface == NULL) {
1700 weston_log("%s: invalid argument\n", __func__);
1701 return IVI_FAILED;
1702 }
1703
1704 weston_surface_get_content_size(ivisurf->surface, &w, &h);
1705
1706 if (width != NULL)
1707 *width = w;
1708
1709 if (height != NULL)
1710 *height = h;
1711
1712 if (stride != NULL)
1713 *stride = w * bytespp;
1714
1715 return IVI_SUCCEEDED;
1716}
1717
1718static int32_t
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001719ivi_layout_layer_add_listener(struct ivi_layout_layer *ivilayer,
1720 struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001721{
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001722 if (ivilayer == NULL || listener == NULL) {
1723 weston_log("ivi_layout_layer_add_listener: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001724 return IVI_FAILED;
1725 }
1726
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001727 wl_signal_add(&ivilayer->property_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001728
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001729 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001730}
1731
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001732static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001733ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
1734{
1735 if (ivisurf == NULL) {
1736 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
1737 return NULL;
1738 }
1739
1740 return &ivisurf->prop;
1741}
1742
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001743static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001744ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
1745 struct ivi_layout_surface *addsurf)
1746{
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001747 struct ivi_layout_view *ivi_view;
1748
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001749 if (ivilayer == NULL || addsurf == NULL) {
1750 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
1751 return IVI_FAILED;
1752 }
1753
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001754 ivi_view = get_ivi_view(ivilayer, addsurf);
1755 if (!ivi_view)
1756 ivi_view = ivi_view_create(ivilayer, addsurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001757
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001758 wl_list_remove(&ivi_view->pending_link);
1759 wl_list_insert(&ivilayer->pending.view_list, &ivi_view->pending_link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001760
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001761 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001762
1763 return IVI_SUCCEEDED;
1764}
1765
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001766static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001767ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
1768 struct ivi_layout_surface *remsurf)
1769{
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001770 struct ivi_layout_view *ivi_view;
1771
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001772 if (ivilayer == NULL || remsurf == NULL) {
1773 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
1774 return;
1775 }
1776
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001777 ivi_view = get_ivi_view(ivilayer, remsurf);
1778 if (ivi_view) {
1779 wl_list_remove(&ivi_view->pending_link);
1780 wl_list_init(&ivi_view->pending_link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001781
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001782 ivilayer->order.dirty = 1;
1783 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001784}
1785
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001786static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001787ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
1788 int32_t x, int32_t y,
1789 int32_t width, int32_t height)
1790{
1791 struct ivi_layout_surface_properties *prop = NULL;
1792
1793 if (ivisurf == NULL) {
1794 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
1795 return IVI_FAILED;
1796 }
1797
1798 prop = &ivisurf->pending.prop;
1799 prop->source_x = x;
1800 prop->source_y = y;
1801 prop->source_width = width;
1802 prop->source_height = height;
1803
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001804 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
1805 ivisurf->prop.source_width != width ||
1806 ivisurf->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001807 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001808 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001809 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001810
1811 return IVI_SUCCEEDED;
1812}
1813
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001814int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001815ivi_layout_commit_changes(void)
1816{
1817 struct ivi_layout *layout = get_instance();
1818
1819 commit_surface_list(layout);
1820 commit_layer_list(layout);
1821 commit_screen_list(layout);
1822
1823 commit_transition(layout);
1824
1825 commit_changes(layout);
1826 send_prop(layout);
1827 weston_compositor_schedule_repaint(layout->compositor);
1828
1829 return IVI_SUCCEEDED;
1830}
1831
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001832static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001833ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
1834 enum ivi_layout_transition_type type,
1835 uint32_t duration)
1836{
1837 if (ivilayer == NULL) {
1838 weston_log("%s: invalid argument\n", __func__);
1839 return -1;
1840 }
1841
1842 ivilayer->pending.prop.transition_type = type;
1843 ivilayer->pending.prop.transition_duration = duration;
1844
1845 return 0;
1846}
1847
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001848static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001849ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
1850 uint32_t is_fade_in,
1851 double start_alpha, double end_alpha)
1852{
1853 if (ivilayer == NULL) {
1854 weston_log("%s: invalid argument\n", __func__);
1855 return -1;
1856 }
1857
1858 ivilayer->pending.prop.is_fade_in = is_fade_in;
1859 ivilayer->pending.prop.start_alpha = start_alpha;
1860 ivilayer->pending.prop.end_alpha = end_alpha;
1861
1862 return 0;
1863}
1864
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001865static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001866ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
1867 uint32_t duration)
1868{
1869 struct ivi_layout_surface_properties *prop;
1870
1871 if (ivisurf == NULL) {
1872 weston_log("%s: invalid argument\n", __func__);
1873 return -1;
1874 }
1875
1876 prop = &ivisurf->pending.prop;
1877 prop->transition_duration = duration*10;
1878 return 0;
1879}
1880
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001881static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001882ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
1883 enum ivi_layout_transition_type type,
1884 uint32_t duration)
1885{
1886 struct ivi_layout_surface_properties *prop;
1887
1888 if (ivisurf == NULL) {
1889 weston_log("%s: invalid argument\n", __func__);
1890 return -1;
1891 }
1892
1893 prop = &ivisurf->pending.prop;
1894 prop->transition_type = type;
1895 prop->transition_duration = duration;
1896 return 0;
1897}
1898
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09001899static int32_t
1900ivi_layout_surface_dump(struct weston_surface *surface,
1901 void *target, size_t size,int32_t x, int32_t y,
1902 int32_t width, int32_t height)
1903{
1904 int result = 0;
1905
1906 if (surface == NULL) {
1907 weston_log("%s: invalid argument\n", __func__);
1908 return IVI_FAILED;
1909 }
1910
1911 result = weston_surface_copy_content(
1912 surface, target, size,
1913 x, y, width, height);
1914
1915 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
1916}
1917
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001918/**
1919 * methods of interaction between ivi-shell with ivi-layout
1920 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001921
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001922void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001923ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
1924 int32_t width, int32_t height)
1925{
1926 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001927
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09001928 /* emit callback which is set by ivi-layout api user */
1929 wl_signal_emit(&layout->surface_notification.configure_changed,
1930 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001931}
1932
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001933struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001934ivi_layout_surface_create(struct weston_surface *wl_surface,
1935 uint32_t id_surface)
1936{
1937 struct ivi_layout *layout = get_instance();
1938 struct ivi_layout_surface *ivisurf = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001939
1940 if (wl_surface == NULL) {
1941 weston_log("ivi_layout_surface_create: invalid argument\n");
1942 return NULL;
1943 }
1944
1945 ivisurf = get_surface(&layout->surface_list, id_surface);
1946 if (ivisurf != NULL) {
1947 if (ivisurf->surface != NULL) {
1948 weston_log("id_surface(%d) is already created\n", id_surface);
1949 return NULL;
1950 }
1951 }
1952
1953 ivisurf = calloc(1, sizeof *ivisurf);
1954 if (ivisurf == NULL) {
1955 weston_log("fails to allocate memory\n");
1956 return NULL;
1957 }
1958
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001959 wl_signal_init(&ivisurf->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001960 ivisurf->id_surface = id_surface;
1961 ivisurf->layout = layout;
1962
1963 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001964
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001965 ivisurf->surface->width_from_buffer = 0;
1966 ivisurf->surface->height_from_buffer = 0;
1967
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001968 init_surface_properties(&ivisurf->prop);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001969
1970 ivisurf->pending.prop = ivisurf->prop;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001971
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001972 wl_list_init(&ivisurf->view_list);
1973
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001974 wl_list_insert(&layout->surface_list, &ivisurf->link);
1975
1976 wl_signal_emit(&layout->surface_notification.created, ivisurf);
1977
1978 return ivisurf;
1979}
1980
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001981void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001982ivi_layout_init_with_compositor(struct weston_compositor *ec)
1983{
1984 struct ivi_layout *layout = get_instance();
1985
1986 layout->compositor = ec;
1987
1988 wl_list_init(&layout->surface_list);
1989 wl_list_init(&layout->layer_list);
1990 wl_list_init(&layout->screen_list);
Ucan, Emre (ADITG/SW1)5e8d55d2016-06-14 14:43:40 +00001991 wl_list_init(&layout->view_list);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001992
1993 wl_signal_init(&layout->layer_notification.created);
1994 wl_signal_init(&layout->layer_notification.removed);
1995
1996 wl_signal_init(&layout->surface_notification.created);
1997 wl_signal_init(&layout->surface_notification.removed);
1998 wl_signal_init(&layout->surface_notification.configure_changed);
1999
2000 /* Add layout_layer at the last of weston_compositor.layer_list */
Quentin Glidic82681572016-12-17 13:40:51 +01002001 weston_layer_init(&layout->layout_layer, ec);
2002 weston_layer_set_position(&layout->layout_layer,
2003 WESTON_LAYER_POSITION_NORMAL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002004
2005 create_screen(ec);
2006
2007 layout->transitions = ivi_layout_transition_set_create(ec);
2008 wl_list_init(&layout->pending_transition_list);
2009}
2010
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002011static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002012 /**
2013 * commit all changes
2014 */
2015 .commit_changes = ivi_layout_commit_changes,
2016
2017 /**
2018 * surface controller interfaces
2019 */
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00002020 .add_listener_create_surface = ivi_layout_add_listener_create_surface,
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +00002021 .add_listener_remove_surface = ivi_layout_add_listener_remove_surface,
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +00002022 .add_listener_configure_surface = ivi_layout_add_listener_configure_surface,
Pekka Paalaneneaa43fc2016-04-12 16:06:58 +03002023 .get_surface = shell_get_ivi_layout_surface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002024 .get_surfaces = ivi_layout_get_surfaces,
2025 .get_id_of_surface = ivi_layout_get_id_of_surface,
2026 .get_surface_from_id = ivi_layout_get_surface_from_id,
2027 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2028 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2029 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002030 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002031 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2032 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00002033 .surface_add_listener = ivi_layout_surface_add_listener,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002034 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2035 .surface_set_transition = ivi_layout_surface_set_transition,
2036 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2037
2038 /**
2039 * layer controller interfaces
2040 */
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +00002041 .add_listener_create_layer = ivi_layout_add_listener_create_layer,
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +00002042 .add_listener_remove_layer = ivi_layout_add_listener_remove_layer,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002043 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002044 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002045 .get_layers = ivi_layout_get_layers,
2046 .get_id_of_layer = ivi_layout_get_id_of_layer,
2047 .get_layer_from_id = ivi_layout_get_layer_from_id,
2048 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2049 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2050 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2051 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002052 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002053 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2054 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002055 .layer_add_surface = ivi_layout_layer_add_surface,
2056 .layer_remove_surface = ivi_layout_layer_remove_surface,
2057 .layer_set_render_order = ivi_layout_layer_set_render_order,
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00002058 .layer_add_listener = ivi_layout_layer_add_listener,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002059 .layer_set_transition = ivi_layout_layer_set_transition,
2060
2061 /**
Ucan, Emre (ADITG/SW1)6d89b1c2016-03-17 15:30:49 +00002062 * screen controller interfaces
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002063 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002064 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2065 .screen_add_layer = ivi_layout_screen_add_layer,
Ucan, Emre (ADITG/SW1)deee8582017-03-02 08:47:33 +00002066 .screen_remove_layer = ivi_layout_screen_remove_layer,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002067 .screen_set_render_order = ivi_layout_screen_set_render_order,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002068
2069 /**
2070 * animation
2071 */
2072 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002073 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2074
2075 /**
2076 * surface content dumping for debugging
2077 */
2078 .surface_get_size = ivi_layout_surface_get_size,
2079 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002080};
2081
2082int
2083load_controller_modules(struct weston_compositor *compositor, const char *modules,
2084 int *argc, char *argv[])
2085{
2086 const char *p, *end;
2087 char buffer[256];
2088 int (*controller_module_init)(struct weston_compositor *compositor,
2089 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002090 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002091 size_t interface_version);
2092
2093 if (modules == NULL)
2094 return 0;
2095
2096 p = modules;
2097 while (*p) {
2098 end = strchrnul(p, ',');
2099 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2100
Quentin Glidic8af2bec2016-12-02 14:21:46 +01002101 controller_module_init =
2102 wet_load_module_entrypoint(buffer,
2103 "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002104 if (!controller_module_init)
2105 return -1;
2106
2107 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002108 &ivi_layout_interface,
2109 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002110 weston_log("ivi-shell: Initialization of controller module fails");
2111 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002112 }
2113
2114 p = end;
2115 while (*p == ',')
2116 p++;
2117 }
2118
2119 return 0;
2120}