blob: 82a6d5594dc9a8b22b7db53d765b8670549af0c2 [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
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900934surface_removed(struct wl_listener *listener, void *data)
935{
936 struct ivi_layout_surface *ivisurface = 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 *removed_callback =
944 notification->userdata;
945
946 ((surface_remove_notification_func)removed_callback->callback)
947 (ivisurface, removed_callback->data);
948}
949
950static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900951surface_configure_changed(struct wl_listener *listener,
952 void *data)
953{
954 struct ivi_layout_surface *ivisurface = data;
955
956 struct listener_layout_notification *notification =
957 container_of(listener,
958 struct listener_layout_notification,
959 listener);
960
961 struct ivi_layout_notification_callback *configure_changed_callback =
962 notification->userdata;
963
964 ((surface_configure_notification_func)configure_changed_callback->callback)
965 (ivisurface, configure_changed_callback->data);
966}
967
968static int32_t
969add_notification(struct wl_signal *signal,
970 wl_notify_func_t callback,
971 void *userdata)
972{
973 struct listener_layout_notification *notification = NULL;
974
975 notification = malloc(sizeof *notification);
976 if (notification == NULL) {
977 weston_log("fails to allocate memory\n");
978 free(userdata);
979 return IVI_FAILED;
980 }
981
982 notification->listener.notify = callback;
983 notification->userdata = userdata;
984
985 wl_signal_add(signal, &notification->listener);
986
987 return IVI_SUCCEEDED;
988}
989
990static void
991remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
992{
993 struct wl_listener *listener = NULL;
994 struct wl_listener *next = NULL;
995
996 wl_list_for_each_safe(listener, next, listener_list, link) {
997 struct listener_layout_notification *notification =
998 container_of(listener,
999 struct listener_layout_notification,
1000 listener);
1001
1002 struct ivi_layout_notification_callback *notification_callback =
1003 notification->userdata;
1004
1005 if ((notification_callback->callback != callback) ||
1006 (notification_callback->data != userdata)) {
1007 continue;
1008 }
1009
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001010 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001011
1012 free(notification->userdata);
1013 free(notification);
1014 }
1015}
1016
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001017/**
1018 * Exported APIs of ivi-layout library are implemented from here.
1019 * Brief of APIs is described in ivi-layout-export.h.
1020 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001021static int32_t
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +00001022ivi_layout_add_listener_create_layer(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001023{
1024 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001025
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +00001026 if (listener == NULL) {
1027 weston_log("ivi_layout_add_listener_create_layer: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001028 return IVI_FAILED;
1029 }
1030
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +00001031 wl_signal_add(&layout->layer_notification.created, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001032
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +00001033 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001034}
1035
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001036static int32_t
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +00001037ivi_layout_add_listener_remove_layer(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001038{
1039 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001040
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +00001041 if (listener == NULL) {
1042 weston_log("ivi_layout_add_listener_remove_layer: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001043 return IVI_FAILED;
1044 }
1045
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +00001046 wl_signal_add(&layout->layer_notification.removed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001047
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +00001048 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001049}
1050
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001051static int32_t
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001052ivi_layout_add_listener_create_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001053{
1054 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001055
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001056 if (listener == NULL) {
1057 weston_log("ivi_layout_add_listener_create_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001058 return IVI_FAILED;
1059 }
1060
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001061 wl_signal_add(&layout->surface_notification.created, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001062
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001063 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001064}
1065
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001066static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001067ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1068 void *userdata)
1069{
1070 struct ivi_layout *layout = get_instance();
1071 struct ivi_layout_notification_callback *removed_callback = NULL;
1072
1073 if (callback == NULL) {
1074 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1075 return IVI_FAILED;
1076 }
1077
1078 removed_callback = malloc(sizeof *removed_callback);
1079 if (removed_callback == NULL) {
1080 weston_log("fails to allocate memory\n");
1081 return IVI_FAILED;
1082 }
1083
1084 removed_callback->callback = callback;
1085 removed_callback->data = userdata;
1086
1087 return add_notification(&layout->surface_notification.removed,
1088 surface_removed,
1089 removed_callback);
1090}
1091
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001092static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001093ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1094 void *userdata)
1095{
1096 struct ivi_layout *layout = get_instance();
1097 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1098}
1099
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001100static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001101ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1102 void *userdata)
1103{
1104 struct ivi_layout *layout = get_instance();
1105 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1106 if (callback == NULL) {
1107 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1108 return IVI_FAILED;
1109 }
1110
1111 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1112 if (configure_changed_callback == NULL) {
1113 weston_log("fails to allocate memory\n");
1114 return IVI_FAILED;
1115 }
1116
1117 configure_changed_callback->callback = callback;
1118 configure_changed_callback->data = userdata;
1119
1120 return add_notification(&layout->surface_notification.configure_changed,
1121 surface_configure_changed,
1122 configure_changed_callback);
1123}
1124
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001125static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001126ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1127 void *userdata)
1128{
1129 struct ivi_layout *layout = get_instance();
1130 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1131}
1132
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001133uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001134ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1135{
1136 return ivisurf->id_surface;
1137}
1138
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001139static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001140ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1141{
1142 return ivilayer->id_layer;
1143}
1144
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001145static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001146ivi_layout_get_layer_from_id(uint32_t id_layer)
1147{
1148 struct ivi_layout *layout = get_instance();
1149 struct ivi_layout_layer *ivilayer = NULL;
1150
1151 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1152 if (ivilayer->id_layer == id_layer) {
1153 return ivilayer;
1154 }
1155 }
1156
1157 return NULL;
1158}
1159
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001160struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001161ivi_layout_get_surface_from_id(uint32_t id_surface)
1162{
1163 struct ivi_layout *layout = get_instance();
1164 struct ivi_layout_surface *ivisurf = NULL;
1165
1166 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1167 if (ivisurf->id_surface == id_surface) {
1168 return ivisurf;
1169 }
1170 }
1171
1172 return NULL;
1173}
1174
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001175static int32_t
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001176ivi_layout_surface_add_listener(struct ivi_layout_surface *ivisurf,
1177 struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001178{
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001179 if (ivisurf == NULL || listener == NULL) {
1180 weston_log("ivi_layout_surface_add_listener: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001181 return IVI_FAILED;
1182 }
1183
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001184 wl_signal_add(&ivisurf->property_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001185
1186 return IVI_SUCCEEDED;
1187}
1188
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001189static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001190ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1191{
1192 if (ivilayer == NULL) {
1193 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1194 return NULL;
1195 }
1196
1197 return &ivilayer->prop;
1198}
1199
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001200static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001201ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1202 int32_t *pLength,
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001203 struct weston_output ***ppArray)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001204{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001205 int32_t length = 0;
1206 int32_t n = 0;
1207
1208 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1209 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1210 return IVI_FAILED;
1211 }
1212
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001213 if (ivilayer->on_screen != NULL)
1214 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001215
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001216 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001217 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001218 *ppArray = calloc(length, sizeof(struct weston_output *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001219 if (*ppArray == NULL) {
1220 weston_log("fails to allocate memory\n");
1221 return IVI_FAILED;
1222 }
1223
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001224 (*ppArray)[n++] = ivilayer->on_screen->output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001225 }
1226
1227 *pLength = length;
1228
1229 return IVI_SUCCEEDED;
1230}
1231
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001232static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001233ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1234{
1235 struct ivi_layout *layout = get_instance();
1236 struct ivi_layout_layer *ivilayer = NULL;
1237 int32_t length = 0;
1238 int32_t n = 0;
1239
1240 if (pLength == NULL || ppArray == NULL) {
1241 weston_log("ivi_layout_get_layers: invalid argument\n");
1242 return IVI_FAILED;
1243 }
1244
1245 length = wl_list_length(&layout->layer_list);
1246
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001247 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001248 /* the Array must be free by module which called this function */
1249 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1250 if (*ppArray == NULL) {
1251 weston_log("fails to allocate memory\n");
1252 return IVI_FAILED;
1253 }
1254
1255 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1256 (*ppArray)[n++] = ivilayer;
1257 }
1258 }
1259
1260 *pLength = length;
1261
1262 return IVI_SUCCEEDED;
1263}
1264
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001265static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001266ivi_layout_get_layers_on_screen(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001267 int32_t *pLength,
1268 struct ivi_layout_layer ***ppArray)
1269{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001270 struct ivi_layout_screen *iviscrn = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001271 struct ivi_layout_layer *ivilayer = NULL;
1272 int32_t length = 0;
1273 int32_t n = 0;
1274
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001275 if (output == NULL || pLength == NULL || ppArray == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001276 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1277 return IVI_FAILED;
1278 }
1279
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001280 iviscrn = get_screen_from_output(output);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001281 length = wl_list_length(&iviscrn->order.layer_list);
1282
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001283 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001284 /* the Array must be free by module which called this function */
1285 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1286 if (*ppArray == NULL) {
1287 weston_log("fails to allocate memory\n");
1288 return IVI_FAILED;
1289 }
1290
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001291 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001292 (*ppArray)[n++] = ivilayer;
1293 }
1294 }
1295
1296 *pLength = length;
1297
1298 return IVI_SUCCEEDED;
1299}
1300
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001301static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001302ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1303 int32_t *pLength,
1304 struct ivi_layout_layer ***ppArray)
1305{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001306 int32_t length = 0;
1307 int32_t n = 0;
1308
1309 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1310 weston_log("ivi_layout_getLayers: invalid argument\n");
1311 return IVI_FAILED;
1312 }
1313
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001314 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001315 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001316 length = 1;
1317 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001318 if (*ppArray == NULL) {
1319 weston_log("fails to allocate memory\n");
1320 return IVI_FAILED;
1321 }
1322
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001323 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001324 }
1325
1326 *pLength = length;
1327
1328 return IVI_SUCCEEDED;
1329}
1330
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001331static
1332int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001333ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1334{
1335 struct ivi_layout *layout = get_instance();
1336 struct ivi_layout_surface *ivisurf = NULL;
1337 int32_t length = 0;
1338 int32_t n = 0;
1339
1340 if (pLength == NULL || ppArray == NULL) {
1341 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1342 return IVI_FAILED;
1343 }
1344
1345 length = wl_list_length(&layout->surface_list);
1346
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001347 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001348 /* the Array must be free by module which called this function */
1349 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1350 if (*ppArray == NULL) {
1351 weston_log("fails to allocate memory\n");
1352 return IVI_FAILED;
1353 }
1354
1355 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1356 (*ppArray)[n++] = ivisurf;
1357 }
1358 }
1359
1360 *pLength = length;
1361
1362 return IVI_SUCCEEDED;
1363}
1364
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001365static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001366ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1367 int32_t *pLength,
1368 struct ivi_layout_surface ***ppArray)
1369{
1370 struct ivi_layout_surface *ivisurf = NULL;
1371 int32_t length = 0;
1372 int32_t n = 0;
1373
1374 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1375 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1376 return IVI_FAILED;
1377 }
1378
1379 length = wl_list_length(&ivilayer->order.surface_list);
1380
1381 if (length != 0) {
1382 /* the Array must be free by module which called this function */
1383 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1384 if (*ppArray == NULL) {
1385 weston_log("fails to allocate memory\n");
1386 return IVI_FAILED;
1387 }
1388
1389 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1390 (*ppArray)[n++] = ivisurf;
1391 }
1392 }
1393
1394 *pLength = length;
1395
1396 return IVI_SUCCEEDED;
1397}
1398
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001399static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001400ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1401 int32_t width, int32_t height)
1402{
1403 struct ivi_layout *layout = get_instance();
1404 struct ivi_layout_layer *ivilayer = NULL;
1405
1406 ivilayer = get_layer(&layout->layer_list, id_layer);
1407 if (ivilayer != NULL) {
1408 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001409 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001410 return ivilayer;
1411 }
1412
1413 ivilayer = calloc(1, sizeof *ivilayer);
1414 if (ivilayer == NULL) {
1415 weston_log("fails to allocate memory\n");
1416 return NULL;
1417 }
1418
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001419 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001420 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001421 ivilayer->layout = layout;
1422 ivilayer->id_layer = id_layer;
1423
1424 init_layer_properties(&ivilayer->prop, width, height);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001425
1426 wl_list_init(&ivilayer->pending.surface_list);
1427 wl_list_init(&ivilayer->pending.link);
1428 ivilayer->pending.prop = ivilayer->prop;
1429
1430 wl_list_init(&ivilayer->order.surface_list);
1431 wl_list_init(&ivilayer->order.link);
1432
1433 wl_list_insert(&layout->layer_list, &ivilayer->link);
1434
1435 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1436
1437 return ivilayer;
1438}
1439
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001440static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001441ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001442{
1443 struct ivi_layout *layout = get_instance();
1444
1445 if (ivilayer == NULL) {
1446 weston_log("ivi_layout_layer_remove: invalid argument\n");
1447 return;
1448 }
1449
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001450 if (--ivilayer->ref_count > 0)
1451 return;
1452
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001453 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1454
1455 clear_surface_pending_list(ivilayer);
1456 clear_surface_order_list(ivilayer);
1457
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001458 wl_list_remove(&ivilayer->pending.link);
1459 wl_list_remove(&ivilayer->order.link);
1460 wl_list_remove(&ivilayer->link);
1461
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001462 free(ivilayer);
1463}
1464
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001465int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001466ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1467 bool newVisibility)
1468{
1469 struct ivi_layout_layer_properties *prop = NULL;
1470
1471 if (ivilayer == NULL) {
1472 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1473 return IVI_FAILED;
1474 }
1475
1476 prop = &ivilayer->pending.prop;
1477 prop->visibility = newVisibility;
1478
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001479 if (ivilayer->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001480 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001481 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001482 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001483
1484 return IVI_SUCCEEDED;
1485}
1486
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001487int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001488ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1489 wl_fixed_t opacity)
1490{
1491 struct ivi_layout_layer_properties *prop = NULL;
1492
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001493 if (ivilayer == NULL ||
1494 opacity < wl_fixed_from_double(0.0) ||
1495 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001496 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1497 return IVI_FAILED;
1498 }
1499
1500 prop = &ivilayer->pending.prop;
1501 prop->opacity = opacity;
1502
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001503 if (ivilayer->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001504 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001505 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001506 prop->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001507
1508 return IVI_SUCCEEDED;
1509}
1510
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001511static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001512ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1513 int32_t x, int32_t y,
1514 int32_t width, int32_t height)
1515{
1516 struct ivi_layout_layer_properties *prop = NULL;
1517
1518 if (ivilayer == NULL) {
1519 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1520 return IVI_FAILED;
1521 }
1522
1523 prop = &ivilayer->pending.prop;
1524 prop->source_x = x;
1525 prop->source_y = y;
1526 prop->source_width = width;
1527 prop->source_height = height;
1528
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001529 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1530 ivilayer->prop.source_width != width ||
1531 ivilayer->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001532 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001533 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001534 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001535
1536 return IVI_SUCCEEDED;
1537}
1538
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001539int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001540ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1541 int32_t x, int32_t y,
1542 int32_t width, int32_t height)
1543{
1544 struct ivi_layout_layer_properties *prop = NULL;
1545
1546 if (ivilayer == NULL) {
1547 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1548 return IVI_FAILED;
1549 }
1550
1551 prop = &ivilayer->pending.prop;
1552 prop->dest_x = x;
1553 prop->dest_y = y;
1554 prop->dest_width = width;
1555 prop->dest_height = height;
1556
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001557 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1558 ivilayer->prop.dest_width != width ||
1559 ivilayer->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001560 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001561 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001562 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001563
1564 return IVI_SUCCEEDED;
1565}
1566
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001567static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001568ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1569 enum wl_output_transform orientation)
1570{
1571 struct ivi_layout_layer_properties *prop = NULL;
1572
1573 if (ivilayer == NULL) {
1574 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1575 return IVI_FAILED;
1576 }
1577
1578 prop = &ivilayer->pending.prop;
1579 prop->orientation = orientation;
1580
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001581 if (ivilayer->prop.orientation != orientation)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001582 prop->event_mask |= IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001583 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001584 prop->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001585
1586 return IVI_SUCCEEDED;
1587}
1588
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001589int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001590ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1591 struct ivi_layout_surface **pSurface,
1592 int32_t number)
1593{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001594 int32_t i = 0;
1595
1596 if (ivilayer == NULL) {
1597 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1598 return IVI_FAILED;
1599 }
1600
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001601 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001602
1603 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)72ad1642016-03-16 13:37:05 +00001604 wl_list_remove(&pSurface[i]->pending.link);
1605 wl_list_insert(&ivilayer->pending.surface_list,
1606 &pSurface[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001607 }
1608
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001609 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001610
1611 return IVI_SUCCEEDED;
1612}
1613
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001614int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001615ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1616 bool newVisibility)
1617{
1618 struct ivi_layout_surface_properties *prop = NULL;
1619
1620 if (ivisurf == NULL) {
1621 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1622 return IVI_FAILED;
1623 }
1624
1625 prop = &ivisurf->pending.prop;
1626 prop->visibility = newVisibility;
1627
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001628 if (ivisurf->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001629 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001630 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001631 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001632
1633 return IVI_SUCCEEDED;
1634}
1635
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001636int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001637ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1638 wl_fixed_t opacity)
1639{
1640 struct ivi_layout_surface_properties *prop = NULL;
1641
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001642 if (ivisurf == NULL ||
1643 opacity < wl_fixed_from_double(0.0) ||
1644 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001645 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1646 return IVI_FAILED;
1647 }
1648
1649 prop = &ivisurf->pending.prop;
1650 prop->opacity = opacity;
1651
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001652 if (ivisurf->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001653 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
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_OPACITY;
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_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1662 int32_t x, int32_t y,
1663 int32_t width, int32_t height)
1664{
1665 struct ivi_layout_surface_properties *prop = NULL;
1666
1667 if (ivisurf == NULL) {
1668 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1669 return IVI_FAILED;
1670 }
1671
1672 prop = &ivisurf->pending.prop;
1673 prop->start_x = prop->dest_x;
1674 prop->start_y = prop->dest_y;
1675 prop->dest_x = x;
1676 prop->dest_y = y;
1677 prop->start_width = prop->dest_width;
1678 prop->start_height = prop->dest_height;
1679 prop->dest_width = width;
1680 prop->dest_height = height;
1681
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001682 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
1683 ivisurf->prop.dest_width != width ||
1684 ivisurf->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001685 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001686 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001687 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001688
1689 return IVI_SUCCEEDED;
1690}
1691
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001692static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001693ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
1694 enum wl_output_transform orientation)
1695{
1696 struct ivi_layout_surface_properties *prop = NULL;
1697
1698 if (ivisurf == NULL) {
1699 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
1700 return IVI_FAILED;
1701 }
1702
1703 prop = &ivisurf->pending.prop;
1704 prop->orientation = orientation;
1705
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001706 if (ivisurf->prop.orientation != orientation)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001707 prop->event_mask |= IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001708 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001709 prop->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001710
1711 return IVI_SUCCEEDED;
1712}
1713
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001714static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001715ivi_layout_screen_add_layer(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001716 struct ivi_layout_layer *addlayer)
1717{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001718 struct ivi_layout_screen *iviscrn;
1719
1720 if (output == NULL || addlayer == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001721 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
1722 return IVI_FAILED;
1723 }
1724
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001725 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001726
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00001727 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001728 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
1729 return IVI_SUCCEEDED;
1730 }
1731
Ucan, Emre (ADITG/SW1)f46306f2016-03-16 13:37:07 +00001732 wl_list_remove(&addlayer->pending.link);
1733 wl_list_insert(&iviscrn->pending.layer_list, &addlayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001734
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001735 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001736
1737 return IVI_SUCCEEDED;
1738}
1739
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001740static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001741ivi_layout_screen_set_render_order(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001742 struct ivi_layout_layer **pLayer,
1743 const int32_t number)
1744{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001745 struct ivi_layout_screen *iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001746 struct ivi_layout_layer *ivilayer = NULL;
1747 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001748 int32_t i = 0;
1749
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001750 if (output == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001751 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
1752 return IVI_FAILED;
1753 }
1754
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001755 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001756
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001757 wl_list_for_each_safe(ivilayer, next,
1758 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001759 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001760 wl_list_init(&ivilayer->pending.link);
1761 }
1762
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001763 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001764
1765 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)4e221f02016-03-16 13:37:08 +00001766 wl_list_remove(&pLayer[i]->pending.link);
1767 wl_list_insert(&iviscrn->pending.layer_list,
1768 &pLayer[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001769 }
1770
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001771 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001772
1773 return IVI_SUCCEEDED;
1774}
1775
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001776/**
1777 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
1778 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
1779 * This function is used to get the result of drawing by clients.
1780 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001781static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001782ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
1783{
1784 return ivisurf != NULL ? ivisurf->surface : NULL;
1785}
1786
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001787static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09001788ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
1789 int32_t *width, int32_t *height,
1790 int32_t *stride)
1791{
1792 int32_t w;
1793 int32_t h;
1794 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
1795
1796 if (ivisurf == NULL || ivisurf->surface == NULL) {
1797 weston_log("%s: invalid argument\n", __func__);
1798 return IVI_FAILED;
1799 }
1800
1801 weston_surface_get_content_size(ivisurf->surface, &w, &h);
1802
1803 if (width != NULL)
1804 *width = w;
1805
1806 if (height != NULL)
1807 *height = h;
1808
1809 if (stride != NULL)
1810 *stride = w * bytespp;
1811
1812 return IVI_SUCCEEDED;
1813}
1814
1815static int32_t
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001816ivi_layout_layer_add_listener(struct ivi_layout_layer *ivilayer,
1817 struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001818{
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001819 if (ivilayer == NULL || listener == NULL) {
1820 weston_log("ivi_layout_layer_add_listener: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001821 return IVI_FAILED;
1822 }
1823
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001824 wl_signal_add(&ivilayer->property_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001825
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001826 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001827}
1828
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001829static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001830ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
1831{
1832 if (ivisurf == NULL) {
1833 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
1834 return NULL;
1835 }
1836
1837 return &ivisurf->prop;
1838}
1839
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001840static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001841ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
1842 struct ivi_layout_surface *addsurf)
1843{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001844 if (ivilayer == NULL || addsurf == NULL) {
1845 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
1846 return IVI_FAILED;
1847 }
1848
Wataru Natsume9c926fe2016-03-03 19:56:09 +09001849 if (addsurf->on_layer == ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001850 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001851
Ucan, Emre (ADITG/SW1)10942372016-03-16 13:37:02 +00001852 wl_list_remove(&addsurf->pending.link);
1853 wl_list_insert(&ivilayer->pending.surface_list, &addsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001854
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001855 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001856
1857 return IVI_SUCCEEDED;
1858}
1859
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001860static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001861ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
1862 struct ivi_layout_surface *remsurf)
1863{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001864 if (ivilayer == NULL || remsurf == NULL) {
1865 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
1866 return;
1867 }
1868
Ucan, Emre (ADITG/SW1)536d8332016-03-16 13:36:59 +00001869 wl_list_remove(&remsurf->pending.link);
1870 wl_list_init(&remsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001871
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001872 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001873}
1874
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001875static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001876ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
1877 int32_t x, int32_t y,
1878 int32_t width, int32_t height)
1879{
1880 struct ivi_layout_surface_properties *prop = NULL;
1881
1882 if (ivisurf == NULL) {
1883 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
1884 return IVI_FAILED;
1885 }
1886
1887 prop = &ivisurf->pending.prop;
1888 prop->source_x = x;
1889 prop->source_y = y;
1890 prop->source_width = width;
1891 prop->source_height = height;
1892
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001893 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
1894 ivisurf->prop.source_width != width ||
1895 ivisurf->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001896 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001897 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001898 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001899
1900 return IVI_SUCCEEDED;
1901}
1902
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001903int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001904ivi_layout_commit_changes(void)
1905{
1906 struct ivi_layout *layout = get_instance();
1907
1908 commit_surface_list(layout);
1909 commit_layer_list(layout);
1910 commit_screen_list(layout);
1911
1912 commit_transition(layout);
1913
1914 commit_changes(layout);
1915 send_prop(layout);
1916 weston_compositor_schedule_repaint(layout->compositor);
1917
1918 return IVI_SUCCEEDED;
1919}
1920
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001921static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001922ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
1923 enum ivi_layout_transition_type type,
1924 uint32_t duration)
1925{
1926 if (ivilayer == NULL) {
1927 weston_log("%s: invalid argument\n", __func__);
1928 return -1;
1929 }
1930
1931 ivilayer->pending.prop.transition_type = type;
1932 ivilayer->pending.prop.transition_duration = duration;
1933
1934 return 0;
1935}
1936
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001937static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001938ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
1939 uint32_t is_fade_in,
1940 double start_alpha, double end_alpha)
1941{
1942 if (ivilayer == NULL) {
1943 weston_log("%s: invalid argument\n", __func__);
1944 return -1;
1945 }
1946
1947 ivilayer->pending.prop.is_fade_in = is_fade_in;
1948 ivilayer->pending.prop.start_alpha = start_alpha;
1949 ivilayer->pending.prop.end_alpha = end_alpha;
1950
1951 return 0;
1952}
1953
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001954static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001955ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
1956 uint32_t duration)
1957{
1958 struct ivi_layout_surface_properties *prop;
1959
1960 if (ivisurf == NULL) {
1961 weston_log("%s: invalid argument\n", __func__);
1962 return -1;
1963 }
1964
1965 prop = &ivisurf->pending.prop;
1966 prop->transition_duration = duration*10;
1967 return 0;
1968}
1969
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001970static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001971ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
1972 enum ivi_layout_transition_type type,
1973 uint32_t duration)
1974{
1975 struct ivi_layout_surface_properties *prop;
1976
1977 if (ivisurf == NULL) {
1978 weston_log("%s: invalid argument\n", __func__);
1979 return -1;
1980 }
1981
1982 prop = &ivisurf->pending.prop;
1983 prop->transition_type = type;
1984 prop->transition_duration = duration;
1985 return 0;
1986}
1987
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09001988static int32_t
1989ivi_layout_surface_dump(struct weston_surface *surface,
1990 void *target, size_t size,int32_t x, int32_t y,
1991 int32_t width, int32_t height)
1992{
1993 int result = 0;
1994
1995 if (surface == NULL) {
1996 weston_log("%s: invalid argument\n", __func__);
1997 return IVI_FAILED;
1998 }
1999
2000 result = weston_surface_copy_content(
2001 surface, target, size,
2002 x, y, width, height);
2003
2004 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2005}
2006
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002007/**
2008 * methods of interaction between ivi-shell with ivi-layout
2009 */
2010struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002011ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2012{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002013 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002014 return NULL;
2015
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002016 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002017}
2018
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002019void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002020ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2021 int32_t width, int32_t height)
2022{
2023 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002024
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002025 /* emit callback which is set by ivi-layout api user */
2026 wl_signal_emit(&layout->surface_notification.configure_changed,
2027 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002028}
2029
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002030struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002031ivi_layout_surface_create(struct weston_surface *wl_surface,
2032 uint32_t id_surface)
2033{
2034 struct ivi_layout *layout = get_instance();
2035 struct ivi_layout_surface *ivisurf = NULL;
2036 struct weston_view *tmpview = NULL;
2037
2038 if (wl_surface == NULL) {
2039 weston_log("ivi_layout_surface_create: invalid argument\n");
2040 return NULL;
2041 }
2042
2043 ivisurf = get_surface(&layout->surface_list, id_surface);
2044 if (ivisurf != NULL) {
2045 if (ivisurf->surface != NULL) {
2046 weston_log("id_surface(%d) is already created\n", id_surface);
2047 return NULL;
2048 }
2049 }
2050
2051 ivisurf = calloc(1, sizeof *ivisurf);
2052 if (ivisurf == NULL) {
2053 weston_log("fails to allocate memory\n");
2054 return NULL;
2055 }
2056
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002057 wl_signal_init(&ivisurf->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002058 ivisurf->id_surface = id_surface;
2059 ivisurf->layout = layout;
2060
2061 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002062
2063 tmpview = weston_view_create(wl_surface);
2064 if (tmpview == NULL) {
2065 weston_log("fails to allocate memory\n");
2066 }
2067
2068 ivisurf->surface->width_from_buffer = 0;
2069 ivisurf->surface->height_from_buffer = 0;
2070
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002071 weston_matrix_init(&ivisurf->transform.matrix);
2072 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002073
2074 init_surface_properties(&ivisurf->prop);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002075
2076 ivisurf->pending.prop = ivisurf->prop;
2077 wl_list_init(&ivisurf->pending.link);
2078
2079 wl_list_init(&ivisurf->order.link);
2080 wl_list_init(&ivisurf->order.layer_list);
2081
2082 wl_list_insert(&layout->surface_list, &ivisurf->link);
2083
2084 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2085
2086 return ivisurf;
2087}
2088
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002089void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002090ivi_layout_init_with_compositor(struct weston_compositor *ec)
2091{
2092 struct ivi_layout *layout = get_instance();
2093
2094 layout->compositor = ec;
2095
2096 wl_list_init(&layout->surface_list);
2097 wl_list_init(&layout->layer_list);
2098 wl_list_init(&layout->screen_list);
2099
2100 wl_signal_init(&layout->layer_notification.created);
2101 wl_signal_init(&layout->layer_notification.removed);
2102
2103 wl_signal_init(&layout->surface_notification.created);
2104 wl_signal_init(&layout->surface_notification.removed);
2105 wl_signal_init(&layout->surface_notification.configure_changed);
2106
2107 /* Add layout_layer at the last of weston_compositor.layer_list */
2108 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2109
2110 create_screen(ec);
2111
2112 layout->transitions = ivi_layout_transition_set_create(ec);
2113 wl_list_init(&layout->pending_transition_list);
2114}
2115
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002116static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002117 /**
2118 * commit all changes
2119 */
2120 .commit_changes = ivi_layout_commit_changes,
2121
2122 /**
2123 * surface controller interfaces
2124 */
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00002125 .add_listener_create_surface = ivi_layout_add_listener_create_surface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002126 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2127 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2128 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2129 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2130 .get_surfaces = ivi_layout_get_surfaces,
2131 .get_id_of_surface = ivi_layout_get_id_of_surface,
2132 .get_surface_from_id = ivi_layout_get_surface_from_id,
2133 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2134 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2135 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002136 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002137 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2138 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002139 .surface_set_orientation = ivi_layout_surface_set_orientation,
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00002140 .surface_add_listener = ivi_layout_surface_add_listener,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002141 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2142 .surface_set_transition = ivi_layout_surface_set_transition,
2143 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2144
2145 /**
2146 * layer controller interfaces
2147 */
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +00002148 .add_listener_create_layer = ivi_layout_add_listener_create_layer,
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +00002149 .add_listener_remove_layer = ivi_layout_add_listener_remove_layer,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002150 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002151 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002152 .get_layers = ivi_layout_get_layers,
2153 .get_id_of_layer = ivi_layout_get_id_of_layer,
2154 .get_layer_from_id = ivi_layout_get_layer_from_id,
2155 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2156 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2157 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2158 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002159 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002160 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2161 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002162 .layer_set_orientation = ivi_layout_layer_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002163 .layer_add_surface = ivi_layout_layer_add_surface,
2164 .layer_remove_surface = ivi_layout_layer_remove_surface,
2165 .layer_set_render_order = ivi_layout_layer_set_render_order,
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00002166 .layer_add_listener = ivi_layout_layer_add_listener,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002167 .layer_set_transition = ivi_layout_layer_set_transition,
2168
2169 /**
Ucan, Emre (ADITG/SW1)6d89b1c2016-03-17 15:30:49 +00002170 * screen controller interfaces
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002171 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002172 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2173 .screen_add_layer = ivi_layout_screen_add_layer,
2174 .screen_set_render_order = ivi_layout_screen_set_render_order,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002175
2176 /**
2177 * animation
2178 */
2179 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002180 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2181
2182 /**
2183 * surface content dumping for debugging
2184 */
2185 .surface_get_size = ivi_layout_surface_get_size,
2186 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002187};
2188
2189int
2190load_controller_modules(struct weston_compositor *compositor, const char *modules,
2191 int *argc, char *argv[])
2192{
2193 const char *p, *end;
2194 char buffer[256];
2195 int (*controller_module_init)(struct weston_compositor *compositor,
2196 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002197 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002198 size_t interface_version);
2199
2200 if (modules == NULL)
2201 return 0;
2202
2203 p = modules;
2204 while (*p) {
2205 end = strchrnul(p, ',');
2206 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2207
2208 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002209 if (!controller_module_init)
2210 return -1;
2211
2212 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002213 &ivi_layout_interface,
2214 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002215 weston_log("ivi-shell: Initialization of controller module fails");
2216 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002217 }
2218
2219 p = end;
2220 while (*p == ',')
2221 p++;
2222 }
2223
2224 return 0;
2225}