blob: b6c41e4ee3e62aac2c7f49079b946b9093f08b91 [file] [log] [blame]
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001/*
2 * Copyright (C) 2013 DENSO CORPORATION
3 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090011 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090024 */
25
26/**
27 * Implementation of ivi-layout library. The actual view on ivi_screen is
28 * not updated till calling ivi_layout_commit_changes. A overview from
29 * calling API for updating properties of ivi_surface/ivi_layer to asking
30 * compositor to compose them by using weston_compositor_schedule_repaint,
31 * 0/ initialize this library by ivi_layout_init_with_compositor
32 * with (struct weston_compositor *ec) from ivi-shell.
33 * 1/ When a API for updating properties of ivi_surface/ivi_layer, it updates
34 * pending prop of ivi_surface/ivi_layer/ivi_screen which are structure to
35 * store properties.
36 * 2/ Before calling commitChanges, in case of calling a API to get a property,
37 * return current property, not pending property.
38 * 3/ At the timing of calling ivi_layout_commitChanges, pending properties
39 * are applied to properties.
40 *
41 * *) ivi_layout_commitChanges is also called by transition animation
42 * per each frame. See ivi-layout-transition.c in details. Transition
43 * animation interpolates frames between previous properties of ivi_surface
44 * and new ones.
45 * For example, when a property of ivi_surface is changed from invisibility
46 * to visibility, it behaves like fade-in. When ivi_layout_commitChange is
47 * called during transition animation, it cancels the transition and
48 * re-start transition to new properties from current properties of final
49 * frame just before the the cancellation.
50 *
51 * 4/ According properties, set transformation by using weston_matrix and
52 * weston_view per ivi_surfaces and ivi_layers in while loop.
53 * 5/ Set damage and trigger transform by using weston_view_geometry_dirty.
54 * 6/ Notify update of properties.
55 * 7/ Trigger composition by weston_compositor_schedule_repaint.
56 *
57 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090058#include "config.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090059
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090060#include <string.h>
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +000061#include <assert.h>
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090062
63#include "compositor.h"
Pekka Paalanen1f821932016-03-15 16:57:51 +020064#include "ivi-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090065#include "ivi-layout-export.h"
66#include "ivi-layout-private.h"
Pekka Paalanen32ca7912016-03-15 17:21:00 +020067#include "ivi-layout-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090068
Jon Cruz867d50e2015-06-15 15:37:10 -070069#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070070#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090071
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +090072#define max(a, b) ((a) > (b) ? (a) : (b))
73
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090074struct listener_layout_notification {
75 void *userdata;
76 struct wl_listener listener;
77};
78
79struct ivi_layout;
80
81struct ivi_layout_screen {
82 struct wl_list link;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090083
84 struct ivi_layout *layout;
85 struct weston_output *output;
86
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090087 struct {
88 struct wl_list layer_list;
89 struct wl_list link;
90 } pending;
91
92 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +000093 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090094 struct wl_list layer_list;
95 struct wl_list link;
96 } order;
97};
98
99struct ivi_layout_notification_callback {
100 void *callback;
101 void *data;
102};
103
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900104struct ivi_rectangle
105{
106 int32_t x;
107 int32_t y;
108 int32_t width;
109 int32_t height;
110};
111
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900112static void
113remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
114
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900115static struct ivi_layout ivilayout = {0};
116
117struct ivi_layout *
118get_instance(void)
119{
120 return &ivilayout;
121}
122
123/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900124 * Internal API to add/remove a ivi_layer to/from ivi_screen.
125 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900126static struct ivi_layout_surface *
127get_surface(struct wl_list *surf_list, uint32_t id_surface)
128{
129 struct ivi_layout_surface *ivisurf;
130
131 wl_list_for_each(ivisurf, surf_list, link) {
132 if (ivisurf->id_surface == id_surface) {
133 return ivisurf;
134 }
135 }
136
137 return NULL;
138}
139
140static struct ivi_layout_layer *
141get_layer(struct wl_list *layer_list, uint32_t id_layer)
142{
143 struct ivi_layout_layer *ivilayer;
144
145 wl_list_for_each(ivilayer, layer_list, link) {
146 if (ivilayer->id_layer == id_layer) {
147 return ivilayer;
148 }
149 }
150
151 return NULL;
152}
153
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000154static struct weston_view *
155get_weston_view(struct ivi_layout_surface *ivisurf)
156{
157 struct weston_view *view = NULL;
158
159 assert(ivisurf->surface != NULL);
160
161 /* One view per surface */
162 if(wl_list_empty(&ivisurf->surface->views))
163 view = NULL;
164 else
165 view = wl_container_of(ivisurf->surface->views.next, view, surface_link);
166
167 return view;
168}
169
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +0000170static struct ivi_layout_screen *
171get_screen_from_output(struct weston_output *output)
172{
173 struct ivi_layout *layout = get_instance();
174 struct ivi_layout_screen *iviscrn = NULL;
175
176 wl_list_for_each(iviscrn, &layout->screen_list, link) {
177 if (iviscrn->output == output)
178 return iviscrn;
179 }
180
181 return NULL;
182}
183
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900184/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900185 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900186 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900187void
188ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900189{
190 struct ivi_layout *layout = get_instance();
191
192 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900193 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900194 return;
195 }
196
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900197 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900198 wl_list_remove(&ivisurf->pending.link);
199 wl_list_remove(&ivisurf->order.link);
200 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900201
202 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
203
Mateusz Polroladada6e32016-03-09 09:13:26 +0000204 ivi_layout_remove_all_surface_transitions(ivisurf);
205
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900206 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900207}
208
209/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900210 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
211 * Called by ivi_layout_init_with_compositor.
212 */
213static void
214create_screen(struct weston_compositor *ec)
215{
216 struct ivi_layout *layout = get_instance();
217 struct ivi_layout_screen *iviscrn = NULL;
218 struct weston_output *output = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900219
220 wl_list_for_each(output, &ec->output_list, link) {
221 iviscrn = calloc(1, sizeof *iviscrn);
222 if (iviscrn == NULL) {
223 weston_log("fails to allocate memory\n");
224 continue;
225 }
226
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900227 iviscrn->layout = layout;
228
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900229 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900230
231 wl_list_init(&iviscrn->pending.layer_list);
232 wl_list_init(&iviscrn->pending.link);
233
234 wl_list_init(&iviscrn->order.layer_list);
235 wl_list_init(&iviscrn->order.link);
236
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900237 wl_list_insert(&layout->screen_list, &iviscrn->link);
238 }
239}
240
241/**
242 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
243 */
244static void
245init_layer_properties(struct ivi_layout_layer_properties *prop,
246 int32_t width, int32_t height)
247{
248 memset(prop, 0, sizeof *prop);
249 prop->opacity = wl_fixed_from_double(1.0);
250 prop->source_width = width;
251 prop->source_height = height;
252 prop->dest_width = width;
253 prop->dest_height = height;
254}
255
256static void
257init_surface_properties(struct ivi_layout_surface_properties *prop)
258{
259 memset(prop, 0, sizeof *prop);
260 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900261 /*
262 * FIXME: this shall be finxed by ivi-layout-transition.
263 */
264 prop->dest_width = 1;
265 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900266}
267
268/**
269 * Internal APIs to be called from ivi_layout_commit_changes.
270 */
271static void
272update_opacity(struct ivi_layout_layer *ivilayer,
273 struct ivi_layout_surface *ivisurf)
274{
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000275 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900276 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
277 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
278
Nobuhiko Tanibata90c27892015-12-26 23:52:51 +0900279 tmpview = get_weston_view(ivisurf);
280 assert(tmpview != NULL);
281 tmpview->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900282}
283
284static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900285get_rotate_values(enum wl_output_transform orientation,
286 float *v_sin,
287 float *v_cos)
288{
289 switch (orientation) {
290 case WL_OUTPUT_TRANSFORM_90:
291 *v_sin = 1.0f;
292 *v_cos = 0.0f;
293 break;
294 case WL_OUTPUT_TRANSFORM_180:
295 *v_sin = 0.0f;
296 *v_cos = -1.0f;
297 break;
298 case WL_OUTPUT_TRANSFORM_270:
299 *v_sin = -1.0f;
300 *v_cos = 0.0f;
301 break;
302 case WL_OUTPUT_TRANSFORM_NORMAL:
303 default:
304 *v_sin = 0.0f;
305 *v_cos = 1.0f;
306 break;
307 }
308}
309
310static void
311get_scale(enum wl_output_transform orientation,
312 float dest_width,
313 float dest_height,
314 float source_width,
315 float source_height,
316 float *scale_x,
317 float *scale_y)
318{
319 switch (orientation) {
320 case WL_OUTPUT_TRANSFORM_90:
321 *scale_x = dest_width / source_height;
322 *scale_y = dest_height / source_width;
323 break;
324 case WL_OUTPUT_TRANSFORM_180:
325 *scale_x = dest_width / source_width;
326 *scale_y = dest_height / source_height;
327 break;
328 case WL_OUTPUT_TRANSFORM_270:
329 *scale_x = dest_width / source_height;
330 *scale_y = dest_height / source_width;
331 break;
332 case WL_OUTPUT_TRANSFORM_NORMAL:
333 default:
334 *scale_x = dest_width / source_width;
335 *scale_y = dest_height / source_height;
336 break;
337 }
338}
339
340static void
341calc_transformation_matrix(struct ivi_rectangle *source_rect,
342 struct ivi_rectangle *dest_rect,
343 enum wl_output_transform orientation,
344 struct weston_matrix *m)
345{
346 float source_center_x;
347 float source_center_y;
348 float vsin;
349 float vcos;
350 float scale_x;
351 float scale_y;
352 float translate_x;
353 float translate_y;
354
355 source_center_x = source_rect->x + source_rect->width * 0.5f;
356 source_center_y = source_rect->y + source_rect->height * 0.5f;
357 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
358
359 get_rotate_values(orientation, &vsin, &vcos);
360 weston_matrix_rotate_xy(m, vcos, vsin);
361
362 get_scale(orientation,
363 dest_rect->width,
364 dest_rect->height,
365 source_rect->width,
366 source_rect->height,
367 &scale_x,
368 &scale_y);
369 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
370
371 translate_x = dest_rect->width * 0.5f + dest_rect->x;
372 translate_y = dest_rect->height * 0.5f + dest_rect->y;
373 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
374}
375
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900376/*
377 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900378 */
379static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900380ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
381 const struct ivi_rectangle *rect2,
382 struct ivi_rectangle *rect_output)
383{
384 int32_t rect1_right = rect1->x + rect1->width;
385 int32_t rect1_bottom = rect1->y + rect1->height;
386 int32_t rect2_right = rect2->x + rect2->width;
387 int32_t rect2_bottom = rect2->y + rect2->height;
388
389 rect_output->x = max(rect1->x, rect2->x);
390 rect_output->y = max(rect1->y, rect2->y);
391 rect_output->width = rect1_right < rect2_right ?
392 rect1_right - rect_output->x :
393 rect2_right - rect_output->x;
394 rect_output->height = rect1_bottom < rect2_bottom ?
395 rect1_bottom - rect_output->y :
396 rect2_bottom - rect_output->y;
397
398 if (rect_output->width < 0 || rect_output->height < 0) {
399 rect_output->width = 0;
400 rect_output->height = 0;
401 }
402}
403
404/*
405 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
406 * and store the result in rect_output.
407 * The boundingbox must be given in the same coordinate space as rect_output.
408 * Additionally, there are the following restrictions on the matrix:
409 * - no projective transformations
410 * - no skew
411 * - only multiples of 90-degree rotations supported
412 *
413 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
414 * as a fail-safe with log.
415 */
416static void
417calc_inverse_matrix_transform(const struct weston_matrix *matrix,
418 const struct ivi_rectangle *rect_input,
419 const struct ivi_rectangle *boundingbox,
420 struct ivi_rectangle *rect_output)
421{
422 struct weston_matrix m;
423 struct weston_vector top_left;
424 struct weston_vector bottom_right;
425
426 assert(boundingbox != rect_output);
427
428 if (weston_matrix_invert(&m, matrix) < 0) {
429 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
430 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
431 rect_output->x = boundingbox->x;
432 rect_output->y = boundingbox->y;
433 rect_output->width = boundingbox->width;
434 rect_output->height = boundingbox->height;
435 }
436
437 /* The vectors and matrices involved will always produce f[3] == 1.0. */
438 top_left.f[0] = rect_input->x;
439 top_left.f[1] = rect_input->y;
440 top_left.f[2] = 0.0f;
441 top_left.f[3] = 1.0f;
442
443 bottom_right.f[0] = rect_input->x + rect_input->width;
444 bottom_right.f[1] = rect_input->y + rect_input->height;
445 bottom_right.f[2] = 0.0f;
446 bottom_right.f[3] = 1.0f;
447
448 weston_matrix_transform(&m, &top_left);
449 weston_matrix_transform(&m, &bottom_right);
450
451 if (top_left.f[0] < bottom_right.f[0]) {
452 rect_output->x = top_left.f[0];
453 rect_output->width = bottom_right.f[0] - rect_output->x;
454 } else {
455 rect_output->x = bottom_right.f[0];
456 rect_output->width = top_left.f[0] - rect_output->x;
457 }
458
459 if (top_left.f[1] < bottom_right.f[1]) {
460 rect_output->y = top_left.f[1];
461 rect_output->height = bottom_right.f[1] - rect_output->y;
462 } else {
463 rect_output->y = bottom_right.f[1];
464 rect_output->height = top_left.f[1] - rect_output->y;
465 }
466
467 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
468}
469
470/**
471 * This computes the whole transformation matrix:m from surface-local
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900472 * coordinates to multi screens coordinate, which is global coordinates.
473 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900474 *
475 * Additionally, this computes the mask on surface-local coordinates as a
476 * ivi_rectangle. This can be set to weston_view_set_mask.
477 *
478 * The mask is computed by following steps
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900479 * - destination rectangle of layer is tansformed to multi screen coordinate,
480 * global coordinates. This is done by adding weston_output.{x,y} in simple
481 * because there is no scaled and rotated transformation.
482 * - destination rectangle of layer in multi screens coordinate needs to be
483 * intersected inside of a screen the layer is assigned to. This is because
484 * overlapped region of weston surface in another screen shall not be
485 * displayed according to ivi use case.
486 * - destination rectangle of layer
487 * - in multi screen coordinates,
488 * - and intersected inside of an assigned screen,
489 * is inversed to surface-local cooodinates by inversed matrix:m.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900490 * - the area is intersected by intersected area between weston_surface and
491 * source rectangle of ivi_surface.
492 */
493static void
494calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900495 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900496 struct ivi_layout_layer *ivilayer,
497 struct ivi_layout_surface *ivisurf,
498 struct weston_matrix *m,
499 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900500{
501 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
502 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900503 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900504 struct ivi_rectangle weston_surface_rect = { 0,
505 0,
506 ivisurf->surface->width,
507 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900508 struct ivi_rectangle surface_source_rect = { sp->source_x,
509 sp->source_y,
510 sp->source_width,
511 sp->source_height };
512 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
513 sp->dest_y,
514 sp->dest_width,
515 sp->dest_height };
516 struct ivi_rectangle layer_source_rect = { lp->source_x,
517 lp->source_y,
518 lp->source_width,
519 lp->source_height };
520 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
521 lp->dest_y,
522 lp->dest_width,
523 lp->dest_height };
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900524 struct ivi_rectangle screen_dest_rect = { output->x,
525 output->y,
526 output->width,
527 output->height };
528 struct ivi_rectangle layer_dest_rect_in_global =
529 { lp->dest_x + output->x,
530 lp->dest_y + output->y,
531 lp->dest_width,
532 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900533 struct ivi_rectangle surface_result;
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900534 struct ivi_rectangle layer_dest_rect_in_global_intersected;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900535
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900536 /*
537 * the whole transformation matrix:m from surface-local
538 * coordinates to global coordinates, which is computed by
539 * two steps,
540 * - surface-local coordinates to layer-local coordinates
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900541 * - layer-local coordinates to a single screen-local coordinates
542 * - a single screen-local coordinates to multi screen coordinates,
543 * which is global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900544 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900545 calc_transformation_matrix(&surface_source_rect,
546 &surface_dest_rect,
547 sp->orientation, m);
548
549 calc_transformation_matrix(&layer_source_rect,
550 &layer_dest_rect,
551 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900552
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900553 weston_matrix_translate(m, output->x, output->y, 0.0f);
554
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900555 /* this intersected ivi_rectangle would be used for masking
556 * weston_surface
557 */
558 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
559 &surface_result);
560
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900561 /*
562 * destination rectangle of layer in multi screens coordinate
563 * is intersected to avoid displaying outside of an assigned screen.
564 */
565 ivi_rectangle_intersect(&layer_dest_rect_in_global, &screen_dest_rect,
566 &layer_dest_rect_in_global_intersected);
567
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900568 /* calc masking area of weston_surface from m */
569 calc_inverse_matrix_transform(m,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900570 &layer_dest_rect_in_global_intersected,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900571 &surface_result,
572 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900573}
574
575static void
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900576update_prop(struct ivi_layout_screen *iviscrn,
577 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900578 struct ivi_layout_surface *ivisurf)
579{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900580 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900581 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900582 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900583
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900584 /*In case of no prop change, this just returns*/
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000585 if (!ivilayer->prop.event_mask && !ivisurf->prop.event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900586 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900587
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900588 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900589
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000590 tmpview = get_weston_view(ivisurf);
591 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900592
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900593 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
594 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
595 can_calc = false;
596 }
597
598 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
599 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
600 can_calc = false;
601 }
602
603 if (can_calc) {
604 wl_list_remove(&ivisurf->transform.link);
605 weston_matrix_init(&ivisurf->transform.matrix);
606
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900607 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900608 iviscrn, ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900609
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000610 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
611 wl_list_insert(&tmpview->geometry.transformation_list,
612 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900613
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000614 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900615 }
616
617 ivisurf->update_count++;
618
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000619 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900620
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000621 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900622}
623
624static void
625commit_changes(struct ivi_layout *layout)
626{
627 struct ivi_layout_screen *iviscrn = NULL;
628 struct ivi_layout_layer *ivilayer = NULL;
629 struct ivi_layout_surface *ivisurf = NULL;
630
631 wl_list_for_each(iviscrn, &layout->screen_list, link) {
632 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900633 /*
634 * If ivilayer is invisible, weston_view of ivisurf doesn't
635 * need to be modified.
636 */
637 if (ivilayer->prop.visibility == false)
638 continue;
639
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900640 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900641 /*
642 * If ivilayer is invisible, weston_view of ivisurf doesn't
643 * need to be modified.
644 */
645 if (ivisurf->prop.visibility == false)
646 continue;
647
648 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900649 }
650 }
651 }
652}
653
654static void
655commit_surface_list(struct ivi_layout *layout)
656{
657 struct ivi_layout_surface *ivisurf = NULL;
658 int32_t dest_x = 0;
659 int32_t dest_y = 0;
660 int32_t dest_width = 0;
661 int32_t dest_height = 0;
662 int32_t configured = 0;
663
664 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300665 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900666 dest_x = ivisurf->prop.dest_x;
667 dest_y = ivisurf->prop.dest_y;
668 dest_width = ivisurf->prop.dest_width;
669 dest_height = ivisurf->prop.dest_height;
670
671 ivi_layout_transition_move_resize_view(ivisurf,
672 ivisurf->pending.prop.dest_x,
673 ivisurf->pending.prop.dest_y,
674 ivisurf->pending.prop.dest_width,
675 ivisurf->pending.prop.dest_height,
676 ivisurf->pending.prop.transition_duration);
677
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300678 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900679 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
680 } else {
681 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
682 }
683
684 ivisurf->prop = ivisurf->pending.prop;
685 ivisurf->prop.dest_x = dest_x;
686 ivisurf->prop.dest_y = dest_y;
687 ivisurf->prop.dest_width = dest_width;
688 ivisurf->prop.dest_height = dest_height;
689 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
690 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
691
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300692 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900693 dest_x = ivisurf->prop.dest_x;
694 dest_y = ivisurf->prop.dest_y;
695 dest_width = ivisurf->prop.dest_width;
696 dest_height = ivisurf->prop.dest_height;
697
698 ivi_layout_transition_move_resize_view(ivisurf,
699 ivisurf->pending.prop.dest_x,
700 ivisurf->pending.prop.dest_y,
701 ivisurf->pending.prop.dest_width,
702 ivisurf->pending.prop.dest_height,
703 ivisurf->pending.prop.transition_duration);
704
705 ivisurf->prop = ivisurf->pending.prop;
706 ivisurf->prop.dest_x = dest_x;
707 ivisurf->prop.dest_y = dest_y;
708 ivisurf->prop.dest_width = dest_width;
709 ivisurf->prop.dest_height = dest_height;
710
711 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
712 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
713
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300714 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900715 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300716 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900717 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
718 } else {
719 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
720 }
721
722 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
723 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
724 configured = 1;
725 }
726
727 ivisurf->prop = ivisurf->pending.prop;
728 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
729 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
730
Pekka Paalanen1f821932016-03-15 16:57:51 +0200731 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200732 shell_surface_send_configure(ivisurf->surface,
733 ivisurf->prop.dest_width,
734 ivisurf->prop.dest_height);
735 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900736 } else {
737 configured = 0;
738 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
739 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
740 configured = 1;
741 }
742
743 ivisurf->prop = ivisurf->pending.prop;
744 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
745 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
746
Pekka Paalanen1f821932016-03-15 16:57:51 +0200747 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200748 shell_surface_send_configure(ivisurf->surface,
749 ivisurf->prop.dest_width,
750 ivisurf->prop.dest_height);
751 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900752 }
753 }
754}
755
756static void
757commit_layer_list(struct ivi_layout *layout)
758{
759 struct ivi_layout_layer *ivilayer = NULL;
760 struct ivi_layout_surface *ivisurf = NULL;
761 struct ivi_layout_surface *next = NULL;
762
763 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300764 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900765 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 -0300766 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900767 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
768 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
769 NULL, NULL,
770 ivilayer->pending.prop.transition_duration);
771 }
772 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
773
774 ivilayer->prop = ivilayer->pending.prop;
775
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000776 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900777 continue;
778 }
779
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000780 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
781 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000782 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000783 wl_list_remove(&ivisurf->order.link);
784 wl_list_init(&ivisurf->order.link);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000785 ivisurf->prop.event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900786 }
787
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000788 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900789
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000790 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900791 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000792 wl_list_remove(&ivisurf->order.link);
793 wl_list_insert(&ivilayer->order.surface_list,
794 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000795 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000796 ivisurf->prop.event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900797 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000798
799 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900800 }
801}
802
803static void
804commit_screen_list(struct ivi_layout *layout)
805{
806 struct ivi_layout_screen *iviscrn = NULL;
807 struct ivi_layout_layer *ivilayer = NULL;
808 struct ivi_layout_layer *next = NULL;
809 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000810 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900811
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900812 /* Clear view list of layout ivi_layer */
813 wl_list_init(&layout->layout_layer.view_list.link);
814
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900815 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000816 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900817 wl_list_for_each_safe(ivilayer, next,
818 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000819 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000820 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900821 wl_list_init(&ivilayer->order.link);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000822 ivilayer->prop.event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900823 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900824
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000825 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900826
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900827 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
828 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900829 /* FIXME: avoid to insert order.link to multiple screens */
830 wl_list_remove(&ivilayer->order.link);
831
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900832 wl_list_insert(&iviscrn->order.layer_list,
833 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000834 ivilayer->on_screen = iviscrn;
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000835 ivilayer->prop.event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900836 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900837
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000838 iviscrn->order.dirty = 0;
839 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900840
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900841 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
842 if (ivilayer->prop.visibility == false)
843 continue;
844
845 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900846 if (ivisurf->prop.visibility == false)
847 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000848
849 tmpview = get_weston_view(ivisurf);
850 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900851
852 weston_layer_entry_insert(&layout->layout_layer.view_list,
853 &tmpview->layer_link);
854
855 ivisurf->surface->output = iviscrn->output;
856 }
857 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900858 }
859}
860
861static void
862commit_transition(struct ivi_layout* layout)
863{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300864 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900865 return;
866 }
867
868 wl_list_insert_list(&layout->transitions->transition_list,
869 &layout->pending_transition_list);
870
871 wl_list_init(&layout->pending_transition_list);
872
873 wl_event_source_timer_update(layout->transitions->event_source, 1);
874}
875
876static void
877send_surface_prop(struct ivi_layout_surface *ivisurf)
878{
879 wl_signal_emit(&ivisurf->property_changed, ivisurf);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000880 ivisurf->pending.prop.event_mask = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900881}
882
883static void
884send_layer_prop(struct ivi_layout_layer *ivilayer)
885{
886 wl_signal_emit(&ivilayer->property_changed, ivilayer);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000887 ivilayer->pending.prop.event_mask = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900888}
889
890static void
891send_prop(struct ivi_layout *layout)
892{
893 struct ivi_layout_layer *ivilayer = NULL;
894 struct ivi_layout_surface *ivisurf = NULL;
895
896 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000897 if (ivilayer->prop.event_mask)
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900898 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900899 }
900
901 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000902 if (ivisurf->prop.event_mask)
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900903 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900904 }
905}
906
907static void
908clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
909{
910 struct ivi_layout_surface *surface_link = NULL;
911 struct ivi_layout_surface *surface_next = NULL;
912
913 wl_list_for_each_safe(surface_link, surface_next,
914 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000915 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900916 wl_list_init(&surface_link->pending.link);
917 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900918}
919
920static void
921clear_surface_order_list(struct ivi_layout_layer *ivilayer)
922{
923 struct ivi_layout_surface *surface_link = NULL;
924 struct ivi_layout_surface *surface_next = NULL;
925
926 wl_list_for_each_safe(surface_link, surface_next,
927 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000928 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900929 wl_list_init(&surface_link->order.link);
930 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900931}
932
933static void
934layer_created(struct wl_listener *listener, void *data)
935{
936 struct ivi_layout_layer *ivilayer = data;
937
938 struct listener_layout_notification *notification =
939 container_of(listener,
940 struct listener_layout_notification,
941 listener);
942
943 struct ivi_layout_notification_callback *created_callback =
944 notification->userdata;
945
946 ((layer_create_notification_func)created_callback->callback)
947 (ivilayer, created_callback->data);
948}
949
950static void
951layer_removed(struct wl_listener *listener, void *data)
952{
953 struct ivi_layout_layer *ivilayer = data;
954
955 struct listener_layout_notification *notification =
956 container_of(listener,
957 struct listener_layout_notification,
958 listener);
959
960 struct ivi_layout_notification_callback *removed_callback =
961 notification->userdata;
962
963 ((layer_remove_notification_func)removed_callback->callback)
964 (ivilayer, removed_callback->data);
965}
966
967static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900968surface_removed(struct wl_listener *listener, void *data)
969{
970 struct ivi_layout_surface *ivisurface = data;
971
972 struct listener_layout_notification *notification =
973 container_of(listener,
974 struct listener_layout_notification,
975 listener);
976
977 struct ivi_layout_notification_callback *removed_callback =
978 notification->userdata;
979
980 ((surface_remove_notification_func)removed_callback->callback)
981 (ivisurface, removed_callback->data);
982}
983
984static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900985surface_configure_changed(struct wl_listener *listener,
986 void *data)
987{
988 struct ivi_layout_surface *ivisurface = data;
989
990 struct listener_layout_notification *notification =
991 container_of(listener,
992 struct listener_layout_notification,
993 listener);
994
995 struct ivi_layout_notification_callback *configure_changed_callback =
996 notification->userdata;
997
998 ((surface_configure_notification_func)configure_changed_callback->callback)
999 (ivisurface, configure_changed_callback->data);
1000}
1001
1002static int32_t
1003add_notification(struct wl_signal *signal,
1004 wl_notify_func_t callback,
1005 void *userdata)
1006{
1007 struct listener_layout_notification *notification = NULL;
1008
1009 notification = malloc(sizeof *notification);
1010 if (notification == NULL) {
1011 weston_log("fails to allocate memory\n");
1012 free(userdata);
1013 return IVI_FAILED;
1014 }
1015
1016 notification->listener.notify = callback;
1017 notification->userdata = userdata;
1018
1019 wl_signal_add(signal, &notification->listener);
1020
1021 return IVI_SUCCEEDED;
1022}
1023
1024static void
1025remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1026{
1027 struct wl_listener *listener = NULL;
1028 struct wl_listener *next = NULL;
1029
1030 wl_list_for_each_safe(listener, next, listener_list, link) {
1031 struct listener_layout_notification *notification =
1032 container_of(listener,
1033 struct listener_layout_notification,
1034 listener);
1035
1036 struct ivi_layout_notification_callback *notification_callback =
1037 notification->userdata;
1038
1039 if ((notification_callback->callback != callback) ||
1040 (notification_callback->data != userdata)) {
1041 continue;
1042 }
1043
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001044 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001045
1046 free(notification->userdata);
1047 free(notification);
1048 }
1049}
1050
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001051/**
1052 * Exported APIs of ivi-layout library are implemented from here.
1053 * Brief of APIs is described in ivi-layout-export.h.
1054 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001055static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001056ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1057 void *userdata)
1058{
1059 struct ivi_layout *layout = get_instance();
1060 struct ivi_layout_notification_callback *created_callback = NULL;
1061
1062 if (callback == NULL) {
1063 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1064 return IVI_FAILED;
1065 }
1066
1067 created_callback = malloc(sizeof *created_callback);
1068 if (created_callback == NULL) {
1069 weston_log("fails to allocate memory\n");
1070 return IVI_FAILED;
1071 }
1072
1073 created_callback->callback = callback;
1074 created_callback->data = userdata;
1075
1076 return add_notification(&layout->layer_notification.created,
1077 layer_created,
1078 created_callback);
1079}
1080
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001081static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001082ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1083 void *userdata)
1084{
1085 struct ivi_layout *layout = get_instance();
1086 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1087}
1088
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001089static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001090ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1091 void *userdata)
1092{
1093 struct ivi_layout *layout = get_instance();
1094 struct ivi_layout_notification_callback *removed_callback = NULL;
1095
1096 if (callback == NULL) {
1097 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1098 return IVI_FAILED;
1099 }
1100
1101 removed_callback = malloc(sizeof *removed_callback);
1102 if (removed_callback == NULL) {
1103 weston_log("fails to allocate memory\n");
1104 return IVI_FAILED;
1105 }
1106
1107 removed_callback->callback = callback;
1108 removed_callback->data = userdata;
1109 return add_notification(&layout->layer_notification.removed,
1110 layer_removed,
1111 removed_callback);
1112}
1113
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001114static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001115ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1116 void *userdata)
1117{
1118 struct ivi_layout *layout = get_instance();
1119 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1120}
1121
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001122static int32_t
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001123ivi_layout_add_listener_create_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001124{
1125 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001126
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001127 if (listener == NULL) {
1128 weston_log("ivi_layout_add_listener_create_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001129 return IVI_FAILED;
1130 }
1131
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001132 wl_signal_add(&layout->surface_notification.created, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001133
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001134 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001135}
1136
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001137static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001138ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1139 void *userdata)
1140{
1141 struct ivi_layout *layout = get_instance();
1142 struct ivi_layout_notification_callback *removed_callback = NULL;
1143
1144 if (callback == NULL) {
1145 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1146 return IVI_FAILED;
1147 }
1148
1149 removed_callback = malloc(sizeof *removed_callback);
1150 if (removed_callback == NULL) {
1151 weston_log("fails to allocate memory\n");
1152 return IVI_FAILED;
1153 }
1154
1155 removed_callback->callback = callback;
1156 removed_callback->data = userdata;
1157
1158 return add_notification(&layout->surface_notification.removed,
1159 surface_removed,
1160 removed_callback);
1161}
1162
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001163static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001164ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1165 void *userdata)
1166{
1167 struct ivi_layout *layout = get_instance();
1168 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1169}
1170
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001171static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001172ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1173 void *userdata)
1174{
1175 struct ivi_layout *layout = get_instance();
1176 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1177 if (callback == NULL) {
1178 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1179 return IVI_FAILED;
1180 }
1181
1182 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1183 if (configure_changed_callback == NULL) {
1184 weston_log("fails to allocate memory\n");
1185 return IVI_FAILED;
1186 }
1187
1188 configure_changed_callback->callback = callback;
1189 configure_changed_callback->data = userdata;
1190
1191 return add_notification(&layout->surface_notification.configure_changed,
1192 surface_configure_changed,
1193 configure_changed_callback);
1194}
1195
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001196static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001197ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1198 void *userdata)
1199{
1200 struct ivi_layout *layout = get_instance();
1201 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1202}
1203
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001204uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001205ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1206{
1207 return ivisurf->id_surface;
1208}
1209
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001210static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001211ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1212{
1213 return ivilayer->id_layer;
1214}
1215
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001216static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001217ivi_layout_get_layer_from_id(uint32_t id_layer)
1218{
1219 struct ivi_layout *layout = get_instance();
1220 struct ivi_layout_layer *ivilayer = NULL;
1221
1222 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1223 if (ivilayer->id_layer == id_layer) {
1224 return ivilayer;
1225 }
1226 }
1227
1228 return NULL;
1229}
1230
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001231struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001232ivi_layout_get_surface_from_id(uint32_t id_surface)
1233{
1234 struct ivi_layout *layout = get_instance();
1235 struct ivi_layout_surface *ivisurf = NULL;
1236
1237 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1238 if (ivisurf->id_surface == id_surface) {
1239 return ivisurf;
1240 }
1241 }
1242
1243 return NULL;
1244}
1245
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001246static int32_t
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001247ivi_layout_surface_add_listener(struct ivi_layout_surface *ivisurf,
1248 struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001249{
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001250 if (ivisurf == NULL || listener == NULL) {
1251 weston_log("ivi_layout_surface_add_listener: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001252 return IVI_FAILED;
1253 }
1254
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001255 wl_signal_add(&ivisurf->property_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001256
1257 return IVI_SUCCEEDED;
1258}
1259
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001260static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001261ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1262{
1263 if (ivilayer == NULL) {
1264 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1265 return NULL;
1266 }
1267
1268 return &ivilayer->prop;
1269}
1270
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001271static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001272ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1273 int32_t *pLength,
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001274 struct weston_output ***ppArray)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001275{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001276 int32_t length = 0;
1277 int32_t n = 0;
1278
1279 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1280 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1281 return IVI_FAILED;
1282 }
1283
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001284 if (ivilayer->on_screen != NULL)
1285 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001286
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001287 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001288 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001289 *ppArray = calloc(length, sizeof(struct weston_output *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001290 if (*ppArray == NULL) {
1291 weston_log("fails to allocate memory\n");
1292 return IVI_FAILED;
1293 }
1294
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001295 (*ppArray)[n++] = ivilayer->on_screen->output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001296 }
1297
1298 *pLength = length;
1299
1300 return IVI_SUCCEEDED;
1301}
1302
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001303static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001304ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1305{
1306 struct ivi_layout *layout = get_instance();
1307 struct ivi_layout_layer *ivilayer = NULL;
1308 int32_t length = 0;
1309 int32_t n = 0;
1310
1311 if (pLength == NULL || ppArray == NULL) {
1312 weston_log("ivi_layout_get_layers: invalid argument\n");
1313 return IVI_FAILED;
1314 }
1315
1316 length = wl_list_length(&layout->layer_list);
1317
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001318 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001319 /* the Array must be free by module which called this function */
1320 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1321 if (*ppArray == NULL) {
1322 weston_log("fails to allocate memory\n");
1323 return IVI_FAILED;
1324 }
1325
1326 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1327 (*ppArray)[n++] = ivilayer;
1328 }
1329 }
1330
1331 *pLength = length;
1332
1333 return IVI_SUCCEEDED;
1334}
1335
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001336static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001337ivi_layout_get_layers_on_screen(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001338 int32_t *pLength,
1339 struct ivi_layout_layer ***ppArray)
1340{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001341 struct ivi_layout_screen *iviscrn = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001342 struct ivi_layout_layer *ivilayer = NULL;
1343 int32_t length = 0;
1344 int32_t n = 0;
1345
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001346 if (output == NULL || pLength == NULL || ppArray == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001347 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1348 return IVI_FAILED;
1349 }
1350
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001351 iviscrn = get_screen_from_output(output);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001352 length = wl_list_length(&iviscrn->order.layer_list);
1353
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001354 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001355 /* the Array must be free by module which called this function */
1356 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1357 if (*ppArray == NULL) {
1358 weston_log("fails to allocate memory\n");
1359 return IVI_FAILED;
1360 }
1361
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001362 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001363 (*ppArray)[n++] = ivilayer;
1364 }
1365 }
1366
1367 *pLength = length;
1368
1369 return IVI_SUCCEEDED;
1370}
1371
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001372static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001373ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1374 int32_t *pLength,
1375 struct ivi_layout_layer ***ppArray)
1376{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001377 int32_t length = 0;
1378 int32_t n = 0;
1379
1380 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1381 weston_log("ivi_layout_getLayers: invalid argument\n");
1382 return IVI_FAILED;
1383 }
1384
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001385 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001386 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001387 length = 1;
1388 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001389 if (*ppArray == NULL) {
1390 weston_log("fails to allocate memory\n");
1391 return IVI_FAILED;
1392 }
1393
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001394 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001395 }
1396
1397 *pLength = length;
1398
1399 return IVI_SUCCEEDED;
1400}
1401
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001402static
1403int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001404ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1405{
1406 struct ivi_layout *layout = get_instance();
1407 struct ivi_layout_surface *ivisurf = NULL;
1408 int32_t length = 0;
1409 int32_t n = 0;
1410
1411 if (pLength == NULL || ppArray == NULL) {
1412 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1413 return IVI_FAILED;
1414 }
1415
1416 length = wl_list_length(&layout->surface_list);
1417
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001418 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001419 /* the Array must be free by module which called this function */
1420 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1421 if (*ppArray == NULL) {
1422 weston_log("fails to allocate memory\n");
1423 return IVI_FAILED;
1424 }
1425
1426 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1427 (*ppArray)[n++] = ivisurf;
1428 }
1429 }
1430
1431 *pLength = length;
1432
1433 return IVI_SUCCEEDED;
1434}
1435
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001436static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001437ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1438 int32_t *pLength,
1439 struct ivi_layout_surface ***ppArray)
1440{
1441 struct ivi_layout_surface *ivisurf = NULL;
1442 int32_t length = 0;
1443 int32_t n = 0;
1444
1445 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1446 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1447 return IVI_FAILED;
1448 }
1449
1450 length = wl_list_length(&ivilayer->order.surface_list);
1451
1452 if (length != 0) {
1453 /* the Array must be free by module which called this function */
1454 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1455 if (*ppArray == NULL) {
1456 weston_log("fails to allocate memory\n");
1457 return IVI_FAILED;
1458 }
1459
1460 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1461 (*ppArray)[n++] = ivisurf;
1462 }
1463 }
1464
1465 *pLength = length;
1466
1467 return IVI_SUCCEEDED;
1468}
1469
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001470static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001471ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1472 int32_t width, int32_t height)
1473{
1474 struct ivi_layout *layout = get_instance();
1475 struct ivi_layout_layer *ivilayer = NULL;
1476
1477 ivilayer = get_layer(&layout->layer_list, id_layer);
1478 if (ivilayer != NULL) {
1479 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001480 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001481 return ivilayer;
1482 }
1483
1484 ivilayer = calloc(1, sizeof *ivilayer);
1485 if (ivilayer == NULL) {
1486 weston_log("fails to allocate memory\n");
1487 return NULL;
1488 }
1489
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001490 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001491 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001492 ivilayer->layout = layout;
1493 ivilayer->id_layer = id_layer;
1494
1495 init_layer_properties(&ivilayer->prop, width, height);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001496
1497 wl_list_init(&ivilayer->pending.surface_list);
1498 wl_list_init(&ivilayer->pending.link);
1499 ivilayer->pending.prop = ivilayer->prop;
1500
1501 wl_list_init(&ivilayer->order.surface_list);
1502 wl_list_init(&ivilayer->order.link);
1503
1504 wl_list_insert(&layout->layer_list, &ivilayer->link);
1505
1506 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1507
1508 return ivilayer;
1509}
1510
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001511static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001512ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001513{
1514 struct ivi_layout *layout = get_instance();
1515
1516 if (ivilayer == NULL) {
1517 weston_log("ivi_layout_layer_remove: invalid argument\n");
1518 return;
1519 }
1520
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001521 if (--ivilayer->ref_count > 0)
1522 return;
1523
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001524 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1525
1526 clear_surface_pending_list(ivilayer);
1527 clear_surface_order_list(ivilayer);
1528
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001529 wl_list_remove(&ivilayer->pending.link);
1530 wl_list_remove(&ivilayer->order.link);
1531 wl_list_remove(&ivilayer->link);
1532
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001533 free(ivilayer);
1534}
1535
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001536int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001537ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1538 bool newVisibility)
1539{
1540 struct ivi_layout_layer_properties *prop = NULL;
1541
1542 if (ivilayer == NULL) {
1543 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1544 return IVI_FAILED;
1545 }
1546
1547 prop = &ivilayer->pending.prop;
1548 prop->visibility = newVisibility;
1549
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001550 if (ivilayer->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001551 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001552 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001553 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001554
1555 return IVI_SUCCEEDED;
1556}
1557
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001558int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001559ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1560 wl_fixed_t opacity)
1561{
1562 struct ivi_layout_layer_properties *prop = NULL;
1563
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001564 if (ivilayer == NULL ||
1565 opacity < wl_fixed_from_double(0.0) ||
1566 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001567 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1568 return IVI_FAILED;
1569 }
1570
1571 prop = &ivilayer->pending.prop;
1572 prop->opacity = opacity;
1573
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001574 if (ivilayer->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001575 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001576 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001577 prop->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001578
1579 return IVI_SUCCEEDED;
1580}
1581
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001582static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001583ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1584 int32_t x, int32_t y,
1585 int32_t width, int32_t height)
1586{
1587 struct ivi_layout_layer_properties *prop = NULL;
1588
1589 if (ivilayer == NULL) {
1590 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1591 return IVI_FAILED;
1592 }
1593
1594 prop = &ivilayer->pending.prop;
1595 prop->source_x = x;
1596 prop->source_y = y;
1597 prop->source_width = width;
1598 prop->source_height = height;
1599
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001600 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1601 ivilayer->prop.source_width != width ||
1602 ivilayer->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001603 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001604 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001605 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001606
1607 return IVI_SUCCEEDED;
1608}
1609
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001610int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001611ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1612 int32_t x, int32_t y,
1613 int32_t width, int32_t height)
1614{
1615 struct ivi_layout_layer_properties *prop = NULL;
1616
1617 if (ivilayer == NULL) {
1618 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1619 return IVI_FAILED;
1620 }
1621
1622 prop = &ivilayer->pending.prop;
1623 prop->dest_x = x;
1624 prop->dest_y = y;
1625 prop->dest_width = width;
1626 prop->dest_height = height;
1627
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001628 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1629 ivilayer->prop.dest_width != width ||
1630 ivilayer->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001631 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001632 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001633 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001634
1635 return IVI_SUCCEEDED;
1636}
1637
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001638static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001639ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1640 enum wl_output_transform orientation)
1641{
1642 struct ivi_layout_layer_properties *prop = NULL;
1643
1644 if (ivilayer == NULL) {
1645 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1646 return IVI_FAILED;
1647 }
1648
1649 prop = &ivilayer->pending.prop;
1650 prop->orientation = orientation;
1651
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001652 if (ivilayer->prop.orientation != orientation)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001653 prop->event_mask |= IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001654 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001655 prop->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001656
1657 return IVI_SUCCEEDED;
1658}
1659
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001660int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001661ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1662 struct ivi_layout_surface **pSurface,
1663 int32_t number)
1664{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001665 int32_t i = 0;
1666
1667 if (ivilayer == NULL) {
1668 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1669 return IVI_FAILED;
1670 }
1671
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001672 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001673
1674 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)72ad1642016-03-16 13:37:05 +00001675 wl_list_remove(&pSurface[i]->pending.link);
1676 wl_list_insert(&ivilayer->pending.surface_list,
1677 &pSurface[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001678 }
1679
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001680 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001681
1682 return IVI_SUCCEEDED;
1683}
1684
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001685int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001686ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1687 bool newVisibility)
1688{
1689 struct ivi_layout_surface_properties *prop = NULL;
1690
1691 if (ivisurf == NULL) {
1692 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1693 return IVI_FAILED;
1694 }
1695
1696 prop = &ivisurf->pending.prop;
1697 prop->visibility = newVisibility;
1698
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001699 if (ivisurf->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001700 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001701 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001702 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001703
1704 return IVI_SUCCEEDED;
1705}
1706
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001707int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001708ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1709 wl_fixed_t opacity)
1710{
1711 struct ivi_layout_surface_properties *prop = NULL;
1712
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001713 if (ivisurf == NULL ||
1714 opacity < wl_fixed_from_double(0.0) ||
1715 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001716 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1717 return IVI_FAILED;
1718 }
1719
1720 prop = &ivisurf->pending.prop;
1721 prop->opacity = opacity;
1722
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001723 if (ivisurf->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001724 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001725 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001726 prop->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001727
1728 return IVI_SUCCEEDED;
1729}
1730
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001731int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001732ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1733 int32_t x, int32_t y,
1734 int32_t width, int32_t height)
1735{
1736 struct ivi_layout_surface_properties *prop = NULL;
1737
1738 if (ivisurf == NULL) {
1739 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1740 return IVI_FAILED;
1741 }
1742
1743 prop = &ivisurf->pending.prop;
1744 prop->start_x = prop->dest_x;
1745 prop->start_y = prop->dest_y;
1746 prop->dest_x = x;
1747 prop->dest_y = y;
1748 prop->start_width = prop->dest_width;
1749 prop->start_height = prop->dest_height;
1750 prop->dest_width = width;
1751 prop->dest_height = height;
1752
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001753 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
1754 ivisurf->prop.dest_width != width ||
1755 ivisurf->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001756 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001757 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001758 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001759
1760 return IVI_SUCCEEDED;
1761}
1762
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001763static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001764ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
1765 enum wl_output_transform orientation)
1766{
1767 struct ivi_layout_surface_properties *prop = NULL;
1768
1769 if (ivisurf == NULL) {
1770 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
1771 return IVI_FAILED;
1772 }
1773
1774 prop = &ivisurf->pending.prop;
1775 prop->orientation = orientation;
1776
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001777 if (ivisurf->prop.orientation != orientation)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001778 prop->event_mask |= IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001779 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001780 prop->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001781
1782 return IVI_SUCCEEDED;
1783}
1784
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001785static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001786ivi_layout_screen_add_layer(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001787 struct ivi_layout_layer *addlayer)
1788{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001789 struct ivi_layout_screen *iviscrn;
1790
1791 if (output == NULL || addlayer == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001792 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
1793 return IVI_FAILED;
1794 }
1795
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001796 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001797
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00001798 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001799 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
1800 return IVI_SUCCEEDED;
1801 }
1802
Ucan, Emre (ADITG/SW1)f46306f2016-03-16 13:37:07 +00001803 wl_list_remove(&addlayer->pending.link);
1804 wl_list_insert(&iviscrn->pending.layer_list, &addlayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001805
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001806 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001807
1808 return IVI_SUCCEEDED;
1809}
1810
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001811static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001812ivi_layout_screen_set_render_order(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001813 struct ivi_layout_layer **pLayer,
1814 const int32_t number)
1815{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001816 struct ivi_layout_screen *iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001817 struct ivi_layout_layer *ivilayer = NULL;
1818 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001819 int32_t i = 0;
1820
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001821 if (output == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001822 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
1823 return IVI_FAILED;
1824 }
1825
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001826 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001827
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001828 wl_list_for_each_safe(ivilayer, next,
1829 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001830 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001831 wl_list_init(&ivilayer->pending.link);
1832 }
1833
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001834 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001835
1836 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)4e221f02016-03-16 13:37:08 +00001837 wl_list_remove(&pLayer[i]->pending.link);
1838 wl_list_insert(&iviscrn->pending.layer_list,
1839 &pLayer[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001840 }
1841
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001842 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001843
1844 return IVI_SUCCEEDED;
1845}
1846
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001847/**
1848 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
1849 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
1850 * This function is used to get the result of drawing by clients.
1851 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001852static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001853ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
1854{
1855 return ivisurf != NULL ? ivisurf->surface : NULL;
1856}
1857
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001858static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09001859ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
1860 int32_t *width, int32_t *height,
1861 int32_t *stride)
1862{
1863 int32_t w;
1864 int32_t h;
1865 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
1866
1867 if (ivisurf == NULL || ivisurf->surface == NULL) {
1868 weston_log("%s: invalid argument\n", __func__);
1869 return IVI_FAILED;
1870 }
1871
1872 weston_surface_get_content_size(ivisurf->surface, &w, &h);
1873
1874 if (width != NULL)
1875 *width = w;
1876
1877 if (height != NULL)
1878 *height = h;
1879
1880 if (stride != NULL)
1881 *stride = w * bytespp;
1882
1883 return IVI_SUCCEEDED;
1884}
1885
1886static int32_t
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001887ivi_layout_layer_add_listener(struct ivi_layout_layer *ivilayer,
1888 struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001889{
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001890 if (ivilayer == NULL || listener == NULL) {
1891 weston_log("ivi_layout_layer_add_listener: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001892 return IVI_FAILED;
1893 }
1894
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001895 wl_signal_add(&ivilayer->property_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001896
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001897 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001898}
1899
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001900static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001901ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
1902{
1903 if (ivisurf == NULL) {
1904 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
1905 return NULL;
1906 }
1907
1908 return &ivisurf->prop;
1909}
1910
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001911static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001912ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
1913 struct ivi_layout_surface *addsurf)
1914{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001915 if (ivilayer == NULL || addsurf == NULL) {
1916 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
1917 return IVI_FAILED;
1918 }
1919
Wataru Natsume9c926fe2016-03-03 19:56:09 +09001920 if (addsurf->on_layer == ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001921 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001922
Ucan, Emre (ADITG/SW1)10942372016-03-16 13:37:02 +00001923 wl_list_remove(&addsurf->pending.link);
1924 wl_list_insert(&ivilayer->pending.surface_list, &addsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001925
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001926 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001927
1928 return IVI_SUCCEEDED;
1929}
1930
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001931static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001932ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
1933 struct ivi_layout_surface *remsurf)
1934{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001935 if (ivilayer == NULL || remsurf == NULL) {
1936 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
1937 return;
1938 }
1939
Ucan, Emre (ADITG/SW1)536d8332016-03-16 13:36:59 +00001940 wl_list_remove(&remsurf->pending.link);
1941 wl_list_init(&remsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001942
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001943 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001944}
1945
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001946static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001947ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
1948 int32_t x, int32_t y,
1949 int32_t width, int32_t height)
1950{
1951 struct ivi_layout_surface_properties *prop = NULL;
1952
1953 if (ivisurf == NULL) {
1954 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
1955 return IVI_FAILED;
1956 }
1957
1958 prop = &ivisurf->pending.prop;
1959 prop->source_x = x;
1960 prop->source_y = y;
1961 prop->source_width = width;
1962 prop->source_height = height;
1963
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001964 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
1965 ivisurf->prop.source_width != width ||
1966 ivisurf->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001967 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001968 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001969 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001970
1971 return IVI_SUCCEEDED;
1972}
1973
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001974int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001975ivi_layout_commit_changes(void)
1976{
1977 struct ivi_layout *layout = get_instance();
1978
1979 commit_surface_list(layout);
1980 commit_layer_list(layout);
1981 commit_screen_list(layout);
1982
1983 commit_transition(layout);
1984
1985 commit_changes(layout);
1986 send_prop(layout);
1987 weston_compositor_schedule_repaint(layout->compositor);
1988
1989 return IVI_SUCCEEDED;
1990}
1991
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001992static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001993ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
1994 enum ivi_layout_transition_type type,
1995 uint32_t duration)
1996{
1997 if (ivilayer == NULL) {
1998 weston_log("%s: invalid argument\n", __func__);
1999 return -1;
2000 }
2001
2002 ivilayer->pending.prop.transition_type = type;
2003 ivilayer->pending.prop.transition_duration = duration;
2004
2005 return 0;
2006}
2007
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002008static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002009ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2010 uint32_t is_fade_in,
2011 double start_alpha, double end_alpha)
2012{
2013 if (ivilayer == NULL) {
2014 weston_log("%s: invalid argument\n", __func__);
2015 return -1;
2016 }
2017
2018 ivilayer->pending.prop.is_fade_in = is_fade_in;
2019 ivilayer->pending.prop.start_alpha = start_alpha;
2020 ivilayer->pending.prop.end_alpha = end_alpha;
2021
2022 return 0;
2023}
2024
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002025static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002026ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2027 uint32_t duration)
2028{
2029 struct ivi_layout_surface_properties *prop;
2030
2031 if (ivisurf == NULL) {
2032 weston_log("%s: invalid argument\n", __func__);
2033 return -1;
2034 }
2035
2036 prop = &ivisurf->pending.prop;
2037 prop->transition_duration = duration*10;
2038 return 0;
2039}
2040
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002041static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002042ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2043 enum ivi_layout_transition_type type,
2044 uint32_t duration)
2045{
2046 struct ivi_layout_surface_properties *prop;
2047
2048 if (ivisurf == NULL) {
2049 weston_log("%s: invalid argument\n", __func__);
2050 return -1;
2051 }
2052
2053 prop = &ivisurf->pending.prop;
2054 prop->transition_type = type;
2055 prop->transition_duration = duration;
2056 return 0;
2057}
2058
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002059static int32_t
2060ivi_layout_surface_dump(struct weston_surface *surface,
2061 void *target, size_t size,int32_t x, int32_t y,
2062 int32_t width, int32_t height)
2063{
2064 int result = 0;
2065
2066 if (surface == NULL) {
2067 weston_log("%s: invalid argument\n", __func__);
2068 return IVI_FAILED;
2069 }
2070
2071 result = weston_surface_copy_content(
2072 surface, target, size,
2073 x, y, width, height);
2074
2075 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2076}
2077
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002078/**
2079 * methods of interaction between ivi-shell with ivi-layout
2080 */
2081struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002082ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2083{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002084 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002085 return NULL;
2086
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002087 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002088}
2089
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002090void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002091ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2092 int32_t width, int32_t height)
2093{
2094 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002095
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002096 /* emit callback which is set by ivi-layout api user */
2097 wl_signal_emit(&layout->surface_notification.configure_changed,
2098 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002099}
2100
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002101struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002102ivi_layout_surface_create(struct weston_surface *wl_surface,
2103 uint32_t id_surface)
2104{
2105 struct ivi_layout *layout = get_instance();
2106 struct ivi_layout_surface *ivisurf = NULL;
2107 struct weston_view *tmpview = NULL;
2108
2109 if (wl_surface == NULL) {
2110 weston_log("ivi_layout_surface_create: invalid argument\n");
2111 return NULL;
2112 }
2113
2114 ivisurf = get_surface(&layout->surface_list, id_surface);
2115 if (ivisurf != NULL) {
2116 if (ivisurf->surface != NULL) {
2117 weston_log("id_surface(%d) is already created\n", id_surface);
2118 return NULL;
2119 }
2120 }
2121
2122 ivisurf = calloc(1, sizeof *ivisurf);
2123 if (ivisurf == NULL) {
2124 weston_log("fails to allocate memory\n");
2125 return NULL;
2126 }
2127
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002128 wl_signal_init(&ivisurf->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002129 ivisurf->id_surface = id_surface;
2130 ivisurf->layout = layout;
2131
2132 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002133
2134 tmpview = weston_view_create(wl_surface);
2135 if (tmpview == NULL) {
2136 weston_log("fails to allocate memory\n");
2137 }
2138
2139 ivisurf->surface->width_from_buffer = 0;
2140 ivisurf->surface->height_from_buffer = 0;
2141
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002142 weston_matrix_init(&ivisurf->transform.matrix);
2143 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002144
2145 init_surface_properties(&ivisurf->prop);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002146
2147 ivisurf->pending.prop = ivisurf->prop;
2148 wl_list_init(&ivisurf->pending.link);
2149
2150 wl_list_init(&ivisurf->order.link);
2151 wl_list_init(&ivisurf->order.layer_list);
2152
2153 wl_list_insert(&layout->surface_list, &ivisurf->link);
2154
2155 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2156
2157 return ivisurf;
2158}
2159
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002160void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002161ivi_layout_init_with_compositor(struct weston_compositor *ec)
2162{
2163 struct ivi_layout *layout = get_instance();
2164
2165 layout->compositor = ec;
2166
2167 wl_list_init(&layout->surface_list);
2168 wl_list_init(&layout->layer_list);
2169 wl_list_init(&layout->screen_list);
2170
2171 wl_signal_init(&layout->layer_notification.created);
2172 wl_signal_init(&layout->layer_notification.removed);
2173
2174 wl_signal_init(&layout->surface_notification.created);
2175 wl_signal_init(&layout->surface_notification.removed);
2176 wl_signal_init(&layout->surface_notification.configure_changed);
2177
2178 /* Add layout_layer at the last of weston_compositor.layer_list */
2179 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2180
2181 create_screen(ec);
2182
2183 layout->transitions = ivi_layout_transition_set_create(ec);
2184 wl_list_init(&layout->pending_transition_list);
2185}
2186
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002187static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002188 /**
2189 * commit all changes
2190 */
2191 .commit_changes = ivi_layout_commit_changes,
2192
2193 /**
2194 * surface controller interfaces
2195 */
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00002196 .add_listener_create_surface = ivi_layout_add_listener_create_surface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002197 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2198 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2199 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2200 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2201 .get_surfaces = ivi_layout_get_surfaces,
2202 .get_id_of_surface = ivi_layout_get_id_of_surface,
2203 .get_surface_from_id = ivi_layout_get_surface_from_id,
2204 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2205 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2206 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002207 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002208 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2209 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002210 .surface_set_orientation = ivi_layout_surface_set_orientation,
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00002211 .surface_add_listener = ivi_layout_surface_add_listener,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002212 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2213 .surface_set_transition = ivi_layout_surface_set_transition,
2214 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2215
2216 /**
2217 * layer controller interfaces
2218 */
2219 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2220 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2221 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2222 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2223 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002224 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002225 .get_layers = ivi_layout_get_layers,
2226 .get_id_of_layer = ivi_layout_get_id_of_layer,
2227 .get_layer_from_id = ivi_layout_get_layer_from_id,
2228 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2229 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2230 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2231 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002232 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002233 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2234 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002235 .layer_set_orientation = ivi_layout_layer_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002236 .layer_add_surface = ivi_layout_layer_add_surface,
2237 .layer_remove_surface = ivi_layout_layer_remove_surface,
2238 .layer_set_render_order = ivi_layout_layer_set_render_order,
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00002239 .layer_add_listener = ivi_layout_layer_add_listener,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002240 .layer_set_transition = ivi_layout_layer_set_transition,
2241
2242 /**
Ucan, Emre (ADITG/SW1)6d89b1c2016-03-17 15:30:49 +00002243 * screen controller interfaces
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002244 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002245 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2246 .screen_add_layer = ivi_layout_screen_add_layer,
2247 .screen_set_render_order = ivi_layout_screen_set_render_order,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002248
2249 /**
2250 * animation
2251 */
2252 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002253 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2254
2255 /**
2256 * surface content dumping for debugging
2257 */
2258 .surface_get_size = ivi_layout_surface_get_size,
2259 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002260};
2261
2262int
2263load_controller_modules(struct weston_compositor *compositor, const char *modules,
2264 int *argc, char *argv[])
2265{
2266 const char *p, *end;
2267 char buffer[256];
2268 int (*controller_module_init)(struct weston_compositor *compositor,
2269 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002270 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002271 size_t interface_version);
2272
2273 if (modules == NULL)
2274 return 0;
2275
2276 p = modules;
2277 while (*p) {
2278 end = strchrnul(p, ',');
2279 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2280
2281 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002282 if (!controller_module_init)
2283 return -1;
2284
2285 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002286 &ivi_layout_interface,
2287 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002288 weston_log("ivi-shell: Initialization of controller module fails");
2289 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002290 }
2291
2292 p = end;
2293 while (*p == ',')
2294 p++;
2295 }
2296
2297 return 0;
2298}