Migrate IVI-Shell backport to Weston 1.8.0 (Yocto 2.0)
[AGL/meta-agl.git] / meta-ivi-common / recipes-graphics / wayland / weston-ivi-shell / 0001-IVI-Shell-Backport-from-Weston-1.9.0-to-1.8.0.patch
1 From fb20221f0c0068a4a75fe62f2873d9d3c5566e73 Mon Sep 17 00:00:00 2001
2 From: Manuel Bachmann <manuel.bachmann@iot.bzh>
3 Date: Wed, 13 Jan 2016 18:42:26 +0100
4 Subject: [PATCH] [PATCH] Backport IVI-Shell from Weston 1.9.0 to 1.8.0
5
6 IVI-Shell is the alternative Weston shell implementing the
7 eponymous protocol, and supported in client toolkits such
8 as EFL, Qt...
9
10 We backport only what is necessary, without modifying core
11 compositor code.
12
13 Signed-off-by: Manuel Bachmann <manuel.bachmann@iot.bzh>
14 ---
15  ivi-shell/hmi-controller.c        | 140 +++---
16  ivi-shell/input-panel-ivi.c       |  41 +-
17  ivi-shell/ivi-layout-export.h     |  58 ++-
18  ivi-shell/ivi-layout-private.h    |  47 +-
19  ivi-shell/ivi-layout-transition.c |  39 +-
20  ivi-shell/ivi-layout.c            | 983 +++++++++++++++++++-------------------
21  ivi-shell/ivi-shell.c             |  91 ++--
22  ivi-shell/ivi-shell.h             |  37 +-
23  8 files changed, 758 insertions(+), 678 deletions(-)
24
25 diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
26 index 88e9333..2f18217 100644
27 --- a/ivi-shell/hmi-controller.c
28 +++ b/ivi-shell/hmi-controller.c
29 @@ -1,23 +1,26 @@
30  /*
31   * Copyright (C) 2014 DENSO CORPORATION
32   *
33 - * Permission to use, copy, modify, distribute, and sell this software and
34 - * its documentation for any purpose is hereby granted without fee, provided
35 - * that the above copyright notice appear in all copies and that both that
36 - * copyright notice and this permission notice appear in supporting
37 - * documentation, and that the name of the copyright holders not be used in
38 - * advertising or publicity pertaining to distribution of the software
39 - * without specific, written prior permission.  The copyright holders make
40 - * no representations about the suitability of this software for any
41 - * purpose.  It is provided "as is" without express or implied warranty.
42 + * Permission is hereby granted, free of charge, to any person obtaining
43 + * a copy of this software and associated documentation files (the
44 + * "Software"), to deal in the Software without restriction, including
45 + * without limitation the rights to use, copy, modify, merge, publish,
46 + * distribute, sublicense, and/or sell copies of the Software, and to
47 + * permit persons to whom the Software is furnished to do so, subject to
48 + * the following conditions:
49   *
50 - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
51 - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
52 - * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
53 - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
54 - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
55 - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
56 - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
57 + * The above copyright notice and this permission notice (including the
58 + * next paragraph) shall be included in all copies or substantial
59 + * portions of the Software.
60 + *
61 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
62 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
63 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
64 + * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
65 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
66 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
67 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
68 + * SOFTWARE.
69   */
70  
71  /**
72 @@ -721,27 +724,9 @@ hmi_controller_create(struct weston_compositor *ec)
73         ivi_controller_interface->layer_set_visibility(
74                 hmi_ctrl->workspace_background_layer.ivilayer, false);
75  
76 -       /* init workspace ivi_layer */
77 -       hmi_ctrl->workspace_layer.x = hmi_ctrl->workspace_background_layer.x;
78 -       hmi_ctrl->workspace_layer.y = hmi_ctrl->workspace_background_layer.y;
79 -       hmi_ctrl->workspace_layer.width =
80 -               hmi_ctrl->workspace_background_layer.width;
81 -       hmi_ctrl->workspace_layer.height =
82 -               hmi_ctrl->workspace_background_layer.height;
83 -       hmi_ctrl->workspace_layer.id_layer =
84 -               hmi_ctrl->hmi_setting->workspace_layer_id;
85 -
86 -       create_layer(iviscrn, &hmi_ctrl->workspace_layer);
87 -       ivi_controller_interface->layer_set_opacity(hmi_ctrl->workspace_layer.ivilayer, 0);
88 -       ivi_controller_interface->layer_set_visibility(hmi_ctrl->workspace_layer.ivilayer,
89 -                                       false);
90  
91         wl_list_init(&hmi_ctrl->workspace_fade.layer_list);
92         tmp_link_layer = MEM_ALLOC(sizeof(*tmp_link_layer));
93 -       tmp_link_layer->layout_layer = hmi_ctrl->workspace_layer.ivilayer;
94 -       wl_list_insert(&hmi_ctrl->workspace_fade.layer_list,
95 -                      &tmp_link_layer->link);
96 -       tmp_link_layer = MEM_ALLOC(sizeof(*tmp_link_layer));
97         tmp_link_layer->layout_layer =
98                 hmi_ctrl->workspace_background_layer.ivilayer;
99         wl_list_insert(&hmi_ctrl->workspace_fade.layer_list,
100 @@ -976,12 +961,11 @@ static void
101  ivi_hmi_controller_add_launchers(struct hmi_controller *hmi_ctrl,
102                                  int32_t icon_size)
103  {
104 -       struct ivi_layout_layer *layer = hmi_ctrl->workspace_layer.ivilayer;
105         int32_t minspace_x = 10;
106         int32_t minspace_y = minspace_x;
107  
108 -       int32_t width  = hmi_ctrl->workspace_layer.width;
109 -       int32_t height = hmi_ctrl->workspace_layer.height;
110 +       int32_t width  = hmi_ctrl->workspace_background_layer.width;
111 +       int32_t height = hmi_ctrl->workspace_background_layer.height;
112  
113         int32_t x_count = (width - minspace_x) / (minspace_x + icon_size);
114         int32_t space_x = (int32_t)((width - x_count * icon_size) / (1.0 + x_count));
115 @@ -1011,6 +995,11 @@ ivi_hmi_controller_add_launchers(struct hmi_controller *hmi_ctrl,
116         struct ivi_layout_surface* layout_surface = NULL;
117         uint32_t *add_surface_id = NULL;
118  
119 +       struct ivi_layout_screen *iviscrn = NULL;
120 +       struct link_layer *tmp_link_layer = NULL;
121 +       struct ivi_layout_screen **pp_screen = NULL;
122 +       int32_t screen_length  = 0;
123 +
124         if (0 == x_count)
125                 x_count = 1;
126  
127 @@ -1087,16 +1076,10 @@ ivi_hmi_controller_add_launchers(struct hmi_controller *hmi_ctrl,
128                         ivi_controller_interface->get_surface_from_id(data->surface_id);
129                 assert(layout_surface);
130  
131 -               ret = ivi_controller_interface->layer_add_surface(layer, layout_surface);
132 -               assert(!ret);
133 -
134                 ret = ivi_controller_interface->surface_set_destination_rectangle(
135                                 layout_surface, x, y, icon_size, icon_size);
136                 assert(!ret);
137  
138 -               ret = ivi_controller_interface->surface_set_visibility(layout_surface, true);
139 -               assert(!ret);
140 -
141                 nx++;
142  
143                 if (x_count == nx) {
144 @@ -1105,6 +1088,43 @@ ivi_hmi_controller_add_launchers(struct hmi_controller *hmi_ctrl,
145                 }
146         }
147  
148 +       /* init workspace ivi_layer */
149 +       hmi_ctrl->workspace_layer.x = hmi_ctrl->workspace_background_layer.x;
150 +       hmi_ctrl->workspace_layer.y = hmi_ctrl->workspace_background_layer.y;
151 +       hmi_ctrl->workspace_layer.width =
152 +               hmi_ctrl->workspace_background_layer.width * hmi_ctrl->workspace_count;
153 +       hmi_ctrl->workspace_layer.height =
154 +               hmi_ctrl->workspace_background_layer.height;
155 +       hmi_ctrl->workspace_layer.id_layer =
156 +               hmi_ctrl->hmi_setting->workspace_layer_id;
157 +
158 +       ivi_controller_interface->get_screens(&screen_length, &pp_screen);
159 +       iviscrn = pp_screen[0];
160 +       free(pp_screen);
161 +       create_layer(iviscrn, &hmi_ctrl->workspace_layer);
162 +       ivi_controller_interface->layer_set_opacity(hmi_ctrl->workspace_layer.ivilayer, 0);
163 +       ivi_controller_interface->layer_set_visibility(hmi_ctrl->workspace_layer.ivilayer,
164 +                                       false);
165 +
166 +       tmp_link_layer = MEM_ALLOC(sizeof(*tmp_link_layer));
167 +       tmp_link_layer->layout_layer = hmi_ctrl->workspace_layer.ivilayer;
168 +       wl_list_insert(&hmi_ctrl->workspace_fade.layer_list,
169 +                      &tmp_link_layer->link);
170 +
171 +       /* Add surface to layer */
172 +       wl_array_for_each(data, &launchers) {
173 +               layout_surface =
174 +                       ivi_controller_interface->get_surface_from_id(data->surface_id);
175 +               assert(layout_surface);
176 +
177 +               ret = ivi_controller_interface->layer_add_surface(hmi_ctrl->workspace_layer.ivilayer,
178 +                                                                 layout_surface);
179 +               assert(!ret);
180 +
181 +               ret = ivi_controller_interface->surface_set_visibility(layout_surface, true);
182 +               assert(!ret);
183 +       }
184 +
185         wl_array_release(&launchers);
186         ivi_controller_interface->commit_changes();
187  }
188 @@ -1266,8 +1286,8 @@ move_workspace_grab_end(struct move_grab *move, struct wl_resource* resource,
189                                         duration);
190         ivi_controller_interface->layer_set_destination_rectangle(layer,
191                                 end_pos, pos_y,
192 -                               hmi_ctrl->workspace_background_layer.width,
193 -                               hmi_ctrl->workspace_background_layer.height);
194 +                               hmi_ctrl->workspace_layer.width,
195 +                               hmi_ctrl->workspace_layer.height);
196         ivi_controller_interface->commit_changes();
197  }
198  
199 @@ -1465,15 +1485,18 @@ enum HMI_GRAB_DEVICE {
200  static enum HMI_GRAB_DEVICE
201  get_hmi_grab_device(struct weston_seat *seat, uint32_t serial)
202  {
203 -       if (seat->pointer &&
204 -           seat->pointer->focus &&
205 -           seat->pointer->button_count &&
206 -           seat->pointer->grab_serial == serial)
207 +       struct weston_pointer *pointer = seat->pointer;
208 +       struct weston_touch *touch = seat->touch;
209 +
210 +       if (pointer &&
211 +           pointer->focus &&
212 +           pointer->button_count &&
213 +           pointer->grab_serial == serial)
214                 return HMI_GRAB_DEVICE_POINTER;
215  
216 -       if (seat->touch &&
217 -           seat->touch->focus &&
218 -           seat->touch->grab_serial == serial)
219 +       if (touch &&
220 +           touch->focus &&
221 +           touch->grab_serial == serial)
222                 return HMI_GRAB_DEVICE_TOUCH;
223  
224         return HMI_GRAB_DEVICE_NONE;
225 @@ -1564,6 +1587,9 @@ ivi_hmi_controller_workspace_control(struct wl_client *client,
226         struct pointer_move_grab *pnt_move_grab = NULL;
227         struct touch_move_grab *tch_move_grab = NULL;
228         struct weston_seat *seat = NULL;
229 +       struct weston_pointer *pointer;
230 +       struct weston_touch *touch;
231 +
232         enum HMI_GRAB_DEVICE device;
233  
234         if (hmi_ctrl->workspace_count < 2)
235 @@ -1582,21 +1608,23 @@ ivi_hmi_controller_workspace_control(struct wl_client *client,
236  
237         switch (device) {
238         case HMI_GRAB_DEVICE_POINTER:
239 -               pnt_move_grab = create_workspace_pointer_move(seat->pointer,
240 +               pointer = seat->pointer;
241 +               pnt_move_grab = create_workspace_pointer_move(pointer,
242                                                               resource);
243  
244                 pointer_grab_start(&pnt_move_grab->base, layer,
245                                    &pointer_move_grab_workspace_interface,
246 -                                  seat->pointer);
247 +                                  pointer);
248                 break;
249  
250         case HMI_GRAB_DEVICE_TOUCH:
251 -               tch_move_grab = create_workspace_touch_move(seat->touch,
252 +               touch = seat->touch;
253 +               tch_move_grab = create_workspace_touch_move(touch,
254                                                             resource);
255  
256                 touch_grab_start(&tch_move_grab->base, layer,
257                                  &touch_move_grab_workspace_interface,
258 -                                seat->touch);
259 +                                touch);
260                 break;
261  
262         default:
263 diff --git a/ivi-shell/input-panel-ivi.c b/ivi-shell/input-panel-ivi.c
264 index 6b89177..3eefb68 100644
265 --- a/ivi-shell/input-panel-ivi.c
266 +++ b/ivi-shell/input-panel-ivi.c
267 @@ -3,23 +3,26 @@
268   * Copyright Â© 2011-2012 Collabora, Ltd.
269   * Copyright Â© 2013 Raspberry Pi Foundation
270   *
271 - * Permission to use, copy, modify, distribute, and sell this software and
272 - * its documentation for any purpose is hereby granted without fee, provided
273 - * that the above copyright notice appear in all copies and that both that
274 - * copyright notice and this permission notice appear in supporting
275 - * documentation, and that the name of the copyright holders not be used in
276 - * advertising or publicity pertaining to distribution of the software
277 - * without specific, written prior permission.  The copyright holders make
278 - * no representations about the suitability of this software for any
279 - * purpose.  It is provided "as is" without express or implied warranty.
280 + * Permission is hereby granted, free of charge, to any person obtaining
281 + * a copy of this software and associated documentation files (the
282 + * "Software"), to deal in the Software without restriction, including
283 + * without limitation the rights to use, copy, modify, merge, publish,
284 + * distribute, sublicense, and/or sell copies of the Software, and to
285 + * permit persons to whom the Software is furnished to do so, subject to
286 + * the following conditions:
287   *
288 - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
289 - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
290 - * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
291 - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
292 - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
293 - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
294 - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
295 + * The above copyright notice and this permission notice (including the
296 + * next paragraph) shall be included in all copies or substantial
297 + * portions of the Software.
298 + *
299 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
300 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
301 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
302 + * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
303 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
304 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
305 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
306 + * SOFTWARE.
307   */
308  
309  #include "config.h"
310 @@ -66,9 +69,11 @@ show_input_panel_surface(struct input_panel_surface *ipsurf)
311         float x, y;
312  
313         wl_list_for_each(seat, &shell->compositor->seat_list, link) {
314 -               if (!seat->keyboard || !seat->keyboard->focus)
315 +               struct weston_keyboard *keyboard = seat->keyboard;
316 +
317 +               if (!keyboard || !keyboard->focus)
318                         continue;
319 -               focus = weston_surface_get_main_surface(seat->keyboard->focus);
320 +               focus = weston_surface_get_main_surface(keyboard->focus);
321                 ipsurf->output = focus->output;
322                 x = ipsurf->output->x + (ipsurf->output->width - ipsurf->surface->width) / 2;
323                 y = ipsurf->output->y + ipsurf->output->height - ipsurf->surface->height;
324 diff --git a/ivi-shell/ivi-layout-export.h b/ivi-shell/ivi-layout-export.h
325 index 4b4328c..8a92009 100644
326 --- a/ivi-shell/ivi-layout-export.h
327 +++ b/ivi-shell/ivi-layout-export.h
328 @@ -1,23 +1,26 @@
329  /*
330   * Copyright (C) 2013 DENSO CORPORATION
331   *
332 - * Permission to use, copy, modify, distribute, and sell this software and
333 - * its documentation for any purpose is hereby granted without fee, provided
334 - * that the above copyright notice appear in all copies and that both that
335 - * copyright notice and this permission notice appear in supporting
336 - * documentation, and that the name of the copyright holders not be used in
337 - * advertising or publicity pertaining to distribution of the software
338 - * without specific, written prior permission.  The copyright holders make
339 - * no representations about the suitability of this software for any
340 - * purpose.  It is provided "as is" without express or implied warranty.
341 + * Permission is hereby granted, free of charge, to any person obtaining
342 + * a copy of this software and associated documentation files (the
343 + * "Software"), to deal in the Software without restriction, including
344 + * without limitation the rights to use, copy, modify, merge, publish,
345 + * distribute, sublicense, and/or sell copies of the Software, and to
346 + * permit persons to whom the Software is furnished to do so, subject to
347 + * the following conditions:
348   *
349 - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
350 - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
351 - * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
352 - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
353 - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
354 - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
355 - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
356 + * The above copyright notice and this permission notice (including the
357 + * next paragraph) shall be included in all copies or substantial
358 + * portions of the Software.
359 + *
360 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
361 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
362 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
363 + * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
364 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
365 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
366 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
367 + * SOFTWARE.
368   */
369  
370  /**
371 @@ -467,7 +470,7 @@ struct ivi_controller_interface {
372         /**
373          * \brief Removes a ivi_layer which is currently managed by the service
374          */
375 -       void (*layer_remove)(struct ivi_layout_layer *ivilayer);
376 +       void (*layer_destroy)(struct ivi_layout_layer *ivilayer);
377  
378         /**
379          * \brief Get all ivi_layers which are currently registered and managed
380 @@ -780,6 +783,27 @@ struct ivi_controller_interface {
381                                 int32_t x, int32_t y,
382                                 int32_t width, int32_t height);
383  
384 +       /**
385 +        * remove notification by callback on property changes of ivi_surface
386 +        */
387 +       void (*surface_remove_notification_by_callback)(struct ivi_layout_surface *ivisurf,
388 +                                                       surface_property_notification_func callback,
389 +                                                       void *userdata);
390 +
391 +       /**
392 +        * \brief remove notification by callback on property changes of ivi_layer
393 +        */
394 +       void (*layer_remove_notification_by_callback)(struct ivi_layout_layer *ivilayer,
395 +                                                     layer_property_notification_func callback,
396 +                                                     void *userdata);
397 +
398 +       /**
399 +        * \brief get id of ivi_screen from ivi_layout_screen
400 +        *
401 +        *
402 +        * \return id of ivi_screen
403 +        */
404 +       uint32_t (*get_id_of_screen)(struct ivi_layout_screen *iviscrn);
405  };
406  
407  #ifdef __cplusplus
408 diff --git a/ivi-shell/ivi-layout-private.h b/ivi-shell/ivi-layout-private.h
409 index 4531748..074d598 100644
410 --- a/ivi-shell/ivi-layout-private.h
411 +++ b/ivi-shell/ivi-layout-private.h
412 @@ -1,23 +1,26 @@
413  /*
414   * Copyright (C) 2014 DENSO CORPORATION
415   *
416 - * Permission to use, copy, modify, distribute, and sell this software and
417 - * its documentation for any purpose is hereby granted without fee, provided
418 - * that the above copyright notice appear in all copies and that both that
419 - * copyright notice and this permission notice appear in supporting
420 - * documentation, and that the name of the copyright holders not be used in
421 - * advertising or publicity pertaining to distribution of the software
422 - * without specific, written prior permission.  The copyright holders make
423 - * no representations about the suitability of this software for any
424 - * purpose.  It is provided "as is" without express or implied warranty.
425 + * Permission is hereby granted, free of charge, to any person obtaining
426 + * a copy of this software and associated documentation files (the
427 + * "Software"), to deal in the Software without restriction, including
428 + * without limitation the rights to use, copy, modify, merge, publish,
429 + * distribute, sublicense, and/or sell copies of the Software, and to
430 + * permit persons to whom the Software is furnished to do so, subject to
431 + * the following conditions:
432   *
433 - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
434 - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
435 - * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
436 - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
437 - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
438 - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
439 - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
440 + * The above copyright notice and this permission notice (including the
441 + * next paragraph) shall be included in all copies or substantial
442 + * portions of the Software.
443 + *
444 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
445 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
446 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
447 + * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
448 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
449 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
450 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
451 + * SOFTWARE.
452   */
453  
454  #ifndef _ivi_layout_PRIVATE_H_
455 @@ -36,12 +39,7 @@ struct ivi_layout_surface {
456         struct ivi_layout *layout;
457         struct weston_surface *surface;
458  
459 -       struct wl_listener surface_destroy_listener;
460 -       struct weston_transform surface_rotation;
461 -       struct weston_transform layer_rotation;
462 -       struct weston_transform surface_pos;
463 -       struct weston_transform layer_pos;
464 -       struct weston_transform scaling;
465 +       struct weston_transform transform;
466  
467         struct ivi_layout_surface_properties prop;
468         uint32_t event_mask;
469 @@ -83,9 +81,12 @@ struct ivi_layout_layer {
470         } pending;
471  
472         struct {
473 +               int dirty;
474                 struct wl_list surface_list;
475                 struct wl_list link;
476         } order;
477 +
478 +       int32_t ref_count;
479  };
480  
481  struct ivi_layout {
482 @@ -223,4 +224,6 @@ ivi_layout_transition_move_layer_cancel(struct ivi_layout_layer *layer);
483  int
484  load_controller_modules(struct weston_compositor *compositor, const char *modules,
485                         int *argc, char *argv[]);
486 +void
487 +ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf);
488  #endif
489 diff --git a/ivi-shell/ivi-layout-transition.c b/ivi-shell/ivi-layout-transition.c
490 index f691d35..d12a8f4 100644
491 --- a/ivi-shell/ivi-layout-transition.c
492 +++ b/ivi-shell/ivi-layout-transition.c
493 @@ -1,23 +1,26 @@
494  /*
495   * Copyright (C) 2014 DENSO CORPORATION
496   *
497 - * Permission to use, copy, modify, distribute, and sell this software and
498 - * its documentation for any purpose is hereby granted without fee, provided
499 - * that the above copyright notice appear in all copies and that both that
500 - * copyright notice and this permission notice appear in supporting
501 - * documentation, and that the name of the copyright holders not be used in
502 - * advertising or publicity pertaining to distribution of the software
503 - * without specific, written prior permission.  The copyright holders make
504 - * no representations about the suitability of this software for any
505 - * purpose.  It is provided "as is" without express or implied warranty.
506 + * Permission is hereby granted, free of charge, to any person obtaining
507 + * a copy of this software and associated documentation files (the
508 + * "Software"), to deal in the Software without restriction, including
509 + * without limitation the rights to use, copy, modify, merge, publish,
510 + * distribute, sublicense, and/or sell copies of the Software, and to
511 + * permit persons to whom the Software is furnished to do so, subject to
512 + * the following conditions:
513   *
514 - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
515 - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
516 - * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
517 - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
518 - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
519 - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
520 - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
521 + * The above copyright notice and this permission notice (including the
522 + * next paragraph) shall be included in all copies or substantial
523 + * portions of the Software.
524 + *
525 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
526 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
527 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
528 + * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
529 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
530 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
531 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
532 + * SOFTWARE.
533   */
534  
535  #include <time.h>
536 @@ -226,7 +229,7 @@ layout_transition_destroy(struct ivi_layout_transition *transition)
537         struct ivi_layout *layout = get_instance();
538  
539         remove_transition(layout, transition);
540 -       if(transition->destroy_func)
541 +       if (transition->destroy_func)
542                 transition->destroy_func(transition);
543         free(transition);
544  }
545 @@ -660,7 +663,7 @@ transition_move_layer_destroy(struct ivi_layout_transition *transition)
546  {
547         struct move_layer_data *data = transition->private_data;
548  
549 -       if(data->destroy_func)
550 +       if (data->destroy_func)
551                 data->destroy_func(transition->user_data);
552  
553         free(data);
554 diff --git a/ivi-shell/ivi-layout.c b/ivi-shell/ivi-layout.c
555 index abfba70..c153884 100644
556 --- a/ivi-shell/ivi-layout.c
557 +++ b/ivi-shell/ivi-layout.c
558 @@ -1,23 +1,26 @@
559  /*
560   * Copyright (C) 2013 DENSO CORPORATION
561   *
562 - * Permission to use, copy, modify, distribute, and sell this software and
563 - * its documentation for any purpose is hereby granted without fee, provided
564 - * that the above copyright notice appear in all copies and that both that
565 - * copyright notice and this permission notice appear in supporting
566 - * documentation, and that the name of the copyright holders not be used in
567 - * advertising or publicity pertaining to distribution of the software
568 - * without specific, written prior permission.  The copyright holders make
569 - * no representations about the suitability of this software for any
570 - * purpose.  It is provided "as is" without express or implied warranty.
571 + * Permission is hereby granted, free of charge, to any person obtaining
572 + * a copy of this software and associated documentation files (the
573 + * "Software"), to deal in the Software without restriction, including
574 + * without limitation the rights to use, copy, modify, merge, publish,
575 + * distribute, sublicense, and/or sell copies of the Software, and to
576 + * permit persons to whom the Software is furnished to do so, subject to
577 + * the following conditions:
578   *
579 - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
580 - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
581 - * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
582 - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
583 - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
584 - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
585 - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
586 + * The above copyright notice and this permission notice (including the
587 + * next paragraph) shall be included in all copies or substantial
588 + * portions of the Software.
589 + *
590 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
591 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
592 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
593 + * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
594 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
595 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
596 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
597 + * SOFTWARE.
598   */
599  
600  /**
601 @@ -55,12 +58,15 @@
602  #include "config.h"
603  
604  #include <string.h>
605 +#include <assert.h>
606  
607  #include "compositor.h"
608  #include "ivi-layout-export.h"
609  #include "ivi-layout-private.h"
610  
611 -#include "../shared/os-compatibility.h"
612 +#include "shared/os-compatibility.h"
613 +
614 +#define max(a, b) ((a) > (b) ? (a) : (b))
615  
616  struct link_layer {
617         struct ivi_layout_layer *ivilayer;
618 @@ -89,14 +95,13 @@ struct ivi_layout_screen {
619         struct ivi_layout *layout;
620         struct weston_output *output;
621  
622 -       uint32_t event_mask;
623 -
624         struct {
625                 struct wl_list layer_list;
626                 struct wl_list link;
627         } pending;
628  
629         struct {
630 +               int dirty;
631                 struct wl_list layer_list;
632                 struct wl_list link;
633         } order;
634 @@ -107,6 +112,17 @@ struct ivi_layout_notification_callback {
635         void *data;
636  };
637  
638 +struct ivi_rectangle
639 +{
640 +       int32_t x;
641 +       int32_t y;
642 +       int32_t width;
643 +       int32_t height;
644 +};
645 +
646 +static void
647 +remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
648 +
649  static struct ivi_layout ivilayout = {0};
650  
651  struct ivi_layout *
652 @@ -139,12 +155,8 @@ remove_link_to_surface(struct ivi_layout_layer *ivilayer)
653         struct link_layer *next = NULL;
654  
655         wl_list_for_each_safe(link, next, &ivilayer->link_to_surface, link_to_layer) {
656 -               if (!wl_list_empty(&link->link_to_layer)) {
657 -                       wl_list_remove(&link->link_to_layer);
658 -               }
659 -               if (!wl_list_empty(&link->link)) {
660 -                       wl_list_remove(&link->link);
661 -               }
662 +               wl_list_remove(&link->link_to_layer);
663 +               wl_list_remove(&link->link);
664                 free(link);
665         }
666  
667 @@ -158,7 +170,6 @@ static void
668  add_link_to_layer(struct ivi_layout_screen *iviscrn,
669                   struct link_screen *link_screen)
670  {
671 -       wl_list_init(&link_screen->link_to_screen);
672         wl_list_insert(&iviscrn->link_to_layer, &link_screen->link_to_screen);
673  }
674  
675 @@ -178,7 +189,6 @@ add_ordersurface_to_layer(struct ivi_layout_surface *ivisurf,
676         }
677  
678         link_layer->ivilayer = ivilayer;
679 -       wl_list_init(&link_layer->link);
680         wl_list_insert(&ivisurf->layer_list, &link_layer->link);
681         add_link_to_surface(ivilayer, link_layer);
682  }
683 @@ -190,12 +200,8 @@ remove_ordersurface_from_layer(struct ivi_layout_surface *ivisurf)
684         struct link_layer *next = NULL;
685  
686         wl_list_for_each_safe(link_layer, next, &ivisurf->layer_list, link) {
687 -               if (!wl_list_empty(&link_layer->link)) {
688 -                       wl_list_remove(&link_layer->link);
689 -               }
690 -               if (!wl_list_empty(&link_layer->link_to_layer)) {
691 -                       wl_list_remove(&link_layer->link_to_layer);
692 -               }
693 +               wl_list_remove(&link_layer->link);
694 +               wl_list_remove(&link_layer->link_to_layer);
695                 free(link_layer);
696         }
697         wl_list_init(&ivisurf->layer_list);
698 @@ -217,7 +223,6 @@ add_orderlayer_to_screen(struct ivi_layout_layer *ivilayer,
699         }
700  
701         link_scrn->iviscrn = iviscrn;
702 -       wl_list_init(&link_scrn->link);
703         wl_list_insert(&ivilayer->screen_list, &link_scrn->link);
704         add_link_to_layer(iviscrn, link_scrn);
705  }
706 @@ -229,12 +234,8 @@ remove_orderlayer_from_screen(struct ivi_layout_layer *ivilayer)
707         struct link_screen *next = NULL;
708  
709         wl_list_for_each_safe(link_scrn, next, &ivilayer->screen_list, link) {
710 -               if (!wl_list_empty(&link_scrn->link)) {
711 -                       wl_list_remove(&link_scrn->link);
712 -               }
713 -               if (!wl_list_empty(&link_scrn->link_to_screen)) {
714 -                       wl_list_remove(&link_scrn->link_to_screen);
715 -               }
716 +               wl_list_remove(&link_scrn->link);
717 +               wl_list_remove(&link_scrn->link_to_screen);
718                 free(link_scrn);
719         }
720         wl_list_init(&ivilayer->screen_list);
721 @@ -290,9 +291,7 @@ remove_all_notification(struct wl_list *listener_list)
722  
723         wl_list_for_each_safe(listener, next, listener_list, link) {
724                 struct listener_layout_notification *notification = NULL;
725 -               if (!wl_list_empty(&listener->link)) {
726 -                       wl_list_remove(&listener->link);
727 -               }
728 +               wl_list_remove(&listener->link);
729  
730                 notification =
731                         container_of(listener,
732 @@ -315,29 +314,36 @@ ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
733         remove_all_notification(&ivisurf->property_changed.listener_list);
734  }
735  
736 +static void
737 +ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
738 +                                                  surface_property_notification_func callback,
739 +                                                  void *userdata)
740 +{
741 +       if (ivisurf == NULL) {
742 +               weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
743 +               return;
744 +       }
745 +
746 +       remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
747 +}
748 +
749  /**
750 - * this shall not be called from controller because this is triggered by ivi_surface.destroy
751 - * This means that this is called from westonsurface_destroy_from_ivisurface.
752 + * Called at destruction of wl_surface/ivi_surface
753   */
754 -static void
755 -ivi_layout_surface_remove(struct ivi_layout_surface *ivisurf)
756 +void
757 +ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
758  {
759         struct ivi_layout *layout = get_instance();
760  
761         if (ivisurf == NULL) {
762 -               weston_log("ivi_layout_surface_remove: invalid argument\n");
763 +               weston_log("%s: invalid argument\n", __func__);
764                 return;
765         }
766  
767 -       if (!wl_list_empty(&ivisurf->pending.link)) {
768 -               wl_list_remove(&ivisurf->pending.link);
769 -       }
770 -       if (!wl_list_empty(&ivisurf->order.link)) {
771 -               wl_list_remove(&ivisurf->order.link);
772 -       }
773 -       if (!wl_list_empty(&ivisurf->link)) {
774 -               wl_list_remove(&ivisurf->link);
775 -       }
776 +       wl_list_remove(&ivisurf->transform.link);
777 +       wl_list_remove(&ivisurf->pending.link);
778 +       wl_list_remove(&ivisurf->order.link);
779 +       wl_list_remove(&ivisurf->link);
780         remove_ordersurface_from_layer(ivisurf);
781  
782         wl_signal_emit(&layout->surface_notification.removed, ivisurf);
783 @@ -350,27 +356,6 @@ ivi_layout_surface_remove(struct ivi_layout_surface *ivisurf)
784  }
785  
786  /**
787 - * Called at destruction of ivi_surface
788 - */
789 -static void
790 -westonsurface_destroy_from_ivisurface(struct wl_listener *listener, void *data)
791 -{
792 -       struct ivi_layout_surface *ivisurf = NULL;
793 -
794 -       ivisurf = container_of(listener, struct ivi_layout_surface,
795 -                              surface_destroy_listener);
796 -
797 -       wl_list_remove(&ivisurf->surface_rotation.link);
798 -       wl_list_remove(&ivisurf->layer_rotation.link);
799 -       wl_list_remove(&ivisurf->surface_pos.link);
800 -       wl_list_remove(&ivisurf->layer_pos.link);
801 -       wl_list_remove(&ivisurf->scaling.link);
802 -
803 -       ivisurf->surface = NULL;
804 -       ivi_layout_surface_remove(ivisurf);
805 -}
806 -
807 -/**
808   * Internal API to check ivi_layer/ivi_surface already added in ivi_layer/ivi_screen.
809   * Called by ivi_layout_layer_add_surface/ivi_layout_screenAddLayer
810   */
811 @@ -423,14 +408,12 @@ create_screen(struct weston_compositor *ec)
812                         continue;
813                 }
814  
815 -               wl_list_init(&iviscrn->link);
816                 iviscrn->layout = layout;
817  
818                 iviscrn->id_screen = count;
819                 count++;
820  
821                 iviscrn->output = output;
822 -               iviscrn->event_mask = 0;
823  
824                 wl_list_init(&iviscrn->pending.layer_list);
825                 wl_list_init(&iviscrn->pending.link);
826 @@ -494,293 +477,319 @@ update_opacity(struct ivi_layout_layer *ivilayer,
827  }
828  
829  static void
830 -update_surface_orientation(struct ivi_layout_layer *ivilayer,
831 -                          struct ivi_layout_surface *ivisurf)
832 -{
833 -       struct weston_view *view;
834 -       struct weston_matrix  *matrix = &ivisurf->surface_rotation.matrix;
835 -       float width  = 0.0f;
836 -       float height = 0.0f;
837 -       float v_sin  = 0.0f;
838 -       float v_cos  = 0.0f;
839 -       float cx = 0.0f;
840 -       float cy = 0.0f;
841 -       float sx = 1.0f;
842 -       float sy = 1.0f;
843 -
844 -       wl_list_for_each(view, &ivisurf->surface->views, surface_link) {
845 -               if (view != NULL) {
846 -                       break;
847 -               }
848 -       }
849 -
850 -       if (view == NULL) {
851 -               return;
852 -       }
853 -
854 -       if ((ivilayer->prop.dest_width == 0) ||
855 -           (ivilayer->prop.dest_height == 0)) {
856 -               return;
857 -       }
858 -       width  = (float)ivilayer->prop.dest_width;
859 -       height = (float)ivilayer->prop.dest_height;
860 -
861 -       switch (ivisurf->prop.orientation) {
862 -       case WL_OUTPUT_TRANSFORM_NORMAL:
863 -               v_sin = 0.0f;
864 -               v_cos = 1.0f;
865 -               break;
866 +get_rotate_values(enum wl_output_transform orientation,
867 +                 float *v_sin,
868 +                 float *v_cos)
869 +{
870 +       switch (orientation) {
871         case WL_OUTPUT_TRANSFORM_90:
872 -               v_sin = 1.0f;
873 -               v_cos = 0.0f;
874 -               sx = width / height;
875 -               sy = height / width;
876 +               *v_sin = 1.0f;
877 +               *v_cos = 0.0f;
878                 break;
879         case WL_OUTPUT_TRANSFORM_180:
880 -               v_sin = 0.0f;
881 -               v_cos = -1.0f;
882 +               *v_sin = 0.0f;
883 +               *v_cos = -1.0f;
884                 break;
885         case WL_OUTPUT_TRANSFORM_270:
886 +               *v_sin = -1.0f;
887 +               *v_cos = 0.0f;
888 +               break;
889 +       case WL_OUTPUT_TRANSFORM_NORMAL:
890         default:
891 -               v_sin = -1.0f;
892 -               v_cos = 0.0f;
893 -               sx = width / height;
894 -               sy = height / width;
895 +               *v_sin = 0.0f;
896 +               *v_cos = 1.0f;
897                 break;
898         }
899 -       wl_list_remove(&ivisurf->surface_rotation.link);
900 -       weston_view_geometry_dirty(view);
901 -
902 -       weston_matrix_init(matrix);
903 -       cx = 0.5f * width;
904 -       cy = 0.5f * height;
905 -       weston_matrix_translate(matrix, -cx, -cy, 0.0f);
906 -       weston_matrix_rotate_xy(matrix, v_cos, v_sin);
907 -       weston_matrix_scale(matrix, sx, sy, 1.0);
908 -       weston_matrix_translate(matrix, cx, cy, 0.0f);
909 -       wl_list_insert(&view->geometry.transformation_list,
910 -                      &ivisurf->surface_rotation.link);
911 -
912 -       weston_view_set_transform_parent(view, NULL);
913 -       weston_view_update_transform(view);
914  }
915  
916  static void
917 -update_layer_orientation(struct ivi_layout_layer *ivilayer,
918 -                        struct ivi_layout_surface *ivisurf)
919 -{
920 -       struct weston_surface *es = ivisurf->surface;
921 -       struct weston_view    *view;
922 -       struct weston_matrix  *matrix = &ivisurf->layer_rotation.matrix;
923 -       struct weston_output  *output = NULL;
924 -       float width  = 0.0f;
925 -       float height = 0.0f;
926 -       float v_sin  = 0.0f;
927 -       float v_cos  = 0.0f;
928 -       float cx = 0.0f;
929 -       float cy = 0.0f;
930 -       float sx = 1.0f;
931 -       float sy = 1.0f;
932 -
933 -       wl_list_for_each(view, &ivisurf->surface->views, surface_link) {
934 -               if (view != NULL) {
935 -                       break;
936 -               }
937 -       }
938 -
939 -       if (es == NULL || view == NULL) {
940 -               return;
941 -       }
942 -
943 -       output = es->output;
944 -       if (output == NULL) {
945 -               return;
946 -       }
947 -       if ((output->width == 0) || (output->height == 0)) {
948 -               return;
949 -       }
950 -       width = (float)output->width;
951 -       height = (float)output->height;
952 -
953 -       switch (ivilayer->prop.orientation) {
954 -       case WL_OUTPUT_TRANSFORM_NORMAL:
955 -               v_sin = 0.0f;
956 -               v_cos = 1.0f;
957 -               break;
958 +get_scale(enum wl_output_transform orientation,
959 +         float dest_width,
960 +         float dest_height,
961 +         float source_width,
962 +         float source_height,
963 +         float *scale_x,
964 +         float *scale_y)
965 +{
966 +       switch (orientation) {
967         case WL_OUTPUT_TRANSFORM_90:
968 -               v_sin = 1.0f;
969 -               v_cos = 0.0f;
970 -               sx = width / height;
971 -               sy = height / width;
972 +               *scale_x = dest_width / source_height;
973 +               *scale_y = dest_height / source_width;
974                 break;
975         case WL_OUTPUT_TRANSFORM_180:
976 -               v_sin = 0.0f;
977 -               v_cos = -1.0f;
978 +               *scale_x = dest_width / source_width;
979 +               *scale_y = dest_height / source_height;
980                 break;
981         case WL_OUTPUT_TRANSFORM_270:
982 +               *scale_x = dest_width / source_height;
983 +               *scale_y = dest_height / source_width;
984 +               break;
985 +       case WL_OUTPUT_TRANSFORM_NORMAL:
986         default:
987 -               v_sin = -1.0f;
988 -               v_cos = 0.0f;
989 -               sx = width / height;
990 -               sy = height / width;
991 +               *scale_x = dest_width / source_width;
992 +               *scale_y = dest_height / source_height;
993                 break;
994         }
995 -       wl_list_remove(&ivisurf->layer_rotation.link);
996 -       weston_view_geometry_dirty(view);
997 -
998 -       weston_matrix_init(matrix);
999 -       cx = 0.5f * width;
1000 -       cy = 0.5f * height;
1001 -       weston_matrix_translate(matrix, -cx, -cy, 0.0f);
1002 -       weston_matrix_rotate_xy(matrix, v_cos, v_sin);
1003 -       weston_matrix_scale(matrix, sx, sy, 1.0);
1004 -       weston_matrix_translate(matrix, cx, cy, 0.0f);
1005 -       wl_list_insert(&view->geometry.transformation_list,
1006 -                      &ivisurf->layer_rotation.link);
1007 +}
1008  
1009 -       weston_view_set_transform_parent(view, NULL);
1010 -       weston_view_update_transform(view);
1011 +static void
1012 +calc_transformation_matrix(struct ivi_rectangle *source_rect,
1013 +                          struct ivi_rectangle *dest_rect,
1014 +                          enum wl_output_transform orientation,
1015 +                          struct weston_matrix *m)
1016 +{
1017 +       float source_center_x;
1018 +       float source_center_y;
1019 +       float vsin;
1020 +       float vcos;
1021 +       float scale_x;
1022 +       float scale_y;
1023 +       float translate_x;
1024 +       float translate_y;
1025 +
1026 +       source_center_x = source_rect->x + source_rect->width * 0.5f;
1027 +       source_center_y = source_rect->y + source_rect->height * 0.5f;
1028 +       weston_matrix_translate(m, -source_center_x, -source_center_y, 0.0f);
1029 +
1030 +       get_rotate_values(orientation, &vsin, &vcos);
1031 +       weston_matrix_rotate_xy(m, vcos, vsin);
1032 +
1033 +       get_scale(orientation,
1034 +                 dest_rect->width,
1035 +                 dest_rect->height,
1036 +                 source_rect->width,
1037 +                 source_rect->height,
1038 +                 &scale_x,
1039 +                 &scale_y);
1040 +       weston_matrix_scale(m, scale_x, scale_y, 1.0f);
1041 +
1042 +       translate_x = dest_rect->width * 0.5f + dest_rect->x;
1043 +       translate_y = dest_rect->height * 0.5f + dest_rect->y;
1044 +       weston_matrix_translate(m, translate_x, translate_y, 0.0f);
1045  }
1046  
1047 +/*
1048 + * This computes intersected rect_output from two ivi_rectangles
1049 + */
1050  static void
1051 -update_surface_position(struct ivi_layout_surface *ivisurf)
1052 +ivi_rectangle_intersect(const struct ivi_rectangle *rect1,
1053 +                       const struct ivi_rectangle *rect2,
1054 +                       struct ivi_rectangle *rect_output)
1055  {
1056 -       struct weston_view *view;
1057 -       float tx  = (float)ivisurf->prop.dest_x;
1058 -       float ty  = (float)ivisurf->prop.dest_y;
1059 -       struct weston_matrix *matrix = &ivisurf->surface_pos.matrix;
1060 +       int32_t rect1_right = rect1->x + rect1->width;
1061 +       int32_t rect1_bottom = rect1->y + rect1->height;
1062 +       int32_t rect2_right = rect2->x + rect2->width;
1063 +       int32_t rect2_bottom = rect2->y + rect2->height;
1064  
1065 -       wl_list_for_each(view, &ivisurf->surface->views, surface_link) {
1066 -               if (view != NULL) {
1067 -                       break;
1068 -               }
1069 -       }
1070 +       rect_output->x = max(rect1->x, rect2->x);
1071 +       rect_output->y = max(rect1->y, rect2->y);
1072 +       rect_output->width = rect1_right < rect2_right ?
1073 +                            rect1_right - rect_output->x :
1074 +                            rect2_right - rect_output->x;
1075 +       rect_output->height = rect1_bottom < rect2_bottom ?
1076 +                             rect1_bottom - rect_output->y :
1077 +                             rect2_bottom - rect_output->y;
1078  
1079 -       if (view == NULL) {
1080 -               return;
1081 +       if (rect_output->width < 0 || rect_output->height < 0) {
1082 +               rect_output->width = 0;
1083 +               rect_output->height = 0;
1084         }
1085 -
1086 -       wl_list_remove(&ivisurf->surface_pos.link);
1087 -
1088 -       weston_matrix_init(matrix);
1089 -       weston_matrix_translate(matrix, tx, ty, 0.0f);
1090 -       wl_list_insert(&view->geometry.transformation_list,
1091 -                      &ivisurf->surface_pos.link);
1092 -
1093 -       weston_view_set_transform_parent(view, NULL);
1094 -       weston_view_update_transform(view);
1095  }
1096  
1097 +/*
1098 + * Transform rect_input by the inverse of matrix, intersect with boundingbox,
1099 + * and store the result in rect_output.
1100 + * The boundingbox must be given in the same coordinate space as rect_output.
1101 + * Additionally, there are the following restrictions on the matrix:
1102 + * - no projective transformations
1103 + * - no skew
1104 + * - only multiples of 90-degree rotations supported
1105 + *
1106 + * In failure case of weston_matrix_invert, rect_output is set to boundingbox
1107 + * as a fail-safe with log.
1108 + */
1109  static void
1110 -update_layer_position(struct ivi_layout_layer *ivilayer,
1111 -                     struct ivi_layout_surface *ivisurf)
1112 +calc_inverse_matrix_transform(const struct weston_matrix *matrix,
1113 +                             const struct ivi_rectangle *rect_input,
1114 +                             const struct ivi_rectangle *boundingbox,
1115 +                             struct ivi_rectangle *rect_output)
1116  {
1117 -       struct weston_view *view;
1118 -       struct weston_matrix *matrix = &ivisurf->layer_pos.matrix;
1119 -       float tx  = (float)ivilayer->prop.dest_x;
1120 -       float ty  = (float)ivilayer->prop.dest_y;
1121 +       struct weston_matrix m;
1122 +       struct weston_vector top_left;
1123 +       struct weston_vector bottom_right;
1124  
1125 -       wl_list_for_each(view, &ivisurf->surface->views, surface_link) {
1126 -               if (view != NULL) {
1127 -                       break;
1128 -               }
1129 -       }
1130 +       assert(boundingbox != rect_output);
1131  
1132 -       if (view == NULL) {
1133 -               return;
1134 +       if (weston_matrix_invert(&m, matrix) < 0) {
1135 +               weston_log("ivi-shell: calc_inverse_matrix_transform fails to invert a matrix.\n");
1136 +               weston_log("ivi-shell: boundingbox is set to the rect_output.\n");
1137 +               rect_output->x = boundingbox->x;
1138 +               rect_output->y = boundingbox->y;
1139 +               rect_output->width = boundingbox->width;
1140 +               rect_output->height = boundingbox->height;
1141         }
1142  
1143 -       wl_list_remove(&ivisurf->layer_pos.link);
1144 +       /* The vectors and matrices involved will always produce f[3] == 1.0. */
1145 +       top_left.f[0] = rect_input->x;
1146 +       top_left.f[1] = rect_input->y;
1147 +       top_left.f[2] = 0.0f;
1148 +       top_left.f[3] = 1.0f;
1149  
1150 -       weston_matrix_init(matrix);
1151 -       weston_matrix_translate(matrix, tx, ty, 0.0f);
1152 -       wl_list_insert(&view->geometry.transformation_list,
1153 -                      &ivisurf->layer_pos.link);
1154 +       bottom_right.f[0] = rect_input->x + rect_input->width;
1155 +       bottom_right.f[1] = rect_input->y + rect_input->height;
1156 +       bottom_right.f[2] = 0.0f;
1157 +       bottom_right.f[3] = 1.0f;
1158  
1159 -       weston_view_set_transform_parent(view, NULL);
1160 -       weston_view_update_transform(view);
1161 -}
1162 +       weston_matrix_transform(&m, &top_left);
1163 +       weston_matrix_transform(&m, &bottom_right);
1164  
1165 -static void
1166 -update_scale(struct ivi_layout_layer *ivilayer,
1167 -            struct ivi_layout_surface *ivisurf)
1168 -{
1169 -       struct weston_view *view;
1170 -       struct weston_matrix *matrix = &ivisurf->scaling.matrix;
1171 -       float sx = 0.0f;
1172 -       float sy = 0.0f;
1173 -       float lw = 0.0f;
1174 -       float sw = 0.0f;
1175 -       float lh = 0.0f;
1176 -       float sh = 0.0f;
1177 -
1178 -       wl_list_for_each(view, &ivisurf->surface->views, surface_link) {
1179 -               if (view != NULL) {
1180 -                       break;
1181 -               }
1182 +       if (top_left.f[0] < bottom_right.f[0]) {
1183 +               rect_output->x = top_left.f[0];
1184 +               rect_output->width = bottom_right.f[0] - rect_output->x;
1185 +       } else {
1186 +               rect_output->x = bottom_right.f[0];
1187 +               rect_output->width = top_left.f[0] - rect_output->x;
1188         }
1189  
1190 -       if (view == NULL) {
1191 -               return;
1192 +       if (top_left.f[1] < bottom_right.f[1]) {
1193 +               rect_output->y = top_left.f[1];
1194 +               rect_output->height = bottom_right.f[1] - rect_output->y;
1195 +       } else {
1196 +               rect_output->y = bottom_right.f[1];
1197 +               rect_output->height = top_left.f[1] - rect_output->y;
1198         }
1199  
1200 -       if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
1201 -               weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
1202 -               return;
1203 -       }
1204 +       ivi_rectangle_intersect(rect_output, boundingbox, rect_output);
1205 +}
1206  
1207 -       if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
1208 -               weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
1209 -               return;
1210 -       }
1211 +/**
1212 + * This computes the whole transformation matrix:m from surface-local
1213 + * coordinates to global coordinates. It is assumed that
1214 + * weston_view::geometry.{x,y} are zero.
1215 + *
1216 + * Additionally, this computes the mask on surface-local coordinates as a
1217 + * ivi_rectangle. This can be set to weston_view_set_mask.
1218 + *
1219 + * The mask is computed by following steps
1220 + * - destination rectangle of layer is inversed to surface-local cooodinates
1221 + *   by inversed matrix:m.
1222 + * - the area is intersected by intersected area between weston_surface and
1223 + *   source rectangle of ivi_surface.
1224 + */
1225 +static void
1226 +calc_surface_to_global_matrix_and_mask_to_weston_surface(
1227 +       struct ivi_layout_layer *ivilayer,
1228 +       struct ivi_layout_surface *ivisurf,
1229 +       struct weston_matrix *m,
1230 +       struct ivi_rectangle *result)
1231 +{
1232 +       const struct ivi_layout_surface_properties *sp = &ivisurf->prop;
1233 +       const struct ivi_layout_layer_properties *lp = &ivilayer->prop;
1234 +       struct ivi_rectangle weston_surface_rect = { 0,
1235 +                                                    0,
1236 +                                                    ivisurf->surface->width,
1237 +                                                    ivisurf->surface->height };
1238 +       struct ivi_rectangle surface_source_rect = { sp->source_x,
1239 +                                                    sp->source_y,
1240 +                                                    sp->source_width,
1241 +                                                    sp->source_height };
1242 +       struct ivi_rectangle surface_dest_rect =   { sp->dest_x,
1243 +                                                    sp->dest_y,
1244 +                                                    sp->dest_width,
1245 +                                                    sp->dest_height };
1246 +       struct ivi_rectangle layer_source_rect =   { lp->source_x,
1247 +                                                    lp->source_y,
1248 +                                                    lp->source_width,
1249 +                                                    lp->source_height };
1250 +       struct ivi_rectangle layer_dest_rect =     { lp->dest_x,
1251 +                                                    lp->dest_y,
1252 +                                                    lp->dest_width,
1253 +                                                    lp->dest_height };
1254 +       struct ivi_rectangle surface_result;
1255  
1256 -       lw = ((float)ivilayer->prop.dest_width  / (float)ivilayer->prop.source_width );
1257 -       sw = ((float)ivisurf->prop.dest_width   / (float)ivisurf->prop.source_width  );
1258 -       lh = ((float)ivilayer->prop.dest_height / (float)ivilayer->prop.source_height);
1259 -       sh = ((float)ivisurf->prop.dest_height  / (float)ivisurf->prop.source_height );
1260 -       sx = sw * lw;
1261 -       sy = sh * lh;
1262 +       /*
1263 +        * the whole transformation matrix:m from surface-local
1264 +        * coordinates to global coordinates, which is computed by
1265 +        * two steps,
1266 +        * - surface-local coordinates to layer-local coordinates
1267 +        * - layer-local coordinates to global coordinates
1268 +        */
1269 +       calc_transformation_matrix(&surface_source_rect,
1270 +                                  &surface_dest_rect,
1271 +                                  sp->orientation, m);
1272  
1273 -       wl_list_remove(&ivisurf->scaling.link);
1274 -       weston_matrix_init(matrix);
1275 -       weston_matrix_scale(matrix, sx, sy, 1.0f);
1276 +       calc_transformation_matrix(&layer_source_rect,
1277 +                                  &layer_dest_rect,
1278 +                                  lp->orientation, m);
1279  
1280 -       wl_list_insert(&view->geometry.transformation_list,
1281 -                      &ivisurf->scaling.link);
1282 +       /* this intersected ivi_rectangle would be used for masking
1283 +        * weston_surface
1284 +        */
1285 +       ivi_rectangle_intersect(&surface_source_rect, &weston_surface_rect,
1286 +                               &surface_result);
1287  
1288 -       weston_view_set_transform_parent(view, NULL);
1289 -       weston_view_update_transform(view);
1290 +       /* calc masking area of weston_surface from m */
1291 +       calc_inverse_matrix_transform(m,
1292 +                                     &layer_dest_rect,
1293 +                                     &surface_result,
1294 +                                     result);
1295  }
1296  
1297  static void
1298  update_prop(struct ivi_layout_layer *ivilayer,
1299             struct ivi_layout_surface *ivisurf)
1300  {
1301 -       if (ivilayer->event_mask | ivisurf->event_mask) {
1302 -               struct weston_view *tmpview;
1303 -               update_opacity(ivilayer, ivisurf);
1304 -               update_layer_orientation(ivilayer, ivisurf);
1305 -               update_layer_position(ivilayer, ivisurf);
1306 -               update_surface_position(ivisurf);
1307 -               update_surface_orientation(ivilayer, ivisurf);
1308 -               update_scale(ivilayer, ivisurf);
1309 +       struct weston_view *tmpview;
1310 +       struct ivi_rectangle r;
1311 +       bool can_calc = true;
1312  
1313 -               ivisurf->update_count++;
1314 +       if (!ivilayer->event_mask && !ivisurf->event_mask) {
1315 +               return;
1316 +       }
1317  
1318 -               wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
1319 -                       if (tmpview != NULL) {
1320 -                               break;
1321 -                       }
1322 -               }
1323 +       update_opacity(ivilayer, ivisurf);
1324  
1325 +       wl_list_for_each(tmpview, &ivisurf->surface->views, surface_link) {
1326                 if (tmpview != NULL) {
1327 -                       weston_view_geometry_dirty(tmpview);
1328 +                       break;
1329                 }
1330 +       }
1331  
1332 -               if (ivisurf->surface != NULL) {
1333 -                       weston_surface_damage(ivisurf->surface);
1334 +       if (ivisurf->prop.source_width == 0 || ivisurf->prop.source_height == 0) {
1335 +               weston_log("ivi-shell: source rectangle is not yet set by ivi_layout_surface_set_source_rectangle\n");
1336 +               can_calc = false;
1337 +       }
1338 +
1339 +       if (ivisurf->prop.dest_width == 0 || ivisurf->prop.dest_height == 0) {
1340 +               weston_log("ivi-shell: destination rectangle is not yet set by ivi_layout_surface_set_destination_rectangle\n");
1341 +               can_calc = false;
1342 +       }
1343 +
1344 +       if (can_calc) {
1345 +               wl_list_remove(&ivisurf->transform.link);
1346 +               weston_matrix_init(&ivisurf->transform.matrix);
1347 +
1348 +               calc_surface_to_global_matrix_and_mask_to_weston_surface(
1349 +                       ivilayer, ivisurf, &ivisurf->transform.matrix, &r);
1350 +
1351 +               if (tmpview != NULL) {
1352 +                       weston_view_set_mask(tmpview, r.x, r.y, r.width, r.height);
1353 +                       wl_list_insert(&tmpview->geometry.transformation_list,
1354 +                                      &ivisurf->transform.link);
1355 +
1356 +                       weston_view_set_transform_parent(tmpview, NULL);
1357                 }
1358         }
1359 +
1360 +       ivisurf->update_count++;
1361 +
1362 +       if (tmpview != NULL) {
1363 +               weston_view_geometry_dirty(tmpview);
1364 +       }
1365 +
1366 +       if (ivisurf->surface != NULL) {
1367 +               weston_surface_damage(ivisurf->surface);
1368 +       }
1369  }
1370  
1371  static void
1372 @@ -810,7 +819,7 @@ commit_surface_list(struct ivi_layout *layout)
1373         int32_t configured = 0;
1374  
1375         wl_list_for_each(ivisurf, &layout->surface_list, link) {
1376 -               if(ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
1377 +               if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEFAULT) {
1378                         dest_x = ivisurf->prop.dest_x;
1379                         dest_y = ivisurf->prop.dest_y;
1380                         dest_width = ivisurf->prop.dest_width;
1381 @@ -823,7 +832,7 @@ commit_surface_list(struct ivi_layout *layout)
1382                                                                ivisurf->pending.prop.dest_height,
1383                                                                ivisurf->pending.prop.transition_duration);
1384  
1385 -                       if(ivisurf->pending.prop.visibility) {
1386 +                       if (ivisurf->pending.prop.visibility) {
1387                                 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
1388                         } else {
1389                                 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
1390 @@ -837,7 +846,7 @@ commit_surface_list(struct ivi_layout *layout)
1391                         ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
1392                         ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
1393  
1394 -               } else if(ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY){
1395 +               } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_DEST_RECT_ONLY) {
1396                         dest_x = ivisurf->prop.dest_x;
1397                         dest_y = ivisurf->prop.dest_y;
1398                         dest_width = ivisurf->prop.dest_width;
1399 @@ -859,9 +868,9 @@ commit_surface_list(struct ivi_layout *layout)
1400                         ivisurf->prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
1401                         ivisurf->pending.prop.transition_type = IVI_LAYOUT_TRANSITION_NONE;
1402  
1403 -               } else if(ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY){
1404 +               } else if (ivisurf->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY) {
1405                         configured = 0;
1406 -                       if(ivisurf->pending.prop.visibility) {
1407 +                       if (ivisurf->pending.prop.visibility) {
1408                                 ivi_layout_transition_visibility_on(ivisurf, ivisurf->pending.prop.transition_duration);
1409                         } else {
1410                                 ivi_layout_transition_visibility_off(ivisurf, ivisurf->pending.prop.transition_duration);
1411 @@ -903,9 +912,9 @@ commit_layer_list(struct ivi_layout *layout)
1412         struct ivi_layout_surface *next     = NULL;
1413  
1414         wl_list_for_each(ivilayer, &layout->layer_list, link) {
1415 -               if(ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
1416 +               if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_MOVE) {
1417                         ivi_layout_transition_move_layer(ivilayer, ivilayer->pending.prop.dest_x, ivilayer->pending.prop.dest_y, ivilayer->pending.prop.transition_duration);
1418 -               } else if(ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
1419 +               } else if (ivilayer->pending.prop.transition_type == IVI_LAYOUT_TRANSITION_LAYER_FADE) {
1420                         ivi_layout_transition_fade_layer(ivilayer,ivilayer->pending.prop.is_fade_in,
1421                                                          ivilayer->pending.prop.start_alpha,ivilayer->pending.prop.end_alpha,
1422                                                          NULL, NULL,
1423 @@ -915,53 +924,30 @@ commit_layer_list(struct ivi_layout *layout)
1424  
1425                 ivilayer->prop = ivilayer->pending.prop;
1426  
1427 -               if (!(ivilayer->event_mask &
1428 -                     (IVI_NOTIFICATION_ADD | IVI_NOTIFICATION_REMOVE)) ) {
1429 +               if (!ivilayer->order.dirty) {
1430                         continue;
1431                 }
1432  
1433 -               if (ivilayer->event_mask & IVI_NOTIFICATION_REMOVE) {
1434 -                       wl_list_for_each_safe(ivisurf, next,
1435 -                               &ivilayer->order.surface_list, order.link) {
1436 -                               remove_ordersurface_from_layer(ivisurf);
1437 -
1438 -                               if (!wl_list_empty(&ivisurf->order.link)) {
1439 -                                       wl_list_remove(&ivisurf->order.link);
1440 -                               }
1441 -
1442 -                               wl_list_init(&ivisurf->order.link);
1443 -                               ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
1444 -                       }
1445 -
1446 -                       wl_list_init(&ivilayer->order.surface_list);
1447 +               wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
1448 +                                        order.link) {
1449 +                       remove_ordersurface_from_layer(ivisurf);
1450 +                       wl_list_remove(&ivisurf->order.link);
1451 +                       wl_list_init(&ivisurf->order.link);
1452 +                       ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
1453                 }
1454  
1455 -               if (ivilayer->event_mask & IVI_NOTIFICATION_ADD) {
1456 -                       wl_list_for_each_safe(ivisurf, next,
1457 -                                             &ivilayer->order.surface_list, order.link) {
1458 -                               remove_ordersurface_from_layer(ivisurf);
1459 -
1460 -                               if (!wl_list_empty(&ivisurf->order.link)) {
1461 -                                       wl_list_remove(&ivisurf->order.link);
1462 -                               }
1463 -
1464 -                               wl_list_init(&ivisurf->order.link);
1465 -                       }
1466 +               assert(wl_list_empty(&ivilayer->order.surface_list));
1467  
1468 -                       wl_list_init(&ivilayer->order.surface_list);
1469 -                       wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
1470 +               wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
1471                                          pending.link) {
1472 -                               if(!wl_list_empty(&ivisurf->order.link)){
1473 -                                       wl_list_remove(&ivisurf->order.link);
1474 -                                       wl_list_init(&ivisurf->order.link);
1475 -                               }
1476 -
1477 -                               wl_list_insert(&ivilayer->order.surface_list,
1478 -                                              &ivisurf->order.link);
1479 -                               add_ordersurface_to_layer(ivisurf, ivilayer);
1480 -                               ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
1481 -                       }
1482 +                       wl_list_remove(&ivisurf->order.link);
1483 +                       wl_list_insert(&ivilayer->order.surface_list,
1484 +                                      &ivisurf->order.link);
1485 +                       add_ordersurface_to_layer(ivisurf, ivilayer);
1486 +                       ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
1487                 }
1488 +
1489 +               ivilayer->order.dirty = 0;
1490         }
1491  }
1492  
1493 @@ -974,33 +960,17 @@ commit_screen_list(struct ivi_layout *layout)
1494         struct ivi_layout_surface *ivisurf  = NULL;
1495  
1496         wl_list_for_each(iviscrn, &layout->screen_list, link) {
1497 -               if (iviscrn->event_mask & IVI_NOTIFICATION_REMOVE) {
1498 +               if (iviscrn->order.dirty) {
1499                         wl_list_for_each_safe(ivilayer, next,
1500                                               &iviscrn->order.layer_list, order.link) {
1501                                 remove_orderlayer_from_screen(ivilayer);
1502 -
1503 -                               if (!wl_list_empty(&ivilayer->order.link)) {
1504 -                                   wl_list_remove(&ivilayer->order.link);
1505 -                               }
1506 -
1507 +                               wl_list_remove(&ivilayer->order.link);
1508                                 wl_list_init(&ivilayer->order.link);
1509                                 ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
1510                         }
1511 -               }
1512  
1513 -               if (iviscrn->event_mask & IVI_NOTIFICATION_ADD) {
1514 -                       wl_list_for_each_safe(ivilayer, next,
1515 -                                             &iviscrn->order.layer_list, order.link) {
1516 -                               remove_orderlayer_from_screen(ivilayer);
1517 +                       assert(wl_list_empty(&iviscrn->order.layer_list));
1518  
1519 -                               if (!wl_list_empty(&ivilayer->order.link)) {
1520 -                                       wl_list_remove(&ivilayer->order.link);
1521 -                               }
1522 -
1523 -                               wl_list_init(&ivilayer->order.link);
1524 -                       }
1525 -
1526 -                       wl_list_init(&iviscrn->order.layer_list);
1527                         wl_list_for_each(ivilayer, &iviscrn->pending.layer_list,
1528                                          pending.link) {
1529                                 wl_list_insert(&iviscrn->order.layer_list,
1530 @@ -1008,9 +978,9 @@ commit_screen_list(struct ivi_layout *layout)
1531                                 add_orderlayer_to_screen(ivilayer, iviscrn);
1532                                 ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
1533                         }
1534 -               }
1535  
1536 -               iviscrn->event_mask = 0;
1537 +                       iviscrn->order.dirty = 0;
1538 +               }
1539  
1540                 /* Clear view list of layout ivi_layer */
1541                 wl_list_init(&layout->layout_layer.view_list.link);
1542 @@ -1046,7 +1016,7 @@ commit_screen_list(struct ivi_layout *layout)
1543  static void
1544  commit_transition(struct ivi_layout* layout)
1545  {
1546 -       if(wl_list_empty(&layout->pending_transition_list)){
1547 +       if (wl_list_empty(&layout->pending_transition_list)) {
1548                 return;
1549         }
1550  
1551 @@ -1079,11 +1049,13 @@ send_prop(struct ivi_layout *layout)
1552         struct ivi_layout_surface *ivisurf  = NULL;
1553  
1554         wl_list_for_each_reverse(ivilayer, &layout->layer_list, link) {
1555 -               send_layer_prop(ivilayer);
1556 +               if (ivilayer->event_mask)
1557 +                       send_layer_prop(ivilayer);
1558         }
1559  
1560         wl_list_for_each_reverse(ivisurf, &layout->surface_list, link) {
1561 -               send_surface_prop(ivisurf);
1562 +               if (ivisurf->event_mask)
1563 +                       send_surface_prop(ivisurf);
1564         }
1565  }
1566  
1567 @@ -1095,14 +1067,9 @@ clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
1568  
1569         wl_list_for_each_safe(surface_link, surface_next,
1570                               &ivilayer->pending.surface_list, pending.link) {
1571 -               if (!wl_list_empty(&surface_link->pending.link)) {
1572 -                       wl_list_remove(&surface_link->pending.link);
1573 -               }
1574 -
1575 +               wl_list_remove(&surface_link->pending.link);
1576                 wl_list_init(&surface_link->pending.link);
1577         }
1578 -
1579 -       ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
1580  }
1581  
1582  static void
1583 @@ -1113,14 +1080,9 @@ clear_surface_order_list(struct ivi_layout_layer *ivilayer)
1584  
1585         wl_list_for_each_safe(surface_link, surface_next,
1586                               &ivilayer->order.surface_list, order.link) {
1587 -               if (!wl_list_empty(&surface_link->order.link)) {
1588 -                       wl_list_remove(&surface_link->order.link);
1589 -               }
1590 -
1591 +               wl_list_remove(&surface_link->order.link);
1592                 wl_list_init(&surface_link->order.link);
1593         }
1594 -
1595 -       ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
1596  }
1597  
1598  static void
1599 @@ -1287,9 +1249,7 @@ remove_notification(struct wl_list *listener_list, void *callback, void *userdat
1600                         continue;
1601                 }
1602  
1603 -               if (!wl_list_empty(&listener->link)) {
1604 -                       wl_list_remove(&listener->link);
1605 -               }
1606 +               wl_list_remove(&listener->link);
1607  
1608                 free(notification->userdata);
1609                 free(notification);
1610 @@ -1480,6 +1440,12 @@ ivi_layout_get_id_of_layer(struct ivi_layout_layer *ivilayer)
1611         return ivilayer->id_layer;
1612  }
1613  
1614 +static uint32_t
1615 +ivi_layout_get_id_of_screen(struct ivi_layout_screen *iviscrn)
1616 +{
1617 +       return iviscrn->id_screen;
1618 +}
1619 +
1620  static struct ivi_layout_layer *
1621  ivi_layout_get_layer_from_id(uint32_t id_layer)
1622  {
1623 @@ -1531,7 +1497,7 @@ ivi_layout_get_screen_resolution(struct ivi_layout_screen *iviscrn,
1624  {
1625         struct weston_output *output = NULL;
1626  
1627 -       if (pWidth == NULL || pHeight == NULL) {
1628 +       if (iviscrn == NULL || pWidth == NULL || pHeight == NULL) {
1629                 weston_log("ivi_layout_get_screen_resolution: invalid argument\n");
1630                 return IVI_FAILED;
1631         }
1632 @@ -1605,7 +1571,7 @@ ivi_layout_get_screens(int32_t *pLength, struct ivi_layout_screen ***ppArray)
1633  
1634         length = wl_list_length(&layout->screen_list);
1635  
1636 -       if (length != 0){
1637 +       if (length != 0) {
1638                 /* the Array must be free by module which called this function */
1639                 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1640                 if (*ppArray == NULL) {
1641 @@ -1639,7 +1605,7 @@ ivi_layout_get_screens_under_layer(struct ivi_layout_layer *ivilayer,
1642  
1643         length = wl_list_length(&ivilayer->screen_list);
1644  
1645 -       if (length != 0){
1646 +       if (length != 0) {
1647                 /* the Array must be free by module which called this function */
1648                 *ppArray = calloc(length, sizeof(struct ivi_layout_screen *));
1649                 if (*ppArray == NULL) {
1650 @@ -1672,7 +1638,7 @@ ivi_layout_get_layers(int32_t *pLength, struct ivi_layout_layer ***ppArray)
1651  
1652         length = wl_list_length(&layout->layer_list);
1653  
1654 -       if (length != 0){
1655 +       if (length != 0) {
1656                 /* the Array must be free by module which called this function */
1657                 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1658                 if (*ppArray == NULL) {
1659 @@ -1706,7 +1672,7 @@ ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1660  
1661         length = wl_list_length(&iviscrn->order.layer_list);
1662  
1663 -       if (length != 0){
1664 +       if (length != 0) {
1665                 /* the Array must be free by module which called this function */
1666                 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1667                 if (*ppArray == NULL) {
1668 @@ -1714,7 +1680,7 @@ ivi_layout_get_layers_on_screen(struct ivi_layout_screen *iviscrn,
1669                         return IVI_FAILED;
1670                 }
1671  
1672 -               wl_list_for_each(ivilayer, &iviscrn->order.layer_list, link) {
1673 +               wl_list_for_each(ivilayer, &iviscrn->order.layer_list, order.link) {
1674                         (*ppArray)[n++] = ivilayer;
1675                 }
1676         }
1677 @@ -1740,7 +1706,7 @@ ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
1678  
1679         length = wl_list_length(&ivisurf->layer_list);
1680  
1681 -       if (length != 0){
1682 +       if (length != 0) {
1683                 /* the Array must be free by module which called this function */
1684                 *ppArray = calloc(length, sizeof(struct ivi_layout_layer *));
1685                 if (*ppArray == NULL) {
1686 @@ -1774,7 +1740,7 @@ ivi_layout_get_surfaces(int32_t *pLength, struct ivi_layout_surface ***ppArray)
1687  
1688         length = wl_list_length(&layout->surface_list);
1689  
1690 -       if (length != 0){
1691 +       if (length != 0) {
1692                 /* the Array must be free by module which called this function */
1693                 *ppArray = calloc(length, sizeof(struct ivi_layout_surface *));
1694                 if (*ppArray == NULL) {
1695 @@ -1836,6 +1802,7 @@ ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1696         ivilayer = get_layer(&layout->layer_list, id_layer);
1697         if (ivilayer != NULL) {
1698                 weston_log("id_layer is already created\n");
1699 +               ++ivilayer->ref_count;
1700                 return ivilayer;
1701         }
1702  
1703 @@ -1845,7 +1812,7 @@ ivi_layout_layer_create_with_dimension(uint32_t id_layer,
1704                 return NULL;
1705         }
1706  
1707 -       wl_list_init(&ivilayer->link);
1708 +       ivilayer->ref_count = 1;
1709         wl_signal_init(&ivilayer->property_changed);
1710         wl_list_init(&ivilayer->screen_list);
1711         wl_list_init(&ivilayer->link_to_surface);
1712 @@ -1881,7 +1848,20 @@ ivi_layout_layer_remove_notification(struct ivi_layout_layer *ivilayer)
1713  }
1714  
1715  static void
1716 -ivi_layout_layer_remove(struct ivi_layout_layer *ivilayer)
1717 +ivi_layout_layer_remove_notification_by_callback(struct ivi_layout_layer *ivilayer,
1718 +                                                layer_property_notification_func callback,
1719 +                                                void *userdata)
1720 +{
1721 +       if (ivilayer == NULL) {
1722 +               weston_log("ivi_layout_layer_remove_notification_by_callback: invalid argument\n");
1723 +               return;
1724 +       }
1725 +
1726 +       remove_notification(&ivilayer->property_changed.listener_list, callback, userdata);
1727 +}
1728 +
1729 +static void
1730 +ivi_layout_layer_destroy(struct ivi_layout_layer *ivilayer)
1731  {
1732         struct ivi_layout *layout = get_instance();
1733  
1734 @@ -1890,20 +1870,18 @@ ivi_layout_layer_remove(struct ivi_layout_layer *ivilayer)
1735                 return;
1736         }
1737  
1738 +       if (--ivilayer->ref_count > 0)
1739 +               return;
1740 +
1741         wl_signal_emit(&layout->layer_notification.removed, ivilayer);
1742  
1743         clear_surface_pending_list(ivilayer);
1744         clear_surface_order_list(ivilayer);
1745  
1746 -       if (!wl_list_empty(&ivilayer->pending.link)) {
1747 -               wl_list_remove(&ivilayer->pending.link);
1748 -       }
1749 -       if (!wl_list_empty(&ivilayer->order.link)) {
1750 -               wl_list_remove(&ivilayer->order.link);
1751 -       }
1752 -       if (!wl_list_empty(&ivilayer->link)) {
1753 -               wl_list_remove(&ivilayer->link);
1754 -       }
1755 +       wl_list_remove(&ivilayer->pending.link);
1756 +       wl_list_remove(&ivilayer->order.link);
1757 +       wl_list_remove(&ivilayer->link);
1758 +
1759         remove_orderlayer_from_screen(ivilayer);
1760         remove_link_to_surface(ivilayer);
1761         ivi_layout_layer_remove_notification(ivilayer);
1762 @@ -1925,7 +1903,10 @@ ivi_layout_layer_set_visibility(struct ivi_layout_layer *ivilayer,
1763         prop = &ivilayer->pending.prop;
1764         prop->visibility = newVisibility;
1765  
1766 -       ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1767 +       if (ivilayer->prop.visibility != newVisibility)
1768 +               ivilayer->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1769 +       else
1770 +               ivilayer->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
1771  
1772         return IVI_SUCCEEDED;
1773  }
1774 @@ -1947,7 +1928,9 @@ ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1775  {
1776         struct ivi_layout_layer_properties *prop = NULL;
1777  
1778 -       if (ivilayer == NULL) {
1779 +       if (ivilayer == NULL ||
1780 +           opacity < wl_fixed_from_double(0.0) ||
1781 +           wl_fixed_from_double(1.0) < opacity) {
1782                 weston_log("ivi_layout_layer_set_opacity: invalid argument\n");
1783                 return IVI_FAILED;
1784         }
1785 @@ -1955,7 +1938,10 @@ ivi_layout_layer_set_opacity(struct ivi_layout_layer *ivilayer,
1786         prop = &ivilayer->pending.prop;
1787         prop->opacity = opacity;
1788  
1789 -       ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1790 +       if (ivilayer->prop.opacity != opacity)
1791 +               ivilayer->event_mask |= IVI_NOTIFICATION_OPACITY;
1792 +       else
1793 +               ivilayer->event_mask &= ~IVI_NOTIFICATION_OPACITY;
1794  
1795         return IVI_SUCCEEDED;
1796  }
1797 @@ -1989,7 +1975,12 @@ ivi_layout_layer_set_source_rectangle(struct ivi_layout_layer *ivilayer,
1798         prop->source_width = width;
1799         prop->source_height = height;
1800  
1801 -       ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1802 +       if (ivilayer->prop.source_x != x || ivilayer->prop.source_y != y ||
1803 +           ivilayer->prop.source_width != width ||
1804 +           ivilayer->prop.source_height != height)
1805 +               ivilayer->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
1806 +       else
1807 +               ivilayer->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
1808  
1809         return IVI_SUCCEEDED;
1810  }
1811 @@ -2012,7 +2003,12 @@ ivi_layout_layer_set_destination_rectangle(struct ivi_layout_layer *ivilayer,
1812         prop->dest_width = width;
1813         prop->dest_height = height;
1814  
1815 -       ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1816 +       if (ivilayer->prop.dest_x != x || ivilayer->prop.dest_y != y ||
1817 +           ivilayer->prop.dest_width != width ||
1818 +           ivilayer->prop.dest_height != height)
1819 +               ivilayer->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1820 +       else
1821 +               ivilayer->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
1822  
1823         return IVI_SUCCEEDED;
1824  }
1825 @@ -2048,7 +2044,11 @@ ivi_layout_layer_set_dimension(struct ivi_layout_layer *ivilayer,
1826         prop->dest_width  = dest_width;
1827         prop->dest_height = dest_height;
1828  
1829 -       ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
1830 +       if (ivilayer->prop.dest_width != dest_width ||
1831 +           ivilayer->prop.dest_height != dest_height)
1832 +               ivilayer->event_mask |= IVI_NOTIFICATION_DIMENSION;
1833 +       else
1834 +               ivilayer->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
1835  
1836         return IVI_SUCCEEDED;
1837  }
1838 @@ -2083,7 +2083,10 @@ ivi_layout_layer_set_position(struct ivi_layout_layer *ivilayer,
1839         prop->dest_x = dest_x;
1840         prop->dest_y = dest_y;
1841  
1842 -       ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
1843 +       if (ivilayer->prop.dest_x != dest_x || ivilayer->prop.dest_y != dest_y)
1844 +               ivilayer->event_mask |= IVI_NOTIFICATION_POSITION;
1845 +       else
1846 +               ivilayer->event_mask &= ~IVI_NOTIFICATION_POSITION;
1847  
1848         return IVI_SUCCEEDED;
1849  }
1850 @@ -2102,7 +2105,10 @@ ivi_layout_layer_set_orientation(struct ivi_layout_layer *ivilayer,
1851         prop = &ivilayer->pending.prop;
1852         prop->orientation = orientation;
1853  
1854 -       ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1855 +       if (ivilayer->prop.orientation != orientation)
1856 +               ivilayer->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1857 +       else
1858 +               ivilayer->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
1859  
1860         return IVI_SUCCEEDED;
1861  }
1862 @@ -2134,17 +2140,7 @@ ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1863                 return IVI_FAILED;
1864         }
1865  
1866 -       if (pSurface == NULL) {
1867 -               wl_list_for_each_safe(ivisurf, next, &ivilayer->pending.surface_list, pending.link) {
1868 -                       if (!wl_list_empty(&ivisurf->pending.link)) {
1869 -                               wl_list_remove(&ivisurf->pending.link);
1870 -                       }
1871 -
1872 -                       wl_list_init(&ivisurf->pending.link);
1873 -               }
1874 -               ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
1875 -               return IVI_SUCCEEDED;
1876 -       }
1877 +       clear_surface_pending_list(ivilayer);
1878  
1879         for (i = 0; i < number; i++) {
1880                 id_surface = &pSurface[i]->id_surface;
1881 @@ -2154,17 +2150,14 @@ ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
1882                                 continue;
1883                         }
1884  
1885 -                       if (!wl_list_empty(&ivisurf->pending.link)) {
1886 -                               wl_list_remove(&ivisurf->pending.link);
1887 -                       }
1888 -                       wl_list_init(&ivisurf->pending.link);
1889 +                       wl_list_remove(&ivisurf->pending.link);
1890                         wl_list_insert(&ivilayer->pending.surface_list,
1891                                        &ivisurf->pending.link);
1892                         break;
1893                 }
1894         }
1895  
1896 -       ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
1897 +       ivilayer->order.dirty = 1;
1898  
1899         return IVI_SUCCEEDED;
1900  }
1901 @@ -2183,7 +2176,10 @@ ivi_layout_surface_set_visibility(struct ivi_layout_surface *ivisurf,
1902         prop = &ivisurf->pending.prop;
1903         prop->visibility = newVisibility;
1904  
1905 -       ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1906 +       if (ivisurf->prop.visibility != newVisibility)
1907 +               ivisurf->event_mask |= IVI_NOTIFICATION_VISIBILITY;
1908 +       else
1909 +               ivisurf->event_mask &= ~IVI_NOTIFICATION_VISIBILITY;
1910  
1911         return IVI_SUCCEEDED;
1912  }
1913 @@ -2205,7 +2201,9 @@ ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1914  {
1915         struct ivi_layout_surface_properties *prop = NULL;
1916  
1917 -       if (ivisurf == NULL) {
1918 +       if (ivisurf == NULL ||
1919 +           opacity < wl_fixed_from_double(0.0) ||
1920 +           wl_fixed_from_double(1.0) < opacity) {
1921                 weston_log("ivi_layout_surface_set_opacity: invalid argument\n");
1922                 return IVI_FAILED;
1923         }
1924 @@ -2213,7 +2211,10 @@ ivi_layout_surface_set_opacity(struct ivi_layout_surface *ivisurf,
1925         prop = &ivisurf->pending.prop;
1926         prop->opacity = opacity;
1927  
1928 -       ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
1929 +       if (ivisurf->prop.opacity != opacity)
1930 +               ivisurf->event_mask |= IVI_NOTIFICATION_OPACITY;
1931 +       else
1932 +               ivisurf->event_mask &= ~IVI_NOTIFICATION_OPACITY;
1933  
1934         return IVI_SUCCEEDED;
1935  }
1936 @@ -2251,7 +2252,12 @@ ivi_layout_surface_set_destination_rectangle(struct ivi_layout_surface *ivisurf,
1937         prop->dest_width = width;
1938         prop->dest_height = height;
1939  
1940 -       ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1941 +       if (ivisurf->prop.dest_x != x || ivisurf->prop.dest_y != y ||
1942 +           ivisurf->prop.dest_width != width ||
1943 +           ivisurf->prop.dest_height != height)
1944 +               ivisurf->event_mask |= IVI_NOTIFICATION_DEST_RECT;
1945 +       else
1946 +               ivisurf->event_mask &= ~IVI_NOTIFICATION_DEST_RECT;
1947  
1948         return IVI_SUCCEEDED;
1949  }
1950 @@ -2271,7 +2277,11 @@ ivi_layout_surface_set_dimension(struct ivi_layout_surface *ivisurf,
1951         prop->dest_width  = dest_width;
1952         prop->dest_height = dest_height;
1953  
1954 -       ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
1955 +       if (ivisurf->prop.dest_width != dest_width ||
1956 +           ivisurf->prop.dest_height != dest_height)
1957 +               ivisurf->event_mask |= IVI_NOTIFICATION_DIMENSION;
1958 +       else
1959 +               ivisurf->event_mask &= ~IVI_NOTIFICATION_DIMENSION;
1960  
1961         return IVI_SUCCEEDED;
1962  }
1963 @@ -2306,7 +2316,10 @@ ivi_layout_surface_set_position(struct ivi_layout_surface *ivisurf,
1964         prop->dest_x = dest_x;
1965         prop->dest_y = dest_y;
1966  
1967 -       ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
1968 +       if (ivisurf->prop.dest_x != dest_x || ivisurf->prop.dest_y != dest_y)
1969 +               ivisurf->event_mask |= IVI_NOTIFICATION_POSITION;
1970 +       else
1971 +               ivisurf->event_mask &= ~IVI_NOTIFICATION_POSITION;
1972  
1973         return IVI_SUCCEEDED;
1974  }
1975 @@ -2340,7 +2353,10 @@ ivi_layout_surface_set_orientation(struct ivi_layout_surface *ivisurf,
1976         prop = &ivisurf->pending.prop;
1977         prop->orientation = orientation;
1978  
1979 -       ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1980 +       if (ivisurf->prop.orientation != orientation)
1981 +               ivisurf->event_mask |= IVI_NOTIFICATION_ORIENTATION;
1982 +       else
1983 +               ivisurf->event_mask &= ~IVI_NOTIFICATION_ORIENTATION;
1984  
1985         return IVI_SUCCEEDED;
1986  }
1987 @@ -2378,17 +2394,14 @@ ivi_layout_screen_add_layer(struct ivi_layout_screen *iviscrn,
1988  
1989         wl_list_for_each_safe(ivilayer, next, &layout->layer_list, link) {
1990                 if (ivilayer->id_layer == addlayer->id_layer) {
1991 -                       if (!wl_list_empty(&ivilayer->pending.link)) {
1992 -                               wl_list_remove(&ivilayer->pending.link);
1993 -                       }
1994 -                       wl_list_init(&ivilayer->pending.link);
1995 +                       wl_list_remove(&ivilayer->pending.link);
1996                         wl_list_insert(&iviscrn->pending.layer_list,
1997                                        &ivilayer->pending.link);
1998                         break;
1999                 }
2000         }
2001  
2002 -       iviscrn->event_mask |= IVI_NOTIFICATION_ADD;
2003 +       iviscrn->order.dirty = 1;
2004  
2005         return IVI_SUCCEEDED;
2006  }
2007 @@ -2411,23 +2424,11 @@ ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2008  
2009         wl_list_for_each_safe(ivilayer, next,
2010                               &iviscrn->pending.layer_list, pending.link) {
2011 +               wl_list_remove(&ivilayer->pending.link);
2012                 wl_list_init(&ivilayer->pending.link);
2013         }
2014  
2015 -       wl_list_init(&iviscrn->pending.layer_list);
2016 -
2017 -       if (pLayer == NULL) {
2018 -               wl_list_for_each_safe(ivilayer, next, &iviscrn->pending.layer_list, pending.link) {
2019 -                       if (!wl_list_empty(&ivilayer->pending.link)) {
2020 -                               wl_list_remove(&ivilayer->pending.link);
2021 -                       }
2022 -
2023 -                       wl_list_init(&ivilayer->pending.link);
2024 -               }
2025 -
2026 -               iviscrn->event_mask |= IVI_NOTIFICATION_REMOVE;
2027 -               return IVI_SUCCEEDED;
2028 -       }
2029 +       assert(wl_list_empty(&iviscrn->pending.layer_list));
2030  
2031         for (i = 0; i < number; i++) {
2032                 id_layer = &pLayer[i]->id_layer;
2033 @@ -2436,17 +2437,14 @@ ivi_layout_screen_set_render_order(struct ivi_layout_screen *iviscrn,
2034                                 continue;
2035                         }
2036  
2037 -                       if (!wl_list_empty(&ivilayer->pending.link)) {
2038 -                               wl_list_remove(&ivilayer->pending.link);
2039 -                       }
2040 -                       wl_list_init(&ivilayer->pending.link);
2041 +                       wl_list_remove(&ivilayer->pending.link);
2042                         wl_list_insert(&iviscrn->pending.layer_list,
2043                                        &ivilayer->pending.link);
2044                         break;
2045                 }
2046         }
2047  
2048 -       iviscrn->event_mask |= IVI_NOTIFICATION_ADD;
2049 +       iviscrn->order.dirty = 1;
2050  
2051         return IVI_SUCCEEDED;
2052  }
2053 @@ -2555,17 +2553,14 @@ ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
2054  
2055         wl_list_for_each_safe(ivisurf, next, &layout->surface_list, link) {
2056                 if (ivisurf->id_surface == addsurf->id_surface) {
2057 -                       if (!wl_list_empty(&ivisurf->pending.link)) {
2058 -                               wl_list_remove(&ivisurf->pending.link);
2059 -                       }
2060 -                       wl_list_init(&ivisurf->pending.link);
2061 +                       wl_list_remove(&ivisurf->pending.link);
2062                         wl_list_insert(&ivilayer->pending.surface_list,
2063                                        &ivisurf->pending.link);
2064                         break;
2065                 }
2066         }
2067  
2068 -       ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
2069 +       ivilayer->order.dirty = 1;
2070  
2071         return IVI_SUCCEEDED;
2072  }
2073 @@ -2585,15 +2580,13 @@ ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
2074         wl_list_for_each_safe(ivisurf, next,
2075                               &ivilayer->pending.surface_list, pending.link) {
2076                 if (ivisurf->id_surface == remsurf->id_surface) {
2077 -                       if (!wl_list_empty(&ivisurf->pending.link)) {
2078 -                               wl_list_remove(&ivisurf->pending.link);
2079 -                       }
2080 +                       wl_list_remove(&ivisurf->pending.link);
2081                         wl_list_init(&ivisurf->pending.link);
2082                         break;
2083                 }
2084         }
2085  
2086 -       remsurf->event_mask |= IVI_NOTIFICATION_REMOVE;
2087 +       ivilayer->order.dirty = 1;
2088  }
2089  
2090  static int32_t
2091 @@ -2614,7 +2607,12 @@ ivi_layout_surface_set_source_rectangle(struct ivi_layout_surface *ivisurf,
2092         prop->source_width = width;
2093         prop->source_height = height;
2094  
2095 -       ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2096 +       if (ivisurf->prop.source_x != x || ivisurf->prop.source_y != y ||
2097 +           ivisurf->prop.source_width != width ||
2098 +           ivisurf->prop.source_height != height)
2099 +               ivisurf->event_mask |= IVI_NOTIFICATION_SOURCE_RECT;
2100 +       else
2101 +               ivisurf->event_mask &= ~IVI_NOTIFICATION_SOURCE_RECT;
2102  
2103         return IVI_SUCCEEDED;
2104  }
2105 @@ -2731,7 +2729,7 @@ ivi_layout_get_weston_view(struct ivi_layout_surface *surface)
2106  {
2107         struct weston_view *tmpview = NULL;
2108  
2109 -       if(surface == NULL)
2110 +       if (surface == NULL)
2111                 return NULL;
2112  
2113         wl_list_for_each(tmpview, &surface->surface->views, surface_link)
2114 @@ -2796,7 +2794,6 @@ ivi_layout_surface_create(struct weston_surface *wl_surface,
2115                 return NULL;
2116         }
2117  
2118 -       wl_list_init(&ivisurf->link);
2119         wl_signal_init(&ivisurf->property_changed);
2120         wl_signal_init(&ivisurf->configured);
2121         wl_list_init(&ivisurf->layer_list);
2122 @@ -2804,10 +2801,6 @@ ivi_layout_surface_create(struct weston_surface *wl_surface,
2123         ivisurf->layout = layout;
2124  
2125         ivisurf->surface = wl_surface;
2126 -       ivisurf->surface_destroy_listener.notify =
2127 -               westonsurface_destroy_from_ivisurface;
2128 -       wl_resource_add_destroy_listener(wl_surface->resource,
2129 -                                        &ivisurf->surface_destroy_listener);
2130  
2131         tmpview = weston_view_create(wl_surface);
2132         if (tmpview == NULL) {
2133 @@ -2817,17 +2810,8 @@ ivi_layout_surface_create(struct weston_surface *wl_surface,
2134         ivisurf->surface->width_from_buffer  = 0;
2135         ivisurf->surface->height_from_buffer = 0;
2136  
2137 -       weston_matrix_init(&ivisurf->surface_rotation.matrix);
2138 -       weston_matrix_init(&ivisurf->layer_rotation.matrix);
2139 -       weston_matrix_init(&ivisurf->surface_pos.matrix);
2140 -       weston_matrix_init(&ivisurf->layer_pos.matrix);
2141 -       weston_matrix_init(&ivisurf->scaling.matrix);
2142 -
2143 -       wl_list_init(&ivisurf->surface_rotation.link);
2144 -       wl_list_init(&ivisurf->layer_rotation.link);
2145 -       wl_list_init(&ivisurf->surface_pos.link);
2146 -       wl_list_init(&ivisurf->layer_pos.link);
2147 -       wl_list_init(&ivisurf->scaling.link);
2148 +       weston_matrix_init(&ivisurf->transform.matrix);
2149 +       wl_list_init(&ivisurf->transform.link);
2150  
2151         init_surface_properties(&ivisurf->prop);
2152         ivisurf->event_mask = 0;
2153 @@ -2927,7 +2911,7 @@ static struct ivi_controller_interface ivi_controller_interface = {
2154         .add_notification_remove_layer          = ivi_layout_add_notification_remove_layer,
2155         .remove_notification_remove_layer       = ivi_layout_remove_notification_remove_layer,
2156         .layer_create_with_dimension            = ivi_layout_layer_create_with_dimension,
2157 -       .layer_remove                           = ivi_layout_layer_remove,
2158 +       .layer_destroy                          = ivi_layout_layer_destroy,
2159         .get_layers                             = ivi_layout_get_layers,
2160         .get_id_of_layer                        = ivi_layout_get_id_of_layer,
2161         .get_layer_from_id                      = ivi_layout_get_layer_from_id,
2162 @@ -2954,7 +2938,7 @@ static struct ivi_controller_interface ivi_controller_interface = {
2163         .layer_set_transition                   = ivi_layout_layer_set_transition,
2164  
2165         /**
2166 -        * screen controller interfaces
2167 +        * screen controller interfaces part1
2168          */
2169         .get_screen_from_id             = ivi_layout_get_screen_from_id,
2170         .get_screen_resolution          = ivi_layout_get_screen_resolution,
2171 @@ -2975,6 +2959,17 @@ static struct ivi_controller_interface ivi_controller_interface = {
2172          */
2173         .surface_get_size               = ivi_layout_surface_get_size,
2174         .surface_dump                   = ivi_layout_surface_dump,
2175 +
2176 +       /**
2177 +        * remove notification by callback on property changes of ivi_surface/layer
2178 +        */
2179 +       .surface_remove_notification_by_callback        = ivi_layout_surface_remove_notification_by_callback,
2180 +       .layer_remove_notification_by_callback          = ivi_layout_layer_remove_notification_by_callback,
2181 +
2182 +       /**
2183 +        * screen controller interfaces part2
2184 +        */
2185 +       .get_id_of_screen       = ivi_layout_get_id_of_screen
2186  };
2187  
2188  int
2189 diff --git a/ivi-shell/ivi-shell.c b/ivi-shell/ivi-shell.c
2190 index 4a688cc..4c63410 100644
2191 --- a/ivi-shell/ivi-shell.c
2192 +++ b/ivi-shell/ivi-shell.c
2193 @@ -1,23 +1,26 @@
2194  /*
2195   * Copyright (C) 2013 DENSO CORPORATION
2196   *
2197 - * Permission to use, copy, modify, distribute, and sell this software and
2198 - * its documentation for any purpose is hereby granted without fee, provided
2199 - * that the above copyright notice appear in all copies and that both that
2200 - * copyright notice and this permission notice appear in supporting
2201 - * documentation, and that the name of the copyright holders not be used in
2202 - * advertising or publicity pertaining to distribution of the software
2203 - * without specific, written prior permission.  The copyright holders make
2204 - * no representations about the suitability of this software for any
2205 - * purpose.  It is provided "as is" without express or implied warranty.
2206 + * Permission is hereby granted, free of charge, to any person obtaining
2207 + * a copy of this software and associated documentation files (the
2208 + * "Software"), to deal in the Software without restriction, including
2209 + * without limitation the rights to use, copy, modify, merge, publish,
2210 + * distribute, sublicense, and/or sell copies of the Software, and to
2211 + * permit persons to whom the Software is furnished to do so, subject to
2212 + * the following conditions:
2213   *
2214 - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
2215 - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
2216 - * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
2217 - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
2218 - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
2219 - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
2220 - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2221 + * The above copyright notice and this permission notice (including the
2222 + * next paragraph) shall be included in all copies or substantial
2223 + * portions of the Software.
2224 + *
2225 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2226 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2227 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2228 + * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2229 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2230 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2231 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2232 + * SOFTWARE.
2233   */
2234  
2235  /*
2236 @@ -126,6 +129,22 @@ ivi_shell_surface_configure(struct weston_surface *surface,
2237         }
2238  }
2239  
2240 +static void
2241 +layout_surface_cleanup(struct ivi_shell_surface *ivisurf)
2242 +{
2243 +       assert(ivisurf->layout_surface != NULL);
2244 +
2245 +       ivi_layout_surface_destroy(ivisurf->layout_surface);
2246 +       ivisurf->layout_surface = NULL;
2247 +
2248 +       ivisurf->surface->configure = NULL;
2249 +       ivisurf->surface->configure_private = NULL;
2250 +       ivisurf->surface = NULL;
2251 +
2252 +       // destroy weston_surface destroy signal.
2253 +       wl_list_remove(&ivisurf->surface_destroy_listener.link);
2254 +}
2255 +
2256  /*
2257   * The ivi_surface wl_resource destructor.
2258   *
2259 @@ -135,9 +154,18 @@ static void
2260  shell_destroy_shell_surface(struct wl_resource *resource)
2261  {
2262         struct ivi_shell_surface *ivisurf = wl_resource_get_user_data(resource);
2263 -       if (ivisurf != NULL) {
2264 -               ivisurf->resource = NULL;
2265 -       }
2266 +
2267 +       if (ivisurf == NULL)
2268 +               return;
2269 +
2270 +       assert(ivisurf->resource == resource);
2271 +
2272 +       if (ivisurf->layout_surface != NULL)
2273 +               layout_surface_cleanup(ivisurf);
2274 +
2275 +       wl_list_remove(&ivisurf->link);
2276 +
2277 +       free(ivisurf);
2278  }
2279  
2280  /* Gets called through the weston_surface destroy signal. */
2281 @@ -150,21 +178,8 @@ shell_handle_surface_destroy(struct wl_listener *listener, void *data)
2282  
2283         assert(ivisurf != NULL);
2284  
2285 -       if (ivisurf->surface!=NULL) {
2286 -               ivisurf->surface->configure = NULL;
2287 -               ivisurf->surface->configure_private = NULL;
2288 -               ivisurf->surface = NULL;
2289 -       }
2290 -
2291 -       wl_list_remove(&ivisurf->surface_destroy_listener.link);
2292 -       wl_list_remove(&ivisurf->link);
2293 -
2294 -       if (ivisurf->resource != NULL) {
2295 -               wl_resource_set_user_data(ivisurf->resource, NULL);
2296 -               ivisurf->resource = NULL;
2297 -       }
2298 -       free(ivisurf);
2299 -
2300 +       if (ivisurf->layout_surface != NULL)
2301 +               layout_surface_cleanup(ivisurf);
2302  }
2303  
2304  /* Gets called, when a client sends ivi_surface.destroy request. */
2305 @@ -219,7 +234,7 @@ application_surface_create(struct wl_client *client,
2306         layout_surface = ivi_layout_surface_create(weston_surface, id_surface);
2307  
2308         /* check if id_ivi is already used for wl_surface*/
2309 -       if (layout_surface == NULL){
2310 +       if (layout_surface == NULL) {
2311                 wl_resource_post_error(resource,
2312                                        IVI_APPLICATION_ERROR_IVI_ID,
2313                                        "surface_id is already assigned "
2314 @@ -338,8 +353,8 @@ shell_destroy(struct wl_listener *listener, void *data)
2315  }
2316  
2317  static void
2318 -terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
2319 -                 void *data)
2320 +terminate_binding(struct weston_seat *seat, uint32_t time,
2321 +                 uint32_t key, void *data)
2322  {
2323         struct weston_compositor *compositor = data;
2324  
2325 @@ -423,6 +438,8 @@ module_init(struct weston_compositor *compositor,
2326         if (input_panel_setup(shell) < 0)
2327                 goto out_settings;
2328  
2329 +       text_backend_init(compositor);
2330 +
2331         if (wl_global_create(compositor->wl_display,
2332                              &ivi_application_interface, 1,
2333                              shell, bind_ivi_application) == NULL)
2334 diff --git a/ivi-shell/ivi-shell.h b/ivi-shell/ivi-shell.h
2335 index 2f42173..9a05eb2 100644
2336 --- a/ivi-shell/ivi-shell.h
2337 +++ b/ivi-shell/ivi-shell.h
2338 @@ -1,23 +1,26 @@
2339  /*
2340   * Copyright (C) 2013 DENSO CORPORATION
2341   *
2342 - * Permission to use, copy, modify, distribute, and sell this software and
2343 - * its documentation for any purpose is hereby granted without fee, provided
2344 - * that the above copyright notice appear in all copies and that both that
2345 - * copyright notice and this permission notice appear in supporting
2346 - * documentation, and that the name of the copyright holders not be used in
2347 - * advertising or publicity pertaining to distribution of the software
2348 - * without specific, written prior permission.  The copyright holders make
2349 - * no representations about the suitability of this software for any
2350 - * purpose.  It is provided "as is" without express or implied warranty.
2351 + * Permission is hereby granted, free of charge, to any person obtaining
2352 + * a copy of this software and associated documentation files (the
2353 + * "Software"), to deal in the Software without restriction, including
2354 + * without limitation the rights to use, copy, modify, merge, publish,
2355 + * distribute, sublicense, and/or sell copies of the Software, and to
2356 + * permit persons to whom the Software is furnished to do so, subject to
2357 + * the following conditions:
2358   *
2359 - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
2360 - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
2361 - * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
2362 - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
2363 - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
2364 - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
2365 - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2366 + * The above copyright notice and this permission notice (including the
2367 + * next paragraph) shall be included in all copies or substantial
2368 + * portions of the Software.
2369 + *
2370 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2371 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2372 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2373 + * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2374 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2375 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2376 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2377 + * SOFTWARE.
2378   */
2379  
2380  #include <stdbool.h>
2381 @@ -32,6 +35,8 @@ struct ivi_shell
2382  
2383         struct wl_list ivi_surface_list; /* struct ivi_shell_surface::link */
2384  
2385 +       struct text_backend *text_backend;
2386 +
2387         struct wl_listener show_input_panel_listener;
2388         struct wl_listener hide_input_panel_listener;
2389         struct wl_listener update_input_panel_listener;
2390 -- 
2391 1.8.3.1
2392