blob: 6d01799861b50a7874cc3604d919369f55d39652 [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(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900535 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900536 struct ivi_layout_layer *ivilayer,
537 struct ivi_layout_surface *ivisurf,
538 struct weston_matrix *m,
539 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900540{
541 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
542 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900543 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900544 struct ivi_rectangle weston_surface_rect = { 0,
545 0,
546 ivisurf->surface->width,
547 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900548 struct ivi_rectangle surface_source_rect = { sp->source_x,
549 sp->source_y,
550 sp->source_width,
551 sp->source_height };
552 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
553 sp->dest_y,
554 sp->dest_width,
555 sp->dest_height };
556 struct ivi_rectangle layer_source_rect = { lp->source_x,
557 lp->source_y,
558 lp->source_width,
559 lp->source_height };
560 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
561 lp->dest_y,
562 lp->dest_width,
563 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900564 struct ivi_rectangle surface_result;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900565
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900566 /*
567 * the whole transformation matrix:m from surface-local
568 * coordinates to global coordinates, which is computed by
569 * two steps,
570 * - surface-local coordinates to layer-local coordinates
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900571 * - layer-local coordinates to a single screen-local coordinates
572 * - a single screen-local coordinates to multi screen coordinates,
573 * which is global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900574 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900575 calc_transformation_matrix(&surface_source_rect,
576 &surface_dest_rect,
577 sp->orientation, m);
578
579 calc_transformation_matrix(&layer_source_rect,
580 &layer_dest_rect,
581 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900582
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900583 weston_matrix_translate(m, output->x, output->y, 0.0f);
584
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900585 /* this intersected ivi_rectangle would be used for masking
586 * weston_surface
587 */
588 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
589 &surface_result);
590
591 /* calc masking area of weston_surface from m */
592 calc_inverse_matrix_transform(m,
593 &layer_dest_rect,
594 &surface_result,
595 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900596}
597
598static void
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900599update_prop(struct ivi_layout_screen *iviscrn,
600 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900601 struct ivi_layout_surface *ivisurf)
602{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900603 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900604 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900605 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900606
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900607 /*In case of no prop change, this just returns*/
608 if (!ivilayer->event_mask && !ivisurf->event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900609 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900610
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900611 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900612
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000613 tmpview = get_weston_view(ivisurf);
614 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900615
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900616 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
617 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
618 can_calc = false;
619 }
620
621 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
622 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
623 can_calc = false;
624 }
625
626 if (can_calc) {
627 wl_list_remove(&ivisurf->transform.link);
628 weston_matrix_init(&ivisurf->transform.matrix);
629
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900630 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900631 iviscrn, ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900632
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000633 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
634 wl_list_insert(&tmpview->geometry.transformation_list,
635 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900636
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000637 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900638 }
639
640 ivisurf->update_count++;
641
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000642 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900643
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000644 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900645}
646
647static void
648commit_changes(struct ivi_layout *layout)
649{
650 struct ivi_layout_screen *iviscrn = NULL;
651 struct ivi_layout_layer *ivilayer = NULL;
652 struct ivi_layout_surface *ivisurf = NULL;
653
654 wl_list_for_each(iviscrn, &layout->screen_list, link) {
655 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900656 /*
657 * If ivilayer is invisible, weston_view of ivisurf doesn't
658 * need to be modified.
659 */
660 if (ivilayer->prop.visibility == false)
661 continue;
662
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900663 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900664 /*
665 * If ivilayer is invisible, weston_view of ivisurf doesn't
666 * need to be modified.
667 */
668 if (ivisurf->prop.visibility == false)
669 continue;
670
671 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900672 }
673 }
674 }
675}
676
677static void
678commit_surface_list(struct ivi_layout *layout)
679{
680 struct ivi_layout_surface *ivisurf = NULL;
681 int32_t dest_x = 0;
682 int32_t dest_y = 0;
683 int32_t dest_width = 0;
684 int32_t dest_height = 0;
685 int32_t configured = 0;
686
687 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300688 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900689 dest_x = ivisurf->prop.dest_x;
690 dest_y = ivisurf->prop.dest_y;
691 dest_width = ivisurf->prop.dest_width;
692 dest_height = ivisurf->prop.dest_height;
693
694 ivi_layout_transition_move_resize_view(ivisurf,
695 ivisurf->pending.prop.dest_x,
696 ivisurf->pending.prop.dest_y,
697 ivisurf->pending.prop.dest_width,
698 ivisurf->pending.prop.dest_height,
699 ivisurf->pending.prop.transition_duration);
700
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300701 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900702 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
703 } else {
704 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
705 }
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 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
713 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
714
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300715 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900716 dest_x = ivisurf->prop.dest_x;
717 dest_y = ivisurf->prop.dest_y;
718 dest_width = ivisurf->prop.dest_width;
719 dest_height = ivisurf->prop.dest_height;
720
721 ivi_layout_transition_move_resize_view(ivisurf,
722 ivisurf->pending.prop.dest_x,
723 ivisurf->pending.prop.dest_y,
724 ivisurf->pending.prop.dest_width,
725 ivisurf->pending.prop.dest_height,
726 ivisurf->pending.prop.transition_duration);
727
728 ivisurf->prop = ivisurf->pending.prop;
729 ivisurf->prop.dest_x = dest_x;
730 ivisurf->prop.dest_y = dest_y;
731 ivisurf->prop.dest_width = dest_width;
732 ivisurf->prop.dest_height = dest_height;
733
734 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
735 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
736
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300737 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900738 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300739 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900740 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
741 } else {
742 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
743 }
744
745 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
746 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
747 configured = 1;
748 }
749
750 ivisurf->prop = ivisurf->pending.prop;
751 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
752 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
753
754 if (configured && !is_surface_transition(ivisurf))
755 wl_signal_emit(&ivisurf->configured, ivisurf);
756 } else {
757 configured = 0;
758 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
759 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
760 configured = 1;
761 }
762
763 ivisurf->prop = ivisurf->pending.prop;
764 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
765 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
766
767 if (configured && !is_surface_transition(ivisurf))
768 wl_signal_emit(&ivisurf->configured, ivisurf);
769 }
770 }
771}
772
773static void
774commit_layer_list(struct ivi_layout *layout)
775{
776 struct ivi_layout_layer *ivilayer = NULL;
777 struct ivi_layout_surface *ivisurf = NULL;
778 struct ivi_layout_surface *next = NULL;
779
780 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300781 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900782 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 -0300783 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900784 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
785 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
786 NULL, NULL,
787 ivilayer->pending.prop.transition_duration);
788 }
789 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
790
791 ivilayer->prop = ivilayer->pending.prop;
792
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000793 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900794 continue;
795 }
796
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000797 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
798 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000799 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000800 wl_list_remove(&ivisurf->order.link);
801 wl_list_init(&ivisurf->order.link);
802 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900803 }
804
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000805 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900806
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000807 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900808 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000809 wl_list_remove(&ivisurf->order.link);
810 wl_list_insert(&ivilayer->order.surface_list,
811 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000812 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000813 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900814 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000815
816 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900817 }
818}
819
820static void
821commit_screen_list(struct ivi_layout *layout)
822{
823 struct ivi_layout_screen *iviscrn = NULL;
824 struct ivi_layout_layer *ivilayer = NULL;
825 struct ivi_layout_layer *next = NULL;
826 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000827 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900828
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900829 /* Clear view list of layout ivi_layer */
830 wl_list_init(&layout->layout_layer.view_list.link);
831
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900832 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000833 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900834 wl_list_for_each_safe(ivilayer, next,
835 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000836 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000837 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900838 wl_list_init(&ivilayer->order.link);
839 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
840 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900841
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000842 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900843
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900844 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
845 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900846 /* FIXME: avoid to insert order.link to multiple screens */
847 wl_list_remove(&ivilayer->order.link);
848
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900849 wl_list_insert(&iviscrn->order.layer_list,
850 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000851 ivilayer->on_screen = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900852 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
853 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900854
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000855 iviscrn->order.dirty = 0;
856 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900857
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900858 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
859 if (ivilayer->prop.visibility == false)
860 continue;
861
862 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900863 if (ivisurf->prop.visibility == false)
864 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000865
866 tmpview = get_weston_view(ivisurf);
867 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900868
869 weston_layer_entry_insert(&layout->layout_layer.view_list,
870 &tmpview->layer_link);
871
872 ivisurf->surface->output = iviscrn->output;
873 }
874 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900875 }
876}
877
878static void
879commit_transition(struct ivi_layout* layout)
880{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300881 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900882 return;
883 }
884
885 wl_list_insert_list(&layout->transitions->transition_list,
886 &layout->pending_transition_list);
887
888 wl_list_init(&layout->pending_transition_list);
889
890 wl_event_source_timer_update(layout->transitions->event_source, 1);
891}
892
893static void
894send_surface_prop(struct ivi_layout_surface *ivisurf)
895{
896 wl_signal_emit(&ivisurf->property_changed, ivisurf);
897 ivisurf->event_mask = 0;
898}
899
900static void
901send_layer_prop(struct ivi_layout_layer *ivilayer)
902{
903 wl_signal_emit(&ivilayer->property_changed, ivilayer);
904 ivilayer->event_mask = 0;
905}
906
907static void
908send_prop(struct ivi_layout *layout)
909{
910 struct ivi_layout_layer *ivilayer = NULL;
911 struct ivi_layout_surface *ivisurf = NULL;
912
913 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900914 if (ivilayer->event_mask)
915 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900916 }
917
918 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900919 if (ivisurf->event_mask)
920 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900921 }
922}
923
924static void
925clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
926{
927 struct ivi_layout_surface *surface_link = NULL;
928 struct ivi_layout_surface *surface_next = NULL;
929
930 wl_list_for_each_safe(surface_link, surface_next,
931 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000932 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900933 wl_list_init(&surface_link->pending.link);
934 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900935}
936
937static void
938clear_surface_order_list(struct ivi_layout_layer *ivilayer)
939{
940 struct ivi_layout_surface *surface_link = NULL;
941 struct ivi_layout_surface *surface_next = NULL;
942
943 wl_list_for_each_safe(surface_link, surface_next,
944 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000945 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900946 wl_list_init(&surface_link->order.link);
947 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900948}
949
950static void
951layer_created(struct wl_listener *listener, void *data)
952{
953 struct ivi_layout_layer *ivilayer = data;
954
955 struct listener_layout_notification *notification =
956 container_of(listener,
957 struct listener_layout_notification,
958 listener);
959
960 struct ivi_layout_notification_callback *created_callback =
961 notification->userdata;
962
963 ((layer_create_notification_func)created_callback->callback)
964 (ivilayer, created_callback->data);
965}
966
967static void
968layer_removed(struct wl_listener *listener, void *data)
969{
970 struct ivi_layout_layer *ivilayer = data;
971
972 struct listener_layout_notification *notification =
973 container_of(listener,
974 struct listener_layout_notification,
975 listener);
976
977 struct ivi_layout_notification_callback *removed_callback =
978 notification->userdata;
979
980 ((layer_remove_notification_func)removed_callback->callback)
981 (ivilayer, removed_callback->data);
982}
983
984static void
985layer_prop_changed(struct wl_listener *listener, void *data)
986{
987 struct ivi_layout_layer *ivilayer = data;
988
989 struct listener_layout_notification *layout_listener =
990 container_of(listener,
991 struct listener_layout_notification,
992 listener);
993
994 struct ivi_layout_notification_callback *prop_callback =
995 layout_listener->userdata;
996
997 ((layer_property_notification_func)prop_callback->callback)
998 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
999}
1000
1001static void
1002surface_created(struct wl_listener *listener, void *data)
1003{
1004 struct ivi_layout_surface *ivisurface = data;
1005
1006 struct listener_layout_notification *notification =
1007 container_of(listener,
1008 struct listener_layout_notification,
1009 listener);
1010
1011 struct ivi_layout_notification_callback *created_callback =
1012 notification->userdata;
1013
1014 ((surface_create_notification_func)created_callback->callback)
1015 (ivisurface, created_callback->data);
1016}
1017
1018static void
1019surface_removed(struct wl_listener *listener, void *data)
1020{
1021 struct ivi_layout_surface *ivisurface = data;
1022
1023 struct listener_layout_notification *notification =
1024 container_of(listener,
1025 struct listener_layout_notification,
1026 listener);
1027
1028 struct ivi_layout_notification_callback *removed_callback =
1029 notification->userdata;
1030
1031 ((surface_remove_notification_func)removed_callback->callback)
1032 (ivisurface, removed_callback->data);
1033}
1034
1035static void
1036surface_prop_changed(struct wl_listener *listener, void *data)
1037{
1038 struct ivi_layout_surface *ivisurf = data;
1039
1040 struct listener_layout_notification *layout_listener =
1041 container_of(listener,
1042 struct listener_layout_notification,
1043 listener);
1044
1045 struct ivi_layout_notification_callback *prop_callback =
1046 layout_listener->userdata;
1047
1048 ((surface_property_notification_func)prop_callback->callback)
1049 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1050
1051 ivisurf->event_mask = 0;
1052}
1053
1054static void
1055surface_configure_changed(struct wl_listener *listener,
1056 void *data)
1057{
1058 struct ivi_layout_surface *ivisurface = data;
1059
1060 struct listener_layout_notification *notification =
1061 container_of(listener,
1062 struct listener_layout_notification,
1063 listener);
1064
1065 struct ivi_layout_notification_callback *configure_changed_callback =
1066 notification->userdata;
1067
1068 ((surface_configure_notification_func)configure_changed_callback->callback)
1069 (ivisurface, configure_changed_callback->data);
1070}
1071
1072static int32_t
1073add_notification(struct wl_signal *signal,
1074 wl_notify_func_t callback,
1075 void *userdata)
1076{
1077 struct listener_layout_notification *notification = NULL;
1078
1079 notification = malloc(sizeof *notification);
1080 if (notification == NULL) {
1081 weston_log("fails to allocate memory\n");
1082 free(userdata);
1083 return IVI_FAILED;
1084 }
1085
1086 notification->listener.notify = callback;
1087 notification->userdata = userdata;
1088
1089 wl_signal_add(signal, &notification->listener);
1090
1091 return IVI_SUCCEEDED;
1092}
1093
1094static void
1095remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1096{
1097 struct wl_listener *listener = NULL;
1098 struct wl_listener *next = NULL;
1099
1100 wl_list_for_each_safe(listener, next, listener_list, link) {
1101 struct listener_layout_notification *notification =
1102 container_of(listener,
1103 struct listener_layout_notification,
1104 listener);
1105
1106 struct ivi_layout_notification_callback *notification_callback =
1107 notification->userdata;
1108
1109 if ((notification_callback->callback != callback) ||
1110 (notification_callback->data != userdata)) {
1111 continue;
1112 }
1113
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001114 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001115
1116 free(notification->userdata);
1117 free(notification);
1118 }
1119}
1120
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001121/**
1122 * Exported APIs of ivi-layout library are implemented from here.
1123 * Brief of APIs is described in ivi-layout-export.h.
1124 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001125static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001126ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1127 void *userdata)
1128{
1129 struct ivi_layout *layout = get_instance();
1130 struct ivi_layout_notification_callback *created_callback = NULL;
1131
1132 if (callback == NULL) {
1133 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1134 return IVI_FAILED;
1135 }
1136
1137 created_callback = malloc(sizeof *created_callback);
1138 if (created_callback == NULL) {
1139 weston_log("fails to allocate memory\n");
1140 return IVI_FAILED;
1141 }
1142
1143 created_callback->callback = callback;
1144 created_callback->data = userdata;
1145
1146 return add_notification(&layout->layer_notification.created,
1147 layer_created,
1148 created_callback);
1149}
1150
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001151static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001152ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1153 void *userdata)
1154{
1155 struct ivi_layout *layout = get_instance();
1156 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1157}
1158
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001159static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001160ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1161 void *userdata)
1162{
1163 struct ivi_layout *layout = get_instance();
1164 struct ivi_layout_notification_callback *removed_callback = NULL;
1165
1166 if (callback == NULL) {
1167 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1168 return IVI_FAILED;
1169 }
1170
1171 removed_callback = malloc(sizeof *removed_callback);
1172 if (removed_callback == NULL) {
1173 weston_log("fails to allocate memory\n");
1174 return IVI_FAILED;
1175 }
1176
1177 removed_callback->callback = callback;
1178 removed_callback->data = userdata;
1179 return add_notification(&layout->layer_notification.removed,
1180 layer_removed,
1181 removed_callback);
1182}
1183
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001184static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001185ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1186 void *userdata)
1187{
1188 struct ivi_layout *layout = get_instance();
1189 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1190}
1191
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001192static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001193ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1194 void *userdata)
1195{
1196 struct ivi_layout *layout = get_instance();
1197 struct ivi_layout_notification_callback *created_callback = NULL;
1198
1199 if (callback == NULL) {
1200 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1201 return IVI_FAILED;
1202 }
1203
1204 created_callback = malloc(sizeof *created_callback);
1205 if (created_callback == NULL) {
1206 weston_log("fails to allocate memory\n");
1207 return IVI_FAILED;
1208 }
1209
1210 created_callback->callback = callback;
1211 created_callback->data = userdata;
1212
1213 return add_notification(&layout->surface_notification.created,
1214 surface_created,
1215 created_callback);
1216}
1217
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001218static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001219ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1220 void *userdata)
1221{
1222 struct ivi_layout *layout = get_instance();
1223 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1224}
1225
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001226static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001227ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1228 void *userdata)
1229{
1230 struct ivi_layout *layout = get_instance();
1231 struct ivi_layout_notification_callback *removed_callback = NULL;
1232
1233 if (callback == NULL) {
1234 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1235 return IVI_FAILED;
1236 }
1237
1238 removed_callback = malloc(sizeof *removed_callback);
1239 if (removed_callback == NULL) {
1240 weston_log("fails to allocate memory\n");
1241 return IVI_FAILED;
1242 }
1243
1244 removed_callback->callback = callback;
1245 removed_callback->data = userdata;
1246
1247 return add_notification(&layout->surface_notification.removed,
1248 surface_removed,
1249 removed_callback);
1250}
1251
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001252static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001253ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1254 void *userdata)
1255{
1256 struct ivi_layout *layout = get_instance();
1257 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1258}
1259
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001260static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001261ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1262 void *userdata)
1263{
1264 struct ivi_layout *layout = get_instance();
1265 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1266 if (callback == NULL) {
1267 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1268 return IVI_FAILED;
1269 }
1270
1271 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1272 if (configure_changed_callback == NULL) {
1273 weston_log("fails to allocate memory\n");
1274 return IVI_FAILED;
1275 }
1276
1277 configure_changed_callback->callback = callback;
1278 configure_changed_callback->data = userdata;
1279
1280 return add_notification(&layout->surface_notification.configure_changed,
1281 surface_configure_changed,
1282 configure_changed_callback);
1283}
1284
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001285static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001286ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1287 void *userdata)
1288{
1289 struct ivi_layout *layout = get_instance();
1290 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1291}
1292
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001293uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001294ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1295{
1296 return ivisurf->id_surface;
1297}
1298
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001299static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001300ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1301{
1302 return ivilayer->id_layer;
1303}
1304
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001305static uint32_t
1306ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1307{
1308 return iviscrn->id_screen;
1309}
1310
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001311static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001312ivi_layout_get_layer_from_id(uint32_t id_layer)
1313{
1314 struct ivi_layout *layout = get_instance();
1315 struct ivi_layout_layer *ivilayer = NULL;
1316
1317 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1318 if (ivilayer->id_layer == id_layer) {
1319 return ivilayer;
1320 }
1321 }
1322
1323 return NULL;
1324}
1325
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001326struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001327ivi_layout_get_surface_from_id(uint32_t id_surface)
1328{
1329 struct ivi_layout *layout = get_instance();
1330 struct ivi_layout_surface *ivisurf = NULL;
1331
1332 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1333 if (ivisurf->id_surface == id_surface) {
1334 return ivisurf;
1335 }
1336 }
1337
1338 return NULL;
1339}
1340
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001341static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001342ivi_layout_get_screen_from_id(uint32_t id_screen)
1343{
1344 struct ivi_layout *layout = get_instance();
1345 struct ivi_layout_screen *iviscrn = NULL;
1346
1347 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Nobuhiko Tanibata3e710d12015-11-25 23:36:09 +09001348 if (iviscrn->id_screen == id_screen)
1349 return iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001350 }
1351
1352 return NULL;
1353}
1354
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001355static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001356ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1357 int32_t *pWidth, int32_t *pHeight)
1358{
1359 struct weston_output *output = NULL;
1360
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001361 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001362 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1363 return IVI_FAILED;
1364 }
1365
1366 output = iviscrn->output;
1367 *pWidth = output->current_mode->width;
1368 *pHeight = output->current_mode->height;
1369
1370 return IVI_SUCCEEDED;
1371}
1372
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001373static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001374ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1375 surface_property_notification_func callback,
1376 void *userdata)
1377{
1378 struct listener_layout_notification* notification = NULL;
1379 struct ivi_layout_notification_callback *prop_callback = NULL;
1380
1381 if (ivisurf == NULL || callback == NULL) {
1382 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1383 return IVI_FAILED;
1384 }
1385
1386 notification = malloc(sizeof *notification);
1387 if (notification == NULL) {
1388 weston_log("fails to allocate memory\n");
1389 return IVI_FAILED;
1390 }
1391
1392 prop_callback = malloc(sizeof *prop_callback);
1393 if (prop_callback == NULL) {
1394 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001395 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001396 return IVI_FAILED;
1397 }
1398
1399 prop_callback->callback = callback;
1400 prop_callback->data = userdata;
1401
1402 notification->listener.notify = surface_prop_changed;
1403 notification->userdata = prop_callback;
1404
1405 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1406
1407 return IVI_SUCCEEDED;
1408}
1409
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001410static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001411ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1412{
1413 if (ivilayer == NULL) {
1414 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1415 return NULL;
1416 }
1417
1418 return &ivilayer->prop;
1419}
1420
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001421static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001422ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1423{
1424 struct ivi_layout *layout = get_instance();
1425 struct ivi_layout_screen *iviscrn = NULL;
1426 int32_t length = 0;
1427 int32_t n = 0;
1428
1429 if (pLength == NULL || ppArray == NULL) {
1430 weston_log("ivi_layout_get_screens: invalid argument\n");
1431 return IVI_FAILED;
1432 }
1433
1434 length = wl_list_length(&layout->screen_list);
1435
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001436 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001437 /* the Array must be free by module which called this function */
1438 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1439 if (*ppArray == NULL) {
1440 weston_log("fails to allocate memory\n");
1441 return IVI_FAILED;
1442 }
1443
1444 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1445 (*ppArray)[n++] = iviscrn;
1446 }
1447 }
1448
1449 *pLength = length;
1450
1451 return IVI_SUCCEEDED;
1452}
1453
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001454static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001455ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1456 int32_t *pLength,
1457 struct ivi_layout_screen ***ppArray)
1458{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001459 int32_t length = 0;
1460 int32_t n = 0;
1461
1462 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1463 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1464 return IVI_FAILED;
1465 }
1466
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001467 if (ivilayer->on_screen != NULL)
1468 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001469
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001470 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001471 /* the Array must be free by module which called this function */
1472 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1473 if (*ppArray == NULL) {
1474 weston_log("fails to allocate memory\n");
1475 return IVI_FAILED;
1476 }
1477
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001478 (*ppArray)[n++] = ivilayer->on_screen;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001479 }
1480
1481 *pLength = length;
1482
1483 return IVI_SUCCEEDED;
1484}
1485
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001486static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001487ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1488{
1489 struct ivi_layout *layout = get_instance();
1490 struct ivi_layout_layer *ivilayer = NULL;
1491 int32_t length = 0;
1492 int32_t n = 0;
1493
1494 if (pLength == NULL || ppArray == NULL) {
1495 weston_log("ivi_layout_get_layers: invalid argument\n");
1496 return IVI_FAILED;
1497 }
1498
1499 length = wl_list_length(&layout->layer_list);
1500
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001501 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001502 /* the Array must be free by module which called this function */
1503 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1504 if (*ppArray == NULL) {
1505 weston_log("fails to allocate memory\n");
1506 return IVI_FAILED;
1507 }
1508
1509 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1510 (*ppArray)[n++] = ivilayer;
1511 }
1512 }
1513
1514 *pLength = length;
1515
1516 return IVI_SUCCEEDED;
1517}
1518
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001519static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001520ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1521 int32_t *pLength,
1522 struct ivi_layout_layer ***ppArray)
1523{
1524 struct ivi_layout_layer *ivilayer = NULL;
1525 int32_t length = 0;
1526 int32_t n = 0;
1527
1528 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1529 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1530 return IVI_FAILED;
1531 }
1532
1533 length = wl_list_length(&iviscrn->order.layer_list);
1534
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001535 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001536 /* the Array must be free by module which called this function */
1537 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1538 if (*ppArray == NULL) {
1539 weston_log("fails to allocate memory\n");
1540 return IVI_FAILED;
1541 }
1542
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001543 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001544 (*ppArray)[n++] = ivilayer;
1545 }
1546 }
1547
1548 *pLength = length;
1549
1550 return IVI_SUCCEEDED;
1551}
1552
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001553static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001554ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1555 int32_t *pLength,
1556 struct ivi_layout_layer ***ppArray)
1557{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001558 int32_t length = 0;
1559 int32_t n = 0;
1560
1561 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1562 weston_log("ivi_layout_getLayers: invalid argument\n");
1563 return IVI_FAILED;
1564 }
1565
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001566 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001567 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001568 length = 1;
1569 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001570 if (*ppArray == NULL) {
1571 weston_log("fails to allocate memory\n");
1572 return IVI_FAILED;
1573 }
1574
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001575 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001576 }
1577
1578 *pLength = length;
1579
1580 return IVI_SUCCEEDED;
1581}
1582
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001583static
1584int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001585ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1586{
1587 struct ivi_layout *layout = get_instance();
1588 struct ivi_layout_surface *ivisurf = NULL;
1589 int32_t length = 0;
1590 int32_t n = 0;
1591
1592 if (pLength == NULL || ppArray == NULL) {
1593 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1594 return IVI_FAILED;
1595 }
1596
1597 length = wl_list_length(&layout->surface_list);
1598
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001599 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001600 /* the Array must be free by module which called this function */
1601 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1602 if (*ppArray == NULL) {
1603 weston_log("fails to allocate memory\n");
1604 return IVI_FAILED;
1605 }
1606
1607 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1608 (*ppArray)[n++] = ivisurf;
1609 }
1610 }
1611
1612 *pLength = length;
1613
1614 return IVI_SUCCEEDED;
1615}
1616
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001617static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001618ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1619 int32_t *pLength,
1620 struct ivi_layout_surface ***ppArray)
1621{
1622 struct ivi_layout_surface *ivisurf = NULL;
1623 int32_t length = 0;
1624 int32_t n = 0;
1625
1626 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1627 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1628 return IVI_FAILED;
1629 }
1630
1631 length = wl_list_length(&ivilayer->order.surface_list);
1632
1633 if (length != 0) {
1634 /* the Array must be free by module which called this function */
1635 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1636 if (*ppArray == NULL) {
1637 weston_log("fails to allocate memory\n");
1638 return IVI_FAILED;
1639 }
1640
1641 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1642 (*ppArray)[n++] = ivisurf;
1643 }
1644 }
1645
1646 *pLength = length;
1647
1648 return IVI_SUCCEEDED;
1649}
1650
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001651static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001652ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1653 int32_t width, int32_t height)
1654{
1655 struct ivi_layout *layout = get_instance();
1656 struct ivi_layout_layer *ivilayer = NULL;
1657
1658 ivilayer = get_layer(&layout->layer_list, id_layer);
1659 if (ivilayer != NULL) {
1660 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001661 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001662 return ivilayer;
1663 }
1664
1665 ivilayer = calloc(1, sizeof *ivilayer);
1666 if (ivilayer == NULL) {
1667 weston_log("fails to allocate memory\n");
1668 return NULL;
1669 }
1670
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001671 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001672 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001673 ivilayer->layout = layout;
1674 ivilayer->id_layer = id_layer;
1675
1676 init_layer_properties(&ivilayer->prop, width, height);
1677 ivilayer->event_mask = 0;
1678
1679 wl_list_init(&ivilayer->pending.surface_list);
1680 wl_list_init(&ivilayer->pending.link);
1681 ivilayer->pending.prop = ivilayer->prop;
1682
1683 wl_list_init(&ivilayer->order.surface_list);
1684 wl_list_init(&ivilayer->order.link);
1685
1686 wl_list_insert(&layout->layer_list, &ivilayer->link);
1687
1688 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1689
1690 return ivilayer;
1691}
1692
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001693static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001694ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1695{
1696 if (ivilayer == NULL) {
1697 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1698 return;
1699 }
1700
1701 remove_all_notification(&ivilayer->property_changed.listener_list);
1702}
1703
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001704static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001705ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1706 layer_property_notification_func callback,
1707 void *userdata)
1708{
1709 if (ivilayer == NULL) {
1710 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1711 return;
1712 }
1713
1714 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1715}
1716
1717static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001718ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001719{
1720 struct ivi_layout *layout = get_instance();
1721
1722 if (ivilayer == NULL) {
1723 weston_log("ivi_layout_layer_remove: invalid argument\n");
1724 return;
1725 }
1726
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001727 if (--ivilayer->ref_count > 0)
1728 return;
1729
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001730 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1731
1732 clear_surface_pending_list(ivilayer);
1733 clear_surface_order_list(ivilayer);
1734
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001735 wl_list_remove(&ivilayer->pending.link);
1736 wl_list_remove(&ivilayer->order.link);
1737 wl_list_remove(&ivilayer->link);
1738
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001739 ivi_layout_layer_remove_notification(ivilayer);
1740
1741 free(ivilayer);
1742}
1743
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001744int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001745ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1746 bool newVisibility)
1747{
1748 struct ivi_layout_layer_properties *prop = NULL;
1749
1750 if (ivilayer == NULL) {
1751 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1752 return IVI_FAILED;
1753 }
1754
1755 prop = &ivilayer->pending.prop;
1756 prop->visibility = newVisibility;
1757
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001758 if (ivilayer->prop.visibility != newVisibility)
1759 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1760 else
1761 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001762
1763 return IVI_SUCCEEDED;
1764}
1765
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001766static bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001767ivi_layout_layer_get_visibility(struct ivi_layout_layer *ivilayer)
1768{
1769 if (ivilayer == NULL) {
1770 weston_log("ivi_layout_layer_get_visibility: invalid argument\n");
1771 return false;
1772 }
1773
1774 return ivilayer->prop.visibility;
1775}
1776
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001777int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001778ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1779 wl_fixed_t opacity)
1780{
1781 struct ivi_layout_layer_properties *prop = NULL;
1782
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001783 if (ivilayer == NULL ||
1784 opacity < wl_fixed_from_double(0.0) ||
1785 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001786 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1787 return IVI_FAILED;
1788 }
1789
1790 prop = &ivilayer->pending.prop;
1791 prop->opacity = opacity;
1792
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001793 if (ivilayer->prop.opacity != opacity)
1794 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1795 else
1796 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001797
1798 return IVI_SUCCEEDED;
1799}
1800
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001801wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001802ivi_layout_layer_get_opacity(struct ivi_layout_layer *ivilayer)
1803{
1804 if (ivilayer == NULL) {
1805 weston_log("ivi_layout_layer_get_opacity: invalid argument\n");
1806 return wl_fixed_from_double(0.0);
1807 }
1808
1809 return ivilayer->prop.opacity;
1810}
1811
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001812static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001813ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1814 int32_t x, int32_t y,
1815 int32_t width, int32_t height)
1816{
1817 struct ivi_layout_layer_properties *prop = NULL;
1818
1819 if (ivilayer == NULL) {
1820 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1821 return IVI_FAILED;
1822 }
1823
1824 prop = &ivilayer->pending.prop;
1825 prop->source_x = x;
1826 prop->source_y = y;
1827 prop->source_width = width;
1828 prop->source_height = height;
1829
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001830 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1831 ivilayer->prop.source_width != width ||
1832 ivilayer->prop.source_height != height)
1833 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1834 else
1835 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001836
1837 return IVI_SUCCEEDED;
1838}
1839
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001840static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001841ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1842 int32_t x, int32_t y,
1843 int32_t width, int32_t height)
1844{
1845 struct ivi_layout_layer_properties *prop = NULL;
1846
1847 if (ivilayer == NULL) {
1848 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1849 return IVI_FAILED;
1850 }
1851
1852 prop = &ivilayer->pending.prop;
1853 prop->dest_x = x;
1854 prop->dest_y = y;
1855 prop->dest_width = width;
1856 prop->dest_height = height;
1857
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001858 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1859 ivilayer->prop.dest_width != width ||
1860 ivilayer->prop.dest_height != height)
1861 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1862 else
1863 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001864
1865 return IVI_SUCCEEDED;
1866}
1867
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001868static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001869ivi_layout_layer_get_dimension(struct ivi_layout_layer *ivilayer,
1870 int32_t *dest_width, int32_t *dest_height)
1871{
1872 if (ivilayer == NULL || dest_width == NULL || dest_height == NULL) {
1873 weston_log("ivi_layout_layer_get_dimension: invalid argument\n");
1874 return IVI_FAILED;
1875 }
1876
1877 *dest_width = ivilayer->prop.dest_width;
1878 *dest_height = ivilayer->prop.dest_height;
1879
1880 return IVI_SUCCEEDED;
1881}
1882
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001883static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001884ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
1885 int32_t dest_width, int32_t dest_height)
1886{
1887 struct ivi_layout_layer_properties *prop = NULL;
1888
1889 if (ivilayer == NULL) {
1890 weston_log("ivi_layout_layer_set_dimension: invalid argument\n");
1891 return IVI_FAILED;
1892 }
1893
1894 prop = &ivilayer->pending.prop;
1895
1896 prop->dest_width = dest_width;
1897 prop->dest_height = dest_height;
1898
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001899 if (ivilayer->prop.dest_width != dest_width ||
1900 ivilayer->prop.dest_height != dest_height)
1901 ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
1902 else
1903 ivilayer->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001904
1905 return IVI_SUCCEEDED;
1906}
1907
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001908int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001909ivi_layout_layer_get_position(struct ivi_layout_layer *ivilayer,
1910 int32_t *dest_x, int32_t *dest_y)
1911{
1912 if (ivilayer == NULL || dest_x == NULL || dest_y == NULL) {
1913 weston_log("ivi_layout_layer_get_position: invalid argument\n");
1914 return IVI_FAILED;
1915 }
1916
1917 *dest_x = ivilayer->prop.dest_x;
1918 *dest_y = ivilayer->prop.dest_y;
1919
1920 return IVI_SUCCEEDED;
1921}
1922
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001923int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001924ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
1925 int32_t dest_x, int32_t dest_y)
1926{
1927 struct ivi_layout_layer_properties *prop = NULL;
1928
1929 if (ivilayer == NULL) {
1930 weston_log("ivi_layout_layer_set_position: invalid argument\n");
1931 return IVI_FAILED;
1932 }
1933
1934 prop = &ivilayer->pending.prop;
1935 prop->dest_x = dest_x;
1936 prop->dest_y = dest_y;
1937
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001938 if (ivilayer->prop.dest_x != dest_x || ivilayer->prop.dest_y != dest_y)
1939 ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
1940 else
1941 ivilayer->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001942
1943 return IVI_SUCCEEDED;
1944}
1945
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001946static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001947ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1948 enum wl_output_transform orientation)
1949{
1950 struct ivi_layout_layer_properties *prop = NULL;
1951
1952 if (ivilayer == NULL) {
1953 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1954 return IVI_FAILED;
1955 }
1956
1957 prop = &ivilayer->pending.prop;
1958 prop->orientation = orientation;
1959
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001960 if (ivilayer->prop.orientation != orientation)
1961 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1962 else
1963 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001964
1965 return IVI_SUCCEEDED;
1966}
1967
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001968static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001969ivi_layout_layer_get_orientation(struct ivi_layout_layer *ivilayer)
1970{
1971 if (ivilayer == NULL) {
1972 weston_log("ivi_layout_layer_get_orientation: invalid argument\n");
1973 return 0;
1974 }
1975
1976 return ivilayer->prop.orientation;
1977}
1978
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001979int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001980ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1981 struct ivi_layout_surface **pSurface,
1982 int32_t number)
1983{
1984 struct ivi_layout *layout = get_instance();
1985 struct ivi_layout_surface *ivisurf = NULL;
1986 struct ivi_layout_surface *next = NULL;
1987 uint32_t *id_surface = NULL;
1988 int32_t i = 0;
1989
1990 if (ivilayer == NULL) {
1991 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1992 return IVI_FAILED;
1993 }
1994
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001995 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001996
1997 for (i = 0; i < number; i++) {
1998 id_surface = &pSurface[i]->id_surface;
1999
2000 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2001 if (*id_surface != ivisurf->id_surface) {
2002 continue;
2003 }
2004
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002005 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002006 wl_list_insert(&ivilayer->pending.surface_list,
2007 &ivisurf->pending.link);
2008 break;
2009 }
2010 }
2011
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002012 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002013
2014 return IVI_SUCCEEDED;
2015}
2016
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002017int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002018ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
2019 bool newVisibility)
2020{
2021 struct ivi_layout_surface_properties *prop = NULL;
2022
2023 if (ivisurf == NULL) {
2024 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
2025 return IVI_FAILED;
2026 }
2027
2028 prop = &ivisurf->pending.prop;
2029 prop->visibility = newVisibility;
2030
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002031 if (ivisurf->prop.visibility != newVisibility)
2032 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
2033 else
2034 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002035
2036 return IVI_SUCCEEDED;
2037}
2038
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002039bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002040ivi_layout_surface_get_visibility(struct ivi_layout_surface *ivisurf)
2041{
2042 if (ivisurf == NULL) {
2043 weston_log("ivi_layout_surface_get_visibility: invalid argument\n");
2044 return false;
2045 }
2046
2047 return ivisurf->prop.visibility;
2048}
2049
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002050int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002051ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
2052 wl_fixed_t opacity)
2053{
2054 struct ivi_layout_surface_properties *prop = NULL;
2055
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09002056 if (ivisurf == NULL ||
2057 opacity < wl_fixed_from_double(0.0) ||
2058 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002059 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
2060 return IVI_FAILED;
2061 }
2062
2063 prop = &ivisurf->pending.prop;
2064 prop->opacity = opacity;
2065
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002066 if (ivisurf->prop.opacity != opacity)
2067 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
2068 else
2069 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002070
2071 return IVI_SUCCEEDED;
2072}
2073
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002074wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002075ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
2076{
2077 if (ivisurf == NULL) {
2078 weston_log("ivi_layout_surface_get_opacity: invalid argument\n");
2079 return wl_fixed_from_double(0.0);
2080 }
2081
2082 return ivisurf->prop.opacity;
2083}
2084
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002085int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002086ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
2087 int32_t x, int32_t y,
2088 int32_t width, int32_t height)
2089{
2090 struct ivi_layout_surface_properties *prop = NULL;
2091
2092 if (ivisurf == NULL) {
2093 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
2094 return IVI_FAILED;
2095 }
2096
2097 prop = &ivisurf->pending.prop;
2098 prop->start_x = prop->dest_x;
2099 prop->start_y = prop->dest_y;
2100 prop->dest_x = x;
2101 prop->dest_y = y;
2102 prop->start_width = prop->dest_width;
2103 prop->start_height = prop->dest_height;
2104 prop->dest_width = width;
2105 prop->dest_height = height;
2106
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002107 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2108 ivisurf->prop.dest_width != width ||
2109 ivisurf->prop.dest_height != height)
2110 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2111 else
2112 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002113
2114 return IVI_SUCCEEDED;
2115}
2116
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002117static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002118ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
2119 int32_t dest_width, int32_t dest_height)
2120{
2121 struct ivi_layout_surface_properties *prop = NULL;
2122
2123 if (ivisurf == NULL) {
2124 weston_log("ivi_layout_surface_set_dimension: invalid argument\n");
2125 return IVI_FAILED;
2126 }
2127
2128 prop = &ivisurf->pending.prop;
2129 prop->dest_width = dest_width;
2130 prop->dest_height = dest_height;
2131
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002132 if (ivisurf->prop.dest_width != dest_width ||
2133 ivisurf->prop.dest_height != dest_height)
2134 ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
2135 else
2136 ivisurf->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002137
2138 return IVI_SUCCEEDED;
2139}
2140
2141int32_t
2142ivi_layout_surface_get_dimension(struct ivi_layout_surface *ivisurf,
2143 int32_t *dest_width, int32_t *dest_height)
2144{
2145 if (ivisurf == NULL || dest_width == NULL || dest_height == NULL) {
2146 weston_log("ivi_layout_surface_get_dimension: invalid argument\n");
2147 return IVI_FAILED;
2148 }
2149
2150 *dest_width = ivisurf->prop.dest_width;
2151 *dest_height = ivisurf->prop.dest_height;
2152
2153 return IVI_SUCCEEDED;
2154}
2155
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002156static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002157ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
2158 int32_t dest_x, int32_t dest_y)
2159{
2160 struct ivi_layout_surface_properties *prop = NULL;
2161
2162 if (ivisurf == NULL) {
2163 weston_log("ivi_layout_surface_set_position: invalid argument\n");
2164 return IVI_FAILED;
2165 }
2166
2167 prop = &ivisurf->pending.prop;
2168 prop->dest_x = dest_x;
2169 prop->dest_y = dest_y;
2170
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002171 if (ivisurf->prop.dest_x != dest_x || ivisurf->prop.dest_y != dest_y)
2172 ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
2173 else
2174 ivisurf->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002175
2176 return IVI_SUCCEEDED;
2177}
2178
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002179static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002180ivi_layout_surface_get_position(struct ivi_layout_surface *ivisurf,
2181 int32_t *dest_x, int32_t *dest_y)
2182{
2183 if (ivisurf == NULL || dest_x == NULL || dest_y == NULL) {
2184 weston_log("ivi_layout_surface_get_position: invalid argument\n");
2185 return IVI_FAILED;
2186 }
2187
2188 *dest_x = ivisurf->prop.dest_x;
2189 *dest_y = ivisurf->prop.dest_y;
2190
2191 return IVI_SUCCEEDED;
2192}
2193
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002194static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002195ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2196 enum wl_output_transform orientation)
2197{
2198 struct ivi_layout_surface_properties *prop = NULL;
2199
2200 if (ivisurf == NULL) {
2201 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2202 return IVI_FAILED;
2203 }
2204
2205 prop = &ivisurf->pending.prop;
2206 prop->orientation = orientation;
2207
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002208 if (ivisurf->prop.orientation != orientation)
2209 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2210 else
2211 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002212
2213 return IVI_SUCCEEDED;
2214}
2215
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002216static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002217ivi_layout_surface_get_orientation(struct ivi_layout_surface *ivisurf)
2218{
2219 if (ivisurf == NULL) {
2220 weston_log("ivi_layout_surface_get_orientation: invalid argument\n");
2221 return 0;
2222 }
2223
2224 return ivisurf->prop.orientation;
2225}
2226
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002227static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002228ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2229 struct ivi_layout_layer *addlayer)
2230{
2231 struct ivi_layout *layout = get_instance();
2232 struct ivi_layout_layer *ivilayer = NULL;
2233 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002234
2235 if (iviscrn == NULL || addlayer == NULL) {
2236 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2237 return IVI_FAILED;
2238 }
2239
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00002240 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002241 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2242 return IVI_SUCCEEDED;
2243 }
2244
2245 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2246 if (ivilayer->id_layer == addlayer->id_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002247 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002248 wl_list_insert(&iviscrn->pending.layer_list,
2249 &ivilayer->pending.link);
2250 break;
2251 }
2252 }
2253
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002254 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002255
2256 return IVI_SUCCEEDED;
2257}
2258
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002259static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002260ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2261 struct ivi_layout_layer **pLayer,
2262 const int32_t number)
2263{
2264 struct ivi_layout *layout = get_instance();
2265 struct ivi_layout_layer *ivilayer = NULL;
2266 struct ivi_layout_layer *next = NULL;
2267 uint32_t *id_layer = NULL;
2268 int32_t i = 0;
2269
2270 if (iviscrn == NULL) {
2271 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2272 return IVI_FAILED;
2273 }
2274
2275 wl_list_for_each_safe(ivilayer, next,
2276 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002277 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002278 wl_list_init(&ivilayer->pending.link);
2279 }
2280
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002281 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002282
2283 for (i = 0; i < number; i++) {
2284 id_layer = &pLayer[i]->id_layer;
2285 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2286 if (*id_layer != ivilayer->id_layer) {
2287 continue;
2288 }
2289
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002290 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002291 wl_list_insert(&iviscrn->pending.layer_list,
2292 &ivilayer->pending.link);
2293 break;
2294 }
2295 }
2296
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002297 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002298
2299 return IVI_SUCCEEDED;
2300}
2301
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002302static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002303ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2304{
2305 return iviscrn->output;
2306}
2307
2308/**
2309 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2310 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2311 * This function is used to get the result of drawing by clients.
2312 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002313static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002314ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2315{
2316 return ivisurf != NULL ? ivisurf->surface : NULL;
2317}
2318
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002319static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002320ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2321 int32_t *width, int32_t *height,
2322 int32_t *stride)
2323{
2324 int32_t w;
2325 int32_t h;
2326 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2327
2328 if (ivisurf == NULL || ivisurf->surface == NULL) {
2329 weston_log("%s: invalid argument\n", __func__);
2330 return IVI_FAILED;
2331 }
2332
2333 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2334
2335 if (width != NULL)
2336 *width = w;
2337
2338 if (height != NULL)
2339 *height = h;
2340
2341 if (stride != NULL)
2342 *stride = w * bytespp;
2343
2344 return IVI_SUCCEEDED;
2345}
2346
2347static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002348ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2349 layer_property_notification_func callback,
2350 void *userdata)
2351{
2352 struct ivi_layout_notification_callback *prop_callback = NULL;
2353
2354 if (ivilayer == NULL || callback == NULL) {
2355 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2356 return IVI_FAILED;
2357 }
2358
2359 prop_callback = malloc(sizeof *prop_callback);
2360 if (prop_callback == NULL) {
2361 weston_log("fails to allocate memory\n");
2362 return IVI_FAILED;
2363 }
2364
2365 prop_callback->callback = callback;
2366 prop_callback->data = userdata;
2367
2368 return add_notification(&ivilayer->property_changed,
2369 layer_prop_changed,
2370 prop_callback);
2371}
2372
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002373static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002374ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2375{
2376 if (ivisurf == NULL) {
2377 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2378 return NULL;
2379 }
2380
2381 return &ivisurf->prop;
2382}
2383
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002384static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002385ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2386 struct ivi_layout_surface *addsurf)
2387{
2388 struct ivi_layout *layout = get_instance();
2389 struct ivi_layout_surface *ivisurf = NULL;
2390 struct ivi_layout_surface *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002391
2392 if (ivilayer == NULL || addsurf == NULL) {
2393 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2394 return IVI_FAILED;
2395 }
2396
Ucan, Emre (ADITG/SW1)4a183642015-08-28 12:59:04 +00002397 if (addsurf->on_layer == ivilayer) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002398 weston_log("ivi_layout_layer_add_surface: addsurf is already available\n");
2399 return IVI_SUCCEEDED;
2400 }
2401
2402 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2403 if (ivisurf->id_surface == addsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002404 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002405 wl_list_insert(&ivilayer->pending.surface_list,
2406 &ivisurf->pending.link);
2407 break;
2408 }
2409 }
2410
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002411 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002412
2413 return IVI_SUCCEEDED;
2414}
2415
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002416static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002417ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2418 struct ivi_layout_surface *remsurf)
2419{
2420 struct ivi_layout_surface *ivisurf = NULL;
2421 struct ivi_layout_surface *next = NULL;
2422
2423 if (ivilayer == NULL || remsurf == NULL) {
2424 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2425 return;
2426 }
2427
2428 wl_list_for_each_safe(ivisurf, next,
2429 &ivilayer->pending.surface_list, pending.link) {
2430 if (ivisurf->id_surface == remsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002431 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002432 wl_list_init(&ivisurf->pending.link);
2433 break;
2434 }
2435 }
2436
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002437 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002438}
2439
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002440static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002441ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2442 int32_t x, int32_t y,
2443 int32_t width, int32_t height)
2444{
2445 struct ivi_layout_surface_properties *prop = NULL;
2446
2447 if (ivisurf == NULL) {
2448 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2449 return IVI_FAILED;
2450 }
2451
2452 prop = &ivisurf->pending.prop;
2453 prop->source_x = x;
2454 prop->source_y = y;
2455 prop->source_width = width;
2456 prop->source_height = height;
2457
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002458 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2459 ivisurf->prop.source_width != width ||
2460 ivisurf->prop.source_height != height)
2461 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2462 else
2463 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002464
2465 return IVI_SUCCEEDED;
2466}
2467
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002468int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002469ivi_layout_commit_changes(void)
2470{
2471 struct ivi_layout *layout = get_instance();
2472
2473 commit_surface_list(layout);
2474 commit_layer_list(layout);
2475 commit_screen_list(layout);
2476
2477 commit_transition(layout);
2478
2479 commit_changes(layout);
2480 send_prop(layout);
2481 weston_compositor_schedule_repaint(layout->compositor);
2482
2483 return IVI_SUCCEEDED;
2484}
2485
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002486static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002487ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2488 enum ivi_layout_transition_type type,
2489 uint32_t duration)
2490{
2491 if (ivilayer == NULL) {
2492 weston_log("%s: invalid argument\n", __func__);
2493 return -1;
2494 }
2495
2496 ivilayer->pending.prop.transition_type = type;
2497 ivilayer->pending.prop.transition_duration = duration;
2498
2499 return 0;
2500}
2501
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002502static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002503ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2504 uint32_t is_fade_in,
2505 double start_alpha, double end_alpha)
2506{
2507 if (ivilayer == NULL) {
2508 weston_log("%s: invalid argument\n", __func__);
2509 return -1;
2510 }
2511
2512 ivilayer->pending.prop.is_fade_in = is_fade_in;
2513 ivilayer->pending.prop.start_alpha = start_alpha;
2514 ivilayer->pending.prop.end_alpha = end_alpha;
2515
2516 return 0;
2517}
2518
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002519static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002520ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2521 uint32_t duration)
2522{
2523 struct ivi_layout_surface_properties *prop;
2524
2525 if (ivisurf == NULL) {
2526 weston_log("%s: invalid argument\n", __func__);
2527 return -1;
2528 }
2529
2530 prop = &ivisurf->pending.prop;
2531 prop->transition_duration = duration*10;
2532 return 0;
2533}
2534
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002535static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002536ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2537 enum ivi_layout_transition_type type,
2538 uint32_t duration)
2539{
2540 struct ivi_layout_surface_properties *prop;
2541
2542 if (ivisurf == NULL) {
2543 weston_log("%s: invalid argument\n", __func__);
2544 return -1;
2545 }
2546
2547 prop = &ivisurf->pending.prop;
2548 prop->transition_type = type;
2549 prop->transition_duration = duration;
2550 return 0;
2551}
2552
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002553static int32_t
2554ivi_layout_surface_dump(struct weston_surface *surface,
2555 void *target, size_t size,int32_t x, int32_t y,
2556 int32_t width, int32_t height)
2557{
2558 int result = 0;
2559
2560 if (surface == NULL) {
2561 weston_log("%s: invalid argument\n", __func__);
2562 return IVI_FAILED;
2563 }
2564
2565 result = weston_surface_copy_content(
2566 surface, target, size,
2567 x, y, width, height);
2568
2569 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2570}
2571
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002572/**
2573 * methods of interaction between ivi-shell with ivi-layout
2574 */
2575struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002576ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2577{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002578 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002579 return NULL;
2580
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002581 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002582}
2583
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002584void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002585ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2586 int32_t width, int32_t height)
2587{
2588 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002589
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002590 /* emit callback which is set by ivi-layout api user */
2591 wl_signal_emit(&layout->surface_notification.configure_changed,
2592 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002593}
2594
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002595static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002596ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2597 ivi_controller_surface_content_callback callback,
2598 void* userdata)
2599{
2600 int32_t ret = IVI_FAILED;
2601
2602 if (ivisurf != NULL) {
2603 ivisurf->content_observer.callback = callback;
2604 ivisurf->content_observer.userdata = userdata;
2605 ret = IVI_SUCCEEDED;
2606 }
2607 return ret;
2608}
2609
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002610struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002611ivi_layout_surface_create(struct weston_surface *wl_surface,
2612 uint32_t id_surface)
2613{
2614 struct ivi_layout *layout = get_instance();
2615 struct ivi_layout_surface *ivisurf = NULL;
2616 struct weston_view *tmpview = NULL;
2617
2618 if (wl_surface == NULL) {
2619 weston_log("ivi_layout_surface_create: invalid argument\n");
2620 return NULL;
2621 }
2622
2623 ivisurf = get_surface(&layout->surface_list, id_surface);
2624 if (ivisurf != NULL) {
2625 if (ivisurf->surface != NULL) {
2626 weston_log("id_surface(%d) is already created\n", id_surface);
2627 return NULL;
2628 }
2629 }
2630
2631 ivisurf = calloc(1, sizeof *ivisurf);
2632 if (ivisurf == NULL) {
2633 weston_log("fails to allocate memory\n");
2634 return NULL;
2635 }
2636
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002637 wl_signal_init(&ivisurf->property_changed);
2638 wl_signal_init(&ivisurf->configured);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002639 ivisurf->id_surface = id_surface;
2640 ivisurf->layout = layout;
2641
2642 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002643
2644 tmpview = weston_view_create(wl_surface);
2645 if (tmpview == NULL) {
2646 weston_log("fails to allocate memory\n");
2647 }
2648
2649 ivisurf->surface->width_from_buffer = 0;
2650 ivisurf->surface->height_from_buffer = 0;
2651
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002652 weston_matrix_init(&ivisurf->transform.matrix);
2653 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002654
2655 init_surface_properties(&ivisurf->prop);
2656 ivisurf->event_mask = 0;
2657
2658 ivisurf->pending.prop = ivisurf->prop;
2659 wl_list_init(&ivisurf->pending.link);
2660
2661 wl_list_init(&ivisurf->order.link);
2662 wl_list_init(&ivisurf->order.layer_list);
2663
2664 wl_list_insert(&layout->surface_list, &ivisurf->link);
2665
2666 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2667
2668 return ivisurf;
2669}
2670
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002671void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002672ivi_layout_init_with_compositor(struct weston_compositor *ec)
2673{
2674 struct ivi_layout *layout = get_instance();
2675
2676 layout->compositor = ec;
2677
2678 wl_list_init(&layout->surface_list);
2679 wl_list_init(&layout->layer_list);
2680 wl_list_init(&layout->screen_list);
2681
2682 wl_signal_init(&layout->layer_notification.created);
2683 wl_signal_init(&layout->layer_notification.removed);
2684
2685 wl_signal_init(&layout->surface_notification.created);
2686 wl_signal_init(&layout->surface_notification.removed);
2687 wl_signal_init(&layout->surface_notification.configure_changed);
2688
2689 /* Add layout_layer at the last of weston_compositor.layer_list */
2690 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2691
2692 create_screen(ec);
2693
2694 layout->transitions = ivi_layout_transition_set_create(ec);
2695 wl_list_init(&layout->pending_transition_list);
2696}
2697
2698
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002699void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002700ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2701 struct wl_listener* listener)
2702{
2703 wl_signal_add(&ivisurf->configured, listener);
2704}
2705
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002706static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002707 /**
2708 * commit all changes
2709 */
2710 .commit_changes = ivi_layout_commit_changes,
2711
2712 /**
2713 * surface controller interfaces
2714 */
2715 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2716 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2717 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2718 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2719 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2720 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2721 .get_surfaces = ivi_layout_get_surfaces,
2722 .get_id_of_surface = ivi_layout_get_id_of_surface,
2723 .get_surface_from_id = ivi_layout_get_surface_from_id,
2724 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2725 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2726 .surface_set_visibility = ivi_layout_surface_set_visibility,
2727 .surface_get_visibility = ivi_layout_surface_get_visibility,
2728 .surface_set_opacity = ivi_layout_surface_set_opacity,
2729 .surface_get_opacity = ivi_layout_surface_get_opacity,
2730 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2731 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
2732 .surface_set_position = ivi_layout_surface_set_position,
2733 .surface_get_position = ivi_layout_surface_get_position,
2734 .surface_set_dimension = ivi_layout_surface_set_dimension,
2735 .surface_get_dimension = ivi_layout_surface_get_dimension,
2736 .surface_set_orientation = ivi_layout_surface_set_orientation,
2737 .surface_get_orientation = ivi_layout_surface_get_orientation,
2738 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2739 .surface_add_notification = ivi_layout_surface_add_notification,
2740 .surface_remove_notification = ivi_layout_surface_remove_notification,
2741 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2742 .surface_set_transition = ivi_layout_surface_set_transition,
2743 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2744
2745 /**
2746 * layer controller interfaces
2747 */
2748 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2749 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2750 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2751 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2752 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002753 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002754 .get_layers = ivi_layout_get_layers,
2755 .get_id_of_layer = ivi_layout_get_id_of_layer,
2756 .get_layer_from_id = ivi_layout_get_layer_from_id,
2757 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2758 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2759 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2760 .layer_set_visibility = ivi_layout_layer_set_visibility,
2761 .layer_get_visibility = ivi_layout_layer_get_visibility,
2762 .layer_set_opacity = ivi_layout_layer_set_opacity,
2763 .layer_get_opacity = ivi_layout_layer_get_opacity,
2764 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2765 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
2766 .layer_set_position = ivi_layout_layer_set_position,
2767 .layer_get_position = ivi_layout_layer_get_position,
2768 .layer_set_dimension = ivi_layout_layer_set_dimension,
2769 .layer_get_dimension = ivi_layout_layer_get_dimension,
2770 .layer_set_orientation = ivi_layout_layer_set_orientation,
2771 .layer_get_orientation = ivi_layout_layer_get_orientation,
2772 .layer_add_surface = ivi_layout_layer_add_surface,
2773 .layer_remove_surface = ivi_layout_layer_remove_surface,
2774 .layer_set_render_order = ivi_layout_layer_set_render_order,
2775 .layer_add_notification = ivi_layout_layer_add_notification,
2776 .layer_remove_notification = ivi_layout_layer_remove_notification,
2777 .layer_set_transition = ivi_layout_layer_set_transition,
2778
2779 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002780 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002781 */
2782 .get_screen_from_id = ivi_layout_get_screen_from_id,
2783 .get_screen_resolution = ivi_layout_get_screen_resolution,
2784 .get_screens = ivi_layout_get_screens,
2785 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2786 .screen_add_layer = ivi_layout_screen_add_layer,
2787 .screen_set_render_order = ivi_layout_screen_set_render_order,
2788 .screen_get_output = ivi_layout_screen_get_output,
2789
2790 /**
2791 * animation
2792 */
2793 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002794 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2795
2796 /**
2797 * surface content dumping for debugging
2798 */
2799 .surface_get_size = ivi_layout_surface_get_size,
2800 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002801
2802 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002803 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002804 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002805 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002806 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2807
2808 /**
2809 * screen controller interfaces part2
2810 */
2811 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002812};
2813
2814int
2815load_controller_modules(struct weston_compositor *compositor, const char *modules,
2816 int *argc, char *argv[])
2817{
2818 const char *p, *end;
2819 char buffer[256];
2820 int (*controller_module_init)(struct weston_compositor *compositor,
2821 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002822 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002823 size_t interface_version);
2824
2825 if (modules == NULL)
2826 return 0;
2827
2828 p = modules;
2829 while (*p) {
2830 end = strchrnul(p, ',');
2831 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2832
2833 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002834 if (!controller_module_init)
2835 return -1;
2836
2837 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002838 &ivi_layout_interface,
2839 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002840 weston_log("ivi-shell: Initialization of controller module fails");
2841 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002842 }
2843
2844 p = end;
2845 while (*p == ',')
2846 p++;
2847 }
2848
2849 return 0;
2850}