blob: 390617c64d65d0332b3663c7c7f47cadd7b528ed [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"
Pekka Paalanen1f821932016-03-15 16:57:51 +020064#include "ivi-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090065#include "ivi-layout-export.h"
66#include "ivi-layout-private.h"
Pekka Paalanen32ca7912016-03-15 17:21:00 +020067#include "ivi-layout-shell.h"
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090068
Jon Cruz867d50e2015-06-15 15:37:10 -070069#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070070#include "shared/os-compatibility.h"
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +090071
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +090072#define max(a, b) ((a) > (b) ? (a) : (b))
73
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090074struct listener_layout_notification {
75 void *userdata;
76 struct wl_listener listener;
77};
78
79struct ivi_layout;
80
81struct ivi_layout_screen {
82 struct wl_list link;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090083 uint32_t id_screen;
84
85 struct ivi_layout *layout;
86 struct weston_output *output;
87
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090088 struct {
89 struct wl_list layer_list;
90 struct wl_list link;
91 } pending;
92
93 struct {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +000094 int dirty;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +090095 struct wl_list layer_list;
96 struct wl_list link;
97 } order;
98};
99
100struct ivi_layout_notification_callback {
101 void *callback;
102 void *data;
103};
104
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900105struct ivi_rectangle
106{
107 int32_t x;
108 int32_t y;
109 int32_t width;
110 int32_t height;
111};
112
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900113static void
114remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
115
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900116static struct ivi_layout ivilayout = {0};
117
118struct ivi_layout *
119get_instance(void)
120{
121 return &ivilayout;
122}
123
124/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900125 * Internal API to add/remove a ivi_layer to/from ivi_screen.
126 */
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900127static struct ivi_layout_surface *
128get_surface(struct wl_list *surf_list, uint32_t id_surface)
129{
130 struct ivi_layout_surface *ivisurf;
131
132 wl_list_for_each(ivisurf, surf_list, link) {
133 if (ivisurf->id_surface == id_surface) {
134 return ivisurf;
135 }
136 }
137
138 return NULL;
139}
140
141static struct ivi_layout_layer *
142get_layer(struct wl_list *layer_list, uint32_t id_layer)
143{
144 struct ivi_layout_layer *ivilayer;
145
146 wl_list_for_each(ivilayer, layer_list, link) {
147 if (ivilayer->id_layer == id_layer) {
148 return ivilayer;
149 }
150 }
151
152 return NULL;
153}
154
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000155static struct weston_view *
156get_weston_view(struct ivi_layout_surface *ivisurf)
157{
158 struct weston_view *view = NULL;
159
160 assert(ivisurf->surface != NULL);
161
162 /* One view per surface */
163 if(wl_list_empty(&ivisurf->surface->views))
164 view = NULL;
165 else
166 view = wl_container_of(ivisurf->surface->views.next, view, surface_link);
167
168 return view;
169}
170
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900171static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900172remove_all_notification(struct wl_list *listener_list)
173{
174 struct wl_listener *listener = NULL;
175 struct wl_listener *next = NULL;
176
177 wl_list_for_each_safe(listener, next, listener_list, link) {
178 struct listener_layout_notification *notification = NULL;
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000179 wl_list_remove(&listener->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900180
181 notification =
182 container_of(listener,
183 struct listener_layout_notification,
184 listener);
185
186 free(notification->userdata);
187 free(notification);
188 }
189}
190
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900191static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900192ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
193{
194 if (ivisurf == NULL) {
195 weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
196 return;
197 }
198
199 remove_all_notification(&ivisurf->property_changed.listener_list);
200}
201
Nobuhiko Tanibata82051702015-06-22 15:31:26 +0900202static void
203ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
204 surface_property_notification_func callback,
205 void *userdata)
206{
207 if (ivisurf == NULL) {
208 weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
209 return;
210 }
211
212 remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
213}
214
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900215/**
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900216 * Called at destruction of wl_surface/ivi_surface
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900217 */
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900218void
219ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900220{
221 struct ivi_layout *layout = get_instance();
222
223 if (ivisurf == NULL) {
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900224 weston_log("%s: invalid argument\n", __func__);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900225 return;
226 }
227
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900228 wl_list_remove(&ivisurf->transform.link);
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900229 wl_list_remove(&ivisurf->pending.link);
230 wl_list_remove(&ivisurf->order.link);
231 wl_list_remove(&ivisurf->link);
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900232
233 wl_signal_emit(&layout->surface_notification.removed, ivisurf);
234
Mateusz Polroladada6e32016-03-09 09:13:26 +0000235 ivi_layout_remove_all_surface_transitions(ivisurf);
236
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +0900237 ivi_layout_surface_remove_notification(ivisurf);
238
Nobuhiko Tanibata6f6c9382015-06-22 15:30:53 +0900239 free(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900240}
241
242/**
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900243 * Internal API to initialize ivi_screens found from output_list of weston_compositor.
244 * Called by ivi_layout_init_with_compositor.
245 */
246static void
247create_screen(struct weston_compositor *ec)
248{
249 struct ivi_layout *layout = get_instance();
250 struct ivi_layout_screen *iviscrn = NULL;
251 struct weston_output *output = NULL;
252 int32_t count = 0;
253
254 wl_list_for_each(output, &ec->output_list, link) {
255 iviscrn = calloc(1, sizeof *iviscrn);
256 if (iviscrn == NULL) {
257 weston_log("fails to allocate memory\n");
258 continue;
259 }
260
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900261 iviscrn->layout = layout;
262
263 iviscrn->id_screen = count;
264 count++;
265
266 iviscrn->output = output;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900267
268 wl_list_init(&iviscrn->pending.layer_list);
269 wl_list_init(&iviscrn->pending.link);
270
271 wl_list_init(&iviscrn->order.layer_list);
272 wl_list_init(&iviscrn->order.link);
273
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900274 wl_list_insert(&layout->screen_list, &iviscrn->link);
275 }
276}
277
278/**
279 * Internal APIs to initialize properties of ivi_surface/ivi_layer when they are created.
280 */
281static void
282init_layer_properties(struct ivi_layout_layer_properties *prop,
283 int32_t width, int32_t height)
284{
285 memset(prop, 0, sizeof *prop);
286 prop->opacity = wl_fixed_from_double(1.0);
287 prop->source_width = width;
288 prop->source_height = height;
289 prop->dest_width = width;
290 prop->dest_height = height;
291}
292
293static void
294init_surface_properties(struct ivi_layout_surface_properties *prop)
295{
296 memset(prop, 0, sizeof *prop);
297 prop->opacity = wl_fixed_from_double(1.0);
Nobuhiko Tanibatae259a7a2015-04-27 17:02:54 +0900298 /*
299 * FIXME: this shall be finxed by ivi-layout-transition.
300 */
301 prop->dest_width = 1;
302 prop->dest_height = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900303}
304
305/**
306 * Internal APIs to be called from ivi_layout_commit_changes.
307 */
308static void
309update_opacity(struct ivi_layout_layer *ivilayer,
310 struct ivi_layout_surface *ivisurf)
311{
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000312 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900313 double layer_alpha = wl_fixed_to_double(ivilayer->prop.opacity);
314 double surf_alpha = wl_fixed_to_double(ivisurf->prop.opacity);
315
Nobuhiko Tanibata90c27892015-12-26 23:52:51 +0900316 tmpview = get_weston_view(ivisurf);
317 assert(tmpview != NULL);
318 tmpview->alpha = layer_alpha * surf_alpha;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900319}
320
321static void
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900322get_rotate_values(enum wl_output_transform orientation,
323 float *v_sin,
324 float *v_cos)
325{
326 switch (orientation) {
327 case WL_OUTPUT_TRANSFORM_90:
328 *v_sin = 1.0f;
329 *v_cos = 0.0f;
330 break;
331 case WL_OUTPUT_TRANSFORM_180:
332 *v_sin = 0.0f;
333 *v_cos = -1.0f;
334 break;
335 case WL_OUTPUT_TRANSFORM_270:
336 *v_sin = -1.0f;
337 *v_cos = 0.0f;
338 break;
339 case WL_OUTPUT_TRANSFORM_NORMAL:
340 default:
341 *v_sin = 0.0f;
342 *v_cos = 1.0f;
343 break;
344 }
345}
346
347static void
348get_scale(enum wl_output_transform orientation,
349 float dest_width,
350 float dest_height,
351 float source_width,
352 float source_height,
353 float *scale_x,
354 float *scale_y)
355{
356 switch (orientation) {
357 case WL_OUTPUT_TRANSFORM_90:
358 *scale_x = dest_width / source_height;
359 *scale_y = dest_height / source_width;
360 break;
361 case WL_OUTPUT_TRANSFORM_180:
362 *scale_x = dest_width / source_width;
363 *scale_y = dest_height / source_height;
364 break;
365 case WL_OUTPUT_TRANSFORM_270:
366 *scale_x = dest_width / source_height;
367 *scale_y = dest_height / source_width;
368 break;
369 case WL_OUTPUT_TRANSFORM_NORMAL:
370 default:
371 *scale_x = dest_width / source_width;
372 *scale_y = dest_height / source_height;
373 break;
374 }
375}
376
377static void
378calc_transformation_matrix(struct ivi_rectangle *source_rect,
379 struct ivi_rectangle *dest_rect,
380 enum wl_output_transform orientation,
381 struct weston_matrix *m)
382{
383 float source_center_x;
384 float source_center_y;
385 float vsin;
386 float vcos;
387 float scale_x;
388 float scale_y;
389 float translate_x;
390 float translate_y;
391
392 source_center_x = source_rect->x + source_rect->width * 0.5f;
393 source_center_y = source_rect->y + source_rect->height * 0.5f;
394 weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
395
396 get_rotate_values(orientation, &vsin, &vcos);
397 weston_matrix_rotate_xy(m, vcos, vsin);
398
399 get_scale(orientation,
400 dest_rect->width,
401 dest_rect->height,
402 source_rect->width,
403 source_rect->height,
404 &scale_x,
405 &scale_y);
406 weston_matrix_scale(m, scale_x, scale_y, 1.0f);
407
408 translate_x = dest_rect->width * 0.5f + dest_rect->x;
409 translate_y = dest_rect->height * 0.5f + dest_rect->y;
410 weston_matrix_translate(m, translate_x, translate_y, 0.0f);
411}
412
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900413/*
414 * This computes intersected rect_output from two ivi_rectangles
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900415 */
416static void
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900417ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
418 const struct ivi_rectangle *rect2,
419 struct ivi_rectangle *rect_output)
420{
421 int32_t rect1_right = rect1->x + rect1->width;
422 int32_t rect1_bottom = rect1->y + rect1->height;
423 int32_t rect2_right = rect2->x + rect2->width;
424 int32_t rect2_bottom = rect2->y + rect2->height;
425
426 rect_output->x = max(rect1->x, rect2->x);
427 rect_output->y = max(rect1->y, rect2->y);
428 rect_output->width = rect1_right < rect2_right ?
429 rect1_right - rect_output->x :
430 rect2_right - rect_output->x;
431 rect_output->height = rect1_bottom < rect2_bottom ?
432 rect1_bottom - rect_output->y :
433 rect2_bottom - rect_output->y;
434
435 if (rect_output->width < 0 || rect_output->height < 0) {
436 rect_output->width = 0;
437 rect_output->height = 0;
438 }
439}
440
441/*
442 * Transform rect_input by the inverse of matrix, intersect with boundingbox,
443 * and store the result in rect_output.
444 * The boundingbox must be given in the same coordinate space as rect_output.
445 * Additionally, there are the following restrictions on the matrix:
446 * - no projective transformations
447 * - no skew
448 * - only multiples of 90-degree rotations supported
449 *
450 * In failure case of weston_matrix_invert, rect_output is set to boundingbox
451 * as a fail-safe with log.
452 */
453static void
454calc_inverse_matrix_transform(const struct weston_matrix *matrix,
455 const struct ivi_rectangle *rect_input,
456 const struct ivi_rectangle *boundingbox,
457 struct ivi_rectangle *rect_output)
458{
459 struct weston_matrix m;
460 struct weston_vector top_left;
461 struct weston_vector bottom_right;
462
463 assert(boundingbox != rect_output);
464
465 if (weston_matrix_invert(&m, matrix) < 0) {
466 weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
467 weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
468 rect_output->x = boundingbox->x;
469 rect_output->y = boundingbox->y;
470 rect_output->width = boundingbox->width;
471 rect_output->height = boundingbox->height;
472 }
473
474 /* The vectors and matrices involved will always produce f[3] == 1.0. */
475 top_left.f[0] = rect_input->x;
476 top_left.f[1] = rect_input->y;
477 top_left.f[2] = 0.0f;
478 top_left.f[3] = 1.0f;
479
480 bottom_right.f[0] = rect_input->x + rect_input->width;
481 bottom_right.f[1] = rect_input->y + rect_input->height;
482 bottom_right.f[2] = 0.0f;
483 bottom_right.f[3] = 1.0f;
484
485 weston_matrix_transform(&m, &top_left);
486 weston_matrix_transform(&m, &bottom_right);
487
488 if (top_left.f[0] < bottom_right.f[0]) {
489 rect_output->x = top_left.f[0];
490 rect_output->width = bottom_right.f[0] - rect_output->x;
491 } else {
492 rect_output->x = bottom_right.f[0];
493 rect_output->width = top_left.f[0] - rect_output->x;
494 }
495
496 if (top_left.f[1] < bottom_right.f[1]) {
497 rect_output->y = top_left.f[1];
498 rect_output->height = bottom_right.f[1] - rect_output->y;
499 } else {
500 rect_output->y = bottom_right.f[1];
501 rect_output->height = top_left.f[1] - rect_output->y;
502 }
503
504 ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
505}
506
507/**
508 * This computes the whole transformation matrix:m from surface-local
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900509 * coordinates to multi screens coordinate, which is global coordinates.
510 * It is assumed that weston_view::geometry.{x,y} are zero.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900511 *
512 * Additionally, this computes the mask on surface-local coordinates as a
513 * ivi_rectangle. This can be set to weston_view_set_mask.
514 *
515 * The mask is computed by following steps
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900516 * - destination rectangle of layer is tansformed to multi screen coordinate,
517 * global coordinates. This is done by adding weston_output.{x,y} in simple
518 * because there is no scaled and rotated transformation.
519 * - destination rectangle of layer in multi screens coordinate needs to be
520 * intersected inside of a screen the layer is assigned to. This is because
521 * overlapped region of weston surface in another screen shall not be
522 * displayed according to ivi use case.
523 * - destination rectangle of layer
524 * - in multi screen coordinates,
525 * - and intersected inside of an assigned screen,
526 * is inversed to surface-local cooodinates by inversed matrix:m.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900527 * - the area is intersected by intersected area between weston_surface and
528 * source rectangle of ivi_surface.
529 */
530static void
531calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900532 struct ivi_layout_screen *iviscrn,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900533 struct ivi_layout_layer *ivilayer,
534 struct ivi_layout_surface *ivisurf,
535 struct weston_matrix *m,
536 struct ivi_rectangle *result)
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900537{
538 const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
539 const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900540 struct weston_output *output = iviscrn->output;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900541 struct ivi_rectangle weston_surface_rect = { 0,
542 0,
543 ivisurf->surface->width,
544 ivisurf->surface->height };
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900545 struct ivi_rectangle surface_source_rect = { sp->source_x,
546 sp->source_y,
547 sp->source_width,
548 sp->source_height };
549 struct ivi_rectangle surface_dest_rect = { sp->dest_x,
550 sp->dest_y,
551 sp->dest_width,
552 sp->dest_height };
553 struct ivi_rectangle layer_source_rect = { lp->source_x,
554 lp->source_y,
555 lp->source_width,
556 lp->source_height };
557 struct ivi_rectangle layer_dest_rect = { lp->dest_x,
558 lp->dest_y,
559 lp->dest_width,
560 lp->dest_height };
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900561 struct ivi_rectangle screen_dest_rect = { output->x,
562 output->y,
563 output->width,
564 output->height };
565 struct ivi_rectangle layer_dest_rect_in_global =
566 { lp->dest_x + output->x,
567 lp->dest_y + output->y,
568 lp->dest_width,
569 lp->dest_height };
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900570 struct ivi_rectangle surface_result;
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900571 struct ivi_rectangle layer_dest_rect_in_global_intersected;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900572
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900573 /*
574 * the whole transformation matrix:m from surface-local
575 * coordinates to global coordinates, which is computed by
576 * two steps,
577 * - surface-local coordinates to layer-local coordinates
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900578 * - layer-local coordinates to a single screen-local coordinates
579 * - a single screen-local coordinates to multi screen coordinates,
580 * which is global coordinates.
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900581 */
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900582 calc_transformation_matrix(&surface_source_rect,
583 &surface_dest_rect,
584 sp->orientation, m);
585
586 calc_transformation_matrix(&layer_source_rect,
587 &layer_dest_rect,
588 lp->orientation, m);
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900589
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900590 weston_matrix_translate(m, output->x, output->y, 0.0f);
591
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900592 /* this intersected ivi_rectangle would be used for masking
593 * weston_surface
594 */
595 ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
596 &surface_result);
597
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900598 /*
599 * destination rectangle of layer in multi screens coordinate
600 * is intersected to avoid displaying outside of an assigned screen.
601 */
602 ivi_rectangle_intersect(&layer_dest_rect_in_global, &screen_dest_rect,
603 &layer_dest_rect_in_global_intersected);
604
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900605 /* calc masking area of weston_surface from m */
606 calc_inverse_matrix_transform(m,
Nobuhiko Tanibata1c2618e2015-12-09 15:39:26 +0900607 &layer_dest_rect_in_global_intersected,
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900608 &surface_result,
609 result);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900610}
611
612static void
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900613update_prop(struct ivi_layout_screen *iviscrn,
614 struct ivi_layout_layer *ivilayer,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900615 struct ivi_layout_surface *ivisurf)
616{
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900617 struct weston_view *tmpview;
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900618 struct ivi_rectangle r;
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900619 bool can_calc = true;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900620
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900621 /*In case of no prop change, this just returns*/
622 if (!ivilayer->event_mask && !ivisurf->event_mask)
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900623 return;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900624
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900625 update_opacity(ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900626
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000627 tmpview = get_weston_view(ivisurf);
628 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900629
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900630 if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
631 weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
632 can_calc = false;
633 }
634
635 if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
636 weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
637 can_calc = false;
638 }
639
640 if (can_calc) {
641 wl_list_remove(&ivisurf->transform.link);
642 weston_matrix_init(&ivisurf->transform.matrix);
643
Nobuhiko Tanibataacbcc6c2015-08-24 10:24:15 +0900644 calc_surface_to_global_matrix_and_mask_to_weston_surface(
Nobuhiko Tanibata29babdf2015-12-09 15:38:41 +0900645 iviscrn, ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900646
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000647 weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
648 wl_list_insert(&tmpview->geometry.transformation_list,
649 &ivisurf->transform.link);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900650
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000651 weston_view_set_transform_parent(tmpview, NULL);
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +0900652 }
653
654 ivisurf->update_count++;
655
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000656 weston_view_geometry_dirty(tmpview);
Nobuhiko Tanibata4c1dbf72015-07-15 13:55:50 +0900657
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000658 weston_surface_damage(ivisurf->surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900659}
660
661static void
662commit_changes(struct ivi_layout *layout)
663{
664 struct ivi_layout_screen *iviscrn = NULL;
665 struct ivi_layout_layer *ivilayer = NULL;
666 struct ivi_layout_surface *ivisurf = NULL;
667
668 wl_list_for_each(iviscrn, &layout->screen_list, link) {
669 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900670 /*
671 * If ivilayer is invisible, weston_view of ivisurf doesn't
672 * need to be modified.
673 */
674 if (ivilayer->prop.visibility == false)
675 continue;
676
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900677 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibatab4cb25d2015-12-09 15:36:58 +0900678 /*
679 * If ivilayer is invisible, weston_view of ivisurf doesn't
680 * need to be modified.
681 */
682 if (ivisurf->prop.visibility == false)
683 continue;
684
685 update_prop(iviscrn, ivilayer, ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900686 }
687 }
688 }
689}
690
691static void
692commit_surface_list(struct ivi_layout *layout)
693{
694 struct ivi_layout_surface *ivisurf = NULL;
695 int32_t dest_x = 0;
696 int32_t dest_y = 0;
697 int32_t dest_width = 0;
698 int32_t dest_height = 0;
699 int32_t configured = 0;
700
701 wl_list_for_each(ivisurf, &layout->surface_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300702 if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900703 dest_x = ivisurf->prop.dest_x;
704 dest_y = ivisurf->prop.dest_y;
705 dest_width = ivisurf->prop.dest_width;
706 dest_height = ivisurf->prop.dest_height;
707
708 ivi_layout_transition_move_resize_view(ivisurf,
709 ivisurf->pending.prop.dest_x,
710 ivisurf->pending.prop.dest_y,
711 ivisurf->pending.prop.dest_width,
712 ivisurf->pending.prop.dest_height,
713 ivisurf->pending.prop.transition_duration);
714
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300715 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900716 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
717 } else {
718 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
719 }
720
721 ivisurf->prop = ivisurf->pending.prop;
722 ivisurf->prop.dest_x = dest_x;
723 ivisurf->prop.dest_y = dest_y;
724 ivisurf->prop.dest_width = dest_width;
725 ivisurf->prop.dest_height = dest_height;
726 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
727 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
728
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300729 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900730 dest_x = ivisurf->prop.dest_x;
731 dest_y = ivisurf->prop.dest_y;
732 dest_width = ivisurf->prop.dest_width;
733 dest_height = ivisurf->prop.dest_height;
734
735 ivi_layout_transition_move_resize_view(ivisurf,
736 ivisurf->pending.prop.dest_x,
737 ivisurf->pending.prop.dest_y,
738 ivisurf->pending.prop.dest_width,
739 ivisurf->pending.prop.dest_height,
740 ivisurf->pending.prop.transition_duration);
741
742 ivisurf->prop = ivisurf->pending.prop;
743 ivisurf->prop.dest_x = dest_x;
744 ivisurf->prop.dest_y = dest_y;
745 ivisurf->prop.dest_width = dest_width;
746 ivisurf->prop.dest_height = dest_height;
747
748 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
749 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
750
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300751 } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900752 configured = 0;
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300753 if (ivisurf->pending.prop.visibility) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900754 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
755 } else {
756 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
757 }
758
759 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
760 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
761 configured = 1;
762 }
763
764 ivisurf->prop = ivisurf->pending.prop;
765 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
766 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
767
Pekka Paalanen1f821932016-03-15 16:57:51 +0200768 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200769 shell_surface_send_configure(ivisurf->surface,
770 ivisurf->prop.dest_width,
771 ivisurf->prop.dest_height);
772 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900773 } else {
774 configured = 0;
775 if (ivisurf->prop.dest_width != ivisurf->pending.prop.dest_width ||
776 ivisurf->prop.dest_height != ivisurf->pending.prop.dest_height) {
777 configured = 1;
778 }
779
780 ivisurf->prop = ivisurf->pending.prop;
781 ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
782 ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
783
Pekka Paalanen1f821932016-03-15 16:57:51 +0200784 if (configured && !is_surface_transition(ivisurf)) {
Pekka Paalanen1f821932016-03-15 16:57:51 +0200785 shell_surface_send_configure(ivisurf->surface,
786 ivisurf->prop.dest_width,
787 ivisurf->prop.dest_height);
788 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900789 }
790 }
791}
792
793static void
794commit_layer_list(struct ivi_layout *layout)
795{
796 struct ivi_layout_layer *ivilayer = NULL;
797 struct ivi_layout_surface *ivisurf = NULL;
798 struct ivi_layout_surface *next = NULL;
799
800 wl_list_for_each(ivilayer, &layout->layer_list, link) {
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300801 if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900802 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 -0300803 } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900804 ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
805 ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
806 NULL, NULL,
807 ivilayer->pending.prop.transition_duration);
808 }
809 ivilayer->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
810
811 ivilayer->prop = ivilayer->pending.prop;
812
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000813 if (!ivilayer->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900814 continue;
815 }
816
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000817 wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
818 order.link) {
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000819 ivisurf->on_layer = NULL;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000820 wl_list_remove(&ivisurf->order.link);
821 wl_list_init(&ivisurf->order.link);
822 ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900823 }
824
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000825 assert(wl_list_empty(&ivilayer->order.surface_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900826
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000827 wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900828 pending.link) {
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000829 wl_list_remove(&ivisurf->order.link);
830 wl_list_insert(&ivilayer->order.surface_list,
831 &ivisurf->order.link);
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +0000832 ivisurf->on_layer = ivilayer;
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000833 ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900834 }
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +0000835
836 ivilayer->order.dirty = 0;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900837 }
838}
839
840static void
841commit_screen_list(struct ivi_layout *layout)
842{
843 struct ivi_layout_screen *iviscrn = NULL;
844 struct ivi_layout_layer *ivilayer = NULL;
845 struct ivi_layout_layer *next = NULL;
846 struct ivi_layout_surface *ivisurf = NULL;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000847 struct weston_view *tmpview = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900848
Nobuhiko Tanibatafbfa8f22015-11-25 23:36:57 +0900849 /* Clear view list of layout ivi_layer */
850 wl_list_init(&layout->layout_layer.view_list.link);
851
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900852 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000853 if (iviscrn->order.dirty) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900854 wl_list_for_each_safe(ivilayer, next,
855 &iviscrn->order.layer_list, order.link) {
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000856 ivilayer->on_screen = NULL;
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000857 wl_list_remove(&ivilayer->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900858 wl_list_init(&ivilayer->order.link);
859 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
860 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900861
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000862 assert(wl_list_empty(&iviscrn->order.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900863
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900864 wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
865 pending.link) {
Nobuhiko Tanibata77b0ee12015-11-25 23:36:46 +0900866 /* FIXME: avoid to insert order.link to multiple screens */
867 wl_list_remove(&ivilayer->order.link);
868
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900869 wl_list_insert(&iviscrn->order.layer_list,
870 &ivilayer->order.link);
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +0000871 ivilayer->on_screen = iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900872 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
873 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900874
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +0000875 iviscrn->order.dirty = 0;
876 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900877
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900878 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
879 if (ivilayer->prop.visibility == false)
880 continue;
881
882 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900883 if (ivisurf->prop.visibility == false)
884 continue;
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +0000885
886 tmpview = get_weston_view(ivisurf);
887 assert(tmpview != NULL);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900888
889 weston_layer_entry_insert(&layout->layout_layer.view_list,
890 &tmpview->layer_link);
891
892 ivisurf->surface->output = iviscrn->output;
893 }
894 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900895 }
896}
897
898static void
899commit_transition(struct ivi_layout* layout)
900{
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300901 if (wl_list_empty(&layout->pending_transition_list)) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900902 return;
903 }
904
905 wl_list_insert_list(&layout->transitions->transition_list,
906 &layout->pending_transition_list);
907
908 wl_list_init(&layout->pending_transition_list);
909
910 wl_event_source_timer_update(layout->transitions->event_source, 1);
911}
912
913static void
914send_surface_prop(struct ivi_layout_surface *ivisurf)
915{
916 wl_signal_emit(&ivisurf->property_changed, ivisurf);
917 ivisurf->event_mask = 0;
918}
919
920static void
921send_layer_prop(struct ivi_layout_layer *ivilayer)
922{
923 wl_signal_emit(&ivilayer->property_changed, ivilayer);
924 ivilayer->event_mask = 0;
925}
926
927static void
928send_prop(struct ivi_layout *layout)
929{
930 struct ivi_layout_layer *ivilayer = NULL;
931 struct ivi_layout_surface *ivisurf = NULL;
932
933 wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900934 if (ivilayer->event_mask)
935 send_layer_prop(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900936 }
937
938 wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
Nobuhiko Tanibata6ce3ef82015-06-22 15:32:06 +0900939 if (ivisurf->event_mask)
940 send_surface_prop(ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900941 }
942}
943
944static void
945clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
946{
947 struct ivi_layout_surface *surface_link = NULL;
948 struct ivi_layout_surface *surface_next = NULL;
949
950 wl_list_for_each_safe(surface_link, surface_next,
951 &ivilayer->pending.surface_list, pending.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000952 wl_list_remove(&surface_link->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900953 wl_list_init(&surface_link->pending.link);
954 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900955}
956
957static void
958clear_surface_order_list(struct ivi_layout_layer *ivilayer)
959{
960 struct ivi_layout_surface *surface_link = NULL;
961 struct ivi_layout_surface *surface_next = NULL;
962
963 wl_list_for_each_safe(surface_link, surface_next,
964 &ivilayer->order.surface_list, order.link) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +0000965 wl_list_remove(&surface_link->order.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900966 wl_list_init(&surface_link->order.link);
967 }
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +0900968}
969
970static void
971layer_created(struct wl_listener *listener, void *data)
972{
973 struct ivi_layout_layer *ivilayer = data;
974
975 struct listener_layout_notification *notification =
976 container_of(listener,
977 struct listener_layout_notification,
978 listener);
979
980 struct ivi_layout_notification_callback *created_callback =
981 notification->userdata;
982
983 ((layer_create_notification_func)created_callback->callback)
984 (ivilayer, created_callback->data);
985}
986
987static void
988layer_removed(struct wl_listener *listener, void *data)
989{
990 struct ivi_layout_layer *ivilayer = data;
991
992 struct listener_layout_notification *notification =
993 container_of(listener,
994 struct listener_layout_notification,
995 listener);
996
997 struct ivi_layout_notification_callback *removed_callback =
998 notification->userdata;
999
1000 ((layer_remove_notification_func)removed_callback->callback)
1001 (ivilayer, removed_callback->data);
1002}
1003
1004static void
1005layer_prop_changed(struct wl_listener *listener, void *data)
1006{
1007 struct ivi_layout_layer *ivilayer = data;
1008
1009 struct listener_layout_notification *layout_listener =
1010 container_of(listener,
1011 struct listener_layout_notification,
1012 listener);
1013
1014 struct ivi_layout_notification_callback *prop_callback =
1015 layout_listener->userdata;
1016
1017 ((layer_property_notification_func)prop_callback->callback)
1018 (ivilayer, &ivilayer->prop, ivilayer->event_mask, prop_callback->data);
1019}
1020
1021static void
1022surface_created(struct wl_listener *listener, void *data)
1023{
1024 struct ivi_layout_surface *ivisurface = data;
1025
1026 struct listener_layout_notification *notification =
1027 container_of(listener,
1028 struct listener_layout_notification,
1029 listener);
1030
1031 struct ivi_layout_notification_callback *created_callback =
1032 notification->userdata;
1033
1034 ((surface_create_notification_func)created_callback->callback)
1035 (ivisurface, created_callback->data);
1036}
1037
1038static void
1039surface_removed(struct wl_listener *listener, void *data)
1040{
1041 struct ivi_layout_surface *ivisurface = data;
1042
1043 struct listener_layout_notification *notification =
1044 container_of(listener,
1045 struct listener_layout_notification,
1046 listener);
1047
1048 struct ivi_layout_notification_callback *removed_callback =
1049 notification->userdata;
1050
1051 ((surface_remove_notification_func)removed_callback->callback)
1052 (ivisurface, removed_callback->data);
1053}
1054
1055static void
1056surface_prop_changed(struct wl_listener *listener, void *data)
1057{
1058 struct ivi_layout_surface *ivisurf = data;
1059
1060 struct listener_layout_notification *layout_listener =
1061 container_of(listener,
1062 struct listener_layout_notification,
1063 listener);
1064
1065 struct ivi_layout_notification_callback *prop_callback =
1066 layout_listener->userdata;
1067
1068 ((surface_property_notification_func)prop_callback->callback)
1069 (ivisurf, &ivisurf->prop, ivisurf->event_mask, prop_callback->data);
1070
1071 ivisurf->event_mask = 0;
1072}
1073
1074static void
1075surface_configure_changed(struct wl_listener *listener,
1076 void *data)
1077{
1078 struct ivi_layout_surface *ivisurface = data;
1079
1080 struct listener_layout_notification *notification =
1081 container_of(listener,
1082 struct listener_layout_notification,
1083 listener);
1084
1085 struct ivi_layout_notification_callback *configure_changed_callback =
1086 notification->userdata;
1087
1088 ((surface_configure_notification_func)configure_changed_callback->callback)
1089 (ivisurface, configure_changed_callback->data);
1090}
1091
1092static int32_t
1093add_notification(struct wl_signal *signal,
1094 wl_notify_func_t callback,
1095 void *userdata)
1096{
1097 struct listener_layout_notification *notification = NULL;
1098
1099 notification = malloc(sizeof *notification);
1100 if (notification == NULL) {
1101 weston_log("fails to allocate memory\n");
1102 free(userdata);
1103 return IVI_FAILED;
1104 }
1105
1106 notification->listener.notify = callback;
1107 notification->userdata = userdata;
1108
1109 wl_signal_add(signal, &notification->listener);
1110
1111 return IVI_SUCCEEDED;
1112}
1113
1114static void
1115remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
1116{
1117 struct wl_listener *listener = NULL;
1118 struct wl_listener *next = NULL;
1119
1120 wl_list_for_each_safe(listener, next, listener_list, link) {
1121 struct listener_layout_notification *notification =
1122 container_of(listener,
1123 struct listener_layout_notification,
1124 listener);
1125
1126 struct ivi_layout_notification_callback *notification_callback =
1127 notification->userdata;
1128
1129 if ((notification_callback->callback != callback) ||
1130 (notification_callback->data != userdata)) {
1131 continue;
1132 }
1133
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001134 wl_list_remove(&listener->link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001135
1136 free(notification->userdata);
1137 free(notification);
1138 }
1139}
1140
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001141/**
1142 * Exported APIs of ivi-layout library are implemented from here.
1143 * Brief of APIs is described in ivi-layout-export.h.
1144 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001145static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001146ivi_layout_add_notification_create_layer(layer_create_notification_func callback,
1147 void *userdata)
1148{
1149 struct ivi_layout *layout = get_instance();
1150 struct ivi_layout_notification_callback *created_callback = NULL;
1151
1152 if (callback == NULL) {
1153 weston_log("ivi_layout_add_notification_create_layer: invalid argument\n");
1154 return IVI_FAILED;
1155 }
1156
1157 created_callback = malloc(sizeof *created_callback);
1158 if (created_callback == NULL) {
1159 weston_log("fails to allocate memory\n");
1160 return IVI_FAILED;
1161 }
1162
1163 created_callback->callback = callback;
1164 created_callback->data = userdata;
1165
1166 return add_notification(&layout->layer_notification.created,
1167 layer_created,
1168 created_callback);
1169}
1170
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001171static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001172ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
1173 void *userdata)
1174{
1175 struct ivi_layout *layout = get_instance();
1176 remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
1177}
1178
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001179static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001180ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
1181 void *userdata)
1182{
1183 struct ivi_layout *layout = get_instance();
1184 struct ivi_layout_notification_callback *removed_callback = NULL;
1185
1186 if (callback == NULL) {
1187 weston_log("ivi_layout_add_notification_remove_layer: invalid argument\n");
1188 return IVI_FAILED;
1189 }
1190
1191 removed_callback = malloc(sizeof *removed_callback);
1192 if (removed_callback == NULL) {
1193 weston_log("fails to allocate memory\n");
1194 return IVI_FAILED;
1195 }
1196
1197 removed_callback->callback = callback;
1198 removed_callback->data = userdata;
1199 return add_notification(&layout->layer_notification.removed,
1200 layer_removed,
1201 removed_callback);
1202}
1203
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001204static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001205ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
1206 void *userdata)
1207{
1208 struct ivi_layout *layout = get_instance();
1209 remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
1210}
1211
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001212static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001213ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
1214 void *userdata)
1215{
1216 struct ivi_layout *layout = get_instance();
1217 struct ivi_layout_notification_callback *created_callback = NULL;
1218
1219 if (callback == NULL) {
1220 weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
1221 return IVI_FAILED;
1222 }
1223
1224 created_callback = malloc(sizeof *created_callback);
1225 if (created_callback == NULL) {
1226 weston_log("fails to allocate memory\n");
1227 return IVI_FAILED;
1228 }
1229
1230 created_callback->callback = callback;
1231 created_callback->data = userdata;
1232
1233 return add_notification(&layout->surface_notification.created,
1234 surface_created,
1235 created_callback);
1236}
1237
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001238static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001239ivi_layout_remove_notification_create_surface(surface_create_notification_func callback,
1240 void *userdata)
1241{
1242 struct ivi_layout *layout = get_instance();
1243 remove_notification(&layout->surface_notification.created.listener_list, callback, userdata);
1244}
1245
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001246static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001247ivi_layout_add_notification_remove_surface(surface_remove_notification_func callback,
1248 void *userdata)
1249{
1250 struct ivi_layout *layout = get_instance();
1251 struct ivi_layout_notification_callback *removed_callback = NULL;
1252
1253 if (callback == NULL) {
1254 weston_log("ivi_layout_add_notification_remove_surface: invalid argument\n");
1255 return IVI_FAILED;
1256 }
1257
1258 removed_callback = malloc(sizeof *removed_callback);
1259 if (removed_callback == NULL) {
1260 weston_log("fails to allocate memory\n");
1261 return IVI_FAILED;
1262 }
1263
1264 removed_callback->callback = callback;
1265 removed_callback->data = userdata;
1266
1267 return add_notification(&layout->surface_notification.removed,
1268 surface_removed,
1269 removed_callback);
1270}
1271
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001272static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001273ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
1274 void *userdata)
1275{
1276 struct ivi_layout *layout = get_instance();
1277 remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
1278}
1279
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001280static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001281ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
1282 void *userdata)
1283{
1284 struct ivi_layout *layout = get_instance();
1285 struct ivi_layout_notification_callback *configure_changed_callback = NULL;
1286 if (callback == NULL) {
1287 weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
1288 return IVI_FAILED;
1289 }
1290
1291 configure_changed_callback = malloc(sizeof *configure_changed_callback);
1292 if (configure_changed_callback == NULL) {
1293 weston_log("fails to allocate memory\n");
1294 return IVI_FAILED;
1295 }
1296
1297 configure_changed_callback->callback = callback;
1298 configure_changed_callback->data = userdata;
1299
1300 return add_notification(&layout->surface_notification.configure_changed,
1301 surface_configure_changed,
1302 configure_changed_callback);
1303}
1304
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001305static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001306ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
1307 void *userdata)
1308{
1309 struct ivi_layout *layout = get_instance();
1310 remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
1311}
1312
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001313uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001314ivi_layout_get_id_of_surface(struct ivi_layout_surface *ivisurf)
1315{
1316 return ivisurf->id_surface;
1317}
1318
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001319static uint32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001320ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1321{
1322 return ivilayer->id_layer;
1323}
1324
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09001325static uint32_t
1326ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1327{
1328 return iviscrn->id_screen;
1329}
1330
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001331static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001332ivi_layout_get_layer_from_id(uint32_t id_layer)
1333{
1334 struct ivi_layout *layout = get_instance();
1335 struct ivi_layout_layer *ivilayer = NULL;
1336
1337 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1338 if (ivilayer->id_layer == id_layer) {
1339 return ivilayer;
1340 }
1341 }
1342
1343 return NULL;
1344}
1345
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001346struct ivi_layout_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001347ivi_layout_get_surface_from_id(uint32_t id_surface)
1348{
1349 struct ivi_layout *layout = get_instance();
1350 struct ivi_layout_surface *ivisurf = NULL;
1351
1352 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1353 if (ivisurf->id_surface == id_surface) {
1354 return ivisurf;
1355 }
1356 }
1357
1358 return NULL;
1359}
1360
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001361static struct ivi_layout_screen *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001362ivi_layout_get_screen_from_id(uint32_t id_screen)
1363{
1364 struct ivi_layout *layout = get_instance();
1365 struct ivi_layout_screen *iviscrn = NULL;
1366
1367 wl_list_for_each(iviscrn, &layout->screen_list, link) {
Nobuhiko Tanibata3e710d12015-11-25 23:36:09 +09001368 if (iviscrn->id_screen == id_screen)
1369 return iviscrn;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001370 }
1371
1372 return NULL;
1373}
1374
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001375static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001376ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1377 int32_t *pWidth, int32_t *pHeight)
1378{
1379 struct weston_output *output = NULL;
1380
Nobuhiko Tanibata0c217cb2015-06-22 15:30:32 +09001381 if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001382 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1383 return IVI_FAILED;
1384 }
1385
1386 output = iviscrn->output;
1387 *pWidth = output->current_mode->width;
1388 *pHeight = output->current_mode->height;
1389
1390 return IVI_SUCCEEDED;
1391}
1392
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001393static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001394ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
1395 surface_property_notification_func callback,
1396 void *userdata)
1397{
1398 struct listener_layout_notification* notification = NULL;
1399 struct ivi_layout_notification_callback *prop_callback = NULL;
1400
1401 if (ivisurf == NULL || callback == NULL) {
1402 weston_log("ivi_layout_surface_add_notification: invalid argument\n");
1403 return IVI_FAILED;
1404 }
1405
1406 notification = malloc(sizeof *notification);
1407 if (notification == NULL) {
1408 weston_log("fails to allocate memory\n");
1409 return IVI_FAILED;
1410 }
1411
1412 prop_callback = malloc(sizeof *prop_callback);
1413 if (prop_callback == NULL) {
1414 weston_log("fails to allocate memory\n");
Lucas Tanure193c7a52015-09-19 18:24:58 -03001415 free(notification);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001416 return IVI_FAILED;
1417 }
1418
1419 prop_callback->callback = callback;
1420 prop_callback->data = userdata;
1421
1422 notification->listener.notify = surface_prop_changed;
1423 notification->userdata = prop_callback;
1424
1425 wl_signal_add(&ivisurf->property_changed, &notification->listener);
1426
1427 return IVI_SUCCEEDED;
1428}
1429
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001430static const struct ivi_layout_layer_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001431ivi_layout_get_properties_of_layer(struct ivi_layout_layer *ivilayer)
1432{
1433 if (ivilayer == NULL) {
1434 weston_log("ivi_layout_get_properties_of_layer: invalid argument\n");
1435 return NULL;
1436 }
1437
1438 return &ivilayer->prop;
1439}
1440
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001441static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001442ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1443{
1444 struct ivi_layout *layout = get_instance();
1445 struct ivi_layout_screen *iviscrn = NULL;
1446 int32_t length = 0;
1447 int32_t n = 0;
1448
1449 if (pLength == NULL || ppArray == NULL) {
1450 weston_log("ivi_layout_get_screens: invalid argument\n");
1451 return IVI_FAILED;
1452 }
1453
1454 length = wl_list_length(&layout->screen_list);
1455
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001456 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001457 /* the Array must be free by module which called this function */
1458 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1459 if (*ppArray == NULL) {
1460 weston_log("fails to allocate memory\n");
1461 return IVI_FAILED;
1462 }
1463
1464 wl_list_for_each(iviscrn, &layout->screen_list, link) {
1465 (*ppArray)[n++] = iviscrn;
1466 }
1467 }
1468
1469 *pLength = length;
1470
1471 return IVI_SUCCEEDED;
1472}
1473
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001474static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001475ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1476 int32_t *pLength,
1477 struct ivi_layout_screen ***ppArray)
1478{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001479 int32_t length = 0;
1480 int32_t n = 0;
1481
1482 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1483 weston_log("ivi_layout_get_screens_under_layer: invalid argument\n");
1484 return IVI_FAILED;
1485 }
1486
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001487 if (ivilayer->on_screen != NULL)
1488 length = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001489
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001490 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001491 /* the Array must be free by module which called this function */
1492 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1493 if (*ppArray == NULL) {
1494 weston_log("fails to allocate memory\n");
1495 return IVI_FAILED;
1496 }
1497
Ucan, Emre (ADITG/SW1)8a223672015-08-28 12:58:55 +00001498 (*ppArray)[n++] = ivilayer->on_screen;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001499 }
1500
1501 *pLength = length;
1502
1503 return IVI_SUCCEEDED;
1504}
1505
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001506static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001507ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1508{
1509 struct ivi_layout *layout = get_instance();
1510 struct ivi_layout_layer *ivilayer = NULL;
1511 int32_t length = 0;
1512 int32_t n = 0;
1513
1514 if (pLength == NULL || ppArray == NULL) {
1515 weston_log("ivi_layout_get_layers: invalid argument\n");
1516 return IVI_FAILED;
1517 }
1518
1519 length = wl_list_length(&layout->layer_list);
1520
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001521 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001522 /* the Array must be free by module which called this function */
1523 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1524 if (*ppArray == NULL) {
1525 weston_log("fails to allocate memory\n");
1526 return IVI_FAILED;
1527 }
1528
1529 wl_list_for_each(ivilayer, &layout->layer_list, link) {
1530 (*ppArray)[n++] = ivilayer;
1531 }
1532 }
1533
1534 *pLength = length;
1535
1536 return IVI_SUCCEEDED;
1537}
1538
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001539static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001540ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1541 int32_t *pLength,
1542 struct ivi_layout_layer ***ppArray)
1543{
1544 struct ivi_layout_layer *ivilayer = NULL;
1545 int32_t length = 0;
1546 int32_t n = 0;
1547
1548 if (iviscrn == NULL || pLength == NULL || ppArray == NULL) {
1549 weston_log("ivi_layout_get_layers_on_screen: invalid argument\n");
1550 return IVI_FAILED;
1551 }
1552
1553 length = wl_list_length(&iviscrn->order.layer_list);
1554
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001555 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001556 /* the Array must be free by module which called this function */
1557 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1558 if (*ppArray == NULL) {
1559 weston_log("fails to allocate memory\n");
1560 return IVI_FAILED;
1561 }
1562
Nobuhiko Tanibatae2b82142015-06-22 15:30:19 +09001563 wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001564 (*ppArray)[n++] = ivilayer;
1565 }
1566 }
1567
1568 *pLength = length;
1569
1570 return IVI_SUCCEEDED;
1571}
1572
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001573static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001574ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1575 int32_t *pLength,
1576 struct ivi_layout_layer ***ppArray)
1577{
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001578 int32_t length = 0;
1579 int32_t n = 0;
1580
1581 if (ivisurf == NULL || pLength == NULL || ppArray == NULL) {
1582 weston_log("ivi_layout_getLayers: invalid argument\n");
1583 return IVI_FAILED;
1584 }
1585
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001586 if (ivisurf->on_layer != NULL) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001587 /* the Array must be free by module which called this function */
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001588 length = 1;
1589 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001590 if (*ppArray == NULL) {
1591 weston_log("fails to allocate memory\n");
1592 return IVI_FAILED;
1593 }
1594
Ucan, Emre (ADITG/SW1)dfac3752015-08-28 12:58:58 +00001595 (*ppArray)[n++] = ivisurf->on_layer;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001596 }
1597
1598 *pLength = length;
1599
1600 return IVI_SUCCEEDED;
1601}
1602
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001603static
1604int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001605ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1606{
1607 struct ivi_layout *layout = get_instance();
1608 struct ivi_layout_surface *ivisurf = NULL;
1609 int32_t length = 0;
1610 int32_t n = 0;
1611
1612 if (pLength == NULL || ppArray == NULL) {
1613 weston_log("ivi_layout_get_surfaces: invalid argument\n");
1614 return IVI_FAILED;
1615 }
1616
1617 length = wl_list_length(&layout->surface_list);
1618
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001619 if (length != 0) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001620 /* the Array must be free by module which called this function */
1621 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1622 if (*ppArray == NULL) {
1623 weston_log("fails to allocate memory\n");
1624 return IVI_FAILED;
1625 }
1626
1627 wl_list_for_each(ivisurf, &layout->surface_list, link) {
1628 (*ppArray)[n++] = ivisurf;
1629 }
1630 }
1631
1632 *pLength = length;
1633
1634 return IVI_SUCCEEDED;
1635}
1636
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001637static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001638ivi_layout_get_surfaces_on_layer(struct ivi_layout_layer *ivilayer,
1639 int32_t *pLength,
1640 struct ivi_layout_surface ***ppArray)
1641{
1642 struct ivi_layout_surface *ivisurf = NULL;
1643 int32_t length = 0;
1644 int32_t n = 0;
1645
1646 if (ivilayer == NULL || pLength == NULL || ppArray == NULL) {
1647 weston_log("ivi_layout_getSurfaceIDsOnLayer: invalid argument\n");
1648 return IVI_FAILED;
1649 }
1650
1651 length = wl_list_length(&ivilayer->order.surface_list);
1652
1653 if (length != 0) {
1654 /* the Array must be free by module which called this function */
1655 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1656 if (*ppArray == NULL) {
1657 weston_log("fails to allocate memory\n");
1658 return IVI_FAILED;
1659 }
1660
1661 wl_list_for_each(ivisurf, &ivilayer->order.surface_list, order.link) {
1662 (*ppArray)[n++] = ivisurf;
1663 }
1664 }
1665
1666 *pLength = length;
1667
1668 return IVI_SUCCEEDED;
1669}
1670
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001671static struct ivi_layout_layer *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001672ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1673 int32_t width, int32_t height)
1674{
1675 struct ivi_layout *layout = get_instance();
1676 struct ivi_layout_layer *ivilayer = NULL;
1677
1678 ivilayer = get_layer(&layout->layer_list, id_layer);
1679 if (ivilayer != NULL) {
1680 weston_log("id_layer is already created\n");
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001681 ++ivilayer->ref_count;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001682 return ivilayer;
1683 }
1684
1685 ivilayer = calloc(1, sizeof *ivilayer);
1686 if (ivilayer == NULL) {
1687 weston_log("fails to allocate memory\n");
1688 return NULL;
1689 }
1690
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001691 ivilayer->ref_count = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001692 wl_signal_init(&ivilayer->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001693 ivilayer->layout = layout;
1694 ivilayer->id_layer = id_layer;
1695
1696 init_layer_properties(&ivilayer->prop, width, height);
1697 ivilayer->event_mask = 0;
1698
1699 wl_list_init(&ivilayer->pending.surface_list);
1700 wl_list_init(&ivilayer->pending.link);
1701 ivilayer->pending.prop = ivilayer->prop;
1702
1703 wl_list_init(&ivilayer->order.surface_list);
1704 wl_list_init(&ivilayer->order.link);
1705
1706 wl_list_insert(&layout->layer_list, &ivilayer->link);
1707
1708 wl_signal_emit(&layout->layer_notification.created, ivilayer);
1709
1710 return ivilayer;
1711}
1712
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001713static void
Nobuhiko Tanibataef6c7862014-12-15 13:20:44 +09001714ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1715{
1716 if (ivilayer == NULL) {
1717 weston_log("ivi_layout_layer_remove_notification: invalid argument\n");
1718 return;
1719 }
1720
1721 remove_all_notification(&ivilayer->property_changed.listener_list);
1722}
1723
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001724static void
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09001725ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1726 layer_property_notification_func callback,
1727 void *userdata)
1728{
1729 if (ivilayer == NULL) {
1730 weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1731 return;
1732 }
1733
1734 remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1735}
1736
1737static void
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09001738ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001739{
1740 struct ivi_layout *layout = get_instance();
1741
1742 if (ivilayer == NULL) {
1743 weston_log("ivi_layout_layer_remove: invalid argument\n");
1744 return;
1745 }
1746
Nobuhiko Tanibata4b601e12015-06-22 15:31:16 +09001747 if (--ivilayer->ref_count > 0)
1748 return;
1749
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001750 wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1751
1752 clear_surface_pending_list(ivilayer);
1753 clear_surface_order_list(ivilayer);
1754
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001755 wl_list_remove(&ivilayer->pending.link);
1756 wl_list_remove(&ivilayer->order.link);
1757 wl_list_remove(&ivilayer->link);
1758
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001759 ivi_layout_layer_remove_notification(ivilayer);
1760
1761 free(ivilayer);
1762}
1763
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001764int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001765ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1766 bool newVisibility)
1767{
1768 struct ivi_layout_layer_properties *prop = NULL;
1769
1770 if (ivilayer == NULL) {
1771 weston_log("ivi_layout_layer_set_visibility: invalid argument\n");
1772 return IVI_FAILED;
1773 }
1774
1775 prop = &ivilayer->pending.prop;
1776 prop->visibility = newVisibility;
1777
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001778 if (ivilayer->prop.visibility != newVisibility)
1779 ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1780 else
1781 ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001782
1783 return IVI_SUCCEEDED;
1784}
1785
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001786int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001787ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1788 wl_fixed_t opacity)
1789{
1790 struct ivi_layout_layer_properties *prop = NULL;
1791
Nobuhiko Tanibata7bbacc62015-06-22 15:30:09 +09001792 if (ivilayer == NULL ||
1793 opacity < wl_fixed_from_double(0.0) ||
1794 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001795 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1796 return IVI_FAILED;
1797 }
1798
1799 prop = &ivilayer->pending.prop;
1800 prop->opacity = opacity;
1801
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001802 if (ivilayer->prop.opacity != opacity)
1803 ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1804 else
1805 ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001806
1807 return IVI_SUCCEEDED;
1808}
1809
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001810static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001811ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1812 int32_t x, int32_t y,
1813 int32_t width, int32_t height)
1814{
1815 struct ivi_layout_layer_properties *prop = NULL;
1816
1817 if (ivilayer == NULL) {
1818 weston_log("ivi_layout_layer_set_source_rectangle: invalid argument\n");
1819 return IVI_FAILED;
1820 }
1821
1822 prop = &ivilayer->pending.prop;
1823 prop->source_x = x;
1824 prop->source_y = y;
1825 prop->source_width = width;
1826 prop->source_height = height;
1827
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001828 if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1829 ivilayer->prop.source_width != width ||
1830 ivilayer->prop.source_height != height)
1831 ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1832 else
1833 ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001834
1835 return IVI_SUCCEEDED;
1836}
1837
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001838int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001839ivi_layout_layer_set_destination_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_destination_rectangle: invalid argument\n");
1847 return IVI_FAILED;
1848 }
1849
1850 prop = &ivilayer->pending.prop;
1851 prop->dest_x = x;
1852 prop->dest_y = y;
1853 prop->dest_width = width;
1854 prop->dest_height = height;
1855
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001856 if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1857 ivilayer->prop.dest_width != width ||
1858 ivilayer->prop.dest_height != height)
1859 ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1860 else
1861 ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_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_orientation(struct ivi_layout_layer *ivilayer,
1868 enum wl_output_transform orientation)
1869{
1870 struct ivi_layout_layer_properties *prop = NULL;
1871
1872 if (ivilayer == NULL) {
1873 weston_log("ivi_layout_layer_set_orientation: invalid argument\n");
1874 return IVI_FAILED;
1875 }
1876
1877 prop = &ivilayer->pending.prop;
1878 prop->orientation = orientation;
1879
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001880 if (ivilayer->prop.orientation != orientation)
1881 ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1882 else
1883 ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001884
1885 return IVI_SUCCEEDED;
1886}
1887
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001888int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001889ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1890 struct ivi_layout_surface **pSurface,
1891 int32_t number)
1892{
1893 struct ivi_layout *layout = get_instance();
1894 struct ivi_layout_surface *ivisurf = NULL;
1895 struct ivi_layout_surface *next = NULL;
1896 uint32_t *id_surface = NULL;
1897 int32_t i = 0;
1898
1899 if (ivilayer == NULL) {
1900 weston_log("ivi_layout_layer_set_render_order: invalid argument\n");
1901 return IVI_FAILED;
1902 }
1903
Ucan, Emre (ADITG/SW1)c2be6382015-08-19 11:25:01 +00001904 clear_surface_pending_list(ivilayer);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001905
1906 for (i = 0; i < number; i++) {
1907 id_surface = &pSurface[i]->id_surface;
1908
1909 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
1910 if (*id_surface != ivisurf->id_surface) {
1911 continue;
1912 }
1913
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00001914 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001915 wl_list_insert(&ivilayer->pending.surface_list,
1916 &ivisurf->pending.link);
1917 break;
1918 }
1919 }
1920
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00001921 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001922
1923 return IVI_SUCCEEDED;
1924}
1925
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001926int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001927ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1928 bool newVisibility)
1929{
1930 struct ivi_layout_surface_properties *prop = NULL;
1931
1932 if (ivisurf == NULL) {
1933 weston_log("ivi_layout_surface_set_visibility: invalid argument\n");
1934 return IVI_FAILED;
1935 }
1936
1937 prop = &ivisurf->pending.prop;
1938 prop->visibility = newVisibility;
1939
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001940 if (ivisurf->prop.visibility != newVisibility)
1941 ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1942 else
1943 ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001944
1945 return IVI_SUCCEEDED;
1946}
1947
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001948int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001949ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1950 wl_fixed_t opacity)
1951{
1952 struct ivi_layout_surface_properties *prop = NULL;
1953
Nobuhiko Tanibataa86226c2015-06-22 15:29:20 +09001954 if (ivisurf == NULL ||
1955 opacity < wl_fixed_from_double(0.0) ||
1956 wl_fixed_from_double(1.0) < opacity) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001957 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1958 return IVI_FAILED;
1959 }
1960
1961 prop = &ivisurf->pending.prop;
1962 prop->opacity = opacity;
1963
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001964 if (ivisurf->prop.opacity != opacity)
1965 ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
1966 else
1967 ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001968
1969 return IVI_SUCCEEDED;
1970}
1971
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001972int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09001973ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1974 int32_t x, int32_t y,
1975 int32_t width, int32_t height)
1976{
1977 struct ivi_layout_surface_properties *prop = NULL;
1978
1979 if (ivisurf == NULL) {
1980 weston_log("ivi_layout_surface_set_destination_rectangle: invalid argument\n");
1981 return IVI_FAILED;
1982 }
1983
1984 prop = &ivisurf->pending.prop;
1985 prop->start_x = prop->dest_x;
1986 prop->start_y = prop->dest_y;
1987 prop->dest_x = x;
1988 prop->dest_y = y;
1989 prop->start_width = prop->dest_width;
1990 prop->start_height = prop->dest_height;
1991 prop->dest_width = width;
1992 prop->dest_height = height;
1993
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09001994 if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
1995 ivisurf->prop.dest_width != width ||
1996 ivisurf->prop.dest_height != height)
1997 ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1998 else
1999 ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002000
2001 return IVI_SUCCEEDED;
2002}
2003
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002004static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002005ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
2006 enum wl_output_transform orientation)
2007{
2008 struct ivi_layout_surface_properties *prop = NULL;
2009
2010 if (ivisurf == NULL) {
2011 weston_log("ivi_layout_surface_set_orientation: invalid argument\n");
2012 return IVI_FAILED;
2013 }
2014
2015 prop = &ivisurf->pending.prop;
2016 prop->orientation = orientation;
2017
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002018 if (ivisurf->prop.orientation != orientation)
2019 ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
2020 else
2021 ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002022
2023 return IVI_SUCCEEDED;
2024}
2025
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002026static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002027ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
2028 struct ivi_layout_layer *addlayer)
2029{
2030 struct ivi_layout *layout = get_instance();
2031 struct ivi_layout_layer *ivilayer = NULL;
2032 struct ivi_layout_layer *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002033
2034 if (iviscrn == NULL || addlayer == NULL) {
2035 weston_log("ivi_layout_screen_add_layer: invalid argument\n");
2036 return IVI_FAILED;
2037 }
2038
Ucan, Emre (ADITG/SW1)bb4ec0a2015-08-28 12:59:01 +00002039 if (addlayer->on_screen == iviscrn) {
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002040 weston_log("ivi_layout_screen_add_layer: addlayer is already available\n");
2041 return IVI_SUCCEEDED;
2042 }
2043
2044 wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
2045 if (ivilayer->id_layer == addlayer->id_layer) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002046 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002047 wl_list_insert(&iviscrn->pending.layer_list,
2048 &ivilayer->pending.link);
2049 break;
2050 }
2051 }
2052
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002053 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002054
2055 return IVI_SUCCEEDED;
2056}
2057
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002058static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002059ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2060 struct ivi_layout_layer **pLayer,
2061 const int32_t number)
2062{
2063 struct ivi_layout *layout = get_instance();
2064 struct ivi_layout_layer *ivilayer = NULL;
2065 struct ivi_layout_layer *next = NULL;
2066 uint32_t *id_layer = NULL;
2067 int32_t i = 0;
2068
2069 if (iviscrn == NULL) {
2070 weston_log("ivi_layout_screen_set_render_order: invalid argument\n");
2071 return IVI_FAILED;
2072 }
2073
2074 wl_list_for_each_safe(ivilayer, next,
2075 &iviscrn->pending.layer_list, pending.link) {
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002076 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002077 wl_list_init(&ivilayer->pending.link);
2078 }
2079
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002080 assert(wl_list_empty(&iviscrn->pending.layer_list));
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002081
2082 for (i = 0; i < number; i++) {
2083 id_layer = &pLayer[i]->id_layer;
2084 wl_list_for_each(ivilayer, &layout->layer_list, link) {
2085 if (*id_layer != ivilayer->id_layer) {
2086 continue;
2087 }
2088
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002089 wl_list_remove(&ivilayer->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002090 wl_list_insert(&iviscrn->pending.layer_list,
2091 &ivilayer->pending.link);
2092 break;
2093 }
2094 }
2095
Ucan, Emre (ADITG/SW1)174257b2015-08-20 14:13:30 +00002096 iviscrn->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002097
2098 return IVI_SUCCEEDED;
2099}
2100
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002101static struct weston_output *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002102ivi_layout_screen_get_output(struct ivi_layout_screen *iviscrn)
2103{
2104 return iviscrn->output;
2105}
2106
2107/**
2108 * This function is used by the additional ivi-module because of dumping ivi_surface sceenshot.
2109 * The ivi-module, e.g. ivi-controller.so, is in wayland-ivi-extension of Genivi's Layer Management.
2110 * This function is used to get the result of drawing by clients.
2111 */
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002112static struct weston_surface *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002113ivi_layout_surface_get_weston_surface(struct ivi_layout_surface *ivisurf)
2114{
2115 return ivisurf != NULL ? ivisurf->surface : NULL;
2116}
2117
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002118static int32_t
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002119ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
2120 int32_t *width, int32_t *height,
2121 int32_t *stride)
2122{
2123 int32_t w;
2124 int32_t h;
2125 const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
2126
2127 if (ivisurf == NULL || ivisurf->surface == NULL) {
2128 weston_log("%s: invalid argument\n", __func__);
2129 return IVI_FAILED;
2130 }
2131
2132 weston_surface_get_content_size(ivisurf->surface, &w, &h);
2133
2134 if (width != NULL)
2135 *width = w;
2136
2137 if (height != NULL)
2138 *height = h;
2139
2140 if (stride != NULL)
2141 *stride = w * bytespp;
2142
2143 return IVI_SUCCEEDED;
2144}
2145
2146static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002147ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
2148 layer_property_notification_func callback,
2149 void *userdata)
2150{
2151 struct ivi_layout_notification_callback *prop_callback = NULL;
2152
2153 if (ivilayer == NULL || callback == NULL) {
2154 weston_log("ivi_layout_layer_add_notification: invalid argument\n");
2155 return IVI_FAILED;
2156 }
2157
2158 prop_callback = malloc(sizeof *prop_callback);
2159 if (prop_callback == NULL) {
2160 weston_log("fails to allocate memory\n");
2161 return IVI_FAILED;
2162 }
2163
2164 prop_callback->callback = callback;
2165 prop_callback->data = userdata;
2166
2167 return add_notification(&ivilayer->property_changed,
2168 layer_prop_changed,
2169 prop_callback);
2170}
2171
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002172static const struct ivi_layout_surface_properties *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002173ivi_layout_get_properties_of_surface(struct ivi_layout_surface *ivisurf)
2174{
2175 if (ivisurf == NULL) {
2176 weston_log("ivi_layout_get_properties_of_surface: invalid argument\n");
2177 return NULL;
2178 }
2179
2180 return &ivisurf->prop;
2181}
2182
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002183static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002184ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2185 struct ivi_layout_surface *addsurf)
2186{
2187 struct ivi_layout *layout = get_instance();
2188 struct ivi_layout_surface *ivisurf = NULL;
2189 struct ivi_layout_surface *next = NULL;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002190
2191 if (ivilayer == NULL || addsurf == NULL) {
2192 weston_log("ivi_layout_layer_add_surface: invalid argument\n");
2193 return IVI_FAILED;
2194 }
2195
Wataru Natsume9c926fe2016-03-03 19:56:09 +09002196 if (addsurf->on_layer == ivilayer)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002197 return IVI_SUCCEEDED;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002198
2199 wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2200 if (ivisurf->id_surface == addsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002201 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002202 wl_list_insert(&ivilayer->pending.surface_list,
2203 &ivisurf->pending.link);
2204 break;
2205 }
2206 }
2207
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002208 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002209
2210 return IVI_SUCCEEDED;
2211}
2212
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002213static void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002214ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2215 struct ivi_layout_surface *remsurf)
2216{
2217 struct ivi_layout_surface *ivisurf = NULL;
2218 struct ivi_layout_surface *next = NULL;
2219
2220 if (ivilayer == NULL || remsurf == NULL) {
2221 weston_log("ivi_layout_layer_remove_surface: invalid argument\n");
2222 return;
2223 }
2224
2225 wl_list_for_each_safe(ivisurf, next,
2226 &ivilayer->pending.surface_list, pending.link) {
2227 if (ivisurf->id_surface == remsurf->id_surface) {
Ucan, Emre (ADITG/SW1)cf34dc22015-08-20 14:13:33 +00002228 wl_list_remove(&ivisurf->pending.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002229 wl_list_init(&ivisurf->pending.link);
2230 break;
2231 }
2232 }
2233
Ucan, Emre (ADITG/SW1)38fcf382015-08-20 14:13:29 +00002234 ivilayer->order.dirty = 1;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002235}
2236
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002237static int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002238ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2239 int32_t x, int32_t y,
2240 int32_t width, int32_t height)
2241{
2242 struct ivi_layout_surface_properties *prop = NULL;
2243
2244 if (ivisurf == NULL) {
2245 weston_log("ivi_layout_surface_set_source_rectangle: invalid argument\n");
2246 return IVI_FAILED;
2247 }
2248
2249 prop = &ivisurf->pending.prop;
2250 prop->source_x = x;
2251 prop->source_y = y;
2252 prop->source_width = width;
2253 prop->source_height = height;
2254
Nobuhiko Tanibata5d4a3232015-06-22 15:32:14 +09002255 if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2256 ivisurf->prop.source_width != width ||
2257 ivisurf->prop.source_height != height)
2258 ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2259 else
2260 ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002261
2262 return IVI_SUCCEEDED;
2263}
2264
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002265int32_t
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002266ivi_layout_commit_changes(void)
2267{
2268 struct ivi_layout *layout = get_instance();
2269
2270 commit_surface_list(layout);
2271 commit_layer_list(layout);
2272 commit_screen_list(layout);
2273
2274 commit_transition(layout);
2275
2276 commit_changes(layout);
2277 send_prop(layout);
2278 weston_compositor_schedule_repaint(layout->compositor);
2279
2280 return IVI_SUCCEEDED;
2281}
2282
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002283static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002284ivi_layout_layer_set_transition(struct ivi_layout_layer *ivilayer,
2285 enum ivi_layout_transition_type type,
2286 uint32_t duration)
2287{
2288 if (ivilayer == NULL) {
2289 weston_log("%s: invalid argument\n", __func__);
2290 return -1;
2291 }
2292
2293 ivilayer->pending.prop.transition_type = type;
2294 ivilayer->pending.prop.transition_duration = duration;
2295
2296 return 0;
2297}
2298
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002299static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002300ivi_layout_layer_set_fade_info(struct ivi_layout_layer* ivilayer,
2301 uint32_t is_fade_in,
2302 double start_alpha, double end_alpha)
2303{
2304 if (ivilayer == NULL) {
2305 weston_log("%s: invalid argument\n", __func__);
2306 return -1;
2307 }
2308
2309 ivilayer->pending.prop.is_fade_in = is_fade_in;
2310 ivilayer->pending.prop.start_alpha = start_alpha;
2311 ivilayer->pending.prop.end_alpha = end_alpha;
2312
2313 return 0;
2314}
2315
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002316static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002317ivi_layout_surface_set_transition_duration(struct ivi_layout_surface *ivisurf,
2318 uint32_t duration)
2319{
2320 struct ivi_layout_surface_properties *prop;
2321
2322 if (ivisurf == NULL) {
2323 weston_log("%s: invalid argument\n", __func__);
2324 return -1;
2325 }
2326
2327 prop = &ivisurf->pending.prop;
2328 prop->transition_duration = duration*10;
2329 return 0;
2330}
2331
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002332static int32_t
Nobuhiko Tanibata3c6796f2014-12-15 13:20:58 +09002333ivi_layout_surface_set_transition(struct ivi_layout_surface *ivisurf,
2334 enum ivi_layout_transition_type type,
2335 uint32_t duration)
2336{
2337 struct ivi_layout_surface_properties *prop;
2338
2339 if (ivisurf == NULL) {
2340 weston_log("%s: invalid argument\n", __func__);
2341 return -1;
2342 }
2343
2344 prop = &ivisurf->pending.prop;
2345 prop->transition_type = type;
2346 prop->transition_duration = duration;
2347 return 0;
2348}
2349
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002350static int32_t
2351ivi_layout_surface_dump(struct weston_surface *surface,
2352 void *target, size_t size,int32_t x, int32_t y,
2353 int32_t width, int32_t height)
2354{
2355 int result = 0;
2356
2357 if (surface == NULL) {
2358 weston_log("%s: invalid argument\n", __func__);
2359 return IVI_FAILED;
2360 }
2361
2362 result = weston_surface_copy_content(
2363 surface, target, size,
2364 x, y, width, height);
2365
2366 return result == 0 ? IVI_SUCCEEDED : IVI_FAILED;
2367}
2368
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002369/**
2370 * methods of interaction between ivi-shell with ivi-layout
2371 */
2372struct weston_view *
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002373ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2374{
Dawid Gajownik74a635b2015-08-06 17:12:19 -03002375 if (surface == NULL)
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002376 return NULL;
2377
Ucan, Emre (ADITG/SW1)64635ee2015-08-28 12:59:06 +00002378 return get_weston_view(surface);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002379}
2380
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002381void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002382ivi_layout_surface_configure(struct ivi_layout_surface *ivisurf,
2383 int32_t width, int32_t height)
2384{
2385 struct ivi_layout *layout = get_instance();
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002386
Nobuhiko Tanibatae6cc9972015-04-27 16:54:01 +09002387 /* emit callback which is set by ivi-layout api user */
2388 wl_signal_emit(&layout->surface_notification.configure_changed,
2389 ivisurf);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002390}
2391
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002392struct ivi_layout_surface*
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002393ivi_layout_surface_create(struct weston_surface *wl_surface,
2394 uint32_t id_surface)
2395{
2396 struct ivi_layout *layout = get_instance();
2397 struct ivi_layout_surface *ivisurf = NULL;
2398 struct weston_view *tmpview = NULL;
2399
2400 if (wl_surface == NULL) {
2401 weston_log("ivi_layout_surface_create: invalid argument\n");
2402 return NULL;
2403 }
2404
2405 ivisurf = get_surface(&layout->surface_list, id_surface);
2406 if (ivisurf != NULL) {
2407 if (ivisurf->surface != NULL) {
2408 weston_log("id_surface(%d) is already created\n", id_surface);
2409 return NULL;
2410 }
2411 }
2412
2413 ivisurf = calloc(1, sizeof *ivisurf);
2414 if (ivisurf == NULL) {
2415 weston_log("fails to allocate memory\n");
2416 return NULL;
2417 }
2418
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002419 wl_signal_init(&ivisurf->property_changed);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002420 ivisurf->id_surface = id_surface;
2421 ivisurf->layout = layout;
2422
2423 ivisurf->surface = wl_surface;
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002424
2425 tmpview = weston_view_create(wl_surface);
2426 if (tmpview == NULL) {
2427 weston_log("fails to allocate memory\n");
2428 }
2429
2430 ivisurf->surface->width_from_buffer = 0;
2431 ivisurf->surface->height_from_buffer = 0;
2432
Nobuhiko Tanibata21deb282015-07-15 14:05:32 +09002433 weston_matrix_init(&ivisurf->transform.matrix);
2434 wl_list_init(&ivisurf->transform.link);
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002435
2436 init_surface_properties(&ivisurf->prop);
2437 ivisurf->event_mask = 0;
2438
2439 ivisurf->pending.prop = ivisurf->prop;
2440 wl_list_init(&ivisurf->pending.link);
2441
2442 wl_list_init(&ivisurf->order.link);
2443 wl_list_init(&ivisurf->order.layer_list);
2444
2445 wl_list_insert(&layout->surface_list, &ivisurf->link);
2446
2447 wl_signal_emit(&layout->surface_notification.created, ivisurf);
2448
2449 return ivisurf;
2450}
2451
Nobuhiko Tanibata28dc18c2014-12-15 13:22:31 +09002452void
Nobuhiko Tanibata6f9df652014-11-27 13:22:00 +09002453ivi_layout_init_with_compositor(struct weston_compositor *ec)
2454{
2455 struct ivi_layout *layout = get_instance();
2456
2457 layout->compositor = ec;
2458
2459 wl_list_init(&layout->surface_list);
2460 wl_list_init(&layout->layer_list);
2461 wl_list_init(&layout->screen_list);
2462
2463 wl_signal_init(&layout->layer_notification.created);
2464 wl_signal_init(&layout->layer_notification.removed);
2465
2466 wl_signal_init(&layout->surface_notification.created);
2467 wl_signal_init(&layout->surface_notification.removed);
2468 wl_signal_init(&layout->surface_notification.configure_changed);
2469
2470 /* Add layout_layer at the last of weston_compositor.layer_list */
2471 weston_layer_init(&layout->layout_layer, ec->layer_list.prev);
2472
2473 create_screen(ec);
2474
2475 layout->transitions = ivi_layout_transition_set_create(ec);
2476 wl_list_init(&layout->pending_transition_list);
2477}
2478
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002479static struct ivi_layout_interface ivi_layout_interface = {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002480 /**
2481 * commit all changes
2482 */
2483 .commit_changes = ivi_layout_commit_changes,
2484
2485 /**
2486 * surface controller interfaces
2487 */
2488 .add_notification_create_surface = ivi_layout_add_notification_create_surface,
2489 .remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
2490 .add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
2491 .remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
2492 .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
2493 .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
2494 .get_surfaces = ivi_layout_get_surfaces,
2495 .get_id_of_surface = ivi_layout_get_id_of_surface,
2496 .get_surface_from_id = ivi_layout_get_surface_from_id,
2497 .get_properties_of_surface = ivi_layout_get_properties_of_surface,
2498 .get_surfaces_on_layer = ivi_layout_get_surfaces_on_layer,
2499 .surface_set_visibility = ivi_layout_surface_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002500 .surface_set_opacity = ivi_layout_surface_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002501 .surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
2502 .surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002503 .surface_set_orientation = ivi_layout_surface_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002504 .surface_add_notification = ivi_layout_surface_add_notification,
2505 .surface_remove_notification = ivi_layout_surface_remove_notification,
2506 .surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
2507 .surface_set_transition = ivi_layout_surface_set_transition,
2508 .surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
2509
2510 /**
2511 * layer controller interfaces
2512 */
2513 .add_notification_create_layer = ivi_layout_add_notification_create_layer,
2514 .remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
2515 .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
2516 .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
2517 .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
Nobuhiko Tanibata3aa8aed2015-06-22 15:32:23 +09002518 .layer_destroy = ivi_layout_layer_destroy,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002519 .get_layers = ivi_layout_get_layers,
2520 .get_id_of_layer = ivi_layout_get_id_of_layer,
2521 .get_layer_from_id = ivi_layout_get_layer_from_id,
2522 .get_properties_of_layer = ivi_layout_get_properties_of_layer,
2523 .get_layers_under_surface = ivi_layout_get_layers_under_surface,
2524 .get_layers_on_screen = ivi_layout_get_layers_on_screen,
2525 .layer_set_visibility = ivi_layout_layer_set_visibility,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002526 .layer_set_opacity = ivi_layout_layer_set_opacity,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002527 .layer_set_source_rectangle = ivi_layout_layer_set_source_rectangle,
2528 .layer_set_destination_rectangle = ivi_layout_layer_set_destination_rectangle,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002529 .layer_set_orientation = ivi_layout_layer_set_orientation,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002530 .layer_add_surface = ivi_layout_layer_add_surface,
2531 .layer_remove_surface = ivi_layout_layer_remove_surface,
2532 .layer_set_render_order = ivi_layout_layer_set_render_order,
2533 .layer_add_notification = ivi_layout_layer_add_notification,
2534 .layer_remove_notification = ivi_layout_layer_remove_notification,
2535 .layer_set_transition = ivi_layout_layer_set_transition,
2536
2537 /**
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002538 * screen controller interfaces part1
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002539 */
2540 .get_screen_from_id = ivi_layout_get_screen_from_id,
2541 .get_screen_resolution = ivi_layout_get_screen_resolution,
2542 .get_screens = ivi_layout_get_screens,
2543 .get_screens_under_layer = ivi_layout_get_screens_under_layer,
2544 .screen_add_layer = ivi_layout_screen_add_layer,
2545 .screen_set_render_order = ivi_layout_screen_set_render_order,
2546 .screen_get_output = ivi_layout_screen_get_output,
2547
2548 /**
2549 * animation
2550 */
2551 .transition_move_layer_cancel = ivi_layout_transition_move_layer_cancel,
Nobuhiko Tanibatac3fd6242015-04-21 02:13:15 +09002552 .layer_set_fade_info = ivi_layout_layer_set_fade_info,
2553
2554 /**
2555 * surface content dumping for debugging
2556 */
2557 .surface_get_size = ivi_layout_surface_get_size,
2558 .surface_dump = ivi_layout_surface_dump,
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002559
2560 /**
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002561 * remove notification by callback on property changes of ivi_surface/layer
Nobuhiko Tanibata82051702015-06-22 15:31:26 +09002562 */
Nobuhiko Tanibatadb8efd12015-06-22 15:31:39 +09002563 .surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
Nobuhiko Tanibata4d0116e2015-06-22 15:31:57 +09002564 .layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback,
2565
2566 /**
2567 * screen controller interfaces part2
2568 */
2569 .get_id_of_screen = ivi_layout_get_id_of_screen
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002570};
2571
2572int
2573load_controller_modules(struct weston_compositor *compositor, const char *modules,
2574 int *argc, char *argv[])
2575{
2576 const char *p, *end;
2577 char buffer[256];
2578 int (*controller_module_init)(struct weston_compositor *compositor,
2579 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002580 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002581 size_t interface_version);
2582
2583 if (modules == NULL)
2584 return 0;
2585
2586 p = modules;
2587 while (*p) {
2588 end = strchrnul(p, ',');
2589 snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
2590
2591 controller_module_init = weston_load_module(buffer, "controller_module_init");
Pekka Paalanen97246c02015-03-26 15:47:29 +02002592 if (!controller_module_init)
2593 return -1;
2594
2595 if (controller_module_init(compositor, argc, argv,
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002596 &ivi_layout_interface,
2597 sizeof(struct ivi_layout_interface)) != 0) {
Pekka Paalanen97246c02015-03-26 15:47:29 +02002598 weston_log("ivi-shell: Initialization of controller module fails");
2599 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002600 }
2601
2602 p = end;
2603 while (*p == ',')
2604 p++;
2605 }
2606
2607 return 0;
2608}