blob: f1ea9bd79c2d100b9d1510a03f2143a4455deee8 [file] [log] [blame]
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001/*
2 * Copyright (C) 2013 DENSO CORPORATION
3 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090011 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090024 */
25
26/**
27 * Implementation of ivi-layout library. The actual view on ivi_screen is
28 * not updated till calling ivi_layout_commit_changes. A overview from
29 * calling API for updating properties of ivi_surface/ivi_layer to asking
30 * compositor to compose them by using weston_compositor_schedule_repaint,
31 * 0/ initialize this library by ivi_layout_init_with_compositor
32 * with (struct weston_compositor *ec) from ivi-shell.
33 * 1/ When a API for updating properties of ivi_surface/ivi_layer, it updates
34 * pending prop of ivi_surface/ivi_layer/ivi_screen which are structure to
35 * store properties.
36 * 2/ Before calling commitChanges, in case of calling a API to get a property,
37 * return current property, not pending property.
38 * 3/ At the timing of calling ivi_layout_commitChanges, pending properties
39 * are applied to properties.
40 *
41 * *) ivi_layout_commitChanges is also called by transition animation
42 * per each frame. See ivi-layout-transition.c in details. Transition
43 * animation interpolates frames between previous properties of ivi_surface
44 * and new ones.
45 * For example, when a property of ivi_surface is changed from invisibility
46 * to visibility, it behaves like fade-in. When ivi_layout_commitChange is
47 * called during transition animation, it cancels the transition and
48 * re-start transition to new properties from current properties of final
49 * frame just before the the cancellation.
50 *
51 * 4/ According properties, set transformation by using weston_matrix and
52 * weston_view per ivi_surfaces and ivi_layers in while loop.
53 * 5/ Set damage and trigger transform by using weston_view_geometry_dirty.
54 * 6/ Notify update of properties.
55 * 7/ Trigger composition by weston_compositor_schedule_repaint.
56 *
57 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090058#include "config.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090059
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090060#include <string.h>
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +000061#include <assert.h>
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090062
63#include "compositor.h"
Pekka Paalanen1f821932016-03-15 16:57:51 +020064#include "ivi-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090065#include "ivi-layout-export.h"
66#include "ivi-layout-private.h"
67
Jon Cruz867d50e2015-06-15 15:37:10 -070068#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070069#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090070
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +090071#define max(a, b) ((a) > (b) ? (a) : (b))
72
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090073struct listener_layout_notification {
74 void *userdata;
75 struct wl_listener listener;
76};
77
78struct ivi_layout;
79
80struct ivi_layout_screen {
81 struct wl_list link;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090082 uint32_t id_screen;
83
84 struct ivi_layout *layout;
85 struct weston_output *output;
86
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090087 struct {
88 struct wl_list layer_list;
89 struct wl_list link;
90 } pending;
91
92 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +000093 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090094 struct wl_list layer_list;
95 struct wl_list link;
96 } order;
97};
98
99struct ivi_layout_notification_callback {
100 void *callback;
101 void *data;
102};
103
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900104struct ivi_rectangle
105{
106 int32_t x;
107 int32_t y;
108 int32_t width;
109 int32_t height;
110};
111
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900112static void
113remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
114
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900115static struct ivi_layout ivilayout = {0};
116
117struct ivi_layout *
118get_instance(void)
119{
120 return &ivilayout;
121}
122
123/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900124 * Internal API to add/remove a ivi_layer to/from ivi_screen.
125 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900126static struct ivi_layout_surface *
127get_surface(struct wl_list *surf_list, uint32_t id_surface)
128{
129 struct ivi_layout_surface *ivisurf;
130
131 wl_list_for_each(ivisurf, surf_list, link) {
132 if (ivisurf->id_surface == id_surface) {
133 return ivisurf;
134 }
135 }
136
137 return NULL;
138}
139
140static struct ivi_layout_layer *
141get_layer(struct wl_list *layer_list, uint32_t id_layer)
142{
143 struct ivi_layout_layer *ivilayer;
144
145 wl_list_for_each(ivilayer, layer_list, link) {
146 if (ivilayer->id_layer == id_layer) {
147 return ivilayer;
148 }
149 }
150
151 return NULL;
152}
153
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000154static struct weston_view *
155get_weston_view(struct ivi_layout_surface *ivisurf)
156{
157 struct weston_view *view = NULL;
158
159 assert(ivisurf->surface != NULL);
160
161 /* One view per surface */
162 if(wl_list_empty(&ivisurf->surface->views))
163 view = NULL;
164 else
165 view = wl_container_of(ivisurf->surface->views.next, view, surface_link);
166
167 return view;
168}
169
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900170static void
171remove_configured_listener(struct ivi_layout_surface *ivisurf)
172{
173 struct wl_listener *link = NULL;
174 struct wl_listener *next = NULL;
175
176 wl_list_for_each_safe(link, next, &ivisurf->configured.listener_list, link) {
177 wl_list_remove(&link->link);
178 }
179}
180
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900181static void
182remove_all_notification(struct wl_list *listener_list)
183{
184 struct wl_listener *listener = NULL;
185 struct wl_listener *next = NULL;
186
187 wl_list_for_each_safe(listener, next, listener_list, link) {
188 struct listener_layout_notification *notification = NULL;
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000189 wl_list_remove(&listener->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900190
191 notification =
192 container_of(listener,
193 struct listener_layout_notification,
194 listener);
195
196 free(notification->userdata);
197 free(notification);
198 }
199}
200
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900201static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900202ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
203{
204 if (ivisurf == NULL) {
205 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
206 return;
207 }
208
209 remove_all_notification(&ivisurf->property_changed.listener_list);
210}
211
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900212static void
213ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
214 surface_property_notification_func callback,
215 void *userdata)
216{
217 if (ivisurf == NULL) {
218 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
219 return;
220 }
221
222 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
223}
224
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900225/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900226 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900227 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900228void
229ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900230{
231 struct ivi_layout *layout = get_instance();
232
233 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900234 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900235 return;
236 }
237
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900238 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900239 wl_list_remove(&ivisurf->pending.link);
240 wl_list_remove(&ivisurf->order.link);
241 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900242
243 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
244
Mateusz Polroladada6e32016-03-09 09:13:26 +0000245 ivi_layout_remove_all_surface_transitions(ivisurf);
246
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900247 remove_configured_listener(ivisurf);
248
249 ivi_layout_surface_remove_notification(ivisurf);
250
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900251 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900252}
253
254/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900255 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
256 * Called by ivi_layout_init_with_compositor.
257 */
258static void
259create_screen(struct weston_compositor *ec)
260{
261 struct ivi_layout *layout = get_instance();
262 struct ivi_layout_screen *iviscrn = NULL;
263 struct weston_output *output = NULL;
264 int32_t count = 0;
265
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
275 iviscrn->id_screen = count;
276 count++;
277
278 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900279
280 wl_list_init(&iviscrn->pending.layer_list);
281 wl_list_init(&iviscrn->pending.link);
282
283 wl_list_init(&iviscrn->order.layer_list);
284 wl_list_init(&iviscrn->order.link);
285
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900286 wl_list_insert(&layout->screen_list, &iviscrn->link);
287 }
288}
289
290/**
291 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
292 */
293static void
294init_layer_properties(struct ivi_layout_layer_properties *prop,
295 int32_t width, int32_t height)
296{
297 memset(prop, 0, sizeof *prop);
298 prop->opacity = wl_fixed_from_double(1.0);
299 prop->source_width = width;
300 prop->source_height = height;
301 prop->dest_width = width;
302 prop->dest_height = height;
303}
304
305static void
306init_surface_properties(struct ivi_layout_surface_properties *prop)
307{
308 memset(prop, 0, sizeof *prop);
309 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900310 /*
311 * FIXME: this shall be finxed by ivi-layout-transition.
312 */
313 prop->dest_width = 1;
314 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900315}
316
317/**
318 * Internal APIs to be called from ivi_layout_commit_changes.
319 */
320static void
321update_opacity(struct ivi_layout_layer *ivilayer,
322 struct ivi_layout_surface *ivisurf)
323{
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000324 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900325 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
326 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
327
Nobuhiko Tanibata90c27892015-12-26 23:52:51 +0900328 tmpview = get_weston_view(ivisurf);
329 assert(tmpview != NULL);
330 tmpview->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900331}
332
333static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900334get_rotate_values(enum wl_output_transform orientation,
335 float *v_sin,
336 float *v_cos)
337{
338 switch (orientation) {
339 case WL_OUTPUT_TRANSFORM_90:
340 *v_sin = 1.0f;
341 *v_cos = 0.0f;
342 break;
343 case WL_OUTPUT_TRANSFORM_180:
344 *v_sin = 0.0f;
345 *v_cos = -1.0f;
346 break;
347 case WL_OUTPUT_TRANSFORM_270:
348 *v_sin = -1.0f;
349 *v_cos = 0.0f;
350 break;
351 case WL_OUTPUT_TRANSFORM_NORMAL:
352 default:
353 *v_sin = 0.0f;
354 *v_cos = 1.0f;
355 break;
356 }
357}
358
359static void
360get_scale(enum wl_output_transform orientation,
361 float dest_width,
362 float dest_height,
363 float source_width,
364 float source_height,
365 float *scale_x,
366 float *scale_y)
367{
368 switch (orientation) {
369 case WL_OUTPUT_TRANSFORM_90:
370 *scale_x = dest_width / source_height;
371 *scale_y = dest_height / source_width;
372 break;
373 case WL_OUTPUT_TRANSFORM_180:
374 *scale_x = dest_width / source_width;
375 *scale_y = dest_height / source_height;
376 break;
377 case WL_OUTPUT_TRANSFORM_270:
378 *scale_x = dest_width / source_height;
379 *scale_y = dest_height / source_width;
380 break;
381 case WL_OUTPUT_TRANSFORM_NORMAL:
382 default:
383 *scale_x = dest_width / source_width;
384 *scale_y = dest_height / source_height;
385 break;
386 }
387}
388
389static void
390calc_transformation_matrix(struct ivi_rectangle *source_rect,
391 struct ivi_rectangle *dest_rect,
392 enum wl_output_transform orientation,
393 struct weston_matrix *m)
394{
395 float source_center_x;
396 float source_center_y;
397 float vsin;
398 float vcos;
399 float scale_x;
400 float scale_y;
401 float translate_x;
402 float translate_y;
403
404 source_center_x = source_rect->x + source_rect->width * 0.5f;
405 source_center_y = source_rect->y + source_rect->height * 0.5f;
406 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
407
408 get_rotate_values(orientation, &vsin, &vcos);
409 weston_matrix_rotate_xy(m, vcos, vsin);
410
411 get_scale(orientation,
412 dest_rect->width,
413 dest_rect->height,
414 source_rect->width,
415 source_rect->height,
416 &scale_x,
417 &scale_y);
418 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
419
420 translate_x = dest_rect->width * 0.5f + dest_rect->x;
421 translate_y = dest_rect->height * 0.5f + dest_rect->y;
422 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
423}
424
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900425/*
426 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900427 */
428static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900429ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
430 const struct ivi_rectangle *rect2,
431 struct ivi_rectangle *rect_output)
432{
433 int32_t rect1_right = rect1->x + rect1->width;
434 int32_t rect1_bottom = rect1->y + rect1->height;
435 int32_t rect2_right = rect2->x + rect2->width;
436 int32_t rect2_bottom = rect2->y + rect2->height;
437
438 rect_output->x = max(rect1->x, rect2->x);
439 rect_output->y = max(rect1->y, rect2->y);
440 rect_output->width = rect1_right < rect2_right ?
441 rect1_right - rect_output->x :
442 rect2_right - rect_output->x;
443 rect_output->height = rect1_bottom < rect2_bottom ?
444 rect1_bottom - rect_output->y :
445 rect2_bottom - rect_output->y;
446
447 if (rect_output->width < 0 || rect_output->height < 0) {
448 rect_output->width = 0;
449 rect_output->height = 0;
450 }
451}
452
453/*
454 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
455 * and store the result in rect_output.
456 * The boundingbox must be given in the same coordinate space as rect_output.
457 * Additionally, there are the following restrictions on the matrix:
458 * - no projective transformations
459 * - no skew
460 * - only multiples of 90-degree rotations supported
461 *
462 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
463 * as a fail-safe with log.
464 */
465static void
466calc_inverse_matrix_transform(const struct weston_matrix *matrix,
467 const struct ivi_rectangle *rect_input,
468 const struct ivi_rectangle *boundingbox,
469 struct ivi_rectangle *rect_output)
470{
471 struct weston_matrix m;
472 struct weston_vector top_left;
473 struct weston_vector bottom_right;
474
475 assert(boundingbox != rect_output);
476
477 if (weston_matrix_invert(&m, matrix) < 0) {
478 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
479 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
480 rect_output->x = boundingbox->x;
481 rect_output->y = boundingbox->y;
482 rect_output->width = boundingbox->width;
483 rect_output->height = boundingbox->height;
484 }
485
486 /* The vectors and matrices involved will always produce f[3] == 1.0. */
487 top_left.f[0] = rect_input->x;
488 top_left.f[1] = rect_input->y;
489 top_left.f[2] = 0.0f;
490 top_left.f[3] = 1.0f;
491
492 bottom_right.f[0] = rect_input->x + rect_input->width;
493 bottom_right.f[1] = rect_input->y + rect_input->height;
494 bottom_right.f[2] = 0.0f;
495 bottom_right.f[3] = 1.0f;
496
497 weston_matrix_transform(&m, &top_left);
498 weston_matrix_transform(&m, &bottom_right);
499
500 if (top_left.f[0] < bottom_right.f[0]) {
501 rect_output->x = top_left.f[0];
502 rect_output->width = bottom_right.f[0] - rect_output->x;
503 } else {
504 rect_output->x = bottom_right.f[0];
505 rect_output->width = top_left.f[0] - rect_output->x;
506 }
507
508 if (top_left.f[1] < bottom_right.f[1]) {
509 rect_output->y = top_left.f[1];
510 rect_output->height = bottom_right.f[1] - rect_output->y;
511 } else {
512 rect_output->y = bottom_right.f[1];
513 rect_output->height = top_left.f[1] - rect_output->y;
514 }
515
516 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
517}
518
519/**
520 * This computes the whole transformation matrix:m from surface-local
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900521 * coordinates to multi screens coordinate, which is global coordinates.
522 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900523 *
524 * Additionally, this computes the mask on surface-local coordinates as a
525 * ivi_rectangle. This can be set to weston_view_set_mask.
526 *
527 * The mask is computed by following steps
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900528 * - destination rectangle of layer is tansformed to multi screen coordinate,
529 * global coordinates. This is done by adding weston_output.{x,y} in simple
530 * because there is no scaled and rotated transformation.
531 * - destination rectangle of layer in multi screens coordinate needs to be
532 * intersected inside of a screen the layer is assigned to. This is because
533 * overlapped region of weston surface in another screen shall not be
534 * displayed according to ivi use case.
535 * - destination rectangle of layer
536 * - in multi screen coordinates,
537 * - and intersected inside of an assigned screen,
538 * is inversed to surface-local cooodinates by inversed matrix:m.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900539 * - the area is intersected by intersected area between weston_surface and
540 * source rectangle of ivi_surface.
541 */
542static void
543calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900544 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900545 struct ivi_layout_layer *ivilayer,
546 struct ivi_layout_surface *ivisurf,
547 struct weston_matrix *m,
548 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900549{
550 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
551 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900552 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900553 struct ivi_rectangle weston_surface_rect = { 0,
554 0,
555 ivisurf->surface->width,
556 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900557 struct ivi_rectangle surface_source_rect = { sp->source_x,
558 sp->source_y,
559 sp->source_width,
560 sp->source_height };
561 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
562 sp->dest_y,
563 sp->dest_width,
564 sp->dest_height };
565 struct ivi_rectangle layer_source_rect = { lp->source_x,
566 lp->source_y,
567 lp->source_width,
568 lp->source_height };
569 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
570 lp->dest_y,
571 lp->dest_width,
572 lp->dest_height };
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900573 struct ivi_rectangle screen_dest_rect = { output->x,
574 output->y,
575 output->width,
576 output->height };
577 struct ivi_rectangle layer_dest_rect_in_global =
578 { lp->dest_x + output->x,
579 lp->dest_y + output->y,
580 lp->dest_width,
581 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900582 struct ivi_rectangle surface_result;
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900583 struct ivi_rectangle layer_dest_rect_in_global_intersected;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900584
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900585 /*
586 * the whole transformation matrix:m from surface-local
587 * coordinates to global coordinates, which is computed by
588 * two steps,
589 * - surface-local coordinates to layer-local coordinates
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900590 * - layer-local coordinates to a single screen-local coordinates
591 * - a single screen-local coordinates to multi screen coordinates,
592 * which is global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900593 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900594 calc_transformation_matrix(&surface_source_rect,
595 &surface_dest_rect,
596 sp->orientation, m);
597
598 calc_transformation_matrix(&layer_source_rect,
599 &layer_dest_rect,
600 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900601
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900602 weston_matrix_translate(m, output->x, output->y, 0.0f);
603
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900604 /* this intersected ivi_rectangle would be used for masking
605 * weston_surface
606 */
607 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
608 &surface_result);
609
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900610 /*
611 * destination rectangle of layer in multi screens coordinate
612 * is intersected to avoid displaying outside of an assigned screen.
613 */
614 ivi_rectangle_intersect(&layer_dest_rect_in_global, &screen_dest_rect,
615 &layer_dest_rect_in_global_intersected);
616
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900617 /* calc masking area of weston_surface from m */
618 calc_inverse_matrix_transform(m,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900619 &layer_dest_rect_in_global_intersected,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900620 &surface_result,
621 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900622}
623
624static void
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900625update_prop(struct ivi_layout_screen *iviscrn,
626 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900627 struct ivi_layout_surface *ivisurf)
628{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900629 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900630 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900631 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900632
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900633 /*In case of no prop change, this just returns*/
634 if (!ivilayer->event_mask && !ivisurf->event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900635 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900636
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900637 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900638
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000639 tmpview = get_weston_view(ivisurf);
640 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900641
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900642 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
643 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
644 can_calc = false;
645 }
646
647 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
648 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
649 can_calc = false;
650 }
651
652 if (can_calc) {
653 wl_list_remove(&ivisurf->transform.link);
654 weston_matrix_init(&ivisurf->transform.matrix);
655
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900656 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900657 iviscrn, ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900658
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000659 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
660 wl_list_insert(&tmpview->geometry.transformation_list,
661 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900662
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000663 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900664 }
665
666 ivisurf->update_count++;
667
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000668 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900669
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000670 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900671}
672
673static void
674commit_changes(struct ivi_layout *layout)
675{
676 struct ivi_layout_screen *iviscrn = NULL;
677 struct ivi_layout_layer *ivilayer = NULL;
678 struct ivi_layout_surface *ivisurf = NULL;
679
680 wl_list_for_each(iviscrn, &layout->screen_list, link) {
681 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900682 /*
683 * If ivilayer is invisible, weston_view of ivisurf doesn't
684 * need to be modified.
685 */
686 if (ivilayer->prop.visibility == false)
687 continue;
688
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900689 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900690 /*
691 * If ivilayer is invisible, weston_view of ivisurf doesn't
692 * need to be modified.
693 */
694 if (ivisurf->prop.visibility == false)
695 continue;
696
697 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900698 }
699 }
700 }
701}
702
703static void
704commit_surface_list(struct ivi_layout *layout)
705{
706 struct ivi_layout_surface *ivisurf = NULL;
707 int32_t dest_x = 0;
708 int32_t dest_y = 0;
709 int32_t dest_width = 0;
710 int32_t dest_height = 0;
711 int32_t configured = 0;
712
713 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300714 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900715 dest_x = ivisurf->prop.dest_x;
716 dest_y = ivisurf->prop.dest_y;
717 dest_width = ivisurf->prop.dest_width;
718 dest_height = ivisurf->prop.dest_height;
719
720 ivi_layout_transition_move_resize_view(ivisurf,
721 ivisurf->pending.prop.dest_x,
722 ivisurf->pending.prop.dest_y,
723 ivisurf->pending.prop.dest_width,
724 ivisurf->pending.prop.dest_height,
725 ivisurf->pending.prop.transition_duration);
726
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300727 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900728 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
729 } else {
730 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
731 }
732
733 ivisurf->prop = ivisurf->pending.prop;
734 ivisurf->prop.dest_x = dest_x;
735 ivisurf->prop.dest_y = dest_y;
736 ivisurf->prop.dest_width = dest_width;
737 ivisurf->prop.dest_height = dest_height;
738 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
739 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
740
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300741 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900742 dest_x = ivisurf->prop.dest_x;
743 dest_y = ivisurf->prop.dest_y;
744 dest_width = ivisurf->prop.dest_width;
745 dest_height = ivisurf->prop.dest_height;
746
747 ivi_layout_transition_move_resize_view(ivisurf,
748 ivisurf->pending.prop.dest_x,
749 ivisurf->pending.prop.dest_y,
750 ivisurf->pending.prop.dest_width,
751 ivisurf->pending.prop.dest_height,
752 ivisurf->pending.prop.transition_duration);
753
754 ivisurf->prop = ivisurf->pending.prop;
755 ivisurf->prop.dest_x = dest_x;
756 ivisurf->prop.dest_y = dest_y;
757 ivisurf->prop.dest_width = dest_width;
758 ivisurf->prop.dest_height = dest_height;
759
760 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
761 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
762
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300763 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900764 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300765 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900766 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
767 } else {
768 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
769 }
770
771 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
772 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
773 configured = 1;
774 }
775
776 ivisurf->prop = ivisurf->pending.prop;
777 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
778 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
779
Pekka Paalanen1f821932016-03-15 16:57:51 +0200780 if (configured && !is_surface_transition(ivisurf)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900781 wl_signal_emit(&ivisurf->configured, ivisurf);
Pekka Paalanen1f821932016-03-15 16:57:51 +0200782 shell_surface_send_configure(ivisurf->surface,
783 ivisurf->prop.dest_width,
784 ivisurf->prop.dest_height);
785 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900786 } else {
787 configured = 0;
788 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
789 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
790 configured = 1;
791 }
792
793 ivisurf->prop = ivisurf->pending.prop;
794 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
795 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
796
Pekka Paalanen1f821932016-03-15 16:57:51 +0200797 if (configured && !is_surface_transition(ivisurf)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900798 wl_signal_emit(&ivisurf->configured, ivisurf);
Pekka Paalanen1f821932016-03-15 16:57:51 +0200799 shell_surface_send_configure(ivisurf->surface,
800 ivisurf->prop.dest_width,
801 ivisurf->prop.dest_height);
802 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900803 }
804 }
805}
806
807static void
808commit_layer_list(struct ivi_layout *layout)
809{
810 struct ivi_layout_layer *ivilayer = NULL;
811 struct ivi_layout_surface *ivisurf = NULL;
812 struct ivi_layout_surface *next = NULL;
813
814 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300815 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900816 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 -0300817 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900818 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
819 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
820 NULL, NULL,
821 ivilayer->pending.prop.transition_duration);
822 }
823 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
824
825 ivilayer->prop = ivilayer->pending.prop;
826
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000827 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900828 continue;
829 }
830
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000831 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
832 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000833 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000834 wl_list_remove(&ivisurf->order.link);
835 wl_list_init(&ivisurf->order.link);
836 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900837 }
838
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000839 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900840
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000841 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900842 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000843 wl_list_remove(&ivisurf->order.link);
844 wl_list_insert(&ivilayer->order.surface_list,
845 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000846 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000847 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900848 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000849
850 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900851 }
852}
853
854static void
855commit_screen_list(struct ivi_layout *layout)
856{
857 struct ivi_layout_screen *iviscrn = NULL;
858 struct ivi_layout_layer *ivilayer = NULL;
859 struct ivi_layout_layer *next = NULL;
860 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000861 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900862
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900863 /* Clear view list of layout ivi_layer */
864 wl_list_init(&layout->layout_layer.view_list.link);
865
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900866 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000867 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900868 wl_list_for_each_safe(ivilayer, next,
869 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000870 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000871 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900872 wl_list_init(&ivilayer->order.link);
873 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
874 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900875
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000876 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900877
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900878 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
879 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900880 /* FIXME: avoid to insert order.link to multiple screens */
881 wl_list_remove(&ivilayer->order.link);
882
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900883 wl_list_insert(&iviscrn->order.layer_list,
884 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000885 ivilayer->on_screen = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900886 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
887 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900888
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000889 iviscrn->order.dirty = 0;
890 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900891
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900892 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
893 if (ivilayer->prop.visibility == false)
894 continue;
895
896 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900897 if (ivisurf->prop.visibility == false)
898 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000899
900 tmpview = get_weston_view(ivisurf);
901 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900902
903 weston_layer_entry_insert(&layout->layout_layer.view_list,
904 &tmpview->layer_link);
905
906 ivisurf->surface->output = iviscrn->output;
907 }
908 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900909 }
910}
911
912static void
913commit_transition(struct ivi_layout* layout)
914{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300915 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900916 return;
917 }
918
919 wl_list_insert_list(&layout->transitions->transition_list,
920 &layout->pending_transition_list);
921
922 wl_list_init(&layout->pending_transition_list);
923
924 wl_event_source_timer_update(layout->transitions->event_source, 1);
925}
926
927static void
928send_surface_prop(struct ivi_layout_surface *ivisurf)
929{
930 wl_signal_emit(&ivisurf->property_changed, ivisurf);
931 ivisurf->event_mask = 0;
932}
933
934static void
935send_layer_prop(struct ivi_layout_layer *ivilayer)
936{
937 wl_signal_emit(&ivilayer->property_changed, ivilayer);
938 ivilayer->event_mask = 0;
939}
940
941static void
942send_prop(struct ivi_layout *layout)
943{
944 struct ivi_layout_layer *ivilayer = NULL;
945 struct ivi_layout_surface *ivisurf = NULL;
946
947 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900948 if (ivilayer->event_mask)
949 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900950 }
951
952 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900953 if (ivisurf->event_mask)
954 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900955 }
956}
957
958static void
959clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
960{
961 struct ivi_layout_surface *surface_link = NULL;
962 struct ivi_layout_surface *surface_next = NULL;
963
964 wl_list_for_each_safe(surface_link, surface_next,
965 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000966 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900967 wl_list_init(&surface_link->pending.link);
968 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900969}
970
971static void
972clear_surface_order_list(struct ivi_layout_layer *ivilayer)
973{
974 struct ivi_layout_surface *surface_link = NULL;
975 struct ivi_layout_surface *surface_next = NULL;
976
977 wl_list_for_each_safe(surface_link, surface_next,
978 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000979 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900980 wl_list_init(&surface_link->order.link);
981 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900982}
983
984static void
985layer_created(struct wl_listener *listener, void *data)
986{
987 struct ivi_layout_layer *ivilayer = data;
988
989 struct listener_layout_notification *notification =
990 container_of(listener,
991 struct listener_layout_notification,
992 listener);
993
994 struct ivi_layout_notification_callback *created_callback =
995 notification->userdata;
996
997 ((layer_create_notification_func)created_callback->callback)
998 (ivilayer, created_callback->data);
999}
1000
1001static void
1002layer_removed(struct wl_listener *listener, void *data)
1003{
1004 struct ivi_layout_layer *ivilayer = data;
1005
1006 struct listener_layout_notification *notification =
1007 container_of(listener,
1008 struct listener_layout_notification,
1009 listener);
1010
1011 struct ivi_layout_notification_callback *removed_callback =
1012 notification->userdata;
1013
1014 ((layer_remove_notification_func)removed_callback->callback)
1015 (ivilayer, removed_callback->data);
1016}
1017
1018static void
1019layer_prop_changed(struct wl_listener *listener, void *data)
1020{
1021 struct ivi_layout_layer *ivilayer = data;
1022
1023 struct listener_layout_notification *layout_listener =
1024 container_of(listener,
1025 struct listener_layout_notification,
1026 listener);
1027
1028 struct ivi_layout_notification_callback *prop_callback =
1029 layout_listener->userdata;
1030
1031 ((layer_property_notification_func)prop_callback->callback)
1032 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1033}
1034
1035static void
1036surface_created(struct wl_listener *listener, void *data)
1037{
1038 struct ivi_layout_surface *ivisurface = data;
1039
1040 struct listener_layout_notification *notification =
1041 container_of(listener,
1042 struct listener_layout_notification,
1043 listener);
1044
1045 struct ivi_layout_notification_callback *created_callback =
1046 notification->userdata;
1047
1048 ((surface_create_notification_func)created_callback->callback)
1049 (ivisurface, created_callback->data);
1050}
1051
1052static void
1053surface_removed(struct wl_listener *listener, void *data)
1054{
1055 struct ivi_layout_surface *ivisurface = data;
1056
1057 struct listener_layout_notification *notification =
1058 container_of(listener,
1059 struct listener_layout_notification,
1060 listener);
1061
1062 struct ivi_layout_notification_callback *removed_callback =
1063 notification->userdata;
1064
1065 ((surface_remove_notification_func)removed_callback->callback)
1066 (ivisurface, removed_callback->data);
1067}
1068
1069static void
1070surface_prop_changed(struct wl_listener *listener, void *data)
1071{
1072 struct ivi_layout_surface *ivisurf = data;
1073
1074 struct listener_layout_notification *layout_listener =
1075 container_of(listener,
1076 struct listener_layout_notification,
1077 listener);
1078
1079 struct ivi_layout_notification_callback *prop_callback =
1080 layout_listener->userdata;
1081
1082 ((surface_property_notification_func)prop_callback->callback)
1083 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1084
1085 ivisurf->event_mask = 0;
1086}
1087
1088static void
1089surface_configure_changed(struct wl_listener *listener,
1090 void *data)
1091{
1092 struct ivi_layout_surface *ivisurface = data;
1093
1094 struct listener_layout_notification *notification =
1095 container_of(listener,
1096 struct listener_layout_notification,
1097 listener);
1098
1099 struct ivi_layout_notification_callback *configure_changed_callback =
1100 notification->userdata;
1101
1102 ((surface_configure_notification_func)configure_changed_callback->callback)
1103 (ivisurface, configure_changed_callback->data);
1104}
1105
1106static int32_t
1107add_notification(struct wl_signal *signal,
1108 wl_notify_func_t callback,
1109 void *userdata)
1110{
1111 struct listener_layout_notification *notification = NULL;
1112
1113 notification = malloc(sizeof *notification);
1114 if (notification == NULL) {
1115 weston_log("fails to allocate memory\n");
1116 free(userdata);
1117 return IVI_FAILED;
1118 }
1119
1120 notification->listener.notify = callback;
1121 notification->userdata = userdata;
1122
1123 wl_signal_add(signal, &notification->listener);
1124
1125 return IVI_SUCCEEDED;
1126}
1127
1128static void
1129remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1130{
1131 struct wl_listener *listener = NULL;
1132 struct wl_listener *next = NULL;
1133
1134 wl_list_for_each_safe(listener, next, listener_list, link) {
1135 struct listener_layout_notification *notification =
1136 container_of(listener,
1137 struct listener_layout_notification,
1138 listener);
1139
1140 struct ivi_layout_notification_callback *notification_callback =
1141 notification->userdata;
1142
1143 if ((notification_callback->callback != callback) ||
1144 (notification_callback->data != userdata)) {
1145 continue;
1146 }
1147
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001148 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001149
1150 free(notification->userdata);
1151 free(notification);
1152 }
1153}
1154
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001155/**
1156 * Exported APIs of ivi-layout library are implemented from here.
1157 * Brief of APIs is described in ivi-layout-export.h.
1158 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001159static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001160ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1161 void *userdata)
1162{
1163 struct ivi_layout *layout = get_instance();
1164 struct ivi_layout_notification_callback *created_callback = NULL;
1165
1166 if (callback == NULL) {
1167 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1168 return IVI_FAILED;
1169 }
1170
1171 created_callback = malloc(sizeof *created_callback);
1172 if (created_callback == NULL) {
1173 weston_log("fails to allocate memory\n");
1174 return IVI_FAILED;
1175 }
1176
1177 created_callback->callback = callback;
1178 created_callback->data = userdata;
1179
1180 return add_notification(&layout->layer_notification.created,
1181 layer_created,
1182 created_callback);
1183}
1184
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001185static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001186ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1187 void *userdata)
1188{
1189 struct ivi_layout *layout = get_instance();
1190 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1191}
1192
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001193static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001194ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1195 void *userdata)
1196{
1197 struct ivi_layout *layout = get_instance();
1198 struct ivi_layout_notification_callback *removed_callback = NULL;
1199
1200 if (callback == NULL) {
1201 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1202 return IVI_FAILED;
1203 }
1204
1205 removed_callback = malloc(sizeof *removed_callback);
1206 if (removed_callback == NULL) {
1207 weston_log("fails to allocate memory\n");
1208 return IVI_FAILED;
1209 }
1210
1211 removed_callback->callback = callback;
1212 removed_callback->data = userdata;
1213 return add_notification(&layout->layer_notification.removed,
1214 layer_removed,
1215 removed_callback);
1216}
1217
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001218static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001219ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1220 void *userdata)
1221{
1222 struct ivi_layout *layout = get_instance();
1223 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1224}
1225
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001226static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001227ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1228 void *userdata)
1229{
1230 struct ivi_layout *layout = get_instance();
1231 struct ivi_layout_notification_callback *created_callback = NULL;
1232
1233 if (callback == NULL) {
1234 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1235 return IVI_FAILED;
1236 }
1237
1238 created_callback = malloc(sizeof *created_callback);
1239 if (created_callback == NULL) {
1240 weston_log("fails to allocate memory\n");
1241 return IVI_FAILED;
1242 }
1243
1244 created_callback->callback = callback;
1245 created_callback->data = userdata;
1246
1247 return add_notification(&layout->surface_notification.created,
1248 surface_created,
1249 created_callback);
1250}
1251
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001252static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001253ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1254 void *userdata)
1255{
1256 struct ivi_layout *layout = get_instance();
1257 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1258}
1259
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001260static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001261ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1262 void *userdata)
1263{
1264 struct ivi_layout *layout = get_instance();
1265 struct ivi_layout_notification_callback *removed_callback = NULL;
1266
1267 if (callback == NULL) {
1268 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1269 return IVI_FAILED;
1270 }
1271
1272 removed_callback = malloc(sizeof *removed_callback);
1273 if (removed_callback == NULL) {
1274 weston_log("fails to allocate memory\n");
1275 return IVI_FAILED;
1276 }
1277
1278 removed_callback->callback = callback;
1279 removed_callback->data = userdata;
1280
1281 return add_notification(&layout->surface_notification.removed,
1282 surface_removed,
1283 removed_callback);
1284}
1285
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001286static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001287ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1288 void *userdata)
1289{
1290 struct ivi_layout *layout = get_instance();
1291 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1292}
1293
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001294static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001295ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1296 void *userdata)
1297{
1298 struct ivi_layout *layout = get_instance();
1299 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1300 if (callback == NULL) {
1301 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1302 return IVI_FAILED;
1303 }
1304
1305 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1306 if (configure_changed_callback == NULL) {
1307 weston_log("fails to allocate memory\n");
1308 return IVI_FAILED;
1309 }
1310
1311 configure_changed_callback->callback = callback;
1312 configure_changed_callback->data = userdata;
1313
1314 return add_notification(&layout->surface_notification.configure_changed,
1315 surface_configure_changed,
1316 configure_changed_callback);
1317}
1318
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001319static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001320ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1321 void *userdata)
1322{
1323 struct ivi_layout *layout = get_instance();
1324 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1325}
1326
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001327uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001328ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1329{
1330 return ivisurf->id_surface;
1331}
1332
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001333static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001334ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1335{
1336 return ivilayer->id_layer;
1337}
1338
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001339static uint32_t
1340ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1341{
1342 return iviscrn->id_screen;
1343}
1344
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001345static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001346ivi_layout_get_layer_from_id(uint32_t id_layer)
1347{
1348 struct ivi_layout *layout = get_instance();
1349 struct ivi_layout_layer *ivilayer = NULL;
1350
1351 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1352 if (ivilayer->id_layer == id_layer) {
1353 return ivilayer;
1354 }
1355 }
1356
1357 return NULL;
1358}
1359
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001360struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001361ivi_layout_get_surface_from_id(uint32_t id_surface)
1362{
1363 struct ivi_layout *layout = get_instance();
1364 struct ivi_layout_surface *ivisurf = NULL;
1365
1366 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1367 if (ivisurf->id_surface == id_surface) {
1368 return ivisurf;
1369 }
1370 }
1371
1372 return NULL;
1373}
1374
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001375static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001376ivi_layout_get_screen_from_id(uint32_t id_screen)
1377{
1378 struct ivi_layout *layout = get_instance();
1379 struct ivi_layout_screen *iviscrn = NULL;
1380
1381 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Nobuhiko Tanibata3e710d12015-11-25 23:36:09 +09001382 if (iviscrn->id_screen == id_screen)
1383 return iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001384 }
1385
1386 return NULL;
1387}
1388
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001389static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001390ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1391 int32_t *pWidth, int32_t *pHeight)
1392{
1393 struct weston_output *output = NULL;
1394
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001395 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001396 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1397 return IVI_FAILED;
1398 }
1399
1400 output = iviscrn->output;
1401 *pWidth = output->current_mode->width;
1402 *pHeight = output->current_mode->height;
1403
1404 return IVI_SUCCEEDED;
1405}
1406
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001407static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001408ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1409 surface_property_notification_func callback,
1410 void *userdata)
1411{
1412 struct listener_layout_notification* notification = NULL;
1413 struct ivi_layout_notification_callback *prop_callback = NULL;
1414
1415 if (ivisurf == NULL || callback == NULL) {
1416 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1417 return IVI_FAILED;
1418 }
1419
1420 notification = malloc(sizeof *notification);
1421 if (notification == NULL) {
1422 weston_log("fails to allocate memory\n");
1423 return IVI_FAILED;
1424 }
1425
1426 prop_callback = malloc(sizeof *prop_callback);
1427 if (prop_callback == NULL) {
1428 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001429 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001430 return IVI_FAILED;
1431 }
1432
1433 prop_callback->callback = callback;
1434 prop_callback->data = userdata;
1435
1436 notification->listener.notify = surface_prop_changed;
1437 notification->userdata = prop_callback;
1438
1439 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1440
1441 return IVI_SUCCEEDED;
1442}
1443
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001444static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001445ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1446{
1447 if (ivilayer == NULL) {
1448 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1449 return NULL;
1450 }
1451
1452 return &ivilayer->prop;
1453}
1454
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001455static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001456ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1457{
1458 struct ivi_layout *layout = get_instance();
1459 struct ivi_layout_screen *iviscrn = NULL;
1460 int32_t length = 0;
1461 int32_t n = 0;
1462
1463 if (pLength == NULL || ppArray == NULL) {
1464 weston_log("ivi_layout_get_screens: invalid argument\n");
1465 return IVI_FAILED;
1466 }
1467
1468 length = wl_list_length(&layout->screen_list);
1469
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001470 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001471 /* the Array must be free by module which called this function */
1472 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1473 if (*ppArray == NULL) {
1474 weston_log("fails to allocate memory\n");
1475 return IVI_FAILED;
1476 }
1477
1478 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1479 (*ppArray)[n++] = iviscrn;
1480 }
1481 }
1482
1483 *pLength = length;
1484
1485 return IVI_SUCCEEDED;
1486}
1487
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001488static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001489ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1490 int32_t *pLength,
1491 struct ivi_layout_screen ***ppArray)
1492{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001493 int32_t length = 0;
1494 int32_t n = 0;
1495
1496 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1497 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1498 return IVI_FAILED;
1499 }
1500
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001501 if (ivilayer->on_screen != NULL)
1502 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001503
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001504 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001505 /* the Array must be free by module which called this function */
1506 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1507 if (*ppArray == NULL) {
1508 weston_log("fails to allocate memory\n");
1509 return IVI_FAILED;
1510 }
1511
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001512 (*ppArray)[n++] = ivilayer->on_screen;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001513 }
1514
1515 *pLength = length;
1516
1517 return IVI_SUCCEEDED;
1518}
1519
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001520static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001521ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1522{
1523 struct ivi_layout *layout = get_instance();
1524 struct ivi_layout_layer *ivilayer = NULL;
1525 int32_t length = 0;
1526 int32_t n = 0;
1527
1528 if (pLength == NULL || ppArray == NULL) {
1529 weston_log("ivi_layout_get_layers: invalid argument\n");
1530 return IVI_FAILED;
1531 }
1532
1533 length = wl_list_length(&layout->layer_list);
1534
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001535 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001536 /* the Array must be free by module which called this function */
1537 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1538 if (*ppArray == NULL) {
1539 weston_log("fails to allocate memory\n");
1540 return IVI_FAILED;
1541 }
1542
1543 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1544 (*ppArray)[n++] = ivilayer;
1545 }
1546 }
1547
1548 *pLength = length;
1549
1550 return IVI_SUCCEEDED;
1551}
1552
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001553static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001554ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1555 int32_t *pLength,
1556 struct ivi_layout_layer ***ppArray)
1557{
1558 struct ivi_layout_layer *ivilayer = NULL;
1559 int32_t length = 0;
1560 int32_t n = 0;
1561
1562 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1563 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1564 return IVI_FAILED;
1565 }
1566
1567 length = wl_list_length(&iviscrn->order.layer_list);
1568
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001569 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001570 /* the Array must be free by module which called this function */
1571 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1572 if (*ppArray == NULL) {
1573 weston_log("fails to allocate memory\n");
1574 return IVI_FAILED;
1575 }
1576
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001577 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001578 (*ppArray)[n++] = ivilayer;
1579 }
1580 }
1581
1582 *pLength = length;
1583
1584 return IVI_SUCCEEDED;
1585}
1586
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001587static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001588ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1589 int32_t *pLength,
1590 struct ivi_layout_layer ***ppArray)
1591{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001592 int32_t length = 0;
1593 int32_t n = 0;
1594
1595 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1596 weston_log("ivi_layout_getLayers: invalid argument\n");
1597 return IVI_FAILED;
1598 }
1599
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001600 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001601 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001602 length = 1;
1603 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001604 if (*ppArray == NULL) {
1605 weston_log("fails to allocate memory\n");
1606 return IVI_FAILED;
1607 }
1608
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001609 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001610 }
1611
1612 *pLength = length;
1613
1614 return IVI_SUCCEEDED;
1615}
1616
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001617static
1618int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001619ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1620{
1621 struct ivi_layout *layout = get_instance();
1622 struct ivi_layout_surface *ivisurf = NULL;
1623 int32_t length = 0;
1624 int32_t n = 0;
1625
1626 if (pLength == NULL || ppArray == NULL) {
1627 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1628 return IVI_FAILED;
1629 }
1630
1631 length = wl_list_length(&layout->surface_list);
1632
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001633 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001634 /* the Array must be free by module which called this function */
1635 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1636 if (*ppArray == NULL) {
1637 weston_log("fails to allocate memory\n");
1638 return IVI_FAILED;
1639 }
1640
1641 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1642 (*ppArray)[n++] = ivisurf;
1643 }
1644 }
1645
1646 *pLength = length;
1647
1648 return IVI_SUCCEEDED;
1649}
1650
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001651static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001652ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1653 int32_t *pLength,
1654 struct ivi_layout_surface ***ppArray)
1655{
1656 struct ivi_layout_surface *ivisurf = NULL;
1657 int32_t length = 0;
1658 int32_t n = 0;
1659
1660 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1661 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1662 return IVI_FAILED;
1663 }
1664
1665 length = wl_list_length(&ivilayer->order.surface_list);
1666
1667 if (length != 0) {
1668 /* the Array must be free by module which called this function */
1669 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1670 if (*ppArray == NULL) {
1671 weston_log("fails to allocate memory\n");
1672 return IVI_FAILED;
1673 }
1674
1675 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1676 (*ppArray)[n++] = ivisurf;
1677 }
1678 }
1679
1680 *pLength = length;
1681
1682 return IVI_SUCCEEDED;
1683}
1684
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001685static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001686ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1687 int32_t width, int32_t height)
1688{
1689 struct ivi_layout *layout = get_instance();
1690 struct ivi_layout_layer *ivilayer = NULL;
1691
1692 ivilayer = get_layer(&layout->layer_list, id_layer);
1693 if (ivilayer != NULL) {
1694 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001695 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001696 return ivilayer;
1697 }
1698
1699 ivilayer = calloc(1, sizeof *ivilayer);
1700 if (ivilayer == NULL) {
1701 weston_log("fails to allocate memory\n");
1702 return NULL;
1703 }
1704
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001705 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001706 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001707 ivilayer->layout = layout;
1708 ivilayer->id_layer = id_layer;
1709
1710 init_layer_properties(&ivilayer->prop, width, height);
1711 ivilayer->event_mask = 0;
1712
1713 wl_list_init(&ivilayer->pending.surface_list);
1714 wl_list_init(&ivilayer->pending.link);
1715 ivilayer->pending.prop = ivilayer->prop;
1716
1717 wl_list_init(&ivilayer->order.surface_list);
1718 wl_list_init(&ivilayer->order.link);
1719
1720 wl_list_insert(&layout->layer_list, &ivilayer->link);
1721
1722 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1723
1724 return ivilayer;
1725}
1726
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001727static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001728ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1729{
1730 if (ivilayer == NULL) {
1731 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1732 return;
1733 }
1734
1735 remove_all_notification(&ivilayer->property_changed.listener_list);
1736}
1737
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001738static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001739ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1740 layer_property_notification_func callback,
1741 void *userdata)
1742{
1743 if (ivilayer == NULL) {
1744 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1745 return;
1746 }
1747
1748 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1749}
1750
1751static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001752ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001753{
1754 struct ivi_layout *layout = get_instance();
1755
1756 if (ivilayer == NULL) {
1757 weston_log("ivi_layout_layer_remove: invalid argument\n");
1758 return;
1759 }
1760
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001761 if (--ivilayer->ref_count > 0)
1762 return;
1763
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001764 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1765
1766 clear_surface_pending_list(ivilayer);
1767 clear_surface_order_list(ivilayer);
1768
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001769 wl_list_remove(&ivilayer->pending.link);
1770 wl_list_remove(&ivilayer->order.link);
1771 wl_list_remove(&ivilayer->link);
1772
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001773 ivi_layout_layer_remove_notification(ivilayer);
1774
1775 free(ivilayer);
1776}
1777
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001778int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001779ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1780 bool newVisibility)
1781{
1782 struct ivi_layout_layer_properties *prop = NULL;
1783
1784 if (ivilayer == NULL) {
1785 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1786 return IVI_FAILED;
1787 }
1788
1789 prop = &ivilayer->pending.prop;
1790 prop->visibility = newVisibility;
1791
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001792 if (ivilayer->prop.visibility != newVisibility)
1793 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1794 else
1795 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001796
1797 return IVI_SUCCEEDED;
1798}
1799
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001800int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001801ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1802 wl_fixed_t opacity)
1803{
1804 struct ivi_layout_layer_properties *prop = NULL;
1805
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001806 if (ivilayer == NULL ||
1807 opacity < wl_fixed_from_double(0.0) ||
1808 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001809 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1810 return IVI_FAILED;
1811 }
1812
1813 prop = &ivilayer->pending.prop;
1814 prop->opacity = opacity;
1815
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001816 if (ivilayer->prop.opacity != opacity)
1817 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1818 else
1819 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001820
1821 return IVI_SUCCEEDED;
1822}
1823
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001824static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001825ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1826 int32_t x, int32_t y,
1827 int32_t width, int32_t height)
1828{
1829 struct ivi_layout_layer_properties *prop = NULL;
1830
1831 if (ivilayer == NULL) {
1832 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1833 return IVI_FAILED;
1834 }
1835
1836 prop = &ivilayer->pending.prop;
1837 prop->source_x = x;
1838 prop->source_y = y;
1839 prop->source_width = width;
1840 prop->source_height = height;
1841
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001842 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1843 ivilayer->prop.source_width != width ||
1844 ivilayer->prop.source_height != height)
1845 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1846 else
1847 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001848
1849 return IVI_SUCCEEDED;
1850}
1851
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001852int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001853ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1854 int32_t x, int32_t y,
1855 int32_t width, int32_t height)
1856{
1857 struct ivi_layout_layer_properties *prop = NULL;
1858
1859 if (ivilayer == NULL) {
1860 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1861 return IVI_FAILED;
1862 }
1863
1864 prop = &ivilayer->pending.prop;
1865 prop->dest_x = x;
1866 prop->dest_y = y;
1867 prop->dest_width = width;
1868 prop->dest_height = height;
1869
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001870 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1871 ivilayer->prop.dest_width != width ||
1872 ivilayer->prop.dest_height != height)
1873 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1874 else
1875 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001876
1877 return IVI_SUCCEEDED;
1878}
1879
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001880static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001881ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1882 enum wl_output_transform orientation)
1883{
1884 struct ivi_layout_layer_properties *prop = NULL;
1885
1886 if (ivilayer == NULL) {
1887 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1888 return IVI_FAILED;
1889 }
1890
1891 prop = &ivilayer->pending.prop;
1892 prop->orientation = orientation;
1893
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001894 if (ivilayer->prop.orientation != orientation)
1895 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1896 else
1897 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001898
1899 return IVI_SUCCEEDED;
1900}
1901
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001902int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001903ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1904 struct ivi_layout_surface **pSurface,
1905 int32_t number)
1906{
1907 struct ivi_layout *layout = get_instance();
1908 struct ivi_layout_surface *ivisurf = NULL;
1909 struct ivi_layout_surface *next = NULL;
1910 uint32_t *id_surface = NULL;
1911 int32_t i = 0;
1912
1913 if (ivilayer == NULL) {
1914 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1915 return IVI_FAILED;
1916 }
1917
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001918 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001919
1920 for (i = 0; i < number; i++) {
1921 id_surface = &pSurface[i]->id_surface;
1922
1923 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
1924 if (*id_surface != ivisurf->id_surface) {
1925 continue;
1926 }
1927
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001928 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001929 wl_list_insert(&ivilayer->pending.surface_list,
1930 &ivisurf->pending.link);
1931 break;
1932 }
1933 }
1934
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001935 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001936
1937 return IVI_SUCCEEDED;
1938}
1939
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001940int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001941ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1942 bool newVisibility)
1943{
1944 struct ivi_layout_surface_properties *prop = NULL;
1945
1946 if (ivisurf == NULL) {
1947 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1948 return IVI_FAILED;
1949 }
1950
1951 prop = &ivisurf->pending.prop;
1952 prop->visibility = newVisibility;
1953
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001954 if (ivisurf->prop.visibility != newVisibility)
1955 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1956 else
1957 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001958
1959 return IVI_SUCCEEDED;
1960}
1961
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001962int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001963ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1964 wl_fixed_t opacity)
1965{
1966 struct ivi_layout_surface_properties *prop = NULL;
1967
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001968 if (ivisurf == NULL ||
1969 opacity < wl_fixed_from_double(0.0) ||
1970 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001971 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1972 return IVI_FAILED;
1973 }
1974
1975 prop = &ivisurf->pending.prop;
1976 prop->opacity = opacity;
1977
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001978 if (ivisurf->prop.opacity != opacity)
1979 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
1980 else
1981 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001982
1983 return IVI_SUCCEEDED;
1984}
1985
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001986int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001987ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1988 int32_t x, int32_t y,
1989 int32_t width, int32_t height)
1990{
1991 struct ivi_layout_surface_properties *prop = NULL;
1992
1993 if (ivisurf == NULL) {
1994 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1995 return IVI_FAILED;
1996 }
1997
1998 prop = &ivisurf->pending.prop;
1999 prop->start_x = prop->dest_x;
2000 prop->start_y = prop->dest_y;
2001 prop->dest_x = x;
2002 prop->dest_y = y;
2003 prop->start_width = prop->dest_width;
2004 prop->start_height = prop->dest_height;
2005 prop->dest_width = width;
2006 prop->dest_height = height;
2007
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002008 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2009 ivisurf->prop.dest_width != width ||
2010 ivisurf->prop.dest_height != height)
2011 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2012 else
2013 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002014
2015 return IVI_SUCCEEDED;
2016}
2017
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002018static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002019ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2020 enum wl_output_transform orientation)
2021{
2022 struct ivi_layout_surface_properties *prop = NULL;
2023
2024 if (ivisurf == NULL) {
2025 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2026 return IVI_FAILED;
2027 }
2028
2029 prop = &ivisurf->pending.prop;
2030 prop->orientation = orientation;
2031
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002032 if (ivisurf->prop.orientation != orientation)
2033 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2034 else
2035 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002036
2037 return IVI_SUCCEEDED;
2038}
2039
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002040static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002041ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2042 struct ivi_layout_layer *addlayer)
2043{
2044 struct ivi_layout *layout = get_instance();
2045 struct ivi_layout_layer *ivilayer = NULL;
2046 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002047
2048 if (iviscrn == NULL || addlayer == NULL) {
2049 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2050 return IVI_FAILED;
2051 }
2052
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00002053 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002054 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2055 return IVI_SUCCEEDED;
2056 }
2057
2058 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2059 if (ivilayer->id_layer == addlayer->id_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002060 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002061 wl_list_insert(&iviscrn->pending.layer_list,
2062 &ivilayer->pending.link);
2063 break;
2064 }
2065 }
2066
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002067 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002068
2069 return IVI_SUCCEEDED;
2070}
2071
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002072static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002073ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2074 struct ivi_layout_layer **pLayer,
2075 const int32_t number)
2076{
2077 struct ivi_layout *layout = get_instance();
2078 struct ivi_layout_layer *ivilayer = NULL;
2079 struct ivi_layout_layer *next = NULL;
2080 uint32_t *id_layer = NULL;
2081 int32_t i = 0;
2082
2083 if (iviscrn == NULL) {
2084 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2085 return IVI_FAILED;
2086 }
2087
2088 wl_list_for_each_safe(ivilayer, next,
2089 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002090 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002091 wl_list_init(&ivilayer->pending.link);
2092 }
2093
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002094 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002095
2096 for (i = 0; i < number; i++) {
2097 id_layer = &pLayer[i]->id_layer;
2098 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2099 if (*id_layer != ivilayer->id_layer) {
2100 continue;
2101 }
2102
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002103 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002104 wl_list_insert(&iviscrn->pending.layer_list,
2105 &ivilayer->pending.link);
2106 break;
2107 }
2108 }
2109
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002110 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002111
2112 return IVI_SUCCEEDED;
2113}
2114
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002115static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002116ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2117{
2118 return iviscrn->output;
2119}
2120
2121/**
2122 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2123 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2124 * This function is used to get the result of drawing by clients.
2125 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002126static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002127ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2128{
2129 return ivisurf != NULL ? ivisurf->surface : NULL;
2130}
2131
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002132static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002133ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2134 int32_t *width, int32_t *height,
2135 int32_t *stride)
2136{
2137 int32_t w;
2138 int32_t h;
2139 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2140
2141 if (ivisurf == NULL || ivisurf->surface == NULL) {
2142 weston_log("%s: invalid argument\n", __func__);
2143 return IVI_FAILED;
2144 }
2145
2146 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2147
2148 if (width != NULL)
2149 *width = w;
2150
2151 if (height != NULL)
2152 *height = h;
2153
2154 if (stride != NULL)
2155 *stride = w * bytespp;
2156
2157 return IVI_SUCCEEDED;
2158}
2159
2160static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002161ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2162 layer_property_notification_func callback,
2163 void *userdata)
2164{
2165 struct ivi_layout_notification_callback *prop_callback = NULL;
2166
2167 if (ivilayer == NULL || callback == NULL) {
2168 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2169 return IVI_FAILED;
2170 }
2171
2172 prop_callback = malloc(sizeof *prop_callback);
2173 if (prop_callback == NULL) {
2174 weston_log("fails to allocate memory\n");
2175 return IVI_FAILED;
2176 }
2177
2178 prop_callback->callback = callback;
2179 prop_callback->data = userdata;
2180
2181 return add_notification(&ivilayer->property_changed,
2182 layer_prop_changed,
2183 prop_callback);
2184}
2185
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002186static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002187ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2188{
2189 if (ivisurf == NULL) {
2190 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2191 return NULL;
2192 }
2193
2194 return &ivisurf->prop;
2195}
2196
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002197static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002198ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2199 struct ivi_layout_surface *addsurf)
2200{
2201 struct ivi_layout *layout = get_instance();
2202 struct ivi_layout_surface *ivisurf = NULL;
2203 struct ivi_layout_surface *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002204
2205 if (ivilayer == NULL || addsurf == NULL) {
2206 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2207 return IVI_FAILED;
2208 }
2209
Wataru Natsume9c926fe2016-03-03 19:56:09 +09002210 if (addsurf->on_layer == ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002211 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002212
2213 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2214 if (ivisurf->id_surface == addsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002215 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002216 wl_list_insert(&ivilayer->pending.surface_list,
2217 &ivisurf->pending.link);
2218 break;
2219 }
2220 }
2221
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002222 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002223
2224 return IVI_SUCCEEDED;
2225}
2226
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002227static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002228ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2229 struct ivi_layout_surface *remsurf)
2230{
2231 struct ivi_layout_surface *ivisurf = NULL;
2232 struct ivi_layout_surface *next = NULL;
2233
2234 if (ivilayer == NULL || remsurf == NULL) {
2235 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2236 return;
2237 }
2238
2239 wl_list_for_each_safe(ivisurf, next,
2240 &ivilayer->pending.surface_list, pending.link) {
2241 if (ivisurf->id_surface == remsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002242 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002243 wl_list_init(&ivisurf->pending.link);
2244 break;
2245 }
2246 }
2247
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002248 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002249}
2250
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002251static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002252ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2253 int32_t x, int32_t y,
2254 int32_t width, int32_t height)
2255{
2256 struct ivi_layout_surface_properties *prop = NULL;
2257
2258 if (ivisurf == NULL) {
2259 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2260 return IVI_FAILED;
2261 }
2262
2263 prop = &ivisurf->pending.prop;
2264 prop->source_x = x;
2265 prop->source_y = y;
2266 prop->source_width = width;
2267 prop->source_height = height;
2268
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002269 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2270 ivisurf->prop.source_width != width ||
2271 ivisurf->prop.source_height != height)
2272 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2273 else
2274 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002275
2276 return IVI_SUCCEEDED;
2277}
2278
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002279int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002280ivi_layout_commit_changes(void)
2281{
2282 struct ivi_layout *layout = get_instance();
2283
2284 commit_surface_list(layout);
2285 commit_layer_list(layout);
2286 commit_screen_list(layout);
2287
2288 commit_transition(layout);
2289
2290 commit_changes(layout);
2291 send_prop(layout);
2292 weston_compositor_schedule_repaint(layout->compositor);
2293
2294 return IVI_SUCCEEDED;
2295}
2296
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002297static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002298ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2299 enum ivi_layout_transition_type type,
2300 uint32_t duration)
2301{
2302 if (ivilayer == NULL) {
2303 weston_log("%s: invalid argument\n", __func__);
2304 return -1;
2305 }
2306
2307 ivilayer->pending.prop.transition_type = type;
2308 ivilayer->pending.prop.transition_duration = duration;
2309
2310 return 0;
2311}
2312
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002313static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002314ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2315 uint32_t is_fade_in,
2316 double start_alpha, double end_alpha)
2317{
2318 if (ivilayer == NULL) {
2319 weston_log("%s: invalid argument\n", __func__);
2320 return -1;
2321 }
2322
2323 ivilayer->pending.prop.is_fade_in = is_fade_in;
2324 ivilayer->pending.prop.start_alpha = start_alpha;
2325 ivilayer->pending.prop.end_alpha = end_alpha;
2326
2327 return 0;
2328}
2329
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002330static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002331ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2332 uint32_t duration)
2333{
2334 struct ivi_layout_surface_properties *prop;
2335
2336 if (ivisurf == NULL) {
2337 weston_log("%s: invalid argument\n", __func__);
2338 return -1;
2339 }
2340
2341 prop = &ivisurf->pending.prop;
2342 prop->transition_duration = duration*10;
2343 return 0;
2344}
2345
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002346static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002347ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2348 enum ivi_layout_transition_type type,
2349 uint32_t duration)
2350{
2351 struct ivi_layout_surface_properties *prop;
2352
2353 if (ivisurf == NULL) {
2354 weston_log("%s: invalid argument\n", __func__);
2355 return -1;
2356 }
2357
2358 prop = &ivisurf->pending.prop;
2359 prop->transition_type = type;
2360 prop->transition_duration = duration;
2361 return 0;
2362}
2363
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002364static int32_t
2365ivi_layout_surface_dump(struct weston_surface *surface,
2366 void *target, size_t size,int32_t x, int32_t y,
2367 int32_t width, int32_t height)
2368{
2369 int result = 0;
2370
2371 if (surface == NULL) {
2372 weston_log("%s: invalid argument\n", __func__);
2373 return IVI_FAILED;
2374 }
2375
2376 result = weston_surface_copy_content(
2377 surface, target, size,
2378 x, y, width, height);
2379
2380 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2381}
2382
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002383/**
2384 * methods of interaction between ivi-shell with ivi-layout
2385 */
2386struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002387ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2388{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002389 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002390 return NULL;
2391
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002392 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002393}
2394
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002395void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002396ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2397 int32_t width, int32_t height)
2398{
2399 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002400
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002401 /* emit callback which is set by ivi-layout api user */
2402 wl_signal_emit(&layout->surface_notification.configure_changed,
2403 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002404}
2405
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002406struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002407ivi_layout_surface_create(struct weston_surface *wl_surface,
2408 uint32_t id_surface)
2409{
2410 struct ivi_layout *layout = get_instance();
2411 struct ivi_layout_surface *ivisurf = NULL;
2412 struct weston_view *tmpview = NULL;
2413
2414 if (wl_surface == NULL) {
2415 weston_log("ivi_layout_surface_create: invalid argument\n");
2416 return NULL;
2417 }
2418
2419 ivisurf = get_surface(&layout->surface_list, id_surface);
2420 if (ivisurf != NULL) {
2421 if (ivisurf->surface != NULL) {
2422 weston_log("id_surface(%d) is already created\n", id_surface);
2423 return NULL;
2424 }
2425 }
2426
2427 ivisurf = calloc(1, sizeof *ivisurf);
2428 if (ivisurf == NULL) {
2429 weston_log("fails to allocate memory\n");
2430 return NULL;
2431 }
2432
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002433 wl_signal_init(&ivisurf->property_changed);
2434 wl_signal_init(&ivisurf->configured);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002435 ivisurf->id_surface = id_surface;
2436 ivisurf->layout = layout;
2437
2438 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002439
2440 tmpview = weston_view_create(wl_surface);
2441 if (tmpview == NULL) {
2442 weston_log("fails to allocate memory\n");
2443 }
2444
2445 ivisurf->surface->width_from_buffer = 0;
2446 ivisurf->surface->height_from_buffer = 0;
2447
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002448 weston_matrix_init(&ivisurf->transform.matrix);
2449 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002450
2451 init_surface_properties(&ivisurf->prop);
2452 ivisurf->event_mask = 0;
2453
2454 ivisurf->pending.prop = ivisurf->prop;
2455 wl_list_init(&ivisurf->pending.link);
2456
2457 wl_list_init(&ivisurf->order.link);
2458 wl_list_init(&ivisurf->order.layer_list);
2459
2460 wl_list_insert(&layout->surface_list, &ivisurf->link);
2461
2462 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2463
2464 return ivisurf;
2465}
2466
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002467void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002468ivi_layout_init_with_compositor(struct weston_compositor *ec)
2469{
2470 struct ivi_layout *layout = get_instance();
2471
2472 layout->compositor = ec;
2473
2474 wl_list_init(&layout->surface_list);
2475 wl_list_init(&layout->layer_list);
2476 wl_list_init(&layout->screen_list);
2477
2478 wl_signal_init(&layout->layer_notification.created);
2479 wl_signal_init(&layout->layer_notification.removed);
2480
2481 wl_signal_init(&layout->surface_notification.created);
2482 wl_signal_init(&layout->surface_notification.removed);
2483 wl_signal_init(&layout->surface_notification.configure_changed);
2484
2485 /* Add layout_layer at the last of weston_compositor.layer_list */
2486 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2487
2488 create_screen(ec);
2489
2490 layout->transitions = ivi_layout_transition_set_create(ec);
2491 wl_list_init(&layout->pending_transition_list);
2492}
2493
2494
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002495void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002496ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2497 struct wl_listener* listener)
2498{
2499 wl_signal_add(&ivisurf->configured, listener);
2500}
2501
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002502static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002503 /**
2504 * commit all changes
2505 */
2506 .commit_changes = ivi_layout_commit_changes,
2507
2508 /**
2509 * surface controller interfaces
2510 */
2511 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2512 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2513 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2514 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2515 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2516 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2517 .get_surfaces = ivi_layout_get_surfaces,
2518 .get_id_of_surface = ivi_layout_get_id_of_surface,
2519 .get_surface_from_id = ivi_layout_get_surface_from_id,
2520 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2521 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2522 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002523 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002524 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2525 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002526 .surface_set_orientation = ivi_layout_surface_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002527 .surface_add_notification = ivi_layout_surface_add_notification,
2528 .surface_remove_notification = ivi_layout_surface_remove_notification,
2529 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2530 .surface_set_transition = ivi_layout_surface_set_transition,
2531 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2532
2533 /**
2534 * layer controller interfaces
2535 */
2536 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2537 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2538 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2539 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2540 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002541 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002542 .get_layers = ivi_layout_get_layers,
2543 .get_id_of_layer = ivi_layout_get_id_of_layer,
2544 .get_layer_from_id = ivi_layout_get_layer_from_id,
2545 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2546 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2547 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2548 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002549 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002550 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2551 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002552 .layer_set_orientation = ivi_layout_layer_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002553 .layer_add_surface = ivi_layout_layer_add_surface,
2554 .layer_remove_surface = ivi_layout_layer_remove_surface,
2555 .layer_set_render_order = ivi_layout_layer_set_render_order,
2556 .layer_add_notification = ivi_layout_layer_add_notification,
2557 .layer_remove_notification = ivi_layout_layer_remove_notification,
2558 .layer_set_transition = ivi_layout_layer_set_transition,
2559
2560 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002561 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002562 */
2563 .get_screen_from_id = ivi_layout_get_screen_from_id,
2564 .get_screen_resolution = ivi_layout_get_screen_resolution,
2565 .get_screens = ivi_layout_get_screens,
2566 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2567 .screen_add_layer = ivi_layout_screen_add_layer,
2568 .screen_set_render_order = ivi_layout_screen_set_render_order,
2569 .screen_get_output = ivi_layout_screen_get_output,
2570
2571 /**
2572 * animation
2573 */
2574 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002575 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2576
2577 /**
2578 * surface content dumping for debugging
2579 */
2580 .surface_get_size = ivi_layout_surface_get_size,
2581 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002582
2583 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002584 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002585 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002586 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002587 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2588
2589 /**
2590 * screen controller interfaces part2
2591 */
2592 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002593};
2594
2595int
2596load_controller_modules(struct weston_compositor *compositor, const char *modules,
2597 int *argc, char *argv[])
2598{
2599 const char *p, *end;
2600 char buffer[256];
2601 int (*controller_module_init)(struct weston_compositor *compositor,
2602 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002603 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002604 size_t interface_version);
2605
2606 if (modules == NULL)
2607 return 0;
2608
2609 p = modules;
2610 while (*p) {
2611 end = strchrnul(p, ',');
2612 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2613
2614 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002615 if (!controller_module_init)
2616 return -1;
2617
2618 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002619 &ivi_layout_interface,
2620 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002621 weston_log("ivi-shell: Initialization of controller module fails");
2622 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002623 }
2624
2625 p = end;
2626 while (*p == ',')
2627 p++;
2628 }
2629
2630 return 0;
2631}