blob: 724ca6fe839a69f8692c1413df98961357aa4864 [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 Tanibatab4cb25d2015-12-09 15:36:58 +0900593update_prop(struct ivi_layout_screen *iviscrn,
594 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900595 struct ivi_layout_surface *ivisurf)
596{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900597 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900598 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900599 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900600
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900601 /*In case of no prop change, this just returns*/
602 if (!ivilayer->event_mask && !ivisurf->event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900603 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900604
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900605 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900606
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000607 tmpview = get_weston_view(ivisurf);
608 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900609
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900610 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
611 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
612 can_calc = false;
613 }
614
615 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
616 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
617 can_calc = false;
618 }
619
620 if (can_calc) {
621 wl_list_remove(&ivisurf->transform.link);
622 weston_matrix_init(&ivisurf->transform.matrix);
623
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900624 calc_surface_to_global_matrix_and_mask_to_weston_surface(
625 ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900626
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000627 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
628 wl_list_insert(&tmpview->geometry.transformation_list,
629 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900630
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000631 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900632 }
633
634 ivisurf->update_count++;
635
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000636 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900637
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000638 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900639}
640
641static void
642commit_changes(struct ivi_layout *layout)
643{
644 struct ivi_layout_screen *iviscrn = NULL;
645 struct ivi_layout_layer *ivilayer = NULL;
646 struct ivi_layout_surface *ivisurf = NULL;
647
648 wl_list_for_each(iviscrn, &layout->screen_list, link) {
649 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900650 /*
651 * If ivilayer is invisible, weston_view of ivisurf doesn't
652 * need to be modified.
653 */
654 if (ivilayer->prop.visibility == false)
655 continue;
656
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900657 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900658 /*
659 * If ivilayer is invisible, weston_view of ivisurf doesn't
660 * need to be modified.
661 */
662 if (ivisurf->prop.visibility == false)
663 continue;
664
665 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900666 }
667 }
668 }
669}
670
671static void
672commit_surface_list(struct ivi_layout *layout)
673{
674 struct ivi_layout_surface *ivisurf = NULL;
675 int32_t dest_x = 0;
676 int32_t dest_y = 0;
677 int32_t dest_width = 0;
678 int32_t dest_height = 0;
679 int32_t configured = 0;
680
681 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300682 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900683 dest_x = ivisurf->prop.dest_x;
684 dest_y = ivisurf->prop.dest_y;
685 dest_width = ivisurf->prop.dest_width;
686 dest_height = ivisurf->prop.dest_height;
687
688 ivi_layout_transition_move_resize_view(ivisurf,
689 ivisurf->pending.prop.dest_x,
690 ivisurf->pending.prop.dest_y,
691 ivisurf->pending.prop.dest_width,
692 ivisurf->pending.prop.dest_height,
693 ivisurf->pending.prop.transition_duration);
694
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300695 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900696 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
697 } else {
698 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
699 }
700
701 ivisurf->prop = ivisurf->pending.prop;
702 ivisurf->prop.dest_x = dest_x;
703 ivisurf->prop.dest_y = dest_y;
704 ivisurf->prop.dest_width = dest_width;
705 ivisurf->prop.dest_height = dest_height;
706 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
707 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
708
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300709 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900710 dest_x = ivisurf->prop.dest_x;
711 dest_y = ivisurf->prop.dest_y;
712 dest_width = ivisurf->prop.dest_width;
713 dest_height = ivisurf->prop.dest_height;
714
715 ivi_layout_transition_move_resize_view(ivisurf,
716 ivisurf->pending.prop.dest_x,
717 ivisurf->pending.prop.dest_y,
718 ivisurf->pending.prop.dest_width,
719 ivisurf->pending.prop.dest_height,
720 ivisurf->pending.prop.transition_duration);
721
722 ivisurf->prop = ivisurf->pending.prop;
723 ivisurf->prop.dest_x = dest_x;
724 ivisurf->prop.dest_y = dest_y;
725 ivisurf->prop.dest_width = dest_width;
726 ivisurf->prop.dest_height = dest_height;
727
728 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
729 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
730
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300731 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900732 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300733 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900734 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
735 } else {
736 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
737 }
738
739 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
740 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
741 configured = 1;
742 }
743
744 ivisurf->prop = ivisurf->pending.prop;
745 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
746 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
747
748 if (configured && !is_surface_transition(ivisurf))
749 wl_signal_emit(&ivisurf->configured, ivisurf);
750 } else {
751 configured = 0;
752 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
753 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
754 configured = 1;
755 }
756
757 ivisurf->prop = ivisurf->pending.prop;
758 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
759 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
760
761 if (configured && !is_surface_transition(ivisurf))
762 wl_signal_emit(&ivisurf->configured, ivisurf);
763 }
764 }
765}
766
767static void
768commit_layer_list(struct ivi_layout *layout)
769{
770 struct ivi_layout_layer *ivilayer = NULL;
771 struct ivi_layout_surface *ivisurf = NULL;
772 struct ivi_layout_surface *next = NULL;
773
774 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300775 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900776 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 -0300777 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900778 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
779 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
780 NULL, NULL,
781 ivilayer->pending.prop.transition_duration);
782 }
783 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
784
785 ivilayer->prop = ivilayer->pending.prop;
786
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000787 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900788 continue;
789 }
790
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000791 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
792 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000793 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000794 wl_list_remove(&ivisurf->order.link);
795 wl_list_init(&ivisurf->order.link);
796 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900797 }
798
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000799 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900800
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000801 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900802 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000803 wl_list_remove(&ivisurf->order.link);
804 wl_list_insert(&ivilayer->order.surface_list,
805 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000806 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000807 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900808 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000809
810 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900811 }
812}
813
814static void
815commit_screen_list(struct ivi_layout *layout)
816{
817 struct ivi_layout_screen *iviscrn = NULL;
818 struct ivi_layout_layer *ivilayer = NULL;
819 struct ivi_layout_layer *next = NULL;
820 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000821 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900822
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900823 /* Clear view list of layout ivi_layer */
824 wl_list_init(&layout->layout_layer.view_list.link);
825
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900826 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000827 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900828 wl_list_for_each_safe(ivilayer, next,
829 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000830 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000831 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900832 wl_list_init(&ivilayer->order.link);
833 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
834 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900835
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000836 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900837
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900838 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
839 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900840 /* FIXME: avoid to insert order.link to multiple screens */
841 wl_list_remove(&ivilayer->order.link);
842
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900843 wl_list_insert(&iviscrn->order.layer_list,
844 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000845 ivilayer->on_screen = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900846 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
847 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900848
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000849 iviscrn->order.dirty = 0;
850 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900851
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900852 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
853 if (ivilayer->prop.visibility == false)
854 continue;
855
856 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900857 if (ivisurf->prop.visibility == false)
858 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000859
860 tmpview = get_weston_view(ivisurf);
861 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900862
863 weston_layer_entry_insert(&layout->layout_layer.view_list,
864 &tmpview->layer_link);
865
866 ivisurf->surface->output = iviscrn->output;
867 }
868 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900869 }
870}
871
872static void
873commit_transition(struct ivi_layout* layout)
874{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300875 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900876 return;
877 }
878
879 wl_list_insert_list(&layout->transitions->transition_list,
880 &layout->pending_transition_list);
881
882 wl_list_init(&layout->pending_transition_list);
883
884 wl_event_source_timer_update(layout->transitions->event_source, 1);
885}
886
887static void
888send_surface_prop(struct ivi_layout_surface *ivisurf)
889{
890 wl_signal_emit(&ivisurf->property_changed, ivisurf);
891 ivisurf->event_mask = 0;
892}
893
894static void
895send_layer_prop(struct ivi_layout_layer *ivilayer)
896{
897 wl_signal_emit(&ivilayer->property_changed, ivilayer);
898 ivilayer->event_mask = 0;
899}
900
901static void
902send_prop(struct ivi_layout *layout)
903{
904 struct ivi_layout_layer *ivilayer = NULL;
905 struct ivi_layout_surface *ivisurf = NULL;
906
907 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900908 if (ivilayer->event_mask)
909 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900910 }
911
912 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900913 if (ivisurf->event_mask)
914 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900915 }
916}
917
918static void
919clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
920{
921 struct ivi_layout_surface *surface_link = NULL;
922 struct ivi_layout_surface *surface_next = NULL;
923
924 wl_list_for_each_safe(surface_link, surface_next,
925 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000926 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900927 wl_list_init(&surface_link->pending.link);
928 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900929}
930
931static void
932clear_surface_order_list(struct ivi_layout_layer *ivilayer)
933{
934 struct ivi_layout_surface *surface_link = NULL;
935 struct ivi_layout_surface *surface_next = NULL;
936
937 wl_list_for_each_safe(surface_link, surface_next,
938 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000939 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900940 wl_list_init(&surface_link->order.link);
941 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900942}
943
944static void
945layer_created(struct wl_listener *listener, void *data)
946{
947 struct ivi_layout_layer *ivilayer = data;
948
949 struct listener_layout_notification *notification =
950 container_of(listener,
951 struct listener_layout_notification,
952 listener);
953
954 struct ivi_layout_notification_callback *created_callback =
955 notification->userdata;
956
957 ((layer_create_notification_func)created_callback->callback)
958 (ivilayer, created_callback->data);
959}
960
961static void
962layer_removed(struct wl_listener *listener, void *data)
963{
964 struct ivi_layout_layer *ivilayer = data;
965
966 struct listener_layout_notification *notification =
967 container_of(listener,
968 struct listener_layout_notification,
969 listener);
970
971 struct ivi_layout_notification_callback *removed_callback =
972 notification->userdata;
973
974 ((layer_remove_notification_func)removed_callback->callback)
975 (ivilayer, removed_callback->data);
976}
977
978static void
979layer_prop_changed(struct wl_listener *listener, void *data)
980{
981 struct ivi_layout_layer *ivilayer = data;
982
983 struct listener_layout_notification *layout_listener =
984 container_of(listener,
985 struct listener_layout_notification,
986 listener);
987
988 struct ivi_layout_notification_callback *prop_callback =
989 layout_listener->userdata;
990
991 ((layer_property_notification_func)prop_callback->callback)
992 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
993}
994
995static void
996surface_created(struct wl_listener *listener, void *data)
997{
998 struct ivi_layout_surface *ivisurface = data;
999
1000 struct listener_layout_notification *notification =
1001 container_of(listener,
1002 struct listener_layout_notification,
1003 listener);
1004
1005 struct ivi_layout_notification_callback *created_callback =
1006 notification->userdata;
1007
1008 ((surface_create_notification_func)created_callback->callback)
1009 (ivisurface, created_callback->data);
1010}
1011
1012static void
1013surface_removed(struct wl_listener *listener, void *data)
1014{
1015 struct ivi_layout_surface *ivisurface = data;
1016
1017 struct listener_layout_notification *notification =
1018 container_of(listener,
1019 struct listener_layout_notification,
1020 listener);
1021
1022 struct ivi_layout_notification_callback *removed_callback =
1023 notification->userdata;
1024
1025 ((surface_remove_notification_func)removed_callback->callback)
1026 (ivisurface, removed_callback->data);
1027}
1028
1029static void
1030surface_prop_changed(struct wl_listener *listener, void *data)
1031{
1032 struct ivi_layout_surface *ivisurf = data;
1033
1034 struct listener_layout_notification *layout_listener =
1035 container_of(listener,
1036 struct listener_layout_notification,
1037 listener);
1038
1039 struct ivi_layout_notification_callback *prop_callback =
1040 layout_listener->userdata;
1041
1042 ((surface_property_notification_func)prop_callback->callback)
1043 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1044
1045 ivisurf->event_mask = 0;
1046}
1047
1048static void
1049surface_configure_changed(struct wl_listener *listener,
1050 void *data)
1051{
1052 struct ivi_layout_surface *ivisurface = data;
1053
1054 struct listener_layout_notification *notification =
1055 container_of(listener,
1056 struct listener_layout_notification,
1057 listener);
1058
1059 struct ivi_layout_notification_callback *configure_changed_callback =
1060 notification->userdata;
1061
1062 ((surface_configure_notification_func)configure_changed_callback->callback)
1063 (ivisurface, configure_changed_callback->data);
1064}
1065
1066static int32_t
1067add_notification(struct wl_signal *signal,
1068 wl_notify_func_t callback,
1069 void *userdata)
1070{
1071 struct listener_layout_notification *notification = NULL;
1072
1073 notification = malloc(sizeof *notification);
1074 if (notification == NULL) {
1075 weston_log("fails to allocate memory\n");
1076 free(userdata);
1077 return IVI_FAILED;
1078 }
1079
1080 notification->listener.notify = callback;
1081 notification->userdata = userdata;
1082
1083 wl_signal_add(signal, &notification->listener);
1084
1085 return IVI_SUCCEEDED;
1086}
1087
1088static void
1089remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1090{
1091 struct wl_listener *listener = NULL;
1092 struct wl_listener *next = NULL;
1093
1094 wl_list_for_each_safe(listener, next, listener_list, link) {
1095 struct listener_layout_notification *notification =
1096 container_of(listener,
1097 struct listener_layout_notification,
1098 listener);
1099
1100 struct ivi_layout_notification_callback *notification_callback =
1101 notification->userdata;
1102
1103 if ((notification_callback->callback != callback) ||
1104 (notification_callback->data != userdata)) {
1105 continue;
1106 }
1107
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001108 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001109
1110 free(notification->userdata);
1111 free(notification);
1112 }
1113}
1114
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001115/**
1116 * Exported APIs of ivi-layout library are implemented from here.
1117 * Brief of APIs is described in ivi-layout-export.h.
1118 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001119static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001120ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1121 void *userdata)
1122{
1123 struct ivi_layout *layout = get_instance();
1124 struct ivi_layout_notification_callback *created_callback = NULL;
1125
1126 if (callback == NULL) {
1127 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1128 return IVI_FAILED;
1129 }
1130
1131 created_callback = malloc(sizeof *created_callback);
1132 if (created_callback == NULL) {
1133 weston_log("fails to allocate memory\n");
1134 return IVI_FAILED;
1135 }
1136
1137 created_callback->callback = callback;
1138 created_callback->data = userdata;
1139
1140 return add_notification(&layout->layer_notification.created,
1141 layer_created,
1142 created_callback);
1143}
1144
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001145static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001146ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1147 void *userdata)
1148{
1149 struct ivi_layout *layout = get_instance();
1150 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1151}
1152
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001153static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001154ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1155 void *userdata)
1156{
1157 struct ivi_layout *layout = get_instance();
1158 struct ivi_layout_notification_callback *removed_callback = NULL;
1159
1160 if (callback == NULL) {
1161 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1162 return IVI_FAILED;
1163 }
1164
1165 removed_callback = malloc(sizeof *removed_callback);
1166 if (removed_callback == NULL) {
1167 weston_log("fails to allocate memory\n");
1168 return IVI_FAILED;
1169 }
1170
1171 removed_callback->callback = callback;
1172 removed_callback->data = userdata;
1173 return add_notification(&layout->layer_notification.removed,
1174 layer_removed,
1175 removed_callback);
1176}
1177
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001178static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001179ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1180 void *userdata)
1181{
1182 struct ivi_layout *layout = get_instance();
1183 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1184}
1185
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001186static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001187ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1188 void *userdata)
1189{
1190 struct ivi_layout *layout = get_instance();
1191 struct ivi_layout_notification_callback *created_callback = NULL;
1192
1193 if (callback == NULL) {
1194 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1195 return IVI_FAILED;
1196 }
1197
1198 created_callback = malloc(sizeof *created_callback);
1199 if (created_callback == NULL) {
1200 weston_log("fails to allocate memory\n");
1201 return IVI_FAILED;
1202 }
1203
1204 created_callback->callback = callback;
1205 created_callback->data = userdata;
1206
1207 return add_notification(&layout->surface_notification.created,
1208 surface_created,
1209 created_callback);
1210}
1211
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001212static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001213ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1214 void *userdata)
1215{
1216 struct ivi_layout *layout = get_instance();
1217 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1218}
1219
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001220static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001221ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1222 void *userdata)
1223{
1224 struct ivi_layout *layout = get_instance();
1225 struct ivi_layout_notification_callback *removed_callback = NULL;
1226
1227 if (callback == NULL) {
1228 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1229 return IVI_FAILED;
1230 }
1231
1232 removed_callback = malloc(sizeof *removed_callback);
1233 if (removed_callback == NULL) {
1234 weston_log("fails to allocate memory\n");
1235 return IVI_FAILED;
1236 }
1237
1238 removed_callback->callback = callback;
1239 removed_callback->data = userdata;
1240
1241 return add_notification(&layout->surface_notification.removed,
1242 surface_removed,
1243 removed_callback);
1244}
1245
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001246static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001247ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1248 void *userdata)
1249{
1250 struct ivi_layout *layout = get_instance();
1251 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1252}
1253
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001254static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001255ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1256 void *userdata)
1257{
1258 struct ivi_layout *layout = get_instance();
1259 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1260 if (callback == NULL) {
1261 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1262 return IVI_FAILED;
1263 }
1264
1265 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1266 if (configure_changed_callback == NULL) {
1267 weston_log("fails to allocate memory\n");
1268 return IVI_FAILED;
1269 }
1270
1271 configure_changed_callback->callback = callback;
1272 configure_changed_callback->data = userdata;
1273
1274 return add_notification(&layout->surface_notification.configure_changed,
1275 surface_configure_changed,
1276 configure_changed_callback);
1277}
1278
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001279static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001280ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1281 void *userdata)
1282{
1283 struct ivi_layout *layout = get_instance();
1284 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1285}
1286
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001287uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001288ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1289{
1290 return ivisurf->id_surface;
1291}
1292
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001293static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001294ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1295{
1296 return ivilayer->id_layer;
1297}
1298
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001299static uint32_t
1300ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1301{
1302 return iviscrn->id_screen;
1303}
1304
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001305static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001306ivi_layout_get_layer_from_id(uint32_t id_layer)
1307{
1308 struct ivi_layout *layout = get_instance();
1309 struct ivi_layout_layer *ivilayer = NULL;
1310
1311 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1312 if (ivilayer->id_layer == id_layer) {
1313 return ivilayer;
1314 }
1315 }
1316
1317 return NULL;
1318}
1319
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001320struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001321ivi_layout_get_surface_from_id(uint32_t id_surface)
1322{
1323 struct ivi_layout *layout = get_instance();
1324 struct ivi_layout_surface *ivisurf = NULL;
1325
1326 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1327 if (ivisurf->id_surface == id_surface) {
1328 return ivisurf;
1329 }
1330 }
1331
1332 return NULL;
1333}
1334
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001335static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001336ivi_layout_get_screen_from_id(uint32_t id_screen)
1337{
1338 struct ivi_layout *layout = get_instance();
1339 struct ivi_layout_screen *iviscrn = NULL;
1340
1341 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Nobuhiko Tanibata3e710d12015-11-25 23:36:09 +09001342 if (iviscrn->id_screen == id_screen)
1343 return iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001344 }
1345
1346 return NULL;
1347}
1348
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001349static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001350ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1351 int32_t *pWidth, int32_t *pHeight)
1352{
1353 struct weston_output *output = NULL;
1354
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001355 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001356 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1357 return IVI_FAILED;
1358 }
1359
1360 output = iviscrn->output;
1361 *pWidth = output->current_mode->width;
1362 *pHeight = output->current_mode->height;
1363
1364 return IVI_SUCCEEDED;
1365}
1366
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001367static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001368ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1369 surface_property_notification_func callback,
1370 void *userdata)
1371{
1372 struct listener_layout_notification* notification = NULL;
1373 struct ivi_layout_notification_callback *prop_callback = NULL;
1374
1375 if (ivisurf == NULL || callback == NULL) {
1376 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1377 return IVI_FAILED;
1378 }
1379
1380 notification = malloc(sizeof *notification);
1381 if (notification == NULL) {
1382 weston_log("fails to allocate memory\n");
1383 return IVI_FAILED;
1384 }
1385
1386 prop_callback = malloc(sizeof *prop_callback);
1387 if (prop_callback == NULL) {
1388 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001389 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001390 return IVI_FAILED;
1391 }
1392
1393 prop_callback->callback = callback;
1394 prop_callback->data = userdata;
1395
1396 notification->listener.notify = surface_prop_changed;
1397 notification->userdata = prop_callback;
1398
1399 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1400
1401 return IVI_SUCCEEDED;
1402}
1403
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001404static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001405ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1406{
1407 if (ivilayer == NULL) {
1408 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1409 return NULL;
1410 }
1411
1412 return &ivilayer->prop;
1413}
1414
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001415static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001416ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1417{
1418 struct ivi_layout *layout = get_instance();
1419 struct ivi_layout_screen *iviscrn = NULL;
1420 int32_t length = 0;
1421 int32_t n = 0;
1422
1423 if (pLength == NULL || ppArray == NULL) {
1424 weston_log("ivi_layout_get_screens: invalid argument\n");
1425 return IVI_FAILED;
1426 }
1427
1428 length = wl_list_length(&layout->screen_list);
1429
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001430 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001431 /* the Array must be free by module which called this function */
1432 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1433 if (*ppArray == NULL) {
1434 weston_log("fails to allocate memory\n");
1435 return IVI_FAILED;
1436 }
1437
1438 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1439 (*ppArray)[n++] = iviscrn;
1440 }
1441 }
1442
1443 *pLength = length;
1444
1445 return IVI_SUCCEEDED;
1446}
1447
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001448static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001449ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1450 int32_t *pLength,
1451 struct ivi_layout_screen ***ppArray)
1452{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001453 int32_t length = 0;
1454 int32_t n = 0;
1455
1456 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1457 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1458 return IVI_FAILED;
1459 }
1460
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001461 if (ivilayer->on_screen != NULL)
1462 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001463
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001464 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001465 /* the Array must be free by module which called this function */
1466 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1467 if (*ppArray == NULL) {
1468 weston_log("fails to allocate memory\n");
1469 return IVI_FAILED;
1470 }
1471
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001472 (*ppArray)[n++] = ivilayer->on_screen;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001473 }
1474
1475 *pLength = length;
1476
1477 return IVI_SUCCEEDED;
1478}
1479
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001480static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001481ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1482{
1483 struct ivi_layout *layout = get_instance();
1484 struct ivi_layout_layer *ivilayer = NULL;
1485 int32_t length = 0;
1486 int32_t n = 0;
1487
1488 if (pLength == NULL || ppArray == NULL) {
1489 weston_log("ivi_layout_get_layers: invalid argument\n");
1490 return IVI_FAILED;
1491 }
1492
1493 length = wl_list_length(&layout->layer_list);
1494
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001495 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001496 /* the Array must be free by module which called this function */
1497 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1498 if (*ppArray == NULL) {
1499 weston_log("fails to allocate memory\n");
1500 return IVI_FAILED;
1501 }
1502
1503 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1504 (*ppArray)[n++] = ivilayer;
1505 }
1506 }
1507
1508 *pLength = length;
1509
1510 return IVI_SUCCEEDED;
1511}
1512
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001513static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001514ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1515 int32_t *pLength,
1516 struct ivi_layout_layer ***ppArray)
1517{
1518 struct ivi_layout_layer *ivilayer = NULL;
1519 int32_t length = 0;
1520 int32_t n = 0;
1521
1522 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1523 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1524 return IVI_FAILED;
1525 }
1526
1527 length = wl_list_length(&iviscrn->order.layer_list);
1528
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001529 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001530 /* the Array must be free by module which called this function */
1531 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1532 if (*ppArray == NULL) {
1533 weston_log("fails to allocate memory\n");
1534 return IVI_FAILED;
1535 }
1536
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001537 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001538 (*ppArray)[n++] = ivilayer;
1539 }
1540 }
1541
1542 *pLength = length;
1543
1544 return IVI_SUCCEEDED;
1545}
1546
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001547static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001548ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1549 int32_t *pLength,
1550 struct ivi_layout_layer ***ppArray)
1551{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001552 int32_t length = 0;
1553 int32_t n = 0;
1554
1555 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1556 weston_log("ivi_layout_getLayers: invalid argument\n");
1557 return IVI_FAILED;
1558 }
1559
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001560 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001561 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001562 length = 1;
1563 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001564 if (*ppArray == NULL) {
1565 weston_log("fails to allocate memory\n");
1566 return IVI_FAILED;
1567 }
1568
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001569 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001570 }
1571
1572 *pLength = length;
1573
1574 return IVI_SUCCEEDED;
1575}
1576
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001577static
1578int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001579ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1580{
1581 struct ivi_layout *layout = get_instance();
1582 struct ivi_layout_surface *ivisurf = NULL;
1583 int32_t length = 0;
1584 int32_t n = 0;
1585
1586 if (pLength == NULL || ppArray == NULL) {
1587 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1588 return IVI_FAILED;
1589 }
1590
1591 length = wl_list_length(&layout->surface_list);
1592
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001593 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001594 /* the Array must be free by module which called this function */
1595 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1596 if (*ppArray == NULL) {
1597 weston_log("fails to allocate memory\n");
1598 return IVI_FAILED;
1599 }
1600
1601 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1602 (*ppArray)[n++] = ivisurf;
1603 }
1604 }
1605
1606 *pLength = length;
1607
1608 return IVI_SUCCEEDED;
1609}
1610
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001611static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001612ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1613 int32_t *pLength,
1614 struct ivi_layout_surface ***ppArray)
1615{
1616 struct ivi_layout_surface *ivisurf = NULL;
1617 int32_t length = 0;
1618 int32_t n = 0;
1619
1620 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1621 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1622 return IVI_FAILED;
1623 }
1624
1625 length = wl_list_length(&ivilayer->order.surface_list);
1626
1627 if (length != 0) {
1628 /* the Array must be free by module which called this function */
1629 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1630 if (*ppArray == NULL) {
1631 weston_log("fails to allocate memory\n");
1632 return IVI_FAILED;
1633 }
1634
1635 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1636 (*ppArray)[n++] = ivisurf;
1637 }
1638 }
1639
1640 *pLength = length;
1641
1642 return IVI_SUCCEEDED;
1643}
1644
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001645static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001646ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1647 int32_t width, int32_t height)
1648{
1649 struct ivi_layout *layout = get_instance();
1650 struct ivi_layout_layer *ivilayer = NULL;
1651
1652 ivilayer = get_layer(&layout->layer_list, id_layer);
1653 if (ivilayer != NULL) {
1654 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001655 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001656 return ivilayer;
1657 }
1658
1659 ivilayer = calloc(1, sizeof *ivilayer);
1660 if (ivilayer == NULL) {
1661 weston_log("fails to allocate memory\n");
1662 return NULL;
1663 }
1664
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001665 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001666 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001667 ivilayer->layout = layout;
1668 ivilayer->id_layer = id_layer;
1669
1670 init_layer_properties(&ivilayer->prop, width, height);
1671 ivilayer->event_mask = 0;
1672
1673 wl_list_init(&ivilayer->pending.surface_list);
1674 wl_list_init(&ivilayer->pending.link);
1675 ivilayer->pending.prop = ivilayer->prop;
1676
1677 wl_list_init(&ivilayer->order.surface_list);
1678 wl_list_init(&ivilayer->order.link);
1679
1680 wl_list_insert(&layout->layer_list, &ivilayer->link);
1681
1682 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1683
1684 return ivilayer;
1685}
1686
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001687static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001688ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1689{
1690 if (ivilayer == NULL) {
1691 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1692 return;
1693 }
1694
1695 remove_all_notification(&ivilayer->property_changed.listener_list);
1696}
1697
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001698static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001699ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1700 layer_property_notification_func callback,
1701 void *userdata)
1702{
1703 if (ivilayer == NULL) {
1704 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1705 return;
1706 }
1707
1708 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1709}
1710
1711static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001712ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001713{
1714 struct ivi_layout *layout = get_instance();
1715
1716 if (ivilayer == NULL) {
1717 weston_log("ivi_layout_layer_remove: invalid argument\n");
1718 return;
1719 }
1720
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001721 if (--ivilayer->ref_count > 0)
1722 return;
1723
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001724 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1725
1726 clear_surface_pending_list(ivilayer);
1727 clear_surface_order_list(ivilayer);
1728
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001729 wl_list_remove(&ivilayer->pending.link);
1730 wl_list_remove(&ivilayer->order.link);
1731 wl_list_remove(&ivilayer->link);
1732
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001733 ivi_layout_layer_remove_notification(ivilayer);
1734
1735 free(ivilayer);
1736}
1737
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001738int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001739ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1740 bool newVisibility)
1741{
1742 struct ivi_layout_layer_properties *prop = NULL;
1743
1744 if (ivilayer == NULL) {
1745 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1746 return IVI_FAILED;
1747 }
1748
1749 prop = &ivilayer->pending.prop;
1750 prop->visibility = newVisibility;
1751
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001752 if (ivilayer->prop.visibility != newVisibility)
1753 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1754 else
1755 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001756
1757 return IVI_SUCCEEDED;
1758}
1759
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001760static bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001761ivi_layout_layer_get_visibility(struct ivi_layout_layer *ivilayer)
1762{
1763 if (ivilayer == NULL) {
1764 weston_log("ivi_layout_layer_get_visibility: invalid argument\n");
1765 return false;
1766 }
1767
1768 return ivilayer->prop.visibility;
1769}
1770
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001771int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001772ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1773 wl_fixed_t opacity)
1774{
1775 struct ivi_layout_layer_properties *prop = NULL;
1776
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001777 if (ivilayer == NULL ||
1778 opacity < wl_fixed_from_double(0.0) ||
1779 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001780 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1781 return IVI_FAILED;
1782 }
1783
1784 prop = &ivilayer->pending.prop;
1785 prop->opacity = opacity;
1786
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001787 if (ivilayer->prop.opacity != opacity)
1788 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1789 else
1790 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001791
1792 return IVI_SUCCEEDED;
1793}
1794
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001795wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001796ivi_layout_layer_get_opacity(struct ivi_layout_layer *ivilayer)
1797{
1798 if (ivilayer == NULL) {
1799 weston_log("ivi_layout_layer_get_opacity: invalid argument\n");
1800 return wl_fixed_from_double(0.0);
1801 }
1802
1803 return ivilayer->prop.opacity;
1804}
1805
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001806static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001807ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1808 int32_t x, int32_t y,
1809 int32_t width, int32_t height)
1810{
1811 struct ivi_layout_layer_properties *prop = NULL;
1812
1813 if (ivilayer == NULL) {
1814 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1815 return IVI_FAILED;
1816 }
1817
1818 prop = &ivilayer->pending.prop;
1819 prop->source_x = x;
1820 prop->source_y = y;
1821 prop->source_width = width;
1822 prop->source_height = height;
1823
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001824 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1825 ivilayer->prop.source_width != width ||
1826 ivilayer->prop.source_height != height)
1827 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1828 else
1829 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001830
1831 return IVI_SUCCEEDED;
1832}
1833
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001834static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001835ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1836 int32_t x, int32_t y,
1837 int32_t width, int32_t height)
1838{
1839 struct ivi_layout_layer_properties *prop = NULL;
1840
1841 if (ivilayer == NULL) {
1842 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1843 return IVI_FAILED;
1844 }
1845
1846 prop = &ivilayer->pending.prop;
1847 prop->dest_x = x;
1848 prop->dest_y = y;
1849 prop->dest_width = width;
1850 prop->dest_height = height;
1851
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001852 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1853 ivilayer->prop.dest_width != width ||
1854 ivilayer->prop.dest_height != height)
1855 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1856 else
1857 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001858
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_get_dimension(struct ivi_layout_layer *ivilayer,
1864 int32_t *dest_width, int32_t *dest_height)
1865{
1866 if (ivilayer == NULL || dest_width == NULL || dest_height == NULL) {
1867 weston_log("ivi_layout_layer_get_dimension: invalid argument\n");
1868 return IVI_FAILED;
1869 }
1870
1871 *dest_width = ivilayer->prop.dest_width;
1872 *dest_height = ivilayer->prop.dest_height;
1873
1874 return IVI_SUCCEEDED;
1875}
1876
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001877static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001878ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
1879 int32_t dest_width, int32_t dest_height)
1880{
1881 struct ivi_layout_layer_properties *prop = NULL;
1882
1883 if (ivilayer == NULL) {
1884 weston_log("ivi_layout_layer_set_dimension: invalid argument\n");
1885 return IVI_FAILED;
1886 }
1887
1888 prop = &ivilayer->pending.prop;
1889
1890 prop->dest_width = dest_width;
1891 prop->dest_height = dest_height;
1892
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001893 if (ivilayer->prop.dest_width != dest_width ||
1894 ivilayer->prop.dest_height != dest_height)
1895 ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
1896 else
1897 ivilayer->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001898
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_get_position(struct ivi_layout_layer *ivilayer,
1904 int32_t *dest_x, int32_t *dest_y)
1905{
1906 if (ivilayer == NULL || dest_x == NULL || dest_y == NULL) {
1907 weston_log("ivi_layout_layer_get_position: invalid argument\n");
1908 return IVI_FAILED;
1909 }
1910
1911 *dest_x = ivilayer->prop.dest_x;
1912 *dest_y = ivilayer->prop.dest_y;
1913
1914 return IVI_SUCCEEDED;
1915}
1916
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001917int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001918ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
1919 int32_t dest_x, int32_t dest_y)
1920{
1921 struct ivi_layout_layer_properties *prop = NULL;
1922
1923 if (ivilayer == NULL) {
1924 weston_log("ivi_layout_layer_set_position: invalid argument\n");
1925 return IVI_FAILED;
1926 }
1927
1928 prop = &ivilayer->pending.prop;
1929 prop->dest_x = dest_x;
1930 prop->dest_y = dest_y;
1931
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001932 if (ivilayer->prop.dest_x != dest_x || ivilayer->prop.dest_y != dest_y)
1933 ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
1934 else
1935 ivilayer->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001936
1937 return IVI_SUCCEEDED;
1938}
1939
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001940static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001941ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1942 enum wl_output_transform orientation)
1943{
1944 struct ivi_layout_layer_properties *prop = NULL;
1945
1946 if (ivilayer == NULL) {
1947 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1948 return IVI_FAILED;
1949 }
1950
1951 prop = &ivilayer->pending.prop;
1952 prop->orientation = orientation;
1953
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001954 if (ivilayer->prop.orientation != orientation)
1955 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1956 else
1957 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001958
1959 return IVI_SUCCEEDED;
1960}
1961
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001962static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001963ivi_layout_layer_get_orientation(struct ivi_layout_layer *ivilayer)
1964{
1965 if (ivilayer == NULL) {
1966 weston_log("ivi_layout_layer_get_orientation: invalid argument\n");
1967 return 0;
1968 }
1969
1970 return ivilayer->prop.orientation;
1971}
1972
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001973int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001974ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1975 struct ivi_layout_surface **pSurface,
1976 int32_t number)
1977{
1978 struct ivi_layout *layout = get_instance();
1979 struct ivi_layout_surface *ivisurf = NULL;
1980 struct ivi_layout_surface *next = NULL;
1981 uint32_t *id_surface = NULL;
1982 int32_t i = 0;
1983
1984 if (ivilayer == NULL) {
1985 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1986 return IVI_FAILED;
1987 }
1988
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001989 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001990
1991 for (i = 0; i < number; i++) {
1992 id_surface = &pSurface[i]->id_surface;
1993
1994 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
1995 if (*id_surface != ivisurf->id_surface) {
1996 continue;
1997 }
1998
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001999 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002000 wl_list_insert(&ivilayer->pending.surface_list,
2001 &ivisurf->pending.link);
2002 break;
2003 }
2004 }
2005
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002006 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002007
2008 return IVI_SUCCEEDED;
2009}
2010
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002011int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002012ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
2013 bool newVisibility)
2014{
2015 struct ivi_layout_surface_properties *prop = NULL;
2016
2017 if (ivisurf == NULL) {
2018 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
2019 return IVI_FAILED;
2020 }
2021
2022 prop = &ivisurf->pending.prop;
2023 prop->visibility = newVisibility;
2024
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002025 if (ivisurf->prop.visibility != newVisibility)
2026 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
2027 else
2028 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002029
2030 return IVI_SUCCEEDED;
2031}
2032
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002033bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002034ivi_layout_surface_get_visibility(struct ivi_layout_surface *ivisurf)
2035{
2036 if (ivisurf == NULL) {
2037 weston_log("ivi_layout_surface_get_visibility: invalid argument\n");
2038 return false;
2039 }
2040
2041 return ivisurf->prop.visibility;
2042}
2043
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002044int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002045ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
2046 wl_fixed_t opacity)
2047{
2048 struct ivi_layout_surface_properties *prop = NULL;
2049
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09002050 if (ivisurf == NULL ||
2051 opacity < wl_fixed_from_double(0.0) ||
2052 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002053 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
2054 return IVI_FAILED;
2055 }
2056
2057 prop = &ivisurf->pending.prop;
2058 prop->opacity = opacity;
2059
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002060 if (ivisurf->prop.opacity != opacity)
2061 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
2062 else
2063 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002064
2065 return IVI_SUCCEEDED;
2066}
2067
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002068wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002069ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
2070{
2071 if (ivisurf == NULL) {
2072 weston_log("ivi_layout_surface_get_opacity: invalid argument\n");
2073 return wl_fixed_from_double(0.0);
2074 }
2075
2076 return ivisurf->prop.opacity;
2077}
2078
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002079int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002080ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
2081 int32_t x, int32_t y,
2082 int32_t width, int32_t height)
2083{
2084 struct ivi_layout_surface_properties *prop = NULL;
2085
2086 if (ivisurf == NULL) {
2087 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
2088 return IVI_FAILED;
2089 }
2090
2091 prop = &ivisurf->pending.prop;
2092 prop->start_x = prop->dest_x;
2093 prop->start_y = prop->dest_y;
2094 prop->dest_x = x;
2095 prop->dest_y = y;
2096 prop->start_width = prop->dest_width;
2097 prop->start_height = prop->dest_height;
2098 prop->dest_width = width;
2099 prop->dest_height = height;
2100
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002101 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2102 ivisurf->prop.dest_width != width ||
2103 ivisurf->prop.dest_height != height)
2104 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2105 else
2106 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002107
2108 return IVI_SUCCEEDED;
2109}
2110
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002111static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002112ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
2113 int32_t dest_width, int32_t dest_height)
2114{
2115 struct ivi_layout_surface_properties *prop = NULL;
2116
2117 if (ivisurf == NULL) {
2118 weston_log("ivi_layout_surface_set_dimension: invalid argument\n");
2119 return IVI_FAILED;
2120 }
2121
2122 prop = &ivisurf->pending.prop;
2123 prop->dest_width = dest_width;
2124 prop->dest_height = dest_height;
2125
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002126 if (ivisurf->prop.dest_width != dest_width ||
2127 ivisurf->prop.dest_height != dest_height)
2128 ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
2129 else
2130 ivisurf->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002131
2132 return IVI_SUCCEEDED;
2133}
2134
2135int32_t
2136ivi_layout_surface_get_dimension(struct ivi_layout_surface *ivisurf,
2137 int32_t *dest_width, int32_t *dest_height)
2138{
2139 if (ivisurf == NULL || dest_width == NULL || dest_height == NULL) {
2140 weston_log("ivi_layout_surface_get_dimension: invalid argument\n");
2141 return IVI_FAILED;
2142 }
2143
2144 *dest_width = ivisurf->prop.dest_width;
2145 *dest_height = ivisurf->prop.dest_height;
2146
2147 return IVI_SUCCEEDED;
2148}
2149
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002150static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002151ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
2152 int32_t dest_x, int32_t dest_y)
2153{
2154 struct ivi_layout_surface_properties *prop = NULL;
2155
2156 if (ivisurf == NULL) {
2157 weston_log("ivi_layout_surface_set_position: invalid argument\n");
2158 return IVI_FAILED;
2159 }
2160
2161 prop = &ivisurf->pending.prop;
2162 prop->dest_x = dest_x;
2163 prop->dest_y = dest_y;
2164
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002165 if (ivisurf->prop.dest_x != dest_x || ivisurf->prop.dest_y != dest_y)
2166 ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
2167 else
2168 ivisurf->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002169
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_get_position(struct ivi_layout_surface *ivisurf,
2175 int32_t *dest_x, int32_t *dest_y)
2176{
2177 if (ivisurf == NULL || dest_x == NULL || dest_y == NULL) {
2178 weston_log("ivi_layout_surface_get_position: invalid argument\n");
2179 return IVI_FAILED;
2180 }
2181
2182 *dest_x = ivisurf->prop.dest_x;
2183 *dest_y = ivisurf->prop.dest_y;
2184
2185 return IVI_SUCCEEDED;
2186}
2187
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002188static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002189ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2190 enum wl_output_transform orientation)
2191{
2192 struct ivi_layout_surface_properties *prop = NULL;
2193
2194 if (ivisurf == NULL) {
2195 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2196 return IVI_FAILED;
2197 }
2198
2199 prop = &ivisurf->pending.prop;
2200 prop->orientation = orientation;
2201
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002202 if (ivisurf->prop.orientation != orientation)
2203 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2204 else
2205 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002206
2207 return IVI_SUCCEEDED;
2208}
2209
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002210static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002211ivi_layout_surface_get_orientation(struct ivi_layout_surface *ivisurf)
2212{
2213 if (ivisurf == NULL) {
2214 weston_log("ivi_layout_surface_get_orientation: invalid argument\n");
2215 return 0;
2216 }
2217
2218 return ivisurf->prop.orientation;
2219}
2220
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002221static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002222ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2223 struct ivi_layout_layer *addlayer)
2224{
2225 struct ivi_layout *layout = get_instance();
2226 struct ivi_layout_layer *ivilayer = NULL;
2227 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002228
2229 if (iviscrn == NULL || addlayer == NULL) {
2230 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2231 return IVI_FAILED;
2232 }
2233
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00002234 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002235 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2236 return IVI_SUCCEEDED;
2237 }
2238
2239 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2240 if (ivilayer->id_layer == addlayer->id_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002241 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002242 wl_list_insert(&iviscrn->pending.layer_list,
2243 &ivilayer->pending.link);
2244 break;
2245 }
2246 }
2247
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002248 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002249
2250 return IVI_SUCCEEDED;
2251}
2252
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002253static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002254ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2255 struct ivi_layout_layer **pLayer,
2256 const int32_t number)
2257{
2258 struct ivi_layout *layout = get_instance();
2259 struct ivi_layout_layer *ivilayer = NULL;
2260 struct ivi_layout_layer *next = NULL;
2261 uint32_t *id_layer = NULL;
2262 int32_t i = 0;
2263
2264 if (iviscrn == NULL) {
2265 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2266 return IVI_FAILED;
2267 }
2268
2269 wl_list_for_each_safe(ivilayer, next,
2270 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002271 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002272 wl_list_init(&ivilayer->pending.link);
2273 }
2274
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002275 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002276
2277 for (i = 0; i < number; i++) {
2278 id_layer = &pLayer[i]->id_layer;
2279 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2280 if (*id_layer != ivilayer->id_layer) {
2281 continue;
2282 }
2283
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002284 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002285 wl_list_insert(&iviscrn->pending.layer_list,
2286 &ivilayer->pending.link);
2287 break;
2288 }
2289 }
2290
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002291 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002292
2293 return IVI_SUCCEEDED;
2294}
2295
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002296static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002297ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2298{
2299 return iviscrn->output;
2300}
2301
2302/**
2303 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2304 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2305 * This function is used to get the result of drawing by clients.
2306 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002307static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002308ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2309{
2310 return ivisurf != NULL ? ivisurf->surface : NULL;
2311}
2312
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002313static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002314ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2315 int32_t *width, int32_t *height,
2316 int32_t *stride)
2317{
2318 int32_t w;
2319 int32_t h;
2320 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2321
2322 if (ivisurf == NULL || ivisurf->surface == NULL) {
2323 weston_log("%s: invalid argument\n", __func__);
2324 return IVI_FAILED;
2325 }
2326
2327 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2328
2329 if (width != NULL)
2330 *width = w;
2331
2332 if (height != NULL)
2333 *height = h;
2334
2335 if (stride != NULL)
2336 *stride = w * bytespp;
2337
2338 return IVI_SUCCEEDED;
2339}
2340
2341static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002342ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2343 layer_property_notification_func callback,
2344 void *userdata)
2345{
2346 struct ivi_layout_notification_callback *prop_callback = NULL;
2347
2348 if (ivilayer == NULL || callback == NULL) {
2349 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2350 return IVI_FAILED;
2351 }
2352
2353 prop_callback = malloc(sizeof *prop_callback);
2354 if (prop_callback == NULL) {
2355 weston_log("fails to allocate memory\n");
2356 return IVI_FAILED;
2357 }
2358
2359 prop_callback->callback = callback;
2360 prop_callback->data = userdata;
2361
2362 return add_notification(&ivilayer->property_changed,
2363 layer_prop_changed,
2364 prop_callback);
2365}
2366
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002367static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002368ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2369{
2370 if (ivisurf == NULL) {
2371 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2372 return NULL;
2373 }
2374
2375 return &ivisurf->prop;
2376}
2377
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002378static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002379ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2380 struct ivi_layout_surface *addsurf)
2381{
2382 struct ivi_layout *layout = get_instance();
2383 struct ivi_layout_surface *ivisurf = NULL;
2384 struct ivi_layout_surface *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002385
2386 if (ivilayer == NULL || addsurf == NULL) {
2387 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2388 return IVI_FAILED;
2389 }
2390
Ucan, Emre (ADITG/SW1)4a183642015-08-28 12:59:04 +00002391 if (addsurf->on_layer == ivilayer) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002392 weston_log("ivi_layout_layer_add_surface: addsurf is already available\n");
2393 return IVI_SUCCEEDED;
2394 }
2395
2396 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2397 if (ivisurf->id_surface == addsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002398 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002399 wl_list_insert(&ivilayer->pending.surface_list,
2400 &ivisurf->pending.link);
2401 break;
2402 }
2403 }
2404
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002405 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002406
2407 return IVI_SUCCEEDED;
2408}
2409
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002410static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002411ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2412 struct ivi_layout_surface *remsurf)
2413{
2414 struct ivi_layout_surface *ivisurf = NULL;
2415 struct ivi_layout_surface *next = NULL;
2416
2417 if (ivilayer == NULL || remsurf == NULL) {
2418 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2419 return;
2420 }
2421
2422 wl_list_for_each_safe(ivisurf, next,
2423 &ivilayer->pending.surface_list, pending.link) {
2424 if (ivisurf->id_surface == remsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002425 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002426 wl_list_init(&ivisurf->pending.link);
2427 break;
2428 }
2429 }
2430
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002431 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002432}
2433
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002434static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002435ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2436 int32_t x, int32_t y,
2437 int32_t width, int32_t height)
2438{
2439 struct ivi_layout_surface_properties *prop = NULL;
2440
2441 if (ivisurf == NULL) {
2442 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2443 return IVI_FAILED;
2444 }
2445
2446 prop = &ivisurf->pending.prop;
2447 prop->source_x = x;
2448 prop->source_y = y;
2449 prop->source_width = width;
2450 prop->source_height = height;
2451
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002452 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2453 ivisurf->prop.source_width != width ||
2454 ivisurf->prop.source_height != height)
2455 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2456 else
2457 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002458
2459 return IVI_SUCCEEDED;
2460}
2461
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002462int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002463ivi_layout_commit_changes(void)
2464{
2465 struct ivi_layout *layout = get_instance();
2466
2467 commit_surface_list(layout);
2468 commit_layer_list(layout);
2469 commit_screen_list(layout);
2470
2471 commit_transition(layout);
2472
2473 commit_changes(layout);
2474 send_prop(layout);
2475 weston_compositor_schedule_repaint(layout->compositor);
2476
2477 return IVI_SUCCEEDED;
2478}
2479
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002480static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002481ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2482 enum ivi_layout_transition_type type,
2483 uint32_t duration)
2484{
2485 if (ivilayer == NULL) {
2486 weston_log("%s: invalid argument\n", __func__);
2487 return -1;
2488 }
2489
2490 ivilayer->pending.prop.transition_type = type;
2491 ivilayer->pending.prop.transition_duration = duration;
2492
2493 return 0;
2494}
2495
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002496static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002497ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2498 uint32_t is_fade_in,
2499 double start_alpha, double end_alpha)
2500{
2501 if (ivilayer == NULL) {
2502 weston_log("%s: invalid argument\n", __func__);
2503 return -1;
2504 }
2505
2506 ivilayer->pending.prop.is_fade_in = is_fade_in;
2507 ivilayer->pending.prop.start_alpha = start_alpha;
2508 ivilayer->pending.prop.end_alpha = end_alpha;
2509
2510 return 0;
2511}
2512
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002513static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002514ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2515 uint32_t duration)
2516{
2517 struct ivi_layout_surface_properties *prop;
2518
2519 if (ivisurf == NULL) {
2520 weston_log("%s: invalid argument\n", __func__);
2521 return -1;
2522 }
2523
2524 prop = &ivisurf->pending.prop;
2525 prop->transition_duration = duration*10;
2526 return 0;
2527}
2528
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002529static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002530ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2531 enum ivi_layout_transition_type type,
2532 uint32_t duration)
2533{
2534 struct ivi_layout_surface_properties *prop;
2535
2536 if (ivisurf == NULL) {
2537 weston_log("%s: invalid argument\n", __func__);
2538 return -1;
2539 }
2540
2541 prop = &ivisurf->pending.prop;
2542 prop->transition_type = type;
2543 prop->transition_duration = duration;
2544 return 0;
2545}
2546
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002547static int32_t
2548ivi_layout_surface_dump(struct weston_surface *surface,
2549 void *target, size_t size,int32_t x, int32_t y,
2550 int32_t width, int32_t height)
2551{
2552 int result = 0;
2553
2554 if (surface == NULL) {
2555 weston_log("%s: invalid argument\n", __func__);
2556 return IVI_FAILED;
2557 }
2558
2559 result = weston_surface_copy_content(
2560 surface, target, size,
2561 x, y, width, height);
2562
2563 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2564}
2565
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002566/**
2567 * methods of interaction between ivi-shell with ivi-layout
2568 */
2569struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002570ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2571{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002572 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002573 return NULL;
2574
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002575 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002576}
2577
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002578void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002579ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2580 int32_t width, int32_t height)
2581{
2582 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002583
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002584 /* emit callback which is set by ivi-layout api user */
2585 wl_signal_emit(&layout->surface_notification.configure_changed,
2586 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002587}
2588
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002589static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002590ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2591 ivi_controller_surface_content_callback callback,
2592 void* userdata)
2593{
2594 int32_t ret = IVI_FAILED;
2595
2596 if (ivisurf != NULL) {
2597 ivisurf->content_observer.callback = callback;
2598 ivisurf->content_observer.userdata = userdata;
2599 ret = IVI_SUCCEEDED;
2600 }
2601 return ret;
2602}
2603
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002604struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002605ivi_layout_surface_create(struct weston_surface *wl_surface,
2606 uint32_t id_surface)
2607{
2608 struct ivi_layout *layout = get_instance();
2609 struct ivi_layout_surface *ivisurf = NULL;
2610 struct weston_view *tmpview = NULL;
2611
2612 if (wl_surface == NULL) {
2613 weston_log("ivi_layout_surface_create: invalid argument\n");
2614 return NULL;
2615 }
2616
2617 ivisurf = get_surface(&layout->surface_list, id_surface);
2618 if (ivisurf != NULL) {
2619 if (ivisurf->surface != NULL) {
2620 weston_log("id_surface(%d) is already created\n", id_surface);
2621 return NULL;
2622 }
2623 }
2624
2625 ivisurf = calloc(1, sizeof *ivisurf);
2626 if (ivisurf == NULL) {
2627 weston_log("fails to allocate memory\n");
2628 return NULL;
2629 }
2630
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002631 wl_signal_init(&ivisurf->property_changed);
2632 wl_signal_init(&ivisurf->configured);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002633 ivisurf->id_surface = id_surface;
2634 ivisurf->layout = layout;
2635
2636 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002637
2638 tmpview = weston_view_create(wl_surface);
2639 if (tmpview == NULL) {
2640 weston_log("fails to allocate memory\n");
2641 }
2642
2643 ivisurf->surface->width_from_buffer = 0;
2644 ivisurf->surface->height_from_buffer = 0;
2645
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002646 weston_matrix_init(&ivisurf->transform.matrix);
2647 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002648
2649 init_surface_properties(&ivisurf->prop);
2650 ivisurf->event_mask = 0;
2651
2652 ivisurf->pending.prop = ivisurf->prop;
2653 wl_list_init(&ivisurf->pending.link);
2654
2655 wl_list_init(&ivisurf->order.link);
2656 wl_list_init(&ivisurf->order.layer_list);
2657
2658 wl_list_insert(&layout->surface_list, &ivisurf->link);
2659
2660 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2661
2662 return ivisurf;
2663}
2664
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002665void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002666ivi_layout_init_with_compositor(struct weston_compositor *ec)
2667{
2668 struct ivi_layout *layout = get_instance();
2669
2670 layout->compositor = ec;
2671
2672 wl_list_init(&layout->surface_list);
2673 wl_list_init(&layout->layer_list);
2674 wl_list_init(&layout->screen_list);
2675
2676 wl_signal_init(&layout->layer_notification.created);
2677 wl_signal_init(&layout->layer_notification.removed);
2678
2679 wl_signal_init(&layout->surface_notification.created);
2680 wl_signal_init(&layout->surface_notification.removed);
2681 wl_signal_init(&layout->surface_notification.configure_changed);
2682
2683 /* Add layout_layer at the last of weston_compositor.layer_list */
2684 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2685
2686 create_screen(ec);
2687
2688 layout->transitions = ivi_layout_transition_set_create(ec);
2689 wl_list_init(&layout->pending_transition_list);
2690}
2691
2692
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002693void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002694ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2695 struct wl_listener* listener)
2696{
2697 wl_signal_add(&ivisurf->configured, listener);
2698}
2699
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002700static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002701 /**
2702 * commit all changes
2703 */
2704 .commit_changes = ivi_layout_commit_changes,
2705
2706 /**
2707 * surface controller interfaces
2708 */
2709 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2710 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2711 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2712 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2713 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2714 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2715 .get_surfaces = ivi_layout_get_surfaces,
2716 .get_id_of_surface = ivi_layout_get_id_of_surface,
2717 .get_surface_from_id = ivi_layout_get_surface_from_id,
2718 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2719 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2720 .surface_set_visibility = ivi_layout_surface_set_visibility,
2721 .surface_get_visibility = ivi_layout_surface_get_visibility,
2722 .surface_set_opacity = ivi_layout_surface_set_opacity,
2723 .surface_get_opacity = ivi_layout_surface_get_opacity,
2724 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2725 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
2726 .surface_set_position = ivi_layout_surface_set_position,
2727 .surface_get_position = ivi_layout_surface_get_position,
2728 .surface_set_dimension = ivi_layout_surface_set_dimension,
2729 .surface_get_dimension = ivi_layout_surface_get_dimension,
2730 .surface_set_orientation = ivi_layout_surface_set_orientation,
2731 .surface_get_orientation = ivi_layout_surface_get_orientation,
2732 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2733 .surface_add_notification = ivi_layout_surface_add_notification,
2734 .surface_remove_notification = ivi_layout_surface_remove_notification,
2735 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2736 .surface_set_transition = ivi_layout_surface_set_transition,
2737 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2738
2739 /**
2740 * layer controller interfaces
2741 */
2742 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2743 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2744 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2745 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2746 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002747 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002748 .get_layers = ivi_layout_get_layers,
2749 .get_id_of_layer = ivi_layout_get_id_of_layer,
2750 .get_layer_from_id = ivi_layout_get_layer_from_id,
2751 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2752 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2753 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2754 .layer_set_visibility = ivi_layout_layer_set_visibility,
2755 .layer_get_visibility = ivi_layout_layer_get_visibility,
2756 .layer_set_opacity = ivi_layout_layer_set_opacity,
2757 .layer_get_opacity = ivi_layout_layer_get_opacity,
2758 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2759 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
2760 .layer_set_position = ivi_layout_layer_set_position,
2761 .layer_get_position = ivi_layout_layer_get_position,
2762 .layer_set_dimension = ivi_layout_layer_set_dimension,
2763 .layer_get_dimension = ivi_layout_layer_get_dimension,
2764 .layer_set_orientation = ivi_layout_layer_set_orientation,
2765 .layer_get_orientation = ivi_layout_layer_get_orientation,
2766 .layer_add_surface = ivi_layout_layer_add_surface,
2767 .layer_remove_surface = ivi_layout_layer_remove_surface,
2768 .layer_set_render_order = ivi_layout_layer_set_render_order,
2769 .layer_add_notification = ivi_layout_layer_add_notification,
2770 .layer_remove_notification = ivi_layout_layer_remove_notification,
2771 .layer_set_transition = ivi_layout_layer_set_transition,
2772
2773 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002774 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002775 */
2776 .get_screen_from_id = ivi_layout_get_screen_from_id,
2777 .get_screen_resolution = ivi_layout_get_screen_resolution,
2778 .get_screens = ivi_layout_get_screens,
2779 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2780 .screen_add_layer = ivi_layout_screen_add_layer,
2781 .screen_set_render_order = ivi_layout_screen_set_render_order,
2782 .screen_get_output = ivi_layout_screen_get_output,
2783
2784 /**
2785 * animation
2786 */
2787 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002788 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2789
2790 /**
2791 * surface content dumping for debugging
2792 */
2793 .surface_get_size = ivi_layout_surface_get_size,
2794 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002795
2796 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002797 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002798 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002799 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002800 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2801
2802 /**
2803 * screen controller interfaces part2
2804 */
2805 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002806};
2807
2808int
2809load_controller_modules(struct weston_compositor *compositor, const char *modules,
2810 int *argc, char *argv[])
2811{
2812 const char *p, *end;
2813 char buffer[256];
2814 int (*controller_module_init)(struct weston_compositor *compositor,
2815 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002816 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002817 size_t interface_version);
2818
2819 if (modules == NULL)
2820 return 0;
2821
2822 p = modules;
2823 while (*p) {
2824 end = strchrnul(p, ',');
2825 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2826
2827 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002828 if (!controller_module_init)
2829 return -1;
2830
2831 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002832 &ivi_layout_interface,
2833 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002834 weston_log("ivi-shell: Initialization of controller module fails");
2835 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002836 }
2837
2838 p = end;
2839 while (*p == ',')
2840 p++;
2841 }
2842
2843 return 0;
2844}