blob: 732a557ee7514dedce17caa6a97d6e9f56c9fef3 [file] [log] [blame]
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001/*
2 * Copyright (C) 2013 DENSO CORPORATION
3 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090011 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090024 */
25
26/**
27 * Implementation of ivi-layout library. The actual view on ivi_screen is
28 * not updated till calling ivi_layout_commit_changes. A overview from
29 * calling API for updating properties of ivi_surface/ivi_layer to asking
30 * compositor to compose them by using weston_compositor_schedule_repaint,
31 * 0/ initialize this library by ivi_layout_init_with_compositor
32 * with (struct weston_compositor *ec) from ivi-shell.
33 * 1/ When a API for updating properties of ivi_surface/ivi_layer, it updates
34 * pending prop of ivi_surface/ivi_layer/ivi_screen which are structure to
35 * store properties.
36 * 2/ Before calling commitChanges, in case of calling a API to get a property,
37 * return current property, not pending property.
38 * 3/ At the timing of calling ivi_layout_commitChanges, pending properties
39 * are applied to properties.
40 *
41 * *) ivi_layout_commitChanges is also called by transition animation
42 * per each frame. See ivi-layout-transition.c in details. Transition
43 * animation interpolates frames between previous properties of ivi_surface
44 * and new ones.
45 * For example, when a property of ivi_surface is changed from invisibility
46 * to visibility, it behaves like fade-in. When ivi_layout_commitChange is
47 * called during transition animation, it cancels the transition and
48 * re-start transition to new properties from current properties of final
49 * frame just before the the cancellation.
50 *
51 * 4/ According properties, set transformation by using weston_matrix and
52 * weston_view per ivi_surfaces and ivi_layers in while loop.
53 * 5/ Set damage and trigger transform by using weston_view_geometry_dirty.
54 * 6/ Notify update of properties.
55 * 7/ Trigger composition by weston_compositor_schedule_repaint.
56 *
57 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090058#include "config.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090059
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090060#include <string.h>
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +000061#include <assert.h>
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090062
63#include "compositor.h"
64#include "ivi-layout-export.h"
65#include "ivi-layout-private.h"
66
Jon Cruz867d50e2015-06-15 15:37:10 -070067#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070068#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090069
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +090070#define max(a, b) ((a) > (b) ? (a) : (b))
71
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090072struct listener_layout_notification {
73 void *userdata;
74 struct wl_listener listener;
75};
76
77struct ivi_layout;
78
79struct ivi_layout_screen {
80 struct wl_list link;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090081 uint32_t id_screen;
82
83 struct ivi_layout *layout;
84 struct weston_output *output;
85
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090086 struct {
87 struct wl_list layer_list;
88 struct wl_list link;
89 } pending;
90
91 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +000092 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090093 struct wl_list layer_list;
94 struct wl_list link;
95 } order;
96};
97
98struct ivi_layout_notification_callback {
99 void *callback;
100 void *data;
101};
102
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900103struct ivi_rectangle
104{
105 int32_t x;
106 int32_t y;
107 int32_t width;
108 int32_t height;
109};
110
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900111static void
112remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
113
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900114static struct ivi_layout ivilayout = {0};
115
116struct ivi_layout *
117get_instance(void)
118{
119 return &ivilayout;
120}
121
122/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900123 * Internal API to add/remove a ivi_layer to/from ivi_screen.
124 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900125static struct ivi_layout_surface *
126get_surface(struct wl_list *surf_list, uint32_t id_surface)
127{
128 struct ivi_layout_surface *ivisurf;
129
130 wl_list_for_each(ivisurf, surf_list, link) {
131 if (ivisurf->id_surface == id_surface) {
132 return ivisurf;
133 }
134 }
135
136 return NULL;
137}
138
139static struct ivi_layout_layer *
140get_layer(struct wl_list *layer_list, uint32_t id_layer)
141{
142 struct ivi_layout_layer *ivilayer;
143
144 wl_list_for_each(ivilayer, layer_list, link) {
145 if (ivilayer->id_layer == id_layer) {
146 return ivilayer;
147 }
148 }
149
150 return NULL;
151}
152
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000153static struct weston_view *
154get_weston_view(struct ivi_layout_surface *ivisurf)
155{
156 struct weston_view *view = NULL;
157
158 assert(ivisurf->surface != NULL);
159
160 /* One view per surface */
161 if(wl_list_empty(&ivisurf->surface->views))
162 view = NULL;
163 else
164 view = wl_container_of(ivisurf->surface->views.next, view, surface_link);
165
166 return view;
167}
168
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900169static void
170remove_configured_listener(struct ivi_layout_surface *ivisurf)
171{
172 struct wl_listener *link = NULL;
173 struct wl_listener *next = NULL;
174
175 wl_list_for_each_safe(link, next, &ivisurf->configured.listener_list, link) {
176 wl_list_remove(&link->link);
177 }
178}
179
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900180static void
181remove_all_notification(struct wl_list *listener_list)
182{
183 struct wl_listener *listener = NULL;
184 struct wl_listener *next = NULL;
185
186 wl_list_for_each_safe(listener, next, listener_list, link) {
187 struct listener_layout_notification *notification = NULL;
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000188 wl_list_remove(&listener->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900189
190 notification =
191 container_of(listener,
192 struct listener_layout_notification,
193 listener);
194
195 free(notification->userdata);
196 free(notification);
197 }
198}
199
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900200static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900201ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
202{
203 if (ivisurf == NULL) {
204 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
205 return;
206 }
207
208 remove_all_notification(&ivisurf->property_changed.listener_list);
209}
210
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900211static void
212ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
213 surface_property_notification_func callback,
214 void *userdata)
215{
216 if (ivisurf == NULL) {
217 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
218 return;
219 }
220
221 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
222}
223
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900224/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900225 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900226 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900227void
228ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900229{
230 struct ivi_layout *layout = get_instance();
231
232 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900233 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900234 return;
235 }
236
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900237 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900238 wl_list_remove(&ivisurf->pending.link);
239 wl_list_remove(&ivisurf->order.link);
240 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900241
242 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
243
244 remove_configured_listener(ivisurf);
245
246 ivi_layout_surface_remove_notification(ivisurf);
247
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900248 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900249}
250
251/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900252 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
253 * Called by ivi_layout_init_with_compositor.
254 */
255static void
256create_screen(struct weston_compositor *ec)
257{
258 struct ivi_layout *layout = get_instance();
259 struct ivi_layout_screen *iviscrn = NULL;
260 struct weston_output *output = NULL;
261 int32_t count = 0;
262
263 wl_list_for_each(output, &ec->output_list, link) {
264 iviscrn = calloc(1, sizeof *iviscrn);
265 if (iviscrn == NULL) {
266 weston_log("fails to allocate memory\n");
267 continue;
268 }
269
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900270 iviscrn->layout = layout;
271
272 iviscrn->id_screen = count;
273 count++;
274
275 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900276
277 wl_list_init(&iviscrn->pending.layer_list);
278 wl_list_init(&iviscrn->pending.link);
279
280 wl_list_init(&iviscrn->order.layer_list);
281 wl_list_init(&iviscrn->order.link);
282
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900283 wl_list_insert(&layout->screen_list, &iviscrn->link);
284 }
285}
286
287/**
288 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
289 */
290static void
291init_layer_properties(struct ivi_layout_layer_properties *prop,
292 int32_t width, int32_t height)
293{
294 memset(prop, 0, sizeof *prop);
295 prop->opacity = wl_fixed_from_double(1.0);
296 prop->source_width = width;
297 prop->source_height = height;
298 prop->dest_width = width;
299 prop->dest_height = height;
300}
301
302static void
303init_surface_properties(struct ivi_layout_surface_properties *prop)
304{
305 memset(prop, 0, sizeof *prop);
306 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900307 /*
308 * FIXME: this shall be finxed by ivi-layout-transition.
309 */
310 prop->dest_width = 1;
311 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900312}
313
314/**
315 * Internal APIs to be called from ivi_layout_commit_changes.
316 */
317static void
318update_opacity(struct ivi_layout_layer *ivilayer,
319 struct ivi_layout_surface *ivisurf)
320{
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000321 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900322 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
323 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
324
325 if ((ivilayer->event_mask & IVI_NOTIFICATION_OPACITY) ||
326 (ivisurf->event_mask & IVI_NOTIFICATION_OPACITY)) {
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000327 tmpview = get_weston_view(ivisurf);
328 assert(tmpview != NULL);
329 tmpview->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900330 }
331}
332
333static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900334get_rotate_values(enum wl_output_transform orientation,
335 float *v_sin,
336 float *v_cos)
337{
338 switch (orientation) {
339 case WL_OUTPUT_TRANSFORM_90:
340 *v_sin = 1.0f;
341 *v_cos = 0.0f;
342 break;
343 case WL_OUTPUT_TRANSFORM_180:
344 *v_sin = 0.0f;
345 *v_cos = -1.0f;
346 break;
347 case WL_OUTPUT_TRANSFORM_270:
348 *v_sin = -1.0f;
349 *v_cos = 0.0f;
350 break;
351 case WL_OUTPUT_TRANSFORM_NORMAL:
352 default:
353 *v_sin = 0.0f;
354 *v_cos = 1.0f;
355 break;
356 }
357}
358
359static void
360get_scale(enum wl_output_transform orientation,
361 float dest_width,
362 float dest_height,
363 float source_width,
364 float source_height,
365 float *scale_x,
366 float *scale_y)
367{
368 switch (orientation) {
369 case WL_OUTPUT_TRANSFORM_90:
370 *scale_x = dest_width / source_height;
371 *scale_y = dest_height / source_width;
372 break;
373 case WL_OUTPUT_TRANSFORM_180:
374 *scale_x = dest_width / source_width;
375 *scale_y = dest_height / source_height;
376 break;
377 case WL_OUTPUT_TRANSFORM_270:
378 *scale_x = dest_width / source_height;
379 *scale_y = dest_height / source_width;
380 break;
381 case WL_OUTPUT_TRANSFORM_NORMAL:
382 default:
383 *scale_x = dest_width / source_width;
384 *scale_y = dest_height / source_height;
385 break;
386 }
387}
388
389static void
390calc_transformation_matrix(struct ivi_rectangle *source_rect,
391 struct ivi_rectangle *dest_rect,
392 enum wl_output_transform orientation,
393 struct weston_matrix *m)
394{
395 float source_center_x;
396 float source_center_y;
397 float vsin;
398 float vcos;
399 float scale_x;
400 float scale_y;
401 float translate_x;
402 float translate_y;
403
404 source_center_x = source_rect->x + source_rect->width * 0.5f;
405 source_center_y = source_rect->y + source_rect->height * 0.5f;
406 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
407
408 get_rotate_values(orientation, &vsin, &vcos);
409 weston_matrix_rotate_xy(m, vcos, vsin);
410
411 get_scale(orientation,
412 dest_rect->width,
413 dest_rect->height,
414 source_rect->width,
415 source_rect->height,
416 &scale_x,
417 &scale_y);
418 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
419
420 translate_x = dest_rect->width * 0.5f + dest_rect->x;
421 translate_y = dest_rect->height * 0.5f + dest_rect->y;
422 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
423}
424
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900425/*
426 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900427 */
428static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900429ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
430 const struct ivi_rectangle *rect2,
431 struct ivi_rectangle *rect_output)
432{
433 int32_t rect1_right = rect1->x + rect1->width;
434 int32_t rect1_bottom = rect1->y + rect1->height;
435 int32_t rect2_right = rect2->x + rect2->width;
436 int32_t rect2_bottom = rect2->y + rect2->height;
437
438 rect_output->x = max(rect1->x, rect2->x);
439 rect_output->y = max(rect1->y, rect2->y);
440 rect_output->width = rect1_right < rect2_right ?
441 rect1_right - rect_output->x :
442 rect2_right - rect_output->x;
443 rect_output->height = rect1_bottom < rect2_bottom ?
444 rect1_bottom - rect_output->y :
445 rect2_bottom - rect_output->y;
446
447 if (rect_output->width < 0 || rect_output->height < 0) {
448 rect_output->width = 0;
449 rect_output->height = 0;
450 }
451}
452
453/*
454 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
455 * and store the result in rect_output.
456 * The boundingbox must be given in the same coordinate space as rect_output.
457 * Additionally, there are the following restrictions on the matrix:
458 * - no projective transformations
459 * - no skew
460 * - only multiples of 90-degree rotations supported
461 *
462 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
463 * as a fail-safe with log.
464 */
465static void
466calc_inverse_matrix_transform(const struct weston_matrix *matrix,
467 const struct ivi_rectangle *rect_input,
468 const struct ivi_rectangle *boundingbox,
469 struct ivi_rectangle *rect_output)
470{
471 struct weston_matrix m;
472 struct weston_vector top_left;
473 struct weston_vector bottom_right;
474
475 assert(boundingbox != rect_output);
476
477 if (weston_matrix_invert(&m, matrix) < 0) {
478 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
479 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
480 rect_output->x = boundingbox->x;
481 rect_output->y = boundingbox->y;
482 rect_output->width = boundingbox->width;
483 rect_output->height = boundingbox->height;
484 }
485
486 /* The vectors and matrices involved will always produce f[3] == 1.0. */
487 top_left.f[0] = rect_input->x;
488 top_left.f[1] = rect_input->y;
489 top_left.f[2] = 0.0f;
490 top_left.f[3] = 1.0f;
491
492 bottom_right.f[0] = rect_input->x + rect_input->width;
493 bottom_right.f[1] = rect_input->y + rect_input->height;
494 bottom_right.f[2] = 0.0f;
495 bottom_right.f[3] = 1.0f;
496
497 weston_matrix_transform(&m, &top_left);
498 weston_matrix_transform(&m, &bottom_right);
499
500 if (top_left.f[0] < bottom_right.f[0]) {
501 rect_output->x = top_left.f[0];
502 rect_output->width = bottom_right.f[0] - rect_output->x;
503 } else {
504 rect_output->x = bottom_right.f[0];
505 rect_output->width = top_left.f[0] - rect_output->x;
506 }
507
508 if (top_left.f[1] < bottom_right.f[1]) {
509 rect_output->y = top_left.f[1];
510 rect_output->height = bottom_right.f[1] - rect_output->y;
511 } else {
512 rect_output->y = bottom_right.f[1];
513 rect_output->height = top_left.f[1] - rect_output->y;
514 }
515
516 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
517}
518
519/**
520 * This computes the whole transformation matrix:m from surface-local
521 * coordinates to global coordinates. It is assumed that
522 * weston_view::geometry.{x,y} are zero.
523 *
524 * Additionally, this computes the mask on surface-local coordinates as a
525 * ivi_rectangle. This can be set to weston_view_set_mask.
526 *
527 * The mask is computed by following steps
528 * - destination rectangle of layer is inversed to surface-local cooodinates
529 * by inversed matrix:m.
530 * - the area is intersected by intersected area between weston_surface and
531 * source rectangle of ivi_surface.
532 */
533static void
534calc_surface_to_global_matrix_and_mask_to_weston_surface(
535 struct ivi_layout_layer *ivilayer,
536 struct ivi_layout_surface *ivisurf,
537 struct weston_matrix *m,
538 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900539{
540 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
541 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900542 struct ivi_rectangle weston_surface_rect = { 0,
543 0,
544 ivisurf->surface->width,
545 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900546 struct ivi_rectangle surface_source_rect = { sp->source_x,
547 sp->source_y,
548 sp->source_width,
549 sp->source_height };
550 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
551 sp->dest_y,
552 sp->dest_width,
553 sp->dest_height };
554 struct ivi_rectangle layer_source_rect = { lp->source_x,
555 lp->source_y,
556 lp->source_width,
557 lp->source_height };
558 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
559 lp->dest_y,
560 lp->dest_width,
561 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900562 struct ivi_rectangle surface_result;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900563
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900564 /*
565 * the whole transformation matrix:m from surface-local
566 * coordinates to global coordinates, which is computed by
567 * two steps,
568 * - surface-local coordinates to layer-local coordinates
569 * - layer-local coordinates to global coordinates
570 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900571 calc_transformation_matrix(&surface_source_rect,
572 &surface_dest_rect,
573 sp->orientation, m);
574
575 calc_transformation_matrix(&layer_source_rect,
576 &layer_dest_rect,
577 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900578
579 /* this intersected ivi_rectangle would be used for masking
580 * weston_surface
581 */
582 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
583 &surface_result);
584
585 /* calc masking area of weston_surface from m */
586 calc_inverse_matrix_transform(m,
587 &layer_dest_rect,
588 &surface_result,
589 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900590}
591
592static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900593update_prop(struct ivi_layout_layer *ivilayer,
594 struct ivi_layout_surface *ivisurf)
595{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900596 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900597 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900598 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900599
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900600 if (!ivilayer->event_mask && !ivisurf->event_mask) {
601 return;
602 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900603
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900604 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900605
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000606 tmpview = get_weston_view(ivisurf);
607 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900608
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900609 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
610 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
611 can_calc = false;
612 }
613
614 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
615 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
616 can_calc = false;
617 }
618
619 if (can_calc) {
620 wl_list_remove(&ivisurf->transform.link);
621 weston_matrix_init(&ivisurf->transform.matrix);
622
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900623 calc_surface_to_global_matrix_and_mask_to_weston_surface(
624 ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900625
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000626 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
627 wl_list_insert(&tmpview->geometry.transformation_list,
628 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900629
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000630 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900631 }
632
633 ivisurf->update_count++;
634
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000635 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900636
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000637 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900638}
639
640static void
641commit_changes(struct ivi_layout *layout)
642{
643 struct ivi_layout_screen *iviscrn = NULL;
644 struct ivi_layout_layer *ivilayer = NULL;
645 struct ivi_layout_surface *ivisurf = NULL;
646
647 wl_list_for_each(iviscrn, &layout->screen_list, link) {
648 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
649 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
650 update_prop(ivilayer, ivisurf);
651 }
652 }
653 }
654}
655
656static void
657commit_surface_list(struct ivi_layout *layout)
658{
659 struct ivi_layout_surface *ivisurf = NULL;
660 int32_t dest_x = 0;
661 int32_t dest_y = 0;
662 int32_t dest_width = 0;
663 int32_t dest_height = 0;
664 int32_t configured = 0;
665
666 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300667 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900668 dest_x = ivisurf->prop.dest_x;
669 dest_y = ivisurf->prop.dest_y;
670 dest_width = ivisurf->prop.dest_width;
671 dest_height = ivisurf->prop.dest_height;
672
673 ivi_layout_transition_move_resize_view(ivisurf,
674 ivisurf->pending.prop.dest_x,
675 ivisurf->pending.prop.dest_y,
676 ivisurf->pending.prop.dest_width,
677 ivisurf->pending.prop.dest_height,
678 ivisurf->pending.prop.transition_duration);
679
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300680 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900681 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
682 } else {
683 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
684 }
685
686 ivisurf->prop = ivisurf->pending.prop;
687 ivisurf->prop.dest_x = dest_x;
688 ivisurf->prop.dest_y = dest_y;
689 ivisurf->prop.dest_width = dest_width;
690 ivisurf->prop.dest_height = dest_height;
691 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
692 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
693
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300694 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900695 dest_x = ivisurf->prop.dest_x;
696 dest_y = ivisurf->prop.dest_y;
697 dest_width = ivisurf->prop.dest_width;
698 dest_height = ivisurf->prop.dest_height;
699
700 ivi_layout_transition_move_resize_view(ivisurf,
701 ivisurf->pending.prop.dest_x,
702 ivisurf->pending.prop.dest_y,
703 ivisurf->pending.prop.dest_width,
704 ivisurf->pending.prop.dest_height,
705 ivisurf->pending.prop.transition_duration);
706
707 ivisurf->prop = ivisurf->pending.prop;
708 ivisurf->prop.dest_x = dest_x;
709 ivisurf->prop.dest_y = dest_y;
710 ivisurf->prop.dest_width = dest_width;
711 ivisurf->prop.dest_height = dest_height;
712
713 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
714 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
715
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300716 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900717 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300718 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900719 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
720 } else {
721 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
722 }
723
724 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
725 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
726 configured = 1;
727 }
728
729 ivisurf->prop = ivisurf->pending.prop;
730 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
731 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
732
733 if (configured && !is_surface_transition(ivisurf))
734 wl_signal_emit(&ivisurf->configured, ivisurf);
735 } else {
736 configured = 0;
737 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
738 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
739 configured = 1;
740 }
741
742 ivisurf->prop = ivisurf->pending.prop;
743 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
744 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
745
746 if (configured && !is_surface_transition(ivisurf))
747 wl_signal_emit(&ivisurf->configured, ivisurf);
748 }
749 }
750}
751
752static void
753commit_layer_list(struct ivi_layout *layout)
754{
755 struct ivi_layout_layer *ivilayer = NULL;
756 struct ivi_layout_surface *ivisurf = NULL;
757 struct ivi_layout_surface *next = NULL;
758
759 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300760 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900761 ivi_layout_transition_move_layer(ivilayer, ivilayer->pending.prop.dest_x, ivilayer->pending.prop.dest_y, ivilayer->pending.prop.transition_duration);
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300762 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900763 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
764 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
765 NULL, NULL,
766 ivilayer->pending.prop.transition_duration);
767 }
768 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
769
770 ivilayer->prop = ivilayer->pending.prop;
771
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000772 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900773 continue;
774 }
775
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000776 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
777 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000778 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000779 wl_list_remove(&ivisurf->order.link);
780 wl_list_init(&ivisurf->order.link);
781 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900782 }
783
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000784 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900785
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000786 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900787 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000788 wl_list_remove(&ivisurf->order.link);
789 wl_list_insert(&ivilayer->order.surface_list,
790 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000791 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000792 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900793 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000794
795 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900796 }
797}
798
799static void
800commit_screen_list(struct ivi_layout *layout)
801{
802 struct ivi_layout_screen *iviscrn = NULL;
803 struct ivi_layout_layer *ivilayer = NULL;
804 struct ivi_layout_layer *next = NULL;
805 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000806 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900807
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900808 /* Clear view list of layout ivi_layer */
809 wl_list_init(&layout->layout_layer.view_list.link);
810
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900811 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000812 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900813 wl_list_for_each_safe(ivilayer, next,
814 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000815 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000816 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900817 wl_list_init(&ivilayer->order.link);
818 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
819 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900820
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000821 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900822
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900823 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
824 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900825 /* FIXME: avoid to insert order.link to multiple screens */
826 wl_list_remove(&ivilayer->order.link);
827
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900828 wl_list_insert(&iviscrn->order.layer_list,
829 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000830 ivilayer->on_screen = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900831 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
832 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900833
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000834 iviscrn->order.dirty = 0;
835 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900836
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900837 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
838 if (ivilayer->prop.visibility == false)
839 continue;
840
841 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900842 if (ivisurf->prop.visibility == false)
843 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000844
845 tmpview = get_weston_view(ivisurf);
846 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900847
848 weston_layer_entry_insert(&layout->layout_layer.view_list,
849 &tmpview->layer_link);
850
851 ivisurf->surface->output = iviscrn->output;
852 }
853 }
854
855 break;
856 }
857}
858
859static void
860commit_transition(struct ivi_layout* layout)
861{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300862 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900863 return;
864 }
865
866 wl_list_insert_list(&layout->transitions->transition_list,
867 &layout->pending_transition_list);
868
869 wl_list_init(&layout->pending_transition_list);
870
871 wl_event_source_timer_update(layout->transitions->event_source, 1);
872}
873
874static void
875send_surface_prop(struct ivi_layout_surface *ivisurf)
876{
877 wl_signal_emit(&ivisurf->property_changed, ivisurf);
878 ivisurf->event_mask = 0;
879}
880
881static void
882send_layer_prop(struct ivi_layout_layer *ivilayer)
883{
884 wl_signal_emit(&ivilayer->property_changed, ivilayer);
885 ivilayer->event_mask = 0;
886}
887
888static void
889send_prop(struct ivi_layout *layout)
890{
891 struct ivi_layout_layer *ivilayer = NULL;
892 struct ivi_layout_surface *ivisurf = NULL;
893
894 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900895 if (ivilayer->event_mask)
896 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900897 }
898
899 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900900 if (ivisurf->event_mask)
901 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900902 }
903}
904
905static void
906clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
907{
908 struct ivi_layout_surface *surface_link = NULL;
909 struct ivi_layout_surface *surface_next = NULL;
910
911 wl_list_for_each_safe(surface_link, surface_next,
912 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000913 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900914 wl_list_init(&surface_link->pending.link);
915 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900916}
917
918static void
919clear_surface_order_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->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000926 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900927 wl_list_init(&surface_link->order.link);
928 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900929}
930
931static void
932layer_created(struct wl_listener *listener, void *data)
933{
934 struct ivi_layout_layer *ivilayer = data;
935
936 struct listener_layout_notification *notification =
937 container_of(listener,
938 struct listener_layout_notification,
939 listener);
940
941 struct ivi_layout_notification_callback *created_callback =
942 notification->userdata;
943
944 ((layer_create_notification_func)created_callback->callback)
945 (ivilayer, created_callback->data);
946}
947
948static void
949layer_removed(struct wl_listener *listener, void *data)
950{
951 struct ivi_layout_layer *ivilayer = data;
952
953 struct listener_layout_notification *notification =
954 container_of(listener,
955 struct listener_layout_notification,
956 listener);
957
958 struct ivi_layout_notification_callback *removed_callback =
959 notification->userdata;
960
961 ((layer_remove_notification_func)removed_callback->callback)
962 (ivilayer, removed_callback->data);
963}
964
965static void
966layer_prop_changed(struct wl_listener *listener, void *data)
967{
968 struct ivi_layout_layer *ivilayer = data;
969
970 struct listener_layout_notification *layout_listener =
971 container_of(listener,
972 struct listener_layout_notification,
973 listener);
974
975 struct ivi_layout_notification_callback *prop_callback =
976 layout_listener->userdata;
977
978 ((layer_property_notification_func)prop_callback->callback)
979 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
980}
981
982static void
983surface_created(struct wl_listener *listener, void *data)
984{
985 struct ivi_layout_surface *ivisurface = data;
986
987 struct listener_layout_notification *notification =
988 container_of(listener,
989 struct listener_layout_notification,
990 listener);
991
992 struct ivi_layout_notification_callback *created_callback =
993 notification->userdata;
994
995 ((surface_create_notification_func)created_callback->callback)
996 (ivisurface, created_callback->data);
997}
998
999static void
1000surface_removed(struct wl_listener *listener, void *data)
1001{
1002 struct ivi_layout_surface *ivisurface = data;
1003
1004 struct listener_layout_notification *notification =
1005 container_of(listener,
1006 struct listener_layout_notification,
1007 listener);
1008
1009 struct ivi_layout_notification_callback *removed_callback =
1010 notification->userdata;
1011
1012 ((surface_remove_notification_func)removed_callback->callback)
1013 (ivisurface, removed_callback->data);
1014}
1015
1016static void
1017surface_prop_changed(struct wl_listener *listener, void *data)
1018{
1019 struct ivi_layout_surface *ivisurf = data;
1020
1021 struct listener_layout_notification *layout_listener =
1022 container_of(listener,
1023 struct listener_layout_notification,
1024 listener);
1025
1026 struct ivi_layout_notification_callback *prop_callback =
1027 layout_listener->userdata;
1028
1029 ((surface_property_notification_func)prop_callback->callback)
1030 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1031
1032 ivisurf->event_mask = 0;
1033}
1034
1035static void
1036surface_configure_changed(struct wl_listener *listener,
1037 void *data)
1038{
1039 struct ivi_layout_surface *ivisurface = data;
1040
1041 struct listener_layout_notification *notification =
1042 container_of(listener,
1043 struct listener_layout_notification,
1044 listener);
1045
1046 struct ivi_layout_notification_callback *configure_changed_callback =
1047 notification->userdata;
1048
1049 ((surface_configure_notification_func)configure_changed_callback->callback)
1050 (ivisurface, configure_changed_callback->data);
1051}
1052
1053static int32_t
1054add_notification(struct wl_signal *signal,
1055 wl_notify_func_t callback,
1056 void *userdata)
1057{
1058 struct listener_layout_notification *notification = NULL;
1059
1060 notification = malloc(sizeof *notification);
1061 if (notification == NULL) {
1062 weston_log("fails to allocate memory\n");
1063 free(userdata);
1064 return IVI_FAILED;
1065 }
1066
1067 notification->listener.notify = callback;
1068 notification->userdata = userdata;
1069
1070 wl_signal_add(signal, &notification->listener);
1071
1072 return IVI_SUCCEEDED;
1073}
1074
1075static void
1076remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1077{
1078 struct wl_listener *listener = NULL;
1079 struct wl_listener *next = NULL;
1080
1081 wl_list_for_each_safe(listener, next, listener_list, link) {
1082 struct listener_layout_notification *notification =
1083 container_of(listener,
1084 struct listener_layout_notification,
1085 listener);
1086
1087 struct ivi_layout_notification_callback *notification_callback =
1088 notification->userdata;
1089
1090 if ((notification_callback->callback != callback) ||
1091 (notification_callback->data != userdata)) {
1092 continue;
1093 }
1094
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001095 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001096
1097 free(notification->userdata);
1098 free(notification);
1099 }
1100}
1101
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001102/**
1103 * Exported APIs of ivi-layout library are implemented from here.
1104 * Brief of APIs is described in ivi-layout-export.h.
1105 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001106static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001107ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1108 void *userdata)
1109{
1110 struct ivi_layout *layout = get_instance();
1111 struct ivi_layout_notification_callback *created_callback = NULL;
1112
1113 if (callback == NULL) {
1114 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1115 return IVI_FAILED;
1116 }
1117
1118 created_callback = malloc(sizeof *created_callback);
1119 if (created_callback == NULL) {
1120 weston_log("fails to allocate memory\n");
1121 return IVI_FAILED;
1122 }
1123
1124 created_callback->callback = callback;
1125 created_callback->data = userdata;
1126
1127 return add_notification(&layout->layer_notification.created,
1128 layer_created,
1129 created_callback);
1130}
1131
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001132static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001133ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1134 void *userdata)
1135{
1136 struct ivi_layout *layout = get_instance();
1137 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1138}
1139
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001140static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001141ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1142 void *userdata)
1143{
1144 struct ivi_layout *layout = get_instance();
1145 struct ivi_layout_notification_callback *removed_callback = NULL;
1146
1147 if (callback == NULL) {
1148 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1149 return IVI_FAILED;
1150 }
1151
1152 removed_callback = malloc(sizeof *removed_callback);
1153 if (removed_callback == NULL) {
1154 weston_log("fails to allocate memory\n");
1155 return IVI_FAILED;
1156 }
1157
1158 removed_callback->callback = callback;
1159 removed_callback->data = userdata;
1160 return add_notification(&layout->layer_notification.removed,
1161 layer_removed,
1162 removed_callback);
1163}
1164
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001165static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001166ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1167 void *userdata)
1168{
1169 struct ivi_layout *layout = get_instance();
1170 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1171}
1172
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001173static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001174ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1175 void *userdata)
1176{
1177 struct ivi_layout *layout = get_instance();
1178 struct ivi_layout_notification_callback *created_callback = NULL;
1179
1180 if (callback == NULL) {
1181 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1182 return IVI_FAILED;
1183 }
1184
1185 created_callback = malloc(sizeof *created_callback);
1186 if (created_callback == NULL) {
1187 weston_log("fails to allocate memory\n");
1188 return IVI_FAILED;
1189 }
1190
1191 created_callback->callback = callback;
1192 created_callback->data = userdata;
1193
1194 return add_notification(&layout->surface_notification.created,
1195 surface_created,
1196 created_callback);
1197}
1198
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001199static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001200ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1201 void *userdata)
1202{
1203 struct ivi_layout *layout = get_instance();
1204 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1205}
1206
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001207static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001208ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1209 void *userdata)
1210{
1211 struct ivi_layout *layout = get_instance();
1212 struct ivi_layout_notification_callback *removed_callback = NULL;
1213
1214 if (callback == NULL) {
1215 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1216 return IVI_FAILED;
1217 }
1218
1219 removed_callback = malloc(sizeof *removed_callback);
1220 if (removed_callback == NULL) {
1221 weston_log("fails to allocate memory\n");
1222 return IVI_FAILED;
1223 }
1224
1225 removed_callback->callback = callback;
1226 removed_callback->data = userdata;
1227
1228 return add_notification(&layout->surface_notification.removed,
1229 surface_removed,
1230 removed_callback);
1231}
1232
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001233static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001234ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1235 void *userdata)
1236{
1237 struct ivi_layout *layout = get_instance();
1238 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1239}
1240
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001241static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001242ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1243 void *userdata)
1244{
1245 struct ivi_layout *layout = get_instance();
1246 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1247 if (callback == NULL) {
1248 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1249 return IVI_FAILED;
1250 }
1251
1252 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1253 if (configure_changed_callback == NULL) {
1254 weston_log("fails to allocate memory\n");
1255 return IVI_FAILED;
1256 }
1257
1258 configure_changed_callback->callback = callback;
1259 configure_changed_callback->data = userdata;
1260
1261 return add_notification(&layout->surface_notification.configure_changed,
1262 surface_configure_changed,
1263 configure_changed_callback);
1264}
1265
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001266static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001267ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1268 void *userdata)
1269{
1270 struct ivi_layout *layout = get_instance();
1271 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1272}
1273
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001274uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001275ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1276{
1277 return ivisurf->id_surface;
1278}
1279
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001280static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001281ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1282{
1283 return ivilayer->id_layer;
1284}
1285
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001286static uint32_t
1287ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1288{
1289 return iviscrn->id_screen;
1290}
1291
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001292static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001293ivi_layout_get_layer_from_id(uint32_t id_layer)
1294{
1295 struct ivi_layout *layout = get_instance();
1296 struct ivi_layout_layer *ivilayer = NULL;
1297
1298 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1299 if (ivilayer->id_layer == id_layer) {
1300 return ivilayer;
1301 }
1302 }
1303
1304 return NULL;
1305}
1306
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001307struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001308ivi_layout_get_surface_from_id(uint32_t id_surface)
1309{
1310 struct ivi_layout *layout = get_instance();
1311 struct ivi_layout_surface *ivisurf = NULL;
1312
1313 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1314 if (ivisurf->id_surface == id_surface) {
1315 return ivisurf;
1316 }
1317 }
1318
1319 return NULL;
1320}
1321
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001322static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001323ivi_layout_get_screen_from_id(uint32_t id_screen)
1324{
1325 struct ivi_layout *layout = get_instance();
1326 struct ivi_layout_screen *iviscrn = NULL;
1327
1328 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Nobuhiko Tanibata3e710d12015-11-25 23:36:09 +09001329 if (iviscrn->id_screen == id_screen)
1330 return iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001331 }
1332
1333 return NULL;
1334}
1335
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001336static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001337ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1338 int32_t *pWidth, int32_t *pHeight)
1339{
1340 struct weston_output *output = NULL;
1341
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001342 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001343 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1344 return IVI_FAILED;
1345 }
1346
1347 output = iviscrn->output;
1348 *pWidth = output->current_mode->width;
1349 *pHeight = output->current_mode->height;
1350
1351 return IVI_SUCCEEDED;
1352}
1353
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001354static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001355ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1356 surface_property_notification_func callback,
1357 void *userdata)
1358{
1359 struct listener_layout_notification* notification = NULL;
1360 struct ivi_layout_notification_callback *prop_callback = NULL;
1361
1362 if (ivisurf == NULL || callback == NULL) {
1363 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1364 return IVI_FAILED;
1365 }
1366
1367 notification = malloc(sizeof *notification);
1368 if (notification == NULL) {
1369 weston_log("fails to allocate memory\n");
1370 return IVI_FAILED;
1371 }
1372
1373 prop_callback = malloc(sizeof *prop_callback);
1374 if (prop_callback == NULL) {
1375 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001376 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001377 return IVI_FAILED;
1378 }
1379
1380 prop_callback->callback = callback;
1381 prop_callback->data = userdata;
1382
1383 notification->listener.notify = surface_prop_changed;
1384 notification->userdata = prop_callback;
1385
1386 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1387
1388 return IVI_SUCCEEDED;
1389}
1390
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001391static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001392ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1393{
1394 if (ivilayer == NULL) {
1395 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1396 return NULL;
1397 }
1398
1399 return &ivilayer->prop;
1400}
1401
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001402static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001403ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1404{
1405 struct ivi_layout *layout = get_instance();
1406 struct ivi_layout_screen *iviscrn = NULL;
1407 int32_t length = 0;
1408 int32_t n = 0;
1409
1410 if (pLength == NULL || ppArray == NULL) {
1411 weston_log("ivi_layout_get_screens: invalid argument\n");
1412 return IVI_FAILED;
1413 }
1414
1415 length = wl_list_length(&layout->screen_list);
1416
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001417 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001418 /* the Array must be free by module which called this function */
1419 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1420 if (*ppArray == NULL) {
1421 weston_log("fails to allocate memory\n");
1422 return IVI_FAILED;
1423 }
1424
1425 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1426 (*ppArray)[n++] = iviscrn;
1427 }
1428 }
1429
1430 *pLength = length;
1431
1432 return IVI_SUCCEEDED;
1433}
1434
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001435static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001436ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1437 int32_t *pLength,
1438 struct ivi_layout_screen ***ppArray)
1439{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001440 int32_t length = 0;
1441 int32_t n = 0;
1442
1443 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1444 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1445 return IVI_FAILED;
1446 }
1447
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001448 if (ivilayer->on_screen != NULL)
1449 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001450
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001451 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001452 /* the Array must be free by module which called this function */
1453 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1454 if (*ppArray == NULL) {
1455 weston_log("fails to allocate memory\n");
1456 return IVI_FAILED;
1457 }
1458
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001459 (*ppArray)[n++] = ivilayer->on_screen;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001460 }
1461
1462 *pLength = length;
1463
1464 return IVI_SUCCEEDED;
1465}
1466
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001467static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001468ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1469{
1470 struct ivi_layout *layout = get_instance();
1471 struct ivi_layout_layer *ivilayer = NULL;
1472 int32_t length = 0;
1473 int32_t n = 0;
1474
1475 if (pLength == NULL || ppArray == NULL) {
1476 weston_log("ivi_layout_get_layers: invalid argument\n");
1477 return IVI_FAILED;
1478 }
1479
1480 length = wl_list_length(&layout->layer_list);
1481
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001482 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001483 /* the Array must be free by module which called this function */
1484 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1485 if (*ppArray == NULL) {
1486 weston_log("fails to allocate memory\n");
1487 return IVI_FAILED;
1488 }
1489
1490 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1491 (*ppArray)[n++] = ivilayer;
1492 }
1493 }
1494
1495 *pLength = length;
1496
1497 return IVI_SUCCEEDED;
1498}
1499
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001500static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001501ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1502 int32_t *pLength,
1503 struct ivi_layout_layer ***ppArray)
1504{
1505 struct ivi_layout_layer *ivilayer = NULL;
1506 int32_t length = 0;
1507 int32_t n = 0;
1508
1509 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1510 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1511 return IVI_FAILED;
1512 }
1513
1514 length = wl_list_length(&iviscrn->order.layer_list);
1515
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001516 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001517 /* the Array must be free by module which called this function */
1518 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1519 if (*ppArray == NULL) {
1520 weston_log("fails to allocate memory\n");
1521 return IVI_FAILED;
1522 }
1523
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001524 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001525 (*ppArray)[n++] = ivilayer;
1526 }
1527 }
1528
1529 *pLength = length;
1530
1531 return IVI_SUCCEEDED;
1532}
1533
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001534static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001535ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1536 int32_t *pLength,
1537 struct ivi_layout_layer ***ppArray)
1538{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001539 int32_t length = 0;
1540 int32_t n = 0;
1541
1542 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1543 weston_log("ivi_layout_getLayers: invalid argument\n");
1544 return IVI_FAILED;
1545 }
1546
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001547 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001548 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001549 length = 1;
1550 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001551 if (*ppArray == NULL) {
1552 weston_log("fails to allocate memory\n");
1553 return IVI_FAILED;
1554 }
1555
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001556 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001557 }
1558
1559 *pLength = length;
1560
1561 return IVI_SUCCEEDED;
1562}
1563
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001564static
1565int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001566ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1567{
1568 struct ivi_layout *layout = get_instance();
1569 struct ivi_layout_surface *ivisurf = NULL;
1570 int32_t length = 0;
1571 int32_t n = 0;
1572
1573 if (pLength == NULL || ppArray == NULL) {
1574 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1575 return IVI_FAILED;
1576 }
1577
1578 length = wl_list_length(&layout->surface_list);
1579
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001580 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001581 /* the Array must be free by module which called this function */
1582 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1583 if (*ppArray == NULL) {
1584 weston_log("fails to allocate memory\n");
1585 return IVI_FAILED;
1586 }
1587
1588 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1589 (*ppArray)[n++] = ivisurf;
1590 }
1591 }
1592
1593 *pLength = length;
1594
1595 return IVI_SUCCEEDED;
1596}
1597
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001598static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001599ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1600 int32_t *pLength,
1601 struct ivi_layout_surface ***ppArray)
1602{
1603 struct ivi_layout_surface *ivisurf = NULL;
1604 int32_t length = 0;
1605 int32_t n = 0;
1606
1607 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1608 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1609 return IVI_FAILED;
1610 }
1611
1612 length = wl_list_length(&ivilayer->order.surface_list);
1613
1614 if (length != 0) {
1615 /* the Array must be free by module which called this function */
1616 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1617 if (*ppArray == NULL) {
1618 weston_log("fails to allocate memory\n");
1619 return IVI_FAILED;
1620 }
1621
1622 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1623 (*ppArray)[n++] = ivisurf;
1624 }
1625 }
1626
1627 *pLength = length;
1628
1629 return IVI_SUCCEEDED;
1630}
1631
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001632static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001633ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1634 int32_t width, int32_t height)
1635{
1636 struct ivi_layout *layout = get_instance();
1637 struct ivi_layout_layer *ivilayer = NULL;
1638
1639 ivilayer = get_layer(&layout->layer_list, id_layer);
1640 if (ivilayer != NULL) {
1641 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001642 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001643 return ivilayer;
1644 }
1645
1646 ivilayer = calloc(1, sizeof *ivilayer);
1647 if (ivilayer == NULL) {
1648 weston_log("fails to allocate memory\n");
1649 return NULL;
1650 }
1651
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001652 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001653 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001654 ivilayer->layout = layout;
1655 ivilayer->id_layer = id_layer;
1656
1657 init_layer_properties(&ivilayer->prop, width, height);
1658 ivilayer->event_mask = 0;
1659
1660 wl_list_init(&ivilayer->pending.surface_list);
1661 wl_list_init(&ivilayer->pending.link);
1662 ivilayer->pending.prop = ivilayer->prop;
1663
1664 wl_list_init(&ivilayer->order.surface_list);
1665 wl_list_init(&ivilayer->order.link);
1666
1667 wl_list_insert(&layout->layer_list, &ivilayer->link);
1668
1669 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1670
1671 return ivilayer;
1672}
1673
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001674static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001675ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1676{
1677 if (ivilayer == NULL) {
1678 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1679 return;
1680 }
1681
1682 remove_all_notification(&ivilayer->property_changed.listener_list);
1683}
1684
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001685static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001686ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1687 layer_property_notification_func callback,
1688 void *userdata)
1689{
1690 if (ivilayer == NULL) {
1691 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1692 return;
1693 }
1694
1695 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1696}
1697
1698static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001699ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001700{
1701 struct ivi_layout *layout = get_instance();
1702
1703 if (ivilayer == NULL) {
1704 weston_log("ivi_layout_layer_remove: invalid argument\n");
1705 return;
1706 }
1707
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001708 if (--ivilayer->ref_count > 0)
1709 return;
1710
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001711 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1712
1713 clear_surface_pending_list(ivilayer);
1714 clear_surface_order_list(ivilayer);
1715
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001716 wl_list_remove(&ivilayer->pending.link);
1717 wl_list_remove(&ivilayer->order.link);
1718 wl_list_remove(&ivilayer->link);
1719
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001720 ivi_layout_layer_remove_notification(ivilayer);
1721
1722 free(ivilayer);
1723}
1724
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001725int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001726ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1727 bool newVisibility)
1728{
1729 struct ivi_layout_layer_properties *prop = NULL;
1730
1731 if (ivilayer == NULL) {
1732 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1733 return IVI_FAILED;
1734 }
1735
1736 prop = &ivilayer->pending.prop;
1737 prop->visibility = newVisibility;
1738
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001739 if (ivilayer->prop.visibility != newVisibility)
1740 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1741 else
1742 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001743
1744 return IVI_SUCCEEDED;
1745}
1746
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001747static bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001748ivi_layout_layer_get_visibility(struct ivi_layout_layer *ivilayer)
1749{
1750 if (ivilayer == NULL) {
1751 weston_log("ivi_layout_layer_get_visibility: invalid argument\n");
1752 return false;
1753 }
1754
1755 return ivilayer->prop.visibility;
1756}
1757
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001758int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001759ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1760 wl_fixed_t opacity)
1761{
1762 struct ivi_layout_layer_properties *prop = NULL;
1763
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001764 if (ivilayer == NULL ||
1765 opacity < wl_fixed_from_double(0.0) ||
1766 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001767 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1768 return IVI_FAILED;
1769 }
1770
1771 prop = &ivilayer->pending.prop;
1772 prop->opacity = opacity;
1773
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001774 if (ivilayer->prop.opacity != opacity)
1775 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1776 else
1777 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001778
1779 return IVI_SUCCEEDED;
1780}
1781
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001782wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001783ivi_layout_layer_get_opacity(struct ivi_layout_layer *ivilayer)
1784{
1785 if (ivilayer == NULL) {
1786 weston_log("ivi_layout_layer_get_opacity: invalid argument\n");
1787 return wl_fixed_from_double(0.0);
1788 }
1789
1790 return ivilayer->prop.opacity;
1791}
1792
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001793static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001794ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1795 int32_t x, int32_t y,
1796 int32_t width, int32_t height)
1797{
1798 struct ivi_layout_layer_properties *prop = NULL;
1799
1800 if (ivilayer == NULL) {
1801 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1802 return IVI_FAILED;
1803 }
1804
1805 prop = &ivilayer->pending.prop;
1806 prop->source_x = x;
1807 prop->source_y = y;
1808 prop->source_width = width;
1809 prop->source_height = height;
1810
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001811 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1812 ivilayer->prop.source_width != width ||
1813 ivilayer->prop.source_height != height)
1814 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1815 else
1816 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001817
1818 return IVI_SUCCEEDED;
1819}
1820
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001821static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001822ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1823 int32_t x, int32_t y,
1824 int32_t width, int32_t height)
1825{
1826 struct ivi_layout_layer_properties *prop = NULL;
1827
1828 if (ivilayer == NULL) {
1829 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1830 return IVI_FAILED;
1831 }
1832
1833 prop = &ivilayer->pending.prop;
1834 prop->dest_x = x;
1835 prop->dest_y = y;
1836 prop->dest_width = width;
1837 prop->dest_height = height;
1838
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001839 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1840 ivilayer->prop.dest_width != width ||
1841 ivilayer->prop.dest_height != height)
1842 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1843 else
1844 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001845
1846 return IVI_SUCCEEDED;
1847}
1848
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001849static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001850ivi_layout_layer_get_dimension(struct ivi_layout_layer *ivilayer,
1851 int32_t *dest_width, int32_t *dest_height)
1852{
1853 if (ivilayer == NULL || dest_width == NULL || dest_height == NULL) {
1854 weston_log("ivi_layout_layer_get_dimension: invalid argument\n");
1855 return IVI_FAILED;
1856 }
1857
1858 *dest_width = ivilayer->prop.dest_width;
1859 *dest_height = ivilayer->prop.dest_height;
1860
1861 return IVI_SUCCEEDED;
1862}
1863
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001864static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001865ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
1866 int32_t dest_width, int32_t dest_height)
1867{
1868 struct ivi_layout_layer_properties *prop = NULL;
1869
1870 if (ivilayer == NULL) {
1871 weston_log("ivi_layout_layer_set_dimension: invalid argument\n");
1872 return IVI_FAILED;
1873 }
1874
1875 prop = &ivilayer->pending.prop;
1876
1877 prop->dest_width = dest_width;
1878 prop->dest_height = dest_height;
1879
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001880 if (ivilayer->prop.dest_width != dest_width ||
1881 ivilayer->prop.dest_height != dest_height)
1882 ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
1883 else
1884 ivilayer->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001885
1886 return IVI_SUCCEEDED;
1887}
1888
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001889int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001890ivi_layout_layer_get_position(struct ivi_layout_layer *ivilayer,
1891 int32_t *dest_x, int32_t *dest_y)
1892{
1893 if (ivilayer == NULL || dest_x == NULL || dest_y == NULL) {
1894 weston_log("ivi_layout_layer_get_position: invalid argument\n");
1895 return IVI_FAILED;
1896 }
1897
1898 *dest_x = ivilayer->prop.dest_x;
1899 *dest_y = ivilayer->prop.dest_y;
1900
1901 return IVI_SUCCEEDED;
1902}
1903
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001904int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001905ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
1906 int32_t dest_x, int32_t dest_y)
1907{
1908 struct ivi_layout_layer_properties *prop = NULL;
1909
1910 if (ivilayer == NULL) {
1911 weston_log("ivi_layout_layer_set_position: invalid argument\n");
1912 return IVI_FAILED;
1913 }
1914
1915 prop = &ivilayer->pending.prop;
1916 prop->dest_x = dest_x;
1917 prop->dest_y = dest_y;
1918
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001919 if (ivilayer->prop.dest_x != dest_x || ivilayer->prop.dest_y != dest_y)
1920 ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
1921 else
1922 ivilayer->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001923
1924 return IVI_SUCCEEDED;
1925}
1926
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001927static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001928ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1929 enum wl_output_transform orientation)
1930{
1931 struct ivi_layout_layer_properties *prop = NULL;
1932
1933 if (ivilayer == NULL) {
1934 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1935 return IVI_FAILED;
1936 }
1937
1938 prop = &ivilayer->pending.prop;
1939 prop->orientation = orientation;
1940
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001941 if (ivilayer->prop.orientation != orientation)
1942 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1943 else
1944 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001945
1946 return IVI_SUCCEEDED;
1947}
1948
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001949static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001950ivi_layout_layer_get_orientation(struct ivi_layout_layer *ivilayer)
1951{
1952 if (ivilayer == NULL) {
1953 weston_log("ivi_layout_layer_get_orientation: invalid argument\n");
1954 return 0;
1955 }
1956
1957 return ivilayer->prop.orientation;
1958}
1959
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001960int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001961ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1962 struct ivi_layout_surface **pSurface,
1963 int32_t number)
1964{
1965 struct ivi_layout *layout = get_instance();
1966 struct ivi_layout_surface *ivisurf = NULL;
1967 struct ivi_layout_surface *next = NULL;
1968 uint32_t *id_surface = NULL;
1969 int32_t i = 0;
1970
1971 if (ivilayer == NULL) {
1972 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1973 return IVI_FAILED;
1974 }
1975
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001976 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001977
1978 for (i = 0; i < number; i++) {
1979 id_surface = &pSurface[i]->id_surface;
1980
1981 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
1982 if (*id_surface != ivisurf->id_surface) {
1983 continue;
1984 }
1985
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001986 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001987 wl_list_insert(&ivilayer->pending.surface_list,
1988 &ivisurf->pending.link);
1989 break;
1990 }
1991 }
1992
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001993 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001994
1995 return IVI_SUCCEEDED;
1996}
1997
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001998int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001999ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
2000 bool newVisibility)
2001{
2002 struct ivi_layout_surface_properties *prop = NULL;
2003
2004 if (ivisurf == NULL) {
2005 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
2006 return IVI_FAILED;
2007 }
2008
2009 prop = &ivisurf->pending.prop;
2010 prop->visibility = newVisibility;
2011
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002012 if (ivisurf->prop.visibility != newVisibility)
2013 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
2014 else
2015 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002016
2017 return IVI_SUCCEEDED;
2018}
2019
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002020bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002021ivi_layout_surface_get_visibility(struct ivi_layout_surface *ivisurf)
2022{
2023 if (ivisurf == NULL) {
2024 weston_log("ivi_layout_surface_get_visibility: invalid argument\n");
2025 return false;
2026 }
2027
2028 return ivisurf->prop.visibility;
2029}
2030
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002031int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002032ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
2033 wl_fixed_t opacity)
2034{
2035 struct ivi_layout_surface_properties *prop = NULL;
2036
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09002037 if (ivisurf == NULL ||
2038 opacity < wl_fixed_from_double(0.0) ||
2039 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002040 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
2041 return IVI_FAILED;
2042 }
2043
2044 prop = &ivisurf->pending.prop;
2045 prop->opacity = opacity;
2046
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002047 if (ivisurf->prop.opacity != opacity)
2048 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
2049 else
2050 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002051
2052 return IVI_SUCCEEDED;
2053}
2054
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002055wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002056ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
2057{
2058 if (ivisurf == NULL) {
2059 weston_log("ivi_layout_surface_get_opacity: invalid argument\n");
2060 return wl_fixed_from_double(0.0);
2061 }
2062
2063 return ivisurf->prop.opacity;
2064}
2065
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002066int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002067ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
2068 int32_t x, int32_t y,
2069 int32_t width, int32_t height)
2070{
2071 struct ivi_layout_surface_properties *prop = NULL;
2072
2073 if (ivisurf == NULL) {
2074 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
2075 return IVI_FAILED;
2076 }
2077
2078 prop = &ivisurf->pending.prop;
2079 prop->start_x = prop->dest_x;
2080 prop->start_y = prop->dest_y;
2081 prop->dest_x = x;
2082 prop->dest_y = y;
2083 prop->start_width = prop->dest_width;
2084 prop->start_height = prop->dest_height;
2085 prop->dest_width = width;
2086 prop->dest_height = height;
2087
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002088 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2089 ivisurf->prop.dest_width != width ||
2090 ivisurf->prop.dest_height != height)
2091 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2092 else
2093 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002094
2095 return IVI_SUCCEEDED;
2096}
2097
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002098static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002099ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
2100 int32_t dest_width, int32_t dest_height)
2101{
2102 struct ivi_layout_surface_properties *prop = NULL;
2103
2104 if (ivisurf == NULL) {
2105 weston_log("ivi_layout_surface_set_dimension: invalid argument\n");
2106 return IVI_FAILED;
2107 }
2108
2109 prop = &ivisurf->pending.prop;
2110 prop->dest_width = dest_width;
2111 prop->dest_height = dest_height;
2112
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002113 if (ivisurf->prop.dest_width != dest_width ||
2114 ivisurf->prop.dest_height != dest_height)
2115 ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
2116 else
2117 ivisurf->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002118
2119 return IVI_SUCCEEDED;
2120}
2121
2122int32_t
2123ivi_layout_surface_get_dimension(struct ivi_layout_surface *ivisurf,
2124 int32_t *dest_width, int32_t *dest_height)
2125{
2126 if (ivisurf == NULL || dest_width == NULL || dest_height == NULL) {
2127 weston_log("ivi_layout_surface_get_dimension: invalid argument\n");
2128 return IVI_FAILED;
2129 }
2130
2131 *dest_width = ivisurf->prop.dest_width;
2132 *dest_height = ivisurf->prop.dest_height;
2133
2134 return IVI_SUCCEEDED;
2135}
2136
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002137static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002138ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
2139 int32_t dest_x, int32_t dest_y)
2140{
2141 struct ivi_layout_surface_properties *prop = NULL;
2142
2143 if (ivisurf == NULL) {
2144 weston_log("ivi_layout_surface_set_position: invalid argument\n");
2145 return IVI_FAILED;
2146 }
2147
2148 prop = &ivisurf->pending.prop;
2149 prop->dest_x = dest_x;
2150 prop->dest_y = dest_y;
2151
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002152 if (ivisurf->prop.dest_x != dest_x || ivisurf->prop.dest_y != dest_y)
2153 ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
2154 else
2155 ivisurf->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002156
2157 return IVI_SUCCEEDED;
2158}
2159
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002160static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002161ivi_layout_surface_get_position(struct ivi_layout_surface *ivisurf,
2162 int32_t *dest_x, int32_t *dest_y)
2163{
2164 if (ivisurf == NULL || dest_x == NULL || dest_y == NULL) {
2165 weston_log("ivi_layout_surface_get_position: invalid argument\n");
2166 return IVI_FAILED;
2167 }
2168
2169 *dest_x = ivisurf->prop.dest_x;
2170 *dest_y = ivisurf->prop.dest_y;
2171
2172 return IVI_SUCCEEDED;
2173}
2174
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002175static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002176ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2177 enum wl_output_transform orientation)
2178{
2179 struct ivi_layout_surface_properties *prop = NULL;
2180
2181 if (ivisurf == NULL) {
2182 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2183 return IVI_FAILED;
2184 }
2185
2186 prop = &ivisurf->pending.prop;
2187 prop->orientation = orientation;
2188
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002189 if (ivisurf->prop.orientation != orientation)
2190 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2191 else
2192 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002193
2194 return IVI_SUCCEEDED;
2195}
2196
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002197static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002198ivi_layout_surface_get_orientation(struct ivi_layout_surface *ivisurf)
2199{
2200 if (ivisurf == NULL) {
2201 weston_log("ivi_layout_surface_get_orientation: invalid argument\n");
2202 return 0;
2203 }
2204
2205 return ivisurf->prop.orientation;
2206}
2207
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002208static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002209ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2210 struct ivi_layout_layer *addlayer)
2211{
2212 struct ivi_layout *layout = get_instance();
2213 struct ivi_layout_layer *ivilayer = NULL;
2214 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002215
2216 if (iviscrn == NULL || addlayer == NULL) {
2217 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2218 return IVI_FAILED;
2219 }
2220
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00002221 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002222 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2223 return IVI_SUCCEEDED;
2224 }
2225
2226 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2227 if (ivilayer->id_layer == addlayer->id_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002228 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002229 wl_list_insert(&iviscrn->pending.layer_list,
2230 &ivilayer->pending.link);
2231 break;
2232 }
2233 }
2234
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002235 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002236
2237 return IVI_SUCCEEDED;
2238}
2239
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002240static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002241ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2242 struct ivi_layout_layer **pLayer,
2243 const int32_t number)
2244{
2245 struct ivi_layout *layout = get_instance();
2246 struct ivi_layout_layer *ivilayer = NULL;
2247 struct ivi_layout_layer *next = NULL;
2248 uint32_t *id_layer = NULL;
2249 int32_t i = 0;
2250
2251 if (iviscrn == NULL) {
2252 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2253 return IVI_FAILED;
2254 }
2255
2256 wl_list_for_each_safe(ivilayer, next,
2257 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002258 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002259 wl_list_init(&ivilayer->pending.link);
2260 }
2261
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002262 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002263
2264 for (i = 0; i < number; i++) {
2265 id_layer = &pLayer[i]->id_layer;
2266 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2267 if (*id_layer != ivilayer->id_layer) {
2268 continue;
2269 }
2270
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_insert(&iviscrn->pending.layer_list,
2273 &ivilayer->pending.link);
2274 break;
2275 }
2276 }
2277
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002278 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002279
2280 return IVI_SUCCEEDED;
2281}
2282
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002283static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002284ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2285{
2286 return iviscrn->output;
2287}
2288
2289/**
2290 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2291 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2292 * This function is used to get the result of drawing by clients.
2293 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002294static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002295ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2296{
2297 return ivisurf != NULL ? ivisurf->surface : NULL;
2298}
2299
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002300static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002301ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2302 int32_t *width, int32_t *height,
2303 int32_t *stride)
2304{
2305 int32_t w;
2306 int32_t h;
2307 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2308
2309 if (ivisurf == NULL || ivisurf->surface == NULL) {
2310 weston_log("%s: invalid argument\n", __func__);
2311 return IVI_FAILED;
2312 }
2313
2314 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2315
2316 if (width != NULL)
2317 *width = w;
2318
2319 if (height != NULL)
2320 *height = h;
2321
2322 if (stride != NULL)
2323 *stride = w * bytespp;
2324
2325 return IVI_SUCCEEDED;
2326}
2327
2328static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002329ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2330 layer_property_notification_func callback,
2331 void *userdata)
2332{
2333 struct ivi_layout_notification_callback *prop_callback = NULL;
2334
2335 if (ivilayer == NULL || callback == NULL) {
2336 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2337 return IVI_FAILED;
2338 }
2339
2340 prop_callback = malloc(sizeof *prop_callback);
2341 if (prop_callback == NULL) {
2342 weston_log("fails to allocate memory\n");
2343 return IVI_FAILED;
2344 }
2345
2346 prop_callback->callback = callback;
2347 prop_callback->data = userdata;
2348
2349 return add_notification(&ivilayer->property_changed,
2350 layer_prop_changed,
2351 prop_callback);
2352}
2353
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002354static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002355ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2356{
2357 if (ivisurf == NULL) {
2358 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2359 return NULL;
2360 }
2361
2362 return &ivisurf->prop;
2363}
2364
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002365static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002366ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2367 struct ivi_layout_surface *addsurf)
2368{
2369 struct ivi_layout *layout = get_instance();
2370 struct ivi_layout_surface *ivisurf = NULL;
2371 struct ivi_layout_surface *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002372
2373 if (ivilayer == NULL || addsurf == NULL) {
2374 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2375 return IVI_FAILED;
2376 }
2377
Ucan, Emre (ADITG/SW1)4a183642015-08-28 12:59:04 +00002378 if (addsurf->on_layer == ivilayer) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002379 weston_log("ivi_layout_layer_add_surface: addsurf is already available\n");
2380 return IVI_SUCCEEDED;
2381 }
2382
2383 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2384 if (ivisurf->id_surface == addsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002385 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002386 wl_list_insert(&ivilayer->pending.surface_list,
2387 &ivisurf->pending.link);
2388 break;
2389 }
2390 }
2391
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002392 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002393
2394 return IVI_SUCCEEDED;
2395}
2396
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002397static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002398ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2399 struct ivi_layout_surface *remsurf)
2400{
2401 struct ivi_layout_surface *ivisurf = NULL;
2402 struct ivi_layout_surface *next = NULL;
2403
2404 if (ivilayer == NULL || remsurf == NULL) {
2405 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2406 return;
2407 }
2408
2409 wl_list_for_each_safe(ivisurf, next,
2410 &ivilayer->pending.surface_list, pending.link) {
2411 if (ivisurf->id_surface == remsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002412 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002413 wl_list_init(&ivisurf->pending.link);
2414 break;
2415 }
2416 }
2417
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002418 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002419}
2420
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002421static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002422ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2423 int32_t x, int32_t y,
2424 int32_t width, int32_t height)
2425{
2426 struct ivi_layout_surface_properties *prop = NULL;
2427
2428 if (ivisurf == NULL) {
2429 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2430 return IVI_FAILED;
2431 }
2432
2433 prop = &ivisurf->pending.prop;
2434 prop->source_x = x;
2435 prop->source_y = y;
2436 prop->source_width = width;
2437 prop->source_height = height;
2438
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002439 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2440 ivisurf->prop.source_width != width ||
2441 ivisurf->prop.source_height != height)
2442 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2443 else
2444 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002445
2446 return IVI_SUCCEEDED;
2447}
2448
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002449int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002450ivi_layout_commit_changes(void)
2451{
2452 struct ivi_layout *layout = get_instance();
2453
2454 commit_surface_list(layout);
2455 commit_layer_list(layout);
2456 commit_screen_list(layout);
2457
2458 commit_transition(layout);
2459
2460 commit_changes(layout);
2461 send_prop(layout);
2462 weston_compositor_schedule_repaint(layout->compositor);
2463
2464 return IVI_SUCCEEDED;
2465}
2466
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002467static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002468ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2469 enum ivi_layout_transition_type type,
2470 uint32_t duration)
2471{
2472 if (ivilayer == NULL) {
2473 weston_log("%s: invalid argument\n", __func__);
2474 return -1;
2475 }
2476
2477 ivilayer->pending.prop.transition_type = type;
2478 ivilayer->pending.prop.transition_duration = duration;
2479
2480 return 0;
2481}
2482
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002483static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002484ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2485 uint32_t is_fade_in,
2486 double start_alpha, double end_alpha)
2487{
2488 if (ivilayer == NULL) {
2489 weston_log("%s: invalid argument\n", __func__);
2490 return -1;
2491 }
2492
2493 ivilayer->pending.prop.is_fade_in = is_fade_in;
2494 ivilayer->pending.prop.start_alpha = start_alpha;
2495 ivilayer->pending.prop.end_alpha = end_alpha;
2496
2497 return 0;
2498}
2499
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002500static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002501ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2502 uint32_t duration)
2503{
2504 struct ivi_layout_surface_properties *prop;
2505
2506 if (ivisurf == NULL) {
2507 weston_log("%s: invalid argument\n", __func__);
2508 return -1;
2509 }
2510
2511 prop = &ivisurf->pending.prop;
2512 prop->transition_duration = duration*10;
2513 return 0;
2514}
2515
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002516static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002517ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2518 enum ivi_layout_transition_type type,
2519 uint32_t duration)
2520{
2521 struct ivi_layout_surface_properties *prop;
2522
2523 if (ivisurf == NULL) {
2524 weston_log("%s: invalid argument\n", __func__);
2525 return -1;
2526 }
2527
2528 prop = &ivisurf->pending.prop;
2529 prop->transition_type = type;
2530 prop->transition_duration = duration;
2531 return 0;
2532}
2533
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002534static int32_t
2535ivi_layout_surface_dump(struct weston_surface *surface,
2536 void *target, size_t size,int32_t x, int32_t y,
2537 int32_t width, int32_t height)
2538{
2539 int result = 0;
2540
2541 if (surface == NULL) {
2542 weston_log("%s: invalid argument\n", __func__);
2543 return IVI_FAILED;
2544 }
2545
2546 result = weston_surface_copy_content(
2547 surface, target, size,
2548 x, y, width, height);
2549
2550 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2551}
2552
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002553/**
2554 * methods of interaction between ivi-shell with ivi-layout
2555 */
2556struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002557ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2558{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002559 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002560 return NULL;
2561
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002562 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002563}
2564
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002565void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002566ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2567 int32_t width, int32_t height)
2568{
2569 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002570
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002571 /* emit callback which is set by ivi-layout api user */
2572 wl_signal_emit(&layout->surface_notification.configure_changed,
2573 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002574}
2575
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002576static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002577ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2578 ivi_controller_surface_content_callback callback,
2579 void* userdata)
2580{
2581 int32_t ret = IVI_FAILED;
2582
2583 if (ivisurf != NULL) {
2584 ivisurf->content_observer.callback = callback;
2585 ivisurf->content_observer.userdata = userdata;
2586 ret = IVI_SUCCEEDED;
2587 }
2588 return ret;
2589}
2590
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002591struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002592ivi_layout_surface_create(struct weston_surface *wl_surface,
2593 uint32_t id_surface)
2594{
2595 struct ivi_layout *layout = get_instance();
2596 struct ivi_layout_surface *ivisurf = NULL;
2597 struct weston_view *tmpview = NULL;
2598
2599 if (wl_surface == NULL) {
2600 weston_log("ivi_layout_surface_create: invalid argument\n");
2601 return NULL;
2602 }
2603
2604 ivisurf = get_surface(&layout->surface_list, id_surface);
2605 if (ivisurf != NULL) {
2606 if (ivisurf->surface != NULL) {
2607 weston_log("id_surface(%d) is already created\n", id_surface);
2608 return NULL;
2609 }
2610 }
2611
2612 ivisurf = calloc(1, sizeof *ivisurf);
2613 if (ivisurf == NULL) {
2614 weston_log("fails to allocate memory\n");
2615 return NULL;
2616 }
2617
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002618 wl_signal_init(&ivisurf->property_changed);
2619 wl_signal_init(&ivisurf->configured);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002620 ivisurf->id_surface = id_surface;
2621 ivisurf->layout = layout;
2622
2623 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002624
2625 tmpview = weston_view_create(wl_surface);
2626 if (tmpview == NULL) {
2627 weston_log("fails to allocate memory\n");
2628 }
2629
2630 ivisurf->surface->width_from_buffer = 0;
2631 ivisurf->surface->height_from_buffer = 0;
2632
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002633 weston_matrix_init(&ivisurf->transform.matrix);
2634 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002635
2636 init_surface_properties(&ivisurf->prop);
2637 ivisurf->event_mask = 0;
2638
2639 ivisurf->pending.prop = ivisurf->prop;
2640 wl_list_init(&ivisurf->pending.link);
2641
2642 wl_list_init(&ivisurf->order.link);
2643 wl_list_init(&ivisurf->order.layer_list);
2644
2645 wl_list_insert(&layout->surface_list, &ivisurf->link);
2646
2647 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2648
2649 return ivisurf;
2650}
2651
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002652void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002653ivi_layout_init_with_compositor(struct weston_compositor *ec)
2654{
2655 struct ivi_layout *layout = get_instance();
2656
2657 layout->compositor = ec;
2658
2659 wl_list_init(&layout->surface_list);
2660 wl_list_init(&layout->layer_list);
2661 wl_list_init(&layout->screen_list);
2662
2663 wl_signal_init(&layout->layer_notification.created);
2664 wl_signal_init(&layout->layer_notification.removed);
2665
2666 wl_signal_init(&layout->surface_notification.created);
2667 wl_signal_init(&layout->surface_notification.removed);
2668 wl_signal_init(&layout->surface_notification.configure_changed);
2669
2670 /* Add layout_layer at the last of weston_compositor.layer_list */
2671 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2672
2673 create_screen(ec);
2674
2675 layout->transitions = ivi_layout_transition_set_create(ec);
2676 wl_list_init(&layout->pending_transition_list);
2677}
2678
2679
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002680void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002681ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2682 struct wl_listener* listener)
2683{
2684 wl_signal_add(&ivisurf->configured, listener);
2685}
2686
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002687static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002688 /**
2689 * commit all changes
2690 */
2691 .commit_changes = ivi_layout_commit_changes,
2692
2693 /**
2694 * surface controller interfaces
2695 */
2696 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2697 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2698 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2699 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2700 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2701 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2702 .get_surfaces = ivi_layout_get_surfaces,
2703 .get_id_of_surface = ivi_layout_get_id_of_surface,
2704 .get_surface_from_id = ivi_layout_get_surface_from_id,
2705 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2706 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2707 .surface_set_visibility = ivi_layout_surface_set_visibility,
2708 .surface_get_visibility = ivi_layout_surface_get_visibility,
2709 .surface_set_opacity = ivi_layout_surface_set_opacity,
2710 .surface_get_opacity = ivi_layout_surface_get_opacity,
2711 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2712 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
2713 .surface_set_position = ivi_layout_surface_set_position,
2714 .surface_get_position = ivi_layout_surface_get_position,
2715 .surface_set_dimension = ivi_layout_surface_set_dimension,
2716 .surface_get_dimension = ivi_layout_surface_get_dimension,
2717 .surface_set_orientation = ivi_layout_surface_set_orientation,
2718 .surface_get_orientation = ivi_layout_surface_get_orientation,
2719 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2720 .surface_add_notification = ivi_layout_surface_add_notification,
2721 .surface_remove_notification = ivi_layout_surface_remove_notification,
2722 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2723 .surface_set_transition = ivi_layout_surface_set_transition,
2724 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2725
2726 /**
2727 * layer controller interfaces
2728 */
2729 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2730 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2731 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2732 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2733 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002734 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002735 .get_layers = ivi_layout_get_layers,
2736 .get_id_of_layer = ivi_layout_get_id_of_layer,
2737 .get_layer_from_id = ivi_layout_get_layer_from_id,
2738 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2739 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2740 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2741 .layer_set_visibility = ivi_layout_layer_set_visibility,
2742 .layer_get_visibility = ivi_layout_layer_get_visibility,
2743 .layer_set_opacity = ivi_layout_layer_set_opacity,
2744 .layer_get_opacity = ivi_layout_layer_get_opacity,
2745 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2746 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
2747 .layer_set_position = ivi_layout_layer_set_position,
2748 .layer_get_position = ivi_layout_layer_get_position,
2749 .layer_set_dimension = ivi_layout_layer_set_dimension,
2750 .layer_get_dimension = ivi_layout_layer_get_dimension,
2751 .layer_set_orientation = ivi_layout_layer_set_orientation,
2752 .layer_get_orientation = ivi_layout_layer_get_orientation,
2753 .layer_add_surface = ivi_layout_layer_add_surface,
2754 .layer_remove_surface = ivi_layout_layer_remove_surface,
2755 .layer_set_render_order = ivi_layout_layer_set_render_order,
2756 .layer_add_notification = ivi_layout_layer_add_notification,
2757 .layer_remove_notification = ivi_layout_layer_remove_notification,
2758 .layer_set_transition = ivi_layout_layer_set_transition,
2759
2760 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002761 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002762 */
2763 .get_screen_from_id = ivi_layout_get_screen_from_id,
2764 .get_screen_resolution = ivi_layout_get_screen_resolution,
2765 .get_screens = ivi_layout_get_screens,
2766 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2767 .screen_add_layer = ivi_layout_screen_add_layer,
2768 .screen_set_render_order = ivi_layout_screen_set_render_order,
2769 .screen_get_output = ivi_layout_screen_get_output,
2770
2771 /**
2772 * animation
2773 */
2774 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002775 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2776
2777 /**
2778 * surface content dumping for debugging
2779 */
2780 .surface_get_size = ivi_layout_surface_get_size,
2781 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002782
2783 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002784 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002785 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002786 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002787 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2788
2789 /**
2790 * screen controller interfaces part2
2791 */
2792 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002793};
2794
2795int
2796load_controller_modules(struct weston_compositor *compositor, const char *modules,
2797 int *argc, char *argv[])
2798{
2799 const char *p, *end;
2800 char buffer[256];
2801 int (*controller_module_init)(struct weston_compositor *compositor,
2802 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002803 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002804 size_t interface_version);
2805
2806 if (modules == NULL)
2807 return 0;
2808
2809 p = modules;
2810 while (*p) {
2811 end = strchrnul(p, ',');
2812 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2813
2814 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002815 if (!controller_module_init)
2816 return -1;
2817
2818 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002819 &ivi_layout_interface,
2820 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002821 weston_log("ivi-shell: Initialization of controller module fails");
2822 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002823 }
2824
2825 p = end;
2826 while (*p == ',')
2827 p++;
2828 }
2829
2830 return 0;
2831}