blob: c6d4b90bd66be20de5c931dcdaa9e5cd845545ae [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) {
1326/* FIXME : select iviscrn from screen_list by id_screen */
1327 return iviscrn;
1328 break;
1329 }
1330
1331 return NULL;
1332}
1333
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001334static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001335ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1336 int32_t *pWidth, int32_t *pHeight)
1337{
1338 struct weston_output *output = NULL;
1339
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001340 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001341 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1342 return IVI_FAILED;
1343 }
1344
1345 output = iviscrn->output;
1346 *pWidth = output->current_mode->width;
1347 *pHeight = output->current_mode->height;
1348
1349 return IVI_SUCCEEDED;
1350}
1351
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001352static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001353ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1354 surface_property_notification_func callback,
1355 void *userdata)
1356{
1357 struct listener_layout_notification* notification = NULL;
1358 struct ivi_layout_notification_callback *prop_callback = NULL;
1359
1360 if (ivisurf == NULL || callback == NULL) {
1361 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1362 return IVI_FAILED;
1363 }
1364
1365 notification = malloc(sizeof *notification);
1366 if (notification == NULL) {
1367 weston_log("fails to allocate memory\n");
1368 return IVI_FAILED;
1369 }
1370
1371 prop_callback = malloc(sizeof *prop_callback);
1372 if (prop_callback == NULL) {
1373 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001374 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001375 return IVI_FAILED;
1376 }
1377
1378 prop_callback->callback = callback;
1379 prop_callback->data = userdata;
1380
1381 notification->listener.notify = surface_prop_changed;
1382 notification->userdata = prop_callback;
1383
1384 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1385
1386 return IVI_SUCCEEDED;
1387}
1388
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001389static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001390ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1391{
1392 if (ivilayer == NULL) {
1393 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1394 return NULL;
1395 }
1396
1397 return &ivilayer->prop;
1398}
1399
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001400static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001401ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1402{
1403 struct ivi_layout *layout = get_instance();
1404 struct ivi_layout_screen *iviscrn = NULL;
1405 int32_t length = 0;
1406 int32_t n = 0;
1407
1408 if (pLength == NULL || ppArray == NULL) {
1409 weston_log("ivi_layout_get_screens: invalid argument\n");
1410 return IVI_FAILED;
1411 }
1412
1413 length = wl_list_length(&layout->screen_list);
1414
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001415 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001416 /* the Array must be free by module which called this function */
1417 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1418 if (*ppArray == NULL) {
1419 weston_log("fails to allocate memory\n");
1420 return IVI_FAILED;
1421 }
1422
1423 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1424 (*ppArray)[n++] = iviscrn;
1425 }
1426 }
1427
1428 *pLength = length;
1429
1430 return IVI_SUCCEEDED;
1431}
1432
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001433static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001434ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1435 int32_t *pLength,
1436 struct ivi_layout_screen ***ppArray)
1437{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001438 int32_t length = 0;
1439 int32_t n = 0;
1440
1441 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1442 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1443 return IVI_FAILED;
1444 }
1445
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001446 if (ivilayer->on_screen != NULL)
1447 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001448
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001449 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001450 /* the Array must be free by module which called this function */
1451 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1452 if (*ppArray == NULL) {
1453 weston_log("fails to allocate memory\n");
1454 return IVI_FAILED;
1455 }
1456
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001457 (*ppArray)[n++] = ivilayer->on_screen;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001458 }
1459
1460 *pLength = length;
1461
1462 return IVI_SUCCEEDED;
1463}
1464
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001465static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001466ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1467{
1468 struct ivi_layout *layout = get_instance();
1469 struct ivi_layout_layer *ivilayer = NULL;
1470 int32_t length = 0;
1471 int32_t n = 0;
1472
1473 if (pLength == NULL || ppArray == NULL) {
1474 weston_log("ivi_layout_get_layers: invalid argument\n");
1475 return IVI_FAILED;
1476 }
1477
1478 length = wl_list_length(&layout->layer_list);
1479
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001480 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001481 /* the Array must be free by module which called this function */
1482 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1483 if (*ppArray == NULL) {
1484 weston_log("fails to allocate memory\n");
1485 return IVI_FAILED;
1486 }
1487
1488 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1489 (*ppArray)[n++] = ivilayer;
1490 }
1491 }
1492
1493 *pLength = length;
1494
1495 return IVI_SUCCEEDED;
1496}
1497
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001498static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001499ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1500 int32_t *pLength,
1501 struct ivi_layout_layer ***ppArray)
1502{
1503 struct ivi_layout_layer *ivilayer = NULL;
1504 int32_t length = 0;
1505 int32_t n = 0;
1506
1507 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1508 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1509 return IVI_FAILED;
1510 }
1511
1512 length = wl_list_length(&iviscrn->order.layer_list);
1513
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001514 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001515 /* the Array must be free by module which called this function */
1516 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1517 if (*ppArray == NULL) {
1518 weston_log("fails to allocate memory\n");
1519 return IVI_FAILED;
1520 }
1521
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001522 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001523 (*ppArray)[n++] = ivilayer;
1524 }
1525 }
1526
1527 *pLength = length;
1528
1529 return IVI_SUCCEEDED;
1530}
1531
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001532static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001533ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1534 int32_t *pLength,
1535 struct ivi_layout_layer ***ppArray)
1536{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001537 int32_t length = 0;
1538 int32_t n = 0;
1539
1540 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1541 weston_log("ivi_layout_getLayers: invalid argument\n");
1542 return IVI_FAILED;
1543 }
1544
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001545 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001546 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001547 length = 1;
1548 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001549 if (*ppArray == NULL) {
1550 weston_log("fails to allocate memory\n");
1551 return IVI_FAILED;
1552 }
1553
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001554 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001555 }
1556
1557 *pLength = length;
1558
1559 return IVI_SUCCEEDED;
1560}
1561
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001562static
1563int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001564ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1565{
1566 struct ivi_layout *layout = get_instance();
1567 struct ivi_layout_surface *ivisurf = NULL;
1568 int32_t length = 0;
1569 int32_t n = 0;
1570
1571 if (pLength == NULL || ppArray == NULL) {
1572 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1573 return IVI_FAILED;
1574 }
1575
1576 length = wl_list_length(&layout->surface_list);
1577
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001578 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001579 /* the Array must be free by module which called this function */
1580 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1581 if (*ppArray == NULL) {
1582 weston_log("fails to allocate memory\n");
1583 return IVI_FAILED;
1584 }
1585
1586 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1587 (*ppArray)[n++] = ivisurf;
1588 }
1589 }
1590
1591 *pLength = length;
1592
1593 return IVI_SUCCEEDED;
1594}
1595
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001596static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001597ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1598 int32_t *pLength,
1599 struct ivi_layout_surface ***ppArray)
1600{
1601 struct ivi_layout_surface *ivisurf = NULL;
1602 int32_t length = 0;
1603 int32_t n = 0;
1604
1605 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1606 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1607 return IVI_FAILED;
1608 }
1609
1610 length = wl_list_length(&ivilayer->order.surface_list);
1611
1612 if (length != 0) {
1613 /* the Array must be free by module which called this function */
1614 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1615 if (*ppArray == NULL) {
1616 weston_log("fails to allocate memory\n");
1617 return IVI_FAILED;
1618 }
1619
1620 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1621 (*ppArray)[n++] = ivisurf;
1622 }
1623 }
1624
1625 *pLength = length;
1626
1627 return IVI_SUCCEEDED;
1628}
1629
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001630static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001631ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1632 int32_t width, int32_t height)
1633{
1634 struct ivi_layout *layout = get_instance();
1635 struct ivi_layout_layer *ivilayer = NULL;
1636
1637 ivilayer = get_layer(&layout->layer_list, id_layer);
1638 if (ivilayer != NULL) {
1639 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001640 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001641 return ivilayer;
1642 }
1643
1644 ivilayer = calloc(1, sizeof *ivilayer);
1645 if (ivilayer == NULL) {
1646 weston_log("fails to allocate memory\n");
1647 return NULL;
1648 }
1649
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001650 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001651 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001652 ivilayer->layout = layout;
1653 ivilayer->id_layer = id_layer;
1654
1655 init_layer_properties(&ivilayer->prop, width, height);
1656 ivilayer->event_mask = 0;
1657
1658 wl_list_init(&ivilayer->pending.surface_list);
1659 wl_list_init(&ivilayer->pending.link);
1660 ivilayer->pending.prop = ivilayer->prop;
1661
1662 wl_list_init(&ivilayer->order.surface_list);
1663 wl_list_init(&ivilayer->order.link);
1664
1665 wl_list_insert(&layout->layer_list, &ivilayer->link);
1666
1667 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1668
1669 return ivilayer;
1670}
1671
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001672static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001673ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1674{
1675 if (ivilayer == NULL) {
1676 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1677 return;
1678 }
1679
1680 remove_all_notification(&ivilayer->property_changed.listener_list);
1681}
1682
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001683static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001684ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1685 layer_property_notification_func callback,
1686 void *userdata)
1687{
1688 if (ivilayer == NULL) {
1689 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1690 return;
1691 }
1692
1693 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1694}
1695
1696static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001697ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001698{
1699 struct ivi_layout *layout = get_instance();
1700
1701 if (ivilayer == NULL) {
1702 weston_log("ivi_layout_layer_remove: invalid argument\n");
1703 return;
1704 }
1705
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001706 if (--ivilayer->ref_count > 0)
1707 return;
1708
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001709 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1710
1711 clear_surface_pending_list(ivilayer);
1712 clear_surface_order_list(ivilayer);
1713
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001714 wl_list_remove(&ivilayer->pending.link);
1715 wl_list_remove(&ivilayer->order.link);
1716 wl_list_remove(&ivilayer->link);
1717
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001718 ivi_layout_layer_remove_notification(ivilayer);
1719
1720 free(ivilayer);
1721}
1722
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001723int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001724ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1725 bool newVisibility)
1726{
1727 struct ivi_layout_layer_properties *prop = NULL;
1728
1729 if (ivilayer == NULL) {
1730 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1731 return IVI_FAILED;
1732 }
1733
1734 prop = &ivilayer->pending.prop;
1735 prop->visibility = newVisibility;
1736
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001737 if (ivilayer->prop.visibility != newVisibility)
1738 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1739 else
1740 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001741
1742 return IVI_SUCCEEDED;
1743}
1744
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001745static bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001746ivi_layout_layer_get_visibility(struct ivi_layout_layer *ivilayer)
1747{
1748 if (ivilayer == NULL) {
1749 weston_log("ivi_layout_layer_get_visibility: invalid argument\n");
1750 return false;
1751 }
1752
1753 return ivilayer->prop.visibility;
1754}
1755
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001756int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001757ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1758 wl_fixed_t opacity)
1759{
1760 struct ivi_layout_layer_properties *prop = NULL;
1761
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001762 if (ivilayer == NULL ||
1763 opacity < wl_fixed_from_double(0.0) ||
1764 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001765 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1766 return IVI_FAILED;
1767 }
1768
1769 prop = &ivilayer->pending.prop;
1770 prop->opacity = opacity;
1771
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001772 if (ivilayer->prop.opacity != opacity)
1773 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1774 else
1775 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001776
1777 return IVI_SUCCEEDED;
1778}
1779
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001780wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001781ivi_layout_layer_get_opacity(struct ivi_layout_layer *ivilayer)
1782{
1783 if (ivilayer == NULL) {
1784 weston_log("ivi_layout_layer_get_opacity: invalid argument\n");
1785 return wl_fixed_from_double(0.0);
1786 }
1787
1788 return ivilayer->prop.opacity;
1789}
1790
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001791static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001792ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1793 int32_t x, int32_t y,
1794 int32_t width, int32_t height)
1795{
1796 struct ivi_layout_layer_properties *prop = NULL;
1797
1798 if (ivilayer == NULL) {
1799 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1800 return IVI_FAILED;
1801 }
1802
1803 prop = &ivilayer->pending.prop;
1804 prop->source_x = x;
1805 prop->source_y = y;
1806 prop->source_width = width;
1807 prop->source_height = height;
1808
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001809 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1810 ivilayer->prop.source_width != width ||
1811 ivilayer->prop.source_height != height)
1812 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1813 else
1814 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001815
1816 return IVI_SUCCEEDED;
1817}
1818
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001819static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001820ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1821 int32_t x, int32_t y,
1822 int32_t width, int32_t height)
1823{
1824 struct ivi_layout_layer_properties *prop = NULL;
1825
1826 if (ivilayer == NULL) {
1827 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1828 return IVI_FAILED;
1829 }
1830
1831 prop = &ivilayer->pending.prop;
1832 prop->dest_x = x;
1833 prop->dest_y = y;
1834 prop->dest_width = width;
1835 prop->dest_height = height;
1836
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001837 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1838 ivilayer->prop.dest_width != width ||
1839 ivilayer->prop.dest_height != height)
1840 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1841 else
1842 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001843
1844 return IVI_SUCCEEDED;
1845}
1846
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001847static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001848ivi_layout_layer_get_dimension(struct ivi_layout_layer *ivilayer,
1849 int32_t *dest_width, int32_t *dest_height)
1850{
1851 if (ivilayer == NULL || dest_width == NULL || dest_height == NULL) {
1852 weston_log("ivi_layout_layer_get_dimension: invalid argument\n");
1853 return IVI_FAILED;
1854 }
1855
1856 *dest_width = ivilayer->prop.dest_width;
1857 *dest_height = ivilayer->prop.dest_height;
1858
1859 return IVI_SUCCEEDED;
1860}
1861
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001862static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001863ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
1864 int32_t dest_width, int32_t dest_height)
1865{
1866 struct ivi_layout_layer_properties *prop = NULL;
1867
1868 if (ivilayer == NULL) {
1869 weston_log("ivi_layout_layer_set_dimension: invalid argument\n");
1870 return IVI_FAILED;
1871 }
1872
1873 prop = &ivilayer->pending.prop;
1874
1875 prop->dest_width = dest_width;
1876 prop->dest_height = dest_height;
1877
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001878 if (ivilayer->prop.dest_width != dest_width ||
1879 ivilayer->prop.dest_height != dest_height)
1880 ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
1881 else
1882 ivilayer->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001883
1884 return IVI_SUCCEEDED;
1885}
1886
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001887int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001888ivi_layout_layer_get_position(struct ivi_layout_layer *ivilayer,
1889 int32_t *dest_x, int32_t *dest_y)
1890{
1891 if (ivilayer == NULL || dest_x == NULL || dest_y == NULL) {
1892 weston_log("ivi_layout_layer_get_position: invalid argument\n");
1893 return IVI_FAILED;
1894 }
1895
1896 *dest_x = ivilayer->prop.dest_x;
1897 *dest_y = ivilayer->prop.dest_y;
1898
1899 return IVI_SUCCEEDED;
1900}
1901
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001902int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001903ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
1904 int32_t dest_x, int32_t dest_y)
1905{
1906 struct ivi_layout_layer_properties *prop = NULL;
1907
1908 if (ivilayer == NULL) {
1909 weston_log("ivi_layout_layer_set_position: invalid argument\n");
1910 return IVI_FAILED;
1911 }
1912
1913 prop = &ivilayer->pending.prop;
1914 prop->dest_x = dest_x;
1915 prop->dest_y = dest_y;
1916
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001917 if (ivilayer->prop.dest_x != dest_x || ivilayer->prop.dest_y != dest_y)
1918 ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
1919 else
1920 ivilayer->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001921
1922 return IVI_SUCCEEDED;
1923}
1924
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001925static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001926ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1927 enum wl_output_transform orientation)
1928{
1929 struct ivi_layout_layer_properties *prop = NULL;
1930
1931 if (ivilayer == NULL) {
1932 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1933 return IVI_FAILED;
1934 }
1935
1936 prop = &ivilayer->pending.prop;
1937 prop->orientation = orientation;
1938
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001939 if (ivilayer->prop.orientation != orientation)
1940 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1941 else
1942 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001943
1944 return IVI_SUCCEEDED;
1945}
1946
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001947static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001948ivi_layout_layer_get_orientation(struct ivi_layout_layer *ivilayer)
1949{
1950 if (ivilayer == NULL) {
1951 weston_log("ivi_layout_layer_get_orientation: invalid argument\n");
1952 return 0;
1953 }
1954
1955 return ivilayer->prop.orientation;
1956}
1957
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001958int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001959ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1960 struct ivi_layout_surface **pSurface,
1961 int32_t number)
1962{
1963 struct ivi_layout *layout = get_instance();
1964 struct ivi_layout_surface *ivisurf = NULL;
1965 struct ivi_layout_surface *next = NULL;
1966 uint32_t *id_surface = NULL;
1967 int32_t i = 0;
1968
1969 if (ivilayer == NULL) {
1970 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1971 return IVI_FAILED;
1972 }
1973
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001974 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001975
1976 for (i = 0; i < number; i++) {
1977 id_surface = &pSurface[i]->id_surface;
1978
1979 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
1980 if (*id_surface != ivisurf->id_surface) {
1981 continue;
1982 }
1983
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001984 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001985 wl_list_insert(&ivilayer->pending.surface_list,
1986 &ivisurf->pending.link);
1987 break;
1988 }
1989 }
1990
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001991 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001992
1993 return IVI_SUCCEEDED;
1994}
1995
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001996int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001997ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1998 bool newVisibility)
1999{
2000 struct ivi_layout_surface_properties *prop = NULL;
2001
2002 if (ivisurf == NULL) {
2003 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
2004 return IVI_FAILED;
2005 }
2006
2007 prop = &ivisurf->pending.prop;
2008 prop->visibility = newVisibility;
2009
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002010 if (ivisurf->prop.visibility != newVisibility)
2011 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
2012 else
2013 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002014
2015 return IVI_SUCCEEDED;
2016}
2017
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002018bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002019ivi_layout_surface_get_visibility(struct ivi_layout_surface *ivisurf)
2020{
2021 if (ivisurf == NULL) {
2022 weston_log("ivi_layout_surface_get_visibility: invalid argument\n");
2023 return false;
2024 }
2025
2026 return ivisurf->prop.visibility;
2027}
2028
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002029int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002030ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
2031 wl_fixed_t opacity)
2032{
2033 struct ivi_layout_surface_properties *prop = NULL;
2034
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09002035 if (ivisurf == NULL ||
2036 opacity < wl_fixed_from_double(0.0) ||
2037 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002038 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
2039 return IVI_FAILED;
2040 }
2041
2042 prop = &ivisurf->pending.prop;
2043 prop->opacity = opacity;
2044
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002045 if (ivisurf->prop.opacity != opacity)
2046 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
2047 else
2048 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002049
2050 return IVI_SUCCEEDED;
2051}
2052
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002053wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002054ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
2055{
2056 if (ivisurf == NULL) {
2057 weston_log("ivi_layout_surface_get_opacity: invalid argument\n");
2058 return wl_fixed_from_double(0.0);
2059 }
2060
2061 return ivisurf->prop.opacity;
2062}
2063
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002064int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002065ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
2066 int32_t x, int32_t y,
2067 int32_t width, int32_t height)
2068{
2069 struct ivi_layout_surface_properties *prop = NULL;
2070
2071 if (ivisurf == NULL) {
2072 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
2073 return IVI_FAILED;
2074 }
2075
2076 prop = &ivisurf->pending.prop;
2077 prop->start_x = prop->dest_x;
2078 prop->start_y = prop->dest_y;
2079 prop->dest_x = x;
2080 prop->dest_y = y;
2081 prop->start_width = prop->dest_width;
2082 prop->start_height = prop->dest_height;
2083 prop->dest_width = width;
2084 prop->dest_height = height;
2085
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002086 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2087 ivisurf->prop.dest_width != width ||
2088 ivisurf->prop.dest_height != height)
2089 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2090 else
2091 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002092
2093 return IVI_SUCCEEDED;
2094}
2095
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002096static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002097ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
2098 int32_t dest_width, int32_t dest_height)
2099{
2100 struct ivi_layout_surface_properties *prop = NULL;
2101
2102 if (ivisurf == NULL) {
2103 weston_log("ivi_layout_surface_set_dimension: invalid argument\n");
2104 return IVI_FAILED;
2105 }
2106
2107 prop = &ivisurf->pending.prop;
2108 prop->dest_width = dest_width;
2109 prop->dest_height = dest_height;
2110
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002111 if (ivisurf->prop.dest_width != dest_width ||
2112 ivisurf->prop.dest_height != dest_height)
2113 ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
2114 else
2115 ivisurf->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002116
2117 return IVI_SUCCEEDED;
2118}
2119
2120int32_t
2121ivi_layout_surface_get_dimension(struct ivi_layout_surface *ivisurf,
2122 int32_t *dest_width, int32_t *dest_height)
2123{
2124 if (ivisurf == NULL || dest_width == NULL || dest_height == NULL) {
2125 weston_log("ivi_layout_surface_get_dimension: invalid argument\n");
2126 return IVI_FAILED;
2127 }
2128
2129 *dest_width = ivisurf->prop.dest_width;
2130 *dest_height = ivisurf->prop.dest_height;
2131
2132 return IVI_SUCCEEDED;
2133}
2134
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002135static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002136ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
2137 int32_t dest_x, int32_t dest_y)
2138{
2139 struct ivi_layout_surface_properties *prop = NULL;
2140
2141 if (ivisurf == NULL) {
2142 weston_log("ivi_layout_surface_set_position: invalid argument\n");
2143 return IVI_FAILED;
2144 }
2145
2146 prop = &ivisurf->pending.prop;
2147 prop->dest_x = dest_x;
2148 prop->dest_y = dest_y;
2149
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002150 if (ivisurf->prop.dest_x != dest_x || ivisurf->prop.dest_y != dest_y)
2151 ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
2152 else
2153 ivisurf->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002154
2155 return IVI_SUCCEEDED;
2156}
2157
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002158static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002159ivi_layout_surface_get_position(struct ivi_layout_surface *ivisurf,
2160 int32_t *dest_x, int32_t *dest_y)
2161{
2162 if (ivisurf == NULL || dest_x == NULL || dest_y == NULL) {
2163 weston_log("ivi_layout_surface_get_position: invalid argument\n");
2164 return IVI_FAILED;
2165 }
2166
2167 *dest_x = ivisurf->prop.dest_x;
2168 *dest_y = ivisurf->prop.dest_y;
2169
2170 return IVI_SUCCEEDED;
2171}
2172
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002173static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002174ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2175 enum wl_output_transform orientation)
2176{
2177 struct ivi_layout_surface_properties *prop = NULL;
2178
2179 if (ivisurf == NULL) {
2180 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2181 return IVI_FAILED;
2182 }
2183
2184 prop = &ivisurf->pending.prop;
2185 prop->orientation = orientation;
2186
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002187 if (ivisurf->prop.orientation != orientation)
2188 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2189 else
2190 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002191
2192 return IVI_SUCCEEDED;
2193}
2194
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002195static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002196ivi_layout_surface_get_orientation(struct ivi_layout_surface *ivisurf)
2197{
2198 if (ivisurf == NULL) {
2199 weston_log("ivi_layout_surface_get_orientation: invalid argument\n");
2200 return 0;
2201 }
2202
2203 return ivisurf->prop.orientation;
2204}
2205
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002206static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002207ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2208 struct ivi_layout_layer *addlayer)
2209{
2210 struct ivi_layout *layout = get_instance();
2211 struct ivi_layout_layer *ivilayer = NULL;
2212 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002213
2214 if (iviscrn == NULL || addlayer == NULL) {
2215 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2216 return IVI_FAILED;
2217 }
2218
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00002219 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002220 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2221 return IVI_SUCCEEDED;
2222 }
2223
2224 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2225 if (ivilayer->id_layer == addlayer->id_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002226 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002227 wl_list_insert(&iviscrn->pending.layer_list,
2228 &ivilayer->pending.link);
2229 break;
2230 }
2231 }
2232
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002233 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002234
2235 return IVI_SUCCEEDED;
2236}
2237
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002238static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002239ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2240 struct ivi_layout_layer **pLayer,
2241 const int32_t number)
2242{
2243 struct ivi_layout *layout = get_instance();
2244 struct ivi_layout_layer *ivilayer = NULL;
2245 struct ivi_layout_layer *next = NULL;
2246 uint32_t *id_layer = NULL;
2247 int32_t i = 0;
2248
2249 if (iviscrn == NULL) {
2250 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2251 return IVI_FAILED;
2252 }
2253
2254 wl_list_for_each_safe(ivilayer, next,
2255 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002256 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002257 wl_list_init(&ivilayer->pending.link);
2258 }
2259
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002260 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002261
2262 for (i = 0; i < number; i++) {
2263 id_layer = &pLayer[i]->id_layer;
2264 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2265 if (*id_layer != ivilayer->id_layer) {
2266 continue;
2267 }
2268
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002269 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002270 wl_list_insert(&iviscrn->pending.layer_list,
2271 &ivilayer->pending.link);
2272 break;
2273 }
2274 }
2275
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002276 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002277
2278 return IVI_SUCCEEDED;
2279}
2280
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002281static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002282ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2283{
2284 return iviscrn->output;
2285}
2286
2287/**
2288 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2289 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2290 * This function is used to get the result of drawing by clients.
2291 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002292static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002293ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2294{
2295 return ivisurf != NULL ? ivisurf->surface : NULL;
2296}
2297
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002298static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002299ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2300 int32_t *width, int32_t *height,
2301 int32_t *stride)
2302{
2303 int32_t w;
2304 int32_t h;
2305 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2306
2307 if (ivisurf == NULL || ivisurf->surface == NULL) {
2308 weston_log("%s: invalid argument\n", __func__);
2309 return IVI_FAILED;
2310 }
2311
2312 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2313
2314 if (width != NULL)
2315 *width = w;
2316
2317 if (height != NULL)
2318 *height = h;
2319
2320 if (stride != NULL)
2321 *stride = w * bytespp;
2322
2323 return IVI_SUCCEEDED;
2324}
2325
2326static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002327ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2328 layer_property_notification_func callback,
2329 void *userdata)
2330{
2331 struct ivi_layout_notification_callback *prop_callback = NULL;
2332
2333 if (ivilayer == NULL || callback == NULL) {
2334 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2335 return IVI_FAILED;
2336 }
2337
2338 prop_callback = malloc(sizeof *prop_callback);
2339 if (prop_callback == NULL) {
2340 weston_log("fails to allocate memory\n");
2341 return IVI_FAILED;
2342 }
2343
2344 prop_callback->callback = callback;
2345 prop_callback->data = userdata;
2346
2347 return add_notification(&ivilayer->property_changed,
2348 layer_prop_changed,
2349 prop_callback);
2350}
2351
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002352static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002353ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2354{
2355 if (ivisurf == NULL) {
2356 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2357 return NULL;
2358 }
2359
2360 return &ivisurf->prop;
2361}
2362
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002363static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002364ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2365 struct ivi_layout_surface *addsurf)
2366{
2367 struct ivi_layout *layout = get_instance();
2368 struct ivi_layout_surface *ivisurf = NULL;
2369 struct ivi_layout_surface *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002370
2371 if (ivilayer == NULL || addsurf == NULL) {
2372 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2373 return IVI_FAILED;
2374 }
2375
Ucan, Emre (ADITG/SW1)4a183642015-08-28 12:59:04 +00002376 if (addsurf->on_layer == ivilayer) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002377 weston_log("ivi_layout_layer_add_surface: addsurf is already available\n");
2378 return IVI_SUCCEEDED;
2379 }
2380
2381 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2382 if (ivisurf->id_surface == addsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002383 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002384 wl_list_insert(&ivilayer->pending.surface_list,
2385 &ivisurf->pending.link);
2386 break;
2387 }
2388 }
2389
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002390 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002391
2392 return IVI_SUCCEEDED;
2393}
2394
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002395static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002396ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2397 struct ivi_layout_surface *remsurf)
2398{
2399 struct ivi_layout_surface *ivisurf = NULL;
2400 struct ivi_layout_surface *next = NULL;
2401
2402 if (ivilayer == NULL || remsurf == NULL) {
2403 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2404 return;
2405 }
2406
2407 wl_list_for_each_safe(ivisurf, next,
2408 &ivilayer->pending.surface_list, pending.link) {
2409 if (ivisurf->id_surface == remsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002410 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002411 wl_list_init(&ivisurf->pending.link);
2412 break;
2413 }
2414 }
2415
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002416 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002417}
2418
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002419static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002420ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2421 int32_t x, int32_t y,
2422 int32_t width, int32_t height)
2423{
2424 struct ivi_layout_surface_properties *prop = NULL;
2425
2426 if (ivisurf == NULL) {
2427 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2428 return IVI_FAILED;
2429 }
2430
2431 prop = &ivisurf->pending.prop;
2432 prop->source_x = x;
2433 prop->source_y = y;
2434 prop->source_width = width;
2435 prop->source_height = height;
2436
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002437 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2438 ivisurf->prop.source_width != width ||
2439 ivisurf->prop.source_height != height)
2440 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2441 else
2442 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002443
2444 return IVI_SUCCEEDED;
2445}
2446
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002447int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002448ivi_layout_commit_changes(void)
2449{
2450 struct ivi_layout *layout = get_instance();
2451
2452 commit_surface_list(layout);
2453 commit_layer_list(layout);
2454 commit_screen_list(layout);
2455
2456 commit_transition(layout);
2457
2458 commit_changes(layout);
2459 send_prop(layout);
2460 weston_compositor_schedule_repaint(layout->compositor);
2461
2462 return IVI_SUCCEEDED;
2463}
2464
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002465static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002466ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2467 enum ivi_layout_transition_type type,
2468 uint32_t duration)
2469{
2470 if (ivilayer == NULL) {
2471 weston_log("%s: invalid argument\n", __func__);
2472 return -1;
2473 }
2474
2475 ivilayer->pending.prop.transition_type = type;
2476 ivilayer->pending.prop.transition_duration = duration;
2477
2478 return 0;
2479}
2480
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002481static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002482ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2483 uint32_t is_fade_in,
2484 double start_alpha, double end_alpha)
2485{
2486 if (ivilayer == NULL) {
2487 weston_log("%s: invalid argument\n", __func__);
2488 return -1;
2489 }
2490
2491 ivilayer->pending.prop.is_fade_in = is_fade_in;
2492 ivilayer->pending.prop.start_alpha = start_alpha;
2493 ivilayer->pending.prop.end_alpha = end_alpha;
2494
2495 return 0;
2496}
2497
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002498static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002499ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2500 uint32_t duration)
2501{
2502 struct ivi_layout_surface_properties *prop;
2503
2504 if (ivisurf == NULL) {
2505 weston_log("%s: invalid argument\n", __func__);
2506 return -1;
2507 }
2508
2509 prop = &ivisurf->pending.prop;
2510 prop->transition_duration = duration*10;
2511 return 0;
2512}
2513
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002514static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002515ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2516 enum ivi_layout_transition_type type,
2517 uint32_t duration)
2518{
2519 struct ivi_layout_surface_properties *prop;
2520
2521 if (ivisurf == NULL) {
2522 weston_log("%s: invalid argument\n", __func__);
2523 return -1;
2524 }
2525
2526 prop = &ivisurf->pending.prop;
2527 prop->transition_type = type;
2528 prop->transition_duration = duration;
2529 return 0;
2530}
2531
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002532static int32_t
2533ivi_layout_surface_dump(struct weston_surface *surface,
2534 void *target, size_t size,int32_t x, int32_t y,
2535 int32_t width, int32_t height)
2536{
2537 int result = 0;
2538
2539 if (surface == NULL) {
2540 weston_log("%s: invalid argument\n", __func__);
2541 return IVI_FAILED;
2542 }
2543
2544 result = weston_surface_copy_content(
2545 surface, target, size,
2546 x, y, width, height);
2547
2548 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2549}
2550
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002551/**
2552 * methods of interaction between ivi-shell with ivi-layout
2553 */
2554struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002555ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2556{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002557 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002558 return NULL;
2559
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002560 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002561}
2562
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002563void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002564ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2565 int32_t width, int32_t height)
2566{
2567 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002568
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002569 /* emit callback which is set by ivi-layout api user */
2570 wl_signal_emit(&layout->surface_notification.configure_changed,
2571 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002572}
2573
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002574static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002575ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2576 ivi_controller_surface_content_callback callback,
2577 void* userdata)
2578{
2579 int32_t ret = IVI_FAILED;
2580
2581 if (ivisurf != NULL) {
2582 ivisurf->content_observer.callback = callback;
2583 ivisurf->content_observer.userdata = userdata;
2584 ret = IVI_SUCCEEDED;
2585 }
2586 return ret;
2587}
2588
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002589struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002590ivi_layout_surface_create(struct weston_surface *wl_surface,
2591 uint32_t id_surface)
2592{
2593 struct ivi_layout *layout = get_instance();
2594 struct ivi_layout_surface *ivisurf = NULL;
2595 struct weston_view *tmpview = NULL;
2596
2597 if (wl_surface == NULL) {
2598 weston_log("ivi_layout_surface_create: invalid argument\n");
2599 return NULL;
2600 }
2601
2602 ivisurf = get_surface(&layout->surface_list, id_surface);
2603 if (ivisurf != NULL) {
2604 if (ivisurf->surface != NULL) {
2605 weston_log("id_surface(%d) is already created\n", id_surface);
2606 return NULL;
2607 }
2608 }
2609
2610 ivisurf = calloc(1, sizeof *ivisurf);
2611 if (ivisurf == NULL) {
2612 weston_log("fails to allocate memory\n");
2613 return NULL;
2614 }
2615
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002616 wl_signal_init(&ivisurf->property_changed);
2617 wl_signal_init(&ivisurf->configured);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002618 ivisurf->id_surface = id_surface;
2619 ivisurf->layout = layout;
2620
2621 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002622
2623 tmpview = weston_view_create(wl_surface);
2624 if (tmpview == NULL) {
2625 weston_log("fails to allocate memory\n");
2626 }
2627
2628 ivisurf->surface->width_from_buffer = 0;
2629 ivisurf->surface->height_from_buffer = 0;
2630
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002631 weston_matrix_init(&ivisurf->transform.matrix);
2632 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002633
2634 init_surface_properties(&ivisurf->prop);
2635 ivisurf->event_mask = 0;
2636
2637 ivisurf->pending.prop = ivisurf->prop;
2638 wl_list_init(&ivisurf->pending.link);
2639
2640 wl_list_init(&ivisurf->order.link);
2641 wl_list_init(&ivisurf->order.layer_list);
2642
2643 wl_list_insert(&layout->surface_list, &ivisurf->link);
2644
2645 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2646
2647 return ivisurf;
2648}
2649
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002650void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002651ivi_layout_init_with_compositor(struct weston_compositor *ec)
2652{
2653 struct ivi_layout *layout = get_instance();
2654
2655 layout->compositor = ec;
2656
2657 wl_list_init(&layout->surface_list);
2658 wl_list_init(&layout->layer_list);
2659 wl_list_init(&layout->screen_list);
2660
2661 wl_signal_init(&layout->layer_notification.created);
2662 wl_signal_init(&layout->layer_notification.removed);
2663
2664 wl_signal_init(&layout->surface_notification.created);
2665 wl_signal_init(&layout->surface_notification.removed);
2666 wl_signal_init(&layout->surface_notification.configure_changed);
2667
2668 /* Add layout_layer at the last of weston_compositor.layer_list */
2669 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2670
2671 create_screen(ec);
2672
2673 layout->transitions = ivi_layout_transition_set_create(ec);
2674 wl_list_init(&layout->pending_transition_list);
2675}
2676
2677
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002678void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002679ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2680 struct wl_listener* listener)
2681{
2682 wl_signal_add(&ivisurf->configured, listener);
2683}
2684
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002685static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002686 /**
2687 * commit all changes
2688 */
2689 .commit_changes = ivi_layout_commit_changes,
2690
2691 /**
2692 * surface controller interfaces
2693 */
2694 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2695 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2696 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2697 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2698 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2699 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2700 .get_surfaces = ivi_layout_get_surfaces,
2701 .get_id_of_surface = ivi_layout_get_id_of_surface,
2702 .get_surface_from_id = ivi_layout_get_surface_from_id,
2703 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2704 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2705 .surface_set_visibility = ivi_layout_surface_set_visibility,
2706 .surface_get_visibility = ivi_layout_surface_get_visibility,
2707 .surface_set_opacity = ivi_layout_surface_set_opacity,
2708 .surface_get_opacity = ivi_layout_surface_get_opacity,
2709 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2710 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
2711 .surface_set_position = ivi_layout_surface_set_position,
2712 .surface_get_position = ivi_layout_surface_get_position,
2713 .surface_set_dimension = ivi_layout_surface_set_dimension,
2714 .surface_get_dimension = ivi_layout_surface_get_dimension,
2715 .surface_set_orientation = ivi_layout_surface_set_orientation,
2716 .surface_get_orientation = ivi_layout_surface_get_orientation,
2717 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2718 .surface_add_notification = ivi_layout_surface_add_notification,
2719 .surface_remove_notification = ivi_layout_surface_remove_notification,
2720 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2721 .surface_set_transition = ivi_layout_surface_set_transition,
2722 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2723
2724 /**
2725 * layer controller interfaces
2726 */
2727 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2728 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2729 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2730 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2731 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002732 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002733 .get_layers = ivi_layout_get_layers,
2734 .get_id_of_layer = ivi_layout_get_id_of_layer,
2735 .get_layer_from_id = ivi_layout_get_layer_from_id,
2736 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2737 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2738 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2739 .layer_set_visibility = ivi_layout_layer_set_visibility,
2740 .layer_get_visibility = ivi_layout_layer_get_visibility,
2741 .layer_set_opacity = ivi_layout_layer_set_opacity,
2742 .layer_get_opacity = ivi_layout_layer_get_opacity,
2743 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2744 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
2745 .layer_set_position = ivi_layout_layer_set_position,
2746 .layer_get_position = ivi_layout_layer_get_position,
2747 .layer_set_dimension = ivi_layout_layer_set_dimension,
2748 .layer_get_dimension = ivi_layout_layer_get_dimension,
2749 .layer_set_orientation = ivi_layout_layer_set_orientation,
2750 .layer_get_orientation = ivi_layout_layer_get_orientation,
2751 .layer_add_surface = ivi_layout_layer_add_surface,
2752 .layer_remove_surface = ivi_layout_layer_remove_surface,
2753 .layer_set_render_order = ivi_layout_layer_set_render_order,
2754 .layer_add_notification = ivi_layout_layer_add_notification,
2755 .layer_remove_notification = ivi_layout_layer_remove_notification,
2756 .layer_set_transition = ivi_layout_layer_set_transition,
2757
2758 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002759 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002760 */
2761 .get_screen_from_id = ivi_layout_get_screen_from_id,
2762 .get_screen_resolution = ivi_layout_get_screen_resolution,
2763 .get_screens = ivi_layout_get_screens,
2764 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2765 .screen_add_layer = ivi_layout_screen_add_layer,
2766 .screen_set_render_order = ivi_layout_screen_set_render_order,
2767 .screen_get_output = ivi_layout_screen_get_output,
2768
2769 /**
2770 * animation
2771 */
2772 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002773 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2774
2775 /**
2776 * surface content dumping for debugging
2777 */
2778 .surface_get_size = ivi_layout_surface_get_size,
2779 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002780
2781 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002782 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002783 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002784 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002785 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2786
2787 /**
2788 * screen controller interfaces part2
2789 */
2790 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002791};
2792
2793int
2794load_controller_modules(struct weston_compositor *compositor, const char *modules,
2795 int *argc, char *argv[])
2796{
2797 const char *p, *end;
2798 char buffer[256];
2799 int (*controller_module_init)(struct weston_compositor *compositor,
2800 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002801 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002802 size_t interface_version);
2803
2804 if (modules == NULL)
2805 return 0;
2806
2807 p = modules;
2808 while (*p) {
2809 end = strchrnul(p, ',');
2810 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2811
2812 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002813 if (!controller_module_init)
2814 return -1;
2815
2816 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002817 &ivi_layout_interface,
2818 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002819 weston_log("ivi-shell: Initialization of controller module fails");
2820 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002821 }
2822
2823 p = end;
2824 while (*p == ',')
2825 p++;
2826 }
2827
2828 return 0;
2829}