blob: 204ead0233376438ee344fd44b7ce7879c997519 [file] [log] [blame]
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001/*
2 * Copyright (C) 2013 DENSO CORPORATION
3 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090011 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090024 */
25
26/**
27 * Implementation of ivi-layout library. The actual view on ivi_screen is
28 * not updated till calling ivi_layout_commit_changes. A overview from
29 * calling API for updating properties of ivi_surface/ivi_layer to asking
30 * compositor to compose them by using weston_compositor_schedule_repaint,
31 * 0/ initialize this library by ivi_layout_init_with_compositor
32 * with (struct weston_compositor *ec) from ivi-shell.
33 * 1/ When a API for updating properties of ivi_surface/ivi_layer, it updates
34 * pending prop of ivi_surface/ivi_layer/ivi_screen which are structure to
35 * store properties.
36 * 2/ Before calling commitChanges, in case of calling a API to get a property,
37 * return current property, not pending property.
38 * 3/ At the timing of calling ivi_layout_commitChanges, pending properties
39 * are applied to properties.
40 *
41 * *) ivi_layout_commitChanges is also called by transition animation
42 * per each frame. See ivi-layout-transition.c in details. Transition
43 * animation interpolates frames between previous properties of ivi_surface
44 * and new ones.
45 * For example, when a property of ivi_surface is changed from invisibility
46 * to visibility, it behaves like fade-in. When ivi_layout_commitChange is
47 * called during transition animation, it cancels the transition and
48 * re-start transition to new properties from current properties of final
49 * frame just before the the cancellation.
50 *
51 * 4/ According properties, set transformation by using weston_matrix and
52 * weston_view per ivi_surfaces and ivi_layers in while loop.
53 * 5/ Set damage and trigger transform by using weston_view_geometry_dirty.
54 * 6/ Notify update of properties.
55 * 7/ Trigger composition by weston_compositor_schedule_repaint.
56 *
57 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090058#include "config.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090059
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090060#include <string.h>
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +000061#include <assert.h>
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090062
63#include "compositor.h"
Pekka Paalanen1f821932016-03-15 16:57:51 +020064#include "ivi-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090065#include "ivi-layout-export.h"
66#include "ivi-layout-private.h"
67
Jon Cruz867d50e2015-06-15 15:37:10 -070068#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070069#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090070
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +090071#define max(a, b) ((a) > (b) ? (a) : (b))
72
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090073struct listener_layout_notification {
74 void *userdata;
75 struct wl_listener listener;
76};
77
78struct ivi_layout;
79
80struct ivi_layout_screen {
81 struct wl_list link;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090082 uint32_t id_screen;
83
84 struct ivi_layout *layout;
85 struct weston_output *output;
86
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090087 struct {
88 struct wl_list layer_list;
89 struct wl_list link;
90 } pending;
91
92 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +000093 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090094 struct wl_list layer_list;
95 struct wl_list link;
96 } order;
97};
98
99struct ivi_layout_notification_callback {
100 void *callback;
101 void *data;
102};
103
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900104struct ivi_rectangle
105{
106 int32_t x;
107 int32_t y;
108 int32_t width;
109 int32_t height;
110};
111
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900112static void
113remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
114
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900115static struct ivi_layout ivilayout = {0};
116
117struct ivi_layout *
118get_instance(void)
119{
120 return &ivilayout;
121}
122
123/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900124 * Internal API to add/remove a ivi_layer to/from ivi_screen.
125 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900126static struct ivi_layout_surface *
127get_surface(struct wl_list *surf_list, uint32_t id_surface)
128{
129 struct ivi_layout_surface *ivisurf;
130
131 wl_list_for_each(ivisurf, surf_list, link) {
132 if (ivisurf->id_surface == id_surface) {
133 return ivisurf;
134 }
135 }
136
137 return NULL;
138}
139
140static struct ivi_layout_layer *
141get_layer(struct wl_list *layer_list, uint32_t id_layer)
142{
143 struct ivi_layout_layer *ivilayer;
144
145 wl_list_for_each(ivilayer, layer_list, link) {
146 if (ivilayer->id_layer == id_layer) {
147 return ivilayer;
148 }
149 }
150
151 return NULL;
152}
153
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000154static struct weston_view *
155get_weston_view(struct ivi_layout_surface *ivisurf)
156{
157 struct weston_view *view = NULL;
158
159 assert(ivisurf->surface != NULL);
160
161 /* One view per surface */
162 if(wl_list_empty(&ivisurf->surface->views))
163 view = NULL;
164 else
165 view = wl_container_of(ivisurf->surface->views.next, view, surface_link);
166
167 return view;
168}
169
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900170static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900171remove_all_notification(struct wl_list *listener_list)
172{
173 struct wl_listener *listener = NULL;
174 struct wl_listener *next = NULL;
175
176 wl_list_for_each_safe(listener, next, listener_list, link) {
177 struct listener_layout_notification *notification = NULL;
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000178 wl_list_remove(&listener->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900179
180 notification =
181 container_of(listener,
182 struct listener_layout_notification,
183 listener);
184
185 free(notification->userdata);
186 free(notification);
187 }
188}
189
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900190static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900191ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
192{
193 if (ivisurf == NULL) {
194 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
195 return;
196 }
197
198 remove_all_notification(&ivisurf->property_changed.listener_list);
199}
200
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900201static void
202ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
203 surface_property_notification_func callback,
204 void *userdata)
205{
206 if (ivisurf == NULL) {
207 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
208 return;
209 }
210
211 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
212}
213
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900214/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900215 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900216 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900217void
218ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900219{
220 struct ivi_layout *layout = get_instance();
221
222 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900223 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900224 return;
225 }
226
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900227 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900228 wl_list_remove(&ivisurf->pending.link);
229 wl_list_remove(&ivisurf->order.link);
230 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900231
232 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
233
Mateusz Polroladada6e32016-03-09 09:13:26 +0000234 ivi_layout_remove_all_surface_transitions(ivisurf);
235
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900236 ivi_layout_surface_remove_notification(ivisurf);
237
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900238 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900239}
240
241/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900242 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
243 * Called by ivi_layout_init_with_compositor.
244 */
245static void
246create_screen(struct weston_compositor *ec)
247{
248 struct ivi_layout *layout = get_instance();
249 struct ivi_layout_screen *iviscrn = NULL;
250 struct weston_output *output = NULL;
251 int32_t count = 0;
252
253 wl_list_for_each(output, &ec->output_list, link) {
254 iviscrn = calloc(1, sizeof *iviscrn);
255 if (iviscrn == NULL) {
256 weston_log("fails to allocate memory\n");
257 continue;
258 }
259
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900260 iviscrn->layout = layout;
261
262 iviscrn->id_screen = count;
263 count++;
264
265 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900266
267 wl_list_init(&iviscrn->pending.layer_list);
268 wl_list_init(&iviscrn->pending.link);
269
270 wl_list_init(&iviscrn->order.layer_list);
271 wl_list_init(&iviscrn->order.link);
272
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900273 wl_list_insert(&layout->screen_list, &iviscrn->link);
274 }
275}
276
277/**
278 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
279 */
280static void
281init_layer_properties(struct ivi_layout_layer_properties *prop,
282 int32_t width, int32_t height)
283{
284 memset(prop, 0, sizeof *prop);
285 prop->opacity = wl_fixed_from_double(1.0);
286 prop->source_width = width;
287 prop->source_height = height;
288 prop->dest_width = width;
289 prop->dest_height = height;
290}
291
292static void
293init_surface_properties(struct ivi_layout_surface_properties *prop)
294{
295 memset(prop, 0, sizeof *prop);
296 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900297 /*
298 * FIXME: this shall be finxed by ivi-layout-transition.
299 */
300 prop->dest_width = 1;
301 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900302}
303
304/**
305 * Internal APIs to be called from ivi_layout_commit_changes.
306 */
307static void
308update_opacity(struct ivi_layout_layer *ivilayer,
309 struct ivi_layout_surface *ivisurf)
310{
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000311 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900312 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
313 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
314
Nobuhiko Tanibata90c27892015-12-26 23:52:51 +0900315 tmpview = get_weston_view(ivisurf);
316 assert(tmpview != NULL);
317 tmpview->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900318}
319
320static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900321get_rotate_values(enum wl_output_transform orientation,
322 float *v_sin,
323 float *v_cos)
324{
325 switch (orientation) {
326 case WL_OUTPUT_TRANSFORM_90:
327 *v_sin = 1.0f;
328 *v_cos = 0.0f;
329 break;
330 case WL_OUTPUT_TRANSFORM_180:
331 *v_sin = 0.0f;
332 *v_cos = -1.0f;
333 break;
334 case WL_OUTPUT_TRANSFORM_270:
335 *v_sin = -1.0f;
336 *v_cos = 0.0f;
337 break;
338 case WL_OUTPUT_TRANSFORM_NORMAL:
339 default:
340 *v_sin = 0.0f;
341 *v_cos = 1.0f;
342 break;
343 }
344}
345
346static void
347get_scale(enum wl_output_transform orientation,
348 float dest_width,
349 float dest_height,
350 float source_width,
351 float source_height,
352 float *scale_x,
353 float *scale_y)
354{
355 switch (orientation) {
356 case WL_OUTPUT_TRANSFORM_90:
357 *scale_x = dest_width / source_height;
358 *scale_y = dest_height / source_width;
359 break;
360 case WL_OUTPUT_TRANSFORM_180:
361 *scale_x = dest_width / source_width;
362 *scale_y = dest_height / source_height;
363 break;
364 case WL_OUTPUT_TRANSFORM_270:
365 *scale_x = dest_width / source_height;
366 *scale_y = dest_height / source_width;
367 break;
368 case WL_OUTPUT_TRANSFORM_NORMAL:
369 default:
370 *scale_x = dest_width / source_width;
371 *scale_y = dest_height / source_height;
372 break;
373 }
374}
375
376static void
377calc_transformation_matrix(struct ivi_rectangle *source_rect,
378 struct ivi_rectangle *dest_rect,
379 enum wl_output_transform orientation,
380 struct weston_matrix *m)
381{
382 float source_center_x;
383 float source_center_y;
384 float vsin;
385 float vcos;
386 float scale_x;
387 float scale_y;
388 float translate_x;
389 float translate_y;
390
391 source_center_x = source_rect->x + source_rect->width * 0.5f;
392 source_center_y = source_rect->y + source_rect->height * 0.5f;
393 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
394
395 get_rotate_values(orientation, &vsin, &vcos);
396 weston_matrix_rotate_xy(m, vcos, vsin);
397
398 get_scale(orientation,
399 dest_rect->width,
400 dest_rect->height,
401 source_rect->width,
402 source_rect->height,
403 &scale_x,
404 &scale_y);
405 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
406
407 translate_x = dest_rect->width * 0.5f + dest_rect->x;
408 translate_y = dest_rect->height * 0.5f + dest_rect->y;
409 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
410}
411
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900412/*
413 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900414 */
415static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900416ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
417 const struct ivi_rectangle *rect2,
418 struct ivi_rectangle *rect_output)
419{
420 int32_t rect1_right = rect1->x + rect1->width;
421 int32_t rect1_bottom = rect1->y + rect1->height;
422 int32_t rect2_right = rect2->x + rect2->width;
423 int32_t rect2_bottom = rect2->y + rect2->height;
424
425 rect_output->x = max(rect1->x, rect2->x);
426 rect_output->y = max(rect1->y, rect2->y);
427 rect_output->width = rect1_right < rect2_right ?
428 rect1_right - rect_output->x :
429 rect2_right - rect_output->x;
430 rect_output->height = rect1_bottom < rect2_bottom ?
431 rect1_bottom - rect_output->y :
432 rect2_bottom - rect_output->y;
433
434 if (rect_output->width < 0 || rect_output->height < 0) {
435 rect_output->width = 0;
436 rect_output->height = 0;
437 }
438}
439
440/*
441 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
442 * and store the result in rect_output.
443 * The boundingbox must be given in the same coordinate space as rect_output.
444 * Additionally, there are the following restrictions on the matrix:
445 * - no projective transformations
446 * - no skew
447 * - only multiples of 90-degree rotations supported
448 *
449 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
450 * as a fail-safe with log.
451 */
452static void
453calc_inverse_matrix_transform(const struct weston_matrix *matrix,
454 const struct ivi_rectangle *rect_input,
455 const struct ivi_rectangle *boundingbox,
456 struct ivi_rectangle *rect_output)
457{
458 struct weston_matrix m;
459 struct weston_vector top_left;
460 struct weston_vector bottom_right;
461
462 assert(boundingbox != rect_output);
463
464 if (weston_matrix_invert(&m, matrix) < 0) {
465 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
466 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
467 rect_output->x = boundingbox->x;
468 rect_output->y = boundingbox->y;
469 rect_output->width = boundingbox->width;
470 rect_output->height = boundingbox->height;
471 }
472
473 /* The vectors and matrices involved will always produce f[3] == 1.0. */
474 top_left.f[0] = rect_input->x;
475 top_left.f[1] = rect_input->y;
476 top_left.f[2] = 0.0f;
477 top_left.f[3] = 1.0f;
478
479 bottom_right.f[0] = rect_input->x + rect_input->width;
480 bottom_right.f[1] = rect_input->y + rect_input->height;
481 bottom_right.f[2] = 0.0f;
482 bottom_right.f[3] = 1.0f;
483
484 weston_matrix_transform(&m, &top_left);
485 weston_matrix_transform(&m, &bottom_right);
486
487 if (top_left.f[0] < bottom_right.f[0]) {
488 rect_output->x = top_left.f[0];
489 rect_output->width = bottom_right.f[0] - rect_output->x;
490 } else {
491 rect_output->x = bottom_right.f[0];
492 rect_output->width = top_left.f[0] - rect_output->x;
493 }
494
495 if (top_left.f[1] < bottom_right.f[1]) {
496 rect_output->y = top_left.f[1];
497 rect_output->height = bottom_right.f[1] - rect_output->y;
498 } else {
499 rect_output->y = bottom_right.f[1];
500 rect_output->height = top_left.f[1] - rect_output->y;
501 }
502
503 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
504}
505
506/**
507 * This computes the whole transformation matrix:m from surface-local
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900508 * coordinates to multi screens coordinate, which is global coordinates.
509 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900510 *
511 * Additionally, this computes the mask on surface-local coordinates as a
512 * ivi_rectangle. This can be set to weston_view_set_mask.
513 *
514 * The mask is computed by following steps
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900515 * - destination rectangle of layer is tansformed to multi screen coordinate,
516 * global coordinates. This is done by adding weston_output.{x,y} in simple
517 * because there is no scaled and rotated transformation.
518 * - destination rectangle of layer in multi screens coordinate needs to be
519 * intersected inside of a screen the layer is assigned to. This is because
520 * overlapped region of weston surface in another screen shall not be
521 * displayed according to ivi use case.
522 * - destination rectangle of layer
523 * - in multi screen coordinates,
524 * - and intersected inside of an assigned screen,
525 * is inversed to surface-local cooodinates by inversed matrix:m.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900526 * - the area is intersected by intersected area between weston_surface and
527 * source rectangle of ivi_surface.
528 */
529static void
530calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900531 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900532 struct ivi_layout_layer *ivilayer,
533 struct ivi_layout_surface *ivisurf,
534 struct weston_matrix *m,
535 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900536{
537 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
538 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900539 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900540 struct ivi_rectangle weston_surface_rect = { 0,
541 0,
542 ivisurf->surface->width,
543 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900544 struct ivi_rectangle surface_source_rect = { sp->source_x,
545 sp->source_y,
546 sp->source_width,
547 sp->source_height };
548 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
549 sp->dest_y,
550 sp->dest_width,
551 sp->dest_height };
552 struct ivi_rectangle layer_source_rect = { lp->source_x,
553 lp->source_y,
554 lp->source_width,
555 lp->source_height };
556 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
557 lp->dest_y,
558 lp->dest_width,
559 lp->dest_height };
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900560 struct ivi_rectangle screen_dest_rect = { output->x,
561 output->y,
562 output->width,
563 output->height };
564 struct ivi_rectangle layer_dest_rect_in_global =
565 { lp->dest_x + output->x,
566 lp->dest_y + output->y,
567 lp->dest_width,
568 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900569 struct ivi_rectangle surface_result;
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900570 struct ivi_rectangle layer_dest_rect_in_global_intersected;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900571
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900572 /*
573 * the whole transformation matrix:m from surface-local
574 * coordinates to global coordinates, which is computed by
575 * two steps,
576 * - surface-local coordinates to layer-local coordinates
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900577 * - layer-local coordinates to a single screen-local coordinates
578 * - a single screen-local coordinates to multi screen coordinates,
579 * which is global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900580 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900581 calc_transformation_matrix(&surface_source_rect,
582 &surface_dest_rect,
583 sp->orientation, m);
584
585 calc_transformation_matrix(&layer_source_rect,
586 &layer_dest_rect,
587 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900588
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900589 weston_matrix_translate(m, output->x, output->y, 0.0f);
590
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900591 /* this intersected ivi_rectangle would be used for masking
592 * weston_surface
593 */
594 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
595 &surface_result);
596
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900597 /*
598 * destination rectangle of layer in multi screens coordinate
599 * is intersected to avoid displaying outside of an assigned screen.
600 */
601 ivi_rectangle_intersect(&layer_dest_rect_in_global, &screen_dest_rect,
602 &layer_dest_rect_in_global_intersected);
603
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900604 /* calc masking area of weston_surface from m */
605 calc_inverse_matrix_transform(m,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900606 &layer_dest_rect_in_global_intersected,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900607 &surface_result,
608 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900609}
610
611static void
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900612update_prop(struct ivi_layout_screen *iviscrn,
613 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900614 struct ivi_layout_surface *ivisurf)
615{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900616 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900617 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900618 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900619
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900620 /*In case of no prop change, this just returns*/
621 if (!ivilayer->event_mask && !ivisurf->event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900622 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900623
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900624 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900625
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000626 tmpview = get_weston_view(ivisurf);
627 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900628
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900629 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
630 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
631 can_calc = false;
632 }
633
634 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
635 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
636 can_calc = false;
637 }
638
639 if (can_calc) {
640 wl_list_remove(&ivisurf->transform.link);
641 weston_matrix_init(&ivisurf->transform.matrix);
642
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900643 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900644 iviscrn, ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900645
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000646 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
647 wl_list_insert(&tmpview->geometry.transformation_list,
648 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900649
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000650 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900651 }
652
653 ivisurf->update_count++;
654
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000655 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900656
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000657 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900658}
659
660static void
661commit_changes(struct ivi_layout *layout)
662{
663 struct ivi_layout_screen *iviscrn = NULL;
664 struct ivi_layout_layer *ivilayer = NULL;
665 struct ivi_layout_surface *ivisurf = NULL;
666
667 wl_list_for_each(iviscrn, &layout->screen_list, link) {
668 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900669 /*
670 * If ivilayer is invisible, weston_view of ivisurf doesn't
671 * need to be modified.
672 */
673 if (ivilayer->prop.visibility == false)
674 continue;
675
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900676 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900677 /*
678 * If ivilayer is invisible, weston_view of ivisurf doesn't
679 * need to be modified.
680 */
681 if (ivisurf->prop.visibility == false)
682 continue;
683
684 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900685 }
686 }
687 }
688}
689
690static void
691commit_surface_list(struct ivi_layout *layout)
692{
693 struct ivi_layout_surface *ivisurf = NULL;
694 int32_t dest_x = 0;
695 int32_t dest_y = 0;
696 int32_t dest_width = 0;
697 int32_t dest_height = 0;
698 int32_t configured = 0;
699
700 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300701 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900702 dest_x = ivisurf->prop.dest_x;
703 dest_y = ivisurf->prop.dest_y;
704 dest_width = ivisurf->prop.dest_width;
705 dest_height = ivisurf->prop.dest_height;
706
707 ivi_layout_transition_move_resize_view(ivisurf,
708 ivisurf->pending.prop.dest_x,
709 ivisurf->pending.prop.dest_y,
710 ivisurf->pending.prop.dest_width,
711 ivisurf->pending.prop.dest_height,
712 ivisurf->pending.prop.transition_duration);
713
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300714 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900715 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
716 } else {
717 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
718 }
719
720 ivisurf->prop = ivisurf->pending.prop;
721 ivisurf->prop.dest_x = dest_x;
722 ivisurf->prop.dest_y = dest_y;
723 ivisurf->prop.dest_width = dest_width;
724 ivisurf->prop.dest_height = dest_height;
725 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
726 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
727
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300728 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900729 dest_x = ivisurf->prop.dest_x;
730 dest_y = ivisurf->prop.dest_y;
731 dest_width = ivisurf->prop.dest_width;
732 dest_height = ivisurf->prop.dest_height;
733
734 ivi_layout_transition_move_resize_view(ivisurf,
735 ivisurf->pending.prop.dest_x,
736 ivisurf->pending.prop.dest_y,
737 ivisurf->pending.prop.dest_width,
738 ivisurf->pending.prop.dest_height,
739 ivisurf->pending.prop.transition_duration);
740
741 ivisurf->prop = ivisurf->pending.prop;
742 ivisurf->prop.dest_x = dest_x;
743 ivisurf->prop.dest_y = dest_y;
744 ivisurf->prop.dest_width = dest_width;
745 ivisurf->prop.dest_height = dest_height;
746
747 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
748 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
749
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300750 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900751 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300752 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900753 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
754 } else {
755 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
756 }
757
758 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
759 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
760 configured = 1;
761 }
762
763 ivisurf->prop = ivisurf->pending.prop;
764 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
765 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
766
Pekka Paalanen1f821932016-03-15 16:57:51 +0200767 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200768 shell_surface_send_configure(ivisurf->surface,
769 ivisurf->prop.dest_width,
770 ivisurf->prop.dest_height);
771 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900772 } else {
773 configured = 0;
774 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
775 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
776 configured = 1;
777 }
778
779 ivisurf->prop = ivisurf->pending.prop;
780 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
781 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
782
Pekka Paalanen1f821932016-03-15 16:57:51 +0200783 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200784 shell_surface_send_configure(ivisurf->surface,
785 ivisurf->prop.dest_width,
786 ivisurf->prop.dest_height);
787 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900788 }
789 }
790}
791
792static void
793commit_layer_list(struct ivi_layout *layout)
794{
795 struct ivi_layout_layer *ivilayer = NULL;
796 struct ivi_layout_surface *ivisurf = NULL;
797 struct ivi_layout_surface *next = NULL;
798
799 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300800 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900801 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 -0300802 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900803 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
804 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
805 NULL, NULL,
806 ivilayer->pending.prop.transition_duration);
807 }
808 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
809
810 ivilayer->prop = ivilayer->pending.prop;
811
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000812 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900813 continue;
814 }
815
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000816 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
817 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000818 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000819 wl_list_remove(&ivisurf->order.link);
820 wl_list_init(&ivisurf->order.link);
821 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900822 }
823
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000824 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900825
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000826 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900827 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000828 wl_list_remove(&ivisurf->order.link);
829 wl_list_insert(&ivilayer->order.surface_list,
830 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000831 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000832 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900833 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000834
835 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900836 }
837}
838
839static void
840commit_screen_list(struct ivi_layout *layout)
841{
842 struct ivi_layout_screen *iviscrn = NULL;
843 struct ivi_layout_layer *ivilayer = NULL;
844 struct ivi_layout_layer *next = NULL;
845 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000846 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900847
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900848 /* Clear view list of layout ivi_layer */
849 wl_list_init(&layout->layout_layer.view_list.link);
850
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900851 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000852 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900853 wl_list_for_each_safe(ivilayer, next,
854 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000855 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000856 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900857 wl_list_init(&ivilayer->order.link);
858 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
859 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900860
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000861 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900862
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900863 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
864 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900865 /* FIXME: avoid to insert order.link to multiple screens */
866 wl_list_remove(&ivilayer->order.link);
867
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900868 wl_list_insert(&iviscrn->order.layer_list,
869 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000870 ivilayer->on_screen = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900871 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
872 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900873
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000874 iviscrn->order.dirty = 0;
875 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900876
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900877 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
878 if (ivilayer->prop.visibility == false)
879 continue;
880
881 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900882 if (ivisurf->prop.visibility == false)
883 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000884
885 tmpview = get_weston_view(ivisurf);
886 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900887
888 weston_layer_entry_insert(&layout->layout_layer.view_list,
889 &tmpview->layer_link);
890
891 ivisurf->surface->output = iviscrn->output;
892 }
893 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900894 }
895}
896
897static void
898commit_transition(struct ivi_layout* layout)
899{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300900 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900901 return;
902 }
903
904 wl_list_insert_list(&layout->transitions->transition_list,
905 &layout->pending_transition_list);
906
907 wl_list_init(&layout->pending_transition_list);
908
909 wl_event_source_timer_update(layout->transitions->event_source, 1);
910}
911
912static void
913send_surface_prop(struct ivi_layout_surface *ivisurf)
914{
915 wl_signal_emit(&ivisurf->property_changed, ivisurf);
916 ivisurf->event_mask = 0;
917}
918
919static void
920send_layer_prop(struct ivi_layout_layer *ivilayer)
921{
922 wl_signal_emit(&ivilayer->property_changed, ivilayer);
923 ivilayer->event_mask = 0;
924}
925
926static void
927send_prop(struct ivi_layout *layout)
928{
929 struct ivi_layout_layer *ivilayer = NULL;
930 struct ivi_layout_surface *ivisurf = NULL;
931
932 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900933 if (ivilayer->event_mask)
934 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900935 }
936
937 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900938 if (ivisurf->event_mask)
939 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900940 }
941}
942
943static void
944clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
945{
946 struct ivi_layout_surface *surface_link = NULL;
947 struct ivi_layout_surface *surface_next = NULL;
948
949 wl_list_for_each_safe(surface_link, surface_next,
950 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000951 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900952 wl_list_init(&surface_link->pending.link);
953 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900954}
955
956static void
957clear_surface_order_list(struct ivi_layout_layer *ivilayer)
958{
959 struct ivi_layout_surface *surface_link = NULL;
960 struct ivi_layout_surface *surface_next = NULL;
961
962 wl_list_for_each_safe(surface_link, surface_next,
963 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000964 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900965 wl_list_init(&surface_link->order.link);
966 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900967}
968
969static void
970layer_created(struct wl_listener *listener, void *data)
971{
972 struct ivi_layout_layer *ivilayer = data;
973
974 struct listener_layout_notification *notification =
975 container_of(listener,
976 struct listener_layout_notification,
977 listener);
978
979 struct ivi_layout_notification_callback *created_callback =
980 notification->userdata;
981
982 ((layer_create_notification_func)created_callback->callback)
983 (ivilayer, created_callback->data);
984}
985
986static void
987layer_removed(struct wl_listener *listener, void *data)
988{
989 struct ivi_layout_layer *ivilayer = data;
990
991 struct listener_layout_notification *notification =
992 container_of(listener,
993 struct listener_layout_notification,
994 listener);
995
996 struct ivi_layout_notification_callback *removed_callback =
997 notification->userdata;
998
999 ((layer_remove_notification_func)removed_callback->callback)
1000 (ivilayer, removed_callback->data);
1001}
1002
1003static void
1004layer_prop_changed(struct wl_listener *listener, void *data)
1005{
1006 struct ivi_layout_layer *ivilayer = data;
1007
1008 struct listener_layout_notification *layout_listener =
1009 container_of(listener,
1010 struct listener_layout_notification,
1011 listener);
1012
1013 struct ivi_layout_notification_callback *prop_callback =
1014 layout_listener->userdata;
1015
1016 ((layer_property_notification_func)prop_callback->callback)
1017 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1018}
1019
1020static void
1021surface_created(struct wl_listener *listener, void *data)
1022{
1023 struct ivi_layout_surface *ivisurface = data;
1024
1025 struct listener_layout_notification *notification =
1026 container_of(listener,
1027 struct listener_layout_notification,
1028 listener);
1029
1030 struct ivi_layout_notification_callback *created_callback =
1031 notification->userdata;
1032
1033 ((surface_create_notification_func)created_callback->callback)
1034 (ivisurface, created_callback->data);
1035}
1036
1037static void
1038surface_removed(struct wl_listener *listener, void *data)
1039{
1040 struct ivi_layout_surface *ivisurface = data;
1041
1042 struct listener_layout_notification *notification =
1043 container_of(listener,
1044 struct listener_layout_notification,
1045 listener);
1046
1047 struct ivi_layout_notification_callback *removed_callback =
1048 notification->userdata;
1049
1050 ((surface_remove_notification_func)removed_callback->callback)
1051 (ivisurface, removed_callback->data);
1052}
1053
1054static void
1055surface_prop_changed(struct wl_listener *listener, void *data)
1056{
1057 struct ivi_layout_surface *ivisurf = data;
1058
1059 struct listener_layout_notification *layout_listener =
1060 container_of(listener,
1061 struct listener_layout_notification,
1062 listener);
1063
1064 struct ivi_layout_notification_callback *prop_callback =
1065 layout_listener->userdata;
1066
1067 ((surface_property_notification_func)prop_callback->callback)
1068 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1069
1070 ivisurf->event_mask = 0;
1071}
1072
1073static void
1074surface_configure_changed(struct wl_listener *listener,
1075 void *data)
1076{
1077 struct ivi_layout_surface *ivisurface = data;
1078
1079 struct listener_layout_notification *notification =
1080 container_of(listener,
1081 struct listener_layout_notification,
1082 listener);
1083
1084 struct ivi_layout_notification_callback *configure_changed_callback =
1085 notification->userdata;
1086
1087 ((surface_configure_notification_func)configure_changed_callback->callback)
1088 (ivisurface, configure_changed_callback->data);
1089}
1090
1091static int32_t
1092add_notification(struct wl_signal *signal,
1093 wl_notify_func_t callback,
1094 void *userdata)
1095{
1096 struct listener_layout_notification *notification = NULL;
1097
1098 notification = malloc(sizeof *notification);
1099 if (notification == NULL) {
1100 weston_log("fails to allocate memory\n");
1101 free(userdata);
1102 return IVI_FAILED;
1103 }
1104
1105 notification->listener.notify = callback;
1106 notification->userdata = userdata;
1107
1108 wl_signal_add(signal, &notification->listener);
1109
1110 return IVI_SUCCEEDED;
1111}
1112
1113static void
1114remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1115{
1116 struct wl_listener *listener = NULL;
1117 struct wl_listener *next = NULL;
1118
1119 wl_list_for_each_safe(listener, next, listener_list, link) {
1120 struct listener_layout_notification *notification =
1121 container_of(listener,
1122 struct listener_layout_notification,
1123 listener);
1124
1125 struct ivi_layout_notification_callback *notification_callback =
1126 notification->userdata;
1127
1128 if ((notification_callback->callback != callback) ||
1129 (notification_callback->data != userdata)) {
1130 continue;
1131 }
1132
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001133 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001134
1135 free(notification->userdata);
1136 free(notification);
1137 }
1138}
1139
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001140/**
1141 * Exported APIs of ivi-layout library are implemented from here.
1142 * Brief of APIs is described in ivi-layout-export.h.
1143 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001144static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001145ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1146 void *userdata)
1147{
1148 struct ivi_layout *layout = get_instance();
1149 struct ivi_layout_notification_callback *created_callback = NULL;
1150
1151 if (callback == NULL) {
1152 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1153 return IVI_FAILED;
1154 }
1155
1156 created_callback = malloc(sizeof *created_callback);
1157 if (created_callback == NULL) {
1158 weston_log("fails to allocate memory\n");
1159 return IVI_FAILED;
1160 }
1161
1162 created_callback->callback = callback;
1163 created_callback->data = userdata;
1164
1165 return add_notification(&layout->layer_notification.created,
1166 layer_created,
1167 created_callback);
1168}
1169
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001170static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001171ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1172 void *userdata)
1173{
1174 struct ivi_layout *layout = get_instance();
1175 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1176}
1177
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001178static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001179ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1180 void *userdata)
1181{
1182 struct ivi_layout *layout = get_instance();
1183 struct ivi_layout_notification_callback *removed_callback = NULL;
1184
1185 if (callback == NULL) {
1186 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1187 return IVI_FAILED;
1188 }
1189
1190 removed_callback = malloc(sizeof *removed_callback);
1191 if (removed_callback == NULL) {
1192 weston_log("fails to allocate memory\n");
1193 return IVI_FAILED;
1194 }
1195
1196 removed_callback->callback = callback;
1197 removed_callback->data = userdata;
1198 return add_notification(&layout->layer_notification.removed,
1199 layer_removed,
1200 removed_callback);
1201}
1202
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001203static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001204ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1205 void *userdata)
1206{
1207 struct ivi_layout *layout = get_instance();
1208 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1209}
1210
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001211static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001212ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1213 void *userdata)
1214{
1215 struct ivi_layout *layout = get_instance();
1216 struct ivi_layout_notification_callback *created_callback = NULL;
1217
1218 if (callback == NULL) {
1219 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1220 return IVI_FAILED;
1221 }
1222
1223 created_callback = malloc(sizeof *created_callback);
1224 if (created_callback == NULL) {
1225 weston_log("fails to allocate memory\n");
1226 return IVI_FAILED;
1227 }
1228
1229 created_callback->callback = callback;
1230 created_callback->data = userdata;
1231
1232 return add_notification(&layout->surface_notification.created,
1233 surface_created,
1234 created_callback);
1235}
1236
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001237static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001238ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1239 void *userdata)
1240{
1241 struct ivi_layout *layout = get_instance();
1242 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1243}
1244
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001245static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001246ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1247 void *userdata)
1248{
1249 struct ivi_layout *layout = get_instance();
1250 struct ivi_layout_notification_callback *removed_callback = NULL;
1251
1252 if (callback == NULL) {
1253 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1254 return IVI_FAILED;
1255 }
1256
1257 removed_callback = malloc(sizeof *removed_callback);
1258 if (removed_callback == NULL) {
1259 weston_log("fails to allocate memory\n");
1260 return IVI_FAILED;
1261 }
1262
1263 removed_callback->callback = callback;
1264 removed_callback->data = userdata;
1265
1266 return add_notification(&layout->surface_notification.removed,
1267 surface_removed,
1268 removed_callback);
1269}
1270
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001271static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001272ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1273 void *userdata)
1274{
1275 struct ivi_layout *layout = get_instance();
1276 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1277}
1278
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001279static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001280ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1281 void *userdata)
1282{
1283 struct ivi_layout *layout = get_instance();
1284 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1285 if (callback == NULL) {
1286 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1287 return IVI_FAILED;
1288 }
1289
1290 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1291 if (configure_changed_callback == NULL) {
1292 weston_log("fails to allocate memory\n");
1293 return IVI_FAILED;
1294 }
1295
1296 configure_changed_callback->callback = callback;
1297 configure_changed_callback->data = userdata;
1298
1299 return add_notification(&layout->surface_notification.configure_changed,
1300 surface_configure_changed,
1301 configure_changed_callback);
1302}
1303
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001304static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001305ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1306 void *userdata)
1307{
1308 struct ivi_layout *layout = get_instance();
1309 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1310}
1311
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001312uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001313ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1314{
1315 return ivisurf->id_surface;
1316}
1317
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001318static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001319ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1320{
1321 return ivilayer->id_layer;
1322}
1323
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001324static uint32_t
1325ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1326{
1327 return iviscrn->id_screen;
1328}
1329
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001330static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001331ivi_layout_get_layer_from_id(uint32_t id_layer)
1332{
1333 struct ivi_layout *layout = get_instance();
1334 struct ivi_layout_layer *ivilayer = NULL;
1335
1336 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1337 if (ivilayer->id_layer == id_layer) {
1338 return ivilayer;
1339 }
1340 }
1341
1342 return NULL;
1343}
1344
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001345struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001346ivi_layout_get_surface_from_id(uint32_t id_surface)
1347{
1348 struct ivi_layout *layout = get_instance();
1349 struct ivi_layout_surface *ivisurf = NULL;
1350
1351 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1352 if (ivisurf->id_surface == id_surface) {
1353 return ivisurf;
1354 }
1355 }
1356
1357 return NULL;
1358}
1359
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001360static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001361ivi_layout_get_screen_from_id(uint32_t id_screen)
1362{
1363 struct ivi_layout *layout = get_instance();
1364 struct ivi_layout_screen *iviscrn = NULL;
1365
1366 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Nobuhiko Tanibata3e710d12015-11-25 23:36:09 +09001367 if (iviscrn->id_screen == id_screen)
1368 return iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001369 }
1370
1371 return NULL;
1372}
1373
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001374static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001375ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1376 int32_t *pWidth, int32_t *pHeight)
1377{
1378 struct weston_output *output = NULL;
1379
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001380 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001381 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1382 return IVI_FAILED;
1383 }
1384
1385 output = iviscrn->output;
1386 *pWidth = output->current_mode->width;
1387 *pHeight = output->current_mode->height;
1388
1389 return IVI_SUCCEEDED;
1390}
1391
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001392static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001393ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1394 surface_property_notification_func callback,
1395 void *userdata)
1396{
1397 struct listener_layout_notification* notification = NULL;
1398 struct ivi_layout_notification_callback *prop_callback = NULL;
1399
1400 if (ivisurf == NULL || callback == NULL) {
1401 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1402 return IVI_FAILED;
1403 }
1404
1405 notification = malloc(sizeof *notification);
1406 if (notification == NULL) {
1407 weston_log("fails to allocate memory\n");
1408 return IVI_FAILED;
1409 }
1410
1411 prop_callback = malloc(sizeof *prop_callback);
1412 if (prop_callback == NULL) {
1413 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001414 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001415 return IVI_FAILED;
1416 }
1417
1418 prop_callback->callback = callback;
1419 prop_callback->data = userdata;
1420
1421 notification->listener.notify = surface_prop_changed;
1422 notification->userdata = prop_callback;
1423
1424 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1425
1426 return IVI_SUCCEEDED;
1427}
1428
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001429static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001430ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1431{
1432 if (ivilayer == NULL) {
1433 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1434 return NULL;
1435 }
1436
1437 return &ivilayer->prop;
1438}
1439
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001440static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001441ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1442{
1443 struct ivi_layout *layout = get_instance();
1444 struct ivi_layout_screen *iviscrn = NULL;
1445 int32_t length = 0;
1446 int32_t n = 0;
1447
1448 if (pLength == NULL || ppArray == NULL) {
1449 weston_log("ivi_layout_get_screens: invalid argument\n");
1450 return IVI_FAILED;
1451 }
1452
1453 length = wl_list_length(&layout->screen_list);
1454
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001455 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001456 /* the Array must be free by module which called this function */
1457 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1458 if (*ppArray == NULL) {
1459 weston_log("fails to allocate memory\n");
1460 return IVI_FAILED;
1461 }
1462
1463 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1464 (*ppArray)[n++] = iviscrn;
1465 }
1466 }
1467
1468 *pLength = length;
1469
1470 return IVI_SUCCEEDED;
1471}
1472
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001473static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001474ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1475 int32_t *pLength,
1476 struct ivi_layout_screen ***ppArray)
1477{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001478 int32_t length = 0;
1479 int32_t n = 0;
1480
1481 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1482 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1483 return IVI_FAILED;
1484 }
1485
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001486 if (ivilayer->on_screen != NULL)
1487 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001488
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001489 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001490 /* the Array must be free by module which called this function */
1491 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1492 if (*ppArray == NULL) {
1493 weston_log("fails to allocate memory\n");
1494 return IVI_FAILED;
1495 }
1496
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001497 (*ppArray)[n++] = ivilayer->on_screen;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001498 }
1499
1500 *pLength = length;
1501
1502 return IVI_SUCCEEDED;
1503}
1504
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001505static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001506ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1507{
1508 struct ivi_layout *layout = get_instance();
1509 struct ivi_layout_layer *ivilayer = NULL;
1510 int32_t length = 0;
1511 int32_t n = 0;
1512
1513 if (pLength == NULL || ppArray == NULL) {
1514 weston_log("ivi_layout_get_layers: invalid argument\n");
1515 return IVI_FAILED;
1516 }
1517
1518 length = wl_list_length(&layout->layer_list);
1519
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001520 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001521 /* the Array must be free by module which called this function */
1522 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1523 if (*ppArray == NULL) {
1524 weston_log("fails to allocate memory\n");
1525 return IVI_FAILED;
1526 }
1527
1528 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1529 (*ppArray)[n++] = ivilayer;
1530 }
1531 }
1532
1533 *pLength = length;
1534
1535 return IVI_SUCCEEDED;
1536}
1537
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001538static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001539ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1540 int32_t *pLength,
1541 struct ivi_layout_layer ***ppArray)
1542{
1543 struct ivi_layout_layer *ivilayer = NULL;
1544 int32_t length = 0;
1545 int32_t n = 0;
1546
1547 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1548 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1549 return IVI_FAILED;
1550 }
1551
1552 length = wl_list_length(&iviscrn->order.layer_list);
1553
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001554 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001555 /* the Array must be free by module which called this function */
1556 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1557 if (*ppArray == NULL) {
1558 weston_log("fails to allocate memory\n");
1559 return IVI_FAILED;
1560 }
1561
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001562 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001563 (*ppArray)[n++] = ivilayer;
1564 }
1565 }
1566
1567 *pLength = length;
1568
1569 return IVI_SUCCEEDED;
1570}
1571
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001572static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001573ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1574 int32_t *pLength,
1575 struct ivi_layout_layer ***ppArray)
1576{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001577 int32_t length = 0;
1578 int32_t n = 0;
1579
1580 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1581 weston_log("ivi_layout_getLayers: invalid argument\n");
1582 return IVI_FAILED;
1583 }
1584
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001585 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001586 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001587 length = 1;
1588 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001589 if (*ppArray == NULL) {
1590 weston_log("fails to allocate memory\n");
1591 return IVI_FAILED;
1592 }
1593
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001594 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001595 }
1596
1597 *pLength = length;
1598
1599 return IVI_SUCCEEDED;
1600}
1601
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001602static
1603int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001604ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1605{
1606 struct ivi_layout *layout = get_instance();
1607 struct ivi_layout_surface *ivisurf = NULL;
1608 int32_t length = 0;
1609 int32_t n = 0;
1610
1611 if (pLength == NULL || ppArray == NULL) {
1612 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1613 return IVI_FAILED;
1614 }
1615
1616 length = wl_list_length(&layout->surface_list);
1617
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001618 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001619 /* the Array must be free by module which called this function */
1620 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1621 if (*ppArray == NULL) {
1622 weston_log("fails to allocate memory\n");
1623 return IVI_FAILED;
1624 }
1625
1626 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1627 (*ppArray)[n++] = ivisurf;
1628 }
1629 }
1630
1631 *pLength = length;
1632
1633 return IVI_SUCCEEDED;
1634}
1635
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001636static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001637ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1638 int32_t *pLength,
1639 struct ivi_layout_surface ***ppArray)
1640{
1641 struct ivi_layout_surface *ivisurf = NULL;
1642 int32_t length = 0;
1643 int32_t n = 0;
1644
1645 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1646 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1647 return IVI_FAILED;
1648 }
1649
1650 length = wl_list_length(&ivilayer->order.surface_list);
1651
1652 if (length != 0) {
1653 /* the Array must be free by module which called this function */
1654 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1655 if (*ppArray == NULL) {
1656 weston_log("fails to allocate memory\n");
1657 return IVI_FAILED;
1658 }
1659
1660 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1661 (*ppArray)[n++] = ivisurf;
1662 }
1663 }
1664
1665 *pLength = length;
1666
1667 return IVI_SUCCEEDED;
1668}
1669
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001670static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001671ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1672 int32_t width, int32_t height)
1673{
1674 struct ivi_layout *layout = get_instance();
1675 struct ivi_layout_layer *ivilayer = NULL;
1676
1677 ivilayer = get_layer(&layout->layer_list, id_layer);
1678 if (ivilayer != NULL) {
1679 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001680 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001681 return ivilayer;
1682 }
1683
1684 ivilayer = calloc(1, sizeof *ivilayer);
1685 if (ivilayer == NULL) {
1686 weston_log("fails to allocate memory\n");
1687 return NULL;
1688 }
1689
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001690 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001691 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001692 ivilayer->layout = layout;
1693 ivilayer->id_layer = id_layer;
1694
1695 init_layer_properties(&ivilayer->prop, width, height);
1696 ivilayer->event_mask = 0;
1697
1698 wl_list_init(&ivilayer->pending.surface_list);
1699 wl_list_init(&ivilayer->pending.link);
1700 ivilayer->pending.prop = ivilayer->prop;
1701
1702 wl_list_init(&ivilayer->order.surface_list);
1703 wl_list_init(&ivilayer->order.link);
1704
1705 wl_list_insert(&layout->layer_list, &ivilayer->link);
1706
1707 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1708
1709 return ivilayer;
1710}
1711
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001712static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001713ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1714{
1715 if (ivilayer == NULL) {
1716 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1717 return;
1718 }
1719
1720 remove_all_notification(&ivilayer->property_changed.listener_list);
1721}
1722
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001723static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001724ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1725 layer_property_notification_func callback,
1726 void *userdata)
1727{
1728 if (ivilayer == NULL) {
1729 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1730 return;
1731 }
1732
1733 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1734}
1735
1736static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001737ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001738{
1739 struct ivi_layout *layout = get_instance();
1740
1741 if (ivilayer == NULL) {
1742 weston_log("ivi_layout_layer_remove: invalid argument\n");
1743 return;
1744 }
1745
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001746 if (--ivilayer->ref_count > 0)
1747 return;
1748
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001749 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1750
1751 clear_surface_pending_list(ivilayer);
1752 clear_surface_order_list(ivilayer);
1753
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001754 wl_list_remove(&ivilayer->pending.link);
1755 wl_list_remove(&ivilayer->order.link);
1756 wl_list_remove(&ivilayer->link);
1757
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001758 ivi_layout_layer_remove_notification(ivilayer);
1759
1760 free(ivilayer);
1761}
1762
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001763int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001764ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1765 bool newVisibility)
1766{
1767 struct ivi_layout_layer_properties *prop = NULL;
1768
1769 if (ivilayer == NULL) {
1770 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1771 return IVI_FAILED;
1772 }
1773
1774 prop = &ivilayer->pending.prop;
1775 prop->visibility = newVisibility;
1776
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001777 if (ivilayer->prop.visibility != newVisibility)
1778 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1779 else
1780 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001781
1782 return IVI_SUCCEEDED;
1783}
1784
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001785int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001786ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1787 wl_fixed_t opacity)
1788{
1789 struct ivi_layout_layer_properties *prop = NULL;
1790
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001791 if (ivilayer == NULL ||
1792 opacity < wl_fixed_from_double(0.0) ||
1793 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001794 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1795 return IVI_FAILED;
1796 }
1797
1798 prop = &ivilayer->pending.prop;
1799 prop->opacity = opacity;
1800
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001801 if (ivilayer->prop.opacity != opacity)
1802 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1803 else
1804 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001805
1806 return IVI_SUCCEEDED;
1807}
1808
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001809static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001810ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1811 int32_t x, int32_t y,
1812 int32_t width, int32_t height)
1813{
1814 struct ivi_layout_layer_properties *prop = NULL;
1815
1816 if (ivilayer == NULL) {
1817 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1818 return IVI_FAILED;
1819 }
1820
1821 prop = &ivilayer->pending.prop;
1822 prop->source_x = x;
1823 prop->source_y = y;
1824 prop->source_width = width;
1825 prop->source_height = height;
1826
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001827 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1828 ivilayer->prop.source_width != width ||
1829 ivilayer->prop.source_height != height)
1830 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1831 else
1832 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001833
1834 return IVI_SUCCEEDED;
1835}
1836
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001837int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001838ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1839 int32_t x, int32_t y,
1840 int32_t width, int32_t height)
1841{
1842 struct ivi_layout_layer_properties *prop = NULL;
1843
1844 if (ivilayer == NULL) {
1845 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1846 return IVI_FAILED;
1847 }
1848
1849 prop = &ivilayer->pending.prop;
1850 prop->dest_x = x;
1851 prop->dest_y = y;
1852 prop->dest_width = width;
1853 prop->dest_height = height;
1854
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001855 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1856 ivilayer->prop.dest_width != width ||
1857 ivilayer->prop.dest_height != height)
1858 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1859 else
1860 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001861
1862 return IVI_SUCCEEDED;
1863}
1864
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001865static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001866ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1867 enum wl_output_transform orientation)
1868{
1869 struct ivi_layout_layer_properties *prop = NULL;
1870
1871 if (ivilayer == NULL) {
1872 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1873 return IVI_FAILED;
1874 }
1875
1876 prop = &ivilayer->pending.prop;
1877 prop->orientation = orientation;
1878
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001879 if (ivilayer->prop.orientation != orientation)
1880 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1881 else
1882 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001883
1884 return IVI_SUCCEEDED;
1885}
1886
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001887int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001888ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1889 struct ivi_layout_surface **pSurface,
1890 int32_t number)
1891{
1892 struct ivi_layout *layout = get_instance();
1893 struct ivi_layout_surface *ivisurf = NULL;
1894 struct ivi_layout_surface *next = NULL;
1895 uint32_t *id_surface = NULL;
1896 int32_t i = 0;
1897
1898 if (ivilayer == NULL) {
1899 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1900 return IVI_FAILED;
1901 }
1902
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001903 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001904
1905 for (i = 0; i < number; i++) {
1906 id_surface = &pSurface[i]->id_surface;
1907
1908 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
1909 if (*id_surface != ivisurf->id_surface) {
1910 continue;
1911 }
1912
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001913 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001914 wl_list_insert(&ivilayer->pending.surface_list,
1915 &ivisurf->pending.link);
1916 break;
1917 }
1918 }
1919
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001920 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001921
1922 return IVI_SUCCEEDED;
1923}
1924
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001925int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001926ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1927 bool newVisibility)
1928{
1929 struct ivi_layout_surface_properties *prop = NULL;
1930
1931 if (ivisurf == NULL) {
1932 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1933 return IVI_FAILED;
1934 }
1935
1936 prop = &ivisurf->pending.prop;
1937 prop->visibility = newVisibility;
1938
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001939 if (ivisurf->prop.visibility != newVisibility)
1940 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1941 else
1942 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001943
1944 return IVI_SUCCEEDED;
1945}
1946
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001947int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001948ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1949 wl_fixed_t opacity)
1950{
1951 struct ivi_layout_surface_properties *prop = NULL;
1952
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001953 if (ivisurf == NULL ||
1954 opacity < wl_fixed_from_double(0.0) ||
1955 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001956 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1957 return IVI_FAILED;
1958 }
1959
1960 prop = &ivisurf->pending.prop;
1961 prop->opacity = opacity;
1962
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001963 if (ivisurf->prop.opacity != opacity)
1964 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
1965 else
1966 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001967
1968 return IVI_SUCCEEDED;
1969}
1970
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001971int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001972ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1973 int32_t x, int32_t y,
1974 int32_t width, int32_t height)
1975{
1976 struct ivi_layout_surface_properties *prop = NULL;
1977
1978 if (ivisurf == NULL) {
1979 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1980 return IVI_FAILED;
1981 }
1982
1983 prop = &ivisurf->pending.prop;
1984 prop->start_x = prop->dest_x;
1985 prop->start_y = prop->dest_y;
1986 prop->dest_x = x;
1987 prop->dest_y = y;
1988 prop->start_width = prop->dest_width;
1989 prop->start_height = prop->dest_height;
1990 prop->dest_width = width;
1991 prop->dest_height = height;
1992
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001993 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
1994 ivisurf->prop.dest_width != width ||
1995 ivisurf->prop.dest_height != height)
1996 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1997 else
1998 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001999
2000 return IVI_SUCCEEDED;
2001}
2002
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002003static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002004ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2005 enum wl_output_transform orientation)
2006{
2007 struct ivi_layout_surface_properties *prop = NULL;
2008
2009 if (ivisurf == NULL) {
2010 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2011 return IVI_FAILED;
2012 }
2013
2014 prop = &ivisurf->pending.prop;
2015 prop->orientation = orientation;
2016
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002017 if (ivisurf->prop.orientation != orientation)
2018 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2019 else
2020 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002021
2022 return IVI_SUCCEEDED;
2023}
2024
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002025static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002026ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2027 struct ivi_layout_layer *addlayer)
2028{
2029 struct ivi_layout *layout = get_instance();
2030 struct ivi_layout_layer *ivilayer = NULL;
2031 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002032
2033 if (iviscrn == NULL || addlayer == NULL) {
2034 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2035 return IVI_FAILED;
2036 }
2037
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00002038 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002039 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2040 return IVI_SUCCEEDED;
2041 }
2042
2043 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2044 if (ivilayer->id_layer == addlayer->id_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002045 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002046 wl_list_insert(&iviscrn->pending.layer_list,
2047 &ivilayer->pending.link);
2048 break;
2049 }
2050 }
2051
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002052 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002053
2054 return IVI_SUCCEEDED;
2055}
2056
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002057static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002058ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2059 struct ivi_layout_layer **pLayer,
2060 const int32_t number)
2061{
2062 struct ivi_layout *layout = get_instance();
2063 struct ivi_layout_layer *ivilayer = NULL;
2064 struct ivi_layout_layer *next = NULL;
2065 uint32_t *id_layer = NULL;
2066 int32_t i = 0;
2067
2068 if (iviscrn == NULL) {
2069 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2070 return IVI_FAILED;
2071 }
2072
2073 wl_list_for_each_safe(ivilayer, next,
2074 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002075 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002076 wl_list_init(&ivilayer->pending.link);
2077 }
2078
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002079 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002080
2081 for (i = 0; i < number; i++) {
2082 id_layer = &pLayer[i]->id_layer;
2083 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2084 if (*id_layer != ivilayer->id_layer) {
2085 continue;
2086 }
2087
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002088 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002089 wl_list_insert(&iviscrn->pending.layer_list,
2090 &ivilayer->pending.link);
2091 break;
2092 }
2093 }
2094
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002095 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002096
2097 return IVI_SUCCEEDED;
2098}
2099
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002100static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002101ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2102{
2103 return iviscrn->output;
2104}
2105
2106/**
2107 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2108 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2109 * This function is used to get the result of drawing by clients.
2110 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002111static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002112ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2113{
2114 return ivisurf != NULL ? ivisurf->surface : NULL;
2115}
2116
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002117static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002118ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2119 int32_t *width, int32_t *height,
2120 int32_t *stride)
2121{
2122 int32_t w;
2123 int32_t h;
2124 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2125
2126 if (ivisurf == NULL || ivisurf->surface == NULL) {
2127 weston_log("%s: invalid argument\n", __func__);
2128 return IVI_FAILED;
2129 }
2130
2131 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2132
2133 if (width != NULL)
2134 *width = w;
2135
2136 if (height != NULL)
2137 *height = h;
2138
2139 if (stride != NULL)
2140 *stride = w * bytespp;
2141
2142 return IVI_SUCCEEDED;
2143}
2144
2145static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002146ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2147 layer_property_notification_func callback,
2148 void *userdata)
2149{
2150 struct ivi_layout_notification_callback *prop_callback = NULL;
2151
2152 if (ivilayer == NULL || callback == NULL) {
2153 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2154 return IVI_FAILED;
2155 }
2156
2157 prop_callback = malloc(sizeof *prop_callback);
2158 if (prop_callback == NULL) {
2159 weston_log("fails to allocate memory\n");
2160 return IVI_FAILED;
2161 }
2162
2163 prop_callback->callback = callback;
2164 prop_callback->data = userdata;
2165
2166 return add_notification(&ivilayer->property_changed,
2167 layer_prop_changed,
2168 prop_callback);
2169}
2170
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002171static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002172ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2173{
2174 if (ivisurf == NULL) {
2175 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2176 return NULL;
2177 }
2178
2179 return &ivisurf->prop;
2180}
2181
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002182static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002183ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2184 struct ivi_layout_surface *addsurf)
2185{
2186 struct ivi_layout *layout = get_instance();
2187 struct ivi_layout_surface *ivisurf = NULL;
2188 struct ivi_layout_surface *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002189
2190 if (ivilayer == NULL || addsurf == NULL) {
2191 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2192 return IVI_FAILED;
2193 }
2194
Wataru Natsume9c926fe2016-03-03 19:56:09 +09002195 if (addsurf->on_layer == ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002196 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002197
2198 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2199 if (ivisurf->id_surface == addsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002200 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002201 wl_list_insert(&ivilayer->pending.surface_list,
2202 &ivisurf->pending.link);
2203 break;
2204 }
2205 }
2206
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002207 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002208
2209 return IVI_SUCCEEDED;
2210}
2211
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002212static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002213ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2214 struct ivi_layout_surface *remsurf)
2215{
2216 struct ivi_layout_surface *ivisurf = NULL;
2217 struct ivi_layout_surface *next = NULL;
2218
2219 if (ivilayer == NULL || remsurf == NULL) {
2220 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2221 return;
2222 }
2223
2224 wl_list_for_each_safe(ivisurf, next,
2225 &ivilayer->pending.surface_list, pending.link) {
2226 if (ivisurf->id_surface == remsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002227 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002228 wl_list_init(&ivisurf->pending.link);
2229 break;
2230 }
2231 }
2232
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002233 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002234}
2235
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002236static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002237ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2238 int32_t x, int32_t y,
2239 int32_t width, int32_t height)
2240{
2241 struct ivi_layout_surface_properties *prop = NULL;
2242
2243 if (ivisurf == NULL) {
2244 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2245 return IVI_FAILED;
2246 }
2247
2248 prop = &ivisurf->pending.prop;
2249 prop->source_x = x;
2250 prop->source_y = y;
2251 prop->source_width = width;
2252 prop->source_height = height;
2253
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002254 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2255 ivisurf->prop.source_width != width ||
2256 ivisurf->prop.source_height != height)
2257 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2258 else
2259 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002260
2261 return IVI_SUCCEEDED;
2262}
2263
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002264int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002265ivi_layout_commit_changes(void)
2266{
2267 struct ivi_layout *layout = get_instance();
2268
2269 commit_surface_list(layout);
2270 commit_layer_list(layout);
2271 commit_screen_list(layout);
2272
2273 commit_transition(layout);
2274
2275 commit_changes(layout);
2276 send_prop(layout);
2277 weston_compositor_schedule_repaint(layout->compositor);
2278
2279 return IVI_SUCCEEDED;
2280}
2281
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002282static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002283ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2284 enum ivi_layout_transition_type type,
2285 uint32_t duration)
2286{
2287 if (ivilayer == NULL) {
2288 weston_log("%s: invalid argument\n", __func__);
2289 return -1;
2290 }
2291
2292 ivilayer->pending.prop.transition_type = type;
2293 ivilayer->pending.prop.transition_duration = duration;
2294
2295 return 0;
2296}
2297
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002298static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002299ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2300 uint32_t is_fade_in,
2301 double start_alpha, double end_alpha)
2302{
2303 if (ivilayer == NULL) {
2304 weston_log("%s: invalid argument\n", __func__);
2305 return -1;
2306 }
2307
2308 ivilayer->pending.prop.is_fade_in = is_fade_in;
2309 ivilayer->pending.prop.start_alpha = start_alpha;
2310 ivilayer->pending.prop.end_alpha = end_alpha;
2311
2312 return 0;
2313}
2314
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002315static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002316ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2317 uint32_t duration)
2318{
2319 struct ivi_layout_surface_properties *prop;
2320
2321 if (ivisurf == NULL) {
2322 weston_log("%s: invalid argument\n", __func__);
2323 return -1;
2324 }
2325
2326 prop = &ivisurf->pending.prop;
2327 prop->transition_duration = duration*10;
2328 return 0;
2329}
2330
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002331static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002332ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2333 enum ivi_layout_transition_type type,
2334 uint32_t duration)
2335{
2336 struct ivi_layout_surface_properties *prop;
2337
2338 if (ivisurf == NULL) {
2339 weston_log("%s: invalid argument\n", __func__);
2340 return -1;
2341 }
2342
2343 prop = &ivisurf->pending.prop;
2344 prop->transition_type = type;
2345 prop->transition_duration = duration;
2346 return 0;
2347}
2348
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002349static int32_t
2350ivi_layout_surface_dump(struct weston_surface *surface,
2351 void *target, size_t size,int32_t x, int32_t y,
2352 int32_t width, int32_t height)
2353{
2354 int result = 0;
2355
2356 if (surface == NULL) {
2357 weston_log("%s: invalid argument\n", __func__);
2358 return IVI_FAILED;
2359 }
2360
2361 result = weston_surface_copy_content(
2362 surface, target, size,
2363 x, y, width, height);
2364
2365 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2366}
2367
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002368/**
2369 * methods of interaction between ivi-shell with ivi-layout
2370 */
2371struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002372ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2373{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002374 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002375 return NULL;
2376
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002377 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002378}
2379
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002380void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002381ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2382 int32_t width, int32_t height)
2383{
2384 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002385
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002386 /* emit callback which is set by ivi-layout api user */
2387 wl_signal_emit(&layout->surface_notification.configure_changed,
2388 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002389}
2390
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002391struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002392ivi_layout_surface_create(struct weston_surface *wl_surface,
2393 uint32_t id_surface)
2394{
2395 struct ivi_layout *layout = get_instance();
2396 struct ivi_layout_surface *ivisurf = NULL;
2397 struct weston_view *tmpview = NULL;
2398
2399 if (wl_surface == NULL) {
2400 weston_log("ivi_layout_surface_create: invalid argument\n");
2401 return NULL;
2402 }
2403
2404 ivisurf = get_surface(&layout->surface_list, id_surface);
2405 if (ivisurf != NULL) {
2406 if (ivisurf->surface != NULL) {
2407 weston_log("id_surface(%d) is already created\n", id_surface);
2408 return NULL;
2409 }
2410 }
2411
2412 ivisurf = calloc(1, sizeof *ivisurf);
2413 if (ivisurf == NULL) {
2414 weston_log("fails to allocate memory\n");
2415 return NULL;
2416 }
2417
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002418 wl_signal_init(&ivisurf->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002419 ivisurf->id_surface = id_surface;
2420 ivisurf->layout = layout;
2421
2422 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002423
2424 tmpview = weston_view_create(wl_surface);
2425 if (tmpview == NULL) {
2426 weston_log("fails to allocate memory\n");
2427 }
2428
2429 ivisurf->surface->width_from_buffer = 0;
2430 ivisurf->surface->height_from_buffer = 0;
2431
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002432 weston_matrix_init(&ivisurf->transform.matrix);
2433 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002434
2435 init_surface_properties(&ivisurf->prop);
2436 ivisurf->event_mask = 0;
2437
2438 ivisurf->pending.prop = ivisurf->prop;
2439 wl_list_init(&ivisurf->pending.link);
2440
2441 wl_list_init(&ivisurf->order.link);
2442 wl_list_init(&ivisurf->order.layer_list);
2443
2444 wl_list_insert(&layout->surface_list, &ivisurf->link);
2445
2446 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2447
2448 return ivisurf;
2449}
2450
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002451void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002452ivi_layout_init_with_compositor(struct weston_compositor *ec)
2453{
2454 struct ivi_layout *layout = get_instance();
2455
2456 layout->compositor = ec;
2457
2458 wl_list_init(&layout->surface_list);
2459 wl_list_init(&layout->layer_list);
2460 wl_list_init(&layout->screen_list);
2461
2462 wl_signal_init(&layout->layer_notification.created);
2463 wl_signal_init(&layout->layer_notification.removed);
2464
2465 wl_signal_init(&layout->surface_notification.created);
2466 wl_signal_init(&layout->surface_notification.removed);
2467 wl_signal_init(&layout->surface_notification.configure_changed);
2468
2469 /* Add layout_layer at the last of weston_compositor.layer_list */
2470 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2471
2472 create_screen(ec);
2473
2474 layout->transitions = ivi_layout_transition_set_create(ec);
2475 wl_list_init(&layout->pending_transition_list);
2476}
2477
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002478static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002479 /**
2480 * commit all changes
2481 */
2482 .commit_changes = ivi_layout_commit_changes,
2483
2484 /**
2485 * surface controller interfaces
2486 */
2487 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2488 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2489 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2490 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2491 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2492 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2493 .get_surfaces = ivi_layout_get_surfaces,
2494 .get_id_of_surface = ivi_layout_get_id_of_surface,
2495 .get_surface_from_id = ivi_layout_get_surface_from_id,
2496 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2497 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2498 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002499 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002500 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2501 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002502 .surface_set_orientation = ivi_layout_surface_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002503 .surface_add_notification = ivi_layout_surface_add_notification,
2504 .surface_remove_notification = ivi_layout_surface_remove_notification,
2505 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2506 .surface_set_transition = ivi_layout_surface_set_transition,
2507 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2508
2509 /**
2510 * layer controller interfaces
2511 */
2512 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2513 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2514 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2515 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2516 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002517 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002518 .get_layers = ivi_layout_get_layers,
2519 .get_id_of_layer = ivi_layout_get_id_of_layer,
2520 .get_layer_from_id = ivi_layout_get_layer_from_id,
2521 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2522 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2523 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2524 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002525 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002526 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2527 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002528 .layer_set_orientation = ivi_layout_layer_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002529 .layer_add_surface = ivi_layout_layer_add_surface,
2530 .layer_remove_surface = ivi_layout_layer_remove_surface,
2531 .layer_set_render_order = ivi_layout_layer_set_render_order,
2532 .layer_add_notification = ivi_layout_layer_add_notification,
2533 .layer_remove_notification = ivi_layout_layer_remove_notification,
2534 .layer_set_transition = ivi_layout_layer_set_transition,
2535
2536 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002537 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002538 */
2539 .get_screen_from_id = ivi_layout_get_screen_from_id,
2540 .get_screen_resolution = ivi_layout_get_screen_resolution,
2541 .get_screens = ivi_layout_get_screens,
2542 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2543 .screen_add_layer = ivi_layout_screen_add_layer,
2544 .screen_set_render_order = ivi_layout_screen_set_render_order,
2545 .screen_get_output = ivi_layout_screen_get_output,
2546
2547 /**
2548 * animation
2549 */
2550 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002551 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2552
2553 /**
2554 * surface content dumping for debugging
2555 */
2556 .surface_get_size = ivi_layout_surface_get_size,
2557 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002558
2559 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002560 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002561 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002562 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002563 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2564
2565 /**
2566 * screen controller interfaces part2
2567 */
2568 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002569};
2570
2571int
2572load_controller_modules(struct weston_compositor *compositor, const char *modules,
2573 int *argc, char *argv[])
2574{
2575 const char *p, *end;
2576 char buffer[256];
2577 int (*controller_module_init)(struct weston_compositor *compositor,
2578 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002579 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002580 size_t interface_version);
2581
2582 if (modules == NULL)
2583 return 0;
2584
2585 p = modules;
2586 while (*p) {
2587 end = strchrnul(p, ',');
2588 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2589
2590 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002591 if (!controller_module_init)
2592 return -1;
2593
2594 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002595 &ivi_layout_interface,
2596 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002597 weston_log("ivi-shell: Initialization of controller module fails");
2598 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002599 }
2600
2601 p = end;
2602 while (*p == ',')
2603 p++;
2604 }
2605
2606 return 0;
2607}