blob: 81e5621b263e2dc32fa31075bcf730c02a2827a1 [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
Giulio Camuffo179fcda2016-06-02 21:48:14 +030063#include "weston.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090064#include "compositor.h"
Pekka Paalanen1f821932016-03-15 16:57:51 +020065#include "ivi-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090066#include "ivi-layout-export.h"
67#include "ivi-layout-private.h"
Pekka Paalanen32ca7912016-03-15 17:21:00 +020068#include "ivi-layout-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090069
Jon Cruz867d50e2015-06-15 15:37:10 -070070#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070071#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090072
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +090073#define max(a, b) ((a) > (b) ? (a) : (b))
74
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090075struct ivi_layout;
76
77struct ivi_layout_screen {
78 struct wl_list link;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090079
80 struct ivi_layout *layout;
81 struct weston_output *output;
82
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090083 struct {
84 struct wl_list layer_list;
85 struct wl_list link;
86 } pending;
87
88 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +000089 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090090 struct wl_list layer_list;
91 struct wl_list link;
92 } order;
93};
94
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +090095struct ivi_rectangle
96{
97 int32_t x;
98 int32_t y;
99 int32_t width;
100 int32_t height;
101};
102
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900103static struct ivi_layout ivilayout = {0};
104
105struct ivi_layout *
106get_instance(void)
107{
108 return &ivilayout;
109}
110
111/**
Bryce Harringtone6da35d2016-05-19 17:35:02 -0700112 * Internal API to add/remove an ivi_layer to/from ivi_screen.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900113 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900114static struct ivi_layout_surface *
115get_surface(struct wl_list *surf_list, uint32_t id_surface)
116{
117 struct ivi_layout_surface *ivisurf;
118
119 wl_list_for_each(ivisurf, surf_list, link) {
120 if (ivisurf->id_surface == id_surface) {
121 return ivisurf;
122 }
123 }
124
125 return NULL;
126}
127
128static struct ivi_layout_layer *
129get_layer(struct wl_list *layer_list, uint32_t id_layer)
130{
131 struct ivi_layout_layer *ivilayer;
132
133 wl_list_for_each(ivilayer, layer_list, link) {
134 if (ivilayer->id_layer == id_layer) {
135 return ivilayer;
136 }
137 }
138
139 return NULL;
140}
141
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000142static struct weston_view *
143get_weston_view(struct ivi_layout_surface *ivisurf)
144{
145 struct weston_view *view = NULL;
146
147 assert(ivisurf->surface != NULL);
148
149 /* One view per surface */
150 if(wl_list_empty(&ivisurf->surface->views))
151 view = NULL;
152 else
153 view = wl_container_of(ivisurf->surface->views.next, view, surface_link);
154
155 return view;
156}
157
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +0000158static struct ivi_layout_screen *
159get_screen_from_output(struct weston_output *output)
160{
161 struct ivi_layout *layout = get_instance();
162 struct ivi_layout_screen *iviscrn = NULL;
163
164 wl_list_for_each(iviscrn, &layout->screen_list, link) {
165 if (iviscrn->output == output)
166 return iviscrn;
167 }
168
169 return NULL;
170}
171
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900172/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900173 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900174 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900175void
176ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900177{
178 struct ivi_layout *layout = get_instance();
179
180 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900181 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900182 return;
183 }
184
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900185 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900186 wl_list_remove(&ivisurf->pending.link);
187 wl_list_remove(&ivisurf->order.link);
188 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900189
190 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
191
Mateusz Polroladada6e32016-03-09 09:13:26 +0000192 ivi_layout_remove_all_surface_transitions(ivisurf);
193
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900194 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900195}
196
197/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900198 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
199 * Called by ivi_layout_init_with_compositor.
200 */
201static void
202create_screen(struct weston_compositor *ec)
203{
204 struct ivi_layout *layout = get_instance();
205 struct ivi_layout_screen *iviscrn = NULL;
206 struct weston_output *output = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900207
208 wl_list_for_each(output, &ec->output_list, link) {
209 iviscrn = calloc(1, sizeof *iviscrn);
210 if (iviscrn == NULL) {
211 weston_log("fails to allocate memory\n");
212 continue;
213 }
214
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900215 iviscrn->layout = layout;
216
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900217 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900218
219 wl_list_init(&iviscrn->pending.layer_list);
220 wl_list_init(&iviscrn->pending.link);
221
222 wl_list_init(&iviscrn->order.layer_list);
223 wl_list_init(&iviscrn->order.link);
224
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900225 wl_list_insert(&layout->screen_list, &iviscrn->link);
226 }
227}
228
229/**
230 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
231 */
232static void
233init_layer_properties(struct ivi_layout_layer_properties *prop,
234 int32_t width, int32_t height)
235{
236 memset(prop, 0, sizeof *prop);
237 prop->opacity = wl_fixed_from_double(1.0);
238 prop->source_width = width;
239 prop->source_height = height;
240 prop->dest_width = width;
241 prop->dest_height = height;
242}
243
244static void
245init_surface_properties(struct ivi_layout_surface_properties *prop)
246{
247 memset(prop, 0, sizeof *prop);
248 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900249 /*
Bryce Harringtone6da35d2016-05-19 17:35:02 -0700250 * FIXME: this shall be fixed by ivi-layout-transition.
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900251 */
252 prop->dest_width = 1;
253 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900254}
255
256/**
257 * Internal APIs to be called from ivi_layout_commit_changes.
258 */
259static void
260update_opacity(struct ivi_layout_layer *ivilayer,
261 struct ivi_layout_surface *ivisurf)
262{
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000263 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900264 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
265 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
266
Nobuhiko Tanibata90c27892015-12-26 23:52:51 +0900267 tmpview = get_weston_view(ivisurf);
268 assert(tmpview != NULL);
269 tmpview->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900270}
271
272static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900273get_rotate_values(enum wl_output_transform orientation,
274 float *v_sin,
275 float *v_cos)
276{
277 switch (orientation) {
278 case WL_OUTPUT_TRANSFORM_90:
279 *v_sin = 1.0f;
280 *v_cos = 0.0f;
281 break;
282 case WL_OUTPUT_TRANSFORM_180:
283 *v_sin = 0.0f;
284 *v_cos = -1.0f;
285 break;
286 case WL_OUTPUT_TRANSFORM_270:
287 *v_sin = -1.0f;
288 *v_cos = 0.0f;
289 break;
290 case WL_OUTPUT_TRANSFORM_NORMAL:
291 default:
292 *v_sin = 0.0f;
293 *v_cos = 1.0f;
294 break;
295 }
296}
297
298static void
299get_scale(enum wl_output_transform orientation,
300 float dest_width,
301 float dest_height,
302 float source_width,
303 float source_height,
304 float *scale_x,
305 float *scale_y)
306{
307 switch (orientation) {
308 case WL_OUTPUT_TRANSFORM_90:
309 *scale_x = dest_width / source_height;
310 *scale_y = dest_height / source_width;
311 break;
312 case WL_OUTPUT_TRANSFORM_180:
313 *scale_x = dest_width / source_width;
314 *scale_y = dest_height / source_height;
315 break;
316 case WL_OUTPUT_TRANSFORM_270:
317 *scale_x = dest_width / source_height;
318 *scale_y = dest_height / source_width;
319 break;
320 case WL_OUTPUT_TRANSFORM_NORMAL:
321 default:
322 *scale_x = dest_width / source_width;
323 *scale_y = dest_height / source_height;
324 break;
325 }
326}
327
328static void
329calc_transformation_matrix(struct ivi_rectangle *source_rect,
330 struct ivi_rectangle *dest_rect,
331 enum wl_output_transform orientation,
332 struct weston_matrix *m)
333{
334 float source_center_x;
335 float source_center_y;
336 float vsin;
337 float vcos;
338 float scale_x;
339 float scale_y;
340 float translate_x;
341 float translate_y;
342
343 source_center_x = source_rect->x + source_rect->width * 0.5f;
344 source_center_y = source_rect->y + source_rect->height * 0.5f;
345 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
346
347 get_rotate_values(orientation, &vsin, &vcos);
348 weston_matrix_rotate_xy(m, vcos, vsin);
349
350 get_scale(orientation,
351 dest_rect->width,
352 dest_rect->height,
353 source_rect->width,
354 source_rect->height,
355 &scale_x,
356 &scale_y);
357 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
358
359 translate_x = dest_rect->width * 0.5f + dest_rect->x;
360 translate_y = dest_rect->height * 0.5f + dest_rect->y;
361 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
362}
363
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900364/*
365 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900366 */
367static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900368ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
369 const struct ivi_rectangle *rect2,
370 struct ivi_rectangle *rect_output)
371{
372 int32_t rect1_right = rect1->x + rect1->width;
373 int32_t rect1_bottom = rect1->y + rect1->height;
374 int32_t rect2_right = rect2->x + rect2->width;
375 int32_t rect2_bottom = rect2->y + rect2->height;
376
377 rect_output->x = max(rect1->x, rect2->x);
378 rect_output->y = max(rect1->y, rect2->y);
379 rect_output->width = rect1_right < rect2_right ?
380 rect1_right - rect_output->x :
381 rect2_right - rect_output->x;
382 rect_output->height = rect1_bottom < rect2_bottom ?
383 rect1_bottom - rect_output->y :
384 rect2_bottom - rect_output->y;
385
386 if (rect_output->width < 0 || rect_output->height < 0) {
387 rect_output->width = 0;
388 rect_output->height = 0;
389 }
390}
391
392/*
393 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
394 * and store the result in rect_output.
395 * The boundingbox must be given in the same coordinate space as rect_output.
396 * Additionally, there are the following restrictions on the matrix:
397 * - no projective transformations
398 * - no skew
399 * - only multiples of 90-degree rotations supported
400 *
401 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
402 * as a fail-safe with log.
403 */
404static void
405calc_inverse_matrix_transform(const struct weston_matrix *matrix,
406 const struct ivi_rectangle *rect_input,
407 const struct ivi_rectangle *boundingbox,
408 struct ivi_rectangle *rect_output)
409{
410 struct weston_matrix m;
411 struct weston_vector top_left;
412 struct weston_vector bottom_right;
413
414 assert(boundingbox != rect_output);
415
416 if (weston_matrix_invert(&m, matrix) < 0) {
417 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
418 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
419 rect_output->x = boundingbox->x;
420 rect_output->y = boundingbox->y;
421 rect_output->width = boundingbox->width;
422 rect_output->height = boundingbox->height;
423 }
424
425 /* The vectors and matrices involved will always produce f[3] == 1.0. */
426 top_left.f[0] = rect_input->x;
427 top_left.f[1] = rect_input->y;
428 top_left.f[2] = 0.0f;
429 top_left.f[3] = 1.0f;
430
431 bottom_right.f[0] = rect_input->x + rect_input->width;
432 bottom_right.f[1] = rect_input->y + rect_input->height;
433 bottom_right.f[2] = 0.0f;
434 bottom_right.f[3] = 1.0f;
435
436 weston_matrix_transform(&m, &top_left);
437 weston_matrix_transform(&m, &bottom_right);
438
439 if (top_left.f[0] < bottom_right.f[0]) {
440 rect_output->x = top_left.f[0];
441 rect_output->width = bottom_right.f[0] - rect_output->x;
442 } else {
443 rect_output->x = bottom_right.f[0];
444 rect_output->width = top_left.f[0] - rect_output->x;
445 }
446
447 if (top_left.f[1] < bottom_right.f[1]) {
448 rect_output->y = top_left.f[1];
449 rect_output->height = bottom_right.f[1] - rect_output->y;
450 } else {
451 rect_output->y = bottom_right.f[1];
452 rect_output->height = top_left.f[1] - rect_output->y;
453 }
454
455 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
456}
457
458/**
459 * This computes the whole transformation matrix:m from surface-local
Yong Bakose0698712016-04-28 11:59:08 -0500460 * coordinates to multi-screen coordinates, which are global coordinates.
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900461 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900462 *
Bryce Harringtone6da35d2016-05-19 17:35:02 -0700463 * Additionally, this computes the mask on surface-local coordinates as an
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900464 * ivi_rectangle. This can be set to weston_view_set_mask.
465 *
466 * The mask is computed by following steps
Yong Bakose0698712016-04-28 11:59:08 -0500467 * - destination rectangle of layer is transformed to multi-screen coordinates,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900468 * global coordinates. This is done by adding weston_output.{x,y} in simple
469 * because there is no scaled and rotated transformation.
Yong Bakose0698712016-04-28 11:59:08 -0500470 * - destination rectangle of layer in multi-screen coordinates needs to be
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900471 * intersected inside of a screen the layer is assigned to. This is because
472 * overlapped region of weston surface in another screen shall not be
473 * displayed according to ivi use case.
474 * - destination rectangle of layer
Yong Bakose0698712016-04-28 11:59:08 -0500475 * - in multi-screen coordinates,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900476 * - and intersected inside of an assigned screen,
Yong Bakose0698712016-04-28 11:59:08 -0500477 * is inversed to surface-local coordinates by inversed matrix:m.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900478 * - the area is intersected by intersected area between weston_surface and
479 * source rectangle of ivi_surface.
480 */
481static void
482calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900483 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900484 struct ivi_layout_layer *ivilayer,
485 struct ivi_layout_surface *ivisurf,
486 struct weston_matrix *m,
487 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900488{
489 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
490 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900491 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900492 struct ivi_rectangle weston_surface_rect = { 0,
493 0,
494 ivisurf->surface->width,
495 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900496 struct ivi_rectangle surface_source_rect = { sp->source_x,
497 sp->source_y,
498 sp->source_width,
499 sp->source_height };
500 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
501 sp->dest_y,
502 sp->dest_width,
503 sp->dest_height };
504 struct ivi_rectangle layer_source_rect = { lp->source_x,
505 lp->source_y,
506 lp->source_width,
507 lp->source_height };
508 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
509 lp->dest_y,
510 lp->dest_width,
511 lp->dest_height };
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900512 struct ivi_rectangle screen_dest_rect = { output->x,
513 output->y,
514 output->width,
515 output->height };
516 struct ivi_rectangle layer_dest_rect_in_global =
517 { lp->dest_x + output->x,
518 lp->dest_y + output->y,
519 lp->dest_width,
520 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900521 struct ivi_rectangle surface_result;
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900522 struct ivi_rectangle layer_dest_rect_in_global_intersected;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900523
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900524 /*
525 * the whole transformation matrix:m from surface-local
526 * coordinates to global coordinates, which is computed by
527 * two steps,
528 * - surface-local coordinates to layer-local coordinates
Yong Bakose0698712016-04-28 11:59:08 -0500529 * - layer-local coordinates to single screen-local coordinates
530 * - single screen-local coordinates to multi-screen coordinates,
531 * which are global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900532 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900533 calc_transformation_matrix(&surface_source_rect,
534 &surface_dest_rect,
535 sp->orientation, m);
536
537 calc_transformation_matrix(&layer_source_rect,
538 &layer_dest_rect,
539 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900540
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900541 weston_matrix_translate(m, output->x, output->y, 0.0f);
542
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900543 /* this intersected ivi_rectangle would be used for masking
544 * weston_surface
545 */
546 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
547 &surface_result);
548
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900549 /*
550 * destination rectangle of layer in multi screens coordinate
551 * is intersected to avoid displaying outside of an assigned screen.
552 */
553 ivi_rectangle_intersect(&layer_dest_rect_in_global, &screen_dest_rect,
554 &layer_dest_rect_in_global_intersected);
555
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900556 /* calc masking area of weston_surface from m */
557 calc_inverse_matrix_transform(m,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900558 &layer_dest_rect_in_global_intersected,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900559 &surface_result,
560 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900561}
562
563static void
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900564update_prop(struct ivi_layout_screen *iviscrn,
565 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900566 struct ivi_layout_surface *ivisurf)
567{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900568 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900569 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900570 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900571
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900572 /*In case of no prop change, this just returns*/
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000573 if (!ivilayer->prop.event_mask && !ivisurf->prop.event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900574 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900575
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900576 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900577
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000578 tmpview = get_weston_view(ivisurf);
579 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900580
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900581 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
582 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
583 can_calc = false;
584 }
585
586 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
587 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
588 can_calc = false;
589 }
590
591 if (can_calc) {
592 wl_list_remove(&ivisurf->transform.link);
593 weston_matrix_init(&ivisurf->transform.matrix);
594
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900595 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900596 iviscrn, ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900597
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000598 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
599 wl_list_insert(&tmpview->geometry.transformation_list,
600 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900601
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000602 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900603 }
604
605 ivisurf->update_count++;
606
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000607 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900608
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000609 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900610}
611
612static void
613commit_changes(struct ivi_layout *layout)
614{
615 struct ivi_layout_screen *iviscrn = NULL;
616 struct ivi_layout_layer *ivilayer = NULL;
617 struct ivi_layout_surface *ivisurf = NULL;
618
619 wl_list_for_each(iviscrn, &layout->screen_list, link) {
620 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900621 /*
622 * If ivilayer is invisible, weston_view of ivisurf doesn't
623 * need to be modified.
624 */
625 if (ivilayer->prop.visibility == false)
626 continue;
627
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900628 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900629 /*
630 * If ivilayer is invisible, weston_view of ivisurf doesn't
631 * need to be modified.
632 */
633 if (ivisurf->prop.visibility == false)
634 continue;
635
636 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900637 }
638 }
639 }
640}
641
642static void
643commit_surface_list(struct ivi_layout *layout)
644{
645 struct ivi_layout_surface *ivisurf = NULL;
646 int32_t dest_x = 0;
647 int32_t dest_y = 0;
648 int32_t dest_width = 0;
649 int32_t dest_height = 0;
650 int32_t configured = 0;
651
652 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300653 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900654 dest_x = ivisurf->prop.dest_x;
655 dest_y = ivisurf->prop.dest_y;
656 dest_width = ivisurf->prop.dest_width;
657 dest_height = ivisurf->prop.dest_height;
658
659 ivi_layout_transition_move_resize_view(ivisurf,
660 ivisurf->pending.prop.dest_x,
661 ivisurf->pending.prop.dest_y,
662 ivisurf->pending.prop.dest_width,
663 ivisurf->pending.prop.dest_height,
664 ivisurf->pending.prop.transition_duration);
665
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300666 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900667 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
668 } else {
669 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
670 }
671
672 ivisurf->prop = ivisurf->pending.prop;
673 ivisurf->prop.dest_x = dest_x;
674 ivisurf->prop.dest_y = dest_y;
675 ivisurf->prop.dest_width = dest_width;
676 ivisurf->prop.dest_height = dest_height;
677 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
678 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
679
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300680 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900681 dest_x = ivisurf->prop.dest_x;
682 dest_y = ivisurf->prop.dest_y;
683 dest_width = ivisurf->prop.dest_width;
684 dest_height = ivisurf->prop.dest_height;
685
686 ivi_layout_transition_move_resize_view(ivisurf,
687 ivisurf->pending.prop.dest_x,
688 ivisurf->pending.prop.dest_y,
689 ivisurf->pending.prop.dest_width,
690 ivisurf->pending.prop.dest_height,
691 ivisurf->pending.prop.transition_duration);
692
693 ivisurf->prop = ivisurf->pending.prop;
694 ivisurf->prop.dest_x = dest_x;
695 ivisurf->prop.dest_y = dest_y;
696 ivisurf->prop.dest_width = dest_width;
697 ivisurf->prop.dest_height = dest_height;
698
699 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
700 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
701
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300702 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900703 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300704 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900705 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
706 } else {
707 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
708 }
709
710 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
711 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
712 configured = 1;
713 }
714
715 ivisurf->prop = ivisurf->pending.prop;
716 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
717 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
718
Pekka Paalanen1f821932016-03-15 16:57:51 +0200719 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200720 shell_surface_send_configure(ivisurf->surface,
721 ivisurf->prop.dest_width,
722 ivisurf->prop.dest_height);
723 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900724 } else {
725 configured = 0;
726 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
727 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
728 configured = 1;
729 }
730
731 ivisurf->prop = ivisurf->pending.prop;
732 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
733 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
734
Pekka Paalanen1f821932016-03-15 16:57:51 +0200735 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200736 shell_surface_send_configure(ivisurf->surface,
737 ivisurf->prop.dest_width,
738 ivisurf->prop.dest_height);
739 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900740 }
741 }
742}
743
744static void
745commit_layer_list(struct ivi_layout *layout)
746{
747 struct ivi_layout_layer *ivilayer = NULL;
748 struct ivi_layout_surface *ivisurf = NULL;
749 struct ivi_layout_surface *next = NULL;
750
751 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300752 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900753 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 -0300754 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900755 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
756 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
757 NULL, NULL,
758 ivilayer->pending.prop.transition_duration);
759 }
760 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
761
762 ivilayer->prop = ivilayer->pending.prop;
763
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000764 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900765 continue;
766 }
767
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000768 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
769 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000770 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000771 wl_list_remove(&ivisurf->order.link);
772 wl_list_init(&ivisurf->order.link);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000773 ivisurf->prop.event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900774 }
775
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000776 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900777
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000778 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900779 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000780 wl_list_remove(&ivisurf->order.link);
781 wl_list_insert(&ivilayer->order.surface_list,
782 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000783 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000784 ivisurf->prop.event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900785 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000786
787 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900788 }
789}
790
791static void
792commit_screen_list(struct ivi_layout *layout)
793{
794 struct ivi_layout_screen *iviscrn = NULL;
795 struct ivi_layout_layer *ivilayer = NULL;
796 struct ivi_layout_layer *next = NULL;
797 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000798 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900799
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900800 /* Clear view list of layout ivi_layer */
801 wl_list_init(&layout->layout_layer.view_list.link);
802
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900803 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000804 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900805 wl_list_for_each_safe(ivilayer, next,
806 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000807 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000808 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900809 wl_list_init(&ivilayer->order.link);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000810 ivilayer->prop.event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900811 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900812
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000813 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900814
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900815 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
816 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900817 /* FIXME: avoid to insert order.link to multiple screens */
818 wl_list_remove(&ivilayer->order.link);
819
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900820 wl_list_insert(&iviscrn->order.layer_list,
821 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000822 ivilayer->on_screen = iviscrn;
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000823 ivilayer->prop.event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900824 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900825
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000826 iviscrn->order.dirty = 0;
827 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900828
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900829 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
830 if (ivilayer->prop.visibility == false)
831 continue;
832
833 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900834 if (ivisurf->prop.visibility == false)
835 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000836
837 tmpview = get_weston_view(ivisurf);
838 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900839
840 weston_layer_entry_insert(&layout->layout_layer.view_list,
841 &tmpview->layer_link);
842
843 ivisurf->surface->output = iviscrn->output;
844 }
845 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900846 }
847}
848
849static void
850commit_transition(struct ivi_layout* layout)
851{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300852 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900853 return;
854 }
855
856 wl_list_insert_list(&layout->transitions->transition_list,
857 &layout->pending_transition_list);
858
859 wl_list_init(&layout->pending_transition_list);
860
861 wl_event_source_timer_update(layout->transitions->event_source, 1);
862}
863
864static void
865send_surface_prop(struct ivi_layout_surface *ivisurf)
866{
867 wl_signal_emit(&ivisurf->property_changed, ivisurf);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000868 ivisurf->pending.prop.event_mask = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900869}
870
871static void
872send_layer_prop(struct ivi_layout_layer *ivilayer)
873{
874 wl_signal_emit(&ivilayer->property_changed, ivilayer);
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000875 ivilayer->pending.prop.event_mask = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900876}
877
878static void
879send_prop(struct ivi_layout *layout)
880{
881 struct ivi_layout_layer *ivilayer = NULL;
882 struct ivi_layout_surface *ivisurf = NULL;
883
884 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000885 if (ivilayer->prop.event_mask)
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900886 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900887 }
888
889 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +0000890 if (ivisurf->prop.event_mask)
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900891 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900892 }
893}
894
895static void
896clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
897{
898 struct ivi_layout_surface *surface_link = NULL;
899 struct ivi_layout_surface *surface_next = NULL;
900
901 wl_list_for_each_safe(surface_link, surface_next,
902 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000903 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900904 wl_list_init(&surface_link->pending.link);
905 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900906}
907
908static void
909clear_surface_order_list(struct ivi_layout_layer *ivilayer)
910{
911 struct ivi_layout_surface *surface_link = NULL;
912 struct ivi_layout_surface *surface_next = NULL;
913
914 wl_list_for_each_safe(surface_link, surface_next,
915 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000916 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900917 wl_list_init(&surface_link->order.link);
Wataru Natsume7b3a52a2016-04-11 21:34:52 +0900918 surface_link->on_layer = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900919 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900920}
921
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900922/**
923 * Exported APIs of ivi-layout library are implemented from here.
924 * Brief of APIs is described in ivi-layout-export.h.
925 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900926static int32_t
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000927ivi_layout_add_listener_create_layer(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900928{
929 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900930
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000931 if (listener == NULL) {
932 weston_log("ivi_layout_add_listener_create_layer: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900933 return IVI_FAILED;
934 }
935
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000936 wl_signal_add(&layout->layer_notification.created, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900937
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +0000938 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900939}
940
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900941static int32_t
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000942ivi_layout_add_listener_remove_layer(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900943{
944 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900945
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000946 if (listener == NULL) {
947 weston_log("ivi_layout_add_listener_remove_layer: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900948 return IVI_FAILED;
949 }
950
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000951 wl_signal_add(&layout->layer_notification.removed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900952
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +0000953 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900954}
955
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900956static int32_t
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000957ivi_layout_add_listener_create_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900958{
959 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900960
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000961 if (listener == NULL) {
962 weston_log("ivi_layout_add_listener_create_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900963 return IVI_FAILED;
964 }
965
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000966 wl_signal_add(&layout->surface_notification.created, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900967
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +0000968 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900969}
970
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900971static int32_t
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000972ivi_layout_add_listener_remove_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900973{
974 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900975
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000976 if (listener == NULL) {
977 weston_log("ivi_layout_add_listener_remove_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900978 return IVI_FAILED;
979 }
980
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000981 wl_signal_add(&layout->surface_notification.removed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900982
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +0000983 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900984}
985
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900986static int32_t
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000987ivi_layout_add_listener_configure_surface(struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900988{
989 struct ivi_layout *layout = get_instance();
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000990
991 if (listener == NULL) {
992 weston_log("ivi_layout_add_listener_configure_surface: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900993 return IVI_FAILED;
994 }
995
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000996 wl_signal_add(&layout->surface_notification.configure_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900997
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +0000998 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900999}
1000
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001001uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001002ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1003{
1004 return ivisurf->id_surface;
1005}
1006
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001007static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001008ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1009{
1010 return ivilayer->id_layer;
1011}
1012
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001013static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001014ivi_layout_get_layer_from_id(uint32_t id_layer)
1015{
1016 struct ivi_layout *layout = get_instance();
1017 struct ivi_layout_layer *ivilayer = NULL;
1018
1019 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1020 if (ivilayer->id_layer == id_layer) {
1021 return ivilayer;
1022 }
1023 }
1024
1025 return NULL;
1026}
1027
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001028struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001029ivi_layout_get_surface_from_id(uint32_t id_surface)
1030{
1031 struct ivi_layout *layout = get_instance();
1032 struct ivi_layout_surface *ivisurf = NULL;
1033
1034 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1035 if (ivisurf->id_surface == id_surface) {
1036 return ivisurf;
1037 }
1038 }
1039
1040 return NULL;
1041}
1042
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001043static int32_t
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001044ivi_layout_surface_add_listener(struct ivi_layout_surface *ivisurf,
1045 struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001046{
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001047 if (ivisurf == NULL || listener == NULL) {
1048 weston_log("ivi_layout_surface_add_listener: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001049 return IVI_FAILED;
1050 }
1051
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00001052 wl_signal_add(&ivisurf->property_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001053
1054 return IVI_SUCCEEDED;
1055}
1056
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001057static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001058ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1059{
1060 if (ivilayer == NULL) {
1061 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1062 return NULL;
1063 }
1064
1065 return &ivilayer->prop;
1066}
1067
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001068static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001069ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1070 int32_t *pLength,
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001071 struct weston_output ***ppArray)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001072{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001073 int32_t length = 0;
1074 int32_t n = 0;
1075
1076 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1077 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1078 return IVI_FAILED;
1079 }
1080
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001081 if (ivilayer->on_screen != NULL)
1082 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001083
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001084 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001085 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001086 *ppArray = calloc(length, sizeof(struct weston_output *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001087 if (*ppArray == NULL) {
1088 weston_log("fails to allocate memory\n");
1089 return IVI_FAILED;
1090 }
1091
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001092 (*ppArray)[n++] = ivilayer->on_screen->output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001093 }
1094
1095 *pLength = length;
1096
1097 return IVI_SUCCEEDED;
1098}
1099
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001100static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001101ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1102{
1103 struct ivi_layout *layout = get_instance();
1104 struct ivi_layout_layer *ivilayer = NULL;
1105 int32_t length = 0;
1106 int32_t n = 0;
1107
1108 if (pLength == NULL || ppArray == NULL) {
1109 weston_log("ivi_layout_get_layers: invalid argument\n");
1110 return IVI_FAILED;
1111 }
1112
1113 length = wl_list_length(&layout->layer_list);
1114
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001115 if (length != 0) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001116 /* the Array must be freed by module which called this function */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001117 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1118 if (*ppArray == NULL) {
1119 weston_log("fails to allocate memory\n");
1120 return IVI_FAILED;
1121 }
1122
1123 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1124 (*ppArray)[n++] = ivilayer;
1125 }
1126 }
1127
1128 *pLength = length;
1129
1130 return IVI_SUCCEEDED;
1131}
1132
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001133static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001134ivi_layout_get_layers_on_screen(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001135 int32_t *pLength,
1136 struct ivi_layout_layer ***ppArray)
1137{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001138 struct ivi_layout_screen *iviscrn = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001139 struct ivi_layout_layer *ivilayer = NULL;
1140 int32_t length = 0;
1141 int32_t n = 0;
1142
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001143 if (output == NULL || pLength == NULL || ppArray == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001144 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1145 return IVI_FAILED;
1146 }
1147
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001148 iviscrn = get_screen_from_output(output);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001149 length = wl_list_length(&iviscrn->order.layer_list);
1150
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001151 if (length != 0) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001152 /* the Array must be freed by module which called this function */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001153 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1154 if (*ppArray == NULL) {
1155 weston_log("fails to allocate memory\n");
1156 return IVI_FAILED;
1157 }
1158
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001159 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001160 (*ppArray)[n++] = ivilayer;
1161 }
1162 }
1163
1164 *pLength = length;
1165
1166 return IVI_SUCCEEDED;
1167}
1168
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001169static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001170ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1171 int32_t *pLength,
1172 struct ivi_layout_layer ***ppArray)
1173{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001174 int32_t length = 0;
1175 int32_t n = 0;
1176
1177 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1178 weston_log("ivi_layout_getLayers: invalid argument\n");
1179 return IVI_FAILED;
1180 }
1181
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001182 if (ivisurf->on_layer != NULL) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001183 /* the Array must be freed by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001184 length = 1;
1185 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001186 if (*ppArray == NULL) {
1187 weston_log("fails to allocate memory\n");
1188 return IVI_FAILED;
1189 }
1190
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001191 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001192 }
1193
1194 *pLength = length;
1195
1196 return IVI_SUCCEEDED;
1197}
1198
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001199static
1200int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001201ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1202{
1203 struct ivi_layout *layout = get_instance();
1204 struct ivi_layout_surface *ivisurf = NULL;
1205 int32_t length = 0;
1206 int32_t n = 0;
1207
1208 if (pLength == NULL || ppArray == NULL) {
1209 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1210 return IVI_FAILED;
1211 }
1212
1213 length = wl_list_length(&layout->surface_list);
1214
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001215 if (length != 0) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001216 /* the Array must be freed by module which called this function */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001217 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1218 if (*ppArray == NULL) {
1219 weston_log("fails to allocate memory\n");
1220 return IVI_FAILED;
1221 }
1222
1223 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1224 (*ppArray)[n++] = ivisurf;
1225 }
1226 }
1227
1228 *pLength = length;
1229
1230 return IVI_SUCCEEDED;
1231}
1232
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001233static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001234ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1235 int32_t *pLength,
1236 struct ivi_layout_surface ***ppArray)
1237{
1238 struct ivi_layout_surface *ivisurf = NULL;
1239 int32_t length = 0;
1240 int32_t n = 0;
1241
1242 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1243 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1244 return IVI_FAILED;
1245 }
1246
1247 length = wl_list_length(&ivilayer->order.surface_list);
1248
1249 if (length != 0) {
Bryce Harringtone6da35d2016-05-19 17:35:02 -07001250 /* the Array must be freed by module which called this function */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001251 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1252 if (*ppArray == NULL) {
1253 weston_log("fails to allocate memory\n");
1254 return IVI_FAILED;
1255 }
1256
1257 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1258 (*ppArray)[n++] = ivisurf;
1259 }
1260 }
1261
1262 *pLength = length;
1263
1264 return IVI_SUCCEEDED;
1265}
1266
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001267static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001268ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1269 int32_t width, int32_t height)
1270{
1271 struct ivi_layout *layout = get_instance();
1272 struct ivi_layout_layer *ivilayer = NULL;
1273
1274 ivilayer = get_layer(&layout->layer_list, id_layer);
1275 if (ivilayer != NULL) {
1276 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001277 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001278 return ivilayer;
1279 }
1280
1281 ivilayer = calloc(1, sizeof *ivilayer);
1282 if (ivilayer == NULL) {
1283 weston_log("fails to allocate memory\n");
1284 return NULL;
1285 }
1286
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001287 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001288 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001289 ivilayer->layout = layout;
1290 ivilayer->id_layer = id_layer;
1291
1292 init_layer_properties(&ivilayer->prop, width, height);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001293
1294 wl_list_init(&ivilayer->pending.surface_list);
1295 wl_list_init(&ivilayer->pending.link);
1296 ivilayer->pending.prop = ivilayer->prop;
1297
1298 wl_list_init(&ivilayer->order.surface_list);
1299 wl_list_init(&ivilayer->order.link);
1300
1301 wl_list_insert(&layout->layer_list, &ivilayer->link);
1302
1303 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1304
1305 return ivilayer;
1306}
1307
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001308static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001309ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001310{
1311 struct ivi_layout *layout = get_instance();
1312
1313 if (ivilayer == NULL) {
1314 weston_log("ivi_layout_layer_remove: invalid argument\n");
1315 return;
1316 }
1317
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001318 if (--ivilayer->ref_count > 0)
1319 return;
1320
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001321 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1322
1323 clear_surface_pending_list(ivilayer);
1324 clear_surface_order_list(ivilayer);
1325
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001326 wl_list_remove(&ivilayer->pending.link);
1327 wl_list_remove(&ivilayer->order.link);
1328 wl_list_remove(&ivilayer->link);
1329
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001330 free(ivilayer);
1331}
1332
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001333int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001334ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1335 bool newVisibility)
1336{
1337 struct ivi_layout_layer_properties *prop = NULL;
1338
1339 if (ivilayer == NULL) {
1340 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1341 return IVI_FAILED;
1342 }
1343
1344 prop = &ivilayer->pending.prop;
1345 prop->visibility = newVisibility;
1346
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001347 if (ivilayer->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001348 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001349 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001350 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001351
1352 return IVI_SUCCEEDED;
1353}
1354
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001355int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001356ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1357 wl_fixed_t opacity)
1358{
1359 struct ivi_layout_layer_properties *prop = NULL;
1360
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001361 if (ivilayer == NULL ||
1362 opacity < wl_fixed_from_double(0.0) ||
1363 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001364 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1365 return IVI_FAILED;
1366 }
1367
1368 prop = &ivilayer->pending.prop;
1369 prop->opacity = opacity;
1370
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001371 if (ivilayer->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001372 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001373 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001374 prop->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001375
1376 return IVI_SUCCEEDED;
1377}
1378
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001379static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001380ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1381 int32_t x, int32_t y,
1382 int32_t width, int32_t height)
1383{
1384 struct ivi_layout_layer_properties *prop = NULL;
1385
1386 if (ivilayer == NULL) {
1387 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1388 return IVI_FAILED;
1389 }
1390
1391 prop = &ivilayer->pending.prop;
1392 prop->source_x = x;
1393 prop->source_y = y;
1394 prop->source_width = width;
1395 prop->source_height = height;
1396
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001397 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1398 ivilayer->prop.source_width != width ||
1399 ivilayer->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001400 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001401 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001402 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001403
1404 return IVI_SUCCEEDED;
1405}
1406
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001407int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001408ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1409 int32_t x, int32_t y,
1410 int32_t width, int32_t height)
1411{
1412 struct ivi_layout_layer_properties *prop = NULL;
1413
1414 if (ivilayer == NULL) {
1415 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1416 return IVI_FAILED;
1417 }
1418
1419 prop = &ivilayer->pending.prop;
1420 prop->dest_x = x;
1421 prop->dest_y = y;
1422 prop->dest_width = width;
1423 prop->dest_height = height;
1424
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001425 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1426 ivilayer->prop.dest_width != width ||
1427 ivilayer->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001428 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001429 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001430 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001431
1432 return IVI_SUCCEEDED;
1433}
1434
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001435static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001436ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1437 enum wl_output_transform orientation)
1438{
1439 struct ivi_layout_layer_properties *prop = NULL;
1440
1441 if (ivilayer == NULL) {
1442 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1443 return IVI_FAILED;
1444 }
1445
1446 prop = &ivilayer->pending.prop;
1447 prop->orientation = orientation;
1448
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001449 if (ivilayer->prop.orientation != orientation)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001450 prop->event_mask |= IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001451 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001452 prop->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001453
1454 return IVI_SUCCEEDED;
1455}
1456
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001457int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001458ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1459 struct ivi_layout_surface **pSurface,
1460 int32_t number)
1461{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001462 int32_t i = 0;
1463
1464 if (ivilayer == NULL) {
1465 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1466 return IVI_FAILED;
1467 }
1468
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001469 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001470
1471 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)72ad1642016-03-16 13:37:05 +00001472 wl_list_remove(&pSurface[i]->pending.link);
1473 wl_list_insert(&ivilayer->pending.surface_list,
1474 &pSurface[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001475 }
1476
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001477 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001478
1479 return IVI_SUCCEEDED;
1480}
1481
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001482int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001483ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1484 bool newVisibility)
1485{
1486 struct ivi_layout_surface_properties *prop = NULL;
1487
1488 if (ivisurf == NULL) {
1489 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1490 return IVI_FAILED;
1491 }
1492
1493 prop = &ivisurf->pending.prop;
1494 prop->visibility = newVisibility;
1495
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001496 if (ivisurf->prop.visibility != newVisibility)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001497 prop->event_mask |= IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001498 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001499 prop->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001500
1501 return IVI_SUCCEEDED;
1502}
1503
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001504int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001505ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1506 wl_fixed_t opacity)
1507{
1508 struct ivi_layout_surface_properties *prop = NULL;
1509
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001510 if (ivisurf == NULL ||
1511 opacity < wl_fixed_from_double(0.0) ||
1512 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001513 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1514 return IVI_FAILED;
1515 }
1516
1517 prop = &ivisurf->pending.prop;
1518 prop->opacity = opacity;
1519
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001520 if (ivisurf->prop.opacity != opacity)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001521 prop->event_mask |= IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001522 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001523 prop->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001524
1525 return IVI_SUCCEEDED;
1526}
1527
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001528int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001529ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1530 int32_t x, int32_t y,
1531 int32_t width, int32_t height)
1532{
1533 struct ivi_layout_surface_properties *prop = NULL;
1534
1535 if (ivisurf == NULL) {
1536 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1537 return IVI_FAILED;
1538 }
1539
1540 prop = &ivisurf->pending.prop;
1541 prop->start_x = prop->dest_x;
1542 prop->start_y = prop->dest_y;
1543 prop->dest_x = x;
1544 prop->dest_y = y;
1545 prop->start_width = prop->dest_width;
1546 prop->start_height = prop->dest_height;
1547 prop->dest_width = width;
1548 prop->dest_height = height;
1549
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001550 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
1551 ivisurf->prop.dest_width != width ||
1552 ivisurf->prop.dest_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001553 prop->event_mask |= IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001554 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001555 prop->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001556
1557 return IVI_SUCCEEDED;
1558}
1559
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001560static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001561ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
1562 enum wl_output_transform orientation)
1563{
1564 struct ivi_layout_surface_properties *prop = NULL;
1565
1566 if (ivisurf == NULL) {
1567 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
1568 return IVI_FAILED;
1569 }
1570
1571 prop = &ivisurf->pending.prop;
1572 prop->orientation = orientation;
1573
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001574 if (ivisurf->prop.orientation != orientation)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001575 prop->event_mask |= IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001576 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001577 prop->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001578
1579 return IVI_SUCCEEDED;
1580}
1581
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001582static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001583ivi_layout_screen_add_layer(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001584 struct ivi_layout_layer *addlayer)
1585{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001586 struct ivi_layout_screen *iviscrn;
1587
1588 if (output == NULL || addlayer == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001589 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
1590 return IVI_FAILED;
1591 }
1592
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001593 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001594
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00001595 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001596 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
1597 return IVI_SUCCEEDED;
1598 }
1599
Ucan, Emre (ADITG/SW1)f46306f2016-03-16 13:37:07 +00001600 wl_list_remove(&addlayer->pending.link);
1601 wl_list_insert(&iviscrn->pending.layer_list, &addlayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001602
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001603 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001604
1605 return IVI_SUCCEEDED;
1606}
1607
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001608static int32_t
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001609ivi_layout_screen_set_render_order(struct weston_output *output,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001610 struct ivi_layout_layer **pLayer,
1611 const int32_t number)
1612{
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001613 struct ivi_layout_screen *iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001614 struct ivi_layout_layer *ivilayer = NULL;
1615 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001616 int32_t i = 0;
1617
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001618 if (output == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001619 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
1620 return IVI_FAILED;
1621 }
1622
Ucan, Emre (ADITG/SW1)b216c922016-03-17 15:30:46 +00001623 iviscrn = get_screen_from_output(output);
Ucan, Emre (ADITG/SW1)273874e2016-03-17 15:30:42 +00001624
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001625 wl_list_for_each_safe(ivilayer, next,
1626 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001627 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001628 wl_list_init(&ivilayer->pending.link);
1629 }
1630
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001631 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001632
1633 for (i = 0; i < number; i++) {
Ucan, Emre (ADITG/SW1)4e221f02016-03-16 13:37:08 +00001634 wl_list_remove(&pLayer[i]->pending.link);
1635 wl_list_insert(&iviscrn->pending.layer_list,
1636 &pLayer[i]->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001637 }
1638
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00001639 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001640
1641 return IVI_SUCCEEDED;
1642}
1643
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001644/**
1645 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
1646 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
1647 * This function is used to get the result of drawing by clients.
1648 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001649static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001650ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
1651{
1652 return ivisurf != NULL ? ivisurf->surface : NULL;
1653}
1654
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001655static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09001656ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
1657 int32_t *width, int32_t *height,
1658 int32_t *stride)
1659{
1660 int32_t w;
1661 int32_t h;
1662 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
1663
1664 if (ivisurf == NULL || ivisurf->surface == NULL) {
1665 weston_log("%s: invalid argument\n", __func__);
1666 return IVI_FAILED;
1667 }
1668
1669 weston_surface_get_content_size(ivisurf->surface, &w, &h);
1670
1671 if (width != NULL)
1672 *width = w;
1673
1674 if (height != NULL)
1675 *height = h;
1676
1677 if (stride != NULL)
1678 *stride = w * bytespp;
1679
1680 return IVI_SUCCEEDED;
1681}
1682
1683static int32_t
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001684ivi_layout_layer_add_listener(struct ivi_layout_layer *ivilayer,
1685 struct wl_listener *listener)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001686{
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001687 if (ivilayer == NULL || listener == NULL) {
1688 weston_log("ivi_layout_layer_add_listener: invalid argument\n");
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001689 return IVI_FAILED;
1690 }
1691
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001692 wl_signal_add(&ivilayer->property_changed, listener);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001693
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00001694 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001695}
1696
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001697static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001698ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
1699{
1700 if (ivisurf == NULL) {
1701 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
1702 return NULL;
1703 }
1704
1705 return &ivisurf->prop;
1706}
1707
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001708static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001709ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
1710 struct ivi_layout_surface *addsurf)
1711{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001712 if (ivilayer == NULL || addsurf == NULL) {
1713 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
1714 return IVI_FAILED;
1715 }
1716
Wataru Natsume9c926fe2016-03-03 19:56:09 +09001717 if (addsurf->on_layer == ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001718 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001719
Ucan, Emre (ADITG/SW1)10942372016-03-16 13:37:02 +00001720 wl_list_remove(&addsurf->pending.link);
1721 wl_list_insert(&ivilayer->pending.surface_list, &addsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001722
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001723 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001724
1725 return IVI_SUCCEEDED;
1726}
1727
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001728static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001729ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
1730 struct ivi_layout_surface *remsurf)
1731{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001732 if (ivilayer == NULL || remsurf == NULL) {
1733 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
1734 return;
1735 }
1736
Ucan, Emre (ADITG/SW1)536d8332016-03-16 13:36:59 +00001737 wl_list_remove(&remsurf->pending.link);
1738 wl_list_init(&remsurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001739
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001740 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001741}
1742
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001743static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001744ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
1745 int32_t x, int32_t y,
1746 int32_t width, int32_t height)
1747{
1748 struct ivi_layout_surface_properties *prop = NULL;
1749
1750 if (ivisurf == NULL) {
1751 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
1752 return IVI_FAILED;
1753 }
1754
1755 prop = &ivisurf->pending.prop;
1756 prop->source_x = x;
1757 prop->source_y = y;
1758 prop->source_width = width;
1759 prop->source_height = height;
1760
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001761 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
1762 ivisurf->prop.source_width != width ||
1763 ivisurf->prop.source_height != height)
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001764 prop->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001765 else
Ucan, Emre (ADITG/SW1)0bd29b62016-03-31 11:08:52 +00001766 prop->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001767
1768 return IVI_SUCCEEDED;
1769}
1770
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001771int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001772ivi_layout_commit_changes(void)
1773{
1774 struct ivi_layout *layout = get_instance();
1775
1776 commit_surface_list(layout);
1777 commit_layer_list(layout);
1778 commit_screen_list(layout);
1779
1780 commit_transition(layout);
1781
1782 commit_changes(layout);
1783 send_prop(layout);
1784 weston_compositor_schedule_repaint(layout->compositor);
1785
1786 return IVI_SUCCEEDED;
1787}
1788
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001789static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001790ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
1791 enum ivi_layout_transition_type type,
1792 uint32_t duration)
1793{
1794 if (ivilayer == NULL) {
1795 weston_log("%s: invalid argument\n", __func__);
1796 return -1;
1797 }
1798
1799 ivilayer->pending.prop.transition_type = type;
1800 ivilayer->pending.prop.transition_duration = duration;
1801
1802 return 0;
1803}
1804
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001805static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001806ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
1807 uint32_t is_fade_in,
1808 double start_alpha, double end_alpha)
1809{
1810 if (ivilayer == NULL) {
1811 weston_log("%s: invalid argument\n", __func__);
1812 return -1;
1813 }
1814
1815 ivilayer->pending.prop.is_fade_in = is_fade_in;
1816 ivilayer->pending.prop.start_alpha = start_alpha;
1817 ivilayer->pending.prop.end_alpha = end_alpha;
1818
1819 return 0;
1820}
1821
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001822static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001823ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
1824 uint32_t duration)
1825{
1826 struct ivi_layout_surface_properties *prop;
1827
1828 if (ivisurf == NULL) {
1829 weston_log("%s: invalid argument\n", __func__);
1830 return -1;
1831 }
1832
1833 prop = &ivisurf->pending.prop;
1834 prop->transition_duration = duration*10;
1835 return 0;
1836}
1837
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001838static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09001839ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
1840 enum ivi_layout_transition_type type,
1841 uint32_t duration)
1842{
1843 struct ivi_layout_surface_properties *prop;
1844
1845 if (ivisurf == NULL) {
1846 weston_log("%s: invalid argument\n", __func__);
1847 return -1;
1848 }
1849
1850 prop = &ivisurf->pending.prop;
1851 prop->transition_type = type;
1852 prop->transition_duration = duration;
1853 return 0;
1854}
1855
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09001856static int32_t
1857ivi_layout_surface_dump(struct weston_surface *surface,
1858 void *target, size_t size,int32_t x, int32_t y,
1859 int32_t width, int32_t height)
1860{
1861 int result = 0;
1862
1863 if (surface == NULL) {
1864 weston_log("%s: invalid argument\n", __func__);
1865 return IVI_FAILED;
1866 }
1867
1868 result = weston_surface_copy_content(
1869 surface, target, size,
1870 x, y, width, height);
1871
1872 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
1873}
1874
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001875/**
1876 * methods of interaction between ivi-shell with ivi-layout
1877 */
1878struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001879ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
1880{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001881 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001882 return NULL;
1883
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00001884 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001885}
1886
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001887void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001888ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
1889 int32_t width, int32_t height)
1890{
1891 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001892
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09001893 /* emit callback which is set by ivi-layout api user */
1894 wl_signal_emit(&layout->surface_notification.configure_changed,
1895 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001896}
1897
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001898struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001899ivi_layout_surface_create(struct weston_surface *wl_surface,
1900 uint32_t id_surface)
1901{
1902 struct ivi_layout *layout = get_instance();
1903 struct ivi_layout_surface *ivisurf = NULL;
1904 struct weston_view *tmpview = NULL;
1905
1906 if (wl_surface == NULL) {
1907 weston_log("ivi_layout_surface_create: invalid argument\n");
1908 return NULL;
1909 }
1910
1911 ivisurf = get_surface(&layout->surface_list, id_surface);
1912 if (ivisurf != NULL) {
1913 if (ivisurf->surface != NULL) {
1914 weston_log("id_surface(%d) is already created\n", id_surface);
1915 return NULL;
1916 }
1917 }
1918
1919 ivisurf = calloc(1, sizeof *ivisurf);
1920 if (ivisurf == NULL) {
1921 weston_log("fails to allocate memory\n");
1922 return NULL;
1923 }
1924
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001925 wl_signal_init(&ivisurf->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001926 ivisurf->id_surface = id_surface;
1927 ivisurf->layout = layout;
1928
1929 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001930
1931 tmpview = weston_view_create(wl_surface);
1932 if (tmpview == NULL) {
1933 weston_log("fails to allocate memory\n");
1934 }
1935
1936 ivisurf->surface->width_from_buffer = 0;
1937 ivisurf->surface->height_from_buffer = 0;
1938
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09001939 weston_matrix_init(&ivisurf->transform.matrix);
1940 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001941
1942 init_surface_properties(&ivisurf->prop);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001943
1944 ivisurf->pending.prop = ivisurf->prop;
1945 wl_list_init(&ivisurf->pending.link);
1946
1947 wl_list_init(&ivisurf->order.link);
1948 wl_list_init(&ivisurf->order.layer_list);
1949
1950 wl_list_insert(&layout->surface_list, &ivisurf->link);
1951
1952 wl_signal_emit(&layout->surface_notification.created, ivisurf);
1953
1954 return ivisurf;
1955}
1956
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09001957void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001958ivi_layout_init_with_compositor(struct weston_compositor *ec)
1959{
1960 struct ivi_layout *layout = get_instance();
1961
1962 layout->compositor = ec;
1963
1964 wl_list_init(&layout->surface_list);
1965 wl_list_init(&layout->layer_list);
1966 wl_list_init(&layout->screen_list);
1967
1968 wl_signal_init(&layout->layer_notification.created);
1969 wl_signal_init(&layout->layer_notification.removed);
1970
1971 wl_signal_init(&layout->surface_notification.created);
1972 wl_signal_init(&layout->surface_notification.removed);
1973 wl_signal_init(&layout->surface_notification.configure_changed);
1974
1975 /* Add layout_layer at the last of weston_compositor.layer_list */
1976 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
1977
1978 create_screen(ec);
1979
1980 layout->transitions = ivi_layout_transition_set_create(ec);
1981 wl_list_init(&layout->pending_transition_list);
1982}
1983
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001984static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001985 /**
1986 * commit all changes
1987 */
1988 .commit_changes = ivi_layout_commit_changes,
1989
1990 /**
1991 * surface controller interfaces
1992 */
Ucan, Emre (ADITG/SW1)970f8312016-04-04 08:05:09 +00001993 .add_listener_create_surface = ivi_layout_add_listener_create_surface,
Ucan, Emre (ADITG/SW1)67f0aa82016-04-04 08:05:18 +00001994 .add_listener_remove_surface = ivi_layout_add_listener_remove_surface,
Ucan, Emre (ADITG/SW1)c49aa5a2016-04-04 08:05:20 +00001995 .add_listener_configure_surface = ivi_layout_add_listener_configure_surface,
Pekka Paalaneneaa43fc2016-04-12 16:06:58 +03001996 .get_surface = shell_get_ivi_layout_surface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001997 .get_surfaces = ivi_layout_get_surfaces,
1998 .get_id_of_surface = ivi_layout_get_id_of_surface,
1999 .get_surface_from_id = ivi_layout_get_surface_from_id,
2000 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2001 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2002 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002003 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002004 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2005 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002006 .surface_set_orientation = ivi_layout_surface_set_orientation,
Ucan, Emre (ADITG/SW1)706cb5a2016-04-04 08:05:03 +00002007 .surface_add_listener = ivi_layout_surface_add_listener,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002008 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2009 .surface_set_transition = ivi_layout_surface_set_transition,
2010 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2011
2012 /**
2013 * layer controller interfaces
2014 */
Ucan, Emre (ADITG/SW1)c98f2cf2016-04-04 08:05:12 +00002015 .add_listener_create_layer = ivi_layout_add_listener_create_layer,
Ucan, Emre (ADITG/SW1)562f2ec2016-04-04 08:05:15 +00002016 .add_listener_remove_layer = ivi_layout_add_listener_remove_layer,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002017 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002018 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002019 .get_layers = ivi_layout_get_layers,
2020 .get_id_of_layer = ivi_layout_get_id_of_layer,
2021 .get_layer_from_id = ivi_layout_get_layer_from_id,
2022 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2023 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2024 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2025 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002026 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002027 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2028 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002029 .layer_set_orientation = ivi_layout_layer_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002030 .layer_add_surface = ivi_layout_layer_add_surface,
2031 .layer_remove_surface = ivi_layout_layer_remove_surface,
2032 .layer_set_render_order = ivi_layout_layer_set_render_order,
Ucan, Emre (ADITG/SW1)3750d1b2016-04-04 08:05:05 +00002033 .layer_add_listener = ivi_layout_layer_add_listener,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002034 .layer_set_transition = ivi_layout_layer_set_transition,
2035
2036 /**
Ucan, Emre (ADITG/SW1)6d89b1c2016-03-17 15:30:49 +00002037 * screen controller interfaces
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002038 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002039 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2040 .screen_add_layer = ivi_layout_screen_add_layer,
2041 .screen_set_render_order = ivi_layout_screen_set_render_order,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002042
2043 /**
2044 * animation
2045 */
2046 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002047 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2048
2049 /**
2050 * surface content dumping for debugging
2051 */
2052 .surface_get_size = ivi_layout_surface_get_size,
2053 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002054};
2055
2056int
2057load_controller_modules(struct weston_compositor *compositor, const char *modules,
2058 int *argc, char *argv[])
2059{
2060 const char *p, *end;
2061 char buffer[256];
2062 int (*controller_module_init)(struct weston_compositor *compositor,
2063 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002064 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002065 size_t interface_version);
2066
2067 if (modules == NULL)
2068 return 0;
2069
2070 p = modules;
2071 while (*p) {
2072 end = strchrnul(p, ',');
2073 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2074
Giulio Camuffo179fcda2016-06-02 21:48:14 +03002075 controller_module_init = wet_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002076 if (!controller_module_init)
2077 return -1;
2078
2079 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002080 &ivi_layout_interface,
2081 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002082 weston_log("ivi-shell: Initialization of controller module fails");
2083 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002084 }
2085
2086 p = end;
2087 while (*p == ',')
2088 p++;
2089 }
2090
2091 return 0;
2092}