blob: 5c0e8f4f968d49dda13b33033abc7fb18b40abaf [file] [log] [blame]
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001/*
2 * Copyright (C) 2013 DENSO CORPORATION
3 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090011 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090024 */
25
26/**
27 * Implementation of ivi-layout library. The actual view on ivi_screen is
28 * not updated till calling ivi_layout_commit_changes. A overview from
29 * calling API for updating properties of ivi_surface/ivi_layer to asking
30 * compositor to compose them by using weston_compositor_schedule_repaint,
31 * 0/ initialize this library by ivi_layout_init_with_compositor
32 * with (struct weston_compositor *ec) from ivi-shell.
33 * 1/ When a API for updating properties of ivi_surface/ivi_layer, it updates
34 * pending prop of ivi_surface/ivi_layer/ivi_screen which are structure to
35 * store properties.
36 * 2/ Before calling commitChanges, in case of calling a API to get a property,
37 * return current property, not pending property.
38 * 3/ At the timing of calling ivi_layout_commitChanges, pending properties
39 * are applied to properties.
40 *
41 * *) ivi_layout_commitChanges is also called by transition animation
42 * per each frame. See ivi-layout-transition.c in details. Transition
43 * animation interpolates frames between previous properties of ivi_surface
44 * and new ones.
45 * For example, when a property of ivi_surface is changed from invisibility
46 * to visibility, it behaves like fade-in. When ivi_layout_commitChange is
47 * called during transition animation, it cancels the transition and
48 * re-start transition to new properties from current properties of final
49 * frame just before the the cancellation.
50 *
51 * 4/ According properties, set transformation by using weston_matrix and
52 * weston_view per ivi_surfaces and ivi_layers in while loop.
53 * 5/ Set damage and trigger transform by using weston_view_geometry_dirty.
54 * 6/ Notify update of properties.
55 * 7/ Trigger composition by weston_compositor_schedule_repaint.
56 *
57 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090058#include "config.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090059
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090060#include <string.h>
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +000061#include <assert.h>
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090062
63#include "compositor.h"
Pekka Paalanen1f821932016-03-15 16:57:51 +020064#include "ivi-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090065#include "ivi-layout-export.h"
66#include "ivi-layout-private.h"
Pekka Paalanen32ca7912016-03-15 17:21:00 +020067#include "ivi-layout-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090068
Jon Cruz867d50e2015-06-15 15:37:10 -070069#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070070#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090071
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +090072#define max(a, b) ((a) > (b) ? (a) : (b))
73
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090074struct listener_layout_notification {
75 void *userdata;
76 struct wl_listener listener;
77};
78
79struct ivi_layout;
80
81struct ivi_layout_screen {
82 struct wl_list link;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090083
84 struct ivi_layout *layout;
85 struct weston_output *output;
86
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090087 struct {
88 struct wl_list layer_list;
89 struct wl_list link;
90 } pending;
91
92 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +000093 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090094 struct wl_list layer_list;
95 struct wl_list link;
96 } order;
97};
98
99struct ivi_layout_notification_callback {
100 void *callback;
101 void *data;
102};
103
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900104struct ivi_rectangle
105{
106 int32_t x;
107 int32_t y;
108 int32_t width;
109 int32_t height;
110};
111
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900112static void
113remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
114
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900115static struct ivi_layout ivilayout = {0};
116
117struct ivi_layout *
118get_instance(void)
119{
120 return &ivilayout;
121}
122
123/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900124 * Internal API to add/remove a ivi_layer to/from ivi_screen.
125 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900126static struct ivi_layout_surface *
127get_surface(struct wl_list *surf_list, uint32_t id_surface)
128{
129 struct ivi_layout_surface *ivisurf;
130
131 wl_list_for_each(ivisurf, surf_list, link) {
132 if (ivisurf->id_surface == id_surface) {
133 return ivisurf;
134 }
135 }
136
137 return NULL;
138}
139
140static struct ivi_layout_layer *
141get_layer(struct wl_list *layer_list, uint32_t id_layer)
142{
143 struct ivi_layout_layer *ivilayer;
144
145 wl_list_for_each(ivilayer, layer_list, link) {
146 if (ivilayer->id_layer == id_layer) {
147 return ivilayer;
148 }
149 }
150
151 return NULL;
152}
153
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000154static struct weston_view *
155get_weston_view(struct ivi_layout_surface *ivisurf)
156{
157 struct weston_view *view = NULL;
158
159 assert(ivisurf->surface != NULL);
160
161 /* One view per surface */
162 if(wl_list_empty(&ivisurf->surface->views))
163 view = NULL;
164 else
165 view = wl_container_of(ivisurf->surface->views.next, view, surface_link);
166
167 return view;
168}
169
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +0000170static struct ivi_layout_screen *
171get_screen_from_output(struct weston_output *output)
172{
173 struct ivi_layout *layout = get_instance();
174 struct ivi_layout_screen *iviscrn = NULL;
175
176 wl_list_for_each(iviscrn, &layout->screen_list, link) {
177 if (iviscrn->output == output)
178 return iviscrn;
179 }
180
181 return NULL;
182}
183
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900184static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900185remove_all_notification(struct wl_list *listener_list)
186{
187 struct wl_listener *listener = NULL;
188 struct wl_listener *next = NULL;
189
190 wl_list_for_each_safe(listener, next, listener_list, link) {
191 struct listener_layout_notification *notification = NULL;
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000192 wl_list_remove(&listener->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900193
194 notification =
195 container_of(listener,
196 struct listener_layout_notification,
197 listener);
198
199 free(notification->userdata);
200 free(notification);
201 }
202}
203
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900204static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900205ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
206{
207 if (ivisurf == NULL) {
208 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
209 return;
210 }
211
212 remove_all_notification(&ivisurf->property_changed.listener_list);
213}
214
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900215static void
216ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
217 surface_property_notification_func callback,
218 void *userdata)
219{
220 if (ivisurf == NULL) {
221 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
222 return;
223 }
224
225 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
226}
227
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900228/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900229 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900230 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900231void
232ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900233{
234 struct ivi_layout *layout = get_instance();
235
236 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900237 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900238 return;
239 }
240
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900241 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900242 wl_list_remove(&ivisurf->pending.link);
243 wl_list_remove(&ivisurf->order.link);
244 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900245
246 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
247
Mateusz Polroladada6e32016-03-09 09:13:26 +0000248 ivi_layout_remove_all_surface_transitions(ivisurf);
249
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900250 ivi_layout_surface_remove_notification(ivisurf);
251
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900252 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900253}
254
255/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900256 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
257 * Called by ivi_layout_init_with_compositor.
258 */
259static void
260create_screen(struct weston_compositor *ec)
261{
262 struct ivi_layout *layout = get_instance();
263 struct ivi_layout_screen *iviscrn = NULL;
264 struct weston_output *output = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900265
266 wl_list_for_each(output, &ec->output_list, link) {
267 iviscrn = calloc(1, sizeof *iviscrn);
268 if (iviscrn == NULL) {
269 weston_log("fails to allocate memory\n");
270 continue;
271 }
272
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900273 iviscrn->layout = layout;
274
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900275 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900276
277 wl_list_init(&iviscrn->pending.layer_list);
278 wl_list_init(&iviscrn->pending.link);
279
280 wl_list_init(&iviscrn->order.layer_list);
281 wl_list_init(&iviscrn->order.link);
282
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900283 wl_list_insert(&layout->screen_list, &iviscrn->link);
284 }
285}
286
287/**
288 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
289 */
290static void
291init_layer_properties(struct ivi_layout_layer_properties *prop,
292 int32_t width, int32_t height)
293{
294 memset(prop, 0, sizeof *prop);
295 prop->opacity = wl_fixed_from_double(1.0);
296 prop->source_width = width;
297 prop->source_height = height;
298 prop->dest_width = width;
299 prop->dest_height = height;
300}
301
302static void
303init_surface_properties(struct ivi_layout_surface_properties *prop)
304{
305 memset(prop, 0, sizeof *prop);
306 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900307 /*
308 * FIXME: this shall be finxed by ivi-layout-transition.
309 */
310 prop->dest_width = 1;
311 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900312}
313
314/**
315 * Internal APIs to be called from ivi_layout_commit_changes.
316 */
317static void
318update_opacity(struct ivi_layout_layer *ivilayer,
319 struct ivi_layout_surface *ivisurf)
320{
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000321 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900322 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
323 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
324
Nobuhiko Tanibata90c27892015-12-26 23:52:51 +0900325 tmpview = get_weston_view(ivisurf);
326 assert(tmpview != NULL);
327 tmpview->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900328}
329
330static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900331get_rotate_values(enum wl_output_transform orientation,
332 float *v_sin,
333 float *v_cos)
334{
335 switch (orientation) {
336 case WL_OUTPUT_TRANSFORM_90:
337 *v_sin = 1.0f;
338 *v_cos = 0.0f;
339 break;
340 case WL_OUTPUT_TRANSFORM_180:
341 *v_sin = 0.0f;
342 *v_cos = -1.0f;
343 break;
344 case WL_OUTPUT_TRANSFORM_270:
345 *v_sin = -1.0f;
346 *v_cos = 0.0f;
347 break;
348 case WL_OUTPUT_TRANSFORM_NORMAL:
349 default:
350 *v_sin = 0.0f;
351 *v_cos = 1.0f;
352 break;
353 }
354}
355
356static void
357get_scale(enum wl_output_transform orientation,
358 float dest_width,
359 float dest_height,
360 float source_width,
361 float source_height,
362 float *scale_x,
363 float *scale_y)
364{
365 switch (orientation) {
366 case WL_OUTPUT_TRANSFORM_90:
367 *scale_x = dest_width / source_height;
368 *scale_y = dest_height / source_width;
369 break;
370 case WL_OUTPUT_TRANSFORM_180:
371 *scale_x = dest_width / source_width;
372 *scale_y = dest_height / source_height;
373 break;
374 case WL_OUTPUT_TRANSFORM_270:
375 *scale_x = dest_width / source_height;
376 *scale_y = dest_height / source_width;
377 break;
378 case WL_OUTPUT_TRANSFORM_NORMAL:
379 default:
380 *scale_x = dest_width / source_width;
381 *scale_y = dest_height / source_height;
382 break;
383 }
384}
385
386static void
387calc_transformation_matrix(struct ivi_rectangle *source_rect,
388 struct ivi_rectangle *dest_rect,
389 enum wl_output_transform orientation,
390 struct weston_matrix *m)
391{
392 float source_center_x;
393 float source_center_y;
394 float vsin;
395 float vcos;
396 float scale_x;
397 float scale_y;
398 float translate_x;
399 float translate_y;
400
401 source_center_x = source_rect->x + source_rect->width * 0.5f;
402 source_center_y = source_rect->y + source_rect->height * 0.5f;
403 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
404
405 get_rotate_values(orientation, &vsin, &vcos);
406 weston_matrix_rotate_xy(m, vcos, vsin);
407
408 get_scale(orientation,
409 dest_rect->width,
410 dest_rect->height,
411 source_rect->width,
412 source_rect->height,
413 &scale_x,
414 &scale_y);
415 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
416
417 translate_x = dest_rect->width * 0.5f + dest_rect->x;
418 translate_y = dest_rect->height * 0.5f + dest_rect->y;
419 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
420}
421
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900422/*
423 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900424 */
425static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900426ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
427 const struct ivi_rectangle *rect2,
428 struct ivi_rectangle *rect_output)
429{
430 int32_t rect1_right = rect1->x + rect1->width;
431 int32_t rect1_bottom = rect1->y + rect1->height;
432 int32_t rect2_right = rect2->x + rect2->width;
433 int32_t rect2_bottom = rect2->y + rect2->height;
434
435 rect_output->x = max(rect1->x, rect2->x);
436 rect_output->y = max(rect1->y, rect2->y);
437 rect_output->width = rect1_right < rect2_right ?
438 rect1_right - rect_output->x :
439 rect2_right - rect_output->x;
440 rect_output->height = rect1_bottom < rect2_bottom ?
441 rect1_bottom - rect_output->y :
442 rect2_bottom - rect_output->y;
443
444 if (rect_output->width < 0 || rect_output->height < 0) {
445 rect_output->width = 0;
446 rect_output->height = 0;
447 }
448}
449
450/*
451 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
452 * and store the result in rect_output.
453 * The boundingbox must be given in the same coordinate space as rect_output.
454 * Additionally, there are the following restrictions on the matrix:
455 * - no projective transformations
456 * - no skew
457 * - only multiples of 90-degree rotations supported
458 *
459 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
460 * as a fail-safe with log.
461 */
462static void
463calc_inverse_matrix_transform(const struct weston_matrix *matrix,
464 const struct ivi_rectangle *rect_input,
465 const struct ivi_rectangle *boundingbox,
466 struct ivi_rectangle *rect_output)
467{
468 struct weston_matrix m;
469 struct weston_vector top_left;
470 struct weston_vector bottom_right;
471
472 assert(boundingbox != rect_output);
473
474 if (weston_matrix_invert(&m, matrix) < 0) {
475 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
476 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
477 rect_output->x = boundingbox->x;
478 rect_output->y = boundingbox->y;
479 rect_output->width = boundingbox->width;
480 rect_output->height = boundingbox->height;
481 }
482
483 /* The vectors and matrices involved will always produce f[3] == 1.0. */
484 top_left.f[0] = rect_input->x;
485 top_left.f[1] = rect_input->y;
486 top_left.f[2] = 0.0f;
487 top_left.f[3] = 1.0f;
488
489 bottom_right.f[0] = rect_input->x + rect_input->width;
490 bottom_right.f[1] = rect_input->y + rect_input->height;
491 bottom_right.f[2] = 0.0f;
492 bottom_right.f[3] = 1.0f;
493
494 weston_matrix_transform(&m, &top_left);
495 weston_matrix_transform(&m, &bottom_right);
496
497 if (top_left.f[0] < bottom_right.f[0]) {
498 rect_output->x = top_left.f[0];
499 rect_output->width = bottom_right.f[0] - rect_output->x;
500 } else {
501 rect_output->x = bottom_right.f[0];
502 rect_output->width = top_left.f[0] - rect_output->x;
503 }
504
505 if (top_left.f[1] < bottom_right.f[1]) {
506 rect_output->y = top_left.f[1];
507 rect_output->height = bottom_right.f[1] - rect_output->y;
508 } else {
509 rect_output->y = bottom_right.f[1];
510 rect_output->height = top_left.f[1] - rect_output->y;
511 }
512
513 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
514}
515
516/**
517 * This computes the whole transformation matrix:m from surface-local
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900518 * coordinates to multi screens coordinate, which is global coordinates.
519 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900520 *
521 * Additionally, this computes the mask on surface-local coordinates as a
522 * ivi_rectangle. This can be set to weston_view_set_mask.
523 *
524 * The mask is computed by following steps
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900525 * - destination rectangle of layer is tansformed to multi screen coordinate,
526 * global coordinates. This is done by adding weston_output.{x,y} in simple
527 * because there is no scaled and rotated transformation.
528 * - destination rectangle of layer in multi screens coordinate needs to be
529 * intersected inside of a screen the layer is assigned to. This is because
530 * overlapped region of weston surface in another screen shall not be
531 * displayed according to ivi use case.
532 * - destination rectangle of layer
533 * - in multi screen coordinates,
534 * - and intersected inside of an assigned screen,
535 * is inversed to surface-local cooodinates by inversed matrix:m.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900536 * - the area is intersected by intersected area between weston_surface and
537 * source rectangle of ivi_surface.
538 */
539static void
540calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900541 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900542 struct ivi_layout_layer *ivilayer,
543 struct ivi_layout_surface *ivisurf,
544 struct weston_matrix *m,
545 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900546{
547 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
548 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900549 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900550 struct ivi_rectangle weston_surface_rect = { 0,
551 0,
552 ivisurf->surface->width,
553 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900554 struct ivi_rectangle surface_source_rect = { sp->source_x,
555 sp->source_y,
556 sp->source_width,
557 sp->source_height };
558 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
559 sp->dest_y,
560 sp->dest_width,
561 sp->dest_height };
562 struct ivi_rectangle layer_source_rect = { lp->source_x,
563 lp->source_y,
564 lp->source_width,
565 lp->source_height };
566 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
567 lp->dest_y,
568 lp->dest_width,
569 lp->dest_height };
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900570 struct ivi_rectangle screen_dest_rect = { output->x,
571 output->y,
572 output->width,
573 output->height };
574 struct ivi_rectangle layer_dest_rect_in_global =
575 { lp->dest_x + output->x,
576 lp->dest_y + output->y,
577 lp->dest_width,
578 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900579 struct ivi_rectangle surface_result;
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900580 struct ivi_rectangle layer_dest_rect_in_global_intersected;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900581
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900582 /*
583 * the whole transformation matrix:m from surface-local
584 * coordinates to global coordinates, which is computed by
585 * two steps,
586 * - surface-local coordinates to layer-local coordinates
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900587 * - layer-local coordinates to a single screen-local coordinates
588 * - a single screen-local coordinates to multi screen coordinates,
589 * which is global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900590 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900591 calc_transformation_matrix(&surface_source_rect,
592 &surface_dest_rect,
593 sp->orientation, m);
594
595 calc_transformation_matrix(&layer_source_rect,
596 &layer_dest_rect,
597 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900598
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900599 weston_matrix_translate(m, output->x, output->y, 0.0f);
600
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900601 /* this intersected ivi_rectangle would be used for masking
602 * weston_surface
603 */
604 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
605 &surface_result);
606
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900607 /*
608 * destination rectangle of layer in multi screens coordinate
609 * is intersected to avoid displaying outside of an assigned screen.
610 */
611 ivi_rectangle_intersect(&layer_dest_rect_in_global, &screen_dest_rect,
612 &layer_dest_rect_in_global_intersected);
613
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900614 /* calc masking area of weston_surface from m */
615 calc_inverse_matrix_transform(m,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900616 &layer_dest_rect_in_global_intersected,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900617 &surface_result,
618 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900619}
620
621static void
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900622update_prop(struct ivi_layout_screen *iviscrn,
623 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900624 struct ivi_layout_surface *ivisurf)
625{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900626 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900627 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900628 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900629
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900630 /*In case of no prop change, this just returns*/
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000631 if (!ivilayer->prop.event_mask && !ivisurf->prop.event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900632 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900633
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900634 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900635
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000636 tmpview = get_weston_view(ivisurf);
637 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900638
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900639 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
640 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
641 can_calc = false;
642 }
643
644 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
645 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
646 can_calc = false;
647 }
648
649 if (can_calc) {
650 wl_list_remove(&ivisurf->transform.link);
651 weston_matrix_init(&ivisurf->transform.matrix);
652
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900653 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900654 iviscrn, ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900655
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000656 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
657 wl_list_insert(&tmpview->geometry.transformation_list,
658 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900659
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000660 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900661 }
662
663 ivisurf->update_count++;
664
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000665 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900666
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000667 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900668}
669
670static void
671commit_changes(struct ivi_layout *layout)
672{
673 struct ivi_layout_screen *iviscrn = NULL;
674 struct ivi_layout_layer *ivilayer = NULL;
675 struct ivi_layout_surface *ivisurf = NULL;
676
677 wl_list_for_each(iviscrn, &layout->screen_list, link) {
678 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900679 /*
680 * If ivilayer is invisible, weston_view of ivisurf doesn't
681 * need to be modified.
682 */
683 if (ivilayer->prop.visibility == false)
684 continue;
685
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900686 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900687 /*
688 * If ivilayer is invisible, weston_view of ivisurf doesn't
689 * need to be modified.
690 */
691 if (ivisurf->prop.visibility == false)
692 continue;
693
694 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900695 }
696 }
697 }
698}
699
700static void
701commit_surface_list(struct ivi_layout *layout)
702{
703 struct ivi_layout_surface *ivisurf = NULL;
704 int32_t dest_x = 0;
705 int32_t dest_y = 0;
706 int32_t dest_width = 0;
707 int32_t dest_height = 0;
708 int32_t configured = 0;
709
710 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300711 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900712 dest_x = ivisurf->prop.dest_x;
713 dest_y = ivisurf->prop.dest_y;
714 dest_width = ivisurf->prop.dest_width;
715 dest_height = ivisurf->prop.dest_height;
716
717 ivi_layout_transition_move_resize_view(ivisurf,
718 ivisurf->pending.prop.dest_x,
719 ivisurf->pending.prop.dest_y,
720 ivisurf->pending.prop.dest_width,
721 ivisurf->pending.prop.dest_height,
722 ivisurf->pending.prop.transition_duration);
723
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300724 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900725 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
726 } else {
727 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
728 }
729
730 ivisurf->prop = ivisurf->pending.prop;
731 ivisurf->prop.dest_x = dest_x;
732 ivisurf->prop.dest_y = dest_y;
733 ivisurf->prop.dest_width = dest_width;
734 ivisurf->prop.dest_height = dest_height;
735 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
736 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
737
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300738 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900739 dest_x = ivisurf->prop.dest_x;
740 dest_y = ivisurf->prop.dest_y;
741 dest_width = ivisurf->prop.dest_width;
742 dest_height = ivisurf->prop.dest_height;
743
744 ivi_layout_transition_move_resize_view(ivisurf,
745 ivisurf->pending.prop.dest_x,
746 ivisurf->pending.prop.dest_y,
747 ivisurf->pending.prop.dest_width,
748 ivisurf->pending.prop.dest_height,
749 ivisurf->pending.prop.transition_duration);
750
751 ivisurf->prop = ivisurf->pending.prop;
752 ivisurf->prop.dest_x = dest_x;
753 ivisurf->prop.dest_y = dest_y;
754 ivisurf->prop.dest_width = dest_width;
755 ivisurf->prop.dest_height = dest_height;
756
757 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
758 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
759
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300760 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900761 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300762 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900763 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
764 } else {
765 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
766 }
767
768 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
769 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
770 configured = 1;
771 }
772
773 ivisurf->prop = ivisurf->pending.prop;
774 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
775 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
776
Pekka Paalanen1f821932016-03-15 16:57:51 +0200777 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200778 shell_surface_send_configure(ivisurf->surface,
779 ivisurf->prop.dest_width,
780 ivisurf->prop.dest_height);
781 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900782 } else {
783 configured = 0;
784 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
785 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
786 configured = 1;
787 }
788
789 ivisurf->prop = ivisurf->pending.prop;
790 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
791 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
792
Pekka Paalanen1f821932016-03-15 16:57:51 +0200793 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200794 shell_surface_send_configure(ivisurf->surface,
795 ivisurf->prop.dest_width,
796 ivisurf->prop.dest_height);
797 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900798 }
799 }
800}
801
802static void
803commit_layer_list(struct ivi_layout *layout)
804{
805 struct ivi_layout_layer *ivilayer = NULL;
806 struct ivi_layout_surface *ivisurf = NULL;
807 struct ivi_layout_surface *next = NULL;
808
809 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300810 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900811 ivi_layout_transition_move_layer(ivilayer, ivilayer->pending.prop.dest_x, ivilayer->pending.prop.dest_y, ivilayer->pending.prop.transition_duration);
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300812 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900813 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
814 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
815 NULL, NULL,
816 ivilayer->pending.prop.transition_duration);
817 }
818 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
819
820 ivilayer->prop = ivilayer->pending.prop;
821
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000822 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900823 continue;
824 }
825
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000826 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
827 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000828 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000829 wl_list_remove(&ivisurf->order.link);
830 wl_list_init(&ivisurf->order.link);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000831 ivisurf->prop.event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900832 }
833
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000834 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900835
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000836 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900837 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000838 wl_list_remove(&ivisurf->order.link);
839 wl_list_insert(&ivilayer->order.surface_list,
840 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000841 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000842 ivisurf->prop.event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900843 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000844
845 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900846 }
847}
848
849static void
850commit_screen_list(struct ivi_layout *layout)
851{
852 struct ivi_layout_screen *iviscrn = NULL;
853 struct ivi_layout_layer *ivilayer = NULL;
854 struct ivi_layout_layer *next = NULL;
855 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000856 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900857
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900858 /* Clear view list of layout ivi_layer */
859 wl_list_init(&layout->layout_layer.view_list.link);
860
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900861 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000862 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900863 wl_list_for_each_safe(ivilayer, next,
864 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000865 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000866 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900867 wl_list_init(&ivilayer->order.link);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000868 ivilayer->prop.event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900869 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900870
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000871 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900872
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900873 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
874 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900875 /* FIXME: avoid to insert order.link to multiple screens */
876 wl_list_remove(&ivilayer->order.link);
877
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900878 wl_list_insert(&iviscrn->order.layer_list,
879 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000880 ivilayer->on_screen = iviscrn;
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000881 ivilayer->prop.event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900882 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900883
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000884 iviscrn->order.dirty = 0;
885 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900886
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900887 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
888 if (ivilayer->prop.visibility == false)
889 continue;
890
891 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900892 if (ivisurf->prop.visibility == false)
893 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000894
895 tmpview = get_weston_view(ivisurf);
896 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900897
898 weston_layer_entry_insert(&layout->layout_layer.view_list,
899 &tmpview->layer_link);
900
901 ivisurf->surface->output = iviscrn->output;
902 }
903 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900904 }
905}
906
907static void
908commit_transition(struct ivi_layout* layout)
909{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300910 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900911 return;
912 }
913
914 wl_list_insert_list(&layout->transitions->transition_list,
915 &layout->pending_transition_list);
916
917 wl_list_init(&layout->pending_transition_list);
918
919 wl_event_source_timer_update(layout->transitions->event_source, 1);
920}
921
922static void
923send_surface_prop(struct ivi_layout_surface *ivisurf)
924{
925 wl_signal_emit(&ivisurf->property_changed, ivisurf);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000926 ivisurf->pending.prop.event_mask = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900927}
928
929static void
930send_layer_prop(struct ivi_layout_layer *ivilayer)
931{
932 wl_signal_emit(&ivilayer->property_changed, ivilayer);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000933 ivilayer->pending.prop.event_mask = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900934}
935
936static void
937send_prop(struct ivi_layout *layout)
938{
939 struct ivi_layout_layer *ivilayer = NULL;
940 struct ivi_layout_surface *ivisurf = NULL;
941
942 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000943 if (ivilayer->prop.event_mask)
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900944 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900945 }
946
947 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000948 if (ivisurf->prop.event_mask)
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900949 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900950 }
951}
952
953static void
954clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
955{
956 struct ivi_layout_surface *surface_link = NULL;
957 struct ivi_layout_surface *surface_next = NULL;
958
959 wl_list_for_each_safe(surface_link, surface_next,
960 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000961 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900962 wl_list_init(&surface_link->pending.link);
963 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900964}
965
966static void
967clear_surface_order_list(struct ivi_layout_layer *ivilayer)
968{
969 struct ivi_layout_surface *surface_link = NULL;
970 struct ivi_layout_surface *surface_next = NULL;
971
972 wl_list_for_each_safe(surface_link, surface_next,
973 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000974 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900975 wl_list_init(&surface_link->order.link);
976 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900977}
978
979static void
980layer_created(struct wl_listener *listener, void *data)
981{
982 struct ivi_layout_layer *ivilayer = data;
983
984 struct listener_layout_notification *notification =
985 container_of(listener,
986 struct listener_layout_notification,
987 listener);
988
989 struct ivi_layout_notification_callback *created_callback =
990 notification->userdata;
991
992 ((layer_create_notification_func)created_callback->callback)
993 (ivilayer, created_callback->data);
994}
995
996static void
997layer_removed(struct wl_listener *listener, void *data)
998{
999 struct ivi_layout_layer *ivilayer = data;
1000
1001 struct listener_layout_notification *notification =
1002 container_of(listener,
1003 struct listener_layout_notification,
1004 listener);
1005
1006 struct ivi_layout_notification_callback *removed_callback =
1007 notification->userdata;
1008
1009 ((layer_remove_notification_func)removed_callback->callback)
1010 (ivilayer, removed_callback->data);
1011}
1012
1013static void
1014layer_prop_changed(struct wl_listener *listener, void *data)
1015{
1016 struct ivi_layout_layer *ivilayer = data;
1017
1018 struct listener_layout_notification *layout_listener =
1019 container_of(listener,
1020 struct listener_layout_notification,
1021 listener);
1022
1023 struct ivi_layout_notification_callback *prop_callback =
1024 layout_listener->userdata;
1025
1026 ((layer_property_notification_func)prop_callback->callback)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001027 (ivilayer, &ivilayer->prop, ivilayer->prop.event_mask, prop_callback->data);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001028}
1029
1030static void
1031surface_created(struct wl_listener *listener, void *data)
1032{
1033 struct ivi_layout_surface *ivisurface = data;
1034
1035 struct listener_layout_notification *notification =
1036 container_of(listener,
1037 struct listener_layout_notification,
1038 listener);
1039
1040 struct ivi_layout_notification_callback *created_callback =
1041 notification->userdata;
1042
1043 ((surface_create_notification_func)created_callback->callback)
1044 (ivisurface, created_callback->data);
1045}
1046
1047static void
1048surface_removed(struct wl_listener *listener, void *data)
1049{
1050 struct ivi_layout_surface *ivisurface = data;
1051
1052 struct listener_layout_notification *notification =
1053 container_of(listener,
1054 struct listener_layout_notification,
1055 listener);
1056
1057 struct ivi_layout_notification_callback *removed_callback =
1058 notification->userdata;
1059
1060 ((surface_remove_notification_func)removed_callback->callback)
1061 (ivisurface, removed_callback->data);
1062}
1063
1064static void
1065surface_prop_changed(struct wl_listener *listener, void *data)
1066{
1067 struct ivi_layout_surface *ivisurf = data;
1068
1069 struct listener_layout_notification *layout_listener =
1070 container_of(listener,
1071 struct listener_layout_notification,
1072 listener);
1073
1074 struct ivi_layout_notification_callback *prop_callback =
1075 layout_listener->userdata;
1076
1077 ((surface_property_notification_func)prop_callback->callback)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001078 (ivisurf, &ivisurf->prop, ivisurf->prop.event_mask, prop_callback->data);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001079}
1080
1081static void
1082surface_configure_changed(struct wl_listener *listener,
1083 void *data)
1084{
1085 struct ivi_layout_surface *ivisurface = data;
1086
1087 struct listener_layout_notification *notification =
1088 container_of(listener,
1089 struct listener_layout_notification,
1090 listener);
1091
1092 struct ivi_layout_notification_callback *configure_changed_callback =
1093 notification->userdata;
1094
1095 ((surface_configure_notification_func)configure_changed_callback->callback)
1096 (ivisurface, configure_changed_callback->data);
1097}
1098
1099static int32_t
1100add_notification(struct wl_signal *signal,
1101 wl_notify_func_t callback,
1102 void *userdata)
1103{
1104 struct listener_layout_notification *notification = NULL;
1105
1106 notification = malloc(sizeof *notification);
1107 if (notification == NULL) {
1108 weston_log("fails to allocate memory\n");
1109 free(userdata);
1110 return IVI_FAILED;
1111 }
1112
1113 notification->listener.notify = callback;
1114 notification->userdata = userdata;
1115
1116 wl_signal_add(signal, &notification->listener);
1117
1118 return IVI_SUCCEEDED;
1119}
1120
1121static void
1122remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1123{
1124 struct wl_listener *listener = NULL;
1125 struct wl_listener *next = NULL;
1126
1127 wl_list_for_each_safe(listener, next, listener_list, link) {
1128 struct listener_layout_notification *notification =
1129 container_of(listener,
1130 struct listener_layout_notification,
1131 listener);
1132
1133 struct ivi_layout_notification_callback *notification_callback =
1134 notification->userdata;
1135
1136 if ((notification_callback->callback != callback) ||
1137 (notification_callback->data != userdata)) {
1138 continue;
1139 }
1140
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001141 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001142
1143 free(notification->userdata);
1144 free(notification);
1145 }
1146}
1147
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001148/**
1149 * Exported APIs of ivi-layout library are implemented from here.
1150 * Brief of APIs is described in ivi-layout-export.h.
1151 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001152static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001153ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1154 void *userdata)
1155{
1156 struct ivi_layout *layout = get_instance();
1157 struct ivi_layout_notification_callback *created_callback = NULL;
1158
1159 if (callback == NULL) {
1160 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1161 return IVI_FAILED;
1162 }
1163
1164 created_callback = malloc(sizeof *created_callback);
1165 if (created_callback == NULL) {
1166 weston_log("fails to allocate memory\n");
1167 return IVI_FAILED;
1168 }
1169
1170 created_callback->callback = callback;
1171 created_callback->data = userdata;
1172
1173 return add_notification(&layout->layer_notification.created,
1174 layer_created,
1175 created_callback);
1176}
1177
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001178static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001179ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1180 void *userdata)
1181{
1182 struct ivi_layout *layout = get_instance();
1183 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1184}
1185
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001186static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001187ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1188 void *userdata)
1189{
1190 struct ivi_layout *layout = get_instance();
1191 struct ivi_layout_notification_callback *removed_callback = NULL;
1192
1193 if (callback == NULL) {
1194 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1195 return IVI_FAILED;
1196 }
1197
1198 removed_callback = malloc(sizeof *removed_callback);
1199 if (removed_callback == NULL) {
1200 weston_log("fails to allocate memory\n");
1201 return IVI_FAILED;
1202 }
1203
1204 removed_callback->callback = callback;
1205 removed_callback->data = userdata;
1206 return add_notification(&layout->layer_notification.removed,
1207 layer_removed,
1208 removed_callback);
1209}
1210
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001211static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001212ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1213 void *userdata)
1214{
1215 struct ivi_layout *layout = get_instance();
1216 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1217}
1218
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001219static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001220ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1221 void *userdata)
1222{
1223 struct ivi_layout *layout = get_instance();
1224 struct ivi_layout_notification_callback *created_callback = NULL;
1225
1226 if (callback == NULL) {
1227 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1228 return IVI_FAILED;
1229 }
1230
1231 created_callback = malloc(sizeof *created_callback);
1232 if (created_callback == NULL) {
1233 weston_log("fails to allocate memory\n");
1234 return IVI_FAILED;
1235 }
1236
1237 created_callback->callback = callback;
1238 created_callback->data = userdata;
1239
1240 return add_notification(&layout->surface_notification.created,
1241 surface_created,
1242 created_callback);
1243}
1244
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001245static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001246ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1247 void *userdata)
1248{
1249 struct ivi_layout *layout = get_instance();
1250 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1251}
1252
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001253static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001254ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1255 void *userdata)
1256{
1257 struct ivi_layout *layout = get_instance();
1258 struct ivi_layout_notification_callback *removed_callback = NULL;
1259
1260 if (callback == NULL) {
1261 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1262 return IVI_FAILED;
1263 }
1264
1265 removed_callback = malloc(sizeof *removed_callback);
1266 if (removed_callback == NULL) {
1267 weston_log("fails to allocate memory\n");
1268 return IVI_FAILED;
1269 }
1270
1271 removed_callback->callback = callback;
1272 removed_callback->data = userdata;
1273
1274 return add_notification(&layout->surface_notification.removed,
1275 surface_removed,
1276 removed_callback);
1277}
1278
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001279static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001280ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1281 void *userdata)
1282{
1283 struct ivi_layout *layout = get_instance();
1284 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1285}
1286
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001287static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001288ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1289 void *userdata)
1290{
1291 struct ivi_layout *layout = get_instance();
1292 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1293 if (callback == NULL) {
1294 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1295 return IVI_FAILED;
1296 }
1297
1298 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1299 if (configure_changed_callback == NULL) {
1300 weston_log("fails to allocate memory\n");
1301 return IVI_FAILED;
1302 }
1303
1304 configure_changed_callback->callback = callback;
1305 configure_changed_callback->data = userdata;
1306
1307 return add_notification(&layout->surface_notification.configure_changed,
1308 surface_configure_changed,
1309 configure_changed_callback);
1310}
1311
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001312static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001313ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1314 void *userdata)
1315{
1316 struct ivi_layout *layout = get_instance();
1317 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1318}
1319
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001320uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001321ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1322{
1323 return ivisurf->id_surface;
1324}
1325
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001326static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001327ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1328{
1329 return ivilayer->id_layer;
1330}
1331
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001332static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001333ivi_layout_get_layer_from_id(uint32_t id_layer)
1334{
1335 struct ivi_layout *layout = get_instance();
1336 struct ivi_layout_layer *ivilayer = NULL;
1337
1338 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1339 if (ivilayer->id_layer == id_layer) {
1340 return ivilayer;
1341 }
1342 }
1343
1344 return NULL;
1345}
1346
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001347struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001348ivi_layout_get_surface_from_id(uint32_t id_surface)
1349{
1350 struct ivi_layout *layout = get_instance();
1351 struct ivi_layout_surface *ivisurf = NULL;
1352
1353 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1354 if (ivisurf->id_surface == id_surface) {
1355 return ivisurf;
1356 }
1357 }
1358
1359 return NULL;
1360}
1361
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001362static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001363ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1364 surface_property_notification_func callback,
1365 void *userdata)
1366{
1367 struct listener_layout_notification* notification = NULL;
1368 struct ivi_layout_notification_callback *prop_callback = NULL;
1369
1370 if (ivisurf == NULL || callback == NULL) {
1371 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1372 return IVI_FAILED;
1373 }
1374
1375 notification = malloc(sizeof *notification);
1376 if (notification == NULL) {
1377 weston_log("fails to allocate memory\n");
1378 return IVI_FAILED;
1379 }
1380
1381 prop_callback = malloc(sizeof *prop_callback);
1382 if (prop_callback == NULL) {
1383 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001384 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001385 return IVI_FAILED;
1386 }
1387
1388 prop_callback->callback = callback;
1389 prop_callback->data = userdata;
1390
1391 notification->listener.notify = surface_prop_changed;
1392 notification->userdata = prop_callback;
1393
1394 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1395
1396 return IVI_SUCCEEDED;
1397}
1398
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001399static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001400ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1401{
1402 if (ivilayer == NULL) {
1403 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1404 return NULL;
1405 }
1406
1407 return &ivilayer->prop;
1408}
1409
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001410static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001411ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1412 int32_t *pLength,
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001413 struct weston_output ***ppArray)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001414{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001415 int32_t length = 0;
1416 int32_t n = 0;
1417
1418 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1419 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1420 return IVI_FAILED;
1421 }
1422
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001423 if (ivilayer->on_screen != NULL)
1424 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001425
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001426 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001427 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001428 *ppArray = calloc(length, sizeof(struct weston_output *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001429 if (*ppArray == NULL) {
1430 weston_log("fails to allocate memory\n");
1431 return IVI_FAILED;
1432 }
1433
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001434 (*ppArray)[n++] = ivilayer->on_screen->output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001435 }
1436
1437 *pLength = length;
1438
1439 return IVI_SUCCEEDED;
1440}
1441
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001442static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001443ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1444{
1445 struct ivi_layout *layout = get_instance();
1446 struct ivi_layout_layer *ivilayer = NULL;
1447 int32_t length = 0;
1448 int32_t n = 0;
1449
1450 if (pLength == NULL || ppArray == NULL) {
1451 weston_log("ivi_layout_get_layers: invalid argument\n");
1452 return IVI_FAILED;
1453 }
1454
1455 length = wl_list_length(&layout->layer_list);
1456
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001457 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001458 /* the Array must be free by module which called this function */
1459 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1460 if (*ppArray == NULL) {
1461 weston_log("fails to allocate memory\n");
1462 return IVI_FAILED;
1463 }
1464
1465 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1466 (*ppArray)[n++] = ivilayer;
1467 }
1468 }
1469
1470 *pLength = length;
1471
1472 return IVI_SUCCEEDED;
1473}
1474
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001475static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001476ivi_layout_get_layers_on_screen(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001477 int32_t *pLength,
1478 struct ivi_layout_layer ***ppArray)
1479{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001480 struct ivi_layout_screen *iviscrn = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001481 struct ivi_layout_layer *ivilayer = NULL;
1482 int32_t length = 0;
1483 int32_t n = 0;
1484
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001485 if (output == NULL || pLength == NULL || ppArray == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001486 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1487 return IVI_FAILED;
1488 }
1489
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001490 iviscrn = get_screen_from_output(output);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001491 length = wl_list_length(&iviscrn->order.layer_list);
1492
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001493 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001494 /* the Array must be free by module which called this function */
1495 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1496 if (*ppArray == NULL) {
1497 weston_log("fails to allocate memory\n");
1498 return IVI_FAILED;
1499 }
1500
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001501 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001502 (*ppArray)[n++] = ivilayer;
1503 }
1504 }
1505
1506 *pLength = length;
1507
1508 return IVI_SUCCEEDED;
1509}
1510
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001511static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001512ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1513 int32_t *pLength,
1514 struct ivi_layout_layer ***ppArray)
1515{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001516 int32_t length = 0;
1517 int32_t n = 0;
1518
1519 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1520 weston_log("ivi_layout_getLayers: invalid argument\n");
1521 return IVI_FAILED;
1522 }
1523
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001524 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001525 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001526 length = 1;
1527 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001528 if (*ppArray == NULL) {
1529 weston_log("fails to allocate memory\n");
1530 return IVI_FAILED;
1531 }
1532
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001533 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001534 }
1535
1536 *pLength = length;
1537
1538 return IVI_SUCCEEDED;
1539}
1540
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001541static
1542int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001543ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1544{
1545 struct ivi_layout *layout = get_instance();
1546 struct ivi_layout_surface *ivisurf = NULL;
1547 int32_t length = 0;
1548 int32_t n = 0;
1549
1550 if (pLength == NULL || ppArray == NULL) {
1551 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1552 return IVI_FAILED;
1553 }
1554
1555 length = wl_list_length(&layout->surface_list);
1556
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001557 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001558 /* the Array must be free by module which called this function */
1559 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1560 if (*ppArray == NULL) {
1561 weston_log("fails to allocate memory\n");
1562 return IVI_FAILED;
1563 }
1564
1565 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1566 (*ppArray)[n++] = ivisurf;
1567 }
1568 }
1569
1570 *pLength = length;
1571
1572 return IVI_SUCCEEDED;
1573}
1574
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001575static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001576ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1577 int32_t *pLength,
1578 struct ivi_layout_surface ***ppArray)
1579{
1580 struct ivi_layout_surface *ivisurf = NULL;
1581 int32_t length = 0;
1582 int32_t n = 0;
1583
1584 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1585 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1586 return IVI_FAILED;
1587 }
1588
1589 length = wl_list_length(&ivilayer->order.surface_list);
1590
1591 if (length != 0) {
1592 /* the Array must be free by module which called this function */
1593 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1594 if (*ppArray == NULL) {
1595 weston_log("fails to allocate memory\n");
1596 return IVI_FAILED;
1597 }
1598
1599 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1600 (*ppArray)[n++] = ivisurf;
1601 }
1602 }
1603
1604 *pLength = length;
1605
1606 return IVI_SUCCEEDED;
1607}
1608
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001609static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001610ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1611 int32_t width, int32_t height)
1612{
1613 struct ivi_layout *layout = get_instance();
1614 struct ivi_layout_layer *ivilayer = NULL;
1615
1616 ivilayer = get_layer(&layout->layer_list, id_layer);
1617 if (ivilayer != NULL) {
1618 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001619 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001620 return ivilayer;
1621 }
1622
1623 ivilayer = calloc(1, sizeof *ivilayer);
1624 if (ivilayer == NULL) {
1625 weston_log("fails to allocate memory\n");
1626 return NULL;
1627 }
1628
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001629 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001630 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001631 ivilayer->layout = layout;
1632 ivilayer->id_layer = id_layer;
1633
1634 init_layer_properties(&ivilayer->prop, width, height);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001635
1636 wl_list_init(&ivilayer->pending.surface_list);
1637 wl_list_init(&ivilayer->pending.link);
1638 ivilayer->pending.prop = ivilayer->prop;
1639
1640 wl_list_init(&ivilayer->order.surface_list);
1641 wl_list_init(&ivilayer->order.link);
1642
1643 wl_list_insert(&layout->layer_list, &ivilayer->link);
1644
1645 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1646
1647 return ivilayer;
1648}
1649
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001650static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001651ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1652{
1653 if (ivilayer == NULL) {
1654 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1655 return;
1656 }
1657
1658 remove_all_notification(&ivilayer->property_changed.listener_list);
1659}
1660
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001661static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001662ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1663 layer_property_notification_func callback,
1664 void *userdata)
1665{
1666 if (ivilayer == NULL) {
1667 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1668 return;
1669 }
1670
1671 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1672}
1673
1674static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001675ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001676{
1677 struct ivi_layout *layout = get_instance();
1678
1679 if (ivilayer == NULL) {
1680 weston_log("ivi_layout_layer_remove: invalid argument\n");
1681 return;
1682 }
1683
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001684 if (--ivilayer->ref_count > 0)
1685 return;
1686
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001687 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1688
1689 clear_surface_pending_list(ivilayer);
1690 clear_surface_order_list(ivilayer);
1691
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001692 wl_list_remove(&ivilayer->pending.link);
1693 wl_list_remove(&ivilayer->order.link);
1694 wl_list_remove(&ivilayer->link);
1695
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001696 ivi_layout_layer_remove_notification(ivilayer);
1697
1698 free(ivilayer);
1699}
1700
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001701int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001702ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1703 bool newVisibility)
1704{
1705 struct ivi_layout_layer_properties *prop = NULL;
1706
1707 if (ivilayer == NULL) {
1708 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1709 return IVI_FAILED;
1710 }
1711
1712 prop = &ivilayer->pending.prop;
1713 prop->visibility = newVisibility;
1714
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001715 if (ivilayer->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001716 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001717 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001718 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001719
1720 return IVI_SUCCEEDED;
1721}
1722
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001723int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001724ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1725 wl_fixed_t opacity)
1726{
1727 struct ivi_layout_layer_properties *prop = NULL;
1728
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001729 if (ivilayer == NULL ||
1730 opacity < wl_fixed_from_double(0.0) ||
1731 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001732 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1733 return IVI_FAILED;
1734 }
1735
1736 prop = &ivilayer->pending.prop;
1737 prop->opacity = opacity;
1738
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001739 if (ivilayer->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001740 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001741 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001742 prop->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001743
1744 return IVI_SUCCEEDED;
1745}
1746
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001747static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001748ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1749 int32_t x, int32_t y,
1750 int32_t width, int32_t height)
1751{
1752 struct ivi_layout_layer_properties *prop = NULL;
1753
1754 if (ivilayer == NULL) {
1755 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1756 return IVI_FAILED;
1757 }
1758
1759 prop = &ivilayer->pending.prop;
1760 prop->source_x = x;
1761 prop->source_y = y;
1762 prop->source_width = width;
1763 prop->source_height = height;
1764
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001765 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1766 ivilayer->prop.source_width != width ||
1767 ivilayer->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001768 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001769 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001770 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001771
1772 return IVI_SUCCEEDED;
1773}
1774
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001775int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001776ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1777 int32_t x, int32_t y,
1778 int32_t width, int32_t height)
1779{
1780 struct ivi_layout_layer_properties *prop = NULL;
1781
1782 if (ivilayer == NULL) {
1783 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1784 return IVI_FAILED;
1785 }
1786
1787 prop = &ivilayer->pending.prop;
1788 prop->dest_x = x;
1789 prop->dest_y = y;
1790 prop->dest_width = width;
1791 prop->dest_height = height;
1792
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001793 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1794 ivilayer->prop.dest_width != width ||
1795 ivilayer->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001796 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001797 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001798 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001799
1800 return IVI_SUCCEEDED;
1801}
1802
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001803static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001804ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1805 enum wl_output_transform orientation)
1806{
1807 struct ivi_layout_layer_properties *prop = NULL;
1808
1809 if (ivilayer == NULL) {
1810 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1811 return IVI_FAILED;
1812 }
1813
1814 prop = &ivilayer->pending.prop;
1815 prop->orientation = orientation;
1816
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001817 if (ivilayer->prop.orientation != orientation)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001818 prop->event_mask |= IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001819 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001820 prop->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001821
1822 return IVI_SUCCEEDED;
1823}
1824
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001825int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001826ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1827 struct ivi_layout_surface **pSurface,
1828 int32_t number)
1829{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001830 int32_t i = 0;
1831
1832 if (ivilayer == NULL) {
1833 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1834 return IVI_FAILED;
1835 }
1836
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001837 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001838
1839 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)72ad1642016-03-16 13:37:05 +00001840 wl_list_remove(&pSurface[i]->pending.link);
1841 wl_list_insert(&ivilayer->pending.surface_list,
1842 &pSurface[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001843 }
1844
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001845 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001846
1847 return IVI_SUCCEEDED;
1848}
1849
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001850int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001851ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1852 bool newVisibility)
1853{
1854 struct ivi_layout_surface_properties *prop = NULL;
1855
1856 if (ivisurf == NULL) {
1857 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1858 return IVI_FAILED;
1859 }
1860
1861 prop = &ivisurf->pending.prop;
1862 prop->visibility = newVisibility;
1863
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001864 if (ivisurf->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001865 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001866 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001867 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001868
1869 return IVI_SUCCEEDED;
1870}
1871
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001872int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001873ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1874 wl_fixed_t opacity)
1875{
1876 struct ivi_layout_surface_properties *prop = NULL;
1877
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001878 if (ivisurf == NULL ||
1879 opacity < wl_fixed_from_double(0.0) ||
1880 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001881 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1882 return IVI_FAILED;
1883 }
1884
1885 prop = &ivisurf->pending.prop;
1886 prop->opacity = opacity;
1887
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001888 if (ivisurf->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001889 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001890 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001891 prop->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001892
1893 return IVI_SUCCEEDED;
1894}
1895
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001896int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001897ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1898 int32_t x, int32_t y,
1899 int32_t width, int32_t height)
1900{
1901 struct ivi_layout_surface_properties *prop = NULL;
1902
1903 if (ivisurf == NULL) {
1904 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1905 return IVI_FAILED;
1906 }
1907
1908 prop = &ivisurf->pending.prop;
1909 prop->start_x = prop->dest_x;
1910 prop->start_y = prop->dest_y;
1911 prop->dest_x = x;
1912 prop->dest_y = y;
1913 prop->start_width = prop->dest_width;
1914 prop->start_height = prop->dest_height;
1915 prop->dest_width = width;
1916 prop->dest_height = height;
1917
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001918 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
1919 ivisurf->prop.dest_width != width ||
1920 ivisurf->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001921 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001922 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001923 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001924
1925 return IVI_SUCCEEDED;
1926}
1927
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001928static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001929ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
1930 enum wl_output_transform orientation)
1931{
1932 struct ivi_layout_surface_properties *prop = NULL;
1933
1934 if (ivisurf == NULL) {
1935 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
1936 return IVI_FAILED;
1937 }
1938
1939 prop = &ivisurf->pending.prop;
1940 prop->orientation = orientation;
1941
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001942 if (ivisurf->prop.orientation != orientation)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001943 prop->event_mask |= IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001944 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001945 prop->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001946
1947 return IVI_SUCCEEDED;
1948}
1949
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001950static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001951ivi_layout_screen_add_layer(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001952 struct ivi_layout_layer *addlayer)
1953{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001954 struct ivi_layout_screen *iviscrn;
1955
1956 if (output == NULL || addlayer == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001957 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
1958 return IVI_FAILED;
1959 }
1960
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001961 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001962
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00001963 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001964 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
1965 return IVI_SUCCEEDED;
1966 }
1967
Ucan, Emre (ADITG/SW1)f46306f2016-03-16 13:37:07 +00001968 wl_list_remove(&addlayer->pending.link);
1969 wl_list_insert(&iviscrn->pending.layer_list, &addlayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001970
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001971 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001972
1973 return IVI_SUCCEEDED;
1974}
1975
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001976static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001977ivi_layout_screen_set_render_order(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001978 struct ivi_layout_layer **pLayer,
1979 const int32_t number)
1980{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001981 struct ivi_layout_screen *iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001982 struct ivi_layout_layer *ivilayer = NULL;
1983 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001984 int32_t i = 0;
1985
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001986 if (output == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001987 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
1988 return IVI_FAILED;
1989 }
1990
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001991 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001992
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001993 wl_list_for_each_safe(ivilayer, next,
1994 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001995 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001996 wl_list_init(&ivilayer->pending.link);
1997 }
1998
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001999 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002000
2001 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)4e221f02016-03-16 13:37:08 +00002002 wl_list_remove(&pLayer[i]->pending.link);
2003 wl_list_insert(&iviscrn->pending.layer_list,
2004 &pLayer[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002005 }
2006
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002007 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002008
2009 return IVI_SUCCEEDED;
2010}
2011
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002012/**
2013 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2014 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2015 * This function is used to get the result of drawing by clients.
2016 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002017static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002018ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2019{
2020 return ivisurf != NULL ? ivisurf->surface : NULL;
2021}
2022
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002023static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002024ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2025 int32_t *width, int32_t *height,
2026 int32_t *stride)
2027{
2028 int32_t w;
2029 int32_t h;
2030 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2031
2032 if (ivisurf == NULL || ivisurf->surface == NULL) {
2033 weston_log("%s: invalid argument\n", __func__);
2034 return IVI_FAILED;
2035 }
2036
2037 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2038
2039 if (width != NULL)
2040 *width = w;
2041
2042 if (height != NULL)
2043 *height = h;
2044
2045 if (stride != NULL)
2046 *stride = w * bytespp;
2047
2048 return IVI_SUCCEEDED;
2049}
2050
2051static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002052ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2053 layer_property_notification_func callback,
2054 void *userdata)
2055{
2056 struct ivi_layout_notification_callback *prop_callback = NULL;
2057
2058 if (ivilayer == NULL || callback == NULL) {
2059 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2060 return IVI_FAILED;
2061 }
2062
2063 prop_callback = malloc(sizeof *prop_callback);
2064 if (prop_callback == NULL) {
2065 weston_log("fails to allocate memory\n");
2066 return IVI_FAILED;
2067 }
2068
2069 prop_callback->callback = callback;
2070 prop_callback->data = userdata;
2071
2072 return add_notification(&ivilayer->property_changed,
2073 layer_prop_changed,
2074 prop_callback);
2075}
2076
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002077static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002078ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2079{
2080 if (ivisurf == NULL) {
2081 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2082 return NULL;
2083 }
2084
2085 return &ivisurf->prop;
2086}
2087
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002088static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002089ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2090 struct ivi_layout_surface *addsurf)
2091{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002092 if (ivilayer == NULL || addsurf == NULL) {
2093 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2094 return IVI_FAILED;
2095 }
2096
Wataru Natsume9c926fe2016-03-03 19:56:09 +09002097 if (addsurf->on_layer == ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002098 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002099
Ucan, Emre (ADITG/SW1)10942372016-03-16 13:37:02 +00002100 wl_list_remove(&addsurf->pending.link);
2101 wl_list_insert(&ivilayer->pending.surface_list, &addsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002102
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002103 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002104
2105 return IVI_SUCCEEDED;
2106}
2107
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002108static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002109ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2110 struct ivi_layout_surface *remsurf)
2111{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002112 if (ivilayer == NULL || remsurf == NULL) {
2113 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2114 return;
2115 }
2116
Ucan, Emre (ADITG/SW1)536d8332016-03-16 13:36:59 +00002117 wl_list_remove(&remsurf->pending.link);
2118 wl_list_init(&remsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002119
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002120 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002121}
2122
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002123static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002124ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2125 int32_t x, int32_t y,
2126 int32_t width, int32_t height)
2127{
2128 struct ivi_layout_surface_properties *prop = NULL;
2129
2130 if (ivisurf == NULL) {
2131 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2132 return IVI_FAILED;
2133 }
2134
2135 prop = &ivisurf->pending.prop;
2136 prop->source_x = x;
2137 prop->source_y = y;
2138 prop->source_width = width;
2139 prop->source_height = height;
2140
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002141 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2142 ivisurf->prop.source_width != width ||
2143 ivisurf->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00002144 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002145 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00002146 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002147
2148 return IVI_SUCCEEDED;
2149}
2150
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002151int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002152ivi_layout_commit_changes(void)
2153{
2154 struct ivi_layout *layout = get_instance();
2155
2156 commit_surface_list(layout);
2157 commit_layer_list(layout);
2158 commit_screen_list(layout);
2159
2160 commit_transition(layout);
2161
2162 commit_changes(layout);
2163 send_prop(layout);
2164 weston_compositor_schedule_repaint(layout->compositor);
2165
2166 return IVI_SUCCEEDED;
2167}
2168
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002169static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002170ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2171 enum ivi_layout_transition_type type,
2172 uint32_t duration)
2173{
2174 if (ivilayer == NULL) {
2175 weston_log("%s: invalid argument\n", __func__);
2176 return -1;
2177 }
2178
2179 ivilayer->pending.prop.transition_type = type;
2180 ivilayer->pending.prop.transition_duration = duration;
2181
2182 return 0;
2183}
2184
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002185static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002186ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2187 uint32_t is_fade_in,
2188 double start_alpha, double end_alpha)
2189{
2190 if (ivilayer == NULL) {
2191 weston_log("%s: invalid argument\n", __func__);
2192 return -1;
2193 }
2194
2195 ivilayer->pending.prop.is_fade_in = is_fade_in;
2196 ivilayer->pending.prop.start_alpha = start_alpha;
2197 ivilayer->pending.prop.end_alpha = end_alpha;
2198
2199 return 0;
2200}
2201
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002202static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002203ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2204 uint32_t duration)
2205{
2206 struct ivi_layout_surface_properties *prop;
2207
2208 if (ivisurf == NULL) {
2209 weston_log("%s: invalid argument\n", __func__);
2210 return -1;
2211 }
2212
2213 prop = &ivisurf->pending.prop;
2214 prop->transition_duration = duration*10;
2215 return 0;
2216}
2217
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002218static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002219ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2220 enum ivi_layout_transition_type type,
2221 uint32_t duration)
2222{
2223 struct ivi_layout_surface_properties *prop;
2224
2225 if (ivisurf == NULL) {
2226 weston_log("%s: invalid argument\n", __func__);
2227 return -1;
2228 }
2229
2230 prop = &ivisurf->pending.prop;
2231 prop->transition_type = type;
2232 prop->transition_duration = duration;
2233 return 0;
2234}
2235
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002236static int32_t
2237ivi_layout_surface_dump(struct weston_surface *surface,
2238 void *target, size_t size,int32_t x, int32_t y,
2239 int32_t width, int32_t height)
2240{
2241 int result = 0;
2242
2243 if (surface == NULL) {
2244 weston_log("%s: invalid argument\n", __func__);
2245 return IVI_FAILED;
2246 }
2247
2248 result = weston_surface_copy_content(
2249 surface, target, size,
2250 x, y, width, height);
2251
2252 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2253}
2254
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002255/**
2256 * methods of interaction between ivi-shell with ivi-layout
2257 */
2258struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002259ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2260{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002261 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002262 return NULL;
2263
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002264 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002265}
2266
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002267void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002268ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2269 int32_t width, int32_t height)
2270{
2271 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002272
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002273 /* emit callback which is set by ivi-layout api user */
2274 wl_signal_emit(&layout->surface_notification.configure_changed,
2275 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002276}
2277
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002278struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002279ivi_layout_surface_create(struct weston_surface *wl_surface,
2280 uint32_t id_surface)
2281{
2282 struct ivi_layout *layout = get_instance();
2283 struct ivi_layout_surface *ivisurf = NULL;
2284 struct weston_view *tmpview = NULL;
2285
2286 if (wl_surface == NULL) {
2287 weston_log("ivi_layout_surface_create: invalid argument\n");
2288 return NULL;
2289 }
2290
2291 ivisurf = get_surface(&layout->surface_list, id_surface);
2292 if (ivisurf != NULL) {
2293 if (ivisurf->surface != NULL) {
2294 weston_log("id_surface(%d) is already created\n", id_surface);
2295 return NULL;
2296 }
2297 }
2298
2299 ivisurf = calloc(1, sizeof *ivisurf);
2300 if (ivisurf == NULL) {
2301 weston_log("fails to allocate memory\n");
2302 return NULL;
2303 }
2304
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002305 wl_signal_init(&ivisurf->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002306 ivisurf->id_surface = id_surface;
2307 ivisurf->layout = layout;
2308
2309 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002310
2311 tmpview = weston_view_create(wl_surface);
2312 if (tmpview == NULL) {
2313 weston_log("fails to allocate memory\n");
2314 }
2315
2316 ivisurf->surface->width_from_buffer = 0;
2317 ivisurf->surface->height_from_buffer = 0;
2318
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002319 weston_matrix_init(&ivisurf->transform.matrix);
2320 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002321
2322 init_surface_properties(&ivisurf->prop);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002323
2324 ivisurf->pending.prop = ivisurf->prop;
2325 wl_list_init(&ivisurf->pending.link);
2326
2327 wl_list_init(&ivisurf->order.link);
2328 wl_list_init(&ivisurf->order.layer_list);
2329
2330 wl_list_insert(&layout->surface_list, &ivisurf->link);
2331
2332 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2333
2334 return ivisurf;
2335}
2336
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002337void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002338ivi_layout_init_with_compositor(struct weston_compositor *ec)
2339{
2340 struct ivi_layout *layout = get_instance();
2341
2342 layout->compositor = ec;
2343
2344 wl_list_init(&layout->surface_list);
2345 wl_list_init(&layout->layer_list);
2346 wl_list_init(&layout->screen_list);
2347
2348 wl_signal_init(&layout->layer_notification.created);
2349 wl_signal_init(&layout->layer_notification.removed);
2350
2351 wl_signal_init(&layout->surface_notification.created);
2352 wl_signal_init(&layout->surface_notification.removed);
2353 wl_signal_init(&layout->surface_notification.configure_changed);
2354
2355 /* Add layout_layer at the last of weston_compositor.layer_list */
2356 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2357
2358 create_screen(ec);
2359
2360 layout->transitions = ivi_layout_transition_set_create(ec);
2361 wl_list_init(&layout->pending_transition_list);
2362}
2363
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002364static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002365 /**
2366 * commit all changes
2367 */
2368 .commit_changes = ivi_layout_commit_changes,
2369
2370 /**
2371 * surface controller interfaces
2372 */
2373 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2374 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2375 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2376 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2377 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2378 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2379 .get_surfaces = ivi_layout_get_surfaces,
2380 .get_id_of_surface = ivi_layout_get_id_of_surface,
2381 .get_surface_from_id = ivi_layout_get_surface_from_id,
2382 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2383 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2384 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002385 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002386 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2387 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002388 .surface_set_orientation = ivi_layout_surface_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002389 .surface_add_notification = ivi_layout_surface_add_notification,
2390 .surface_remove_notification = ivi_layout_surface_remove_notification,
2391 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2392 .surface_set_transition = ivi_layout_surface_set_transition,
2393 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2394
2395 /**
2396 * layer controller interfaces
2397 */
2398 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2399 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2400 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2401 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2402 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002403 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002404 .get_layers = ivi_layout_get_layers,
2405 .get_id_of_layer = ivi_layout_get_id_of_layer,
2406 .get_layer_from_id = ivi_layout_get_layer_from_id,
2407 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2408 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2409 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2410 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002411 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002412 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2413 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002414 .layer_set_orientation = ivi_layout_layer_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002415 .layer_add_surface = ivi_layout_layer_add_surface,
2416 .layer_remove_surface = ivi_layout_layer_remove_surface,
2417 .layer_set_render_order = ivi_layout_layer_set_render_order,
2418 .layer_add_notification = ivi_layout_layer_add_notification,
2419 .layer_remove_notification = ivi_layout_layer_remove_notification,
2420 .layer_set_transition = ivi_layout_layer_set_transition,
2421
2422 /**
Ucan, Emre (ADITG/SW1)6d89b1c2016-03-17 15:30:49 +00002423 * screen controller interfaces
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002424 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002425 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2426 .screen_add_layer = ivi_layout_screen_add_layer,
2427 .screen_set_render_order = ivi_layout_screen_set_render_order,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002428
2429 /**
2430 * animation
2431 */
2432 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002433 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2434
2435 /**
2436 * surface content dumping for debugging
2437 */
2438 .surface_get_size = ivi_layout_surface_get_size,
2439 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002440
2441 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002442 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002443 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002444 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Ucan, Emre (ADITG/SW1)d56b90d2016-03-17 15:30:32 +00002445 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002446};
2447
2448int
2449load_controller_modules(struct weston_compositor *compositor, const char *modules,
2450 int *argc, char *argv[])
2451{
2452 const char *p, *end;
2453 char buffer[256];
2454 int (*controller_module_init)(struct weston_compositor *compositor,
2455 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002456 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002457 size_t interface_version);
2458
2459 if (modules == NULL)
2460 return 0;
2461
2462 p = modules;
2463 while (*p) {
2464 end = strchrnul(p, ',');
2465 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2466
2467 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002468 if (!controller_module_init)
2469 return -1;
2470
2471 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002472 &ivi_layout_interface,
2473 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002474 weston_log("ivi-shell: Initialization of controller module fails");
2475 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002476 }
2477
2478 p = end;
2479 while (*p == ',')
2480 p++;
2481 }
2482
2483 return 0;
2484}