blob: 4ad7a5f5d65d3faf8bb926550c7f066833e26626 [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
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900521 * coordinates to multi screens coordinate, which is global coordinates.
522 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900523 *
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
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900528 * - destination rectangle of layer is tansformed to multi screen coordinate,
529 * global coordinates. This is done by adding weston_output.{x,y} in simple
530 * because there is no scaled and rotated transformation.
531 * - destination rectangle of layer in multi screens coordinate needs to be
532 * intersected inside of a screen the layer is assigned to. This is because
533 * overlapped region of weston surface in another screen shall not be
534 * displayed according to ivi use case.
535 * - destination rectangle of layer
536 * - in multi screen coordinates,
537 * - and intersected inside of an assigned screen,
538 * is inversed to surface-local cooodinates by inversed matrix:m.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900539 * - the area is intersected by intersected area between weston_surface and
540 * source rectangle of ivi_surface.
541 */
542static void
543calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900544 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900545 struct ivi_layout_layer *ivilayer,
546 struct ivi_layout_surface *ivisurf,
547 struct weston_matrix *m,
548 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900549{
550 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
551 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900552 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900553 struct ivi_rectangle weston_surface_rect = { 0,
554 0,
555 ivisurf->surface->width,
556 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900557 struct ivi_rectangle surface_source_rect = { sp->source_x,
558 sp->source_y,
559 sp->source_width,
560 sp->source_height };
561 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
562 sp->dest_y,
563 sp->dest_width,
564 sp->dest_height };
565 struct ivi_rectangle layer_source_rect = { lp->source_x,
566 lp->source_y,
567 lp->source_width,
568 lp->source_height };
569 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
570 lp->dest_y,
571 lp->dest_width,
572 lp->dest_height };
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900573 struct ivi_rectangle screen_dest_rect = { output->x,
574 output->y,
575 output->width,
576 output->height };
577 struct ivi_rectangle layer_dest_rect_in_global =
578 { lp->dest_x + output->x,
579 lp->dest_y + output->y,
580 lp->dest_width,
581 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900582 struct ivi_rectangle surface_result;
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900583 struct ivi_rectangle layer_dest_rect_in_global_intersected;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900584
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900585 /*
586 * the whole transformation matrix:m from surface-local
587 * coordinates to global coordinates, which is computed by
588 * two steps,
589 * - surface-local coordinates to layer-local coordinates
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900590 * - layer-local coordinates to a single screen-local coordinates
591 * - a single screen-local coordinates to multi screen coordinates,
592 * which is global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900593 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900594 calc_transformation_matrix(&surface_source_rect,
595 &surface_dest_rect,
596 sp->orientation, m);
597
598 calc_transformation_matrix(&layer_source_rect,
599 &layer_dest_rect,
600 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900601
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900602 weston_matrix_translate(m, output->x, output->y, 0.0f);
603
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900604 /* this intersected ivi_rectangle would be used for masking
605 * weston_surface
606 */
607 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
608 &surface_result);
609
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900610 /*
611 * destination rectangle of layer in multi screens coordinate
612 * is intersected to avoid displaying outside of an assigned screen.
613 */
614 ivi_rectangle_intersect(&layer_dest_rect_in_global, &screen_dest_rect,
615 &layer_dest_rect_in_global_intersected);
616
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900617 /* calc masking area of weston_surface from m */
618 calc_inverse_matrix_transform(m,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900619 &layer_dest_rect_in_global_intersected,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900620 &surface_result,
621 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900622}
623
624static void
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900625update_prop(struct ivi_layout_screen *iviscrn,
626 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900627 struct ivi_layout_surface *ivisurf)
628{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900629 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900630 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900631 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900632
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900633 /*In case of no prop change, this just returns*/
634 if (!ivilayer->event_mask && !ivisurf->event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900635 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900636
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900637 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900638
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000639 tmpview = get_weston_view(ivisurf);
640 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900641
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900642 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
643 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
644 can_calc = false;
645 }
646
647 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
648 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
649 can_calc = false;
650 }
651
652 if (can_calc) {
653 wl_list_remove(&ivisurf->transform.link);
654 weston_matrix_init(&ivisurf->transform.matrix);
655
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900656 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900657 iviscrn, ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900658
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000659 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
660 wl_list_insert(&tmpview->geometry.transformation_list,
661 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900662
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000663 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900664 }
665
666 ivisurf->update_count++;
667
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000668 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900669
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000670 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900671}
672
673static void
674commit_changes(struct ivi_layout *layout)
675{
676 struct ivi_layout_screen *iviscrn = NULL;
677 struct ivi_layout_layer *ivilayer = NULL;
678 struct ivi_layout_surface *ivisurf = NULL;
679
680 wl_list_for_each(iviscrn, &layout->screen_list, link) {
681 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900682 /*
683 * If ivilayer is invisible, weston_view of ivisurf doesn't
684 * need to be modified.
685 */
686 if (ivilayer->prop.visibility == false)
687 continue;
688
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900689 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900690 /*
691 * If ivilayer is invisible, weston_view of ivisurf doesn't
692 * need to be modified.
693 */
694 if (ivisurf->prop.visibility == false)
695 continue;
696
697 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900698 }
699 }
700 }
701}
702
703static void
704commit_surface_list(struct ivi_layout *layout)
705{
706 struct ivi_layout_surface *ivisurf = NULL;
707 int32_t dest_x = 0;
708 int32_t dest_y = 0;
709 int32_t dest_width = 0;
710 int32_t dest_height = 0;
711 int32_t configured = 0;
712
713 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300714 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900715 dest_x = ivisurf->prop.dest_x;
716 dest_y = ivisurf->prop.dest_y;
717 dest_width = ivisurf->prop.dest_width;
718 dest_height = ivisurf->prop.dest_height;
719
720 ivi_layout_transition_move_resize_view(ivisurf,
721 ivisurf->pending.prop.dest_x,
722 ivisurf->pending.prop.dest_y,
723 ivisurf->pending.prop.dest_width,
724 ivisurf->pending.prop.dest_height,
725 ivisurf->pending.prop.transition_duration);
726
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300727 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900728 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
729 } else {
730 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
731 }
732
733 ivisurf->prop = ivisurf->pending.prop;
734 ivisurf->prop.dest_x = dest_x;
735 ivisurf->prop.dest_y = dest_y;
736 ivisurf->prop.dest_width = dest_width;
737 ivisurf->prop.dest_height = dest_height;
738 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
739 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
740
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300741 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900742 dest_x = ivisurf->prop.dest_x;
743 dest_y = ivisurf->prop.dest_y;
744 dest_width = ivisurf->prop.dest_width;
745 dest_height = ivisurf->prop.dest_height;
746
747 ivi_layout_transition_move_resize_view(ivisurf,
748 ivisurf->pending.prop.dest_x,
749 ivisurf->pending.prop.dest_y,
750 ivisurf->pending.prop.dest_width,
751 ivisurf->pending.prop.dest_height,
752 ivisurf->pending.prop.transition_duration);
753
754 ivisurf->prop = ivisurf->pending.prop;
755 ivisurf->prop.dest_x = dest_x;
756 ivisurf->prop.dest_y = dest_y;
757 ivisurf->prop.dest_width = dest_width;
758 ivisurf->prop.dest_height = dest_height;
759
760 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
761 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
762
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300763 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900764 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300765 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900766 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
767 } else {
768 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
769 }
770
771 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
772 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
773 configured = 1;
774 }
775
776 ivisurf->prop = ivisurf->pending.prop;
777 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
778 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
779
780 if (configured && !is_surface_transition(ivisurf))
781 wl_signal_emit(&ivisurf->configured, ivisurf);
782 } else {
783 configured = 0;
784 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
785 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
786 configured = 1;
787 }
788
789 ivisurf->prop = ivisurf->pending.prop;
790 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
791 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
792
793 if (configured && !is_surface_transition(ivisurf))
794 wl_signal_emit(&ivisurf->configured, ivisurf);
795 }
796 }
797}
798
799static void
800commit_layer_list(struct ivi_layout *layout)
801{
802 struct ivi_layout_layer *ivilayer = NULL;
803 struct ivi_layout_surface *ivisurf = NULL;
804 struct ivi_layout_surface *next = NULL;
805
806 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300807 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900808 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 -0300809 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900810 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
811 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
812 NULL, NULL,
813 ivilayer->pending.prop.transition_duration);
814 }
815 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
816
817 ivilayer->prop = ivilayer->pending.prop;
818
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000819 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900820 continue;
821 }
822
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000823 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
824 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000825 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000826 wl_list_remove(&ivisurf->order.link);
827 wl_list_init(&ivisurf->order.link);
828 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900829 }
830
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000831 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900832
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000833 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900834 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000835 wl_list_remove(&ivisurf->order.link);
836 wl_list_insert(&ivilayer->order.surface_list,
837 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000838 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000839 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900840 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000841
842 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900843 }
844}
845
846static void
847commit_screen_list(struct ivi_layout *layout)
848{
849 struct ivi_layout_screen *iviscrn = NULL;
850 struct ivi_layout_layer *ivilayer = NULL;
851 struct ivi_layout_layer *next = NULL;
852 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000853 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900854
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900855 /* Clear view list of layout ivi_layer */
856 wl_list_init(&layout->layout_layer.view_list.link);
857
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900858 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000859 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900860 wl_list_for_each_safe(ivilayer, next,
861 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000862 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000863 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900864 wl_list_init(&ivilayer->order.link);
865 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
866 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900867
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000868 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900869
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900870 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
871 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900872 /* FIXME: avoid to insert order.link to multiple screens */
873 wl_list_remove(&ivilayer->order.link);
874
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900875 wl_list_insert(&iviscrn->order.layer_list,
876 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000877 ivilayer->on_screen = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900878 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
879 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900880
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000881 iviscrn->order.dirty = 0;
882 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900883
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900884 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
885 if (ivilayer->prop.visibility == false)
886 continue;
887
888 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900889 if (ivisurf->prop.visibility == false)
890 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000891
892 tmpview = get_weston_view(ivisurf);
893 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900894
895 weston_layer_entry_insert(&layout->layout_layer.view_list,
896 &tmpview->layer_link);
897
898 ivisurf->surface->output = iviscrn->output;
899 }
900 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900901 }
902}
903
904static void
905commit_transition(struct ivi_layout* layout)
906{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300907 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900908 return;
909 }
910
911 wl_list_insert_list(&layout->transitions->transition_list,
912 &layout->pending_transition_list);
913
914 wl_list_init(&layout->pending_transition_list);
915
916 wl_event_source_timer_update(layout->transitions->event_source, 1);
917}
918
919static void
920send_surface_prop(struct ivi_layout_surface *ivisurf)
921{
922 wl_signal_emit(&ivisurf->property_changed, ivisurf);
923 ivisurf->event_mask = 0;
924}
925
926static void
927send_layer_prop(struct ivi_layout_layer *ivilayer)
928{
929 wl_signal_emit(&ivilayer->property_changed, ivilayer);
930 ivilayer->event_mask = 0;
931}
932
933static void
934send_prop(struct ivi_layout *layout)
935{
936 struct ivi_layout_layer *ivilayer = NULL;
937 struct ivi_layout_surface *ivisurf = NULL;
938
939 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900940 if (ivilayer->event_mask)
941 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900942 }
943
944 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900945 if (ivisurf->event_mask)
946 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900947 }
948}
949
950static void
951clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
952{
953 struct ivi_layout_surface *surface_link = NULL;
954 struct ivi_layout_surface *surface_next = NULL;
955
956 wl_list_for_each_safe(surface_link, surface_next,
957 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000958 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900959 wl_list_init(&surface_link->pending.link);
960 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900961}
962
963static void
964clear_surface_order_list(struct ivi_layout_layer *ivilayer)
965{
966 struct ivi_layout_surface *surface_link = NULL;
967 struct ivi_layout_surface *surface_next = NULL;
968
969 wl_list_for_each_safe(surface_link, surface_next,
970 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000971 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900972 wl_list_init(&surface_link->order.link);
973 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900974}
975
976static void
977layer_created(struct wl_listener *listener, void *data)
978{
979 struct ivi_layout_layer *ivilayer = data;
980
981 struct listener_layout_notification *notification =
982 container_of(listener,
983 struct listener_layout_notification,
984 listener);
985
986 struct ivi_layout_notification_callback *created_callback =
987 notification->userdata;
988
989 ((layer_create_notification_func)created_callback->callback)
990 (ivilayer, created_callback->data);
991}
992
993static void
994layer_removed(struct wl_listener *listener, void *data)
995{
996 struct ivi_layout_layer *ivilayer = data;
997
998 struct listener_layout_notification *notification =
999 container_of(listener,
1000 struct listener_layout_notification,
1001 listener);
1002
1003 struct ivi_layout_notification_callback *removed_callback =
1004 notification->userdata;
1005
1006 ((layer_remove_notification_func)removed_callback->callback)
1007 (ivilayer, removed_callback->data);
1008}
1009
1010static void
1011layer_prop_changed(struct wl_listener *listener, void *data)
1012{
1013 struct ivi_layout_layer *ivilayer = data;
1014
1015 struct listener_layout_notification *layout_listener =
1016 container_of(listener,
1017 struct listener_layout_notification,
1018 listener);
1019
1020 struct ivi_layout_notification_callback *prop_callback =
1021 layout_listener->userdata;
1022
1023 ((layer_property_notification_func)prop_callback->callback)
1024 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1025}
1026
1027static void
1028surface_created(struct wl_listener *listener, void *data)
1029{
1030 struct ivi_layout_surface *ivisurface = data;
1031
1032 struct listener_layout_notification *notification =
1033 container_of(listener,
1034 struct listener_layout_notification,
1035 listener);
1036
1037 struct ivi_layout_notification_callback *created_callback =
1038 notification->userdata;
1039
1040 ((surface_create_notification_func)created_callback->callback)
1041 (ivisurface, created_callback->data);
1042}
1043
1044static void
1045surface_removed(struct wl_listener *listener, void *data)
1046{
1047 struct ivi_layout_surface *ivisurface = data;
1048
1049 struct listener_layout_notification *notification =
1050 container_of(listener,
1051 struct listener_layout_notification,
1052 listener);
1053
1054 struct ivi_layout_notification_callback *removed_callback =
1055 notification->userdata;
1056
1057 ((surface_remove_notification_func)removed_callback->callback)
1058 (ivisurface, removed_callback->data);
1059}
1060
1061static void
1062surface_prop_changed(struct wl_listener *listener, void *data)
1063{
1064 struct ivi_layout_surface *ivisurf = data;
1065
1066 struct listener_layout_notification *layout_listener =
1067 container_of(listener,
1068 struct listener_layout_notification,
1069 listener);
1070
1071 struct ivi_layout_notification_callback *prop_callback =
1072 layout_listener->userdata;
1073
1074 ((surface_property_notification_func)prop_callback->callback)
1075 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1076
1077 ivisurf->event_mask = 0;
1078}
1079
1080static void
1081surface_configure_changed(struct wl_listener *listener,
1082 void *data)
1083{
1084 struct ivi_layout_surface *ivisurface = data;
1085
1086 struct listener_layout_notification *notification =
1087 container_of(listener,
1088 struct listener_layout_notification,
1089 listener);
1090
1091 struct ivi_layout_notification_callback *configure_changed_callback =
1092 notification->userdata;
1093
1094 ((surface_configure_notification_func)configure_changed_callback->callback)
1095 (ivisurface, configure_changed_callback->data);
1096}
1097
1098static int32_t
1099add_notification(struct wl_signal *signal,
1100 wl_notify_func_t callback,
1101 void *userdata)
1102{
1103 struct listener_layout_notification *notification = NULL;
1104
1105 notification = malloc(sizeof *notification);
1106 if (notification == NULL) {
1107 weston_log("fails to allocate memory\n");
1108 free(userdata);
1109 return IVI_FAILED;
1110 }
1111
1112 notification->listener.notify = callback;
1113 notification->userdata = userdata;
1114
1115 wl_signal_add(signal, &notification->listener);
1116
1117 return IVI_SUCCEEDED;
1118}
1119
1120static void
1121remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1122{
1123 struct wl_listener *listener = NULL;
1124 struct wl_listener *next = NULL;
1125
1126 wl_list_for_each_safe(listener, next, listener_list, link) {
1127 struct listener_layout_notification *notification =
1128 container_of(listener,
1129 struct listener_layout_notification,
1130 listener);
1131
1132 struct ivi_layout_notification_callback *notification_callback =
1133 notification->userdata;
1134
1135 if ((notification_callback->callback != callback) ||
1136 (notification_callback->data != userdata)) {
1137 continue;
1138 }
1139
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001140 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001141
1142 free(notification->userdata);
1143 free(notification);
1144 }
1145}
1146
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001147/**
1148 * Exported APIs of ivi-layout library are implemented from here.
1149 * Brief of APIs is described in ivi-layout-export.h.
1150 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001151static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001152ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1153 void *userdata)
1154{
1155 struct ivi_layout *layout = get_instance();
1156 struct ivi_layout_notification_callback *created_callback = NULL;
1157
1158 if (callback == NULL) {
1159 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1160 return IVI_FAILED;
1161 }
1162
1163 created_callback = malloc(sizeof *created_callback);
1164 if (created_callback == NULL) {
1165 weston_log("fails to allocate memory\n");
1166 return IVI_FAILED;
1167 }
1168
1169 created_callback->callback = callback;
1170 created_callback->data = userdata;
1171
1172 return add_notification(&layout->layer_notification.created,
1173 layer_created,
1174 created_callback);
1175}
1176
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001177static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001178ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1179 void *userdata)
1180{
1181 struct ivi_layout *layout = get_instance();
1182 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1183}
1184
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001185static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001186ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1187 void *userdata)
1188{
1189 struct ivi_layout *layout = get_instance();
1190 struct ivi_layout_notification_callback *removed_callback = NULL;
1191
1192 if (callback == NULL) {
1193 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1194 return IVI_FAILED;
1195 }
1196
1197 removed_callback = malloc(sizeof *removed_callback);
1198 if (removed_callback == NULL) {
1199 weston_log("fails to allocate memory\n");
1200 return IVI_FAILED;
1201 }
1202
1203 removed_callback->callback = callback;
1204 removed_callback->data = userdata;
1205 return add_notification(&layout->layer_notification.removed,
1206 layer_removed,
1207 removed_callback);
1208}
1209
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001210static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001211ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1212 void *userdata)
1213{
1214 struct ivi_layout *layout = get_instance();
1215 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1216}
1217
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001218static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001219ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1220 void *userdata)
1221{
1222 struct ivi_layout *layout = get_instance();
1223 struct ivi_layout_notification_callback *created_callback = NULL;
1224
1225 if (callback == NULL) {
1226 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1227 return IVI_FAILED;
1228 }
1229
1230 created_callback = malloc(sizeof *created_callback);
1231 if (created_callback == NULL) {
1232 weston_log("fails to allocate memory\n");
1233 return IVI_FAILED;
1234 }
1235
1236 created_callback->callback = callback;
1237 created_callback->data = userdata;
1238
1239 return add_notification(&layout->surface_notification.created,
1240 surface_created,
1241 created_callback);
1242}
1243
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001244static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001245ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1246 void *userdata)
1247{
1248 struct ivi_layout *layout = get_instance();
1249 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1250}
1251
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001252static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001253ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1254 void *userdata)
1255{
1256 struct ivi_layout *layout = get_instance();
1257 struct ivi_layout_notification_callback *removed_callback = NULL;
1258
1259 if (callback == NULL) {
1260 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1261 return IVI_FAILED;
1262 }
1263
1264 removed_callback = malloc(sizeof *removed_callback);
1265 if (removed_callback == NULL) {
1266 weston_log("fails to allocate memory\n");
1267 return IVI_FAILED;
1268 }
1269
1270 removed_callback->callback = callback;
1271 removed_callback->data = userdata;
1272
1273 return add_notification(&layout->surface_notification.removed,
1274 surface_removed,
1275 removed_callback);
1276}
1277
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001278static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001279ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1280 void *userdata)
1281{
1282 struct ivi_layout *layout = get_instance();
1283 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1284}
1285
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001286static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001287ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1288 void *userdata)
1289{
1290 struct ivi_layout *layout = get_instance();
1291 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1292 if (callback == NULL) {
1293 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1294 return IVI_FAILED;
1295 }
1296
1297 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1298 if (configure_changed_callback == NULL) {
1299 weston_log("fails to allocate memory\n");
1300 return IVI_FAILED;
1301 }
1302
1303 configure_changed_callback->callback = callback;
1304 configure_changed_callback->data = userdata;
1305
1306 return add_notification(&layout->surface_notification.configure_changed,
1307 surface_configure_changed,
1308 configure_changed_callback);
1309}
1310
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001311static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001312ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1313 void *userdata)
1314{
1315 struct ivi_layout *layout = get_instance();
1316 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1317}
1318
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001319uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001320ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1321{
1322 return ivisurf->id_surface;
1323}
1324
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001325static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001326ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1327{
1328 return ivilayer->id_layer;
1329}
1330
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001331static uint32_t
1332ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1333{
1334 return iviscrn->id_screen;
1335}
1336
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001337static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001338ivi_layout_get_layer_from_id(uint32_t id_layer)
1339{
1340 struct ivi_layout *layout = get_instance();
1341 struct ivi_layout_layer *ivilayer = NULL;
1342
1343 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1344 if (ivilayer->id_layer == id_layer) {
1345 return ivilayer;
1346 }
1347 }
1348
1349 return NULL;
1350}
1351
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001352struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001353ivi_layout_get_surface_from_id(uint32_t id_surface)
1354{
1355 struct ivi_layout *layout = get_instance();
1356 struct ivi_layout_surface *ivisurf = NULL;
1357
1358 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1359 if (ivisurf->id_surface == id_surface) {
1360 return ivisurf;
1361 }
1362 }
1363
1364 return NULL;
1365}
1366
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001367static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001368ivi_layout_get_screen_from_id(uint32_t id_screen)
1369{
1370 struct ivi_layout *layout = get_instance();
1371 struct ivi_layout_screen *iviscrn = NULL;
1372
1373 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Nobuhiko Tanibata3e710d12015-11-25 23:36:09 +09001374 if (iviscrn->id_screen == id_screen)
1375 return iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001376 }
1377
1378 return NULL;
1379}
1380
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001381static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001382ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1383 int32_t *pWidth, int32_t *pHeight)
1384{
1385 struct weston_output *output = NULL;
1386
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001387 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001388 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1389 return IVI_FAILED;
1390 }
1391
1392 output = iviscrn->output;
1393 *pWidth = output->current_mode->width;
1394 *pHeight = output->current_mode->height;
1395
1396 return IVI_SUCCEEDED;
1397}
1398
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001399static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001400ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1401 surface_property_notification_func callback,
1402 void *userdata)
1403{
1404 struct listener_layout_notification* notification = NULL;
1405 struct ivi_layout_notification_callback *prop_callback = NULL;
1406
1407 if (ivisurf == NULL || callback == NULL) {
1408 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1409 return IVI_FAILED;
1410 }
1411
1412 notification = malloc(sizeof *notification);
1413 if (notification == NULL) {
1414 weston_log("fails to allocate memory\n");
1415 return IVI_FAILED;
1416 }
1417
1418 prop_callback = malloc(sizeof *prop_callback);
1419 if (prop_callback == NULL) {
1420 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001421 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001422 return IVI_FAILED;
1423 }
1424
1425 prop_callback->callback = callback;
1426 prop_callback->data = userdata;
1427
1428 notification->listener.notify = surface_prop_changed;
1429 notification->userdata = prop_callback;
1430
1431 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1432
1433 return IVI_SUCCEEDED;
1434}
1435
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001436static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001437ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1438{
1439 if (ivilayer == NULL) {
1440 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1441 return NULL;
1442 }
1443
1444 return &ivilayer->prop;
1445}
1446
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001447static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001448ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1449{
1450 struct ivi_layout *layout = get_instance();
1451 struct ivi_layout_screen *iviscrn = NULL;
1452 int32_t length = 0;
1453 int32_t n = 0;
1454
1455 if (pLength == NULL || ppArray == NULL) {
1456 weston_log("ivi_layout_get_screens: invalid argument\n");
1457 return IVI_FAILED;
1458 }
1459
1460 length = wl_list_length(&layout->screen_list);
1461
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001462 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001463 /* the Array must be free by module which called this function */
1464 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1465 if (*ppArray == NULL) {
1466 weston_log("fails to allocate memory\n");
1467 return IVI_FAILED;
1468 }
1469
1470 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1471 (*ppArray)[n++] = iviscrn;
1472 }
1473 }
1474
1475 *pLength = length;
1476
1477 return IVI_SUCCEEDED;
1478}
1479
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001480static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001481ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1482 int32_t *pLength,
1483 struct ivi_layout_screen ***ppArray)
1484{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001485 int32_t length = 0;
1486 int32_t n = 0;
1487
1488 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1489 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1490 return IVI_FAILED;
1491 }
1492
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001493 if (ivilayer->on_screen != NULL)
1494 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001495
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001496 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001497 /* the Array must be free by module which called this function */
1498 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1499 if (*ppArray == NULL) {
1500 weston_log("fails to allocate memory\n");
1501 return IVI_FAILED;
1502 }
1503
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001504 (*ppArray)[n++] = ivilayer->on_screen;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001505 }
1506
1507 *pLength = length;
1508
1509 return IVI_SUCCEEDED;
1510}
1511
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001512static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001513ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1514{
1515 struct ivi_layout *layout = get_instance();
1516 struct ivi_layout_layer *ivilayer = NULL;
1517 int32_t length = 0;
1518 int32_t n = 0;
1519
1520 if (pLength == NULL || ppArray == NULL) {
1521 weston_log("ivi_layout_get_layers: invalid argument\n");
1522 return IVI_FAILED;
1523 }
1524
1525 length = wl_list_length(&layout->layer_list);
1526
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001527 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001528 /* the Array must be free by module which called this function */
1529 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1530 if (*ppArray == NULL) {
1531 weston_log("fails to allocate memory\n");
1532 return IVI_FAILED;
1533 }
1534
1535 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1536 (*ppArray)[n++] = ivilayer;
1537 }
1538 }
1539
1540 *pLength = length;
1541
1542 return IVI_SUCCEEDED;
1543}
1544
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001545static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001546ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1547 int32_t *pLength,
1548 struct ivi_layout_layer ***ppArray)
1549{
1550 struct ivi_layout_layer *ivilayer = NULL;
1551 int32_t length = 0;
1552 int32_t n = 0;
1553
1554 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1555 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1556 return IVI_FAILED;
1557 }
1558
1559 length = wl_list_length(&iviscrn->order.layer_list);
1560
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001561 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001562 /* the Array must be free by module which called this function */
1563 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1564 if (*ppArray == NULL) {
1565 weston_log("fails to allocate memory\n");
1566 return IVI_FAILED;
1567 }
1568
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001569 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001570 (*ppArray)[n++] = ivilayer;
1571 }
1572 }
1573
1574 *pLength = length;
1575
1576 return IVI_SUCCEEDED;
1577}
1578
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001579static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001580ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1581 int32_t *pLength,
1582 struct ivi_layout_layer ***ppArray)
1583{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001584 int32_t length = 0;
1585 int32_t n = 0;
1586
1587 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1588 weston_log("ivi_layout_getLayers: invalid argument\n");
1589 return IVI_FAILED;
1590 }
1591
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001592 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001593 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001594 length = 1;
1595 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001596 if (*ppArray == NULL) {
1597 weston_log("fails to allocate memory\n");
1598 return IVI_FAILED;
1599 }
1600
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001601 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001602 }
1603
1604 *pLength = length;
1605
1606 return IVI_SUCCEEDED;
1607}
1608
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001609static
1610int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001611ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1612{
1613 struct ivi_layout *layout = get_instance();
1614 struct ivi_layout_surface *ivisurf = NULL;
1615 int32_t length = 0;
1616 int32_t n = 0;
1617
1618 if (pLength == NULL || ppArray == NULL) {
1619 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1620 return IVI_FAILED;
1621 }
1622
1623 length = wl_list_length(&layout->surface_list);
1624
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001625 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001626 /* the Array must be free by module which called this function */
1627 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1628 if (*ppArray == NULL) {
1629 weston_log("fails to allocate memory\n");
1630 return IVI_FAILED;
1631 }
1632
1633 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1634 (*ppArray)[n++] = ivisurf;
1635 }
1636 }
1637
1638 *pLength = length;
1639
1640 return IVI_SUCCEEDED;
1641}
1642
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001643static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001644ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1645 int32_t *pLength,
1646 struct ivi_layout_surface ***ppArray)
1647{
1648 struct ivi_layout_surface *ivisurf = NULL;
1649 int32_t length = 0;
1650 int32_t n = 0;
1651
1652 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1653 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1654 return IVI_FAILED;
1655 }
1656
1657 length = wl_list_length(&ivilayer->order.surface_list);
1658
1659 if (length != 0) {
1660 /* the Array must be free by module which called this function */
1661 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1662 if (*ppArray == NULL) {
1663 weston_log("fails to allocate memory\n");
1664 return IVI_FAILED;
1665 }
1666
1667 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1668 (*ppArray)[n++] = ivisurf;
1669 }
1670 }
1671
1672 *pLength = length;
1673
1674 return IVI_SUCCEEDED;
1675}
1676
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001677static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001678ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1679 int32_t width, int32_t height)
1680{
1681 struct ivi_layout *layout = get_instance();
1682 struct ivi_layout_layer *ivilayer = NULL;
1683
1684 ivilayer = get_layer(&layout->layer_list, id_layer);
1685 if (ivilayer != NULL) {
1686 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001687 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001688 return ivilayer;
1689 }
1690
1691 ivilayer = calloc(1, sizeof *ivilayer);
1692 if (ivilayer == NULL) {
1693 weston_log("fails to allocate memory\n");
1694 return NULL;
1695 }
1696
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001697 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001698 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001699 ivilayer->layout = layout;
1700 ivilayer->id_layer = id_layer;
1701
1702 init_layer_properties(&ivilayer->prop, width, height);
1703 ivilayer->event_mask = 0;
1704
1705 wl_list_init(&ivilayer->pending.surface_list);
1706 wl_list_init(&ivilayer->pending.link);
1707 ivilayer->pending.prop = ivilayer->prop;
1708
1709 wl_list_init(&ivilayer->order.surface_list);
1710 wl_list_init(&ivilayer->order.link);
1711
1712 wl_list_insert(&layout->layer_list, &ivilayer->link);
1713
1714 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1715
1716 return ivilayer;
1717}
1718
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001719static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001720ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1721{
1722 if (ivilayer == NULL) {
1723 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1724 return;
1725 }
1726
1727 remove_all_notification(&ivilayer->property_changed.listener_list);
1728}
1729
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001730static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001731ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1732 layer_property_notification_func callback,
1733 void *userdata)
1734{
1735 if (ivilayer == NULL) {
1736 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1737 return;
1738 }
1739
1740 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1741}
1742
1743static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001744ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001745{
1746 struct ivi_layout *layout = get_instance();
1747
1748 if (ivilayer == NULL) {
1749 weston_log("ivi_layout_layer_remove: invalid argument\n");
1750 return;
1751 }
1752
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001753 if (--ivilayer->ref_count > 0)
1754 return;
1755
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001756 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1757
1758 clear_surface_pending_list(ivilayer);
1759 clear_surface_order_list(ivilayer);
1760
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001761 wl_list_remove(&ivilayer->pending.link);
1762 wl_list_remove(&ivilayer->order.link);
1763 wl_list_remove(&ivilayer->link);
1764
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001765 ivi_layout_layer_remove_notification(ivilayer);
1766
1767 free(ivilayer);
1768}
1769
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001770int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001771ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1772 bool newVisibility)
1773{
1774 struct ivi_layout_layer_properties *prop = NULL;
1775
1776 if (ivilayer == NULL) {
1777 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1778 return IVI_FAILED;
1779 }
1780
1781 prop = &ivilayer->pending.prop;
1782 prop->visibility = newVisibility;
1783
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001784 if (ivilayer->prop.visibility != newVisibility)
1785 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1786 else
1787 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001788
1789 return IVI_SUCCEEDED;
1790}
1791
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001792static bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001793ivi_layout_layer_get_visibility(struct ivi_layout_layer *ivilayer)
1794{
1795 if (ivilayer == NULL) {
1796 weston_log("ivi_layout_layer_get_visibility: invalid argument\n");
1797 return false;
1798 }
1799
1800 return ivilayer->prop.visibility;
1801}
1802
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001803int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001804ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1805 wl_fixed_t opacity)
1806{
1807 struct ivi_layout_layer_properties *prop = NULL;
1808
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001809 if (ivilayer == NULL ||
1810 opacity < wl_fixed_from_double(0.0) ||
1811 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001812 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1813 return IVI_FAILED;
1814 }
1815
1816 prop = &ivilayer->pending.prop;
1817 prop->opacity = opacity;
1818
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001819 if (ivilayer->prop.opacity != opacity)
1820 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1821 else
1822 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001823
1824 return IVI_SUCCEEDED;
1825}
1826
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001827wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001828ivi_layout_layer_get_opacity(struct ivi_layout_layer *ivilayer)
1829{
1830 if (ivilayer == NULL) {
1831 weston_log("ivi_layout_layer_get_opacity: invalid argument\n");
1832 return wl_fixed_from_double(0.0);
1833 }
1834
1835 return ivilayer->prop.opacity;
1836}
1837
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001838static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001839ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1840 int32_t x, int32_t y,
1841 int32_t width, int32_t height)
1842{
1843 struct ivi_layout_layer_properties *prop = NULL;
1844
1845 if (ivilayer == NULL) {
1846 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1847 return IVI_FAILED;
1848 }
1849
1850 prop = &ivilayer->pending.prop;
1851 prop->source_x = x;
1852 prop->source_y = y;
1853 prop->source_width = width;
1854 prop->source_height = height;
1855
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001856 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1857 ivilayer->prop.source_width != width ||
1858 ivilayer->prop.source_height != height)
1859 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1860 else
1861 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001862
1863 return IVI_SUCCEEDED;
1864}
1865
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001866static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001867ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1868 int32_t x, int32_t y,
1869 int32_t width, int32_t height)
1870{
1871 struct ivi_layout_layer_properties *prop = NULL;
1872
1873 if (ivilayer == NULL) {
1874 weston_log("ivi_layout_layer_set_destination_rectangle: invalid argument\n");
1875 return IVI_FAILED;
1876 }
1877
1878 prop = &ivilayer->pending.prop;
1879 prop->dest_x = x;
1880 prop->dest_y = y;
1881 prop->dest_width = width;
1882 prop->dest_height = height;
1883
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001884 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1885 ivilayer->prop.dest_width != width ||
1886 ivilayer->prop.dest_height != height)
1887 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1888 else
1889 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001890
1891 return IVI_SUCCEEDED;
1892}
1893
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001894static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001895ivi_layout_layer_get_dimension(struct ivi_layout_layer *ivilayer,
1896 int32_t *dest_width, int32_t *dest_height)
1897{
1898 if (ivilayer == NULL || dest_width == NULL || dest_height == NULL) {
1899 weston_log("ivi_layout_layer_get_dimension: invalid argument\n");
1900 return IVI_FAILED;
1901 }
1902
1903 *dest_width = ivilayer->prop.dest_width;
1904 *dest_height = ivilayer->prop.dest_height;
1905
1906 return IVI_SUCCEEDED;
1907}
1908
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001909static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001910ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
1911 int32_t dest_width, int32_t dest_height)
1912{
1913 struct ivi_layout_layer_properties *prop = NULL;
1914
1915 if (ivilayer == NULL) {
1916 weston_log("ivi_layout_layer_set_dimension: invalid argument\n");
1917 return IVI_FAILED;
1918 }
1919
1920 prop = &ivilayer->pending.prop;
1921
1922 prop->dest_width = dest_width;
1923 prop->dest_height = dest_height;
1924
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001925 if (ivilayer->prop.dest_width != dest_width ||
1926 ivilayer->prop.dest_height != dest_height)
1927 ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
1928 else
1929 ivilayer->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001930
1931 return IVI_SUCCEEDED;
1932}
1933
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001934int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001935ivi_layout_layer_get_position(struct ivi_layout_layer *ivilayer,
1936 int32_t *dest_x, int32_t *dest_y)
1937{
1938 if (ivilayer == NULL || dest_x == NULL || dest_y == NULL) {
1939 weston_log("ivi_layout_layer_get_position: invalid argument\n");
1940 return IVI_FAILED;
1941 }
1942
1943 *dest_x = ivilayer->prop.dest_x;
1944 *dest_y = ivilayer->prop.dest_y;
1945
1946 return IVI_SUCCEEDED;
1947}
1948
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001949int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001950ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
1951 int32_t dest_x, int32_t dest_y)
1952{
1953 struct ivi_layout_layer_properties *prop = NULL;
1954
1955 if (ivilayer == NULL) {
1956 weston_log("ivi_layout_layer_set_position: invalid argument\n");
1957 return IVI_FAILED;
1958 }
1959
1960 prop = &ivilayer->pending.prop;
1961 prop->dest_x = dest_x;
1962 prop->dest_y = dest_y;
1963
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001964 if (ivilayer->prop.dest_x != dest_x || ivilayer->prop.dest_y != dest_y)
1965 ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
1966 else
1967 ivilayer->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001968
1969 return IVI_SUCCEEDED;
1970}
1971
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001972static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001973ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1974 enum wl_output_transform orientation)
1975{
1976 struct ivi_layout_layer_properties *prop = NULL;
1977
1978 if (ivilayer == NULL) {
1979 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1980 return IVI_FAILED;
1981 }
1982
1983 prop = &ivilayer->pending.prop;
1984 prop->orientation = orientation;
1985
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001986 if (ivilayer->prop.orientation != orientation)
1987 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1988 else
1989 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001990
1991 return IVI_SUCCEEDED;
1992}
1993
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001994static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001995ivi_layout_layer_get_orientation(struct ivi_layout_layer *ivilayer)
1996{
1997 if (ivilayer == NULL) {
1998 weston_log("ivi_layout_layer_get_orientation: invalid argument\n");
1999 return 0;
2000 }
2001
2002 return ivilayer->prop.orientation;
2003}
2004
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002005int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002006ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
2007 struct ivi_layout_surface **pSurface,
2008 int32_t number)
2009{
2010 struct ivi_layout *layout = get_instance();
2011 struct ivi_layout_surface *ivisurf = NULL;
2012 struct ivi_layout_surface *next = NULL;
2013 uint32_t *id_surface = NULL;
2014 int32_t i = 0;
2015
2016 if (ivilayer == NULL) {
2017 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
2018 return IVI_FAILED;
2019 }
2020
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00002021 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002022
2023 for (i = 0; i < number; i++) {
2024 id_surface = &pSurface[i]->id_surface;
2025
2026 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2027 if (*id_surface != ivisurf->id_surface) {
2028 continue;
2029 }
2030
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002031 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002032 wl_list_insert(&ivilayer->pending.surface_list,
2033 &ivisurf->pending.link);
2034 break;
2035 }
2036 }
2037
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002038 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002039
2040 return IVI_SUCCEEDED;
2041}
2042
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002043int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002044ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
2045 bool newVisibility)
2046{
2047 struct ivi_layout_surface_properties *prop = NULL;
2048
2049 if (ivisurf == NULL) {
2050 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
2051 return IVI_FAILED;
2052 }
2053
2054 prop = &ivisurf->pending.prop;
2055 prop->visibility = newVisibility;
2056
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002057 if (ivisurf->prop.visibility != newVisibility)
2058 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
2059 else
2060 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002061
2062 return IVI_SUCCEEDED;
2063}
2064
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002065bool
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002066ivi_layout_surface_get_visibility(struct ivi_layout_surface *ivisurf)
2067{
2068 if (ivisurf == NULL) {
2069 weston_log("ivi_layout_surface_get_visibility: invalid argument\n");
2070 return false;
2071 }
2072
2073 return ivisurf->prop.visibility;
2074}
2075
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002076int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002077ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
2078 wl_fixed_t opacity)
2079{
2080 struct ivi_layout_surface_properties *prop = NULL;
2081
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09002082 if (ivisurf == NULL ||
2083 opacity < wl_fixed_from_double(0.0) ||
2084 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002085 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
2086 return IVI_FAILED;
2087 }
2088
2089 prop = &ivisurf->pending.prop;
2090 prop->opacity = opacity;
2091
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002092 if (ivisurf->prop.opacity != opacity)
2093 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
2094 else
2095 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002096
2097 return IVI_SUCCEEDED;
2098}
2099
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002100wl_fixed_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002101ivi_layout_surface_get_opacity(struct ivi_layout_surface *ivisurf)
2102{
2103 if (ivisurf == NULL) {
2104 weston_log("ivi_layout_surface_get_opacity: invalid argument\n");
2105 return wl_fixed_from_double(0.0);
2106 }
2107
2108 return ivisurf->prop.opacity;
2109}
2110
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002111int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002112ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
2113 int32_t x, int32_t y,
2114 int32_t width, int32_t height)
2115{
2116 struct ivi_layout_surface_properties *prop = NULL;
2117
2118 if (ivisurf == NULL) {
2119 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
2120 return IVI_FAILED;
2121 }
2122
2123 prop = &ivisurf->pending.prop;
2124 prop->start_x = prop->dest_x;
2125 prop->start_y = prop->dest_y;
2126 prop->dest_x = x;
2127 prop->dest_y = y;
2128 prop->start_width = prop->dest_width;
2129 prop->start_height = prop->dest_height;
2130 prop->dest_width = width;
2131 prop->dest_height = height;
2132
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002133 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
2134 ivisurf->prop.dest_width != width ||
2135 ivisurf->prop.dest_height != height)
2136 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
2137 else
2138 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002139
2140 return IVI_SUCCEEDED;
2141}
2142
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002143static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002144ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
2145 int32_t dest_width, int32_t dest_height)
2146{
2147 struct ivi_layout_surface_properties *prop = NULL;
2148
2149 if (ivisurf == NULL) {
2150 weston_log("ivi_layout_surface_set_dimension: invalid argument\n");
2151 return IVI_FAILED;
2152 }
2153
2154 prop = &ivisurf->pending.prop;
2155 prop->dest_width = dest_width;
2156 prop->dest_height = dest_height;
2157
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002158 if (ivisurf->prop.dest_width != dest_width ||
2159 ivisurf->prop.dest_height != dest_height)
2160 ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
2161 else
2162 ivisurf->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002163
2164 return IVI_SUCCEEDED;
2165}
2166
2167int32_t
2168ivi_layout_surface_get_dimension(struct ivi_layout_surface *ivisurf,
2169 int32_t *dest_width, int32_t *dest_height)
2170{
2171 if (ivisurf == NULL || dest_width == NULL || dest_height == NULL) {
2172 weston_log("ivi_layout_surface_get_dimension: invalid argument\n");
2173 return IVI_FAILED;
2174 }
2175
2176 *dest_width = ivisurf->prop.dest_width;
2177 *dest_height = ivisurf->prop.dest_height;
2178
2179 return IVI_SUCCEEDED;
2180}
2181
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002182static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002183ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
2184 int32_t dest_x, int32_t dest_y)
2185{
2186 struct ivi_layout_surface_properties *prop = NULL;
2187
2188 if (ivisurf == NULL) {
2189 weston_log("ivi_layout_surface_set_position: invalid argument\n");
2190 return IVI_FAILED;
2191 }
2192
2193 prop = &ivisurf->pending.prop;
2194 prop->dest_x = dest_x;
2195 prop->dest_y = dest_y;
2196
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002197 if (ivisurf->prop.dest_x != dest_x || ivisurf->prop.dest_y != dest_y)
2198 ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
2199 else
2200 ivisurf->event_mask &= ~IVI_NOTIFICATION_POSITION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002201
2202 return IVI_SUCCEEDED;
2203}
2204
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002205static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002206ivi_layout_surface_get_position(struct ivi_layout_surface *ivisurf,
2207 int32_t *dest_x, int32_t *dest_y)
2208{
2209 if (ivisurf == NULL || dest_x == NULL || dest_y == NULL) {
2210 weston_log("ivi_layout_surface_get_position: invalid argument\n");
2211 return IVI_FAILED;
2212 }
2213
2214 *dest_x = ivisurf->prop.dest_x;
2215 *dest_y = ivisurf->prop.dest_y;
2216
2217 return IVI_SUCCEEDED;
2218}
2219
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002220static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002221ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2222 enum wl_output_transform orientation)
2223{
2224 struct ivi_layout_surface_properties *prop = NULL;
2225
2226 if (ivisurf == NULL) {
2227 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2228 return IVI_FAILED;
2229 }
2230
2231 prop = &ivisurf->pending.prop;
2232 prop->orientation = orientation;
2233
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002234 if (ivisurf->prop.orientation != orientation)
2235 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2236 else
2237 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002238
2239 return IVI_SUCCEEDED;
2240}
2241
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002242static enum wl_output_transform
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002243ivi_layout_surface_get_orientation(struct ivi_layout_surface *ivisurf)
2244{
2245 if (ivisurf == NULL) {
2246 weston_log("ivi_layout_surface_get_orientation: invalid argument\n");
2247 return 0;
2248 }
2249
2250 return ivisurf->prop.orientation;
2251}
2252
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002253static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002254ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2255 struct ivi_layout_layer *addlayer)
2256{
2257 struct ivi_layout *layout = get_instance();
2258 struct ivi_layout_layer *ivilayer = NULL;
2259 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002260
2261 if (iviscrn == NULL || addlayer == NULL) {
2262 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2263 return IVI_FAILED;
2264 }
2265
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00002266 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002267 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2268 return IVI_SUCCEEDED;
2269 }
2270
2271 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2272 if (ivilayer->id_layer == addlayer->id_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002273 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002274 wl_list_insert(&iviscrn->pending.layer_list,
2275 &ivilayer->pending.link);
2276 break;
2277 }
2278 }
2279
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002280 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002281
2282 return IVI_SUCCEEDED;
2283}
2284
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002285static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002286ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2287 struct ivi_layout_layer **pLayer,
2288 const int32_t number)
2289{
2290 struct ivi_layout *layout = get_instance();
2291 struct ivi_layout_layer *ivilayer = NULL;
2292 struct ivi_layout_layer *next = NULL;
2293 uint32_t *id_layer = NULL;
2294 int32_t i = 0;
2295
2296 if (iviscrn == NULL) {
2297 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2298 return IVI_FAILED;
2299 }
2300
2301 wl_list_for_each_safe(ivilayer, next,
2302 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002303 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002304 wl_list_init(&ivilayer->pending.link);
2305 }
2306
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002307 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002308
2309 for (i = 0; i < number; i++) {
2310 id_layer = &pLayer[i]->id_layer;
2311 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2312 if (*id_layer != ivilayer->id_layer) {
2313 continue;
2314 }
2315
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002316 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002317 wl_list_insert(&iviscrn->pending.layer_list,
2318 &ivilayer->pending.link);
2319 break;
2320 }
2321 }
2322
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002323 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002324
2325 return IVI_SUCCEEDED;
2326}
2327
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002328static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002329ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2330{
2331 return iviscrn->output;
2332}
2333
2334/**
2335 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2336 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2337 * This function is used to get the result of drawing by clients.
2338 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002339static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002340ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2341{
2342 return ivisurf != NULL ? ivisurf->surface : NULL;
2343}
2344
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002345static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002346ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2347 int32_t *width, int32_t *height,
2348 int32_t *stride)
2349{
2350 int32_t w;
2351 int32_t h;
2352 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2353
2354 if (ivisurf == NULL || ivisurf->surface == NULL) {
2355 weston_log("%s: invalid argument\n", __func__);
2356 return IVI_FAILED;
2357 }
2358
2359 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2360
2361 if (width != NULL)
2362 *width = w;
2363
2364 if (height != NULL)
2365 *height = h;
2366
2367 if (stride != NULL)
2368 *stride = w * bytespp;
2369
2370 return IVI_SUCCEEDED;
2371}
2372
2373static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002374ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2375 layer_property_notification_func callback,
2376 void *userdata)
2377{
2378 struct ivi_layout_notification_callback *prop_callback = NULL;
2379
2380 if (ivilayer == NULL || callback == NULL) {
2381 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2382 return IVI_FAILED;
2383 }
2384
2385 prop_callback = malloc(sizeof *prop_callback);
2386 if (prop_callback == NULL) {
2387 weston_log("fails to allocate memory\n");
2388 return IVI_FAILED;
2389 }
2390
2391 prop_callback->callback = callback;
2392 prop_callback->data = userdata;
2393
2394 return add_notification(&ivilayer->property_changed,
2395 layer_prop_changed,
2396 prop_callback);
2397}
2398
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002399static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002400ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2401{
2402 if (ivisurf == NULL) {
2403 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2404 return NULL;
2405 }
2406
2407 return &ivisurf->prop;
2408}
2409
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002410static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002411ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2412 struct ivi_layout_surface *addsurf)
2413{
2414 struct ivi_layout *layout = get_instance();
2415 struct ivi_layout_surface *ivisurf = NULL;
2416 struct ivi_layout_surface *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002417
2418 if (ivilayer == NULL || addsurf == NULL) {
2419 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2420 return IVI_FAILED;
2421 }
2422
Ucan, Emre (ADITG/SW1)4a183642015-08-28 12:59:04 +00002423 if (addsurf->on_layer == ivilayer) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002424 weston_log("ivi_layout_layer_add_surface: addsurf is already available\n");
2425 return IVI_SUCCEEDED;
2426 }
2427
2428 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2429 if (ivisurf->id_surface == addsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002430 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002431 wl_list_insert(&ivilayer->pending.surface_list,
2432 &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 return IVI_SUCCEEDED;
2440}
2441
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002442static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002443ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2444 struct ivi_layout_surface *remsurf)
2445{
2446 struct ivi_layout_surface *ivisurf = NULL;
2447 struct ivi_layout_surface *next = NULL;
2448
2449 if (ivilayer == NULL || remsurf == NULL) {
2450 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2451 return;
2452 }
2453
2454 wl_list_for_each_safe(ivisurf, next,
2455 &ivilayer->pending.surface_list, pending.link) {
2456 if (ivisurf->id_surface == remsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002457 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002458 wl_list_init(&ivisurf->pending.link);
2459 break;
2460 }
2461 }
2462
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002463 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002464}
2465
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002466static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002467ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2468 int32_t x, int32_t y,
2469 int32_t width, int32_t height)
2470{
2471 struct ivi_layout_surface_properties *prop = NULL;
2472
2473 if (ivisurf == NULL) {
2474 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2475 return IVI_FAILED;
2476 }
2477
2478 prop = &ivisurf->pending.prop;
2479 prop->source_x = x;
2480 prop->source_y = y;
2481 prop->source_width = width;
2482 prop->source_height = height;
2483
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002484 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2485 ivisurf->prop.source_width != width ||
2486 ivisurf->prop.source_height != height)
2487 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2488 else
2489 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002490
2491 return IVI_SUCCEEDED;
2492}
2493
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002494int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002495ivi_layout_commit_changes(void)
2496{
2497 struct ivi_layout *layout = get_instance();
2498
2499 commit_surface_list(layout);
2500 commit_layer_list(layout);
2501 commit_screen_list(layout);
2502
2503 commit_transition(layout);
2504
2505 commit_changes(layout);
2506 send_prop(layout);
2507 weston_compositor_schedule_repaint(layout->compositor);
2508
2509 return IVI_SUCCEEDED;
2510}
2511
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002512static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002513ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2514 enum ivi_layout_transition_type type,
2515 uint32_t duration)
2516{
2517 if (ivilayer == NULL) {
2518 weston_log("%s: invalid argument\n", __func__);
2519 return -1;
2520 }
2521
2522 ivilayer->pending.prop.transition_type = type;
2523 ivilayer->pending.prop.transition_duration = duration;
2524
2525 return 0;
2526}
2527
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002528static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002529ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2530 uint32_t is_fade_in,
2531 double start_alpha, double end_alpha)
2532{
2533 if (ivilayer == NULL) {
2534 weston_log("%s: invalid argument\n", __func__);
2535 return -1;
2536 }
2537
2538 ivilayer->pending.prop.is_fade_in = is_fade_in;
2539 ivilayer->pending.prop.start_alpha = start_alpha;
2540 ivilayer->pending.prop.end_alpha = end_alpha;
2541
2542 return 0;
2543}
2544
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002545static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002546ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2547 uint32_t duration)
2548{
2549 struct ivi_layout_surface_properties *prop;
2550
2551 if (ivisurf == NULL) {
2552 weston_log("%s: invalid argument\n", __func__);
2553 return -1;
2554 }
2555
2556 prop = &ivisurf->pending.prop;
2557 prop->transition_duration = duration*10;
2558 return 0;
2559}
2560
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002561static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002562ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2563 enum ivi_layout_transition_type type,
2564 uint32_t duration)
2565{
2566 struct ivi_layout_surface_properties *prop;
2567
2568 if (ivisurf == NULL) {
2569 weston_log("%s: invalid argument\n", __func__);
2570 return -1;
2571 }
2572
2573 prop = &ivisurf->pending.prop;
2574 prop->transition_type = type;
2575 prop->transition_duration = duration;
2576 return 0;
2577}
2578
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002579static int32_t
2580ivi_layout_surface_dump(struct weston_surface *surface,
2581 void *target, size_t size,int32_t x, int32_t y,
2582 int32_t width, int32_t height)
2583{
2584 int result = 0;
2585
2586 if (surface == NULL) {
2587 weston_log("%s: invalid argument\n", __func__);
2588 return IVI_FAILED;
2589 }
2590
2591 result = weston_surface_copy_content(
2592 surface, target, size,
2593 x, y, width, height);
2594
2595 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2596}
2597
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002598/**
2599 * methods of interaction between ivi-shell with ivi-layout
2600 */
2601struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002602ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2603{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002604 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002605 return NULL;
2606
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002607 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002608}
2609
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002610void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002611ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2612 int32_t width, int32_t height)
2613{
2614 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002615
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002616 /* emit callback which is set by ivi-layout api user */
2617 wl_signal_emit(&layout->surface_notification.configure_changed,
2618 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002619}
2620
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002621static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002622ivi_layout_surface_set_content_observer(struct ivi_layout_surface *ivisurf,
2623 ivi_controller_surface_content_callback callback,
2624 void* userdata)
2625{
2626 int32_t ret = IVI_FAILED;
2627
2628 if (ivisurf != NULL) {
2629 ivisurf->content_observer.callback = callback;
2630 ivisurf->content_observer.userdata = userdata;
2631 ret = IVI_SUCCEEDED;
2632 }
2633 return ret;
2634}
2635
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002636struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002637ivi_layout_surface_create(struct weston_surface *wl_surface,
2638 uint32_t id_surface)
2639{
2640 struct ivi_layout *layout = get_instance();
2641 struct ivi_layout_surface *ivisurf = NULL;
2642 struct weston_view *tmpview = NULL;
2643
2644 if (wl_surface == NULL) {
2645 weston_log("ivi_layout_surface_create: invalid argument\n");
2646 return NULL;
2647 }
2648
2649 ivisurf = get_surface(&layout->surface_list, id_surface);
2650 if (ivisurf != NULL) {
2651 if (ivisurf->surface != NULL) {
2652 weston_log("id_surface(%d) is already created\n", id_surface);
2653 return NULL;
2654 }
2655 }
2656
2657 ivisurf = calloc(1, sizeof *ivisurf);
2658 if (ivisurf == NULL) {
2659 weston_log("fails to allocate memory\n");
2660 return NULL;
2661 }
2662
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002663 wl_signal_init(&ivisurf->property_changed);
2664 wl_signal_init(&ivisurf->configured);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002665 ivisurf->id_surface = id_surface;
2666 ivisurf->layout = layout;
2667
2668 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002669
2670 tmpview = weston_view_create(wl_surface);
2671 if (tmpview == NULL) {
2672 weston_log("fails to allocate memory\n");
2673 }
2674
2675 ivisurf->surface->width_from_buffer = 0;
2676 ivisurf->surface->height_from_buffer = 0;
2677
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002678 weston_matrix_init(&ivisurf->transform.matrix);
2679 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002680
2681 init_surface_properties(&ivisurf->prop);
2682 ivisurf->event_mask = 0;
2683
2684 ivisurf->pending.prop = ivisurf->prop;
2685 wl_list_init(&ivisurf->pending.link);
2686
2687 wl_list_init(&ivisurf->order.link);
2688 wl_list_init(&ivisurf->order.layer_list);
2689
2690 wl_list_insert(&layout->surface_list, &ivisurf->link);
2691
2692 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2693
2694 return ivisurf;
2695}
2696
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002697void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002698ivi_layout_init_with_compositor(struct weston_compositor *ec)
2699{
2700 struct ivi_layout *layout = get_instance();
2701
2702 layout->compositor = ec;
2703
2704 wl_list_init(&layout->surface_list);
2705 wl_list_init(&layout->layer_list);
2706 wl_list_init(&layout->screen_list);
2707
2708 wl_signal_init(&layout->layer_notification.created);
2709 wl_signal_init(&layout->layer_notification.removed);
2710
2711 wl_signal_init(&layout->surface_notification.created);
2712 wl_signal_init(&layout->surface_notification.removed);
2713 wl_signal_init(&layout->surface_notification.configure_changed);
2714
2715 /* Add layout_layer at the last of weston_compositor.layer_list */
2716 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2717
2718 create_screen(ec);
2719
2720 layout->transitions = ivi_layout_transition_set_create(ec);
2721 wl_list_init(&layout->pending_transition_list);
2722}
2723
2724
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002725void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002726ivi_layout_surface_add_configured_listener(struct ivi_layout_surface* ivisurf,
2727 struct wl_listener* listener)
2728{
2729 wl_signal_add(&ivisurf->configured, listener);
2730}
2731
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002732static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002733 /**
2734 * commit all changes
2735 */
2736 .commit_changes = ivi_layout_commit_changes,
2737
2738 /**
2739 * surface controller interfaces
2740 */
2741 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2742 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2743 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2744 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2745 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2746 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2747 .get_surfaces = ivi_layout_get_surfaces,
2748 .get_id_of_surface = ivi_layout_get_id_of_surface,
2749 .get_surface_from_id = ivi_layout_get_surface_from_id,
2750 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2751 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2752 .surface_set_visibility = ivi_layout_surface_set_visibility,
2753 .surface_get_visibility = ivi_layout_surface_get_visibility,
2754 .surface_set_opacity = ivi_layout_surface_set_opacity,
2755 .surface_get_opacity = ivi_layout_surface_get_opacity,
2756 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2757 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
2758 .surface_set_position = ivi_layout_surface_set_position,
2759 .surface_get_position = ivi_layout_surface_get_position,
2760 .surface_set_dimension = ivi_layout_surface_set_dimension,
2761 .surface_get_dimension = ivi_layout_surface_get_dimension,
2762 .surface_set_orientation = ivi_layout_surface_set_orientation,
2763 .surface_get_orientation = ivi_layout_surface_get_orientation,
2764 .surface_set_content_observer = ivi_layout_surface_set_content_observer,
2765 .surface_add_notification = ivi_layout_surface_add_notification,
2766 .surface_remove_notification = ivi_layout_surface_remove_notification,
2767 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2768 .surface_set_transition = ivi_layout_surface_set_transition,
2769 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2770
2771 /**
2772 * layer controller interfaces
2773 */
2774 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2775 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2776 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2777 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2778 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002779 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002780 .get_layers = ivi_layout_get_layers,
2781 .get_id_of_layer = ivi_layout_get_id_of_layer,
2782 .get_layer_from_id = ivi_layout_get_layer_from_id,
2783 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2784 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2785 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2786 .layer_set_visibility = ivi_layout_layer_set_visibility,
2787 .layer_get_visibility = ivi_layout_layer_get_visibility,
2788 .layer_set_opacity = ivi_layout_layer_set_opacity,
2789 .layer_get_opacity = ivi_layout_layer_get_opacity,
2790 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2791 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
2792 .layer_set_position = ivi_layout_layer_set_position,
2793 .layer_get_position = ivi_layout_layer_get_position,
2794 .layer_set_dimension = ivi_layout_layer_set_dimension,
2795 .layer_get_dimension = ivi_layout_layer_get_dimension,
2796 .layer_set_orientation = ivi_layout_layer_set_orientation,
2797 .layer_get_orientation = ivi_layout_layer_get_orientation,
2798 .layer_add_surface = ivi_layout_layer_add_surface,
2799 .layer_remove_surface = ivi_layout_layer_remove_surface,
2800 .layer_set_render_order = ivi_layout_layer_set_render_order,
2801 .layer_add_notification = ivi_layout_layer_add_notification,
2802 .layer_remove_notification = ivi_layout_layer_remove_notification,
2803 .layer_set_transition = ivi_layout_layer_set_transition,
2804
2805 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002806 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002807 */
2808 .get_screen_from_id = ivi_layout_get_screen_from_id,
2809 .get_screen_resolution = ivi_layout_get_screen_resolution,
2810 .get_screens = ivi_layout_get_screens,
2811 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2812 .screen_add_layer = ivi_layout_screen_add_layer,
2813 .screen_set_render_order = ivi_layout_screen_set_render_order,
2814 .screen_get_output = ivi_layout_screen_get_output,
2815
2816 /**
2817 * animation
2818 */
2819 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002820 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2821
2822 /**
2823 * surface content dumping for debugging
2824 */
2825 .surface_get_size = ivi_layout_surface_get_size,
2826 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002827
2828 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002829 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002830 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002831 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002832 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2833
2834 /**
2835 * screen controller interfaces part2
2836 */
2837 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002838};
2839
2840int
2841load_controller_modules(struct weston_compositor *compositor, const char *modules,
2842 int *argc, char *argv[])
2843{
2844 const char *p, *end;
2845 char buffer[256];
2846 int (*controller_module_init)(struct weston_compositor *compositor,
2847 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002848 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002849 size_t interface_version);
2850
2851 if (modules == NULL)
2852 return 0;
2853
2854 p = modules;
2855 while (*p) {
2856 end = strchrnul(p, ',');
2857 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2858
2859 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002860 if (!controller_module_init)
2861 return -1;
2862
2863 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002864 &ivi_layout_interface,
2865 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002866 weston_log("ivi-shell: Initialization of controller module fails");
2867 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002868 }
2869
2870 p = end;
2871 while (*p == ',')
2872 p++;
2873 }
2874
2875 return 0;
2876}