blob: 23ce67b476607f1982b676079e9b5eced44b362f [file] [log] [blame]
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001/*
2 * Copyright (C) 2013 DENSO CORPORATION
3 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090011 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090024 */
25
26/**
27 * Implementation of ivi-layout library. The actual view on ivi_screen is
28 * not updated till calling ivi_layout_commit_changes. A overview from
29 * calling API for updating properties of ivi_surface/ivi_layer to asking
30 * compositor to compose them by using weston_compositor_schedule_repaint,
31 * 0/ initialize this library by ivi_layout_init_with_compositor
32 * with (struct weston_compositor *ec) from ivi-shell.
33 * 1/ When a API for updating properties of ivi_surface/ivi_layer, it updates
34 * pending prop of ivi_surface/ivi_layer/ivi_screen which are structure to
35 * store properties.
36 * 2/ Before calling commitChanges, in case of calling a API to get a property,
37 * return current property, not pending property.
38 * 3/ At the timing of calling ivi_layout_commitChanges, pending properties
39 * are applied to properties.
40 *
41 * *) ivi_layout_commitChanges is also called by transition animation
42 * per each frame. See ivi-layout-transition.c in details. Transition
43 * animation interpolates frames between previous properties of ivi_surface
44 * and new ones.
45 * For example, when a property of ivi_surface is changed from invisibility
46 * to visibility, it behaves like fade-in. When ivi_layout_commitChange is
47 * called during transition animation, it cancels the transition and
48 * re-start transition to new properties from current properties of final
49 * frame just before the the cancellation.
50 *
51 * 4/ According properties, set transformation by using weston_matrix and
52 * weston_view per ivi_surfaces and ivi_layers in while loop.
53 * 5/ Set damage and trigger transform by using weston_view_geometry_dirty.
54 * 6/ Notify update of properties.
55 * 7/ Trigger composition by weston_compositor_schedule_repaint.
56 *
57 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090058#include "config.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090059
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090060#include <string.h>
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +000061#include <assert.h>
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090062
63#include "compositor.h"
64#include "ivi-layout-export.h"
65#include "ivi-layout-private.h"
66
Jon Cruz867d50e2015-06-15 15:37:10 -070067#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070068#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090069
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +090070#define max(a, b) ((a) > (b) ? (a) : (b))
71
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090072struct listener_layout_notification {
73 void *userdata;
74 struct wl_listener listener;
75};
76
77struct ivi_layout;
78
79struct ivi_layout_screen {
80 struct wl_list link;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090081 uint32_t id_screen;
82
83 struct ivi_layout *layout;
84 struct weston_output *output;
85
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090086 struct {
87 struct wl_list layer_list;
88 struct wl_list link;
89 } pending;
90
91 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +000092 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090093 struct wl_list layer_list;
94 struct wl_list link;
95 } order;
96};
97
98struct ivi_layout_notification_callback {
99 void *callback;
100 void *data;
101};
102
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900103struct ivi_rectangle
104{
105 int32_t x;
106 int32_t y;
107 int32_t width;
108 int32_t height;
109};
110
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900111static void
112remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
113
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900114static struct ivi_layout ivilayout = {0};
115
116struct ivi_layout *
117get_instance(void)
118{
119 return &ivilayout;
120}
121
122/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900123 * Internal API to add/remove a ivi_layer to/from ivi_screen.
124 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900125static struct ivi_layout_surface *
126get_surface(struct wl_list *surf_list, uint32_t id_surface)
127{
128 struct ivi_layout_surface *ivisurf;
129
130 wl_list_for_each(ivisurf, surf_list, link) {
131 if (ivisurf->id_surface == id_surface) {
132 return ivisurf;
133 }
134 }
135
136 return NULL;
137}
138
139static struct ivi_layout_layer *
140get_layer(struct wl_list *layer_list, uint32_t id_layer)
141{
142 struct ivi_layout_layer *ivilayer;
143
144 wl_list_for_each(ivilayer, layer_list, link) {
145 if (ivilayer->id_layer == id_layer) {
146 return ivilayer;
147 }
148 }
149
150 return NULL;
151}
152
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000153static struct weston_view *
154get_weston_view(struct ivi_layout_surface *ivisurf)
155{
156 struct weston_view *view = NULL;
157
158 assert(ivisurf->surface != NULL);
159
160 /* One view per surface */
161 if(wl_list_empty(&ivisurf->surface->views))
162 view = NULL;
163 else
164 view = wl_container_of(ivisurf->surface->views.next, view, surface_link);
165
166 return view;
167}
168
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900169static void
170remove_configured_listener(struct ivi_layout_surface *ivisurf)
171{
172 struct wl_listener *link = NULL;
173 struct wl_listener *next = NULL;
174
175 wl_list_for_each_safe(link, next, &ivisurf->configured.listener_list, link) {
176 wl_list_remove(&link->link);
177 }
178}
179
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900180static void
181remove_all_notification(struct wl_list *listener_list)
182{
183 struct wl_listener *listener = NULL;
184 struct wl_listener *next = NULL;
185
186 wl_list_for_each_safe(listener, next, listener_list, link) {
187 struct listener_layout_notification *notification = NULL;
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000188 wl_list_remove(&listener->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900189
190 notification =
191 container_of(listener,
192 struct listener_layout_notification,
193 listener);
194
195 free(notification->userdata);
196 free(notification);
197 }
198}
199
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900200static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900201ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
202{
203 if (ivisurf == NULL) {
204 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
205 return;
206 }
207
208 remove_all_notification(&ivisurf->property_changed.listener_list);
209}
210
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900211static void
212ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
213 surface_property_notification_func callback,
214 void *userdata)
215{
216 if (ivisurf == NULL) {
217 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
218 return;
219 }
220
221 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
222}
223
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900224/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900225 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900226 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900227void
228ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900229{
230 struct ivi_layout *layout = get_instance();
231
232 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900233 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900234 return;
235 }
236
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900237 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900238 wl_list_remove(&ivisurf->pending.link);
239 wl_list_remove(&ivisurf->order.link);
240 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900241
242 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
243
244 remove_configured_listener(ivisurf);
245
246 ivi_layout_surface_remove_notification(ivisurf);
247
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900248 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900249}
250
251/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900252 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
253 * Called by ivi_layout_init_with_compositor.
254 */
255static void
256create_screen(struct weston_compositor *ec)
257{
258 struct ivi_layout *layout = get_instance();
259 struct ivi_layout_screen *iviscrn = NULL;
260 struct weston_output *output = NULL;
261 int32_t count = 0;
262
263 wl_list_for_each(output, &ec->output_list, link) {
264 iviscrn = calloc(1, sizeof *iviscrn);
265 if (iviscrn == NULL) {
266 weston_log("fails to allocate memory\n");
267 continue;
268 }
269
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900270 iviscrn->layout = layout;
271
272 iviscrn->id_screen = count;
273 count++;
274
275 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900276
277 wl_list_init(&iviscrn->pending.layer_list);
278 wl_list_init(&iviscrn->pending.link);
279
280 wl_list_init(&iviscrn->order.layer_list);
281 wl_list_init(&iviscrn->order.link);
282
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900283 wl_list_insert(&layout->screen_list, &iviscrn->link);
284 }
285}
286
287/**
288 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
289 */
290static void
291init_layer_properties(struct ivi_layout_layer_properties *prop,
292 int32_t width, int32_t height)
293{
294 memset(prop, 0, sizeof *prop);
295 prop->opacity = wl_fixed_from_double(1.0);
296 prop->source_width = width;
297 prop->source_height = height;
298 prop->dest_width = width;
299 prop->dest_height = height;
300}
301
302static void
303init_surface_properties(struct ivi_layout_surface_properties *prop)
304{
305 memset(prop, 0, sizeof *prop);
306 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900307 /*
308 * FIXME: this shall be finxed by ivi-layout-transition.
309 */
310 prop->dest_width = 1;
311 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900312}
313
314/**
315 * Internal APIs to be called from ivi_layout_commit_changes.
316 */
317static void
318update_opacity(struct ivi_layout_layer *ivilayer,
319 struct ivi_layout_surface *ivisurf)
320{
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000321 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900322 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
323 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
324
325 if ((ivilayer->event_mask & IVI_NOTIFICATION_OPACITY) ||
326 (ivisurf->event_mask & IVI_NOTIFICATION_OPACITY)) {
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000327 tmpview = get_weston_view(ivisurf);
328 assert(tmpview != NULL);
329 tmpview->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900330 }
331}
332
333static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900334get_rotate_values(enum wl_output_transform orientation,
335 float *v_sin,
336 float *v_cos)
337{
338 switch (orientation) {
339 case WL_OUTPUT_TRANSFORM_90:
340 *v_sin = 1.0f;
341 *v_cos = 0.0f;
342 break;
343 case WL_OUTPUT_TRANSFORM_180:
344 *v_sin = 0.0f;
345 *v_cos = -1.0f;
346 break;
347 case WL_OUTPUT_TRANSFORM_270:
348 *v_sin = -1.0f;
349 *v_cos = 0.0f;
350 break;
351 case WL_OUTPUT_TRANSFORM_NORMAL:
352 default:
353 *v_sin = 0.0f;
354 *v_cos = 1.0f;
355 break;
356 }
357}
358
359static void
360get_scale(enum wl_output_transform orientation,
361 float dest_width,
362 float dest_height,
363 float source_width,
364 float source_height,
365 float *scale_x,
366 float *scale_y)
367{
368 switch (orientation) {
369 case WL_OUTPUT_TRANSFORM_90:
370 *scale_x = dest_width / source_height;
371 *scale_y = dest_height / source_width;
372 break;
373 case WL_OUTPUT_TRANSFORM_180:
374 *scale_x = dest_width / source_width;
375 *scale_y = dest_height / source_height;
376 break;
377 case WL_OUTPUT_TRANSFORM_270:
378 *scale_x = dest_width / source_height;
379 *scale_y = dest_height / source_width;
380 break;
381 case WL_OUTPUT_TRANSFORM_NORMAL:
382 default:
383 *scale_x = dest_width / source_width;
384 *scale_y = dest_height / source_height;
385 break;
386 }
387}
388
389static void
390calc_transformation_matrix(struct ivi_rectangle *source_rect,
391 struct ivi_rectangle *dest_rect,
392 enum wl_output_transform orientation,
393 struct weston_matrix *m)
394{
395 float source_center_x;
396 float source_center_y;
397 float vsin;
398 float vcos;
399 float scale_x;
400 float scale_y;
401 float translate_x;
402 float translate_y;
403
404 source_center_x = source_rect->x + source_rect->width * 0.5f;
405 source_center_y = source_rect->y + source_rect->height * 0.5f;
406 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
407
408 get_rotate_values(orientation, &vsin, &vcos);
409 weston_matrix_rotate_xy(m, vcos, vsin);
410
411 get_scale(orientation,
412 dest_rect->width,
413 dest_rect->height,
414 source_rect->width,
415 source_rect->height,
416 &scale_x,
417 &scale_y);
418 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
419
420 translate_x = dest_rect->width * 0.5f + dest_rect->x;
421 translate_y = dest_rect->height * 0.5f + dest_rect->y;
422 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
423}
424
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900425/*
426 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900427 */
428static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900429ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
430 const struct ivi_rectangle *rect2,
431 struct ivi_rectangle *rect_output)
432{
433 int32_t rect1_right = rect1->x + rect1->width;
434 int32_t rect1_bottom = rect1->y + rect1->height;
435 int32_t rect2_right = rect2->x + rect2->width;
436 int32_t rect2_bottom = rect2->y + rect2->height;
437
438 rect_output->x = max(rect1->x, rect2->x);
439 rect_output->y = max(rect1->y, rect2->y);
440 rect_output->width = rect1_right < rect2_right ?
441 rect1_right - rect_output->x :
442 rect2_right - rect_output->x;
443 rect_output->height = rect1_bottom < rect2_bottom ?
444 rect1_bottom - rect_output->y :
445 rect2_bottom - rect_output->y;
446
447 if (rect_output->width < 0 || rect_output->height < 0) {
448 rect_output->width = 0;
449 rect_output->height = 0;
450 }
451}
452
453/*
454 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
455 * and store the result in rect_output.
456 * The boundingbox must be given in the same coordinate space as rect_output.
457 * Additionally, there are the following restrictions on the matrix:
458 * - no projective transformations
459 * - no skew
460 * - only multiples of 90-degree rotations supported
461 *
462 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
463 * as a fail-safe with log.
464 */
465static void
466calc_inverse_matrix_transform(const struct weston_matrix *matrix,
467 const struct ivi_rectangle *rect_input,
468 const struct ivi_rectangle *boundingbox,
469 struct ivi_rectangle *rect_output)
470{
471 struct weston_matrix m;
472 struct weston_vector top_left;
473 struct weston_vector bottom_right;
474
475 assert(boundingbox != rect_output);
476
477 if (weston_matrix_invert(&m, matrix) < 0) {
478 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
479 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
480 rect_output->x = boundingbox->x;
481 rect_output->y = boundingbox->y;
482 rect_output->width = boundingbox->width;
483 rect_output->height = boundingbox->height;
484 }
485
486 /* The vectors and matrices involved will always produce f[3] == 1.0. */
487 top_left.f[0] = rect_input->x;
488 top_left.f[1] = rect_input->y;
489 top_left.f[2] = 0.0f;
490 top_left.f[3] = 1.0f;
491
492 bottom_right.f[0] = rect_input->x + rect_input->width;
493 bottom_right.f[1] = rect_input->y + rect_input->height;
494 bottom_right.f[2] = 0.0f;
495 bottom_right.f[3] = 1.0f;
496
497 weston_matrix_transform(&m, &top_left);
498 weston_matrix_transform(&m, &bottom_right);
499
500 if (top_left.f[0] < bottom_right.f[0]) {
501 rect_output->x = top_left.f[0];
502 rect_output->width = bottom_right.f[0] - rect_output->x;
503 } else {
504 rect_output->x = bottom_right.f[0];
505 rect_output->width = top_left.f[0] - rect_output->x;
506 }
507
508 if (top_left.f[1] < bottom_right.f[1]) {
509 rect_output->y = top_left.f[1];
510 rect_output->height = bottom_right.f[1] - rect_output->y;
511 } else {
512 rect_output->y = bottom_right.f[1];
513 rect_output->height = top_left.f[1] - rect_output->y;
514 }
515
516 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
517}
518
519/**
520 * This computes the whole transformation matrix:m from surface-local
521 * coordinates to global coordinates. It is assumed that
522 * weston_view::geometry.{x,y} are zero.
523 *
524 * Additionally, this computes the mask on surface-local coordinates as a
525 * ivi_rectangle. This can be set to weston_view_set_mask.
526 *
527 * The mask is computed by following steps
528 * - destination rectangle of layer is inversed to surface-local cooodinates
529 * by inversed matrix:m.
530 * - the area is intersected by intersected area between weston_surface and
531 * source rectangle of ivi_surface.
532 */
533static void
534calc_surface_to_global_matrix_and_mask_to_weston_surface(
535 struct ivi_layout_layer *ivilayer,
536 struct ivi_layout_surface *ivisurf,
537 struct weston_matrix *m,
538 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900539{
540 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
541 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900542 struct ivi_rectangle weston_surface_rect = { 0,
543 0,
544 ivisurf->surface->width,
545 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900546 struct ivi_rectangle surface_source_rect = { sp->source_x,
547 sp->source_y,
548 sp->source_width,
549 sp->source_height };
550 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
551 sp->dest_y,
552 sp->dest_width,
553 sp->dest_height };
554 struct ivi_rectangle layer_source_rect = { lp->source_x,
555 lp->source_y,
556 lp->source_width,
557 lp->source_height };
558 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
559 lp->dest_y,
560 lp->dest_width,
561 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900562 struct ivi_rectangle surface_result;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900563
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900564 /*
565 * the whole transformation matrix:m from surface-local
566 * coordinates to global coordinates, which is computed by
567 * two steps,
568 * - surface-local coordinates to layer-local coordinates
569 * - layer-local coordinates to global coordinates
570 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900571 calc_transformation_matrix(&surface_source_rect,
572 &surface_dest_rect,
573 sp->orientation, m);
574
575 calc_transformation_matrix(&layer_source_rect,
576 &layer_dest_rect,
577 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900578
579 /* this intersected ivi_rectangle would be used for masking
580 * weston_surface
581 */
582 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
583 &surface_result);
584
585 /* calc masking area of weston_surface from m */
586 calc_inverse_matrix_transform(m,
587 &layer_dest_rect,
588 &surface_result,
589 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900590}
591
592static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900593update_prop(struct ivi_layout_layer *ivilayer,
594 struct ivi_layout_surface *ivisurf)
595{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900596 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900597 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900598 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900599
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900600 if (!ivilayer->event_mask && !ivisurf->event_mask) {
601 return;
602 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900603
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900604 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900605
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000606 tmpview = get_weston_view(ivisurf);
607 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900608
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900609 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
610 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
611 can_calc = false;
612 }
613
614 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
615 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
616 can_calc = false;
617 }
618
619 if (can_calc) {
620 wl_list_remove(&ivisurf->transform.link);
621 weston_matrix_init(&ivisurf->transform.matrix);
622
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900623 calc_surface_to_global_matrix_and_mask_to_weston_surface(
624 ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900625
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000626 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
627 wl_list_insert(&tmpview->geometry.transformation_list,
628 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900629
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000630 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900631 }
632
633 ivisurf->update_count++;
634
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000635 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900636
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000637 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900638}
639
640static void
641commit_changes(struct ivi_layout *layout)
642{
643 struct ivi_layout_screen *iviscrn = NULL;
644 struct ivi_layout_layer *ivilayer = NULL;
645 struct ivi_layout_surface *ivisurf = NULL;
646
647 wl_list_for_each(iviscrn, &layout->screen_list, link) {
648 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
649 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
650 update_prop(ivilayer, ivisurf);
651 }
652 }
653 }
654}
655
656static void
657commit_surface_list(struct ivi_layout *layout)
658{
659 struct ivi_layout_surface *ivisurf = NULL;
660 int32_t dest_x = 0;
661 int32_t dest_y = 0;
662 int32_t dest_width = 0;
663 int32_t dest_height = 0;
664 int32_t configured = 0;
665
666 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300667 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900668 dest_x = ivisurf->prop.dest_x;
669 dest_y = ivisurf->prop.dest_y;
670 dest_width = ivisurf->prop.dest_width;
671 dest_height = ivisurf->prop.dest_height;
672
673 ivi_layout_transition_move_resize_view(ivisurf,
674 ivisurf->pending.prop.dest_x,
675 ivisurf->pending.prop.dest_y,
676 ivisurf->pending.prop.dest_width,
677 ivisurf->pending.prop.dest_height,
678 ivisurf->pending.prop.transition_duration);
679
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300680 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900681 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
682 } else {
683 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
684 }
685
686 ivisurf->prop = ivisurf->pending.prop;
687 ivisurf->prop.dest_x = dest_x;
688 ivisurf->prop.dest_y = dest_y;
689 ivisurf->prop.dest_width = dest_width;
690 ivisurf->prop.dest_height = dest_height;
691 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
692 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
693
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300694 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900695 dest_x = ivisurf->prop.dest_x;
696 dest_y = ivisurf->prop.dest_y;
697 dest_width = ivisurf->prop.dest_width;
698 dest_height = ivisurf->prop.dest_height;
699
700 ivi_layout_transition_move_resize_view(ivisurf,
701 ivisurf->pending.prop.dest_x,
702 ivisurf->pending.prop.dest_y,
703 ivisurf->pending.prop.dest_width,
704 ivisurf->pending.prop.dest_height,
705 ivisurf->pending.prop.transition_duration);
706
707 ivisurf->prop = ivisurf->pending.prop;
708 ivisurf->prop.dest_x = dest_x;
709 ivisurf->prop.dest_y = dest_y;
710 ivisurf->prop.dest_width = dest_width;
711 ivisurf->prop.dest_height = dest_height;
712
713 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
714 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
715
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300716 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900717 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300718 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900719 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
720 } else {
721 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
722 }
723
724 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
725 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
726 configured = 1;
727 }
728
729 ivisurf->prop = ivisurf->pending.prop;
730 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
731 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
732
733 if (configured && !is_surface_transition(ivisurf))
734 wl_signal_emit(&ivisurf->configured, ivisurf);
735 } else {
736 configured = 0;
737 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
738 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
739 configured = 1;
740 }
741
742 ivisurf->prop = ivisurf->pending.prop;
743 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
744 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
745
746 if (configured && !is_surface_transition(ivisurf))
747 wl_signal_emit(&ivisurf->configured, ivisurf);
748 }
749 }
750}
751
752static void
753commit_layer_list(struct ivi_layout *layout)
754{
755 struct ivi_layout_layer *ivilayer = NULL;
756 struct ivi_layout_surface *ivisurf = NULL;
757 struct ivi_layout_surface *next = NULL;
758
759 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300760 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900761 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 -0300762 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900763 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
764 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
765 NULL, NULL,
766 ivilayer->pending.prop.transition_duration);
767 }
768 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
769
770 ivilayer->prop = ivilayer->pending.prop;
771
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000772 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900773 continue;
774 }
775
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000776 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
777 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000778 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000779 wl_list_remove(&ivisurf->order.link);
780 wl_list_init(&ivisurf->order.link);
781 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900782 }
783
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000784 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900785
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000786 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900787 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000788 wl_list_remove(&ivisurf->order.link);
789 wl_list_insert(&ivilayer->order.surface_list,
790 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000791 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000792 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900793 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000794
795 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900796 }
797}
798
799static void
800commit_screen_list(struct ivi_layout *layout)
801{
802 struct ivi_layout_screen *iviscrn = NULL;
803 struct ivi_layout_layer *ivilayer = NULL;
804 struct ivi_layout_layer *next = NULL;
805 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000806 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900807
808 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000809 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900810 wl_list_for_each_safe(ivilayer, next,
811 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000812 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000813 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900814 wl_list_init(&ivilayer->order.link);
815 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
816 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900817
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000818 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900819
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900820 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
821 pending.link) {
822 wl_list_insert(&iviscrn->order.layer_list,
823 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000824 ivilayer->on_screen = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900825 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
826 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900827
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000828 iviscrn->order.dirty = 0;
829 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900830
831 /* Clear view list of layout ivi_layer */
832 wl_list_init(&layout->layout_layer.view_list.link);
833
834 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
835 if (ivilayer->prop.visibility == false)
836 continue;
837
838 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900839 if (ivisurf->prop.visibility == false)
840 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000841
842 tmpview = get_weston_view(ivisurf);
843 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900844
845 weston_layer_entry_insert(&layout->layout_layer.view_list,
846 &tmpview->layer_link);
847
848 ivisurf->surface->output = iviscrn->output;
849 }
850 }
851
852 break;
853 }
854}
855
856static void
857commit_transition(struct ivi_layout* layout)
858{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300859 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900860 return;
861 }
862
863 wl_list_insert_list(&layout->transitions->transition_list,
864 &layout->pending_transition_list);
865
866 wl_list_init(&layout->pending_transition_list);
867
868 wl_event_source_timer_update(layout->transitions->event_source, 1);
869}
870
871static void
872send_surface_prop(struct ivi_layout_surface *ivisurf)
873{
874 wl_signal_emit(&ivisurf->property_changed, ivisurf);
875 ivisurf->event_mask = 0;
876}
877
878static void
879send_layer_prop(struct ivi_layout_layer *ivilayer)
880{
881 wl_signal_emit(&ivilayer->property_changed, ivilayer);
882 ivilayer->event_mask = 0;
883}
884
885static void
886send_prop(struct ivi_layout *layout)
887{
888 struct ivi_layout_layer *ivilayer = NULL;
889 struct ivi_layout_surface *ivisurf = NULL;
890
891 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900892 if (ivilayer->event_mask)
893 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900894 }
895
896 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900897 if (ivisurf->event_mask)
898 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900899 }
900}
901
902static void
903clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
904{
905 struct ivi_layout_surface *surface_link = NULL;
906 struct ivi_layout_surface *surface_next = NULL;
907
908 wl_list_for_each_safe(surface_link, surface_next,
909 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000910 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900911 wl_list_init(&surface_link->pending.link);
912 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900913}
914
915static void
916clear_surface_order_list(struct ivi_layout_layer *ivilayer)
917{
918 struct ivi_layout_surface *surface_link = NULL;
919 struct ivi_layout_surface *surface_next = NULL;
920
921 wl_list_for_each_safe(surface_link, surface_next,
922 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000923 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900924 wl_list_init(&surface_link->order.link);
925 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900926}
927
928static void
929layer_created(struct wl_listener *listener, void *data)
930{
931 struct ivi_layout_layer *ivilayer = data;
932
933 struct listener_layout_notification *notification =
934 container_of(listener,
935 struct listener_layout_notification,
936 listener);
937
938 struct ivi_layout_notification_callback *created_callback =
939 notification->userdata;
940
941 ((layer_create_notification_func)created_callback->callback)
942 (ivilayer, created_callback->data);
943}
944
945static void
946layer_removed(struct wl_listener *listener, void *data)
947{
948 struct ivi_layout_layer *ivilayer = data;
949
950 struct listener_layout_notification *notification =
951 container_of(listener,
952 struct listener_layout_notification,
953 listener);
954
955 struct ivi_layout_notification_callback *removed_callback =
956 notification->userdata;
957
958 ((layer_remove_notification_func)removed_callback->callback)
959 (ivilayer, removed_callback->data);
960}
961
962static void
963layer_prop_changed(struct wl_listener *listener, void *data)
964{
965 struct ivi_layout_layer *ivilayer = data;
966
967 struct listener_layout_notification *layout_listener =
968 container_of(listener,
969 struct listener_layout_notification,
970 listener);
971
972 struct ivi_layout_notification_callback *prop_callback =
973 layout_listener->userdata;
974
975 ((layer_property_notification_func)prop_callback->callback)
976 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
977}
978
979static void
980surface_created(struct wl_listener *listener, void *data)
981{
982 struct ivi_layout_surface *ivisurface = data;
983
984 struct listener_layout_notification *notification =
985 container_of(listener,
986 struct listener_layout_notification,
987 listener);
988
989 struct ivi_layout_notification_callback *created_callback =
990 notification->userdata;
991
992 ((surface_create_notification_func)created_callback->callback)
993 (ivisurface, created_callback->data);
994}
995
996static void
997surface_removed(struct wl_listener *listener, void *data)
998{
999 struct ivi_layout_surface *ivisurface = data;
1000
1001 struct listener_layout_notification *notification =
1002 container_of(listener,
1003 struct listener_layout_notification,
1004 listener);
1005
1006 struct ivi_layout_notification_callback *removed_callback =
1007 notification->userdata;
1008
1009 ((surface_remove_notification_func)removed_callback->callback)
1010 (ivisurface, removed_callback->data);
1011}
1012
1013static void
1014surface_prop_changed(struct wl_listener *listener, void *data)
1015{
1016 struct ivi_layout_surface *ivisurf = data;
1017
1018 struct listener_layout_notification *layout_listener =
1019 container_of(listener,
1020 struct listener_layout_notification,
1021 listener);
1022
1023 struct ivi_layout_notification_callback *prop_callback =
1024 layout_listener->userdata;
1025
1026 ((surface_property_notification_func)prop_callback->callback)
1027 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1028
1029 ivisurf->event_mask = 0;
1030}
1031
1032static void
1033surface_configure_changed(struct wl_listener *listener,
1034 void *data)
1035{
1036 struct ivi_layout_surface *ivisurface = data;
1037
1038 struct listener_layout_notification *notification =
1039 container_of(listener,
1040 struct listener_layout_notification,
1041 listener);
1042
1043 struct ivi_layout_notification_callback *configure_changed_callback =
1044 notification->userdata;
1045
1046 ((surface_configure_notification_func)configure_changed_callback->callback)
1047 (ivisurface, configure_changed_callback->data);
1048}
1049
1050static int32_t
1051add_notification(struct wl_signal *signal,
1052 wl_notify_func_t callback,
1053 void *userdata)
1054{
1055 struct listener_layout_notification *notification = NULL;
1056
1057 notification = malloc(sizeof *notification);
1058 if (notification == NULL) {
1059 weston_log("fails to allocate memory\n");
1060 free(userdata);
1061 return IVI_FAILED;
1062 }
1063
1064 notification->listener.notify = callback;
1065 notification->userdata = userdata;
1066
1067 wl_signal_add(signal, &notification->listener);
1068
1069 return IVI_SUCCEEDED;
1070}
1071
1072static void
1073remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1074{
1075 struct wl_listener *listener = NULL;
1076 struct wl_listener *next = NULL;
1077
1078 wl_list_for_each_safe(listener, next, listener_list, link) {
1079 struct listener_layout_notification *notification =
1080 container_of(listener,
1081 struct listener_layout_notification,
1082 listener);
1083
1084 struct ivi_layout_notification_callback *notification_callback =
1085 notification->userdata;
1086
1087 if ((notification_callback->callback != callback) ||
1088 (notification_callback->data != userdata)) {
1089 continue;
1090 }
1091
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001092 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001093
1094 free(notification->userdata);
1095 free(notification);
1096 }
1097}
1098
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001099/**
1100 * Exported APIs of ivi-layout library are implemented from here.
1101 * Brief of APIs is described in ivi-layout-export.h.
1102 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001103static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001104ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1105 void *userdata)
1106{
1107 struct ivi_layout *layout = get_instance();
1108 struct ivi_layout_notification_callback *created_callback = NULL;
1109
1110 if (callback == NULL) {
1111 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1112 return IVI_FAILED;
1113 }
1114
1115 created_callback = malloc(sizeof *created_callback);
1116 if (created_callback == NULL) {
1117 weston_log("fails to allocate memory\n");
1118 return IVI_FAILED;
1119 }
1120
1121 created_callback->callback = callback;
1122 created_callback->data = userdata;
1123
1124 return add_notification(&layout->layer_notification.created,
1125 layer_created,
1126 created_callback);
1127}
1128
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001129static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001130ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1131 void *userdata)
1132{
1133 struct ivi_layout *layout = get_instance();
1134 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1135}
1136
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001137static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001138ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1139 void *userdata)
1140{
1141 struct ivi_layout *layout = get_instance();
1142 struct ivi_layout_notification_callback *removed_callback = NULL;
1143
1144 if (callback == NULL) {
1145 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1146 return IVI_FAILED;
1147 }
1148
1149 removed_callback = malloc(sizeof *removed_callback);
1150 if (removed_callback == NULL) {
1151 weston_log("fails to allocate memory\n");
1152 return IVI_FAILED;
1153 }
1154
1155 removed_callback->callback = callback;
1156 removed_callback->data = userdata;
1157 return add_notification(&layout->layer_notification.removed,
1158 layer_removed,
1159 removed_callback);
1160}
1161
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001162static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001163ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1164 void *userdata)
1165{
1166 struct ivi_layout *layout = get_instance();
1167 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1168}
1169
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001170static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001171ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1172 void *userdata)
1173{
1174 struct ivi_layout *layout = get_instance();
1175 struct ivi_layout_notification_callback *created_callback = NULL;
1176
1177 if (callback == NULL) {
1178 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1179 return IVI_FAILED;
1180 }
1181
1182 created_callback = malloc(sizeof *created_callback);
1183 if (created_callback == NULL) {
1184 weston_log("fails to allocate memory\n");
1185 return IVI_FAILED;
1186 }
1187
1188 created_callback->callback = callback;
1189 created_callback->data = userdata;
1190
1191 return add_notification(&layout->surface_notification.created,
1192 surface_created,
1193 created_callback);
1194}
1195
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001196static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001197ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1198 void *userdata)
1199{
1200 struct ivi_layout *layout = get_instance();
1201 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1202}
1203
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001204static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001205ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1206 void *userdata)
1207{
1208 struct ivi_layout *layout = get_instance();
1209 struct ivi_layout_notification_callback *removed_callback = NULL;
1210
1211 if (callback == NULL) {
1212 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1213 return IVI_FAILED;
1214 }
1215
1216 removed_callback = malloc(sizeof *removed_callback);
1217 if (removed_callback == NULL) {
1218 weston_log("fails to allocate memory\n");
1219 return IVI_FAILED;
1220 }
1221
1222 removed_callback->callback = callback;
1223 removed_callback->data = userdata;
1224
1225 return add_notification(&layout->surface_notification.removed,
1226 surface_removed,
1227 removed_callback);
1228}
1229
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001230static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001231ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1232 void *userdata)
1233{
1234 struct ivi_layout *layout = get_instance();
1235 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1236}
1237
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001238static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001239ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1240 void *userdata)
1241{
1242 struct ivi_layout *layout = get_instance();
1243 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1244 if (callback == NULL) {
1245 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1246 return IVI_FAILED;
1247 }
1248
1249 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1250 if (configure_changed_callback == NULL) {
1251 weston_log("fails to allocate memory\n");
1252 return IVI_FAILED;
1253 }
1254
1255 configure_changed_callback->callback = callback;
1256 configure_changed_callback->data = userdata;
1257
1258 return add_notification(&layout->surface_notification.configure_changed,
1259 surface_configure_changed,
1260 configure_changed_callback);
1261}
1262
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001263static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001264ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1265 void *userdata)
1266{
1267 struct ivi_layout *layout = get_instance();
1268 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1269}
1270
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001271uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001272ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1273{
1274 return ivisurf->id_surface;
1275}
1276
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001277static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001278ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1279{
1280 return ivilayer->id_layer;
1281}
1282
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001283static uint32_t
1284ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1285{
1286 return iviscrn->id_screen;
1287}
1288
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001289static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001290ivi_layout_get_layer_from_id(uint32_t id_layer)
1291{
1292 struct ivi_layout *layout = get_instance();
1293 struct ivi_layout_layer *ivilayer = NULL;
1294
1295 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1296 if (ivilayer->id_layer == id_layer) {
1297 return ivilayer;
1298 }
1299 }
1300
1301 return NULL;
1302}
1303
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001304struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001305ivi_layout_get_surface_from_id(uint32_t id_surface)
1306{
1307 struct ivi_layout *layout = get_instance();
1308 struct ivi_layout_surface *ivisurf = NULL;
1309
1310 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1311 if (ivisurf->id_surface == id_surface) {
1312 return ivisurf;
1313 }
1314 }
1315
1316 return NULL;
1317}
1318
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001319static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001320ivi_layout_get_screen_from_id(uint32_t id_screen)
1321{
1322 struct ivi_layout *layout = get_instance();
1323 struct ivi_layout_screen *iviscrn = NULL;
1324
1325 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Nobuhiko Tanibata3e710d12015-11-25 23:36:09 +09001326 if (iviscrn->id_screen == id_screen)
1327 return iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001328 }
1329
1330 return NULL;
1331}
1332
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001333static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001334ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1335 int32_t *pWidth, int32_t *pHeight)
1336{
1337 struct weston_output *output = NULL;
1338
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001339 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001340 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1341 return IVI_FAILED;
1342 }
1343
1344 output = iviscrn->output;
1345 *pWidth = output->current_mode->width;
1346 *pHeight = output->current_mode->height;
1347
1348 return IVI_SUCCEEDED;
1349}
1350
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001351static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001352ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1353 surface_property_notification_func callback,
1354 void *userdata)
1355{
1356 struct listener_layout_notification* notification = NULL;
1357 struct ivi_layout_notification_callback *prop_callback = NULL;
1358
1359 if (ivisurf == NULL || callback == NULL) {
1360 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1361 return IVI_FAILED;
1362 }
1363
1364 notification = malloc(sizeof *notification);
1365 if (notification == NULL) {
1366 weston_log("fails to allocate memory\n");
1367 return IVI_FAILED;
1368 }
1369
1370 prop_callback = malloc(sizeof *prop_callback);
1371 if (prop_callback == NULL) {
1372 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001373 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001374 return IVI_FAILED;
1375 }
1376
1377 prop_callback->callback = callback;
1378 prop_callback->data = userdata;
1379
1380 notification->listener.notify = surface_prop_changed;
1381 notification->userdata = prop_callback;
1382
1383 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1384
1385 return IVI_SUCCEEDED;
1386}
1387
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001388static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001389ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1390{
1391 if (ivilayer == NULL) {
1392 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1393 return NULL;
1394 }
1395
1396 return &ivilayer->prop;
1397}
1398
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001399static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001400ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1401{
1402 struct ivi_layout *layout = get_instance();
1403 struct ivi_layout_screen *iviscrn = NULL;
1404 int32_t length = 0;
1405 int32_t n = 0;
1406
1407 if (pLength == NULL || ppArray == NULL) {
1408 weston_log("ivi_layout_get_screens: invalid argument\n");
1409 return IVI_FAILED;
1410 }
1411
1412 length = wl_list_length(&layout->screen_list);
1413
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001414 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001415 /* the Array must be free by module which called this function */
1416 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1417 if (*ppArray == NULL) {
1418 weston_log("fails to allocate memory\n");
1419 return IVI_FAILED;
1420 }
1421
1422 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1423 (*ppArray)[n++] = iviscrn;
1424 }
1425 }
1426
1427 *pLength = length;
1428
1429 return IVI_SUCCEEDED;
1430}
1431
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001432static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001433ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1434 int32_t *pLength,
1435 struct ivi_layout_screen ***ppArray)
1436{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001437 int32_t length = 0;
1438 int32_t n = 0;
1439
1440 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1441 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1442 return IVI_FAILED;
1443 }
1444
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001445 if (ivilayer->on_screen != NULL)
1446 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001447
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001448 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001449 /* the Array must be free by module which called this function */
1450 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1451 if (*ppArray == NULL) {
1452 weston_log("fails to allocate memory\n");
1453 return IVI_FAILED;
1454 }
1455
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001456 (*ppArray)[n++] = ivilayer->on_screen;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001457 }
1458
1459 *pLength = length;
1460
1461 return IVI_SUCCEEDED;
1462}
1463
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001464static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001465ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1466{
1467 struct ivi_layout *layout = get_instance();
1468 struct ivi_layout_layer *ivilayer = NULL;
1469 int32_t length = 0;
1470 int32_t n = 0;
1471
1472 if (pLength == NULL || ppArray == NULL) {
1473 weston_log("ivi_layout_get_layers: invalid argument\n");
1474 return IVI_FAILED;
1475 }
1476
1477 length = wl_list_length(&layout->layer_list);
1478
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001479 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001480 /* the Array must be free by module which called this function */
1481 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1482 if (*ppArray == NULL) {
1483 weston_log("fails to allocate memory\n");
1484 return IVI_FAILED;
1485 }
1486
1487 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1488 (*ppArray)[n++] = ivilayer;
1489 }
1490 }
1491
1492 *pLength = length;
1493
1494 return IVI_SUCCEEDED;
1495}
1496
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001497static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001498ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1499 int32_t *pLength,
1500 struct ivi_layout_layer ***ppArray)
1501{
1502 struct ivi_layout_layer *ivilayer = NULL;
1503 int32_t length = 0;
1504 int32_t n = 0;
1505
1506 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1507 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1508 return IVI_FAILED;
1509 }
1510
1511 length = wl_list_length(&iviscrn->order.layer_list);
1512
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001513 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001514 /* the Array must be free by module which called this function */
1515 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1516 if (*ppArray == NULL) {
1517 weston_log("fails to allocate memory\n");
1518 return IVI_FAILED;
1519 }
1520
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001521 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001522 (*ppArray)[n++] = ivilayer;
1523 }
1524 }
1525
1526 *pLength = length;
1527
1528 return IVI_SUCCEEDED;
1529}
1530
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001531static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001532ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1533 int32_t *pLength,
1534 struct ivi_layout_layer ***ppArray)
1535{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001536 int32_t length = 0;
1537 int32_t n = 0;
1538
1539 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1540 weston_log("ivi_layout_getLayers: invalid argument\n");
1541 return IVI_FAILED;
1542 }
1543
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001544 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001545 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001546 length = 1;
1547 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001548 if (*ppArray == NULL) {
1549 weston_log("fails to allocate memory\n");
1550 return IVI_FAILED;
1551 }
1552
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001553 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001554 }
1555
1556 *pLength = length;
1557
1558 return IVI_SUCCEEDED;
1559}
1560
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001561static
1562int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001563ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1564{
1565 struct ivi_layout *layout = get_instance();
1566 struct ivi_layout_surface *ivisurf = NULL;
1567 int32_t length = 0;
1568 int32_t n = 0;
1569
1570 if (pLength == NULL || ppArray == NULL) {
1571 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1572 return IVI_FAILED;
1573 }
1574
1575 length = wl_list_length(&layout->surface_list);
1576
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001577 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001578 /* the Array must be free by module which called this function */
1579 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1580 if (*ppArray == NULL) {
1581 weston_log("fails to allocate memory\n");
1582 return IVI_FAILED;
1583 }
1584
1585 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1586 (*ppArray)[n++] = ivisurf;
1587 }
1588 }
1589
1590 *pLength = length;
1591
1592 return IVI_SUCCEEDED;
1593}
1594
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001595static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001596ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1597 int32_t *pLength,
1598 struct ivi_layout_surface ***ppArray)
1599{
1600 struct ivi_layout_surface *ivisurf = NULL;
1601 int32_t length = 0;
1602 int32_t n = 0;
1603
1604 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1605 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1606 return IVI_FAILED;
1607 }
1608
1609 length = wl_list_length(&ivilayer->order.surface_list);
1610
1611 if (length != 0) {
1612 /* the Array must be free by module which called this function */
1613 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1614 if (*ppArray == NULL) {
1615 weston_log("fails to allocate memory\n");
1616 return IVI_FAILED;
1617 }
1618
1619 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1620 (*ppArray)[n++] = ivisurf;
1621 }
1622 }
1623
1624 *pLength = length;
1625
1626 return IVI_SUCCEEDED;
1627}
1628
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001629static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001630ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1631 int32_t width, int32_t height)
1632{
1633 struct ivi_layout *layout = get_instance();
1634 struct ivi_layout_layer *ivilayer = NULL;
1635
1636 ivilayer = get_layer(&layout->layer_list, id_layer);
1637 if (ivilayer != NULL) {
1638 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001639 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001640 return ivilayer;
1641 }
1642
1643 ivilayer = calloc(1, sizeof *ivilayer);
1644 if (ivilayer == NULL) {
1645 weston_log("fails to allocate memory\n");
1646 return NULL;
1647 }
1648
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001649 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001650 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001651 ivilayer->layout = layout;
1652 ivilayer->id_layer = id_layer;
1653
1654 init_layer_properties(&ivilayer->prop, width, height);
1655 ivilayer->event_mask = 0;
1656
1657 wl_list_init(&ivilayer->pending.surface_list);
1658 wl_list_init(&ivilayer->pending.link);
1659 ivilayer->pending.prop = ivilayer->prop;
1660
1661 wl_list_init(&ivilayer->order.surface_list);
1662 wl_list_init(&ivilayer->order.link);
1663
1664 wl_list_insert(&layout->layer_list, &ivilayer->link);
1665
1666 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1667
1668 return ivilayer;
1669}
1670
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001671static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001672ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1673{
1674 if (ivilayer == NULL) {
1675 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1676 return;
1677 }
1678
1679 remove_all_notification(&ivilayer->property_changed.listener_list);
1680}
1681
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001682static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001683ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1684 layer_property_notification_func callback,
1685 void *userdata)
1686{
1687 if (ivilayer == NULL) {
1688 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1689 return;
1690 }
1691
1692 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1693}
1694
1695static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001696ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001697{
1698 struct ivi_layout *layout = get_instance();
1699
1700 if (ivilayer == NULL) {
1701 weston_log("ivi_layout_layer_remove: invalid argument\n");
1702 return;
1703 }
1704
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001705 if (--ivilayer->ref_count > 0)
1706 return;
1707
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001708 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1709
1710 clear_surface_pending_list(ivilayer);
1711 clear_surface_order_list(ivilayer);
1712
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001713 wl_list_remove(&ivilayer->pending.link);
1714 wl_list_remove(&ivilayer->order.link);
1715 wl_list_remove(&ivilayer->link);
1716
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001717 ivi_layout_layer_remove_notification(ivilayer);
1718
1719 free(ivilayer);
1720}
1721
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001722int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001723ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1724 bool newVisibility)
1725{
1726 struct ivi_layout_layer_properties *prop = NULL;
1727
1728 if (ivilayer == NULL) {
1729 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1730 return IVI_FAILED;
1731 }
1732
1733 prop = &ivilayer->pending.prop;
1734 prop->visibility = newVisibility;
1735
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001736 if (ivilayer->prop.visibility != newVisibility)
1737 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1738 else
1739 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001740
1741 return IVI_SUCCEEDED;
1742}
1743
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001744static bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001745ivi_layout_layer_get_visibility(struct ivi_layout_layer *ivilayer)
1746{
1747 if (ivilayer == NULL) {
1748 weston_log("ivi_layout_layer_get_visibility: invalid argument\n");
1749 return false;
1750 }
1751
1752 return ivilayer->prop.visibility;
1753}
1754
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001755int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001756ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1757 wl_fixed_t opacity)
1758{
1759 struct ivi_layout_layer_properties *prop = NULL;
1760
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001761 if (ivilayer == NULL ||
1762 opacity < wl_fixed_from_double(0.0) ||
1763 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001764 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1765 return IVI_FAILED;
1766 }
1767
1768 prop = &ivilayer->pending.prop;
1769 prop->opacity = opacity;
1770
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001771 if (ivilayer->prop.opacity != opacity)
1772 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1773 else
1774 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001775
1776 return IVI_SUCCEEDED;
1777}
1778
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001779wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001780ivi_layout_layer_get_opacity(struct ivi_layout_layer *ivilayer)
1781{
1782 if (ivilayer == NULL) {
1783 weston_log("ivi_layout_layer_get_opacity: invalid argument\n");
1784 return wl_fixed_from_double(0.0);
1785 }
1786
1787 return ivilayer->prop.opacity;
1788}
1789
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001790static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001791ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1792 int32_t x, int32_t y,
1793 int32_t width, int32_t height)
1794{
1795 struct ivi_layout_layer_properties *prop = NULL;
1796
1797 if (ivilayer == NULL) {
1798 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1799 return IVI_FAILED;
1800 }
1801
1802 prop = &ivilayer->pending.prop;
1803 prop->source_x = x;
1804 prop->source_y = y;
1805 prop->source_width = width;
1806 prop->source_height = height;
1807
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001808 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1809 ivilayer->prop.source_width != width ||
1810 ivilayer->prop.source_height != height)
1811 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1812 else
1813 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001814
1815 return IVI_SUCCEEDED;
1816}
1817
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001818static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001819ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1820 int32_t x, int32_t y,
1821 int32_t width, int32_t height)
1822{
1823 struct ivi_layout_layer_properties *prop = NULL;
1824
1825 if (ivilayer == NULL) {
1826 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1827 return IVI_FAILED;
1828 }
1829
1830 prop = &ivilayer->pending.prop;
1831 prop->dest_x = x;
1832 prop->dest_y = y;
1833 prop->dest_width = width;
1834 prop->dest_height = height;
1835
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001836 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1837 ivilayer->prop.dest_width != width ||
1838 ivilayer->prop.dest_height != height)
1839 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1840 else
1841 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001842
1843 return IVI_SUCCEEDED;
1844}
1845
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001846static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001847ivi_layout_layer_get_dimension(struct ivi_layout_layer *ivilayer,
1848 int32_t *dest_width, int32_t *dest_height)
1849{
1850 if (ivilayer == NULL || dest_width == NULL || dest_height == NULL) {
1851 weston_log("ivi_layout_layer_get_dimension: invalid argument\n");
1852 return IVI_FAILED;
1853 }
1854
1855 *dest_width = ivilayer->prop.dest_width;
1856 *dest_height = ivilayer->prop.dest_height;
1857
1858 return IVI_SUCCEEDED;
1859}
1860
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001861static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001862ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
1863 int32_t dest_width, int32_t dest_height)
1864{
1865 struct ivi_layout_layer_properties *prop = NULL;
1866
1867 if (ivilayer == NULL) {
1868 weston_log("ivi_layout_layer_set_dimension: invalid argument\n");
1869 return IVI_FAILED;
1870 }
1871
1872 prop = &ivilayer->pending.prop;
1873
1874 prop->dest_width = dest_width;
1875 prop->dest_height = dest_height;
1876
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001877 if (ivilayer->prop.dest_width != dest_width ||
1878 ivilayer->prop.dest_height != dest_height)
1879 ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
1880 else
1881 ivilayer->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001882
1883 return IVI_SUCCEEDED;
1884}
1885
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001886int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001887ivi_layout_layer_get_position(struct ivi_layout_layer *ivilayer,
1888 int32_t *dest_x, int32_t *dest_y)
1889{
1890 if (ivilayer == NULL || dest_x == NULL || dest_y == NULL) {
1891 weston_log("ivi_layout_layer_get_position: invalid argument\n");
1892 return IVI_FAILED;
1893 }
1894
1895 *dest_x = ivilayer->prop.dest_x;
1896 *dest_y = ivilayer->prop.dest_y;
1897
1898 return IVI_SUCCEEDED;
1899}
1900
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001901int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001902ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
1903 int32_t dest_x, int32_t dest_y)
1904{
1905 struct ivi_layout_layer_properties *prop = NULL;
1906
1907 if (ivilayer == NULL) {
1908 weston_log("ivi_layout_layer_set_position: invalid argument\n");
1909 return IVI_FAILED;
1910 }
1911
1912 prop = &ivilayer->pending.prop;
1913 prop->dest_x = dest_x;
1914 prop->dest_y = dest_y;
1915
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001916 if (ivilayer->prop.dest_x != dest_x || ivilayer->prop.dest_y != dest_y)
1917 ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
1918 else
1919 ivilayer->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001920
1921 return IVI_SUCCEEDED;
1922}
1923
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001924static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001925ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1926 enum wl_output_transform orientation)
1927{
1928 struct ivi_layout_layer_properties *prop = NULL;
1929
1930 if (ivilayer == NULL) {
1931 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1932 return IVI_FAILED;
1933 }
1934
1935 prop = &ivilayer->pending.prop;
1936 prop->orientation = orientation;
1937
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001938 if (ivilayer->prop.orientation != orientation)
1939 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1940 else
1941 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001942
1943 return IVI_SUCCEEDED;
1944}
1945
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001946static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001947ivi_layout_layer_get_orientation(struct ivi_layout_layer *ivilayer)
1948{
1949 if (ivilayer == NULL) {
1950 weston_log("ivi_layout_layer_get_orientation: invalid argument\n");
1951 return 0;
1952 }
1953
1954 return ivilayer->prop.orientation;
1955}
1956
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001957int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001958ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1959 struct ivi_layout_surface **pSurface,
1960 int32_t number)
1961{
1962 struct ivi_layout *layout = get_instance();
1963 struct ivi_layout_surface *ivisurf = NULL;
1964 struct ivi_layout_surface *next = NULL;
1965 uint32_t *id_surface = NULL;
1966 int32_t i = 0;
1967
1968 if (ivilayer == NULL) {
1969 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1970 return IVI_FAILED;
1971 }
1972
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001973 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001974
1975 for (i = 0; i < number; i++) {
1976 id_surface = &pSurface[i]->id_surface;
1977
1978 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
1979 if (*id_surface != ivisurf->id_surface) {
1980 continue;
1981 }
1982
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001983 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001984 wl_list_insert(&ivilayer->pending.surface_list,
1985 &ivisurf->pending.link);
1986 break;
1987 }
1988 }
1989
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001990 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001991
1992 return IVI_SUCCEEDED;
1993}
1994
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001995int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001996ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1997 bool newVisibility)
1998{
1999 struct ivi_layout_surface_properties *prop = NULL;
2000
2001 if (ivisurf == NULL) {
2002 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
2003 return IVI_FAILED;
2004 }
2005
2006 prop = &ivisurf->pending.prop;
2007 prop->visibility = newVisibility;
2008
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002009 if (ivisurf->prop.visibility != newVisibility)
2010 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
2011 else
2012 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002013
2014 return IVI_SUCCEEDED;
2015}
2016
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002017bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002018ivi_layout_surface_get_visibility(struct ivi_layout_surface *ivisurf)
2019{
2020 if (ivisurf == NULL) {
2021 weston_log("ivi_layout_surface_get_visibility: invalid argument\n");
2022 return false;
2023 }
2024
2025 return ivisurf->prop.visibility;
2026}
2027
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002028int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002029ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
2030 wl_fixed_t opacity)
2031{
2032 struct ivi_layout_surface_properties *prop = NULL;
2033
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09002034 if (ivisurf == NULL ||
2035 opacity < wl_fixed_from_double(0.0) ||
2036 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002037 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
2038 return IVI_FAILED;
2039 }
2040
2041 prop = &ivisurf->pending.prop;
2042 prop->opacity = opacity;
2043
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002044 if (ivisurf->prop.opacity != opacity)
2045 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
2046 else
2047 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002048
2049 return IVI_SUCCEEDED;
2050}
2051
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002052wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002053ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
2054{
2055 if (ivisurf == NULL) {
2056 weston_log("ivi_layout_surface_get_opacity: invalid argument\n");
2057 return wl_fixed_from_double(0.0);
2058 }
2059
2060 return ivisurf->prop.opacity;
2061}
2062
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002063int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002064ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
2065 int32_t x, int32_t y,
2066 int32_t width, int32_t height)
2067{
2068 struct ivi_layout_surface_properties *prop = NULL;
2069
2070 if (ivisurf == NULL) {
2071 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
2072 return IVI_FAILED;
2073 }
2074
2075 prop = &ivisurf->pending.prop;
2076 prop->start_x = prop->dest_x;
2077 prop->start_y = prop->dest_y;
2078 prop->dest_x = x;
2079 prop->dest_y = y;
2080 prop->start_width = prop->dest_width;
2081 prop->start_height = prop->dest_height;
2082 prop->dest_width = width;
2083 prop->dest_height = height;
2084
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002085 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2086 ivisurf->prop.dest_width != width ||
2087 ivisurf->prop.dest_height != height)
2088 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2089 else
2090 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002091
2092 return IVI_SUCCEEDED;
2093}
2094
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002095static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002096ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
2097 int32_t dest_width, int32_t dest_height)
2098{
2099 struct ivi_layout_surface_properties *prop = NULL;
2100
2101 if (ivisurf == NULL) {
2102 weston_log("ivi_layout_surface_set_dimension: invalid argument\n");
2103 return IVI_FAILED;
2104 }
2105
2106 prop = &ivisurf->pending.prop;
2107 prop->dest_width = dest_width;
2108 prop->dest_height = dest_height;
2109
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002110 if (ivisurf->prop.dest_width != dest_width ||
2111 ivisurf->prop.dest_height != dest_height)
2112 ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
2113 else
2114 ivisurf->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002115
2116 return IVI_SUCCEEDED;
2117}
2118
2119int32_t
2120ivi_layout_surface_get_dimension(struct ivi_layout_surface *ivisurf,
2121 int32_t *dest_width, int32_t *dest_height)
2122{
2123 if (ivisurf == NULL || dest_width == NULL || dest_height == NULL) {
2124 weston_log("ivi_layout_surface_get_dimension: invalid argument\n");
2125 return IVI_FAILED;
2126 }
2127
2128 *dest_width = ivisurf->prop.dest_width;
2129 *dest_height = ivisurf->prop.dest_height;
2130
2131 return IVI_SUCCEEDED;
2132}
2133
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002134static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002135ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
2136 int32_t dest_x, int32_t dest_y)
2137{
2138 struct ivi_layout_surface_properties *prop = NULL;
2139
2140 if (ivisurf == NULL) {
2141 weston_log("ivi_layout_surface_set_position: invalid argument\n");
2142 return IVI_FAILED;
2143 }
2144
2145 prop = &ivisurf->pending.prop;
2146 prop->dest_x = dest_x;
2147 prop->dest_y = dest_y;
2148
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002149 if (ivisurf->prop.dest_x != dest_x || ivisurf->prop.dest_y != dest_y)
2150 ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
2151 else
2152 ivisurf->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002153
2154 return IVI_SUCCEEDED;
2155}
2156
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002157static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002158ivi_layout_surface_get_position(struct ivi_layout_surface *ivisurf,
2159 int32_t *dest_x, int32_t *dest_y)
2160{
2161 if (ivisurf == NULL || dest_x == NULL || dest_y == NULL) {
2162 weston_log("ivi_layout_surface_get_position: invalid argument\n");
2163 return IVI_FAILED;
2164 }
2165
2166 *dest_x = ivisurf->prop.dest_x;
2167 *dest_y = ivisurf->prop.dest_y;
2168
2169 return IVI_SUCCEEDED;
2170}
2171
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002172static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002173ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2174 enum wl_output_transform orientation)
2175{
2176 struct ivi_layout_surface_properties *prop = NULL;
2177
2178 if (ivisurf == NULL) {
2179 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2180 return IVI_FAILED;
2181 }
2182
2183 prop = &ivisurf->pending.prop;
2184 prop->orientation = orientation;
2185
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002186 if (ivisurf->prop.orientation != orientation)
2187 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2188 else
2189 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002190
2191 return IVI_SUCCEEDED;
2192}
2193
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002194static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002195ivi_layout_surface_get_orientation(struct ivi_layout_surface *ivisurf)
2196{
2197 if (ivisurf == NULL) {
2198 weston_log("ivi_layout_surface_get_orientation: invalid argument\n");
2199 return 0;
2200 }
2201
2202 return ivisurf->prop.orientation;
2203}
2204
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002205static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002206ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2207 struct ivi_layout_layer *addlayer)
2208{
2209 struct ivi_layout *layout = get_instance();
2210 struct ivi_layout_layer *ivilayer = NULL;
2211 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002212
2213 if (iviscrn == NULL || addlayer == NULL) {
2214 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2215 return IVI_FAILED;
2216 }
2217
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00002218 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002219 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2220 return IVI_SUCCEEDED;
2221 }
2222
2223 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2224 if (ivilayer->id_layer == addlayer->id_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002225 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002226 wl_list_insert(&iviscrn->pending.layer_list,
2227 &ivilayer->pending.link);
2228 break;
2229 }
2230 }
2231
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002232 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002233
2234 return IVI_SUCCEEDED;
2235}
2236
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002237static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002238ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2239 struct ivi_layout_layer **pLayer,
2240 const int32_t number)
2241{
2242 struct ivi_layout *layout = get_instance();
2243 struct ivi_layout_layer *ivilayer = NULL;
2244 struct ivi_layout_layer *next = NULL;
2245 uint32_t *id_layer = NULL;
2246 int32_t i = 0;
2247
2248 if (iviscrn == NULL) {
2249 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2250 return IVI_FAILED;
2251 }
2252
2253 wl_list_for_each_safe(ivilayer, next,
2254 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002255 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002256 wl_list_init(&ivilayer->pending.link);
2257 }
2258
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002259 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002260
2261 for (i = 0; i < number; i++) {
2262 id_layer = &pLayer[i]->id_layer;
2263 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2264 if (*id_layer != ivilayer->id_layer) {
2265 continue;
2266 }
2267
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002268 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002269 wl_list_insert(&iviscrn->pending.layer_list,
2270 &ivilayer->pending.link);
2271 break;
2272 }
2273 }
2274
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002275 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002276
2277 return IVI_SUCCEEDED;
2278}
2279
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002280static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002281ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2282{
2283 return iviscrn->output;
2284}
2285
2286/**
2287 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2288 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2289 * This function is used to get the result of drawing by clients.
2290 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002291static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002292ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2293{
2294 return ivisurf != NULL ? ivisurf->surface : NULL;
2295}
2296
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002297static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002298ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2299 int32_t *width, int32_t *height,
2300 int32_t *stride)
2301{
2302 int32_t w;
2303 int32_t h;
2304 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2305
2306 if (ivisurf == NULL || ivisurf->surface == NULL) {
2307 weston_log("%s: invalid argument\n", __func__);
2308 return IVI_FAILED;
2309 }
2310
2311 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2312
2313 if (width != NULL)
2314 *width = w;
2315
2316 if (height != NULL)
2317 *height = h;
2318
2319 if (stride != NULL)
2320 *stride = w * bytespp;
2321
2322 return IVI_SUCCEEDED;
2323}
2324
2325static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002326ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2327 layer_property_notification_func callback,
2328 void *userdata)
2329{
2330 struct ivi_layout_notification_callback *prop_callback = NULL;
2331
2332 if (ivilayer == NULL || callback == NULL) {
2333 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2334 return IVI_FAILED;
2335 }
2336
2337 prop_callback = malloc(sizeof *prop_callback);
2338 if (prop_callback == NULL) {
2339 weston_log("fails to allocate memory\n");
2340 return IVI_FAILED;
2341 }
2342
2343 prop_callback->callback = callback;
2344 prop_callback->data = userdata;
2345
2346 return add_notification(&ivilayer->property_changed,
2347 layer_prop_changed,
2348 prop_callback);
2349}
2350
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002351static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002352ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2353{
2354 if (ivisurf == NULL) {
2355 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2356 return NULL;
2357 }
2358
2359 return &ivisurf->prop;
2360}
2361
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002362static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002363ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2364 struct ivi_layout_surface *addsurf)
2365{
2366 struct ivi_layout *layout = get_instance();
2367 struct ivi_layout_surface *ivisurf = NULL;
2368 struct ivi_layout_surface *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002369
2370 if (ivilayer == NULL || addsurf == NULL) {
2371 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2372 return IVI_FAILED;
2373 }
2374
Ucan, Emre (ADITG/SW1)4a183642015-08-28 12:59:04 +00002375 if (addsurf->on_layer == ivilayer) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002376 weston_log("ivi_layout_layer_add_surface: addsurf is already available\n");
2377 return IVI_SUCCEEDED;
2378 }
2379
2380 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2381 if (ivisurf->id_surface == addsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002382 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002383 wl_list_insert(&ivilayer->pending.surface_list,
2384 &ivisurf->pending.link);
2385 break;
2386 }
2387 }
2388
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002389 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002390
2391 return IVI_SUCCEEDED;
2392}
2393
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002394static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002395ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2396 struct ivi_layout_surface *remsurf)
2397{
2398 struct ivi_layout_surface *ivisurf = NULL;
2399 struct ivi_layout_surface *next = NULL;
2400
2401 if (ivilayer == NULL || remsurf == NULL) {
2402 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2403 return;
2404 }
2405
2406 wl_list_for_each_safe(ivisurf, next,
2407 &ivilayer->pending.surface_list, pending.link) {
2408 if (ivisurf->id_surface == remsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002409 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002410 wl_list_init(&ivisurf->pending.link);
2411 break;
2412 }
2413 }
2414
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002415 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002416}
2417
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002418static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002419ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2420 int32_t x, int32_t y,
2421 int32_t width, int32_t height)
2422{
2423 struct ivi_layout_surface_properties *prop = NULL;
2424
2425 if (ivisurf == NULL) {
2426 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2427 return IVI_FAILED;
2428 }
2429
2430 prop = &ivisurf->pending.prop;
2431 prop->source_x = x;
2432 prop->source_y = y;
2433 prop->source_width = width;
2434 prop->source_height = height;
2435
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002436 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2437 ivisurf->prop.source_width != width ||
2438 ivisurf->prop.source_height != height)
2439 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2440 else
2441 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002442
2443 return IVI_SUCCEEDED;
2444}
2445
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002446int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002447ivi_layout_commit_changes(void)
2448{
2449 struct ivi_layout *layout = get_instance();
2450
2451 commit_surface_list(layout);
2452 commit_layer_list(layout);
2453 commit_screen_list(layout);
2454
2455 commit_transition(layout);
2456
2457 commit_changes(layout);
2458 send_prop(layout);
2459 weston_compositor_schedule_repaint(layout->compositor);
2460
2461 return IVI_SUCCEEDED;
2462}
2463
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002464static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002465ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2466 enum ivi_layout_transition_type type,
2467 uint32_t duration)
2468{
2469 if (ivilayer == NULL) {
2470 weston_log("%s: invalid argument\n", __func__);
2471 return -1;
2472 }
2473
2474 ivilayer->pending.prop.transition_type = type;
2475 ivilayer->pending.prop.transition_duration = duration;
2476
2477 return 0;
2478}
2479
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002480static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002481ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2482 uint32_t is_fade_in,
2483 double start_alpha, double end_alpha)
2484{
2485 if (ivilayer == NULL) {
2486 weston_log("%s: invalid argument\n", __func__);
2487 return -1;
2488 }
2489
2490 ivilayer->pending.prop.is_fade_in = is_fade_in;
2491 ivilayer->pending.prop.start_alpha = start_alpha;
2492 ivilayer->pending.prop.end_alpha = end_alpha;
2493
2494 return 0;
2495}
2496
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002497static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002498ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2499 uint32_t duration)
2500{
2501 struct ivi_layout_surface_properties *prop;
2502
2503 if (ivisurf == NULL) {
2504 weston_log("%s: invalid argument\n", __func__);
2505 return -1;
2506 }
2507
2508 prop = &ivisurf->pending.prop;
2509 prop->transition_duration = duration*10;
2510 return 0;
2511}
2512
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002513static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002514ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2515 enum ivi_layout_transition_type type,
2516 uint32_t duration)
2517{
2518 struct ivi_layout_surface_properties *prop;
2519
2520 if (ivisurf == NULL) {
2521 weston_log("%s: invalid argument\n", __func__);
2522 return -1;
2523 }
2524
2525 prop = &ivisurf->pending.prop;
2526 prop->transition_type = type;
2527 prop->transition_duration = duration;
2528 return 0;
2529}
2530
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002531static int32_t
2532ivi_layout_surface_dump(struct weston_surface *surface,
2533 void *target, size_t size,int32_t x, int32_t y,
2534 int32_t width, int32_t height)
2535{
2536 int result = 0;
2537
2538 if (surface == NULL) {
2539 weston_log("%s: invalid argument\n", __func__);
2540 return IVI_FAILED;
2541 }
2542
2543 result = weston_surface_copy_content(
2544 surface, target, size,
2545 x, y, width, height);
2546
2547 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2548}
2549
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002550/**
2551 * methods of interaction between ivi-shell with ivi-layout
2552 */
2553struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002554ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2555{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002556 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002557 return NULL;
2558
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002559 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002560}
2561
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002562void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002563ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2564 int32_t width, int32_t height)
2565{
2566 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002567
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002568 /* emit callback which is set by ivi-layout api user */
2569 wl_signal_emit(&layout->surface_notification.configure_changed,
2570 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002571}
2572
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002573static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002574ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2575 ivi_controller_surface_content_callback callback,
2576 void* userdata)
2577{
2578 int32_t ret = IVI_FAILED;
2579
2580 if (ivisurf != NULL) {
2581 ivisurf->content_observer.callback = callback;
2582 ivisurf->content_observer.userdata = userdata;
2583 ret = IVI_SUCCEEDED;
2584 }
2585 return ret;
2586}
2587
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002588struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002589ivi_layout_surface_create(struct weston_surface *wl_surface,
2590 uint32_t id_surface)
2591{
2592 struct ivi_layout *layout = get_instance();
2593 struct ivi_layout_surface *ivisurf = NULL;
2594 struct weston_view *tmpview = NULL;
2595
2596 if (wl_surface == NULL) {
2597 weston_log("ivi_layout_surface_create: invalid argument\n");
2598 return NULL;
2599 }
2600
2601 ivisurf = get_surface(&layout->surface_list, id_surface);
2602 if (ivisurf != NULL) {
2603 if (ivisurf->surface != NULL) {
2604 weston_log("id_surface(%d) is already created\n", id_surface);
2605 return NULL;
2606 }
2607 }
2608
2609 ivisurf = calloc(1, sizeof *ivisurf);
2610 if (ivisurf == NULL) {
2611 weston_log("fails to allocate memory\n");
2612 return NULL;
2613 }
2614
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002615 wl_signal_init(&ivisurf->property_changed);
2616 wl_signal_init(&ivisurf->configured);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002617 ivisurf->id_surface = id_surface;
2618 ivisurf->layout = layout;
2619
2620 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002621
2622 tmpview = weston_view_create(wl_surface);
2623 if (tmpview == NULL) {
2624 weston_log("fails to allocate memory\n");
2625 }
2626
2627 ivisurf->surface->width_from_buffer = 0;
2628 ivisurf->surface->height_from_buffer = 0;
2629
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002630 weston_matrix_init(&ivisurf->transform.matrix);
2631 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002632
2633 init_surface_properties(&ivisurf->prop);
2634 ivisurf->event_mask = 0;
2635
2636 ivisurf->pending.prop = ivisurf->prop;
2637 wl_list_init(&ivisurf->pending.link);
2638
2639 wl_list_init(&ivisurf->order.link);
2640 wl_list_init(&ivisurf->order.layer_list);
2641
2642 wl_list_insert(&layout->surface_list, &ivisurf->link);
2643
2644 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2645
2646 return ivisurf;
2647}
2648
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002649void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002650ivi_layout_init_with_compositor(struct weston_compositor *ec)
2651{
2652 struct ivi_layout *layout = get_instance();
2653
2654 layout->compositor = ec;
2655
2656 wl_list_init(&layout->surface_list);
2657 wl_list_init(&layout->layer_list);
2658 wl_list_init(&layout->screen_list);
2659
2660 wl_signal_init(&layout->layer_notification.created);
2661 wl_signal_init(&layout->layer_notification.removed);
2662
2663 wl_signal_init(&layout->surface_notification.created);
2664 wl_signal_init(&layout->surface_notification.removed);
2665 wl_signal_init(&layout->surface_notification.configure_changed);
2666
2667 /* Add layout_layer at the last of weston_compositor.layer_list */
2668 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2669
2670 create_screen(ec);
2671
2672 layout->transitions = ivi_layout_transition_set_create(ec);
2673 wl_list_init(&layout->pending_transition_list);
2674}
2675
2676
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002677void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002678ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2679 struct wl_listener* listener)
2680{
2681 wl_signal_add(&ivisurf->configured, listener);
2682}
2683
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002684static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002685 /**
2686 * commit all changes
2687 */
2688 .commit_changes = ivi_layout_commit_changes,
2689
2690 /**
2691 * surface controller interfaces
2692 */
2693 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2694 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2695 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2696 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2697 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2698 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2699 .get_surfaces = ivi_layout_get_surfaces,
2700 .get_id_of_surface = ivi_layout_get_id_of_surface,
2701 .get_surface_from_id = ivi_layout_get_surface_from_id,
2702 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2703 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2704 .surface_set_visibility = ivi_layout_surface_set_visibility,
2705 .surface_get_visibility = ivi_layout_surface_get_visibility,
2706 .surface_set_opacity = ivi_layout_surface_set_opacity,
2707 .surface_get_opacity = ivi_layout_surface_get_opacity,
2708 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2709 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
2710 .surface_set_position = ivi_layout_surface_set_position,
2711 .surface_get_position = ivi_layout_surface_get_position,
2712 .surface_set_dimension = ivi_layout_surface_set_dimension,
2713 .surface_get_dimension = ivi_layout_surface_get_dimension,
2714 .surface_set_orientation = ivi_layout_surface_set_orientation,
2715 .surface_get_orientation = ivi_layout_surface_get_orientation,
2716 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2717 .surface_add_notification = ivi_layout_surface_add_notification,
2718 .surface_remove_notification = ivi_layout_surface_remove_notification,
2719 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2720 .surface_set_transition = ivi_layout_surface_set_transition,
2721 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2722
2723 /**
2724 * layer controller interfaces
2725 */
2726 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2727 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2728 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2729 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2730 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002731 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002732 .get_layers = ivi_layout_get_layers,
2733 .get_id_of_layer = ivi_layout_get_id_of_layer,
2734 .get_layer_from_id = ivi_layout_get_layer_from_id,
2735 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2736 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2737 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2738 .layer_set_visibility = ivi_layout_layer_set_visibility,
2739 .layer_get_visibility = ivi_layout_layer_get_visibility,
2740 .layer_set_opacity = ivi_layout_layer_set_opacity,
2741 .layer_get_opacity = ivi_layout_layer_get_opacity,
2742 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2743 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
2744 .layer_set_position = ivi_layout_layer_set_position,
2745 .layer_get_position = ivi_layout_layer_get_position,
2746 .layer_set_dimension = ivi_layout_layer_set_dimension,
2747 .layer_get_dimension = ivi_layout_layer_get_dimension,
2748 .layer_set_orientation = ivi_layout_layer_set_orientation,
2749 .layer_get_orientation = ivi_layout_layer_get_orientation,
2750 .layer_add_surface = ivi_layout_layer_add_surface,
2751 .layer_remove_surface = ivi_layout_layer_remove_surface,
2752 .layer_set_render_order = ivi_layout_layer_set_render_order,
2753 .layer_add_notification = ivi_layout_layer_add_notification,
2754 .layer_remove_notification = ivi_layout_layer_remove_notification,
2755 .layer_set_transition = ivi_layout_layer_set_transition,
2756
2757 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002758 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002759 */
2760 .get_screen_from_id = ivi_layout_get_screen_from_id,
2761 .get_screen_resolution = ivi_layout_get_screen_resolution,
2762 .get_screens = ivi_layout_get_screens,
2763 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2764 .screen_add_layer = ivi_layout_screen_add_layer,
2765 .screen_set_render_order = ivi_layout_screen_set_render_order,
2766 .screen_get_output = ivi_layout_screen_get_output,
2767
2768 /**
2769 * animation
2770 */
2771 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002772 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2773
2774 /**
2775 * surface content dumping for debugging
2776 */
2777 .surface_get_size = ivi_layout_surface_get_size,
2778 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002779
2780 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002781 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002782 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002783 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002784 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2785
2786 /**
2787 * screen controller interfaces part2
2788 */
2789 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002790};
2791
2792int
2793load_controller_modules(struct weston_compositor *compositor, const char *modules,
2794 int *argc, char *argv[])
2795{
2796 const char *p, *end;
2797 char buffer[256];
2798 int (*controller_module_init)(struct weston_compositor *compositor,
2799 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002800 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002801 size_t interface_version);
2802
2803 if (modules == NULL)
2804 return 0;
2805
2806 p = modules;
2807 while (*p) {
2808 end = strchrnul(p, ',');
2809 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2810
2811 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002812 if (!controller_module_init)
2813 return -1;
2814
2815 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002816 &ivi_layout_interface,
2817 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002818 weston_log("ivi-shell: Initialization of controller module fails");
2819 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002820 }
2821
2822 p = end;
2823 while (*p == ',')
2824 p++;
2825 }
2826
2827 return 0;
2828}