blob: e3452d2c5563c2e93a904863cc1fe779f5375b2a [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 ivi_layout;
75
76struct ivi_layout_screen {
77 struct wl_list link;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090078
79 struct ivi_layout *layout;
80 struct weston_output *output;
81
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090082 struct {
83 struct wl_list layer_list;
84 struct wl_list link;
85 } pending;
86
87 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +000088 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090089 struct wl_list layer_list;
90 struct wl_list link;
91 } order;
92};
93
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +090094struct ivi_rectangle
95{
96 int32_t x;
97 int32_t y;
98 int32_t width;
99 int32_t height;
100};
101
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900102static struct ivi_layout ivilayout = {0};
103
104struct ivi_layout *
105get_instance(void)
106{
107 return &ivilayout;
108}
109
110/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900111 * Internal API to add/remove a ivi_layer to/from ivi_screen.
112 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900113static struct ivi_layout_surface *
114get_surface(struct wl_list *surf_list, uint32_t id_surface)
115{
116 struct ivi_layout_surface *ivisurf;
117
118 wl_list_for_each(ivisurf, surf_list, link) {
119 if (ivisurf->id_surface == id_surface) {
120 return ivisurf;
121 }
122 }
123
124 return NULL;
125}
126
127static struct ivi_layout_layer *
128get_layer(struct wl_list *layer_list, uint32_t id_layer)
129{
130 struct ivi_layout_layer *ivilayer;
131
132 wl_list_for_each(ivilayer, layer_list, link) {
133 if (ivilayer->id_layer == id_layer) {
134 return ivilayer;
135 }
136 }
137
138 return NULL;
139}
140
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000141static struct weston_view *
142get_weston_view(struct ivi_layout_surface *ivisurf)
143{
144 struct weston_view *view = NULL;
145
146 assert(ivisurf->surface != NULL);
147
148 /* One view per surface */
149 if(wl_list_empty(&ivisurf->surface->views))
150 view = NULL;
151 else
152 view = wl_container_of(ivisurf->surface->views.next, view, surface_link);
153
154 return view;
155}
156
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +0000157static struct ivi_layout_screen *
158get_screen_from_output(struct weston_output *output)
159{
160 struct ivi_layout *layout = get_instance();
161 struct ivi_layout_screen *iviscrn = NULL;
162
163 wl_list_for_each(iviscrn, &layout->screen_list, link) {
164 if (iviscrn->output == output)
165 return iviscrn;
166 }
167
168 return NULL;
169}
170
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900171/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900172 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900173 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900174void
175ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900176{
177 struct ivi_layout *layout = get_instance();
178
179 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900180 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900181 return;
182 }
183
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900184 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900185 wl_list_remove(&ivisurf->pending.link);
186 wl_list_remove(&ivisurf->order.link);
187 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900188
189 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
190
Mateusz Polroladada6e32016-03-09 09:13:26 +0000191 ivi_layout_remove_all_surface_transitions(ivisurf);
192
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900193 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900194}
195
196/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900197 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
198 * Called by ivi_layout_init_with_compositor.
199 */
200static void
201create_screen(struct weston_compositor *ec)
202{
203 struct ivi_layout *layout = get_instance();
204 struct ivi_layout_screen *iviscrn = NULL;
205 struct weston_output *output = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900206
207 wl_list_for_each(output, &ec->output_list, link) {
208 iviscrn = calloc(1, sizeof *iviscrn);
209 if (iviscrn == NULL) {
210 weston_log("fails to allocate memory\n");
211 continue;
212 }
213
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900214 iviscrn->layout = layout;
215
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900216 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900217
218 wl_list_init(&iviscrn->pending.layer_list);
219 wl_list_init(&iviscrn->pending.link);
220
221 wl_list_init(&iviscrn->order.layer_list);
222 wl_list_init(&iviscrn->order.link);
223
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900224 wl_list_insert(&layout->screen_list, &iviscrn->link);
225 }
226}
227
228/**
229 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
230 */
231static void
232init_layer_properties(struct ivi_layout_layer_properties *prop,
233 int32_t width, int32_t height)
234{
235 memset(prop, 0, sizeof *prop);
236 prop->opacity = wl_fixed_from_double(1.0);
237 prop->source_width = width;
238 prop->source_height = height;
239 prop->dest_width = width;
240 prop->dest_height = height;
241}
242
243static void
244init_surface_properties(struct ivi_layout_surface_properties *prop)
245{
246 memset(prop, 0, sizeof *prop);
247 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900248 /*
249 * FIXME: this shall be finxed by ivi-layout-transition.
250 */
251 prop->dest_width = 1;
252 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900253}
254
255/**
256 * Internal APIs to be called from ivi_layout_commit_changes.
257 */
258static void
259update_opacity(struct ivi_layout_layer *ivilayer,
260 struct ivi_layout_surface *ivisurf)
261{
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000262 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900263 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
264 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
265
Nobuhiko Tanibata90c27892015-12-26 23:52:51 +0900266 tmpview = get_weston_view(ivisurf);
267 assert(tmpview != NULL);
268 tmpview->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900269}
270
271static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900272get_rotate_values(enum wl_output_transform orientation,
273 float *v_sin,
274 float *v_cos)
275{
276 switch (orientation) {
277 case WL_OUTPUT_TRANSFORM_90:
278 *v_sin = 1.0f;
279 *v_cos = 0.0f;
280 break;
281 case WL_OUTPUT_TRANSFORM_180:
282 *v_sin = 0.0f;
283 *v_cos = -1.0f;
284 break;
285 case WL_OUTPUT_TRANSFORM_270:
286 *v_sin = -1.0f;
287 *v_cos = 0.0f;
288 break;
289 case WL_OUTPUT_TRANSFORM_NORMAL:
290 default:
291 *v_sin = 0.0f;
292 *v_cos = 1.0f;
293 break;
294 }
295}
296
297static void
298get_scale(enum wl_output_transform orientation,
299 float dest_width,
300 float dest_height,
301 float source_width,
302 float source_height,
303 float *scale_x,
304 float *scale_y)
305{
306 switch (orientation) {
307 case WL_OUTPUT_TRANSFORM_90:
308 *scale_x = dest_width / source_height;
309 *scale_y = dest_height / source_width;
310 break;
311 case WL_OUTPUT_TRANSFORM_180:
312 *scale_x = dest_width / source_width;
313 *scale_y = dest_height / source_height;
314 break;
315 case WL_OUTPUT_TRANSFORM_270:
316 *scale_x = dest_width / source_height;
317 *scale_y = dest_height / source_width;
318 break;
319 case WL_OUTPUT_TRANSFORM_NORMAL:
320 default:
321 *scale_x = dest_width / source_width;
322 *scale_y = dest_height / source_height;
323 break;
324 }
325}
326
327static void
328calc_transformation_matrix(struct ivi_rectangle *source_rect,
329 struct ivi_rectangle *dest_rect,
330 enum wl_output_transform orientation,
331 struct weston_matrix *m)
332{
333 float source_center_x;
334 float source_center_y;
335 float vsin;
336 float vcos;
337 float scale_x;
338 float scale_y;
339 float translate_x;
340 float translate_y;
341
342 source_center_x = source_rect->x + source_rect->width * 0.5f;
343 source_center_y = source_rect->y + source_rect->height * 0.5f;
344 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
345
346 get_rotate_values(orientation, &vsin, &vcos);
347 weston_matrix_rotate_xy(m, vcos, vsin);
348
349 get_scale(orientation,
350 dest_rect->width,
351 dest_rect->height,
352 source_rect->width,
353 source_rect->height,
354 &scale_x,
355 &scale_y);
356 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
357
358 translate_x = dest_rect->width * 0.5f + dest_rect->x;
359 translate_y = dest_rect->height * 0.5f + dest_rect->y;
360 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
361}
362
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900363/*
364 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900365 */
366static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900367ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
368 const struct ivi_rectangle *rect2,
369 struct ivi_rectangle *rect_output)
370{
371 int32_t rect1_right = rect1->x + rect1->width;
372 int32_t rect1_bottom = rect1->y + rect1->height;
373 int32_t rect2_right = rect2->x + rect2->width;
374 int32_t rect2_bottom = rect2->y + rect2->height;
375
376 rect_output->x = max(rect1->x, rect2->x);
377 rect_output->y = max(rect1->y, rect2->y);
378 rect_output->width = rect1_right < rect2_right ?
379 rect1_right - rect_output->x :
380 rect2_right - rect_output->x;
381 rect_output->height = rect1_bottom < rect2_bottom ?
382 rect1_bottom - rect_output->y :
383 rect2_bottom - rect_output->y;
384
385 if (rect_output->width < 0 || rect_output->height < 0) {
386 rect_output->width = 0;
387 rect_output->height = 0;
388 }
389}
390
391/*
392 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
393 * and store the result in rect_output.
394 * The boundingbox must be given in the same coordinate space as rect_output.
395 * Additionally, there are the following restrictions on the matrix:
396 * - no projective transformations
397 * - no skew
398 * - only multiples of 90-degree rotations supported
399 *
400 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
401 * as a fail-safe with log.
402 */
403static void
404calc_inverse_matrix_transform(const struct weston_matrix *matrix,
405 const struct ivi_rectangle *rect_input,
406 const struct ivi_rectangle *boundingbox,
407 struct ivi_rectangle *rect_output)
408{
409 struct weston_matrix m;
410 struct weston_vector top_left;
411 struct weston_vector bottom_right;
412
413 assert(boundingbox != rect_output);
414
415 if (weston_matrix_invert(&m, matrix) < 0) {
416 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
417 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
418 rect_output->x = boundingbox->x;
419 rect_output->y = boundingbox->y;
420 rect_output->width = boundingbox->width;
421 rect_output->height = boundingbox->height;
422 }
423
424 /* The vectors and matrices involved will always produce f[3] == 1.0. */
425 top_left.f[0] = rect_input->x;
426 top_left.f[1] = rect_input->y;
427 top_left.f[2] = 0.0f;
428 top_left.f[3] = 1.0f;
429
430 bottom_right.f[0] = rect_input->x + rect_input->width;
431 bottom_right.f[1] = rect_input->y + rect_input->height;
432 bottom_right.f[2] = 0.0f;
433 bottom_right.f[3] = 1.0f;
434
435 weston_matrix_transform(&m, &top_left);
436 weston_matrix_transform(&m, &bottom_right);
437
438 if (top_left.f[0] < bottom_right.f[0]) {
439 rect_output->x = top_left.f[0];
440 rect_output->width = bottom_right.f[0] - rect_output->x;
441 } else {
442 rect_output->x = bottom_right.f[0];
443 rect_output->width = top_left.f[0] - rect_output->x;
444 }
445
446 if (top_left.f[1] < bottom_right.f[1]) {
447 rect_output->y = top_left.f[1];
448 rect_output->height = bottom_right.f[1] - rect_output->y;
449 } else {
450 rect_output->y = bottom_right.f[1];
451 rect_output->height = top_left.f[1] - rect_output->y;
452 }
453
454 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
455}
456
457/**
458 * This computes the whole transformation matrix:m from surface-local
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900459 * coordinates to multi screens coordinate, which is global coordinates.
460 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900461 *
462 * Additionally, this computes the mask on surface-local coordinates as a
463 * ivi_rectangle. This can be set to weston_view_set_mask.
464 *
465 * The mask is computed by following steps
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900466 * - destination rectangle of layer is tansformed to multi screen coordinate,
467 * global coordinates. This is done by adding weston_output.{x,y} in simple
468 * because there is no scaled and rotated transformation.
469 * - destination rectangle of layer in multi screens coordinate needs to be
470 * intersected inside of a screen the layer is assigned to. This is because
471 * overlapped region of weston surface in another screen shall not be
472 * displayed according to ivi use case.
473 * - destination rectangle of layer
474 * - in multi screen coordinates,
475 * - and intersected inside of an assigned screen,
476 * is inversed to surface-local cooodinates by inversed matrix:m.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900477 * - the area is intersected by intersected area between weston_surface and
478 * source rectangle of ivi_surface.
479 */
480static void
481calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900482 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900483 struct ivi_layout_layer *ivilayer,
484 struct ivi_layout_surface *ivisurf,
485 struct weston_matrix *m,
486 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900487{
488 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
489 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900490 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900491 struct ivi_rectangle weston_surface_rect = { 0,
492 0,
493 ivisurf->surface->width,
494 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900495 struct ivi_rectangle surface_source_rect = { sp->source_x,
496 sp->source_y,
497 sp->source_width,
498 sp->source_height };
499 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
500 sp->dest_y,
501 sp->dest_width,
502 sp->dest_height };
503 struct ivi_rectangle layer_source_rect = { lp->source_x,
504 lp->source_y,
505 lp->source_width,
506 lp->source_height };
507 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
508 lp->dest_y,
509 lp->dest_width,
510 lp->dest_height };
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900511 struct ivi_rectangle screen_dest_rect = { output->x,
512 output->y,
513 output->width,
514 output->height };
515 struct ivi_rectangle layer_dest_rect_in_global =
516 { lp->dest_x + output->x,
517 lp->dest_y + output->y,
518 lp->dest_width,
519 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900520 struct ivi_rectangle surface_result;
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900521 struct ivi_rectangle layer_dest_rect_in_global_intersected;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900522
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900523 /*
524 * the whole transformation matrix:m from surface-local
525 * coordinates to global coordinates, which is computed by
526 * two steps,
527 * - surface-local coordinates to layer-local coordinates
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900528 * - layer-local coordinates to a single screen-local coordinates
529 * - a single screen-local coordinates to multi screen coordinates,
530 * which is global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900531 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900532 calc_transformation_matrix(&surface_source_rect,
533 &surface_dest_rect,
534 sp->orientation, m);
535
536 calc_transformation_matrix(&layer_source_rect,
537 &layer_dest_rect,
538 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900539
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900540 weston_matrix_translate(m, output->x, output->y, 0.0f);
541
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900542 /* this intersected ivi_rectangle would be used for masking
543 * weston_surface
544 */
545 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
546 &surface_result);
547
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900548 /*
549 * destination rectangle of layer in multi screens coordinate
550 * is intersected to avoid displaying outside of an assigned screen.
551 */
552 ivi_rectangle_intersect(&layer_dest_rect_in_global, &screen_dest_rect,
553 &layer_dest_rect_in_global_intersected);
554
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900555 /* calc masking area of weston_surface from m */
556 calc_inverse_matrix_transform(m,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900557 &layer_dest_rect_in_global_intersected,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900558 &surface_result,
559 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900560}
561
562static void
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900563update_prop(struct ivi_layout_screen *iviscrn,
564 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900565 struct ivi_layout_surface *ivisurf)
566{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900567 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900568 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900569 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900570
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900571 /*In case of no prop change, this just returns*/
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000572 if (!ivilayer->prop.event_mask && !ivisurf->prop.event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900573 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900574
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900575 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900576
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000577 tmpview = get_weston_view(ivisurf);
578 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900579
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900580 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
581 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
582 can_calc = false;
583 }
584
585 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
586 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
587 can_calc = false;
588 }
589
590 if (can_calc) {
591 wl_list_remove(&ivisurf->transform.link);
592 weston_matrix_init(&ivisurf->transform.matrix);
593
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900594 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900595 iviscrn, ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900596
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000597 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
598 wl_list_insert(&tmpview->geometry.transformation_list,
599 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900600
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000601 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900602 }
603
604 ivisurf->update_count++;
605
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000606 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900607
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000608 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900609}
610
611static void
612commit_changes(struct ivi_layout *layout)
613{
614 struct ivi_layout_screen *iviscrn = NULL;
615 struct ivi_layout_layer *ivilayer = NULL;
616 struct ivi_layout_surface *ivisurf = NULL;
617
618 wl_list_for_each(iviscrn, &layout->screen_list, link) {
619 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900620 /*
621 * If ivilayer is invisible, weston_view of ivisurf doesn't
622 * need to be modified.
623 */
624 if (ivilayer->prop.visibility == false)
625 continue;
626
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900627 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900628 /*
629 * If ivilayer is invisible, weston_view of ivisurf doesn't
630 * need to be modified.
631 */
632 if (ivisurf->prop.visibility == false)
633 continue;
634
635 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900636 }
637 }
638 }
639}
640
641static void
642commit_surface_list(struct ivi_layout *layout)
643{
644 struct ivi_layout_surface *ivisurf = NULL;
645 int32_t dest_x = 0;
646 int32_t dest_y = 0;
647 int32_t dest_width = 0;
648 int32_t dest_height = 0;
649 int32_t configured = 0;
650
651 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300652 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900653 dest_x = ivisurf->prop.dest_x;
654 dest_y = ivisurf->prop.dest_y;
655 dest_width = ivisurf->prop.dest_width;
656 dest_height = ivisurf->prop.dest_height;
657
658 ivi_layout_transition_move_resize_view(ivisurf,
659 ivisurf->pending.prop.dest_x,
660 ivisurf->pending.prop.dest_y,
661 ivisurf->pending.prop.dest_width,
662 ivisurf->pending.prop.dest_height,
663 ivisurf->pending.prop.transition_duration);
664
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300665 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900666 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
667 } else {
668 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
669 }
670
671 ivisurf->prop = ivisurf->pending.prop;
672 ivisurf->prop.dest_x = dest_x;
673 ivisurf->prop.dest_y = dest_y;
674 ivisurf->prop.dest_width = dest_width;
675 ivisurf->prop.dest_height = dest_height;
676 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
677 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
678
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300679 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900680 dest_x = ivisurf->prop.dest_x;
681 dest_y = ivisurf->prop.dest_y;
682 dest_width = ivisurf->prop.dest_width;
683 dest_height = ivisurf->prop.dest_height;
684
685 ivi_layout_transition_move_resize_view(ivisurf,
686 ivisurf->pending.prop.dest_x,
687 ivisurf->pending.prop.dest_y,
688 ivisurf->pending.prop.dest_width,
689 ivisurf->pending.prop.dest_height,
690 ivisurf->pending.prop.transition_duration);
691
692 ivisurf->prop = ivisurf->pending.prop;
693 ivisurf->prop.dest_x = dest_x;
694 ivisurf->prop.dest_y = dest_y;
695 ivisurf->prop.dest_width = dest_width;
696 ivisurf->prop.dest_height = dest_height;
697
698 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
699 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
700
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300701 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900702 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300703 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900704 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
705 } else {
706 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
707 }
708
709 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
710 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
711 configured = 1;
712 }
713
714 ivisurf->prop = ivisurf->pending.prop;
715 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
716 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
717
Pekka Paalanen1f821932016-03-15 16:57:51 +0200718 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200719 shell_surface_send_configure(ivisurf->surface,
720 ivisurf->prop.dest_width,
721 ivisurf->prop.dest_height);
722 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900723 } else {
724 configured = 0;
725 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
726 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
727 configured = 1;
728 }
729
730 ivisurf->prop = ivisurf->pending.prop;
731 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
732 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
733
Pekka Paalanen1f821932016-03-15 16:57:51 +0200734 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200735 shell_surface_send_configure(ivisurf->surface,
736 ivisurf->prop.dest_width,
737 ivisurf->prop.dest_height);
738 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900739 }
740 }
741}
742
743static void
744commit_layer_list(struct ivi_layout *layout)
745{
746 struct ivi_layout_layer *ivilayer = NULL;
747 struct ivi_layout_surface *ivisurf = NULL;
748 struct ivi_layout_surface *next = NULL;
749
750 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300751 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900752 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 -0300753 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900754 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
755 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
756 NULL, NULL,
757 ivilayer->pending.prop.transition_duration);
758 }
759 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
760
761 ivilayer->prop = ivilayer->pending.prop;
762
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000763 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900764 continue;
765 }
766
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000767 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
768 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000769 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000770 wl_list_remove(&ivisurf->order.link);
771 wl_list_init(&ivisurf->order.link);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000772 ivisurf->prop.event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900773 }
774
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000775 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900776
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000777 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900778 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000779 wl_list_remove(&ivisurf->order.link);
780 wl_list_insert(&ivilayer->order.surface_list,
781 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000782 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000783 ivisurf->prop.event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900784 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000785
786 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900787 }
788}
789
790static void
791commit_screen_list(struct ivi_layout *layout)
792{
793 struct ivi_layout_screen *iviscrn = NULL;
794 struct ivi_layout_layer *ivilayer = NULL;
795 struct ivi_layout_layer *next = NULL;
796 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000797 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900798
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900799 /* Clear view list of layout ivi_layer */
800 wl_list_init(&layout->layout_layer.view_list.link);
801
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900802 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000803 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900804 wl_list_for_each_safe(ivilayer, next,
805 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000806 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000807 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900808 wl_list_init(&ivilayer->order.link);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000809 ivilayer->prop.event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900810 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900811
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000812 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900813
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900814 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
815 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900816 /* FIXME: avoid to insert order.link to multiple screens */
817 wl_list_remove(&ivilayer->order.link);
818
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900819 wl_list_insert(&iviscrn->order.layer_list,
820 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000821 ivilayer->on_screen = iviscrn;
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000822 ivilayer->prop.event_mask |= IVI_NOTIFICATION_ADD;
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 iviscrn->order.dirty = 0;
826 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900827
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900828 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
829 if (ivilayer->prop.visibility == false)
830 continue;
831
832 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900833 if (ivisurf->prop.visibility == false)
834 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000835
836 tmpview = get_weston_view(ivisurf);
837 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900838
839 weston_layer_entry_insert(&layout->layout_layer.view_list,
840 &tmpview->layer_link);
841
842 ivisurf->surface->output = iviscrn->output;
843 }
844 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900845 }
846}
847
848static void
849commit_transition(struct ivi_layout* layout)
850{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300851 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900852 return;
853 }
854
855 wl_list_insert_list(&layout->transitions->transition_list,
856 &layout->pending_transition_list);
857
858 wl_list_init(&layout->pending_transition_list);
859
860 wl_event_source_timer_update(layout->transitions->event_source, 1);
861}
862
863static void
864send_surface_prop(struct ivi_layout_surface *ivisurf)
865{
866 wl_signal_emit(&ivisurf->property_changed, ivisurf);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000867 ivisurf->pending.prop.event_mask = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900868}
869
870static void
871send_layer_prop(struct ivi_layout_layer *ivilayer)
872{
873 wl_signal_emit(&ivilayer->property_changed, ivilayer);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000874 ivilayer->pending.prop.event_mask = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900875}
876
877static void
878send_prop(struct ivi_layout *layout)
879{
880 struct ivi_layout_layer *ivilayer = NULL;
881 struct ivi_layout_surface *ivisurf = NULL;
882
883 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000884 if (ivilayer->prop.event_mask)
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900885 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900886 }
887
888 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000889 if (ivisurf->prop.event_mask)
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900890 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900891 }
892}
893
894static void
895clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
896{
897 struct ivi_layout_surface *surface_link = NULL;
898 struct ivi_layout_surface *surface_next = NULL;
899
900 wl_list_for_each_safe(surface_link, surface_next,
901 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000902 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900903 wl_list_init(&surface_link->pending.link);
904 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900905}
906
907static void
908clear_surface_order_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->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000915 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900916 wl_list_init(&surface_link->order.link);
917 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900918}
919
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900920/**
921 * Exported APIs of ivi-layout library are implemented from here.
922 * Brief of APIs is described in ivi-layout-export.h.
923 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900924static int32_t
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000925ivi_layout_add_listener_create_layer(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900926{
927 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900928
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000929 if (listener == NULL) {
930 weston_log("ivi_layout_add_listener_create_layer: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900931 return IVI_FAILED;
932 }
933
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000934 wl_signal_add(&layout->layer_notification.created, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900935
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000936 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900937}
938
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900939static int32_t
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000940ivi_layout_add_listener_remove_layer(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900941{
942 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900943
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000944 if (listener == NULL) {
945 weston_log("ivi_layout_add_listener_remove_layer: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900946 return IVI_FAILED;
947 }
948
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000949 wl_signal_add(&layout->layer_notification.removed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900950
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000951 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900952}
953
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900954static int32_t
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000955ivi_layout_add_listener_create_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900956{
957 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900958
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000959 if (listener == NULL) {
960 weston_log("ivi_layout_add_listener_create_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900961 return IVI_FAILED;
962 }
963
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000964 wl_signal_add(&layout->surface_notification.created, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900965
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000966 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900967}
968
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900969static int32_t
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000970ivi_layout_add_listener_remove_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900971{
972 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900973
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000974 if (listener == NULL) {
975 weston_log("ivi_layout_add_listener_remove_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900976 return IVI_FAILED;
977 }
978
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000979 wl_signal_add(&layout->surface_notification.removed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900980
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000981 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900982}
983
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900984static int32_t
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000985ivi_layout_add_listener_configure_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900986{
987 struct ivi_layout *layout = get_instance();
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000988
989 if (listener == NULL) {
990 weston_log("ivi_layout_add_listener_configure_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900991 return IVI_FAILED;
992 }
993
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000994 wl_signal_add(&layout->surface_notification.configure_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900995
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000996 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900997}
998
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900999uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001000ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1001{
1002 return ivisurf->id_surface;
1003}
1004
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001005static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001006ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1007{
1008 return ivilayer->id_layer;
1009}
1010
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001011static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001012ivi_layout_get_layer_from_id(uint32_t id_layer)
1013{
1014 struct ivi_layout *layout = get_instance();
1015 struct ivi_layout_layer *ivilayer = NULL;
1016
1017 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1018 if (ivilayer->id_layer == id_layer) {
1019 return ivilayer;
1020 }
1021 }
1022
1023 return NULL;
1024}
1025
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001026struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001027ivi_layout_get_surface_from_id(uint32_t id_surface)
1028{
1029 struct ivi_layout *layout = get_instance();
1030 struct ivi_layout_surface *ivisurf = NULL;
1031
1032 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1033 if (ivisurf->id_surface == id_surface) {
1034 return ivisurf;
1035 }
1036 }
1037
1038 return NULL;
1039}
1040
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001041static int32_t
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001042ivi_layout_surface_add_listener(struct ivi_layout_surface *ivisurf,
1043 struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001044{
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001045 if (ivisurf == NULL || listener == NULL) {
1046 weston_log("ivi_layout_surface_add_listener: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001047 return IVI_FAILED;
1048 }
1049
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001050 wl_signal_add(&ivisurf->property_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001051
1052 return IVI_SUCCEEDED;
1053}
1054
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001055static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001056ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1057{
1058 if (ivilayer == NULL) {
1059 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1060 return NULL;
1061 }
1062
1063 return &ivilayer->prop;
1064}
1065
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001066static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001067ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1068 int32_t *pLength,
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001069 struct weston_output ***ppArray)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001070{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001071 int32_t length = 0;
1072 int32_t n = 0;
1073
1074 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1075 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1076 return IVI_FAILED;
1077 }
1078
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001079 if (ivilayer->on_screen != NULL)
1080 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001081
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001082 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001083 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001084 *ppArray = calloc(length, sizeof(struct weston_output *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001085 if (*ppArray == NULL) {
1086 weston_log("fails to allocate memory\n");
1087 return IVI_FAILED;
1088 }
1089
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001090 (*ppArray)[n++] = ivilayer->on_screen->output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001091 }
1092
1093 *pLength = length;
1094
1095 return IVI_SUCCEEDED;
1096}
1097
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001098static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001099ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1100{
1101 struct ivi_layout *layout = get_instance();
1102 struct ivi_layout_layer *ivilayer = NULL;
1103 int32_t length = 0;
1104 int32_t n = 0;
1105
1106 if (pLength == NULL || ppArray == NULL) {
1107 weston_log("ivi_layout_get_layers: invalid argument\n");
1108 return IVI_FAILED;
1109 }
1110
1111 length = wl_list_length(&layout->layer_list);
1112
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001113 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001114 /* the Array must be free by module which called this function */
1115 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1116 if (*ppArray == NULL) {
1117 weston_log("fails to allocate memory\n");
1118 return IVI_FAILED;
1119 }
1120
1121 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1122 (*ppArray)[n++] = ivilayer;
1123 }
1124 }
1125
1126 *pLength = length;
1127
1128 return IVI_SUCCEEDED;
1129}
1130
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001131static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001132ivi_layout_get_layers_on_screen(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001133 int32_t *pLength,
1134 struct ivi_layout_layer ***ppArray)
1135{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001136 struct ivi_layout_screen *iviscrn = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001137 struct ivi_layout_layer *ivilayer = NULL;
1138 int32_t length = 0;
1139 int32_t n = 0;
1140
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001141 if (output == NULL || pLength == NULL || ppArray == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001142 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1143 return IVI_FAILED;
1144 }
1145
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001146 iviscrn = get_screen_from_output(output);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001147 length = wl_list_length(&iviscrn->order.layer_list);
1148
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001149 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001150 /* the Array must be free by module which called this function */
1151 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1152 if (*ppArray == NULL) {
1153 weston_log("fails to allocate memory\n");
1154 return IVI_FAILED;
1155 }
1156
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001157 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001158 (*ppArray)[n++] = ivilayer;
1159 }
1160 }
1161
1162 *pLength = length;
1163
1164 return IVI_SUCCEEDED;
1165}
1166
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001167static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001168ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1169 int32_t *pLength,
1170 struct ivi_layout_layer ***ppArray)
1171{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001172 int32_t length = 0;
1173 int32_t n = 0;
1174
1175 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1176 weston_log("ivi_layout_getLayers: invalid argument\n");
1177 return IVI_FAILED;
1178 }
1179
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001180 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001181 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001182 length = 1;
1183 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001184 if (*ppArray == NULL) {
1185 weston_log("fails to allocate memory\n");
1186 return IVI_FAILED;
1187 }
1188
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001189 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001190 }
1191
1192 *pLength = length;
1193
1194 return IVI_SUCCEEDED;
1195}
1196
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001197static
1198int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001199ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1200{
1201 struct ivi_layout *layout = get_instance();
1202 struct ivi_layout_surface *ivisurf = NULL;
1203 int32_t length = 0;
1204 int32_t n = 0;
1205
1206 if (pLength == NULL || ppArray == NULL) {
1207 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1208 return IVI_FAILED;
1209 }
1210
1211 length = wl_list_length(&layout->surface_list);
1212
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001213 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001214 /* the Array must be free by module which called this function */
1215 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1216 if (*ppArray == NULL) {
1217 weston_log("fails to allocate memory\n");
1218 return IVI_FAILED;
1219 }
1220
1221 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1222 (*ppArray)[n++] = ivisurf;
1223 }
1224 }
1225
1226 *pLength = length;
1227
1228 return IVI_SUCCEEDED;
1229}
1230
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001231static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001232ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1233 int32_t *pLength,
1234 struct ivi_layout_surface ***ppArray)
1235{
1236 struct ivi_layout_surface *ivisurf = NULL;
1237 int32_t length = 0;
1238 int32_t n = 0;
1239
1240 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1241 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1242 return IVI_FAILED;
1243 }
1244
1245 length = wl_list_length(&ivilayer->order.surface_list);
1246
1247 if (length != 0) {
1248 /* the Array must be free by module which called this function */
1249 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1250 if (*ppArray == NULL) {
1251 weston_log("fails to allocate memory\n");
1252 return IVI_FAILED;
1253 }
1254
1255 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1256 (*ppArray)[n++] = ivisurf;
1257 }
1258 }
1259
1260 *pLength = length;
1261
1262 return IVI_SUCCEEDED;
1263}
1264
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001265static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001266ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1267 int32_t width, int32_t height)
1268{
1269 struct ivi_layout *layout = get_instance();
1270 struct ivi_layout_layer *ivilayer = NULL;
1271
1272 ivilayer = get_layer(&layout->layer_list, id_layer);
1273 if (ivilayer != NULL) {
1274 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001275 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001276 return ivilayer;
1277 }
1278
1279 ivilayer = calloc(1, sizeof *ivilayer);
1280 if (ivilayer == NULL) {
1281 weston_log("fails to allocate memory\n");
1282 return NULL;
1283 }
1284
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001285 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001286 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001287 ivilayer->layout = layout;
1288 ivilayer->id_layer = id_layer;
1289
1290 init_layer_properties(&ivilayer->prop, width, height);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001291
1292 wl_list_init(&ivilayer->pending.surface_list);
1293 wl_list_init(&ivilayer->pending.link);
1294 ivilayer->pending.prop = ivilayer->prop;
1295
1296 wl_list_init(&ivilayer->order.surface_list);
1297 wl_list_init(&ivilayer->order.link);
1298
1299 wl_list_insert(&layout->layer_list, &ivilayer->link);
1300
1301 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1302
1303 return ivilayer;
1304}
1305
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001306static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001307ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001308{
1309 struct ivi_layout *layout = get_instance();
1310
1311 if (ivilayer == NULL) {
1312 weston_log("ivi_layout_layer_remove: invalid argument\n");
1313 return;
1314 }
1315
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001316 if (--ivilayer->ref_count > 0)
1317 return;
1318
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001319 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1320
1321 clear_surface_pending_list(ivilayer);
1322 clear_surface_order_list(ivilayer);
1323
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001324 wl_list_remove(&ivilayer->pending.link);
1325 wl_list_remove(&ivilayer->order.link);
1326 wl_list_remove(&ivilayer->link);
1327
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001328 free(ivilayer);
1329}
1330
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001331int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001332ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1333 bool newVisibility)
1334{
1335 struct ivi_layout_layer_properties *prop = NULL;
1336
1337 if (ivilayer == NULL) {
1338 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1339 return IVI_FAILED;
1340 }
1341
1342 prop = &ivilayer->pending.prop;
1343 prop->visibility = newVisibility;
1344
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001345 if (ivilayer->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001346 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001347 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001348 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001349
1350 return IVI_SUCCEEDED;
1351}
1352
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001353int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001354ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1355 wl_fixed_t opacity)
1356{
1357 struct ivi_layout_layer_properties *prop = NULL;
1358
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001359 if (ivilayer == NULL ||
1360 opacity < wl_fixed_from_double(0.0) ||
1361 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001362 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1363 return IVI_FAILED;
1364 }
1365
1366 prop = &ivilayer->pending.prop;
1367 prop->opacity = opacity;
1368
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001369 if (ivilayer->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001370 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001371 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001372 prop->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001373
1374 return IVI_SUCCEEDED;
1375}
1376
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001377static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001378ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1379 int32_t x, int32_t y,
1380 int32_t width, int32_t height)
1381{
1382 struct ivi_layout_layer_properties *prop = NULL;
1383
1384 if (ivilayer == NULL) {
1385 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1386 return IVI_FAILED;
1387 }
1388
1389 prop = &ivilayer->pending.prop;
1390 prop->source_x = x;
1391 prop->source_y = y;
1392 prop->source_width = width;
1393 prop->source_height = height;
1394
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001395 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1396 ivilayer->prop.source_width != width ||
1397 ivilayer->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001398 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001399 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001400 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001401
1402 return IVI_SUCCEEDED;
1403}
1404
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001405int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001406ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1407 int32_t x, int32_t y,
1408 int32_t width, int32_t height)
1409{
1410 struct ivi_layout_layer_properties *prop = NULL;
1411
1412 if (ivilayer == NULL) {
1413 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1414 return IVI_FAILED;
1415 }
1416
1417 prop = &ivilayer->pending.prop;
1418 prop->dest_x = x;
1419 prop->dest_y = y;
1420 prop->dest_width = width;
1421 prop->dest_height = height;
1422
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001423 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1424 ivilayer->prop.dest_width != width ||
1425 ivilayer->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001426 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001427 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001428 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001429
1430 return IVI_SUCCEEDED;
1431}
1432
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001433static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001434ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1435 enum wl_output_transform orientation)
1436{
1437 struct ivi_layout_layer_properties *prop = NULL;
1438
1439 if (ivilayer == NULL) {
1440 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1441 return IVI_FAILED;
1442 }
1443
1444 prop = &ivilayer->pending.prop;
1445 prop->orientation = orientation;
1446
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001447 if (ivilayer->prop.orientation != orientation)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001448 prop->event_mask |= IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001449 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001450 prop->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001451
1452 return IVI_SUCCEEDED;
1453}
1454
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001455int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001456ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1457 struct ivi_layout_surface **pSurface,
1458 int32_t number)
1459{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001460 int32_t i = 0;
1461
1462 if (ivilayer == NULL) {
1463 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1464 return IVI_FAILED;
1465 }
1466
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001467 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001468
1469 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)72ad1642016-03-16 13:37:05 +00001470 wl_list_remove(&pSurface[i]->pending.link);
1471 wl_list_insert(&ivilayer->pending.surface_list,
1472 &pSurface[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001473 }
1474
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001475 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001476
1477 return IVI_SUCCEEDED;
1478}
1479
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001480int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001481ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1482 bool newVisibility)
1483{
1484 struct ivi_layout_surface_properties *prop = NULL;
1485
1486 if (ivisurf == NULL) {
1487 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1488 return IVI_FAILED;
1489 }
1490
1491 prop = &ivisurf->pending.prop;
1492 prop->visibility = newVisibility;
1493
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001494 if (ivisurf->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001495 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001496 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001497 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001498
1499 return IVI_SUCCEEDED;
1500}
1501
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001502int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001503ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1504 wl_fixed_t opacity)
1505{
1506 struct ivi_layout_surface_properties *prop = NULL;
1507
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001508 if (ivisurf == NULL ||
1509 opacity < wl_fixed_from_double(0.0) ||
1510 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001511 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1512 return IVI_FAILED;
1513 }
1514
1515 prop = &ivisurf->pending.prop;
1516 prop->opacity = opacity;
1517
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001518 if (ivisurf->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001519 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001520 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001521 prop->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001522
1523 return IVI_SUCCEEDED;
1524}
1525
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001526int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001527ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1528 int32_t x, int32_t y,
1529 int32_t width, int32_t height)
1530{
1531 struct ivi_layout_surface_properties *prop = NULL;
1532
1533 if (ivisurf == NULL) {
1534 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1535 return IVI_FAILED;
1536 }
1537
1538 prop = &ivisurf->pending.prop;
1539 prop->start_x = prop->dest_x;
1540 prop->start_y = prop->dest_y;
1541 prop->dest_x = x;
1542 prop->dest_y = y;
1543 prop->start_width = prop->dest_width;
1544 prop->start_height = prop->dest_height;
1545 prop->dest_width = width;
1546 prop->dest_height = height;
1547
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001548 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
1549 ivisurf->prop.dest_width != width ||
1550 ivisurf->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001551 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001552 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001553 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001554
1555 return IVI_SUCCEEDED;
1556}
1557
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001558static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001559ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
1560 enum wl_output_transform orientation)
1561{
1562 struct ivi_layout_surface_properties *prop = NULL;
1563
1564 if (ivisurf == NULL) {
1565 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
1566 return IVI_FAILED;
1567 }
1568
1569 prop = &ivisurf->pending.prop;
1570 prop->orientation = orientation;
1571
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001572 if (ivisurf->prop.orientation != orientation)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001573 prop->event_mask |= IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001574 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001575 prop->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001576
1577 return IVI_SUCCEEDED;
1578}
1579
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001580static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001581ivi_layout_screen_add_layer(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001582 struct ivi_layout_layer *addlayer)
1583{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001584 struct ivi_layout_screen *iviscrn;
1585
1586 if (output == NULL || addlayer == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001587 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
1588 return IVI_FAILED;
1589 }
1590
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001591 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001592
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00001593 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001594 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
1595 return IVI_SUCCEEDED;
1596 }
1597
Ucan, Emre (ADITG/SW1)f46306f2016-03-16 13:37:07 +00001598 wl_list_remove(&addlayer->pending.link);
1599 wl_list_insert(&iviscrn->pending.layer_list, &addlayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001600
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001601 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001602
1603 return IVI_SUCCEEDED;
1604}
1605
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001606static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001607ivi_layout_screen_set_render_order(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001608 struct ivi_layout_layer **pLayer,
1609 const int32_t number)
1610{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001611 struct ivi_layout_screen *iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001612 struct ivi_layout_layer *ivilayer = NULL;
1613 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001614 int32_t i = 0;
1615
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001616 if (output == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001617 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
1618 return IVI_FAILED;
1619 }
1620
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001621 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001622
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001623 wl_list_for_each_safe(ivilayer, next,
1624 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001625 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001626 wl_list_init(&ivilayer->pending.link);
1627 }
1628
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001629 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001630
1631 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)4e221f02016-03-16 13:37:08 +00001632 wl_list_remove(&pLayer[i]->pending.link);
1633 wl_list_insert(&iviscrn->pending.layer_list,
1634 &pLayer[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001635 }
1636
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001637 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001638
1639 return IVI_SUCCEEDED;
1640}
1641
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001642/**
1643 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
1644 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
1645 * This function is used to get the result of drawing by clients.
1646 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001647static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001648ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
1649{
1650 return ivisurf != NULL ? ivisurf->surface : NULL;
1651}
1652
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001653static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09001654ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
1655 int32_t *width, int32_t *height,
1656 int32_t *stride)
1657{
1658 int32_t w;
1659 int32_t h;
1660 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
1661
1662 if (ivisurf == NULL || ivisurf->surface == NULL) {
1663 weston_log("%s: invalid argument\n", __func__);
1664 return IVI_FAILED;
1665 }
1666
1667 weston_surface_get_content_size(ivisurf->surface, &w, &h);
1668
1669 if (width != NULL)
1670 *width = w;
1671
1672 if (height != NULL)
1673 *height = h;
1674
1675 if (stride != NULL)
1676 *stride = w * bytespp;
1677
1678 return IVI_SUCCEEDED;
1679}
1680
1681static int32_t
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001682ivi_layout_layer_add_listener(struct ivi_layout_layer *ivilayer,
1683 struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001684{
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001685 if (ivilayer == NULL || listener == NULL) {
1686 weston_log("ivi_layout_layer_add_listener: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001687 return IVI_FAILED;
1688 }
1689
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001690 wl_signal_add(&ivilayer->property_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001691
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001692 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001693}
1694
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001695static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001696ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
1697{
1698 if (ivisurf == NULL) {
1699 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
1700 return NULL;
1701 }
1702
1703 return &ivisurf->prop;
1704}
1705
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001706static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001707ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
1708 struct ivi_layout_surface *addsurf)
1709{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001710 if (ivilayer == NULL || addsurf == NULL) {
1711 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
1712 return IVI_FAILED;
1713 }
1714
Wataru Natsume9c926fe2016-03-03 19:56:09 +09001715 if (addsurf->on_layer == ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001716 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001717
Ucan, Emre (ADITG/SW1)10942372016-03-16 13:37:02 +00001718 wl_list_remove(&addsurf->pending.link);
1719 wl_list_insert(&ivilayer->pending.surface_list, &addsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001720
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001721 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001722
1723 return IVI_SUCCEEDED;
1724}
1725
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001726static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001727ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
1728 struct ivi_layout_surface *remsurf)
1729{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001730 if (ivilayer == NULL || remsurf == NULL) {
1731 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
1732 return;
1733 }
1734
Ucan, Emre (ADITG/SW1)536d8332016-03-16 13:36:59 +00001735 wl_list_remove(&remsurf->pending.link);
1736 wl_list_init(&remsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001737
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001738 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001739}
1740
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001741static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001742ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
1743 int32_t x, int32_t y,
1744 int32_t width, int32_t height)
1745{
1746 struct ivi_layout_surface_properties *prop = NULL;
1747
1748 if (ivisurf == NULL) {
1749 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
1750 return IVI_FAILED;
1751 }
1752
1753 prop = &ivisurf->pending.prop;
1754 prop->source_x = x;
1755 prop->source_y = y;
1756 prop->source_width = width;
1757 prop->source_height = height;
1758
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001759 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
1760 ivisurf->prop.source_width != width ||
1761 ivisurf->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001762 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001763 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001764 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001765
1766 return IVI_SUCCEEDED;
1767}
1768
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001769int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001770ivi_layout_commit_changes(void)
1771{
1772 struct ivi_layout *layout = get_instance();
1773
1774 commit_surface_list(layout);
1775 commit_layer_list(layout);
1776 commit_screen_list(layout);
1777
1778 commit_transition(layout);
1779
1780 commit_changes(layout);
1781 send_prop(layout);
1782 weston_compositor_schedule_repaint(layout->compositor);
1783
1784 return IVI_SUCCEEDED;
1785}
1786
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001787static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001788ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
1789 enum ivi_layout_transition_type type,
1790 uint32_t duration)
1791{
1792 if (ivilayer == NULL) {
1793 weston_log("%s: invalid argument\n", __func__);
1794 return -1;
1795 }
1796
1797 ivilayer->pending.prop.transition_type = type;
1798 ivilayer->pending.prop.transition_duration = duration;
1799
1800 return 0;
1801}
1802
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001803static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001804ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
1805 uint32_t is_fade_in,
1806 double start_alpha, double end_alpha)
1807{
1808 if (ivilayer == NULL) {
1809 weston_log("%s: invalid argument\n", __func__);
1810 return -1;
1811 }
1812
1813 ivilayer->pending.prop.is_fade_in = is_fade_in;
1814 ivilayer->pending.prop.start_alpha = start_alpha;
1815 ivilayer->pending.prop.end_alpha = end_alpha;
1816
1817 return 0;
1818}
1819
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001820static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001821ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
1822 uint32_t duration)
1823{
1824 struct ivi_layout_surface_properties *prop;
1825
1826 if (ivisurf == NULL) {
1827 weston_log("%s: invalid argument\n", __func__);
1828 return -1;
1829 }
1830
1831 prop = &ivisurf->pending.prop;
1832 prop->transition_duration = duration*10;
1833 return 0;
1834}
1835
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001836static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001837ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
1838 enum ivi_layout_transition_type type,
1839 uint32_t duration)
1840{
1841 struct ivi_layout_surface_properties *prop;
1842
1843 if (ivisurf == NULL) {
1844 weston_log("%s: invalid argument\n", __func__);
1845 return -1;
1846 }
1847
1848 prop = &ivisurf->pending.prop;
1849 prop->transition_type = type;
1850 prop->transition_duration = duration;
1851 return 0;
1852}
1853
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09001854static int32_t
1855ivi_layout_surface_dump(struct weston_surface *surface,
1856 void *target, size_t size,int32_t x, int32_t y,
1857 int32_t width, int32_t height)
1858{
1859 int result = 0;
1860
1861 if (surface == NULL) {
1862 weston_log("%s: invalid argument\n", __func__);
1863 return IVI_FAILED;
1864 }
1865
1866 result = weston_surface_copy_content(
1867 surface, target, size,
1868 x, y, width, height);
1869
1870 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
1871}
1872
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001873/**
1874 * methods of interaction between ivi-shell with ivi-layout
1875 */
1876struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001877ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
1878{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001879 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001880 return NULL;
1881
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00001882 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001883}
1884
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001885void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001886ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
1887 int32_t width, int32_t height)
1888{
1889 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001890
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09001891 /* emit callback which is set by ivi-layout api user */
1892 wl_signal_emit(&layout->surface_notification.configure_changed,
1893 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001894}
1895
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001896struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001897ivi_layout_surface_create(struct weston_surface *wl_surface,
1898 uint32_t id_surface)
1899{
1900 struct ivi_layout *layout = get_instance();
1901 struct ivi_layout_surface *ivisurf = NULL;
1902 struct weston_view *tmpview = NULL;
1903
1904 if (wl_surface == NULL) {
1905 weston_log("ivi_layout_surface_create: invalid argument\n");
1906 return NULL;
1907 }
1908
1909 ivisurf = get_surface(&layout->surface_list, id_surface);
1910 if (ivisurf != NULL) {
1911 if (ivisurf->surface != NULL) {
1912 weston_log("id_surface(%d) is already created\n", id_surface);
1913 return NULL;
1914 }
1915 }
1916
1917 ivisurf = calloc(1, sizeof *ivisurf);
1918 if (ivisurf == NULL) {
1919 weston_log("fails to allocate memory\n");
1920 return NULL;
1921 }
1922
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001923 wl_signal_init(&ivisurf->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001924 ivisurf->id_surface = id_surface;
1925 ivisurf->layout = layout;
1926
1927 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001928
1929 tmpview = weston_view_create(wl_surface);
1930 if (tmpview == NULL) {
1931 weston_log("fails to allocate memory\n");
1932 }
1933
1934 ivisurf->surface->width_from_buffer = 0;
1935 ivisurf->surface->height_from_buffer = 0;
1936
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09001937 weston_matrix_init(&ivisurf->transform.matrix);
1938 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001939
1940 init_surface_properties(&ivisurf->prop);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001941
1942 ivisurf->pending.prop = ivisurf->prop;
1943 wl_list_init(&ivisurf->pending.link);
1944
1945 wl_list_init(&ivisurf->order.link);
1946 wl_list_init(&ivisurf->order.layer_list);
1947
1948 wl_list_insert(&layout->surface_list, &ivisurf->link);
1949
1950 wl_signal_emit(&layout->surface_notification.created, ivisurf);
1951
1952 return ivisurf;
1953}
1954
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001955void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001956ivi_layout_init_with_compositor(struct weston_compositor *ec)
1957{
1958 struct ivi_layout *layout = get_instance();
1959
1960 layout->compositor = ec;
1961
1962 wl_list_init(&layout->surface_list);
1963 wl_list_init(&layout->layer_list);
1964 wl_list_init(&layout->screen_list);
1965
1966 wl_signal_init(&layout->layer_notification.created);
1967 wl_signal_init(&layout->layer_notification.removed);
1968
1969 wl_signal_init(&layout->surface_notification.created);
1970 wl_signal_init(&layout->surface_notification.removed);
1971 wl_signal_init(&layout->surface_notification.configure_changed);
1972
1973 /* Add layout_layer at the last of weston_compositor.layer_list */
1974 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
1975
1976 create_screen(ec);
1977
1978 layout->transitions = ivi_layout_transition_set_create(ec);
1979 wl_list_init(&layout->pending_transition_list);
1980}
1981
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001982static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001983 /**
1984 * commit all changes
1985 */
1986 .commit_changes = ivi_layout_commit_changes,
1987
1988 /**
1989 * surface controller interfaces
1990 */
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001991 .add_listener_create_surface = ivi_layout_add_listener_create_surface,
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +00001992 .add_listener_remove_surface = ivi_layout_add_listener_remove_surface,
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +00001993 .add_listener_configure_surface = ivi_layout_add_listener_configure_surface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001994 .get_surfaces = ivi_layout_get_surfaces,
1995 .get_id_of_surface = ivi_layout_get_id_of_surface,
1996 .get_surface_from_id = ivi_layout_get_surface_from_id,
1997 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
1998 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
1999 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002000 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002001 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2002 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002003 .surface_set_orientation = ivi_layout_surface_set_orientation,
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00002004 .surface_add_listener = ivi_layout_surface_add_listener,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002005 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2006 .surface_set_transition = ivi_layout_surface_set_transition,
2007 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2008
2009 /**
2010 * layer controller interfaces
2011 */
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +00002012 .add_listener_create_layer = ivi_layout_add_listener_create_layer,
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +00002013 .add_listener_remove_layer = ivi_layout_add_listener_remove_layer,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002014 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002015 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002016 .get_layers = ivi_layout_get_layers,
2017 .get_id_of_layer = ivi_layout_get_id_of_layer,
2018 .get_layer_from_id = ivi_layout_get_layer_from_id,
2019 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2020 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2021 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2022 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002023 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002024 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2025 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002026 .layer_set_orientation = ivi_layout_layer_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002027 .layer_add_surface = ivi_layout_layer_add_surface,
2028 .layer_remove_surface = ivi_layout_layer_remove_surface,
2029 .layer_set_render_order = ivi_layout_layer_set_render_order,
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00002030 .layer_add_listener = ivi_layout_layer_add_listener,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002031 .layer_set_transition = ivi_layout_layer_set_transition,
2032
2033 /**
Ucan, Emre (ADITG/SW1)6d89b1c2016-03-17 15:30:49 +00002034 * screen controller interfaces
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002035 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002036 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2037 .screen_add_layer = ivi_layout_screen_add_layer,
2038 .screen_set_render_order = ivi_layout_screen_set_render_order,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002039
2040 /**
2041 * animation
2042 */
2043 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002044 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2045
2046 /**
2047 * surface content dumping for debugging
2048 */
2049 .surface_get_size = ivi_layout_surface_get_size,
2050 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002051};
2052
2053int
2054load_controller_modules(struct weston_compositor *compositor, const char *modules,
2055 int *argc, char *argv[])
2056{
2057 const char *p, *end;
2058 char buffer[256];
2059 int (*controller_module_init)(struct weston_compositor *compositor,
2060 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002061 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002062 size_t interface_version);
2063
2064 if (modules == NULL)
2065 return 0;
2066
2067 p = modules;
2068 while (*p) {
2069 end = strchrnul(p, ',');
2070 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2071
2072 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002073 if (!controller_module_init)
2074 return -1;
2075
2076 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002077 &ivi_layout_interface,
2078 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002079 weston_log("ivi-shell: Initialization of controller module fails");
2080 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002081 }
2082
2083 p = end;
2084 while (*p == ',')
2085 p++;
2086 }
2087
2088 return 0;
2089}