blob: 7fa8b334e77def5cfaa7fe7791fd8d2dda4c4d66 [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
Bryce Harringtone6da35d2016-05-19 17:35:02 -070028 * not updated until ivi_layout_commit_changes is called. An overview from
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090029 * 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.
Bryce Harringtone6da35d2016-05-19 17:35:02 -070033 * 1/ When an API for updating properties of ivi_surface/ivi_layer, it updates
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090034 * pending prop of ivi_surface/ivi_layer/ivi_screen which are structure to
35 * store properties.
Bryce Harringtone6da35d2016-05-19 17:35:02 -070036 * 2/ Before calling commitChanges, in case of calling an API to get a property,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090037 * 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.
Bryce Harringtone6da35d2016-05-19 17:35:02 -070045 * For example, when a property of ivi_surface is changed from invisibile
46 * to visibile, it behaves like fade-in. When ivi_layout_commitChange is
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090047 * called during transition animation, it cancels the transition and
48 * re-start transition to new properties from current properties of final
Bryce Harringtone6da35d2016-05-19 17:35:02 -070049 * frame just before the cancellation.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090050 *
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/**
Bryce Harringtone6da35d2016-05-19 17:35:02 -0700111 * Internal API to add/remove an ivi_layer to/from ivi_screen.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900112 */
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 /*
Bryce Harringtone6da35d2016-05-19 17:35:02 -0700249 * FIXME: this shall be fixed by ivi-layout-transition.
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900250 */
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
Yong Bakose0698712016-04-28 11:59:08 -0500459 * coordinates to multi-screen coordinates, which are global coordinates.
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900460 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900461 *
Bryce Harringtone6da35d2016-05-19 17:35:02 -0700462 * Additionally, this computes the mask on surface-local coordinates as an
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900463 * ivi_rectangle. This can be set to weston_view_set_mask.
464 *
465 * The mask is computed by following steps
Yong Bakose0698712016-04-28 11:59:08 -0500466 * - destination rectangle of layer is transformed to multi-screen coordinates,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900467 * global coordinates. This is done by adding weston_output.{x,y} in simple
468 * because there is no scaled and rotated transformation.
Yong Bakose0698712016-04-28 11:59:08 -0500469 * - destination rectangle of layer in multi-screen coordinates needs to be
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900470 * 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
Yong Bakose0698712016-04-28 11:59:08 -0500474 * - in multi-screen coordinates,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900475 * - and intersected inside of an assigned screen,
Yong Bakose0698712016-04-28 11:59:08 -0500476 * is inversed to surface-local coordinates 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
Yong Bakose0698712016-04-28 11:59:08 -0500528 * - layer-local coordinates to single screen-local coordinates
529 * - single screen-local coordinates to multi-screen coordinates,
530 * which are 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);
Wataru Natsume7b3a52a2016-04-11 21:34:52 +0900917 surface_link->on_layer = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900918 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900919}
920
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900921/**
922 * Exported APIs of ivi-layout library are implemented from here.
923 * Brief of APIs is described in ivi-layout-export.h.
924 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900925static int32_t
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000926ivi_layout_add_listener_create_layer(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900927{
928 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900929
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000930 if (listener == NULL) {
931 weston_log("ivi_layout_add_listener_create_layer: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900932 return IVI_FAILED;
933 }
934
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000935 wl_signal_add(&layout->layer_notification.created, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900936
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000937 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900938}
939
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900940static int32_t
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000941ivi_layout_add_listener_remove_layer(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900942{
943 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900944
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000945 if (listener == NULL) {
946 weston_log("ivi_layout_add_listener_remove_layer: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900947 return IVI_FAILED;
948 }
949
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000950 wl_signal_add(&layout->layer_notification.removed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900951
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000952 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900953}
954
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900955static int32_t
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000956ivi_layout_add_listener_create_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900957{
958 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900959
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000960 if (listener == NULL) {
961 weston_log("ivi_layout_add_listener_create_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900962 return IVI_FAILED;
963 }
964
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000965 wl_signal_add(&layout->surface_notification.created, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900966
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000967 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900968}
969
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900970static int32_t
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000971ivi_layout_add_listener_remove_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900972{
973 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900974
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000975 if (listener == NULL) {
976 weston_log("ivi_layout_add_listener_remove_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900977 return IVI_FAILED;
978 }
979
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000980 wl_signal_add(&layout->surface_notification.removed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900981
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000982 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900983}
984
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900985static int32_t
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000986ivi_layout_add_listener_configure_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900987{
988 struct ivi_layout *layout = get_instance();
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000989
990 if (listener == NULL) {
991 weston_log("ivi_layout_add_listener_configure_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900992 return IVI_FAILED;
993 }
994
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000995 wl_signal_add(&layout->surface_notification.configure_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900996
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000997 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900998}
999
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001000uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001001ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1002{
1003 return ivisurf->id_surface;
1004}
1005
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001006static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001007ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1008{
1009 return ivilayer->id_layer;
1010}
1011
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001012static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001013ivi_layout_get_layer_from_id(uint32_t id_layer)
1014{
1015 struct ivi_layout *layout = get_instance();
1016 struct ivi_layout_layer *ivilayer = NULL;
1017
1018 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1019 if (ivilayer->id_layer == id_layer) {
1020 return ivilayer;
1021 }
1022 }
1023
1024 return NULL;
1025}
1026
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001027struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001028ivi_layout_get_surface_from_id(uint32_t id_surface)
1029{
1030 struct ivi_layout *layout = get_instance();
1031 struct ivi_layout_surface *ivisurf = NULL;
1032
1033 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1034 if (ivisurf->id_surface == id_surface) {
1035 return ivisurf;
1036 }
1037 }
1038
1039 return NULL;
1040}
1041
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001042static int32_t
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001043ivi_layout_surface_add_listener(struct ivi_layout_surface *ivisurf,
1044 struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001045{
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001046 if (ivisurf == NULL || listener == NULL) {
1047 weston_log("ivi_layout_surface_add_listener: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001048 return IVI_FAILED;
1049 }
1050
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001051 wl_signal_add(&ivisurf->property_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001052
1053 return IVI_SUCCEEDED;
1054}
1055
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001056static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001057ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1058{
1059 if (ivilayer == NULL) {
1060 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1061 return NULL;
1062 }
1063
1064 return &ivilayer->prop;
1065}
1066
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001067static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001068ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1069 int32_t *pLength,
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001070 struct weston_output ***ppArray)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001071{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001072 int32_t length = 0;
1073 int32_t n = 0;
1074
1075 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1076 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1077 return IVI_FAILED;
1078 }
1079
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001080 if (ivilayer->on_screen != NULL)
1081 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001082
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001083 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001084 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001085 *ppArray = calloc(length, sizeof(struct weston_output *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001086 if (*ppArray == NULL) {
1087 weston_log("fails to allocate memory\n");
1088 return IVI_FAILED;
1089 }
1090
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001091 (*ppArray)[n++] = ivilayer->on_screen->output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001092 }
1093
1094 *pLength = length;
1095
1096 return IVI_SUCCEEDED;
1097}
1098
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001099static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001100ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1101{
1102 struct ivi_layout *layout = get_instance();
1103 struct ivi_layout_layer *ivilayer = NULL;
1104 int32_t length = 0;
1105 int32_t n = 0;
1106
1107 if (pLength == NULL || ppArray == NULL) {
1108 weston_log("ivi_layout_get_layers: invalid argument\n");
1109 return IVI_FAILED;
1110 }
1111
1112 length = wl_list_length(&layout->layer_list);
1113
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001114 if (length != 0) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001115 /* the Array must be freed by module which called this function */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001116 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1117 if (*ppArray == NULL) {
1118 weston_log("fails to allocate memory\n");
1119 return IVI_FAILED;
1120 }
1121
1122 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1123 (*ppArray)[n++] = ivilayer;
1124 }
1125 }
1126
1127 *pLength = length;
1128
1129 return IVI_SUCCEEDED;
1130}
1131
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001132static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001133ivi_layout_get_layers_on_screen(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001134 int32_t *pLength,
1135 struct ivi_layout_layer ***ppArray)
1136{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001137 struct ivi_layout_screen *iviscrn = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001138 struct ivi_layout_layer *ivilayer = NULL;
1139 int32_t length = 0;
1140 int32_t n = 0;
1141
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001142 if (output == NULL || pLength == NULL || ppArray == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001143 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1144 return IVI_FAILED;
1145 }
1146
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001147 iviscrn = get_screen_from_output(output);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001148 length = wl_list_length(&iviscrn->order.layer_list);
1149
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001150 if (length != 0) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001151 /* the Array must be freed by module which called this function */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001152 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1153 if (*ppArray == NULL) {
1154 weston_log("fails to allocate memory\n");
1155 return IVI_FAILED;
1156 }
1157
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001158 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001159 (*ppArray)[n++] = ivilayer;
1160 }
1161 }
1162
1163 *pLength = length;
1164
1165 return IVI_SUCCEEDED;
1166}
1167
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001168static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001169ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1170 int32_t *pLength,
1171 struct ivi_layout_layer ***ppArray)
1172{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001173 int32_t length = 0;
1174 int32_t n = 0;
1175
1176 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1177 weston_log("ivi_layout_getLayers: invalid argument\n");
1178 return IVI_FAILED;
1179 }
1180
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001181 if (ivisurf->on_layer != NULL) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001182 /* the Array must be freed by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001183 length = 1;
1184 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001185 if (*ppArray == NULL) {
1186 weston_log("fails to allocate memory\n");
1187 return IVI_FAILED;
1188 }
1189
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001190 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001191 }
1192
1193 *pLength = length;
1194
1195 return IVI_SUCCEEDED;
1196}
1197
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001198static
1199int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001200ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1201{
1202 struct ivi_layout *layout = get_instance();
1203 struct ivi_layout_surface *ivisurf = NULL;
1204 int32_t length = 0;
1205 int32_t n = 0;
1206
1207 if (pLength == NULL || ppArray == NULL) {
1208 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1209 return IVI_FAILED;
1210 }
1211
1212 length = wl_list_length(&layout->surface_list);
1213
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001214 if (length != 0) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001215 /* the Array must be freed by module which called this function */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001216 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1217 if (*ppArray == NULL) {
1218 weston_log("fails to allocate memory\n");
1219 return IVI_FAILED;
1220 }
1221
1222 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1223 (*ppArray)[n++] = ivisurf;
1224 }
1225 }
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_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1234 int32_t *pLength,
1235 struct ivi_layout_surface ***ppArray)
1236{
1237 struct ivi_layout_surface *ivisurf = NULL;
1238 int32_t length = 0;
1239 int32_t n = 0;
1240
1241 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1242 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1243 return IVI_FAILED;
1244 }
1245
1246 length = wl_list_length(&ivilayer->order.surface_list);
1247
1248 if (length != 0) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001249 /* the Array must be freed by module which called this function */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001250 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1251 if (*ppArray == NULL) {
1252 weston_log("fails to allocate memory\n");
1253 return IVI_FAILED;
1254 }
1255
1256 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1257 (*ppArray)[n++] = ivisurf;
1258 }
1259 }
1260
1261 *pLength = length;
1262
1263 return IVI_SUCCEEDED;
1264}
1265
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001266static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001267ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1268 int32_t width, int32_t height)
1269{
1270 struct ivi_layout *layout = get_instance();
1271 struct ivi_layout_layer *ivilayer = NULL;
1272
1273 ivilayer = get_layer(&layout->layer_list, id_layer);
1274 if (ivilayer != NULL) {
1275 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001276 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001277 return ivilayer;
1278 }
1279
1280 ivilayer = calloc(1, sizeof *ivilayer);
1281 if (ivilayer == NULL) {
1282 weston_log("fails to allocate memory\n");
1283 return NULL;
1284 }
1285
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001286 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001287 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001288 ivilayer->layout = layout;
1289 ivilayer->id_layer = id_layer;
1290
1291 init_layer_properties(&ivilayer->prop, width, height);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001292
1293 wl_list_init(&ivilayer->pending.surface_list);
1294 wl_list_init(&ivilayer->pending.link);
1295 ivilayer->pending.prop = ivilayer->prop;
1296
1297 wl_list_init(&ivilayer->order.surface_list);
1298 wl_list_init(&ivilayer->order.link);
1299
1300 wl_list_insert(&layout->layer_list, &ivilayer->link);
1301
1302 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1303
1304 return ivilayer;
1305}
1306
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001307static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001308ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001309{
1310 struct ivi_layout *layout = get_instance();
1311
1312 if (ivilayer == NULL) {
1313 weston_log("ivi_layout_layer_remove: invalid argument\n");
1314 return;
1315 }
1316
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001317 if (--ivilayer->ref_count > 0)
1318 return;
1319
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001320 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1321
1322 clear_surface_pending_list(ivilayer);
1323 clear_surface_order_list(ivilayer);
1324
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001325 wl_list_remove(&ivilayer->pending.link);
1326 wl_list_remove(&ivilayer->order.link);
1327 wl_list_remove(&ivilayer->link);
1328
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001329 free(ivilayer);
1330}
1331
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001332int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001333ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1334 bool newVisibility)
1335{
1336 struct ivi_layout_layer_properties *prop = NULL;
1337
1338 if (ivilayer == NULL) {
1339 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1340 return IVI_FAILED;
1341 }
1342
1343 prop = &ivilayer->pending.prop;
1344 prop->visibility = newVisibility;
1345
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001346 if (ivilayer->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001347 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001348 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001349 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001350
1351 return IVI_SUCCEEDED;
1352}
1353
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001354int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001355ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1356 wl_fixed_t opacity)
1357{
1358 struct ivi_layout_layer_properties *prop = NULL;
1359
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001360 if (ivilayer == NULL ||
1361 opacity < wl_fixed_from_double(0.0) ||
1362 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001363 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1364 return IVI_FAILED;
1365 }
1366
1367 prop = &ivilayer->pending.prop;
1368 prop->opacity = opacity;
1369
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001370 if (ivilayer->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001371 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001372 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001373 prop->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001374
1375 return IVI_SUCCEEDED;
1376}
1377
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001378static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001379ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1380 int32_t x, int32_t y,
1381 int32_t width, int32_t height)
1382{
1383 struct ivi_layout_layer_properties *prop = NULL;
1384
1385 if (ivilayer == NULL) {
1386 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1387 return IVI_FAILED;
1388 }
1389
1390 prop = &ivilayer->pending.prop;
1391 prop->source_x = x;
1392 prop->source_y = y;
1393 prop->source_width = width;
1394 prop->source_height = height;
1395
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001396 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1397 ivilayer->prop.source_width != width ||
1398 ivilayer->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001399 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001400 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001401 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001402
1403 return IVI_SUCCEEDED;
1404}
1405
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001406int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001407ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1408 int32_t x, int32_t y,
1409 int32_t width, int32_t height)
1410{
1411 struct ivi_layout_layer_properties *prop = NULL;
1412
1413 if (ivilayer == NULL) {
1414 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1415 return IVI_FAILED;
1416 }
1417
1418 prop = &ivilayer->pending.prop;
1419 prop->dest_x = x;
1420 prop->dest_y = y;
1421 prop->dest_width = width;
1422 prop->dest_height = height;
1423
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001424 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1425 ivilayer->prop.dest_width != width ||
1426 ivilayer->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001427 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001428 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001429 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001430
1431 return IVI_SUCCEEDED;
1432}
1433
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001434static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001435ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1436 enum wl_output_transform orientation)
1437{
1438 struct ivi_layout_layer_properties *prop = NULL;
1439
1440 if (ivilayer == NULL) {
1441 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1442 return IVI_FAILED;
1443 }
1444
1445 prop = &ivilayer->pending.prop;
1446 prop->orientation = orientation;
1447
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001448 if (ivilayer->prop.orientation != orientation)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001449 prop->event_mask |= IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001450 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001451 prop->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001452
1453 return IVI_SUCCEEDED;
1454}
1455
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001456int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001457ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1458 struct ivi_layout_surface **pSurface,
1459 int32_t number)
1460{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001461 int32_t i = 0;
1462
1463 if (ivilayer == NULL) {
1464 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1465 return IVI_FAILED;
1466 }
1467
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001468 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001469
1470 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)72ad1642016-03-16 13:37:05 +00001471 wl_list_remove(&pSurface[i]->pending.link);
1472 wl_list_insert(&ivilayer->pending.surface_list,
1473 &pSurface[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001474 }
1475
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001476 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001477
1478 return IVI_SUCCEEDED;
1479}
1480
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001481int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001482ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1483 bool newVisibility)
1484{
1485 struct ivi_layout_surface_properties *prop = NULL;
1486
1487 if (ivisurf == NULL) {
1488 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1489 return IVI_FAILED;
1490 }
1491
1492 prop = &ivisurf->pending.prop;
1493 prop->visibility = newVisibility;
1494
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001495 if (ivisurf->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001496 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001497 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001498 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001499
1500 return IVI_SUCCEEDED;
1501}
1502
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001503int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001504ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1505 wl_fixed_t opacity)
1506{
1507 struct ivi_layout_surface_properties *prop = NULL;
1508
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001509 if (ivisurf == NULL ||
1510 opacity < wl_fixed_from_double(0.0) ||
1511 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001512 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1513 return IVI_FAILED;
1514 }
1515
1516 prop = &ivisurf->pending.prop;
1517 prop->opacity = opacity;
1518
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001519 if (ivisurf->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001520 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001521 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001522 prop->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001523
1524 return IVI_SUCCEEDED;
1525}
1526
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001527int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001528ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1529 int32_t x, int32_t y,
1530 int32_t width, int32_t height)
1531{
1532 struct ivi_layout_surface_properties *prop = NULL;
1533
1534 if (ivisurf == NULL) {
1535 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1536 return IVI_FAILED;
1537 }
1538
1539 prop = &ivisurf->pending.prop;
1540 prop->start_x = prop->dest_x;
1541 prop->start_y = prop->dest_y;
1542 prop->dest_x = x;
1543 prop->dest_y = y;
1544 prop->start_width = prop->dest_width;
1545 prop->start_height = prop->dest_height;
1546 prop->dest_width = width;
1547 prop->dest_height = height;
1548
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001549 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
1550 ivisurf->prop.dest_width != width ||
1551 ivisurf->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001552 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001553 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001554 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001555
1556 return IVI_SUCCEEDED;
1557}
1558
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001559static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001560ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
1561 enum wl_output_transform orientation)
1562{
1563 struct ivi_layout_surface_properties *prop = NULL;
1564
1565 if (ivisurf == NULL) {
1566 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
1567 return IVI_FAILED;
1568 }
1569
1570 prop = &ivisurf->pending.prop;
1571 prop->orientation = orientation;
1572
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001573 if (ivisurf->prop.orientation != orientation)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001574 prop->event_mask |= IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001575 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001576 prop->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001577
1578 return IVI_SUCCEEDED;
1579}
1580
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001581static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001582ivi_layout_screen_add_layer(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001583 struct ivi_layout_layer *addlayer)
1584{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001585 struct ivi_layout_screen *iviscrn;
1586
1587 if (output == NULL || addlayer == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001588 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
1589 return IVI_FAILED;
1590 }
1591
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001592 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001593
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00001594 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001595 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
1596 return IVI_SUCCEEDED;
1597 }
1598
Ucan, Emre (ADITG/SW1)f46306f2016-03-16 13:37:07 +00001599 wl_list_remove(&addlayer->pending.link);
1600 wl_list_insert(&iviscrn->pending.layer_list, &addlayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001601
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001602 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001603
1604 return IVI_SUCCEEDED;
1605}
1606
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001607static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001608ivi_layout_screen_set_render_order(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001609 struct ivi_layout_layer **pLayer,
1610 const int32_t number)
1611{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001612 struct ivi_layout_screen *iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001613 struct ivi_layout_layer *ivilayer = NULL;
1614 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001615 int32_t i = 0;
1616
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001617 if (output == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001618 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
1619 return IVI_FAILED;
1620 }
1621
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001622 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001623
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001624 wl_list_for_each_safe(ivilayer, next,
1625 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001626 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001627 wl_list_init(&ivilayer->pending.link);
1628 }
1629
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001630 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001631
1632 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)4e221f02016-03-16 13:37:08 +00001633 wl_list_remove(&pLayer[i]->pending.link);
1634 wl_list_insert(&iviscrn->pending.layer_list,
1635 &pLayer[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001636 }
1637
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001638 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001639
1640 return IVI_SUCCEEDED;
1641}
1642
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001643/**
1644 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
1645 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
1646 * This function is used to get the result of drawing by clients.
1647 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001648static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001649ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
1650{
1651 return ivisurf != NULL ? ivisurf->surface : NULL;
1652}
1653
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001654static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09001655ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
1656 int32_t *width, int32_t *height,
1657 int32_t *stride)
1658{
1659 int32_t w;
1660 int32_t h;
1661 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
1662
1663 if (ivisurf == NULL || ivisurf->surface == NULL) {
1664 weston_log("%s: invalid argument\n", __func__);
1665 return IVI_FAILED;
1666 }
1667
1668 weston_surface_get_content_size(ivisurf->surface, &w, &h);
1669
1670 if (width != NULL)
1671 *width = w;
1672
1673 if (height != NULL)
1674 *height = h;
1675
1676 if (stride != NULL)
1677 *stride = w * bytespp;
1678
1679 return IVI_SUCCEEDED;
1680}
1681
1682static int32_t
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001683ivi_layout_layer_add_listener(struct ivi_layout_layer *ivilayer,
1684 struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001685{
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001686 if (ivilayer == NULL || listener == NULL) {
1687 weston_log("ivi_layout_layer_add_listener: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001688 return IVI_FAILED;
1689 }
1690
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001691 wl_signal_add(&ivilayer->property_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001692
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001693 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001694}
1695
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001696static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001697ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
1698{
1699 if (ivisurf == NULL) {
1700 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
1701 return NULL;
1702 }
1703
1704 return &ivisurf->prop;
1705}
1706
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001707static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001708ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
1709 struct ivi_layout_surface *addsurf)
1710{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001711 if (ivilayer == NULL || addsurf == NULL) {
1712 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
1713 return IVI_FAILED;
1714 }
1715
Wataru Natsume9c926fe2016-03-03 19:56:09 +09001716 if (addsurf->on_layer == ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001717 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001718
Ucan, Emre (ADITG/SW1)10942372016-03-16 13:37:02 +00001719 wl_list_remove(&addsurf->pending.link);
1720 wl_list_insert(&ivilayer->pending.surface_list, &addsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001721
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001722 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001723
1724 return IVI_SUCCEEDED;
1725}
1726
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001727static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001728ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
1729 struct ivi_layout_surface *remsurf)
1730{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001731 if (ivilayer == NULL || remsurf == NULL) {
1732 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
1733 return;
1734 }
1735
Ucan, Emre (ADITG/SW1)536d8332016-03-16 13:36:59 +00001736 wl_list_remove(&remsurf->pending.link);
1737 wl_list_init(&remsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001738
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001739 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001740}
1741
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001742static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001743ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
1744 int32_t x, int32_t y,
1745 int32_t width, int32_t height)
1746{
1747 struct ivi_layout_surface_properties *prop = NULL;
1748
1749 if (ivisurf == NULL) {
1750 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
1751 return IVI_FAILED;
1752 }
1753
1754 prop = &ivisurf->pending.prop;
1755 prop->source_x = x;
1756 prop->source_y = y;
1757 prop->source_width = width;
1758 prop->source_height = height;
1759
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001760 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
1761 ivisurf->prop.source_width != width ||
1762 ivisurf->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001763 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001764 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001765 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001766
1767 return IVI_SUCCEEDED;
1768}
1769
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001770int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001771ivi_layout_commit_changes(void)
1772{
1773 struct ivi_layout *layout = get_instance();
1774
1775 commit_surface_list(layout);
1776 commit_layer_list(layout);
1777 commit_screen_list(layout);
1778
1779 commit_transition(layout);
1780
1781 commit_changes(layout);
1782 send_prop(layout);
1783 weston_compositor_schedule_repaint(layout->compositor);
1784
1785 return IVI_SUCCEEDED;
1786}
1787
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001788static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001789ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
1790 enum ivi_layout_transition_type type,
1791 uint32_t duration)
1792{
1793 if (ivilayer == NULL) {
1794 weston_log("%s: invalid argument\n", __func__);
1795 return -1;
1796 }
1797
1798 ivilayer->pending.prop.transition_type = type;
1799 ivilayer->pending.prop.transition_duration = duration;
1800
1801 return 0;
1802}
1803
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001804static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001805ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
1806 uint32_t is_fade_in,
1807 double start_alpha, double end_alpha)
1808{
1809 if (ivilayer == NULL) {
1810 weston_log("%s: invalid argument\n", __func__);
1811 return -1;
1812 }
1813
1814 ivilayer->pending.prop.is_fade_in = is_fade_in;
1815 ivilayer->pending.prop.start_alpha = start_alpha;
1816 ivilayer->pending.prop.end_alpha = end_alpha;
1817
1818 return 0;
1819}
1820
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001821static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001822ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
1823 uint32_t duration)
1824{
1825 struct ivi_layout_surface_properties *prop;
1826
1827 if (ivisurf == NULL) {
1828 weston_log("%s: invalid argument\n", __func__);
1829 return -1;
1830 }
1831
1832 prop = &ivisurf->pending.prop;
1833 prop->transition_duration = duration*10;
1834 return 0;
1835}
1836
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001837static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001838ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
1839 enum ivi_layout_transition_type type,
1840 uint32_t duration)
1841{
1842 struct ivi_layout_surface_properties *prop;
1843
1844 if (ivisurf == NULL) {
1845 weston_log("%s: invalid argument\n", __func__);
1846 return -1;
1847 }
1848
1849 prop = &ivisurf->pending.prop;
1850 prop->transition_type = type;
1851 prop->transition_duration = duration;
1852 return 0;
1853}
1854
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09001855static int32_t
1856ivi_layout_surface_dump(struct weston_surface *surface,
1857 void *target, size_t size,int32_t x, int32_t y,
1858 int32_t width, int32_t height)
1859{
1860 int result = 0;
1861
1862 if (surface == NULL) {
1863 weston_log("%s: invalid argument\n", __func__);
1864 return IVI_FAILED;
1865 }
1866
1867 result = weston_surface_copy_content(
1868 surface, target, size,
1869 x, y, width, height);
1870
1871 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
1872}
1873
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001874/**
1875 * methods of interaction between ivi-shell with ivi-layout
1876 */
1877struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001878ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
1879{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001880 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001881 return NULL;
1882
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00001883 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001884}
1885
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001886void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001887ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
1888 int32_t width, int32_t height)
1889{
1890 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001891
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09001892 /* emit callback which is set by ivi-layout api user */
1893 wl_signal_emit(&layout->surface_notification.configure_changed,
1894 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001895}
1896
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001897struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001898ivi_layout_surface_create(struct weston_surface *wl_surface,
1899 uint32_t id_surface)
1900{
1901 struct ivi_layout *layout = get_instance();
1902 struct ivi_layout_surface *ivisurf = NULL;
1903 struct weston_view *tmpview = NULL;
1904
1905 if (wl_surface == NULL) {
1906 weston_log("ivi_layout_surface_create: invalid argument\n");
1907 return NULL;
1908 }
1909
1910 ivisurf = get_surface(&layout->surface_list, id_surface);
1911 if (ivisurf != NULL) {
1912 if (ivisurf->surface != NULL) {
1913 weston_log("id_surface(%d) is already created\n", id_surface);
1914 return NULL;
1915 }
1916 }
1917
1918 ivisurf = calloc(1, sizeof *ivisurf);
1919 if (ivisurf == NULL) {
1920 weston_log("fails to allocate memory\n");
1921 return NULL;
1922 }
1923
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001924 wl_signal_init(&ivisurf->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001925 ivisurf->id_surface = id_surface;
1926 ivisurf->layout = layout;
1927
1928 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001929
1930 tmpview = weston_view_create(wl_surface);
1931 if (tmpview == NULL) {
1932 weston_log("fails to allocate memory\n");
1933 }
1934
1935 ivisurf->surface->width_from_buffer = 0;
1936 ivisurf->surface->height_from_buffer = 0;
1937
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09001938 weston_matrix_init(&ivisurf->transform.matrix);
1939 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001940
1941 init_surface_properties(&ivisurf->prop);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001942
1943 ivisurf->pending.prop = ivisurf->prop;
1944 wl_list_init(&ivisurf->pending.link);
1945
1946 wl_list_init(&ivisurf->order.link);
1947 wl_list_init(&ivisurf->order.layer_list);
1948
1949 wl_list_insert(&layout->surface_list, &ivisurf->link);
1950
1951 wl_signal_emit(&layout->surface_notification.created, ivisurf);
1952
1953 return ivisurf;
1954}
1955
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001956void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001957ivi_layout_init_with_compositor(struct weston_compositor *ec)
1958{
1959 struct ivi_layout *layout = get_instance();
1960
1961 layout->compositor = ec;
1962
1963 wl_list_init(&layout->surface_list);
1964 wl_list_init(&layout->layer_list);
1965 wl_list_init(&layout->screen_list);
1966
1967 wl_signal_init(&layout->layer_notification.created);
1968 wl_signal_init(&layout->layer_notification.removed);
1969
1970 wl_signal_init(&layout->surface_notification.created);
1971 wl_signal_init(&layout->surface_notification.removed);
1972 wl_signal_init(&layout->surface_notification.configure_changed);
1973
1974 /* Add layout_layer at the last of weston_compositor.layer_list */
1975 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
1976
1977 create_screen(ec);
1978
1979 layout->transitions = ivi_layout_transition_set_create(ec);
1980 wl_list_init(&layout->pending_transition_list);
1981}
1982
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001983static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001984 /**
1985 * commit all changes
1986 */
1987 .commit_changes = ivi_layout_commit_changes,
1988
1989 /**
1990 * surface controller interfaces
1991 */
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001992 .add_listener_create_surface = ivi_layout_add_listener_create_surface,
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +00001993 .add_listener_remove_surface = ivi_layout_add_listener_remove_surface,
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +00001994 .add_listener_configure_surface = ivi_layout_add_listener_configure_surface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001995 .get_surfaces = ivi_layout_get_surfaces,
1996 .get_id_of_surface = ivi_layout_get_id_of_surface,
1997 .get_surface_from_id = ivi_layout_get_surface_from_id,
1998 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
1999 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2000 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002001 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002002 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2003 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002004 .surface_set_orientation = ivi_layout_surface_set_orientation,
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00002005 .surface_add_listener = ivi_layout_surface_add_listener,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002006 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2007 .surface_set_transition = ivi_layout_surface_set_transition,
2008 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2009
2010 /**
2011 * layer controller interfaces
2012 */
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +00002013 .add_listener_create_layer = ivi_layout_add_listener_create_layer,
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +00002014 .add_listener_remove_layer = ivi_layout_add_listener_remove_layer,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002015 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002016 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002017 .get_layers = ivi_layout_get_layers,
2018 .get_id_of_layer = ivi_layout_get_id_of_layer,
2019 .get_layer_from_id = ivi_layout_get_layer_from_id,
2020 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2021 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2022 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2023 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002024 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002025 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2026 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002027 .layer_set_orientation = ivi_layout_layer_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002028 .layer_add_surface = ivi_layout_layer_add_surface,
2029 .layer_remove_surface = ivi_layout_layer_remove_surface,
2030 .layer_set_render_order = ivi_layout_layer_set_render_order,
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00002031 .layer_add_listener = ivi_layout_layer_add_listener,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002032 .layer_set_transition = ivi_layout_layer_set_transition,
2033
2034 /**
Ucan, Emre (ADITG/SW1)6d89b1c2016-03-17 15:30:49 +00002035 * screen controller interfaces
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002036 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002037 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2038 .screen_add_layer = ivi_layout_screen_add_layer,
2039 .screen_set_render_order = ivi_layout_screen_set_render_order,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002040
2041 /**
2042 * animation
2043 */
2044 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002045 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2046
2047 /**
2048 * surface content dumping for debugging
2049 */
2050 .surface_get_size = ivi_layout_surface_get_size,
2051 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002052};
2053
2054int
2055load_controller_modules(struct weston_compositor *compositor, const char *modules,
2056 int *argc, char *argv[])
2057{
2058 const char *p, *end;
2059 char buffer[256];
2060 int (*controller_module_init)(struct weston_compositor *compositor,
2061 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002062 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002063 size_t interface_version);
2064
2065 if (modules == NULL)
2066 return 0;
2067
2068 p = modules;
2069 while (*p) {
2070 end = strchrnul(p, ',');
2071 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2072
2073 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002074 if (!controller_module_init)
2075 return -1;
2076
2077 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002078 &ivi_layout_interface,
2079 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002080 weston_log("ivi-shell: Initialization of controller module fails");
2081 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002082 }
2083
2084 p = end;
2085 while (*p == ',')
2086 p++;
2087 }
2088
2089 return 0;
2090}