blob: 437ba22f2fad7e0590c9d2375e9ef0069e0203ba [file] [log] [blame]
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001/*
2 * Copyright (C) 2013 DENSO CORPORATION
3 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090011 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090024 */
25
26/**
27 * Implementation of ivi-layout library. The actual view on ivi_screen is
28 * not updated till calling ivi_layout_commit_changes. A overview from
29 * calling API for updating properties of ivi_surface/ivi_layer to asking
30 * compositor to compose them by using weston_compositor_schedule_repaint,
31 * 0/ initialize this library by ivi_layout_init_with_compositor
32 * with (struct weston_compositor *ec) from ivi-shell.
33 * 1/ When a API for updating properties of ivi_surface/ivi_layer, it updates
34 * pending prop of ivi_surface/ivi_layer/ivi_screen which are structure to
35 * store properties.
36 * 2/ Before calling commitChanges, in case of calling a API to get a property,
37 * return current property, not pending property.
38 * 3/ At the timing of calling ivi_layout_commitChanges, pending properties
39 * are applied to properties.
40 *
41 * *) ivi_layout_commitChanges is also called by transition animation
42 * per each frame. See ivi-layout-transition.c in details. Transition
43 * animation interpolates frames between previous properties of ivi_surface
44 * and new ones.
45 * For example, when a property of ivi_surface is changed from invisibility
46 * to visibility, it behaves like fade-in. When ivi_layout_commitChange is
47 * called during transition animation, it cancels the transition and
48 * re-start transition to new properties from current properties of final
49 * frame just before the the cancellation.
50 *
51 * 4/ According properties, set transformation by using weston_matrix and
52 * weston_view per ivi_surfaces and ivi_layers in while loop.
53 * 5/ Set damage and trigger transform by using weston_view_geometry_dirty.
54 * 6/ Notify update of properties.
55 * 7/ Trigger composition by weston_compositor_schedule_repaint.
56 *
57 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090058#include "config.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090059
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090060#include <string.h>
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +000061#include <assert.h>
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090062
63#include "compositor.h"
Pekka Paalanen1f821932016-03-15 16:57:51 +020064#include "ivi-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090065#include "ivi-layout-export.h"
66#include "ivi-layout-private.h"
Pekka Paalanen32ca7912016-03-15 17:21:00 +020067#include "ivi-layout-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090068
Jon Cruz867d50e2015-06-15 15:37:10 -070069#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070070#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090071
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +090072#define max(a, b) ((a) > (b) ? (a) : (b))
73
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090074struct listener_layout_notification {
75 void *userdata;
76 struct wl_listener listener;
77};
78
79struct ivi_layout;
80
81struct ivi_layout_screen {
82 struct wl_list link;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090083 uint32_t id_screen;
84
85 struct ivi_layout *layout;
86 struct weston_output *output;
87
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090088 struct {
89 struct wl_list layer_list;
90 struct wl_list link;
91 } pending;
92
93 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +000094 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090095 struct wl_list layer_list;
96 struct wl_list link;
97 } order;
98};
99
100struct ivi_layout_notification_callback {
101 void *callback;
102 void *data;
103};
104
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900105struct ivi_rectangle
106{
107 int32_t x;
108 int32_t y;
109 int32_t width;
110 int32_t height;
111};
112
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900113static void
114remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
115
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900116static struct ivi_layout ivilayout = {0};
117
118struct ivi_layout *
119get_instance(void)
120{
121 return &ivilayout;
122}
123
124/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900125 * Internal API to add/remove a ivi_layer to/from ivi_screen.
126 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900127static struct ivi_layout_surface *
128get_surface(struct wl_list *surf_list, uint32_t id_surface)
129{
130 struct ivi_layout_surface *ivisurf;
131
132 wl_list_for_each(ivisurf, surf_list, link) {
133 if (ivisurf->id_surface == id_surface) {
134 return ivisurf;
135 }
136 }
137
138 return NULL;
139}
140
141static struct ivi_layout_layer *
142get_layer(struct wl_list *layer_list, uint32_t id_layer)
143{
144 struct ivi_layout_layer *ivilayer;
145
146 wl_list_for_each(ivilayer, layer_list, link) {
147 if (ivilayer->id_layer == id_layer) {
148 return ivilayer;
149 }
150 }
151
152 return NULL;
153}
154
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000155static struct weston_view *
156get_weston_view(struct ivi_layout_surface *ivisurf)
157{
158 struct weston_view *view = NULL;
159
160 assert(ivisurf->surface != NULL);
161
162 /* One view per surface */
163 if(wl_list_empty(&ivisurf->surface->views))
164 view = NULL;
165 else
166 view = wl_container_of(ivisurf->surface->views.next, view, surface_link);
167
168 return view;
169}
170
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900171static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900172remove_all_notification(struct wl_list *listener_list)
173{
174 struct wl_listener *listener = NULL;
175 struct wl_listener *next = NULL;
176
177 wl_list_for_each_safe(listener, next, listener_list, link) {
178 struct listener_layout_notification *notification = NULL;
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000179 wl_list_remove(&listener->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900180
181 notification =
182 container_of(listener,
183 struct listener_layout_notification,
184 listener);
185
186 free(notification->userdata);
187 free(notification);
188 }
189}
190
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900191static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900192ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
193{
194 if (ivisurf == NULL) {
195 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
196 return;
197 }
198
199 remove_all_notification(&ivisurf->property_changed.listener_list);
200}
201
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900202static void
203ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
204 surface_property_notification_func callback,
205 void *userdata)
206{
207 if (ivisurf == NULL) {
208 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
209 return;
210 }
211
212 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
213}
214
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900215/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900216 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900217 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900218void
219ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900220{
221 struct ivi_layout *layout = get_instance();
222
223 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900224 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900225 return;
226 }
227
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900228 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900229 wl_list_remove(&ivisurf->pending.link);
230 wl_list_remove(&ivisurf->order.link);
231 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900232
233 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
234
Mateusz Polroladada6e32016-03-09 09:13:26 +0000235 ivi_layout_remove_all_surface_transitions(ivisurf);
236
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900237 ivi_layout_surface_remove_notification(ivisurf);
238
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900239 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900240}
241
242/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900243 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
244 * Called by ivi_layout_init_with_compositor.
245 */
246static void
247create_screen(struct weston_compositor *ec)
248{
249 struct ivi_layout *layout = get_instance();
250 struct ivi_layout_screen *iviscrn = NULL;
251 struct weston_output *output = NULL;
252 int32_t count = 0;
253
254 wl_list_for_each(output, &ec->output_list, link) {
255 iviscrn = calloc(1, sizeof *iviscrn);
256 if (iviscrn == NULL) {
257 weston_log("fails to allocate memory\n");
258 continue;
259 }
260
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900261 iviscrn->layout = layout;
262
263 iviscrn->id_screen = count;
264 count++;
265
266 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900267
268 wl_list_init(&iviscrn->pending.layer_list);
269 wl_list_init(&iviscrn->pending.link);
270
271 wl_list_init(&iviscrn->order.layer_list);
272 wl_list_init(&iviscrn->order.link);
273
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900274 wl_list_insert(&layout->screen_list, &iviscrn->link);
275 }
276}
277
278/**
279 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
280 */
281static void
282init_layer_properties(struct ivi_layout_layer_properties *prop,
283 int32_t width, int32_t height)
284{
285 memset(prop, 0, sizeof *prop);
286 prop->opacity = wl_fixed_from_double(1.0);
287 prop->source_width = width;
288 prop->source_height = height;
289 prop->dest_width = width;
290 prop->dest_height = height;
291}
292
293static void
294init_surface_properties(struct ivi_layout_surface_properties *prop)
295{
296 memset(prop, 0, sizeof *prop);
297 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900298 /*
299 * FIXME: this shall be finxed by ivi-layout-transition.
300 */
301 prop->dest_width = 1;
302 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900303}
304
305/**
306 * Internal APIs to be called from ivi_layout_commit_changes.
307 */
308static void
309update_opacity(struct ivi_layout_layer *ivilayer,
310 struct ivi_layout_surface *ivisurf)
311{
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000312 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900313 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
314 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
315
Nobuhiko Tanibata90c27892015-12-26 23:52:51 +0900316 tmpview = get_weston_view(ivisurf);
317 assert(tmpview != NULL);
318 tmpview->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900319}
320
321static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900322get_rotate_values(enum wl_output_transform orientation,
323 float *v_sin,
324 float *v_cos)
325{
326 switch (orientation) {
327 case WL_OUTPUT_TRANSFORM_90:
328 *v_sin = 1.0f;
329 *v_cos = 0.0f;
330 break;
331 case WL_OUTPUT_TRANSFORM_180:
332 *v_sin = 0.0f;
333 *v_cos = -1.0f;
334 break;
335 case WL_OUTPUT_TRANSFORM_270:
336 *v_sin = -1.0f;
337 *v_cos = 0.0f;
338 break;
339 case WL_OUTPUT_TRANSFORM_NORMAL:
340 default:
341 *v_sin = 0.0f;
342 *v_cos = 1.0f;
343 break;
344 }
345}
346
347static void
348get_scale(enum wl_output_transform orientation,
349 float dest_width,
350 float dest_height,
351 float source_width,
352 float source_height,
353 float *scale_x,
354 float *scale_y)
355{
356 switch (orientation) {
357 case WL_OUTPUT_TRANSFORM_90:
358 *scale_x = dest_width / source_height;
359 *scale_y = dest_height / source_width;
360 break;
361 case WL_OUTPUT_TRANSFORM_180:
362 *scale_x = dest_width / source_width;
363 *scale_y = dest_height / source_height;
364 break;
365 case WL_OUTPUT_TRANSFORM_270:
366 *scale_x = dest_width / source_height;
367 *scale_y = dest_height / source_width;
368 break;
369 case WL_OUTPUT_TRANSFORM_NORMAL:
370 default:
371 *scale_x = dest_width / source_width;
372 *scale_y = dest_height / source_height;
373 break;
374 }
375}
376
377static void
378calc_transformation_matrix(struct ivi_rectangle *source_rect,
379 struct ivi_rectangle *dest_rect,
380 enum wl_output_transform orientation,
381 struct weston_matrix *m)
382{
383 float source_center_x;
384 float source_center_y;
385 float vsin;
386 float vcos;
387 float scale_x;
388 float scale_y;
389 float translate_x;
390 float translate_y;
391
392 source_center_x = source_rect->x + source_rect->width * 0.5f;
393 source_center_y = source_rect->y + source_rect->height * 0.5f;
394 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
395
396 get_rotate_values(orientation, &vsin, &vcos);
397 weston_matrix_rotate_xy(m, vcos, vsin);
398
399 get_scale(orientation,
400 dest_rect->width,
401 dest_rect->height,
402 source_rect->width,
403 source_rect->height,
404 &scale_x,
405 &scale_y);
406 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
407
408 translate_x = dest_rect->width * 0.5f + dest_rect->x;
409 translate_y = dest_rect->height * 0.5f + dest_rect->y;
410 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
411}
412
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900413/*
414 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900415 */
416static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900417ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
418 const struct ivi_rectangle *rect2,
419 struct ivi_rectangle *rect_output)
420{
421 int32_t rect1_right = rect1->x + rect1->width;
422 int32_t rect1_bottom = rect1->y + rect1->height;
423 int32_t rect2_right = rect2->x + rect2->width;
424 int32_t rect2_bottom = rect2->y + rect2->height;
425
426 rect_output->x = max(rect1->x, rect2->x);
427 rect_output->y = max(rect1->y, rect2->y);
428 rect_output->width = rect1_right < rect2_right ?
429 rect1_right - rect_output->x :
430 rect2_right - rect_output->x;
431 rect_output->height = rect1_bottom < rect2_bottom ?
432 rect1_bottom - rect_output->y :
433 rect2_bottom - rect_output->y;
434
435 if (rect_output->width < 0 || rect_output->height < 0) {
436 rect_output->width = 0;
437 rect_output->height = 0;
438 }
439}
440
441/*
442 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
443 * and store the result in rect_output.
444 * The boundingbox must be given in the same coordinate space as rect_output.
445 * Additionally, there are the following restrictions on the matrix:
446 * - no projective transformations
447 * - no skew
448 * - only multiples of 90-degree rotations supported
449 *
450 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
451 * as a fail-safe with log.
452 */
453static void
454calc_inverse_matrix_transform(const struct weston_matrix *matrix,
455 const struct ivi_rectangle *rect_input,
456 const struct ivi_rectangle *boundingbox,
457 struct ivi_rectangle *rect_output)
458{
459 struct weston_matrix m;
460 struct weston_vector top_left;
461 struct weston_vector bottom_right;
462
463 assert(boundingbox != rect_output);
464
465 if (weston_matrix_invert(&m, matrix) < 0) {
466 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
467 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
468 rect_output->x = boundingbox->x;
469 rect_output->y = boundingbox->y;
470 rect_output->width = boundingbox->width;
471 rect_output->height = boundingbox->height;
472 }
473
474 /* The vectors and matrices involved will always produce f[3] == 1.0. */
475 top_left.f[0] = rect_input->x;
476 top_left.f[1] = rect_input->y;
477 top_left.f[2] = 0.0f;
478 top_left.f[3] = 1.0f;
479
480 bottom_right.f[0] = rect_input->x + rect_input->width;
481 bottom_right.f[1] = rect_input->y + rect_input->height;
482 bottom_right.f[2] = 0.0f;
483 bottom_right.f[3] = 1.0f;
484
485 weston_matrix_transform(&m, &top_left);
486 weston_matrix_transform(&m, &bottom_right);
487
488 if (top_left.f[0] < bottom_right.f[0]) {
489 rect_output->x = top_left.f[0];
490 rect_output->width = bottom_right.f[0] - rect_output->x;
491 } else {
492 rect_output->x = bottom_right.f[0];
493 rect_output->width = top_left.f[0] - rect_output->x;
494 }
495
496 if (top_left.f[1] < bottom_right.f[1]) {
497 rect_output->y = top_left.f[1];
498 rect_output->height = bottom_right.f[1] - rect_output->y;
499 } else {
500 rect_output->y = bottom_right.f[1];
501 rect_output->height = top_left.f[1] - rect_output->y;
502 }
503
504 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
505}
506
507/**
508 * This computes the whole transformation matrix:m from surface-local
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900509 * coordinates to multi screens coordinate, which is global coordinates.
510 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900511 *
512 * Additionally, this computes the mask on surface-local coordinates as a
513 * ivi_rectangle. This can be set to weston_view_set_mask.
514 *
515 * The mask is computed by following steps
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900516 * - destination rectangle of layer is tansformed to multi screen coordinate,
517 * global coordinates. This is done by adding weston_output.{x,y} in simple
518 * because there is no scaled and rotated transformation.
519 * - destination rectangle of layer in multi screens coordinate needs to be
520 * intersected inside of a screen the layer is assigned to. This is because
521 * overlapped region of weston surface in another screen shall not be
522 * displayed according to ivi use case.
523 * - destination rectangle of layer
524 * - in multi screen coordinates,
525 * - and intersected inside of an assigned screen,
526 * is inversed to surface-local cooodinates by inversed matrix:m.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900527 * - the area is intersected by intersected area between weston_surface and
528 * source rectangle of ivi_surface.
529 */
530static void
531calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900532 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900533 struct ivi_layout_layer *ivilayer,
534 struct ivi_layout_surface *ivisurf,
535 struct weston_matrix *m,
536 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900537{
538 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
539 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900540 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900541 struct ivi_rectangle weston_surface_rect = { 0,
542 0,
543 ivisurf->surface->width,
544 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900545 struct ivi_rectangle surface_source_rect = { sp->source_x,
546 sp->source_y,
547 sp->source_width,
548 sp->source_height };
549 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
550 sp->dest_y,
551 sp->dest_width,
552 sp->dest_height };
553 struct ivi_rectangle layer_source_rect = { lp->source_x,
554 lp->source_y,
555 lp->source_width,
556 lp->source_height };
557 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
558 lp->dest_y,
559 lp->dest_width,
560 lp->dest_height };
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900561 struct ivi_rectangle screen_dest_rect = { output->x,
562 output->y,
563 output->width,
564 output->height };
565 struct ivi_rectangle layer_dest_rect_in_global =
566 { lp->dest_x + output->x,
567 lp->dest_y + output->y,
568 lp->dest_width,
569 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900570 struct ivi_rectangle surface_result;
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900571 struct ivi_rectangle layer_dest_rect_in_global_intersected;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900572
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900573 /*
574 * the whole transformation matrix:m from surface-local
575 * coordinates to global coordinates, which is computed by
576 * two steps,
577 * - surface-local coordinates to layer-local coordinates
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900578 * - layer-local coordinates to a single screen-local coordinates
579 * - a single screen-local coordinates to multi screen coordinates,
580 * which is global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900581 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900582 calc_transformation_matrix(&surface_source_rect,
583 &surface_dest_rect,
584 sp->orientation, m);
585
586 calc_transformation_matrix(&layer_source_rect,
587 &layer_dest_rect,
588 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900589
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900590 weston_matrix_translate(m, output->x, output->y, 0.0f);
591
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900592 /* this intersected ivi_rectangle would be used for masking
593 * weston_surface
594 */
595 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
596 &surface_result);
597
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900598 /*
599 * destination rectangle of layer in multi screens coordinate
600 * is intersected to avoid displaying outside of an assigned screen.
601 */
602 ivi_rectangle_intersect(&layer_dest_rect_in_global, &screen_dest_rect,
603 &layer_dest_rect_in_global_intersected);
604
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900605 /* calc masking area of weston_surface from m */
606 calc_inverse_matrix_transform(m,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900607 &layer_dest_rect_in_global_intersected,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900608 &surface_result,
609 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900610}
611
612static void
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900613update_prop(struct ivi_layout_screen *iviscrn,
614 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900615 struct ivi_layout_surface *ivisurf)
616{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900617 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900618 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900619 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900620
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900621 /*In case of no prop change, this just returns*/
622 if (!ivilayer->event_mask && !ivisurf->event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900623 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900624
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900625 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900626
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000627 tmpview = get_weston_view(ivisurf);
628 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900629
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900630 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
631 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
632 can_calc = false;
633 }
634
635 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
636 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
637 can_calc = false;
638 }
639
640 if (can_calc) {
641 wl_list_remove(&ivisurf->transform.link);
642 weston_matrix_init(&ivisurf->transform.matrix);
643
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900644 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900645 iviscrn, ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900646
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000647 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
648 wl_list_insert(&tmpview->geometry.transformation_list,
649 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900650
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000651 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900652 }
653
654 ivisurf->update_count++;
655
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000656 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900657
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000658 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900659}
660
661static void
662commit_changes(struct ivi_layout *layout)
663{
664 struct ivi_layout_screen *iviscrn = NULL;
665 struct ivi_layout_layer *ivilayer = NULL;
666 struct ivi_layout_surface *ivisurf = NULL;
667
668 wl_list_for_each(iviscrn, &layout->screen_list, link) {
669 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900670 /*
671 * If ivilayer is invisible, weston_view of ivisurf doesn't
672 * need to be modified.
673 */
674 if (ivilayer->prop.visibility == false)
675 continue;
676
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900677 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900678 /*
679 * If ivilayer is invisible, weston_view of ivisurf doesn't
680 * need to be modified.
681 */
682 if (ivisurf->prop.visibility == false)
683 continue;
684
685 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900686 }
687 }
688 }
689}
690
691static void
692commit_surface_list(struct ivi_layout *layout)
693{
694 struct ivi_layout_surface *ivisurf = NULL;
695 int32_t dest_x = 0;
696 int32_t dest_y = 0;
697 int32_t dest_width = 0;
698 int32_t dest_height = 0;
699 int32_t configured = 0;
700
701 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300702 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900703 dest_x = ivisurf->prop.dest_x;
704 dest_y = ivisurf->prop.dest_y;
705 dest_width = ivisurf->prop.dest_width;
706 dest_height = ivisurf->prop.dest_height;
707
708 ivi_layout_transition_move_resize_view(ivisurf,
709 ivisurf->pending.prop.dest_x,
710 ivisurf->pending.prop.dest_y,
711 ivisurf->pending.prop.dest_width,
712 ivisurf->pending.prop.dest_height,
713 ivisurf->pending.prop.transition_duration);
714
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300715 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900716 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
717 } else {
718 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
719 }
720
721 ivisurf->prop = ivisurf->pending.prop;
722 ivisurf->prop.dest_x = dest_x;
723 ivisurf->prop.dest_y = dest_y;
724 ivisurf->prop.dest_width = dest_width;
725 ivisurf->prop.dest_height = dest_height;
726 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
727 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
728
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300729 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900730 dest_x = ivisurf->prop.dest_x;
731 dest_y = ivisurf->prop.dest_y;
732 dest_width = ivisurf->prop.dest_width;
733 dest_height = ivisurf->prop.dest_height;
734
735 ivi_layout_transition_move_resize_view(ivisurf,
736 ivisurf->pending.prop.dest_x,
737 ivisurf->pending.prop.dest_y,
738 ivisurf->pending.prop.dest_width,
739 ivisurf->pending.prop.dest_height,
740 ivisurf->pending.prop.transition_duration);
741
742 ivisurf->prop = ivisurf->pending.prop;
743 ivisurf->prop.dest_x = dest_x;
744 ivisurf->prop.dest_y = dest_y;
745 ivisurf->prop.dest_width = dest_width;
746 ivisurf->prop.dest_height = dest_height;
747
748 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
749 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
750
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300751 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900752 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300753 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900754 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
755 } else {
756 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
757 }
758
759 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
760 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
761 configured = 1;
762 }
763
764 ivisurf->prop = ivisurf->pending.prop;
765 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
766 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
767
Pekka Paalanen1f821932016-03-15 16:57:51 +0200768 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200769 shell_surface_send_configure(ivisurf->surface,
770 ivisurf->prop.dest_width,
771 ivisurf->prop.dest_height);
772 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900773 } else {
774 configured = 0;
775 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
776 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
777 configured = 1;
778 }
779
780 ivisurf->prop = ivisurf->pending.prop;
781 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
782 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
783
Pekka Paalanen1f821932016-03-15 16:57:51 +0200784 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200785 shell_surface_send_configure(ivisurf->surface,
786 ivisurf->prop.dest_width,
787 ivisurf->prop.dest_height);
788 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900789 }
790 }
791}
792
793static void
794commit_layer_list(struct ivi_layout *layout)
795{
796 struct ivi_layout_layer *ivilayer = NULL;
797 struct ivi_layout_surface *ivisurf = NULL;
798 struct ivi_layout_surface *next = NULL;
799
800 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300801 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900802 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 -0300803 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900804 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
805 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
806 NULL, NULL,
807 ivilayer->pending.prop.transition_duration);
808 }
809 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
810
811 ivilayer->prop = ivilayer->pending.prop;
812
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000813 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900814 continue;
815 }
816
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000817 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
818 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000819 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000820 wl_list_remove(&ivisurf->order.link);
821 wl_list_init(&ivisurf->order.link);
822 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900823 }
824
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000825 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900826
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000827 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900828 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000829 wl_list_remove(&ivisurf->order.link);
830 wl_list_insert(&ivilayer->order.surface_list,
831 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000832 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000833 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900834 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000835
836 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900837 }
838}
839
840static void
841commit_screen_list(struct ivi_layout *layout)
842{
843 struct ivi_layout_screen *iviscrn = NULL;
844 struct ivi_layout_layer *ivilayer = NULL;
845 struct ivi_layout_layer *next = NULL;
846 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000847 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900848
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900849 /* Clear view list of layout ivi_layer */
850 wl_list_init(&layout->layout_layer.view_list.link);
851
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900852 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000853 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900854 wl_list_for_each_safe(ivilayer, next,
855 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000856 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000857 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900858 wl_list_init(&ivilayer->order.link);
859 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
860 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900861
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000862 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900863
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900864 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
865 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900866 /* FIXME: avoid to insert order.link to multiple screens */
867 wl_list_remove(&ivilayer->order.link);
868
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900869 wl_list_insert(&iviscrn->order.layer_list,
870 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000871 ivilayer->on_screen = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900872 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
873 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900874
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000875 iviscrn->order.dirty = 0;
876 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900877
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900878 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
879 if (ivilayer->prop.visibility == false)
880 continue;
881
882 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900883 if (ivisurf->prop.visibility == false)
884 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000885
886 tmpview = get_weston_view(ivisurf);
887 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900888
889 weston_layer_entry_insert(&layout->layout_layer.view_list,
890 &tmpview->layer_link);
891
892 ivisurf->surface->output = iviscrn->output;
893 }
894 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900895 }
896}
897
898static void
899commit_transition(struct ivi_layout* layout)
900{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300901 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900902 return;
903 }
904
905 wl_list_insert_list(&layout->transitions->transition_list,
906 &layout->pending_transition_list);
907
908 wl_list_init(&layout->pending_transition_list);
909
910 wl_event_source_timer_update(layout->transitions->event_source, 1);
911}
912
913static void
914send_surface_prop(struct ivi_layout_surface *ivisurf)
915{
916 wl_signal_emit(&ivisurf->property_changed, ivisurf);
917 ivisurf->event_mask = 0;
918}
919
920static void
921send_layer_prop(struct ivi_layout_layer *ivilayer)
922{
923 wl_signal_emit(&ivilayer->property_changed, ivilayer);
924 ivilayer->event_mask = 0;
925}
926
927static void
928send_prop(struct ivi_layout *layout)
929{
930 struct ivi_layout_layer *ivilayer = NULL;
931 struct ivi_layout_surface *ivisurf = NULL;
932
933 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900934 if (ivilayer->event_mask)
935 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900936 }
937
938 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900939 if (ivisurf->event_mask)
940 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900941 }
942}
943
944static void
945clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
946{
947 struct ivi_layout_surface *surface_link = NULL;
948 struct ivi_layout_surface *surface_next = NULL;
949
950 wl_list_for_each_safe(surface_link, surface_next,
951 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000952 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900953 wl_list_init(&surface_link->pending.link);
954 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900955}
956
957static void
958clear_surface_order_list(struct ivi_layout_layer *ivilayer)
959{
960 struct ivi_layout_surface *surface_link = NULL;
961 struct ivi_layout_surface *surface_next = NULL;
962
963 wl_list_for_each_safe(surface_link, surface_next,
964 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000965 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900966 wl_list_init(&surface_link->order.link);
967 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900968}
969
970static void
971layer_created(struct wl_listener *listener, void *data)
972{
973 struct ivi_layout_layer *ivilayer = data;
974
975 struct listener_layout_notification *notification =
976 container_of(listener,
977 struct listener_layout_notification,
978 listener);
979
980 struct ivi_layout_notification_callback *created_callback =
981 notification->userdata;
982
983 ((layer_create_notification_func)created_callback->callback)
984 (ivilayer, created_callback->data);
985}
986
987static void
988layer_removed(struct wl_listener *listener, void *data)
989{
990 struct ivi_layout_layer *ivilayer = data;
991
992 struct listener_layout_notification *notification =
993 container_of(listener,
994 struct listener_layout_notification,
995 listener);
996
997 struct ivi_layout_notification_callback *removed_callback =
998 notification->userdata;
999
1000 ((layer_remove_notification_func)removed_callback->callback)
1001 (ivilayer, removed_callback->data);
1002}
1003
1004static void
1005layer_prop_changed(struct wl_listener *listener, void *data)
1006{
1007 struct ivi_layout_layer *ivilayer = data;
1008
1009 struct listener_layout_notification *layout_listener =
1010 container_of(listener,
1011 struct listener_layout_notification,
1012 listener);
1013
1014 struct ivi_layout_notification_callback *prop_callback =
1015 layout_listener->userdata;
1016
1017 ((layer_property_notification_func)prop_callback->callback)
1018 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1019}
1020
1021static void
1022surface_created(struct wl_listener *listener, void *data)
1023{
1024 struct ivi_layout_surface *ivisurface = data;
1025
1026 struct listener_layout_notification *notification =
1027 container_of(listener,
1028 struct listener_layout_notification,
1029 listener);
1030
1031 struct ivi_layout_notification_callback *created_callback =
1032 notification->userdata;
1033
1034 ((surface_create_notification_func)created_callback->callback)
1035 (ivisurface, created_callback->data);
1036}
1037
1038static void
1039surface_removed(struct wl_listener *listener, void *data)
1040{
1041 struct ivi_layout_surface *ivisurface = data;
1042
1043 struct listener_layout_notification *notification =
1044 container_of(listener,
1045 struct listener_layout_notification,
1046 listener);
1047
1048 struct ivi_layout_notification_callback *removed_callback =
1049 notification->userdata;
1050
1051 ((surface_remove_notification_func)removed_callback->callback)
1052 (ivisurface, removed_callback->data);
1053}
1054
1055static void
1056surface_prop_changed(struct wl_listener *listener, void *data)
1057{
1058 struct ivi_layout_surface *ivisurf = data;
1059
1060 struct listener_layout_notification *layout_listener =
1061 container_of(listener,
1062 struct listener_layout_notification,
1063 listener);
1064
1065 struct ivi_layout_notification_callback *prop_callback =
1066 layout_listener->userdata;
1067
1068 ((surface_property_notification_func)prop_callback->callback)
1069 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1070
1071 ivisurf->event_mask = 0;
1072}
1073
1074static void
1075surface_configure_changed(struct wl_listener *listener,
1076 void *data)
1077{
1078 struct ivi_layout_surface *ivisurface = data;
1079
1080 struct listener_layout_notification *notification =
1081 container_of(listener,
1082 struct listener_layout_notification,
1083 listener);
1084
1085 struct ivi_layout_notification_callback *configure_changed_callback =
1086 notification->userdata;
1087
1088 ((surface_configure_notification_func)configure_changed_callback->callback)
1089 (ivisurface, configure_changed_callback->data);
1090}
1091
1092static int32_t
1093add_notification(struct wl_signal *signal,
1094 wl_notify_func_t callback,
1095 void *userdata)
1096{
1097 struct listener_layout_notification *notification = NULL;
1098
1099 notification = malloc(sizeof *notification);
1100 if (notification == NULL) {
1101 weston_log("fails to allocate memory\n");
1102 free(userdata);
1103 return IVI_FAILED;
1104 }
1105
1106 notification->listener.notify = callback;
1107 notification->userdata = userdata;
1108
1109 wl_signal_add(signal, &notification->listener);
1110
1111 return IVI_SUCCEEDED;
1112}
1113
1114static void
1115remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1116{
1117 struct wl_listener *listener = NULL;
1118 struct wl_listener *next = NULL;
1119
1120 wl_list_for_each_safe(listener, next, listener_list, link) {
1121 struct listener_layout_notification *notification =
1122 container_of(listener,
1123 struct listener_layout_notification,
1124 listener);
1125
1126 struct ivi_layout_notification_callback *notification_callback =
1127 notification->userdata;
1128
1129 if ((notification_callback->callback != callback) ||
1130 (notification_callback->data != userdata)) {
1131 continue;
1132 }
1133
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001134 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001135
1136 free(notification->userdata);
1137 free(notification);
1138 }
1139}
1140
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001141/**
1142 * Exported APIs of ivi-layout library are implemented from here.
1143 * Brief of APIs is described in ivi-layout-export.h.
1144 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001145static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001146ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1147 void *userdata)
1148{
1149 struct ivi_layout *layout = get_instance();
1150 struct ivi_layout_notification_callback *created_callback = NULL;
1151
1152 if (callback == NULL) {
1153 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1154 return IVI_FAILED;
1155 }
1156
1157 created_callback = malloc(sizeof *created_callback);
1158 if (created_callback == NULL) {
1159 weston_log("fails to allocate memory\n");
1160 return IVI_FAILED;
1161 }
1162
1163 created_callback->callback = callback;
1164 created_callback->data = userdata;
1165
1166 return add_notification(&layout->layer_notification.created,
1167 layer_created,
1168 created_callback);
1169}
1170
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001171static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001172ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1173 void *userdata)
1174{
1175 struct ivi_layout *layout = get_instance();
1176 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1177}
1178
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001179static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001180ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1181 void *userdata)
1182{
1183 struct ivi_layout *layout = get_instance();
1184 struct ivi_layout_notification_callback *removed_callback = NULL;
1185
1186 if (callback == NULL) {
1187 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1188 return IVI_FAILED;
1189 }
1190
1191 removed_callback = malloc(sizeof *removed_callback);
1192 if (removed_callback == NULL) {
1193 weston_log("fails to allocate memory\n");
1194 return IVI_FAILED;
1195 }
1196
1197 removed_callback->callback = callback;
1198 removed_callback->data = userdata;
1199 return add_notification(&layout->layer_notification.removed,
1200 layer_removed,
1201 removed_callback);
1202}
1203
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001204static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001205ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1206 void *userdata)
1207{
1208 struct ivi_layout *layout = get_instance();
1209 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1210}
1211
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001212static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001213ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1214 void *userdata)
1215{
1216 struct ivi_layout *layout = get_instance();
1217 struct ivi_layout_notification_callback *created_callback = NULL;
1218
1219 if (callback == NULL) {
1220 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1221 return IVI_FAILED;
1222 }
1223
1224 created_callback = malloc(sizeof *created_callback);
1225 if (created_callback == NULL) {
1226 weston_log("fails to allocate memory\n");
1227 return IVI_FAILED;
1228 }
1229
1230 created_callback->callback = callback;
1231 created_callback->data = userdata;
1232
1233 return add_notification(&layout->surface_notification.created,
1234 surface_created,
1235 created_callback);
1236}
1237
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001238static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001239ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1240 void *userdata)
1241{
1242 struct ivi_layout *layout = get_instance();
1243 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1244}
1245
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001246static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001247ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1248 void *userdata)
1249{
1250 struct ivi_layout *layout = get_instance();
1251 struct ivi_layout_notification_callback *removed_callback = NULL;
1252
1253 if (callback == NULL) {
1254 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1255 return IVI_FAILED;
1256 }
1257
1258 removed_callback = malloc(sizeof *removed_callback);
1259 if (removed_callback == NULL) {
1260 weston_log("fails to allocate memory\n");
1261 return IVI_FAILED;
1262 }
1263
1264 removed_callback->callback = callback;
1265 removed_callback->data = userdata;
1266
1267 return add_notification(&layout->surface_notification.removed,
1268 surface_removed,
1269 removed_callback);
1270}
1271
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001272static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001273ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1274 void *userdata)
1275{
1276 struct ivi_layout *layout = get_instance();
1277 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1278}
1279
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001280static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001281ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1282 void *userdata)
1283{
1284 struct ivi_layout *layout = get_instance();
1285 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1286 if (callback == NULL) {
1287 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1288 return IVI_FAILED;
1289 }
1290
1291 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1292 if (configure_changed_callback == NULL) {
1293 weston_log("fails to allocate memory\n");
1294 return IVI_FAILED;
1295 }
1296
1297 configure_changed_callback->callback = callback;
1298 configure_changed_callback->data = userdata;
1299
1300 return add_notification(&layout->surface_notification.configure_changed,
1301 surface_configure_changed,
1302 configure_changed_callback);
1303}
1304
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001305static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001306ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1307 void *userdata)
1308{
1309 struct ivi_layout *layout = get_instance();
1310 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1311}
1312
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001313uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001314ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1315{
1316 return ivisurf->id_surface;
1317}
1318
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001319static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001320ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1321{
1322 return ivilayer->id_layer;
1323}
1324
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001325static uint32_t
1326ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1327{
1328 return iviscrn->id_screen;
1329}
1330
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001331static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001332ivi_layout_get_layer_from_id(uint32_t id_layer)
1333{
1334 struct ivi_layout *layout = get_instance();
1335 struct ivi_layout_layer *ivilayer = NULL;
1336
1337 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1338 if (ivilayer->id_layer == id_layer) {
1339 return ivilayer;
1340 }
1341 }
1342
1343 return NULL;
1344}
1345
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001346struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001347ivi_layout_get_surface_from_id(uint32_t id_surface)
1348{
1349 struct ivi_layout *layout = get_instance();
1350 struct ivi_layout_surface *ivisurf = NULL;
1351
1352 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1353 if (ivisurf->id_surface == id_surface) {
1354 return ivisurf;
1355 }
1356 }
1357
1358 return NULL;
1359}
1360
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001361static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001362ivi_layout_get_screen_from_id(uint32_t id_screen)
1363{
1364 struct ivi_layout *layout = get_instance();
1365 struct ivi_layout_screen *iviscrn = NULL;
1366
1367 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Nobuhiko Tanibata3e710d12015-11-25 23:36:09 +09001368 if (iviscrn->id_screen == id_screen)
1369 return iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001370 }
1371
1372 return NULL;
1373}
1374
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001375static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001376ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1377 int32_t *pWidth, int32_t *pHeight)
1378{
1379 struct weston_output *output = NULL;
1380
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001381 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001382 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1383 return IVI_FAILED;
1384 }
1385
1386 output = iviscrn->output;
1387 *pWidth = output->current_mode->width;
1388 *pHeight = output->current_mode->height;
1389
1390 return IVI_SUCCEEDED;
1391}
1392
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001393static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001394ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1395 surface_property_notification_func callback,
1396 void *userdata)
1397{
1398 struct listener_layout_notification* notification = NULL;
1399 struct ivi_layout_notification_callback *prop_callback = NULL;
1400
1401 if (ivisurf == NULL || callback == NULL) {
1402 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1403 return IVI_FAILED;
1404 }
1405
1406 notification = malloc(sizeof *notification);
1407 if (notification == NULL) {
1408 weston_log("fails to allocate memory\n");
1409 return IVI_FAILED;
1410 }
1411
1412 prop_callback = malloc(sizeof *prop_callback);
1413 if (prop_callback == NULL) {
1414 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001415 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001416 return IVI_FAILED;
1417 }
1418
1419 prop_callback->callback = callback;
1420 prop_callback->data = userdata;
1421
1422 notification->listener.notify = surface_prop_changed;
1423 notification->userdata = prop_callback;
1424
1425 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1426
1427 return IVI_SUCCEEDED;
1428}
1429
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001430static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001431ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1432{
1433 if (ivilayer == NULL) {
1434 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1435 return NULL;
1436 }
1437
1438 return &ivilayer->prop;
1439}
1440
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001441static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001442ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1443{
1444 struct ivi_layout *layout = get_instance();
1445 struct ivi_layout_screen *iviscrn = NULL;
1446 int32_t length = 0;
1447 int32_t n = 0;
1448
1449 if (pLength == NULL || ppArray == NULL) {
1450 weston_log("ivi_layout_get_screens: invalid argument\n");
1451 return IVI_FAILED;
1452 }
1453
1454 length = wl_list_length(&layout->screen_list);
1455
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001456 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001457 /* the Array must be free by module which called this function */
1458 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1459 if (*ppArray == NULL) {
1460 weston_log("fails to allocate memory\n");
1461 return IVI_FAILED;
1462 }
1463
1464 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1465 (*ppArray)[n++] = iviscrn;
1466 }
1467 }
1468
1469 *pLength = length;
1470
1471 return IVI_SUCCEEDED;
1472}
1473
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001474static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001475ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1476 int32_t *pLength,
1477 struct ivi_layout_screen ***ppArray)
1478{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001479 int32_t length = 0;
1480 int32_t n = 0;
1481
1482 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1483 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1484 return IVI_FAILED;
1485 }
1486
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001487 if (ivilayer->on_screen != NULL)
1488 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001489
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001490 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001491 /* the Array must be free by module which called this function */
1492 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1493 if (*ppArray == NULL) {
1494 weston_log("fails to allocate memory\n");
1495 return IVI_FAILED;
1496 }
1497
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001498 (*ppArray)[n++] = ivilayer->on_screen;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001499 }
1500
1501 *pLength = length;
1502
1503 return IVI_SUCCEEDED;
1504}
1505
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001506static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001507ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1508{
1509 struct ivi_layout *layout = get_instance();
1510 struct ivi_layout_layer *ivilayer = NULL;
1511 int32_t length = 0;
1512 int32_t n = 0;
1513
1514 if (pLength == NULL || ppArray == NULL) {
1515 weston_log("ivi_layout_get_layers: invalid argument\n");
1516 return IVI_FAILED;
1517 }
1518
1519 length = wl_list_length(&layout->layer_list);
1520
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001521 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001522 /* the Array must be free by module which called this function */
1523 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1524 if (*ppArray == NULL) {
1525 weston_log("fails to allocate memory\n");
1526 return IVI_FAILED;
1527 }
1528
1529 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1530 (*ppArray)[n++] = ivilayer;
1531 }
1532 }
1533
1534 *pLength = length;
1535
1536 return IVI_SUCCEEDED;
1537}
1538
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001539static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001540ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1541 int32_t *pLength,
1542 struct ivi_layout_layer ***ppArray)
1543{
1544 struct ivi_layout_layer *ivilayer = NULL;
1545 int32_t length = 0;
1546 int32_t n = 0;
1547
1548 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1549 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1550 return IVI_FAILED;
1551 }
1552
1553 length = wl_list_length(&iviscrn->order.layer_list);
1554
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001555 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001556 /* the Array must be free by module which called this function */
1557 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1558 if (*ppArray == NULL) {
1559 weston_log("fails to allocate memory\n");
1560 return IVI_FAILED;
1561 }
1562
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001563 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001564 (*ppArray)[n++] = ivilayer;
1565 }
1566 }
1567
1568 *pLength = length;
1569
1570 return IVI_SUCCEEDED;
1571}
1572
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001573static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001574ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1575 int32_t *pLength,
1576 struct ivi_layout_layer ***ppArray)
1577{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001578 int32_t length = 0;
1579 int32_t n = 0;
1580
1581 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1582 weston_log("ivi_layout_getLayers: invalid argument\n");
1583 return IVI_FAILED;
1584 }
1585
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001586 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001587 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001588 length = 1;
1589 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001590 if (*ppArray == NULL) {
1591 weston_log("fails to allocate memory\n");
1592 return IVI_FAILED;
1593 }
1594
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001595 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001596 }
1597
1598 *pLength = length;
1599
1600 return IVI_SUCCEEDED;
1601}
1602
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001603static
1604int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001605ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1606{
1607 struct ivi_layout *layout = get_instance();
1608 struct ivi_layout_surface *ivisurf = NULL;
1609 int32_t length = 0;
1610 int32_t n = 0;
1611
1612 if (pLength == NULL || ppArray == NULL) {
1613 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1614 return IVI_FAILED;
1615 }
1616
1617 length = wl_list_length(&layout->surface_list);
1618
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001619 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001620 /* the Array must be free by module which called this function */
1621 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1622 if (*ppArray == NULL) {
1623 weston_log("fails to allocate memory\n");
1624 return IVI_FAILED;
1625 }
1626
1627 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1628 (*ppArray)[n++] = ivisurf;
1629 }
1630 }
1631
1632 *pLength = length;
1633
1634 return IVI_SUCCEEDED;
1635}
1636
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001637static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001638ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1639 int32_t *pLength,
1640 struct ivi_layout_surface ***ppArray)
1641{
1642 struct ivi_layout_surface *ivisurf = NULL;
1643 int32_t length = 0;
1644 int32_t n = 0;
1645
1646 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1647 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1648 return IVI_FAILED;
1649 }
1650
1651 length = wl_list_length(&ivilayer->order.surface_list);
1652
1653 if (length != 0) {
1654 /* the Array must be free by module which called this function */
1655 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1656 if (*ppArray == NULL) {
1657 weston_log("fails to allocate memory\n");
1658 return IVI_FAILED;
1659 }
1660
1661 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1662 (*ppArray)[n++] = ivisurf;
1663 }
1664 }
1665
1666 *pLength = length;
1667
1668 return IVI_SUCCEEDED;
1669}
1670
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001671static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001672ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1673 int32_t width, int32_t height)
1674{
1675 struct ivi_layout *layout = get_instance();
1676 struct ivi_layout_layer *ivilayer = NULL;
1677
1678 ivilayer = get_layer(&layout->layer_list, id_layer);
1679 if (ivilayer != NULL) {
1680 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001681 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001682 return ivilayer;
1683 }
1684
1685 ivilayer = calloc(1, sizeof *ivilayer);
1686 if (ivilayer == NULL) {
1687 weston_log("fails to allocate memory\n");
1688 return NULL;
1689 }
1690
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001691 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001692 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001693 ivilayer->layout = layout;
1694 ivilayer->id_layer = id_layer;
1695
1696 init_layer_properties(&ivilayer->prop, width, height);
1697 ivilayer->event_mask = 0;
1698
1699 wl_list_init(&ivilayer->pending.surface_list);
1700 wl_list_init(&ivilayer->pending.link);
1701 ivilayer->pending.prop = ivilayer->prop;
1702
1703 wl_list_init(&ivilayer->order.surface_list);
1704 wl_list_init(&ivilayer->order.link);
1705
1706 wl_list_insert(&layout->layer_list, &ivilayer->link);
1707
1708 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1709
1710 return ivilayer;
1711}
1712
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001713static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001714ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1715{
1716 if (ivilayer == NULL) {
1717 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1718 return;
1719 }
1720
1721 remove_all_notification(&ivilayer->property_changed.listener_list);
1722}
1723
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001724static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001725ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1726 layer_property_notification_func callback,
1727 void *userdata)
1728{
1729 if (ivilayer == NULL) {
1730 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1731 return;
1732 }
1733
1734 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1735}
1736
1737static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001738ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001739{
1740 struct ivi_layout *layout = get_instance();
1741
1742 if (ivilayer == NULL) {
1743 weston_log("ivi_layout_layer_remove: invalid argument\n");
1744 return;
1745 }
1746
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001747 if (--ivilayer->ref_count > 0)
1748 return;
1749
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001750 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1751
1752 clear_surface_pending_list(ivilayer);
1753 clear_surface_order_list(ivilayer);
1754
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001755 wl_list_remove(&ivilayer->pending.link);
1756 wl_list_remove(&ivilayer->order.link);
1757 wl_list_remove(&ivilayer->link);
1758
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001759 ivi_layout_layer_remove_notification(ivilayer);
1760
1761 free(ivilayer);
1762}
1763
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001764int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001765ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1766 bool newVisibility)
1767{
1768 struct ivi_layout_layer_properties *prop = NULL;
1769
1770 if (ivilayer == NULL) {
1771 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1772 return IVI_FAILED;
1773 }
1774
1775 prop = &ivilayer->pending.prop;
1776 prop->visibility = newVisibility;
1777
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001778 if (ivilayer->prop.visibility != newVisibility)
1779 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1780 else
1781 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001782
1783 return IVI_SUCCEEDED;
1784}
1785
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001786int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001787ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1788 wl_fixed_t opacity)
1789{
1790 struct ivi_layout_layer_properties *prop = NULL;
1791
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001792 if (ivilayer == NULL ||
1793 opacity < wl_fixed_from_double(0.0) ||
1794 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001795 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1796 return IVI_FAILED;
1797 }
1798
1799 prop = &ivilayer->pending.prop;
1800 prop->opacity = opacity;
1801
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001802 if (ivilayer->prop.opacity != opacity)
1803 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1804 else
1805 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001806
1807 return IVI_SUCCEEDED;
1808}
1809
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001810static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001811ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1812 int32_t x, int32_t y,
1813 int32_t width, int32_t height)
1814{
1815 struct ivi_layout_layer_properties *prop = NULL;
1816
1817 if (ivilayer == NULL) {
1818 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1819 return IVI_FAILED;
1820 }
1821
1822 prop = &ivilayer->pending.prop;
1823 prop->source_x = x;
1824 prop->source_y = y;
1825 prop->source_width = width;
1826 prop->source_height = height;
1827
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001828 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1829 ivilayer->prop.source_width != width ||
1830 ivilayer->prop.source_height != height)
1831 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1832 else
1833 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001834
1835 return IVI_SUCCEEDED;
1836}
1837
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001838int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001839ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1840 int32_t x, int32_t y,
1841 int32_t width, int32_t height)
1842{
1843 struct ivi_layout_layer_properties *prop = NULL;
1844
1845 if (ivilayer == NULL) {
1846 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1847 return IVI_FAILED;
1848 }
1849
1850 prop = &ivilayer->pending.prop;
1851 prop->dest_x = x;
1852 prop->dest_y = y;
1853 prop->dest_width = width;
1854 prop->dest_height = height;
1855
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001856 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1857 ivilayer->prop.dest_width != width ||
1858 ivilayer->prop.dest_height != height)
1859 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1860 else
1861 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001862
1863 return IVI_SUCCEEDED;
1864}
1865
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001866static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001867ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1868 enum wl_output_transform orientation)
1869{
1870 struct ivi_layout_layer_properties *prop = NULL;
1871
1872 if (ivilayer == NULL) {
1873 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1874 return IVI_FAILED;
1875 }
1876
1877 prop = &ivilayer->pending.prop;
1878 prop->orientation = orientation;
1879
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001880 if (ivilayer->prop.orientation != orientation)
1881 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1882 else
1883 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001884
1885 return IVI_SUCCEEDED;
1886}
1887
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001888int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001889ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1890 struct ivi_layout_surface **pSurface,
1891 int32_t number)
1892{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001893 int32_t i = 0;
1894
1895 if (ivilayer == NULL) {
1896 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1897 return IVI_FAILED;
1898 }
1899
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001900 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001901
1902 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)72ad1642016-03-16 13:37:05 +00001903 wl_list_remove(&pSurface[i]->pending.link);
1904 wl_list_insert(&ivilayer->pending.surface_list,
1905 &pSurface[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001906 }
1907
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001908 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001909
1910 return IVI_SUCCEEDED;
1911}
1912
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001913int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001914ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1915 bool newVisibility)
1916{
1917 struct ivi_layout_surface_properties *prop = NULL;
1918
1919 if (ivisurf == NULL) {
1920 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1921 return IVI_FAILED;
1922 }
1923
1924 prop = &ivisurf->pending.prop;
1925 prop->visibility = newVisibility;
1926
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001927 if (ivisurf->prop.visibility != newVisibility)
1928 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1929 else
1930 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001931
1932 return IVI_SUCCEEDED;
1933}
1934
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001935int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001936ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1937 wl_fixed_t opacity)
1938{
1939 struct ivi_layout_surface_properties *prop = NULL;
1940
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001941 if (ivisurf == NULL ||
1942 opacity < wl_fixed_from_double(0.0) ||
1943 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001944 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1945 return IVI_FAILED;
1946 }
1947
1948 prop = &ivisurf->pending.prop;
1949 prop->opacity = opacity;
1950
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001951 if (ivisurf->prop.opacity != opacity)
1952 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
1953 else
1954 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001955
1956 return IVI_SUCCEEDED;
1957}
1958
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001959int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001960ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1961 int32_t x, int32_t y,
1962 int32_t width, int32_t height)
1963{
1964 struct ivi_layout_surface_properties *prop = NULL;
1965
1966 if (ivisurf == NULL) {
1967 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1968 return IVI_FAILED;
1969 }
1970
1971 prop = &ivisurf->pending.prop;
1972 prop->start_x = prop->dest_x;
1973 prop->start_y = prop->dest_y;
1974 prop->dest_x = x;
1975 prop->dest_y = y;
1976 prop->start_width = prop->dest_width;
1977 prop->start_height = prop->dest_height;
1978 prop->dest_width = width;
1979 prop->dest_height = height;
1980
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001981 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
1982 ivisurf->prop.dest_width != width ||
1983 ivisurf->prop.dest_height != height)
1984 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1985 else
1986 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001987
1988 return IVI_SUCCEEDED;
1989}
1990
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001991static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001992ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
1993 enum wl_output_transform orientation)
1994{
1995 struct ivi_layout_surface_properties *prop = NULL;
1996
1997 if (ivisurf == NULL) {
1998 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
1999 return IVI_FAILED;
2000 }
2001
2002 prop = &ivisurf->pending.prop;
2003 prop->orientation = orientation;
2004
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002005 if (ivisurf->prop.orientation != orientation)
2006 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2007 else
2008 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002009
2010 return IVI_SUCCEEDED;
2011}
2012
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002013static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002014ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2015 struct ivi_layout_layer *addlayer)
2016{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002017 if (iviscrn == NULL || addlayer == NULL) {
2018 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2019 return IVI_FAILED;
2020 }
2021
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00002022 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002023 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2024 return IVI_SUCCEEDED;
2025 }
2026
Ucan, Emre (ADITG/SW1)f46306f2016-03-16 13:37:07 +00002027 wl_list_remove(&addlayer->pending.link);
2028 wl_list_insert(&iviscrn->pending.layer_list, &addlayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002029
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002030 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002031
2032 return IVI_SUCCEEDED;
2033}
2034
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002035static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002036ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2037 struct ivi_layout_layer **pLayer,
2038 const int32_t number)
2039{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002040 struct ivi_layout_layer *ivilayer = NULL;
2041 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002042 int32_t i = 0;
2043
2044 if (iviscrn == NULL) {
2045 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2046 return IVI_FAILED;
2047 }
2048
2049 wl_list_for_each_safe(ivilayer, next,
2050 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002051 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002052 wl_list_init(&ivilayer->pending.link);
2053 }
2054
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002055 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002056
2057 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)4e221f02016-03-16 13:37:08 +00002058 wl_list_remove(&pLayer[i]->pending.link);
2059 wl_list_insert(&iviscrn->pending.layer_list,
2060 &pLayer[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002061 }
2062
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002063 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002064
2065 return IVI_SUCCEEDED;
2066}
2067
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002068static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002069ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2070{
2071 return iviscrn->output;
2072}
2073
2074/**
2075 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2076 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2077 * This function is used to get the result of drawing by clients.
2078 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002079static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002080ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2081{
2082 return ivisurf != NULL ? ivisurf->surface : NULL;
2083}
2084
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002085static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002086ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2087 int32_t *width, int32_t *height,
2088 int32_t *stride)
2089{
2090 int32_t w;
2091 int32_t h;
2092 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2093
2094 if (ivisurf == NULL || ivisurf->surface == NULL) {
2095 weston_log("%s: invalid argument\n", __func__);
2096 return IVI_FAILED;
2097 }
2098
2099 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2100
2101 if (width != NULL)
2102 *width = w;
2103
2104 if (height != NULL)
2105 *height = h;
2106
2107 if (stride != NULL)
2108 *stride = w * bytespp;
2109
2110 return IVI_SUCCEEDED;
2111}
2112
2113static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002114ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2115 layer_property_notification_func callback,
2116 void *userdata)
2117{
2118 struct ivi_layout_notification_callback *prop_callback = NULL;
2119
2120 if (ivilayer == NULL || callback == NULL) {
2121 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2122 return IVI_FAILED;
2123 }
2124
2125 prop_callback = malloc(sizeof *prop_callback);
2126 if (prop_callback == NULL) {
2127 weston_log("fails to allocate memory\n");
2128 return IVI_FAILED;
2129 }
2130
2131 prop_callback->callback = callback;
2132 prop_callback->data = userdata;
2133
2134 return add_notification(&ivilayer->property_changed,
2135 layer_prop_changed,
2136 prop_callback);
2137}
2138
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002139static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002140ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2141{
2142 if (ivisurf == NULL) {
2143 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2144 return NULL;
2145 }
2146
2147 return &ivisurf->prop;
2148}
2149
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002150static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002151ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2152 struct ivi_layout_surface *addsurf)
2153{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002154 if (ivilayer == NULL || addsurf == NULL) {
2155 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2156 return IVI_FAILED;
2157 }
2158
Wataru Natsume9c926fe2016-03-03 19:56:09 +09002159 if (addsurf->on_layer == ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002160 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002161
Ucan, Emre (ADITG/SW1)10942372016-03-16 13:37:02 +00002162 wl_list_remove(&addsurf->pending.link);
2163 wl_list_insert(&ivilayer->pending.surface_list, &addsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002164
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002165 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002166
2167 return IVI_SUCCEEDED;
2168}
2169
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002170static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002171ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2172 struct ivi_layout_surface *remsurf)
2173{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002174 if (ivilayer == NULL || remsurf == NULL) {
2175 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2176 return;
2177 }
2178
Ucan, Emre (ADITG/SW1)536d8332016-03-16 13:36:59 +00002179 wl_list_remove(&remsurf->pending.link);
2180 wl_list_init(&remsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002181
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002182 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002183}
2184
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002185static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002186ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2187 int32_t x, int32_t y,
2188 int32_t width, int32_t height)
2189{
2190 struct ivi_layout_surface_properties *prop = NULL;
2191
2192 if (ivisurf == NULL) {
2193 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2194 return IVI_FAILED;
2195 }
2196
2197 prop = &ivisurf->pending.prop;
2198 prop->source_x = x;
2199 prop->source_y = y;
2200 prop->source_width = width;
2201 prop->source_height = height;
2202
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002203 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2204 ivisurf->prop.source_width != width ||
2205 ivisurf->prop.source_height != height)
2206 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2207 else
2208 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002209
2210 return IVI_SUCCEEDED;
2211}
2212
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002213int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002214ivi_layout_commit_changes(void)
2215{
2216 struct ivi_layout *layout = get_instance();
2217
2218 commit_surface_list(layout);
2219 commit_layer_list(layout);
2220 commit_screen_list(layout);
2221
2222 commit_transition(layout);
2223
2224 commit_changes(layout);
2225 send_prop(layout);
2226 weston_compositor_schedule_repaint(layout->compositor);
2227
2228 return IVI_SUCCEEDED;
2229}
2230
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002231static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002232ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2233 enum ivi_layout_transition_type type,
2234 uint32_t duration)
2235{
2236 if (ivilayer == NULL) {
2237 weston_log("%s: invalid argument\n", __func__);
2238 return -1;
2239 }
2240
2241 ivilayer->pending.prop.transition_type = type;
2242 ivilayer->pending.prop.transition_duration = duration;
2243
2244 return 0;
2245}
2246
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002247static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002248ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2249 uint32_t is_fade_in,
2250 double start_alpha, double end_alpha)
2251{
2252 if (ivilayer == NULL) {
2253 weston_log("%s: invalid argument\n", __func__);
2254 return -1;
2255 }
2256
2257 ivilayer->pending.prop.is_fade_in = is_fade_in;
2258 ivilayer->pending.prop.start_alpha = start_alpha;
2259 ivilayer->pending.prop.end_alpha = end_alpha;
2260
2261 return 0;
2262}
2263
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002264static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002265ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2266 uint32_t duration)
2267{
2268 struct ivi_layout_surface_properties *prop;
2269
2270 if (ivisurf == NULL) {
2271 weston_log("%s: invalid argument\n", __func__);
2272 return -1;
2273 }
2274
2275 prop = &ivisurf->pending.prop;
2276 prop->transition_duration = duration*10;
2277 return 0;
2278}
2279
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002280static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002281ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2282 enum ivi_layout_transition_type type,
2283 uint32_t duration)
2284{
2285 struct ivi_layout_surface_properties *prop;
2286
2287 if (ivisurf == NULL) {
2288 weston_log("%s: invalid argument\n", __func__);
2289 return -1;
2290 }
2291
2292 prop = &ivisurf->pending.prop;
2293 prop->transition_type = type;
2294 prop->transition_duration = duration;
2295 return 0;
2296}
2297
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002298static int32_t
2299ivi_layout_surface_dump(struct weston_surface *surface,
2300 void *target, size_t size,int32_t x, int32_t y,
2301 int32_t width, int32_t height)
2302{
2303 int result = 0;
2304
2305 if (surface == NULL) {
2306 weston_log("%s: invalid argument\n", __func__);
2307 return IVI_FAILED;
2308 }
2309
2310 result = weston_surface_copy_content(
2311 surface, target, size,
2312 x, y, width, height);
2313
2314 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2315}
2316
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002317/**
2318 * methods of interaction between ivi-shell with ivi-layout
2319 */
2320struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002321ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2322{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002323 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002324 return NULL;
2325
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002326 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002327}
2328
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002329void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002330ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2331 int32_t width, int32_t height)
2332{
2333 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002334
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002335 /* emit callback which is set by ivi-layout api user */
2336 wl_signal_emit(&layout->surface_notification.configure_changed,
2337 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002338}
2339
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002340struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002341ivi_layout_surface_create(struct weston_surface *wl_surface,
2342 uint32_t id_surface)
2343{
2344 struct ivi_layout *layout = get_instance();
2345 struct ivi_layout_surface *ivisurf = NULL;
2346 struct weston_view *tmpview = NULL;
2347
2348 if (wl_surface == NULL) {
2349 weston_log("ivi_layout_surface_create: invalid argument\n");
2350 return NULL;
2351 }
2352
2353 ivisurf = get_surface(&layout->surface_list, id_surface);
2354 if (ivisurf != NULL) {
2355 if (ivisurf->surface != NULL) {
2356 weston_log("id_surface(%d) is already created\n", id_surface);
2357 return NULL;
2358 }
2359 }
2360
2361 ivisurf = calloc(1, sizeof *ivisurf);
2362 if (ivisurf == NULL) {
2363 weston_log("fails to allocate memory\n");
2364 return NULL;
2365 }
2366
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002367 wl_signal_init(&ivisurf->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002368 ivisurf->id_surface = id_surface;
2369 ivisurf->layout = layout;
2370
2371 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002372
2373 tmpview = weston_view_create(wl_surface);
2374 if (tmpview == NULL) {
2375 weston_log("fails to allocate memory\n");
2376 }
2377
2378 ivisurf->surface->width_from_buffer = 0;
2379 ivisurf->surface->height_from_buffer = 0;
2380
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002381 weston_matrix_init(&ivisurf->transform.matrix);
2382 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002383
2384 init_surface_properties(&ivisurf->prop);
2385 ivisurf->event_mask = 0;
2386
2387 ivisurf->pending.prop = ivisurf->prop;
2388 wl_list_init(&ivisurf->pending.link);
2389
2390 wl_list_init(&ivisurf->order.link);
2391 wl_list_init(&ivisurf->order.layer_list);
2392
2393 wl_list_insert(&layout->surface_list, &ivisurf->link);
2394
2395 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2396
2397 return ivisurf;
2398}
2399
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002400void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002401ivi_layout_init_with_compositor(struct weston_compositor *ec)
2402{
2403 struct ivi_layout *layout = get_instance();
2404
2405 layout->compositor = ec;
2406
2407 wl_list_init(&layout->surface_list);
2408 wl_list_init(&layout->layer_list);
2409 wl_list_init(&layout->screen_list);
2410
2411 wl_signal_init(&layout->layer_notification.created);
2412 wl_signal_init(&layout->layer_notification.removed);
2413
2414 wl_signal_init(&layout->surface_notification.created);
2415 wl_signal_init(&layout->surface_notification.removed);
2416 wl_signal_init(&layout->surface_notification.configure_changed);
2417
2418 /* Add layout_layer at the last of weston_compositor.layer_list */
2419 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2420
2421 create_screen(ec);
2422
2423 layout->transitions = ivi_layout_transition_set_create(ec);
2424 wl_list_init(&layout->pending_transition_list);
2425}
2426
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002427static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002428 /**
2429 * commit all changes
2430 */
2431 .commit_changes = ivi_layout_commit_changes,
2432
2433 /**
2434 * surface controller interfaces
2435 */
2436 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2437 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2438 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2439 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2440 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2441 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2442 .get_surfaces = ivi_layout_get_surfaces,
2443 .get_id_of_surface = ivi_layout_get_id_of_surface,
2444 .get_surface_from_id = ivi_layout_get_surface_from_id,
2445 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2446 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2447 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002448 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002449 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2450 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002451 .surface_set_orientation = ivi_layout_surface_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002452 .surface_add_notification = ivi_layout_surface_add_notification,
2453 .surface_remove_notification = ivi_layout_surface_remove_notification,
2454 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2455 .surface_set_transition = ivi_layout_surface_set_transition,
2456 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2457
2458 /**
2459 * layer controller interfaces
2460 */
2461 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2462 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2463 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2464 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2465 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002466 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002467 .get_layers = ivi_layout_get_layers,
2468 .get_id_of_layer = ivi_layout_get_id_of_layer,
2469 .get_layer_from_id = ivi_layout_get_layer_from_id,
2470 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2471 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2472 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2473 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002474 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002475 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2476 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002477 .layer_set_orientation = ivi_layout_layer_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002478 .layer_add_surface = ivi_layout_layer_add_surface,
2479 .layer_remove_surface = ivi_layout_layer_remove_surface,
2480 .layer_set_render_order = ivi_layout_layer_set_render_order,
2481 .layer_add_notification = ivi_layout_layer_add_notification,
2482 .layer_remove_notification = ivi_layout_layer_remove_notification,
2483 .layer_set_transition = ivi_layout_layer_set_transition,
2484
2485 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002486 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002487 */
2488 .get_screen_from_id = ivi_layout_get_screen_from_id,
2489 .get_screen_resolution = ivi_layout_get_screen_resolution,
2490 .get_screens = ivi_layout_get_screens,
2491 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2492 .screen_add_layer = ivi_layout_screen_add_layer,
2493 .screen_set_render_order = ivi_layout_screen_set_render_order,
2494 .screen_get_output = ivi_layout_screen_get_output,
2495
2496 /**
2497 * animation
2498 */
2499 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002500 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2501
2502 /**
2503 * surface content dumping for debugging
2504 */
2505 .surface_get_size = ivi_layout_surface_get_size,
2506 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002507
2508 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002509 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002510 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002511 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002512 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2513
2514 /**
2515 * screen controller interfaces part2
2516 */
2517 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002518};
2519
2520int
2521load_controller_modules(struct weston_compositor *compositor, const char *modules,
2522 int *argc, char *argv[])
2523{
2524 const char *p, *end;
2525 char buffer[256];
2526 int (*controller_module_init)(struct weston_compositor *compositor,
2527 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002528 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002529 size_t interface_version);
2530
2531 if (modules == NULL)
2532 return 0;
2533
2534 p = modules;
2535 while (*p) {
2536 end = strchrnul(p, ',');
2537 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2538
2539 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002540 if (!controller_module_init)
2541 return -1;
2542
2543 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002544 &ivi_layout_interface,
2545 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002546 weston_log("ivi-shell: Initialization of controller module fails");
2547 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002548 }
2549
2550 p = end;
2551 while (*p == ',')
2552 p++;
2553 }
2554
2555 return 0;
2556}