blob: 61897ef8aa2e59961dc0e9b36ddcd87c21ae8952 [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"
64#include "ivi-layout-export.h"
65#include "ivi-layout-private.h"
66
Jon Cruz867d50e2015-06-15 15:37:10 -070067#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070068#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090069
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +090070#define max(a, b) ((a) > (b) ? (a) : (b))
71
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090072struct listener_layout_notification {
73 void *userdata;
74 struct wl_listener listener;
75};
76
77struct ivi_layout;
78
79struct ivi_layout_screen {
80 struct wl_list link;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090081 uint32_t id_screen;
82
83 struct ivi_layout *layout;
84 struct weston_output *output;
85
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090086 struct {
87 struct wl_list layer_list;
88 struct wl_list link;
89 } pending;
90
91 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +000092 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090093 struct wl_list layer_list;
94 struct wl_list link;
95 } order;
96};
97
98struct ivi_layout_notification_callback {
99 void *callback;
100 void *data;
101};
102
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900103struct ivi_rectangle
104{
105 int32_t x;
106 int32_t y;
107 int32_t width;
108 int32_t height;
109};
110
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900111static void
112remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
113
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900114static struct ivi_layout ivilayout = {0};
115
116struct ivi_layout *
117get_instance(void)
118{
119 return &ivilayout;
120}
121
122/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900123 * Internal API to add/remove a ivi_layer to/from ivi_screen.
124 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900125static struct ivi_layout_surface *
126get_surface(struct wl_list *surf_list, uint32_t id_surface)
127{
128 struct ivi_layout_surface *ivisurf;
129
130 wl_list_for_each(ivisurf, surf_list, link) {
131 if (ivisurf->id_surface == id_surface) {
132 return ivisurf;
133 }
134 }
135
136 return NULL;
137}
138
139static struct ivi_layout_layer *
140get_layer(struct wl_list *layer_list, uint32_t id_layer)
141{
142 struct ivi_layout_layer *ivilayer;
143
144 wl_list_for_each(ivilayer, layer_list, link) {
145 if (ivilayer->id_layer == id_layer) {
146 return ivilayer;
147 }
148 }
149
150 return NULL;
151}
152
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000153static struct weston_view *
154get_weston_view(struct ivi_layout_surface *ivisurf)
155{
156 struct weston_view *view = NULL;
157
158 assert(ivisurf->surface != NULL);
159
160 /* One view per surface */
161 if(wl_list_empty(&ivisurf->surface->views))
162 view = NULL;
163 else
164 view = wl_container_of(ivisurf->surface->views.next, view, surface_link);
165
166 return view;
167}
168
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900169static void
170remove_configured_listener(struct ivi_layout_surface *ivisurf)
171{
172 struct wl_listener *link = NULL;
173 struct wl_listener *next = NULL;
174
175 wl_list_for_each_safe(link, next, &ivisurf->configured.listener_list, link) {
176 wl_list_remove(&link->link);
177 }
178}
179
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900180static void
181remove_all_notification(struct wl_list *listener_list)
182{
183 struct wl_listener *listener = NULL;
184 struct wl_listener *next = NULL;
185
186 wl_list_for_each_safe(listener, next, listener_list, link) {
187 struct listener_layout_notification *notification = NULL;
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000188 wl_list_remove(&listener->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900189
190 notification =
191 container_of(listener,
192 struct listener_layout_notification,
193 listener);
194
195 free(notification->userdata);
196 free(notification);
197 }
198}
199
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900200static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900201ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
202{
203 if (ivisurf == NULL) {
204 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
205 return;
206 }
207
208 remove_all_notification(&ivisurf->property_changed.listener_list);
209}
210
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900211static void
212ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
213 surface_property_notification_func callback,
214 void *userdata)
215{
216 if (ivisurf == NULL) {
217 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
218 return;
219 }
220
221 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
222}
223
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900224/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900225 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900226 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900227void
228ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900229{
230 struct ivi_layout *layout = get_instance();
231
232 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900233 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900234 return;
235 }
236
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900237 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900238 wl_list_remove(&ivisurf->pending.link);
239 wl_list_remove(&ivisurf->order.link);
240 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900241
242 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
243
Mateusz Polroladada6e32016-03-09 09:13:26 +0000244 ivi_layout_remove_all_surface_transitions(ivisurf);
245
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900246 remove_configured_listener(ivisurf);
247
248 ivi_layout_surface_remove_notification(ivisurf);
249
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900250 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900251}
252
253/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900254 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
255 * Called by ivi_layout_init_with_compositor.
256 */
257static void
258create_screen(struct weston_compositor *ec)
259{
260 struct ivi_layout *layout = get_instance();
261 struct ivi_layout_screen *iviscrn = NULL;
262 struct weston_output *output = NULL;
263 int32_t count = 0;
264
265 wl_list_for_each(output, &ec->output_list, link) {
266 iviscrn = calloc(1, sizeof *iviscrn);
267 if (iviscrn == NULL) {
268 weston_log("fails to allocate memory\n");
269 continue;
270 }
271
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900272 iviscrn->layout = layout;
273
274 iviscrn->id_screen = count;
275 count++;
276
277 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900278
279 wl_list_init(&iviscrn->pending.layer_list);
280 wl_list_init(&iviscrn->pending.link);
281
282 wl_list_init(&iviscrn->order.layer_list);
283 wl_list_init(&iviscrn->order.link);
284
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900285 wl_list_insert(&layout->screen_list, &iviscrn->link);
286 }
287}
288
289/**
290 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
291 */
292static void
293init_layer_properties(struct ivi_layout_layer_properties *prop,
294 int32_t width, int32_t height)
295{
296 memset(prop, 0, sizeof *prop);
297 prop->opacity = wl_fixed_from_double(1.0);
298 prop->source_width = width;
299 prop->source_height = height;
300 prop->dest_width = width;
301 prop->dest_height = height;
302}
303
304static void
305init_surface_properties(struct ivi_layout_surface_properties *prop)
306{
307 memset(prop, 0, sizeof *prop);
308 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900309 /*
310 * FIXME: this shall be finxed by ivi-layout-transition.
311 */
312 prop->dest_width = 1;
313 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900314}
315
316/**
317 * Internal APIs to be called from ivi_layout_commit_changes.
318 */
319static void
320update_opacity(struct ivi_layout_layer *ivilayer,
321 struct ivi_layout_surface *ivisurf)
322{
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000323 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900324 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
325 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
326
Nobuhiko Tanibata90c27892015-12-26 23:52:51 +0900327 tmpview = get_weston_view(ivisurf);
328 assert(tmpview != NULL);
329 tmpview->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900330}
331
332static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900333get_rotate_values(enum wl_output_transform orientation,
334 float *v_sin,
335 float *v_cos)
336{
337 switch (orientation) {
338 case WL_OUTPUT_TRANSFORM_90:
339 *v_sin = 1.0f;
340 *v_cos = 0.0f;
341 break;
342 case WL_OUTPUT_TRANSFORM_180:
343 *v_sin = 0.0f;
344 *v_cos = -1.0f;
345 break;
346 case WL_OUTPUT_TRANSFORM_270:
347 *v_sin = -1.0f;
348 *v_cos = 0.0f;
349 break;
350 case WL_OUTPUT_TRANSFORM_NORMAL:
351 default:
352 *v_sin = 0.0f;
353 *v_cos = 1.0f;
354 break;
355 }
356}
357
358static void
359get_scale(enum wl_output_transform orientation,
360 float dest_width,
361 float dest_height,
362 float source_width,
363 float source_height,
364 float *scale_x,
365 float *scale_y)
366{
367 switch (orientation) {
368 case WL_OUTPUT_TRANSFORM_90:
369 *scale_x = dest_width / source_height;
370 *scale_y = dest_height / source_width;
371 break;
372 case WL_OUTPUT_TRANSFORM_180:
373 *scale_x = dest_width / source_width;
374 *scale_y = dest_height / source_height;
375 break;
376 case WL_OUTPUT_TRANSFORM_270:
377 *scale_x = dest_width / source_height;
378 *scale_y = dest_height / source_width;
379 break;
380 case WL_OUTPUT_TRANSFORM_NORMAL:
381 default:
382 *scale_x = dest_width / source_width;
383 *scale_y = dest_height / source_height;
384 break;
385 }
386}
387
388static void
389calc_transformation_matrix(struct ivi_rectangle *source_rect,
390 struct ivi_rectangle *dest_rect,
391 enum wl_output_transform orientation,
392 struct weston_matrix *m)
393{
394 float source_center_x;
395 float source_center_y;
396 float vsin;
397 float vcos;
398 float scale_x;
399 float scale_y;
400 float translate_x;
401 float translate_y;
402
403 source_center_x = source_rect->x + source_rect->width * 0.5f;
404 source_center_y = source_rect->y + source_rect->height * 0.5f;
405 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
406
407 get_rotate_values(orientation, &vsin, &vcos);
408 weston_matrix_rotate_xy(m, vcos, vsin);
409
410 get_scale(orientation,
411 dest_rect->width,
412 dest_rect->height,
413 source_rect->width,
414 source_rect->height,
415 &scale_x,
416 &scale_y);
417 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
418
419 translate_x = dest_rect->width * 0.5f + dest_rect->x;
420 translate_y = dest_rect->height * 0.5f + dest_rect->y;
421 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
422}
423
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900424/*
425 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900426 */
427static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900428ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
429 const struct ivi_rectangle *rect2,
430 struct ivi_rectangle *rect_output)
431{
432 int32_t rect1_right = rect1->x + rect1->width;
433 int32_t rect1_bottom = rect1->y + rect1->height;
434 int32_t rect2_right = rect2->x + rect2->width;
435 int32_t rect2_bottom = rect2->y + rect2->height;
436
437 rect_output->x = max(rect1->x, rect2->x);
438 rect_output->y = max(rect1->y, rect2->y);
439 rect_output->width = rect1_right < rect2_right ?
440 rect1_right - rect_output->x :
441 rect2_right - rect_output->x;
442 rect_output->height = rect1_bottom < rect2_bottom ?
443 rect1_bottom - rect_output->y :
444 rect2_bottom - rect_output->y;
445
446 if (rect_output->width < 0 || rect_output->height < 0) {
447 rect_output->width = 0;
448 rect_output->height = 0;
449 }
450}
451
452/*
453 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
454 * and store the result in rect_output.
455 * The boundingbox must be given in the same coordinate space as rect_output.
456 * Additionally, there are the following restrictions on the matrix:
457 * - no projective transformations
458 * - no skew
459 * - only multiples of 90-degree rotations supported
460 *
461 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
462 * as a fail-safe with log.
463 */
464static void
465calc_inverse_matrix_transform(const struct weston_matrix *matrix,
466 const struct ivi_rectangle *rect_input,
467 const struct ivi_rectangle *boundingbox,
468 struct ivi_rectangle *rect_output)
469{
470 struct weston_matrix m;
471 struct weston_vector top_left;
472 struct weston_vector bottom_right;
473
474 assert(boundingbox != rect_output);
475
476 if (weston_matrix_invert(&m, matrix) < 0) {
477 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
478 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
479 rect_output->x = boundingbox->x;
480 rect_output->y = boundingbox->y;
481 rect_output->width = boundingbox->width;
482 rect_output->height = boundingbox->height;
483 }
484
485 /* The vectors and matrices involved will always produce f[3] == 1.0. */
486 top_left.f[0] = rect_input->x;
487 top_left.f[1] = rect_input->y;
488 top_left.f[2] = 0.0f;
489 top_left.f[3] = 1.0f;
490
491 bottom_right.f[0] = rect_input->x + rect_input->width;
492 bottom_right.f[1] = rect_input->y + rect_input->height;
493 bottom_right.f[2] = 0.0f;
494 bottom_right.f[3] = 1.0f;
495
496 weston_matrix_transform(&m, &top_left);
497 weston_matrix_transform(&m, &bottom_right);
498
499 if (top_left.f[0] < bottom_right.f[0]) {
500 rect_output->x = top_left.f[0];
501 rect_output->width = bottom_right.f[0] - rect_output->x;
502 } else {
503 rect_output->x = bottom_right.f[0];
504 rect_output->width = top_left.f[0] - rect_output->x;
505 }
506
507 if (top_left.f[1] < bottom_right.f[1]) {
508 rect_output->y = top_left.f[1];
509 rect_output->height = bottom_right.f[1] - rect_output->y;
510 } else {
511 rect_output->y = bottom_right.f[1];
512 rect_output->height = top_left.f[1] - rect_output->y;
513 }
514
515 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
516}
517
518/**
519 * This computes the whole transformation matrix:m from surface-local
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900520 * coordinates to multi screens coordinate, which is global coordinates.
521 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900522 *
523 * Additionally, this computes the mask on surface-local coordinates as a
524 * ivi_rectangle. This can be set to weston_view_set_mask.
525 *
526 * The mask is computed by following steps
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900527 * - destination rectangle of layer is tansformed to multi screen coordinate,
528 * global coordinates. This is done by adding weston_output.{x,y} in simple
529 * because there is no scaled and rotated transformation.
530 * - destination rectangle of layer in multi screens coordinate needs to be
531 * intersected inside of a screen the layer is assigned to. This is because
532 * overlapped region of weston surface in another screen shall not be
533 * displayed according to ivi use case.
534 * - destination rectangle of layer
535 * - in multi screen coordinates,
536 * - and intersected inside of an assigned screen,
537 * is inversed to surface-local cooodinates by inversed matrix:m.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900538 * - the area is intersected by intersected area between weston_surface and
539 * source rectangle of ivi_surface.
540 */
541static void
542calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900543 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900544 struct ivi_layout_layer *ivilayer,
545 struct ivi_layout_surface *ivisurf,
546 struct weston_matrix *m,
547 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900548{
549 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
550 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900551 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900552 struct ivi_rectangle weston_surface_rect = { 0,
553 0,
554 ivisurf->surface->width,
555 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900556 struct ivi_rectangle surface_source_rect = { sp->source_x,
557 sp->source_y,
558 sp->source_width,
559 sp->source_height };
560 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
561 sp->dest_y,
562 sp->dest_width,
563 sp->dest_height };
564 struct ivi_rectangle layer_source_rect = { lp->source_x,
565 lp->source_y,
566 lp->source_width,
567 lp->source_height };
568 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
569 lp->dest_y,
570 lp->dest_width,
571 lp->dest_height };
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900572 struct ivi_rectangle screen_dest_rect = { output->x,
573 output->y,
574 output->width,
575 output->height };
576 struct ivi_rectangle layer_dest_rect_in_global =
577 { lp->dest_x + output->x,
578 lp->dest_y + output->y,
579 lp->dest_width,
580 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900581 struct ivi_rectangle surface_result;
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900582 struct ivi_rectangle layer_dest_rect_in_global_intersected;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900583
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900584 /*
585 * the whole transformation matrix:m from surface-local
586 * coordinates to global coordinates, which is computed by
587 * two steps,
588 * - surface-local coordinates to layer-local coordinates
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900589 * - layer-local coordinates to a single screen-local coordinates
590 * - a single screen-local coordinates to multi screen coordinates,
591 * which is global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900592 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900593 calc_transformation_matrix(&surface_source_rect,
594 &surface_dest_rect,
595 sp->orientation, m);
596
597 calc_transformation_matrix(&layer_source_rect,
598 &layer_dest_rect,
599 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900600
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900601 weston_matrix_translate(m, output->x, output->y, 0.0f);
602
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900603 /* this intersected ivi_rectangle would be used for masking
604 * weston_surface
605 */
606 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
607 &surface_result);
608
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900609 /*
610 * destination rectangle of layer in multi screens coordinate
611 * is intersected to avoid displaying outside of an assigned screen.
612 */
613 ivi_rectangle_intersect(&layer_dest_rect_in_global, &screen_dest_rect,
614 &layer_dest_rect_in_global_intersected);
615
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900616 /* calc masking area of weston_surface from m */
617 calc_inverse_matrix_transform(m,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900618 &layer_dest_rect_in_global_intersected,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900619 &surface_result,
620 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900621}
622
623static void
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900624update_prop(struct ivi_layout_screen *iviscrn,
625 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900626 struct ivi_layout_surface *ivisurf)
627{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900628 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900629 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900630 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900631
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900632 /*In case of no prop change, this just returns*/
633 if (!ivilayer->event_mask && !ivisurf->event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900634 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900635
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900636 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900637
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000638 tmpview = get_weston_view(ivisurf);
639 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900640
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900641 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
642 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
643 can_calc = false;
644 }
645
646 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
647 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
648 can_calc = false;
649 }
650
651 if (can_calc) {
652 wl_list_remove(&ivisurf->transform.link);
653 weston_matrix_init(&ivisurf->transform.matrix);
654
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900655 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900656 iviscrn, ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900657
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000658 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
659 wl_list_insert(&tmpview->geometry.transformation_list,
660 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900661
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000662 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900663 }
664
665 ivisurf->update_count++;
666
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000667 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900668
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000669 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900670}
671
672static void
673commit_changes(struct ivi_layout *layout)
674{
675 struct ivi_layout_screen *iviscrn = NULL;
676 struct ivi_layout_layer *ivilayer = NULL;
677 struct ivi_layout_surface *ivisurf = NULL;
678
679 wl_list_for_each(iviscrn, &layout->screen_list, link) {
680 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900681 /*
682 * If ivilayer is invisible, weston_view of ivisurf doesn't
683 * need to be modified.
684 */
685 if (ivilayer->prop.visibility == false)
686 continue;
687
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900688 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900689 /*
690 * If ivilayer is invisible, weston_view of ivisurf doesn't
691 * need to be modified.
692 */
693 if (ivisurf->prop.visibility == false)
694 continue;
695
696 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900697 }
698 }
699 }
700}
701
702static void
703commit_surface_list(struct ivi_layout *layout)
704{
705 struct ivi_layout_surface *ivisurf = NULL;
706 int32_t dest_x = 0;
707 int32_t dest_y = 0;
708 int32_t dest_width = 0;
709 int32_t dest_height = 0;
710 int32_t configured = 0;
711
712 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300713 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900714 dest_x = ivisurf->prop.dest_x;
715 dest_y = ivisurf->prop.dest_y;
716 dest_width = ivisurf->prop.dest_width;
717 dest_height = ivisurf->prop.dest_height;
718
719 ivi_layout_transition_move_resize_view(ivisurf,
720 ivisurf->pending.prop.dest_x,
721 ivisurf->pending.prop.dest_y,
722 ivisurf->pending.prop.dest_width,
723 ivisurf->pending.prop.dest_height,
724 ivisurf->pending.prop.transition_duration);
725
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300726 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900727 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
728 } else {
729 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
730 }
731
732 ivisurf->prop = ivisurf->pending.prop;
733 ivisurf->prop.dest_x = dest_x;
734 ivisurf->prop.dest_y = dest_y;
735 ivisurf->prop.dest_width = dest_width;
736 ivisurf->prop.dest_height = dest_height;
737 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
738 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
739
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300740 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900741 dest_x = ivisurf->prop.dest_x;
742 dest_y = ivisurf->prop.dest_y;
743 dest_width = ivisurf->prop.dest_width;
744 dest_height = ivisurf->prop.dest_height;
745
746 ivi_layout_transition_move_resize_view(ivisurf,
747 ivisurf->pending.prop.dest_x,
748 ivisurf->pending.prop.dest_y,
749 ivisurf->pending.prop.dest_width,
750 ivisurf->pending.prop.dest_height,
751 ivisurf->pending.prop.transition_duration);
752
753 ivisurf->prop = ivisurf->pending.prop;
754 ivisurf->prop.dest_x = dest_x;
755 ivisurf->prop.dest_y = dest_y;
756 ivisurf->prop.dest_width = dest_width;
757 ivisurf->prop.dest_height = dest_height;
758
759 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
760 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
761
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300762 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900763 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300764 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900765 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
766 } else {
767 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
768 }
769
770 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
771 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
772 configured = 1;
773 }
774
775 ivisurf->prop = ivisurf->pending.prop;
776 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
777 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
778
779 if (configured && !is_surface_transition(ivisurf))
780 wl_signal_emit(&ivisurf->configured, ivisurf);
781 } else {
782 configured = 0;
783 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
784 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
785 configured = 1;
786 }
787
788 ivisurf->prop = ivisurf->pending.prop;
789 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
790 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
791
792 if (configured && !is_surface_transition(ivisurf))
793 wl_signal_emit(&ivisurf->configured, ivisurf);
794 }
795 }
796}
797
798static void
799commit_layer_list(struct ivi_layout *layout)
800{
801 struct ivi_layout_layer *ivilayer = NULL;
802 struct ivi_layout_surface *ivisurf = NULL;
803 struct ivi_layout_surface *next = NULL;
804
805 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300806 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900807 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 -0300808 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900809 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
810 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
811 NULL, NULL,
812 ivilayer->pending.prop.transition_duration);
813 }
814 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
815
816 ivilayer->prop = ivilayer->pending.prop;
817
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000818 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900819 continue;
820 }
821
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000822 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
823 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000824 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000825 wl_list_remove(&ivisurf->order.link);
826 wl_list_init(&ivisurf->order.link);
827 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900828 }
829
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000830 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900831
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000832 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900833 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000834 wl_list_remove(&ivisurf->order.link);
835 wl_list_insert(&ivilayer->order.surface_list,
836 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000837 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000838 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900839 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000840
841 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900842 }
843}
844
845static void
846commit_screen_list(struct ivi_layout *layout)
847{
848 struct ivi_layout_screen *iviscrn = NULL;
849 struct ivi_layout_layer *ivilayer = NULL;
850 struct ivi_layout_layer *next = NULL;
851 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000852 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900853
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900854 /* Clear view list of layout ivi_layer */
855 wl_list_init(&layout->layout_layer.view_list.link);
856
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900857 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000858 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900859 wl_list_for_each_safe(ivilayer, next,
860 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000861 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000862 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900863 wl_list_init(&ivilayer->order.link);
864 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
865 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900866
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000867 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900868
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900869 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
870 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900871 /* FIXME: avoid to insert order.link to multiple screens */
872 wl_list_remove(&ivilayer->order.link);
873
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900874 wl_list_insert(&iviscrn->order.layer_list,
875 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000876 ivilayer->on_screen = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900877 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
878 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900879
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000880 iviscrn->order.dirty = 0;
881 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900882
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900883 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
884 if (ivilayer->prop.visibility == false)
885 continue;
886
887 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900888 if (ivisurf->prop.visibility == false)
889 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000890
891 tmpview = get_weston_view(ivisurf);
892 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900893
894 weston_layer_entry_insert(&layout->layout_layer.view_list,
895 &tmpview->layer_link);
896
897 ivisurf->surface->output = iviscrn->output;
898 }
899 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900900 }
901}
902
903static void
904commit_transition(struct ivi_layout* layout)
905{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300906 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900907 return;
908 }
909
910 wl_list_insert_list(&layout->transitions->transition_list,
911 &layout->pending_transition_list);
912
913 wl_list_init(&layout->pending_transition_list);
914
915 wl_event_source_timer_update(layout->transitions->event_source, 1);
916}
917
918static void
919send_surface_prop(struct ivi_layout_surface *ivisurf)
920{
921 wl_signal_emit(&ivisurf->property_changed, ivisurf);
922 ivisurf->event_mask = 0;
923}
924
925static void
926send_layer_prop(struct ivi_layout_layer *ivilayer)
927{
928 wl_signal_emit(&ivilayer->property_changed, ivilayer);
929 ivilayer->event_mask = 0;
930}
931
932static void
933send_prop(struct ivi_layout *layout)
934{
935 struct ivi_layout_layer *ivilayer = NULL;
936 struct ivi_layout_surface *ivisurf = NULL;
937
938 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900939 if (ivilayer->event_mask)
940 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900941 }
942
943 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900944 if (ivisurf->event_mask)
945 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900946 }
947}
948
949static void
950clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
951{
952 struct ivi_layout_surface *surface_link = NULL;
953 struct ivi_layout_surface *surface_next = NULL;
954
955 wl_list_for_each_safe(surface_link, surface_next,
956 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000957 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900958 wl_list_init(&surface_link->pending.link);
959 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900960}
961
962static void
963clear_surface_order_list(struct ivi_layout_layer *ivilayer)
964{
965 struct ivi_layout_surface *surface_link = NULL;
966 struct ivi_layout_surface *surface_next = NULL;
967
968 wl_list_for_each_safe(surface_link, surface_next,
969 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000970 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900971 wl_list_init(&surface_link->order.link);
972 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900973}
974
975static void
976layer_created(struct wl_listener *listener, void *data)
977{
978 struct ivi_layout_layer *ivilayer = data;
979
980 struct listener_layout_notification *notification =
981 container_of(listener,
982 struct listener_layout_notification,
983 listener);
984
985 struct ivi_layout_notification_callback *created_callback =
986 notification->userdata;
987
988 ((layer_create_notification_func)created_callback->callback)
989 (ivilayer, created_callback->data);
990}
991
992static void
993layer_removed(struct wl_listener *listener, void *data)
994{
995 struct ivi_layout_layer *ivilayer = data;
996
997 struct listener_layout_notification *notification =
998 container_of(listener,
999 struct listener_layout_notification,
1000 listener);
1001
1002 struct ivi_layout_notification_callback *removed_callback =
1003 notification->userdata;
1004
1005 ((layer_remove_notification_func)removed_callback->callback)
1006 (ivilayer, removed_callback->data);
1007}
1008
1009static void
1010layer_prop_changed(struct wl_listener *listener, void *data)
1011{
1012 struct ivi_layout_layer *ivilayer = data;
1013
1014 struct listener_layout_notification *layout_listener =
1015 container_of(listener,
1016 struct listener_layout_notification,
1017 listener);
1018
1019 struct ivi_layout_notification_callback *prop_callback =
1020 layout_listener->userdata;
1021
1022 ((layer_property_notification_func)prop_callback->callback)
1023 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1024}
1025
1026static void
1027surface_created(struct wl_listener *listener, void *data)
1028{
1029 struct ivi_layout_surface *ivisurface = data;
1030
1031 struct listener_layout_notification *notification =
1032 container_of(listener,
1033 struct listener_layout_notification,
1034 listener);
1035
1036 struct ivi_layout_notification_callback *created_callback =
1037 notification->userdata;
1038
1039 ((surface_create_notification_func)created_callback->callback)
1040 (ivisurface, created_callback->data);
1041}
1042
1043static void
1044surface_removed(struct wl_listener *listener, void *data)
1045{
1046 struct ivi_layout_surface *ivisurface = data;
1047
1048 struct listener_layout_notification *notification =
1049 container_of(listener,
1050 struct listener_layout_notification,
1051 listener);
1052
1053 struct ivi_layout_notification_callback *removed_callback =
1054 notification->userdata;
1055
1056 ((surface_remove_notification_func)removed_callback->callback)
1057 (ivisurface, removed_callback->data);
1058}
1059
1060static void
1061surface_prop_changed(struct wl_listener *listener, void *data)
1062{
1063 struct ivi_layout_surface *ivisurf = data;
1064
1065 struct listener_layout_notification *layout_listener =
1066 container_of(listener,
1067 struct listener_layout_notification,
1068 listener);
1069
1070 struct ivi_layout_notification_callback *prop_callback =
1071 layout_listener->userdata;
1072
1073 ((surface_property_notification_func)prop_callback->callback)
1074 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1075
1076 ivisurf->event_mask = 0;
1077}
1078
1079static void
1080surface_configure_changed(struct wl_listener *listener,
1081 void *data)
1082{
1083 struct ivi_layout_surface *ivisurface = data;
1084
1085 struct listener_layout_notification *notification =
1086 container_of(listener,
1087 struct listener_layout_notification,
1088 listener);
1089
1090 struct ivi_layout_notification_callback *configure_changed_callback =
1091 notification->userdata;
1092
1093 ((surface_configure_notification_func)configure_changed_callback->callback)
1094 (ivisurface, configure_changed_callback->data);
1095}
1096
1097static int32_t
1098add_notification(struct wl_signal *signal,
1099 wl_notify_func_t callback,
1100 void *userdata)
1101{
1102 struct listener_layout_notification *notification = NULL;
1103
1104 notification = malloc(sizeof *notification);
1105 if (notification == NULL) {
1106 weston_log("fails to allocate memory\n");
1107 free(userdata);
1108 return IVI_FAILED;
1109 }
1110
1111 notification->listener.notify = callback;
1112 notification->userdata = userdata;
1113
1114 wl_signal_add(signal, &notification->listener);
1115
1116 return IVI_SUCCEEDED;
1117}
1118
1119static void
1120remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1121{
1122 struct wl_listener *listener = NULL;
1123 struct wl_listener *next = NULL;
1124
1125 wl_list_for_each_safe(listener, next, listener_list, link) {
1126 struct listener_layout_notification *notification =
1127 container_of(listener,
1128 struct listener_layout_notification,
1129 listener);
1130
1131 struct ivi_layout_notification_callback *notification_callback =
1132 notification->userdata;
1133
1134 if ((notification_callback->callback != callback) ||
1135 (notification_callback->data != userdata)) {
1136 continue;
1137 }
1138
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001139 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001140
1141 free(notification->userdata);
1142 free(notification);
1143 }
1144}
1145
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001146/**
1147 * Exported APIs of ivi-layout library are implemented from here.
1148 * Brief of APIs is described in ivi-layout-export.h.
1149 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001150static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001151ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1152 void *userdata)
1153{
1154 struct ivi_layout *layout = get_instance();
1155 struct ivi_layout_notification_callback *created_callback = NULL;
1156
1157 if (callback == NULL) {
1158 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1159 return IVI_FAILED;
1160 }
1161
1162 created_callback = malloc(sizeof *created_callback);
1163 if (created_callback == NULL) {
1164 weston_log("fails to allocate memory\n");
1165 return IVI_FAILED;
1166 }
1167
1168 created_callback->callback = callback;
1169 created_callback->data = userdata;
1170
1171 return add_notification(&layout->layer_notification.created,
1172 layer_created,
1173 created_callback);
1174}
1175
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001176static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001177ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1178 void *userdata)
1179{
1180 struct ivi_layout *layout = get_instance();
1181 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1182}
1183
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001184static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001185ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1186 void *userdata)
1187{
1188 struct ivi_layout *layout = get_instance();
1189 struct ivi_layout_notification_callback *removed_callback = NULL;
1190
1191 if (callback == NULL) {
1192 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1193 return IVI_FAILED;
1194 }
1195
1196 removed_callback = malloc(sizeof *removed_callback);
1197 if (removed_callback == NULL) {
1198 weston_log("fails to allocate memory\n");
1199 return IVI_FAILED;
1200 }
1201
1202 removed_callback->callback = callback;
1203 removed_callback->data = userdata;
1204 return add_notification(&layout->layer_notification.removed,
1205 layer_removed,
1206 removed_callback);
1207}
1208
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001209static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001210ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1211 void *userdata)
1212{
1213 struct ivi_layout *layout = get_instance();
1214 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1215}
1216
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001217static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001218ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1219 void *userdata)
1220{
1221 struct ivi_layout *layout = get_instance();
1222 struct ivi_layout_notification_callback *created_callback = NULL;
1223
1224 if (callback == NULL) {
1225 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1226 return IVI_FAILED;
1227 }
1228
1229 created_callback = malloc(sizeof *created_callback);
1230 if (created_callback == NULL) {
1231 weston_log("fails to allocate memory\n");
1232 return IVI_FAILED;
1233 }
1234
1235 created_callback->callback = callback;
1236 created_callback->data = userdata;
1237
1238 return add_notification(&layout->surface_notification.created,
1239 surface_created,
1240 created_callback);
1241}
1242
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001243static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001244ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1245 void *userdata)
1246{
1247 struct ivi_layout *layout = get_instance();
1248 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1249}
1250
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001251static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001252ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1253 void *userdata)
1254{
1255 struct ivi_layout *layout = get_instance();
1256 struct ivi_layout_notification_callback *removed_callback = NULL;
1257
1258 if (callback == NULL) {
1259 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1260 return IVI_FAILED;
1261 }
1262
1263 removed_callback = malloc(sizeof *removed_callback);
1264 if (removed_callback == NULL) {
1265 weston_log("fails to allocate memory\n");
1266 return IVI_FAILED;
1267 }
1268
1269 removed_callback->callback = callback;
1270 removed_callback->data = userdata;
1271
1272 return add_notification(&layout->surface_notification.removed,
1273 surface_removed,
1274 removed_callback);
1275}
1276
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001277static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001278ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1279 void *userdata)
1280{
1281 struct ivi_layout *layout = get_instance();
1282 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1283}
1284
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001285static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001286ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1287 void *userdata)
1288{
1289 struct ivi_layout *layout = get_instance();
1290 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1291 if (callback == NULL) {
1292 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1293 return IVI_FAILED;
1294 }
1295
1296 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1297 if (configure_changed_callback == NULL) {
1298 weston_log("fails to allocate memory\n");
1299 return IVI_FAILED;
1300 }
1301
1302 configure_changed_callback->callback = callback;
1303 configure_changed_callback->data = userdata;
1304
1305 return add_notification(&layout->surface_notification.configure_changed,
1306 surface_configure_changed,
1307 configure_changed_callback);
1308}
1309
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001310static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001311ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1312 void *userdata)
1313{
1314 struct ivi_layout *layout = get_instance();
1315 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1316}
1317
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001318uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001319ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1320{
1321 return ivisurf->id_surface;
1322}
1323
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001324static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001325ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1326{
1327 return ivilayer->id_layer;
1328}
1329
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001330static uint32_t
1331ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1332{
1333 return iviscrn->id_screen;
1334}
1335
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001336static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001337ivi_layout_get_layer_from_id(uint32_t id_layer)
1338{
1339 struct ivi_layout *layout = get_instance();
1340 struct ivi_layout_layer *ivilayer = NULL;
1341
1342 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1343 if (ivilayer->id_layer == id_layer) {
1344 return ivilayer;
1345 }
1346 }
1347
1348 return NULL;
1349}
1350
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001351struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001352ivi_layout_get_surface_from_id(uint32_t id_surface)
1353{
1354 struct ivi_layout *layout = get_instance();
1355 struct ivi_layout_surface *ivisurf = NULL;
1356
1357 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1358 if (ivisurf->id_surface == id_surface) {
1359 return ivisurf;
1360 }
1361 }
1362
1363 return NULL;
1364}
1365
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001366static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001367ivi_layout_get_screen_from_id(uint32_t id_screen)
1368{
1369 struct ivi_layout *layout = get_instance();
1370 struct ivi_layout_screen *iviscrn = NULL;
1371
1372 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Nobuhiko Tanibata3e710d12015-11-25 23:36:09 +09001373 if (iviscrn->id_screen == id_screen)
1374 return iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001375 }
1376
1377 return NULL;
1378}
1379
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001380static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001381ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1382 int32_t *pWidth, int32_t *pHeight)
1383{
1384 struct weston_output *output = NULL;
1385
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001386 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001387 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1388 return IVI_FAILED;
1389 }
1390
1391 output = iviscrn->output;
1392 *pWidth = output->current_mode->width;
1393 *pHeight = output->current_mode->height;
1394
1395 return IVI_SUCCEEDED;
1396}
1397
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001398static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001399ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1400 surface_property_notification_func callback,
1401 void *userdata)
1402{
1403 struct listener_layout_notification* notification = NULL;
1404 struct ivi_layout_notification_callback *prop_callback = NULL;
1405
1406 if (ivisurf == NULL || callback == NULL) {
1407 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1408 return IVI_FAILED;
1409 }
1410
1411 notification = malloc(sizeof *notification);
1412 if (notification == NULL) {
1413 weston_log("fails to allocate memory\n");
1414 return IVI_FAILED;
1415 }
1416
1417 prop_callback = malloc(sizeof *prop_callback);
1418 if (prop_callback == NULL) {
1419 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001420 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001421 return IVI_FAILED;
1422 }
1423
1424 prop_callback->callback = callback;
1425 prop_callback->data = userdata;
1426
1427 notification->listener.notify = surface_prop_changed;
1428 notification->userdata = prop_callback;
1429
1430 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1431
1432 return IVI_SUCCEEDED;
1433}
1434
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001435static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001436ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1437{
1438 if (ivilayer == NULL) {
1439 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1440 return NULL;
1441 }
1442
1443 return &ivilayer->prop;
1444}
1445
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001446static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001447ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1448{
1449 struct ivi_layout *layout = get_instance();
1450 struct ivi_layout_screen *iviscrn = NULL;
1451 int32_t length = 0;
1452 int32_t n = 0;
1453
1454 if (pLength == NULL || ppArray == NULL) {
1455 weston_log("ivi_layout_get_screens: invalid argument\n");
1456 return IVI_FAILED;
1457 }
1458
1459 length = wl_list_length(&layout->screen_list);
1460
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001461 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001462 /* the Array must be free by module which called this function */
1463 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1464 if (*ppArray == NULL) {
1465 weston_log("fails to allocate memory\n");
1466 return IVI_FAILED;
1467 }
1468
1469 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1470 (*ppArray)[n++] = iviscrn;
1471 }
1472 }
1473
1474 *pLength = length;
1475
1476 return IVI_SUCCEEDED;
1477}
1478
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001479static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001480ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1481 int32_t *pLength,
1482 struct ivi_layout_screen ***ppArray)
1483{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001484 int32_t length = 0;
1485 int32_t n = 0;
1486
1487 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1488 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1489 return IVI_FAILED;
1490 }
1491
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001492 if (ivilayer->on_screen != NULL)
1493 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001494
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001495 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001496 /* the Array must be free by module which called this function */
1497 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1498 if (*ppArray == NULL) {
1499 weston_log("fails to allocate memory\n");
1500 return IVI_FAILED;
1501 }
1502
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001503 (*ppArray)[n++] = ivilayer->on_screen;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001504 }
1505
1506 *pLength = length;
1507
1508 return IVI_SUCCEEDED;
1509}
1510
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001511static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001512ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1513{
1514 struct ivi_layout *layout = get_instance();
1515 struct ivi_layout_layer *ivilayer = NULL;
1516 int32_t length = 0;
1517 int32_t n = 0;
1518
1519 if (pLength == NULL || ppArray == NULL) {
1520 weston_log("ivi_layout_get_layers: invalid argument\n");
1521 return IVI_FAILED;
1522 }
1523
1524 length = wl_list_length(&layout->layer_list);
1525
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001526 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001527 /* the Array must be free by module which called this function */
1528 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1529 if (*ppArray == NULL) {
1530 weston_log("fails to allocate memory\n");
1531 return IVI_FAILED;
1532 }
1533
1534 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1535 (*ppArray)[n++] = ivilayer;
1536 }
1537 }
1538
1539 *pLength = length;
1540
1541 return IVI_SUCCEEDED;
1542}
1543
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001544static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001545ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1546 int32_t *pLength,
1547 struct ivi_layout_layer ***ppArray)
1548{
1549 struct ivi_layout_layer *ivilayer = NULL;
1550 int32_t length = 0;
1551 int32_t n = 0;
1552
1553 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1554 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1555 return IVI_FAILED;
1556 }
1557
1558 length = wl_list_length(&iviscrn->order.layer_list);
1559
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001560 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001561 /* the Array must be free by module which called this function */
1562 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1563 if (*ppArray == NULL) {
1564 weston_log("fails to allocate memory\n");
1565 return IVI_FAILED;
1566 }
1567
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001568 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001569 (*ppArray)[n++] = ivilayer;
1570 }
1571 }
1572
1573 *pLength = length;
1574
1575 return IVI_SUCCEEDED;
1576}
1577
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001578static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001579ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1580 int32_t *pLength,
1581 struct ivi_layout_layer ***ppArray)
1582{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001583 int32_t length = 0;
1584 int32_t n = 0;
1585
1586 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1587 weston_log("ivi_layout_getLayers: invalid argument\n");
1588 return IVI_FAILED;
1589 }
1590
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001591 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001592 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001593 length = 1;
1594 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001595 if (*ppArray == NULL) {
1596 weston_log("fails to allocate memory\n");
1597 return IVI_FAILED;
1598 }
1599
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001600 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001601 }
1602
1603 *pLength = length;
1604
1605 return IVI_SUCCEEDED;
1606}
1607
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001608static
1609int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001610ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1611{
1612 struct ivi_layout *layout = get_instance();
1613 struct ivi_layout_surface *ivisurf = NULL;
1614 int32_t length = 0;
1615 int32_t n = 0;
1616
1617 if (pLength == NULL || ppArray == NULL) {
1618 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1619 return IVI_FAILED;
1620 }
1621
1622 length = wl_list_length(&layout->surface_list);
1623
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001624 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001625 /* the Array must be free by module which called this function */
1626 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1627 if (*ppArray == NULL) {
1628 weston_log("fails to allocate memory\n");
1629 return IVI_FAILED;
1630 }
1631
1632 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1633 (*ppArray)[n++] = ivisurf;
1634 }
1635 }
1636
1637 *pLength = length;
1638
1639 return IVI_SUCCEEDED;
1640}
1641
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001642static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001643ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1644 int32_t *pLength,
1645 struct ivi_layout_surface ***ppArray)
1646{
1647 struct ivi_layout_surface *ivisurf = NULL;
1648 int32_t length = 0;
1649 int32_t n = 0;
1650
1651 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1652 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1653 return IVI_FAILED;
1654 }
1655
1656 length = wl_list_length(&ivilayer->order.surface_list);
1657
1658 if (length != 0) {
1659 /* the Array must be free by module which called this function */
1660 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1661 if (*ppArray == NULL) {
1662 weston_log("fails to allocate memory\n");
1663 return IVI_FAILED;
1664 }
1665
1666 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1667 (*ppArray)[n++] = ivisurf;
1668 }
1669 }
1670
1671 *pLength = length;
1672
1673 return IVI_SUCCEEDED;
1674}
1675
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001676static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001677ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1678 int32_t width, int32_t height)
1679{
1680 struct ivi_layout *layout = get_instance();
1681 struct ivi_layout_layer *ivilayer = NULL;
1682
1683 ivilayer = get_layer(&layout->layer_list, id_layer);
1684 if (ivilayer != NULL) {
1685 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001686 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001687 return ivilayer;
1688 }
1689
1690 ivilayer = calloc(1, sizeof *ivilayer);
1691 if (ivilayer == NULL) {
1692 weston_log("fails to allocate memory\n");
1693 return NULL;
1694 }
1695
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001696 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001697 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001698 ivilayer->layout = layout;
1699 ivilayer->id_layer = id_layer;
1700
1701 init_layer_properties(&ivilayer->prop, width, height);
1702 ivilayer->event_mask = 0;
1703
1704 wl_list_init(&ivilayer->pending.surface_list);
1705 wl_list_init(&ivilayer->pending.link);
1706 ivilayer->pending.prop = ivilayer->prop;
1707
1708 wl_list_init(&ivilayer->order.surface_list);
1709 wl_list_init(&ivilayer->order.link);
1710
1711 wl_list_insert(&layout->layer_list, &ivilayer->link);
1712
1713 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1714
1715 return ivilayer;
1716}
1717
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001718static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001719ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1720{
1721 if (ivilayer == NULL) {
1722 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1723 return;
1724 }
1725
1726 remove_all_notification(&ivilayer->property_changed.listener_list);
1727}
1728
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001729static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001730ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1731 layer_property_notification_func callback,
1732 void *userdata)
1733{
1734 if (ivilayer == NULL) {
1735 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1736 return;
1737 }
1738
1739 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1740}
1741
1742static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001743ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001744{
1745 struct ivi_layout *layout = get_instance();
1746
1747 if (ivilayer == NULL) {
1748 weston_log("ivi_layout_layer_remove: invalid argument\n");
1749 return;
1750 }
1751
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001752 if (--ivilayer->ref_count > 0)
1753 return;
1754
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001755 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1756
1757 clear_surface_pending_list(ivilayer);
1758 clear_surface_order_list(ivilayer);
1759
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001760 wl_list_remove(&ivilayer->pending.link);
1761 wl_list_remove(&ivilayer->order.link);
1762 wl_list_remove(&ivilayer->link);
1763
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001764 ivi_layout_layer_remove_notification(ivilayer);
1765
1766 free(ivilayer);
1767}
1768
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001769int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001770ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1771 bool newVisibility)
1772{
1773 struct ivi_layout_layer_properties *prop = NULL;
1774
1775 if (ivilayer == NULL) {
1776 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1777 return IVI_FAILED;
1778 }
1779
1780 prop = &ivilayer->pending.prop;
1781 prop->visibility = newVisibility;
1782
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001783 if (ivilayer->prop.visibility != newVisibility)
1784 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1785 else
1786 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001787
1788 return IVI_SUCCEEDED;
1789}
1790
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001791int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001792ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1793 wl_fixed_t opacity)
1794{
1795 struct ivi_layout_layer_properties *prop = NULL;
1796
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001797 if (ivilayer == NULL ||
1798 opacity < wl_fixed_from_double(0.0) ||
1799 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001800 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1801 return IVI_FAILED;
1802 }
1803
1804 prop = &ivilayer->pending.prop;
1805 prop->opacity = opacity;
1806
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001807 if (ivilayer->prop.opacity != opacity)
1808 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1809 else
1810 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001811
1812 return IVI_SUCCEEDED;
1813}
1814
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001815static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001816ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1817 int32_t x, int32_t y,
1818 int32_t width, int32_t height)
1819{
1820 struct ivi_layout_layer_properties *prop = NULL;
1821
1822 if (ivilayer == NULL) {
1823 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1824 return IVI_FAILED;
1825 }
1826
1827 prop = &ivilayer->pending.prop;
1828 prop->source_x = x;
1829 prop->source_y = y;
1830 prop->source_width = width;
1831 prop->source_height = height;
1832
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001833 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1834 ivilayer->prop.source_width != width ||
1835 ivilayer->prop.source_height != height)
1836 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1837 else
1838 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001839
1840 return IVI_SUCCEEDED;
1841}
1842
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001843int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001844ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1845 int32_t x, int32_t y,
1846 int32_t width, int32_t height)
1847{
1848 struct ivi_layout_layer_properties *prop = NULL;
1849
1850 if (ivilayer == NULL) {
1851 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1852 return IVI_FAILED;
1853 }
1854
1855 prop = &ivilayer->pending.prop;
1856 prop->dest_x = x;
1857 prop->dest_y = y;
1858 prop->dest_width = width;
1859 prop->dest_height = height;
1860
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001861 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1862 ivilayer->prop.dest_width != width ||
1863 ivilayer->prop.dest_height != height)
1864 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1865 else
1866 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001867
1868 return IVI_SUCCEEDED;
1869}
1870
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001871static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001872ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1873 enum wl_output_transform orientation)
1874{
1875 struct ivi_layout_layer_properties *prop = NULL;
1876
1877 if (ivilayer == NULL) {
1878 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1879 return IVI_FAILED;
1880 }
1881
1882 prop = &ivilayer->pending.prop;
1883 prop->orientation = orientation;
1884
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001885 if (ivilayer->prop.orientation != orientation)
1886 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1887 else
1888 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001889
1890 return IVI_SUCCEEDED;
1891}
1892
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001893int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001894ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1895 struct ivi_layout_surface **pSurface,
1896 int32_t number)
1897{
1898 struct ivi_layout *layout = get_instance();
1899 struct ivi_layout_surface *ivisurf = NULL;
1900 struct ivi_layout_surface *next = NULL;
1901 uint32_t *id_surface = NULL;
1902 int32_t i = 0;
1903
1904 if (ivilayer == NULL) {
1905 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1906 return IVI_FAILED;
1907 }
1908
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001909 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001910
1911 for (i = 0; i < number; i++) {
1912 id_surface = &pSurface[i]->id_surface;
1913
1914 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
1915 if (*id_surface != ivisurf->id_surface) {
1916 continue;
1917 }
1918
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001919 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001920 wl_list_insert(&ivilayer->pending.surface_list,
1921 &ivisurf->pending.link);
1922 break;
1923 }
1924 }
1925
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001926 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001927
1928 return IVI_SUCCEEDED;
1929}
1930
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001931int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001932ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1933 bool newVisibility)
1934{
1935 struct ivi_layout_surface_properties *prop = NULL;
1936
1937 if (ivisurf == NULL) {
1938 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1939 return IVI_FAILED;
1940 }
1941
1942 prop = &ivisurf->pending.prop;
1943 prop->visibility = newVisibility;
1944
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001945 if (ivisurf->prop.visibility != newVisibility)
1946 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1947 else
1948 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001949
1950 return IVI_SUCCEEDED;
1951}
1952
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001953int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001954ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1955 wl_fixed_t opacity)
1956{
1957 struct ivi_layout_surface_properties *prop = NULL;
1958
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001959 if (ivisurf == NULL ||
1960 opacity < wl_fixed_from_double(0.0) ||
1961 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001962 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1963 return IVI_FAILED;
1964 }
1965
1966 prop = &ivisurf->pending.prop;
1967 prop->opacity = opacity;
1968
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001969 if (ivisurf->prop.opacity != opacity)
1970 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
1971 else
1972 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001973
1974 return IVI_SUCCEEDED;
1975}
1976
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001977int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001978ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1979 int32_t x, int32_t y,
1980 int32_t width, int32_t height)
1981{
1982 struct ivi_layout_surface_properties *prop = NULL;
1983
1984 if (ivisurf == NULL) {
1985 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1986 return IVI_FAILED;
1987 }
1988
1989 prop = &ivisurf->pending.prop;
1990 prop->start_x = prop->dest_x;
1991 prop->start_y = prop->dest_y;
1992 prop->dest_x = x;
1993 prop->dest_y = y;
1994 prop->start_width = prop->dest_width;
1995 prop->start_height = prop->dest_height;
1996 prop->dest_width = width;
1997 prop->dest_height = height;
1998
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001999 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2000 ivisurf->prop.dest_width != width ||
2001 ivisurf->prop.dest_height != height)
2002 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2003 else
2004 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002005
2006 return IVI_SUCCEEDED;
2007}
2008
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002009static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002010ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2011 enum wl_output_transform orientation)
2012{
2013 struct ivi_layout_surface_properties *prop = NULL;
2014
2015 if (ivisurf == NULL) {
2016 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2017 return IVI_FAILED;
2018 }
2019
2020 prop = &ivisurf->pending.prop;
2021 prop->orientation = orientation;
2022
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002023 if (ivisurf->prop.orientation != orientation)
2024 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2025 else
2026 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002027
2028 return IVI_SUCCEEDED;
2029}
2030
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002031static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002032ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2033 struct ivi_layout_layer *addlayer)
2034{
2035 struct ivi_layout *layout = get_instance();
2036 struct ivi_layout_layer *ivilayer = NULL;
2037 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002038
2039 if (iviscrn == NULL || addlayer == NULL) {
2040 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2041 return IVI_FAILED;
2042 }
2043
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00002044 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002045 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2046 return IVI_SUCCEEDED;
2047 }
2048
2049 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2050 if (ivilayer->id_layer == addlayer->id_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002051 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002052 wl_list_insert(&iviscrn->pending.layer_list,
2053 &ivilayer->pending.link);
2054 break;
2055 }
2056 }
2057
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002058 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002059
2060 return IVI_SUCCEEDED;
2061}
2062
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002063static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002064ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2065 struct ivi_layout_layer **pLayer,
2066 const int32_t number)
2067{
2068 struct ivi_layout *layout = get_instance();
2069 struct ivi_layout_layer *ivilayer = NULL;
2070 struct ivi_layout_layer *next = NULL;
2071 uint32_t *id_layer = NULL;
2072 int32_t i = 0;
2073
2074 if (iviscrn == NULL) {
2075 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2076 return IVI_FAILED;
2077 }
2078
2079 wl_list_for_each_safe(ivilayer, next,
2080 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002081 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002082 wl_list_init(&ivilayer->pending.link);
2083 }
2084
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002085 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002086
2087 for (i = 0; i < number; i++) {
2088 id_layer = &pLayer[i]->id_layer;
2089 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2090 if (*id_layer != ivilayer->id_layer) {
2091 continue;
2092 }
2093
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002094 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002095 wl_list_insert(&iviscrn->pending.layer_list,
2096 &ivilayer->pending.link);
2097 break;
2098 }
2099 }
2100
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002101 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002102
2103 return IVI_SUCCEEDED;
2104}
2105
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002106static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002107ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2108{
2109 return iviscrn->output;
2110}
2111
2112/**
2113 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2114 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2115 * This function is used to get the result of drawing by clients.
2116 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002117static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002118ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2119{
2120 return ivisurf != NULL ? ivisurf->surface : NULL;
2121}
2122
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002123static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002124ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2125 int32_t *width, int32_t *height,
2126 int32_t *stride)
2127{
2128 int32_t w;
2129 int32_t h;
2130 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2131
2132 if (ivisurf == NULL || ivisurf->surface == NULL) {
2133 weston_log("%s: invalid argument\n", __func__);
2134 return IVI_FAILED;
2135 }
2136
2137 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2138
2139 if (width != NULL)
2140 *width = w;
2141
2142 if (height != NULL)
2143 *height = h;
2144
2145 if (stride != NULL)
2146 *stride = w * bytespp;
2147
2148 return IVI_SUCCEEDED;
2149}
2150
2151static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002152ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2153 layer_property_notification_func callback,
2154 void *userdata)
2155{
2156 struct ivi_layout_notification_callback *prop_callback = NULL;
2157
2158 if (ivilayer == NULL || callback == NULL) {
2159 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2160 return IVI_FAILED;
2161 }
2162
2163 prop_callback = malloc(sizeof *prop_callback);
2164 if (prop_callback == NULL) {
2165 weston_log("fails to allocate memory\n");
2166 return IVI_FAILED;
2167 }
2168
2169 prop_callback->callback = callback;
2170 prop_callback->data = userdata;
2171
2172 return add_notification(&ivilayer->property_changed,
2173 layer_prop_changed,
2174 prop_callback);
2175}
2176
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002177static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002178ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2179{
2180 if (ivisurf == NULL) {
2181 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2182 return NULL;
2183 }
2184
2185 return &ivisurf->prop;
2186}
2187
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002188static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002189ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2190 struct ivi_layout_surface *addsurf)
2191{
2192 struct ivi_layout *layout = get_instance();
2193 struct ivi_layout_surface *ivisurf = NULL;
2194 struct ivi_layout_surface *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002195
2196 if (ivilayer == NULL || addsurf == NULL) {
2197 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2198 return IVI_FAILED;
2199 }
2200
Wataru Natsume9c926fe2016-03-03 19:56:09 +09002201 if (addsurf->on_layer == ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002202 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002203
2204 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2205 if (ivisurf->id_surface == addsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002206 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002207 wl_list_insert(&ivilayer->pending.surface_list,
2208 &ivisurf->pending.link);
2209 break;
2210 }
2211 }
2212
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002213 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002214
2215 return IVI_SUCCEEDED;
2216}
2217
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002218static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002219ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2220 struct ivi_layout_surface *remsurf)
2221{
2222 struct ivi_layout_surface *ivisurf = NULL;
2223 struct ivi_layout_surface *next = NULL;
2224
2225 if (ivilayer == NULL || remsurf == NULL) {
2226 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2227 return;
2228 }
2229
2230 wl_list_for_each_safe(ivisurf, next,
2231 &ivilayer->pending.surface_list, pending.link) {
2232 if (ivisurf->id_surface == remsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002233 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002234 wl_list_init(&ivisurf->pending.link);
2235 break;
2236 }
2237 }
2238
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002239 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002240}
2241
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002242static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002243ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2244 int32_t x, int32_t y,
2245 int32_t width, int32_t height)
2246{
2247 struct ivi_layout_surface_properties *prop = NULL;
2248
2249 if (ivisurf == NULL) {
2250 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2251 return IVI_FAILED;
2252 }
2253
2254 prop = &ivisurf->pending.prop;
2255 prop->source_x = x;
2256 prop->source_y = y;
2257 prop->source_width = width;
2258 prop->source_height = height;
2259
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002260 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2261 ivisurf->prop.source_width != width ||
2262 ivisurf->prop.source_height != height)
2263 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2264 else
2265 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002266
2267 return IVI_SUCCEEDED;
2268}
2269
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002270int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002271ivi_layout_commit_changes(void)
2272{
2273 struct ivi_layout *layout = get_instance();
2274
2275 commit_surface_list(layout);
2276 commit_layer_list(layout);
2277 commit_screen_list(layout);
2278
2279 commit_transition(layout);
2280
2281 commit_changes(layout);
2282 send_prop(layout);
2283 weston_compositor_schedule_repaint(layout->compositor);
2284
2285 return IVI_SUCCEEDED;
2286}
2287
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002288static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002289ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2290 enum ivi_layout_transition_type type,
2291 uint32_t duration)
2292{
2293 if (ivilayer == NULL) {
2294 weston_log("%s: invalid argument\n", __func__);
2295 return -1;
2296 }
2297
2298 ivilayer->pending.prop.transition_type = type;
2299 ivilayer->pending.prop.transition_duration = duration;
2300
2301 return 0;
2302}
2303
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002304static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002305ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2306 uint32_t is_fade_in,
2307 double start_alpha, double end_alpha)
2308{
2309 if (ivilayer == NULL) {
2310 weston_log("%s: invalid argument\n", __func__);
2311 return -1;
2312 }
2313
2314 ivilayer->pending.prop.is_fade_in = is_fade_in;
2315 ivilayer->pending.prop.start_alpha = start_alpha;
2316 ivilayer->pending.prop.end_alpha = end_alpha;
2317
2318 return 0;
2319}
2320
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002321static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002322ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2323 uint32_t duration)
2324{
2325 struct ivi_layout_surface_properties *prop;
2326
2327 if (ivisurf == NULL) {
2328 weston_log("%s: invalid argument\n", __func__);
2329 return -1;
2330 }
2331
2332 prop = &ivisurf->pending.prop;
2333 prop->transition_duration = duration*10;
2334 return 0;
2335}
2336
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002337static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002338ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2339 enum ivi_layout_transition_type type,
2340 uint32_t duration)
2341{
2342 struct ivi_layout_surface_properties *prop;
2343
2344 if (ivisurf == NULL) {
2345 weston_log("%s: invalid argument\n", __func__);
2346 return -1;
2347 }
2348
2349 prop = &ivisurf->pending.prop;
2350 prop->transition_type = type;
2351 prop->transition_duration = duration;
2352 return 0;
2353}
2354
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002355static int32_t
2356ivi_layout_surface_dump(struct weston_surface *surface,
2357 void *target, size_t size,int32_t x, int32_t y,
2358 int32_t width, int32_t height)
2359{
2360 int result = 0;
2361
2362 if (surface == NULL) {
2363 weston_log("%s: invalid argument\n", __func__);
2364 return IVI_FAILED;
2365 }
2366
2367 result = weston_surface_copy_content(
2368 surface, target, size,
2369 x, y, width, height);
2370
2371 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2372}
2373
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002374/**
2375 * methods of interaction between ivi-shell with ivi-layout
2376 */
2377struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002378ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2379{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002380 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002381 return NULL;
2382
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002383 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002384}
2385
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002386void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002387ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2388 int32_t width, int32_t height)
2389{
2390 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002391
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002392 /* emit callback which is set by ivi-layout api user */
2393 wl_signal_emit(&layout->surface_notification.configure_changed,
2394 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002395}
2396
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002397static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002398ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2399 ivi_controller_surface_content_callback callback,
2400 void* userdata)
2401{
2402 int32_t ret = IVI_FAILED;
2403
2404 if (ivisurf != NULL) {
2405 ivisurf->content_observer.callback = callback;
2406 ivisurf->content_observer.userdata = userdata;
2407 ret = IVI_SUCCEEDED;
2408 }
2409 return ret;
2410}
2411
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002412struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002413ivi_layout_surface_create(struct weston_surface *wl_surface,
2414 uint32_t id_surface)
2415{
2416 struct ivi_layout *layout = get_instance();
2417 struct ivi_layout_surface *ivisurf = NULL;
2418 struct weston_view *tmpview = NULL;
2419
2420 if (wl_surface == NULL) {
2421 weston_log("ivi_layout_surface_create: invalid argument\n");
2422 return NULL;
2423 }
2424
2425 ivisurf = get_surface(&layout->surface_list, id_surface);
2426 if (ivisurf != NULL) {
2427 if (ivisurf->surface != NULL) {
2428 weston_log("id_surface(%d) is already created\n", id_surface);
2429 return NULL;
2430 }
2431 }
2432
2433 ivisurf = calloc(1, sizeof *ivisurf);
2434 if (ivisurf == NULL) {
2435 weston_log("fails to allocate memory\n");
2436 return NULL;
2437 }
2438
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002439 wl_signal_init(&ivisurf->property_changed);
2440 wl_signal_init(&ivisurf->configured);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002441 ivisurf->id_surface = id_surface;
2442 ivisurf->layout = layout;
2443
2444 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002445
2446 tmpview = weston_view_create(wl_surface);
2447 if (tmpview == NULL) {
2448 weston_log("fails to allocate memory\n");
2449 }
2450
2451 ivisurf->surface->width_from_buffer = 0;
2452 ivisurf->surface->height_from_buffer = 0;
2453
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002454 weston_matrix_init(&ivisurf->transform.matrix);
2455 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002456
2457 init_surface_properties(&ivisurf->prop);
2458 ivisurf->event_mask = 0;
2459
2460 ivisurf->pending.prop = ivisurf->prop;
2461 wl_list_init(&ivisurf->pending.link);
2462
2463 wl_list_init(&ivisurf->order.link);
2464 wl_list_init(&ivisurf->order.layer_list);
2465
2466 wl_list_insert(&layout->surface_list, &ivisurf->link);
2467
2468 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2469
2470 return ivisurf;
2471}
2472
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002473void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002474ivi_layout_init_with_compositor(struct weston_compositor *ec)
2475{
2476 struct ivi_layout *layout = get_instance();
2477
2478 layout->compositor = ec;
2479
2480 wl_list_init(&layout->surface_list);
2481 wl_list_init(&layout->layer_list);
2482 wl_list_init(&layout->screen_list);
2483
2484 wl_signal_init(&layout->layer_notification.created);
2485 wl_signal_init(&layout->layer_notification.removed);
2486
2487 wl_signal_init(&layout->surface_notification.created);
2488 wl_signal_init(&layout->surface_notification.removed);
2489 wl_signal_init(&layout->surface_notification.configure_changed);
2490
2491 /* Add layout_layer at the last of weston_compositor.layer_list */
2492 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2493
2494 create_screen(ec);
2495
2496 layout->transitions = ivi_layout_transition_set_create(ec);
2497 wl_list_init(&layout->pending_transition_list);
2498}
2499
2500
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002501void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002502ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2503 struct wl_listener* listener)
2504{
2505 wl_signal_add(&ivisurf->configured, listener);
2506}
2507
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002508static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002509 /**
2510 * commit all changes
2511 */
2512 .commit_changes = ivi_layout_commit_changes,
2513
2514 /**
2515 * surface controller interfaces
2516 */
2517 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2518 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2519 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2520 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2521 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2522 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2523 .get_surfaces = ivi_layout_get_surfaces,
2524 .get_id_of_surface = ivi_layout_get_id_of_surface,
2525 .get_surface_from_id = ivi_layout_get_surface_from_id,
2526 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2527 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2528 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002529 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002530 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2531 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002532 .surface_set_orientation = ivi_layout_surface_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002533 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2534 .surface_add_notification = ivi_layout_surface_add_notification,
2535 .surface_remove_notification = ivi_layout_surface_remove_notification,
2536 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2537 .surface_set_transition = ivi_layout_surface_set_transition,
2538 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2539
2540 /**
2541 * layer controller interfaces
2542 */
2543 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2544 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2545 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2546 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2547 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002548 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002549 .get_layers = ivi_layout_get_layers,
2550 .get_id_of_layer = ivi_layout_get_id_of_layer,
2551 .get_layer_from_id = ivi_layout_get_layer_from_id,
2552 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2553 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2554 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2555 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002556 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002557 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2558 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002559 .layer_set_orientation = ivi_layout_layer_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002560 .layer_add_surface = ivi_layout_layer_add_surface,
2561 .layer_remove_surface = ivi_layout_layer_remove_surface,
2562 .layer_set_render_order = ivi_layout_layer_set_render_order,
2563 .layer_add_notification = ivi_layout_layer_add_notification,
2564 .layer_remove_notification = ivi_layout_layer_remove_notification,
2565 .layer_set_transition = ivi_layout_layer_set_transition,
2566
2567 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002568 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002569 */
2570 .get_screen_from_id = ivi_layout_get_screen_from_id,
2571 .get_screen_resolution = ivi_layout_get_screen_resolution,
2572 .get_screens = ivi_layout_get_screens,
2573 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2574 .screen_add_layer = ivi_layout_screen_add_layer,
2575 .screen_set_render_order = ivi_layout_screen_set_render_order,
2576 .screen_get_output = ivi_layout_screen_get_output,
2577
2578 /**
2579 * animation
2580 */
2581 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002582 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2583
2584 /**
2585 * surface content dumping for debugging
2586 */
2587 .surface_get_size = ivi_layout_surface_get_size,
2588 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002589
2590 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002591 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002592 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002593 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002594 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2595
2596 /**
2597 * screen controller interfaces part2
2598 */
2599 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002600};
2601
2602int
2603load_controller_modules(struct weston_compositor *compositor, const char *modules,
2604 int *argc, char *argv[])
2605{
2606 const char *p, *end;
2607 char buffer[256];
2608 int (*controller_module_init)(struct weston_compositor *compositor,
2609 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002610 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002611 size_t interface_version);
2612
2613 if (modules == NULL)
2614 return 0;
2615
2616 p = modules;
2617 while (*p) {
2618 end = strchrnul(p, ',');
2619 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2620
2621 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002622 if (!controller_module_init)
2623 return -1;
2624
2625 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002626 &ivi_layout_interface,
2627 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002628 weston_log("ivi-shell: Initialization of controller module fails");
2629 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002630 }
2631
2632 p = end;
2633 while (*p == ',')
2634 p++;
2635 }
2636
2637 return 0;
2638}