Fix build against Weston 1.6 IVI Shell
[profile/ivi/ico-uxf-weston-plugin.git] / src / ico_window_animation.c
1 /*
2  * Copyright © 2010-2011 Intel Corporation
3  * Copyright © 2008-2011 Kristian Høgsberg
4  * Copyright © 2013-2014 TOYOTA MOTOR CORPORATION.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and
7  * its documentation for any purpose is hereby granted without fee, provided
8  * that the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of the copyright holders not be used in
11  * advertising or publicity pertaining to distribution of the software
12  * without specific, written prior permission.  The copyright holders make
13  * no representations about the suitability of this software for any
14  * purpose.  It is provided "as is" without express or implied warranty.
15  *
16  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
21  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23  */
24 /**
25  * @brief   Window Animation (Weston(Wayland) PlugIn)
26  *
27  * @date    Feb-21-2014
28  */
29
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <stdbool.h>
33 #include <string.h>
34 #include <unistd.h>
35 #include <math.h>
36 #include <time.h>
37 #include <sys/types.h>
38 #include <sys/time.h>
39 #include <sys/stat.h>
40
41 #include <weston/compositor.h>
42 #include <weston/ivi-layout-export.h>
43 #include "ico_ivi_common_private.h"
44 #include "ico_window_mgr_private.h"
45
46 /* Animation type               */
47 #define ANIMA_ZOOM              1           /* ZoomIn/ZoomOut                       */
48 #define ANIMA_FADE              2           /* FadeIn/FadeOut                       */
49 #define ANIMA_SLIDE_TORIGHT    11           /* SlideIn left to right/SlideOut right to left */
50 #define ANIMA_SLIDE_TOLEFT     12           /* SlideIn right to left/SlideOut left to right */
51 #define ANIMA_SLIDE_TOBOTTOM   13           /* SlideIn top to bottom/SlideOut bottom to top */
52 #define ANIMA_SLIDE_TOTOP      14           /* SlideIn bottom to top/SlideOut top to bottom */
53 #define ANIMA_WIPE_TORIGHT     21           /* WipeIn left to right/WipeOut right to left   */
54 #define ANIMA_WIPE_TOLEFT      22           /* WipeIn right to left/WipeOut left to right   */
55 #define ANIMA_WIPE_TOBOTTOM    23           /* WipeIn top to bottom/WipeOut bottom to top   */
56 #define ANIMA_WIPE_TOTOP       24           /* WipeIn bottom to top/WipeOut top to bottom   */
57 #define ANIMA_SWING_TORIGHT    31           /* SwingIn left to right/SwingOut right to left */
58 #define ANIMA_SWING_TOLEFT     32           /* SwingIn right to left/SwingOut left to right */
59 #define ANIMA_SWING_TOBOTTOM   33           /* SwingIn top to bottom/SwingOut bottom to top */
60 #define ANIMA_SWING_TOTOP      34           /* SwingIn bottom to top/SwingOut top to bottom */
61
62 /* animation data               */
63 struct animation_data   {
64     struct animation_data   *next_free;     /* free data list                       */
65     char    transform_set;                  /* need transform reset at end          */
66     char    res[3];                         /* (unused)                             */
67     struct weston_transform transform;      /* transform matrix                     */
68     void    (*end_function)(struct weston_animation *animation);
69                                             /* animation end function               */
70 };
71
72 /* static valiables             */
73 static struct weston_compositor *weston_ec; /* Weston compositor                    */
74 static char *default_animation;             /* default animation name               */
75 static int  animation_fps;                  /* animation frame rate(frame/sec)      */
76 static int  animation_time;                 /* default animation time(ms)           */
77 static int  animation_count;                /* current number of animations         */
78 static struct animation_data    *free_data; /* free data list                       */
79
80 /* support animation names      */
81 static const struct _supprt_animaetions {
82     char    *name;
83     int     animaid;
84 }               supprt_animaetions[] = {
85     { "fade", ANIMA_FADE },
86     { "zoom", ANIMA_ZOOM },
87     { "slide", ANIMA_SLIDE_TOTOP },
88     { "slide.toleft", ANIMA_SLIDE_TOLEFT },
89     { "slide.toright", ANIMA_SLIDE_TORIGHT },
90     { "slide.totop", ANIMA_SLIDE_TOTOP },
91     { "slide.tobottom", ANIMA_SLIDE_TOBOTTOM },
92     { "wipe", ANIMA_WIPE_TOTOP },
93     { "wipe.toleft", ANIMA_WIPE_TOLEFT },
94     { "wipe.toright", ANIMA_WIPE_TORIGHT },
95     { "wipe.totop", ANIMA_WIPE_TOTOP },
96     { "wipe.tobottom", ANIMA_WIPE_TOBOTTOM },
97     { "swing", ANIMA_SWING_TOTOP },
98     { "swing.toleft", ANIMA_SWING_TOLEFT },
99     { "swing.toright", ANIMA_SWING_TORIGHT },
100     { "swing.totop", ANIMA_SWING_TOTOP },
101     { "swing.tobottom", ANIMA_SWING_TOBOTTOM },
102     { "\0", -1 }
103 };
104
105 /* static function              */
106                                             /* slide animation                      */
107 static void animation_slide(struct weston_animation *animation,
108                             struct weston_output *output, uint32_t msecs);
109                                             /* wipe animation                       */
110 static void animation_wipe(struct weston_animation *animation,
111                            struct weston_output *output, uint32_t msecs);
112                                             /* swing animation                      */
113 static void animation_swing(struct weston_animation *animation,
114                             struct weston_output *output, uint32_t msecs);
115                                             /* swing animation end                  */
116 static void animation_swing_end(struct weston_animation *animation);
117                                             /* fade animation                       */
118 static void animation_fade(struct weston_animation *animation,
119                            struct weston_output *output, uint32_t msecs);
120                                             /* fade animation end                   */
121 static void animation_fade_end(struct weston_animation *animation);
122                                             /* slide animation end                  */
123 static void animation_slide_end(struct weston_animation *animation);
124                                             /* zoom animation                       */
125 static void animation_zoom(struct weston_animation *animation,
126                            struct weston_output *output, uint32_t msecs);
127                                             /* zoom animation end                   */
128 static void animation_zoom_end(struct weston_animation *animation);
129                                             /* continue animation                   */
130 static int animation_cont(struct weston_animation *animation,
131                           struct weston_output *output, uint32_t msecs);
132                                             /* terminate animation                  */
133 static void animation_end(struct uifw_win_surface *usurf, const int disp);
134
135 /*--------------------------------------------------------------------------*/
136 /**
137  * @brief   ico_window_animation: Animation addin entry
138  *
139  * @param[in]   op      animation operation
140  * @param[in]   data    data
141  * @return      result
142  * @retval      ICO_WINDOW_MGR_ANIMATION_RET_ANIMA      success
143  * @retval      ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL success(no control)
144  * @retval      ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA    error(no animation)
145  */
146 /*--------------------------------------------------------------------------*/
147 static int
148 ico_window_animation(const int op, void *data)
149 {
150     struct uifw_win_surface *usurf;
151     struct weston_output *output;
152     int         idx;
153     int         ret;
154     uint32_t    nowsec;
155     int         animaid;
156
157     if (op == ICO_WINDOW_MGR_ANIMATION_NAME)    {
158         /* convert animation name to animation type value   */
159         for (idx = 0; supprt_animaetions[idx].animaid > 0; idx++)   {
160             if (strcasecmp(supprt_animaetions[idx].name, (char *)data) == 0)    {
161                 uifw_trace("ico_window_animation: Type %s(%d)",
162                            (char *)data, supprt_animaetions[idx].animaid);
163                 return supprt_animaetions[idx].animaid;
164             }
165         }
166         uifw_warn("ico_window_animation: Unknown Type %s", (char *)data);
167         return ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
168     }
169
170     usurf = (struct uifw_win_surface *)data;
171
172     if (op == ICO_WINDOW_MGR_ANIMATION_DESTROY) {
173         if ((usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE) ||
174             (usurf->animation.animadata != NULL)) {
175             uifw_trace("ico_window_animation: Destroy %08x", usurf->surfaceid);
176             animation_end(usurf, 0);
177         }
178         return ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
179     }
180
181     usurf->animation.visible = ICO_WINDOW_MGR_ANIMA_NOCONTROL_AT_END;
182
183     if (op == ICO_WINDOW_MGR_ANIMATION_OPCANCEL)    {
184         /* cancel animation                     */
185         if ((usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE) &&
186             (usurf->animation.animation.frame != NULL)) {
187             uifw_trace("ico_window_animation: cancel %s.%08x",
188                        usurf->uclient->appid, usurf->surfaceid);
189             (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 0);
190         }
191         animation_end(usurf, 1);
192         ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
193     }
194     else    {
195         /* setup animation              */
196         if ((usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_NONE) ||
197             (usurf->animation.current > 95))    {
198             usurf->animation.animation.frame_counter = 1;
199             usurf->animation.current = 0;
200             usurf->animation.ahalf = 0;
201             if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_NONE)  {
202                 wl_list_init(&usurf->animation.animation.link);
203                 output = container_of(weston_ec->output_list.next,
204                                       struct weston_output, link);
205                 wl_list_insert(output->animation_list.prev,
206                                &usurf->animation.animation.link);
207                 animation_count ++;
208             }
209         }
210         else if (((usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW) &&
211                   ((op == ICO_WINDOW_MGR_ANIMATION_OPHIDE) ||
212                    (op == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS))) ||
213                  ((usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_HIDE) &&
214                   ((op == ICO_WINDOW_MGR_ANIMATION_OPSHOW) ||
215                    (op == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS))))   {
216             /* change ...In(ex.FadeIn) to ...Out(FadeOut) or ...Out to ...In    */
217             nowsec = weston_compositor_get_time();
218             usurf->animation.current = 100 - usurf->animation.current;
219             if ((op == ICO_WINDOW_MGR_ANIMATION_OPHIDE)||
220                 (op == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS)) {
221                 usurf->animation.time = usurf->animation.hide_time;
222             }
223             else    {
224                 usurf->animation.time = usurf->animation.show_time;
225             }
226             if (usurf->animation.time == 0) {
227                 usurf->animation.time = animation_time;
228             }
229             ret = ((usurf->animation.current) * usurf->animation.time) / 100;
230             if (nowsec >= (uint32_t)ret)    {
231                 usurf->animation.starttime = nowsec - ret;
232             }
233             else    {
234                 usurf->animation.starttime = ((long long)nowsec) + ((long long)0x100000000L)
235                                              - ((long long)ret);
236             }
237             usurf->animation.animation.frame_counter = 2;
238         }
239
240         /* set animation function       */
241         if ((op == ICO_WINDOW_MGR_ANIMATION_OPSHOW) ||
242             (op == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS)) {
243             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_SHOW;
244             animaid = usurf->animation.show_anima;
245             usurf->animation.anima = animaid;
246             uifw_trace("ico_window_animation: show(in) %s.%08x anima=%d",
247                        usurf->uclient->appid, usurf->surfaceid, animaid);
248             ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
249         }
250         else if ((op == ICO_WINDOW_MGR_ANIMATION_OPHIDE) ||
251                  (op == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS))    {
252             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_HIDE;
253             animaid = usurf->animation.hide_anima;
254             usurf->animation.anima = animaid;
255             uifw_trace("ico_window_animation: hide(out) %s.%08x anima=%d",
256                        usurf->uclient->appid, usurf->surfaceid, animaid);
257             ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL;
258             usurf->animation.visible = ICO_WINDOW_MGR_ANIMA_HIDE_AT_END;
259         }
260         else if (op == ICO_WINDOW_MGR_ANIMATION_OPMOVE)    {
261             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_MOVE;
262             animaid = usurf->animation.move_anima;
263             usurf->animation.anima = animaid;
264             uifw_trace("ico_window_animation: move %s.%08x anima=%d",
265                        usurf->uclient->appid, usurf->surfaceid, animaid);
266             ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL;
267         }
268         else if (op == ICO_WINDOW_MGR_ANIMATION_OPRESIZE)    {
269             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_RESIZE;
270             animaid = usurf->animation.resize_anima;
271             usurf->animation.anima = animaid;
272             uifw_trace("ico_window_animation: resize %s.%08x anima=%d",
273                        usurf->uclient->appid, usurf->surfaceid, animaid);
274             ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL;
275         }
276         else    {
277             uifw_trace("ico_window_animation: Op=%d unknown", op);
278             return ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
279         }
280         if ((animaid == ANIMA_SLIDE_TOLEFT) || (animaid == ANIMA_SLIDE_TORIGHT) ||
281             (animaid == ANIMA_SLIDE_TOTOP) || (animaid == ANIMA_SLIDE_TOBOTTOM))  {
282             usurf->animation.animation.frame = animation_slide;
283             usurf->restrain_configure = 1;
284             (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 1);
285         }
286         else if ((animaid == ANIMA_WIPE_TOLEFT) || (animaid == ANIMA_WIPE_TORIGHT) ||
287                  (animaid == ANIMA_WIPE_TOTOP) || (animaid == ANIMA_WIPE_TOBOTTOM))  {
288             usurf->animation.animation.frame = animation_wipe;
289             usurf->restrain_configure = 1;
290             (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 1);
291         }
292         else if ((animaid == ANIMA_SWING_TOLEFT) || (animaid == ANIMA_SWING_TORIGHT) ||
293                  (animaid == ANIMA_SWING_TOTOP) || (animaid == ANIMA_SWING_TOBOTTOM))  {
294             usurf->animation.animation.frame = animation_swing;
295             usurf->restrain_configure = 1;
296             (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 1);
297         }
298         else if (animaid == ANIMA_FADE)   {
299             usurf->animation.animation.frame = animation_fade;
300             usurf->restrain_configure = 1;
301             (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 1);
302         }
303         else if (animaid == ANIMA_ZOOM)   {
304             usurf->animation.animation.frame = animation_zoom;
305             usurf->restrain_configure = 1;
306             (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 1);
307         }
308         else    {
309             /* no yet support   */
310             usurf->animation.animation.frame = NULL;
311             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_NONE;
312             usurf->restrain_configure = 0;
313             usurf->animation.anima = 0;
314             wl_list_remove(&usurf->animation.animation.link);
315             ret = ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
316             if (usurf->org_animation.saved) {
317                 usurf->animation.type = usurf->org_animation.type;
318                 usurf->animation.anima = usurf->org_animation.anima;
319                 usurf->animation.next_anima = usurf->org_animation.next_anima;
320                 usurf->animation.hide_anima = usurf->org_animation.hide_anima;
321                 usurf->animation.hide_time = usurf->org_animation.hide_time;
322                 usurf->animation.show_anima = usurf->org_animation.show_anima;
323                 usurf->animation.show_time = usurf->org_animation.show_time;
324                 usurf->animation.move_anima = usurf->org_animation.move_anima;
325                 usurf->animation.move_time = usurf->org_animation.move_time;
326                 usurf->animation.resize_anima = usurf->org_animation.resize_anima;
327                 usurf->animation.resize_time = usurf->org_animation.resize_time;
328                 usurf->org_animation.saved = 0;
329             }
330         }
331         usurf->animation.type = op;
332 #if  PERFORMANCE_EVALUATIONS > 0
333         if (ret != ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA)    {
334             uifw_perf("SWAP_BUFFER Start Animation appid=%s surface=%08x anima=%d",
335                       usurf->uclient->appid, usurf->surfaceid, usurf->animation.anima);
336         }
337 #endif /*PERFORMANCE_EVALUATIONS*/
338     }
339     weston_compositor_schedule_repaint(weston_ec);
340     return ret;
341 }
342
343 /*--------------------------------------------------------------------------*/
344 /**
345  * @brief   animation_cont: continue animation
346  *
347  * @param[in]   animation   weston animation table
348  * @param[in]   output      weston output table
349  * @param[in]   msecs       current time stamp
350  * @return      time has come
351  * @retval      =0          time has come
352  * @retval      >0          time has not yet come(return value is current parcent)
353  */
354 /*--------------------------------------------------------------------------*/
355 static int
356 animation_cont(struct weston_animation *animation, struct weston_output *output,
357                uint32_t msecs)
358 {
359     struct uifw_win_surface *usurf;
360     int         par;
361     uint32_t    nowsec;
362
363     nowsec = weston_compositor_get_time();
364
365     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
366
367     if (animation->frame_counter <= 1)  {
368         /* first call, initialize           */
369         animation->frame_counter = 1;
370         usurf->animation.starttime = nowsec;
371         usurf->animation.current = 1000;
372         if (! usurf->animation.animadata) {
373             if (free_data)  {
374                 usurf->animation.animadata = (void *)free_data;
375                 free_data = free_data->next_free;
376             }
377             else    {
378                 usurf->animation.animadata = (void *)malloc(sizeof(struct animation_data));
379             }
380             memset(usurf->animation.animadata, 0, sizeof(struct animation_data));
381         }
382     }
383     else if (! usurf->animation.animadata)    {
384         animation_end(usurf, 0);
385         return 999;
386     }
387
388     if (nowsec >= usurf->animation.starttime)   {
389         nowsec = nowsec - usurf->animation.starttime;   /* elapsed time(ms) */
390     }
391     else    {
392         nowsec = (uint32_t)(((long long)0x100000000L) +
393                             ((long long)nowsec) - ((long long)usurf->animation.starttime));
394     }
395     switch (usurf->animation.state) {
396     case ICO_WINDOW_MGR_ANIMATION_STATE_SHOW:
397         usurf->animation.time = usurf->animation.show_time;
398         break;
399     case ICO_WINDOW_MGR_ANIMATION_STATE_HIDE:
400         usurf->animation.time = usurf->animation.hide_time;
401         break;
402     case ICO_WINDOW_MGR_ANIMATION_STATE_MOVE:
403         usurf->animation.time = usurf->animation.move_time;
404         break;
405     default:
406         usurf->animation.time = usurf->animation.resize_time;
407         break;
408     }
409     if (usurf->animation.time == 0) {
410         usurf->animation.time = animation_time;
411     }
412     if (((output == NULL) && (msecs == 0)) || (nowsec >= ((uint32_t)usurf->animation.time))) {
413         par = 100;
414     }
415     else    {
416         par = (nowsec * 100 + usurf->animation.time / 2) / usurf->animation.time;
417         if (par < 2)    par = 2;
418     }
419     if ((par >= 100) ||
420         (abs(usurf->animation.current - par) >=
421          (((1000 * 100) / animation_fps) / usurf->animation.time)) ||
422         ((animation_count > 1) && (par != usurf->animation.current)))   {
423         usurf->animation.current = par;
424         return 0;
425     }
426     return par;
427 }
428
429 /*--------------------------------------------------------------------------*/
430 /**
431  * @brief   animation_end: terminate animation
432  *
433  * @param[in]   usurf       UIFW surface table
434  * @param[in]   disp        display control(1)/no display(0)
435  * @return      none
436  */
437 /*--------------------------------------------------------------------------*/
438 static void
439 animation_end(struct uifw_win_surface *usurf, const int disp)
440 {
441     struct animation_data   *animadata;
442     struct weston_view      *ev;
443
444     usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_NONE;
445     if (usurf->org_animation.saved) {
446         usurf->animation.type = usurf->org_animation.type;
447         usurf->animation.anima = usurf->org_animation.anima;
448         usurf->animation.next_anima = usurf->org_animation.next_anima;
449         usurf->animation.hide_anima = usurf->org_animation.hide_anima;
450         usurf->animation.hide_time = usurf->org_animation.hide_time;
451         usurf->animation.show_anima = usurf->org_animation.show_anima;
452         usurf->animation.show_time = usurf->org_animation.show_time;
453         usurf->animation.move_anima = usurf->org_animation.move_anima;
454         usurf->animation.move_time = usurf->org_animation.move_time;
455         usurf->animation.resize_anima = usurf->org_animation.resize_anima;
456         usurf->animation.resize_time = usurf->org_animation.resize_time;
457         usurf->org_animation.saved = 0;
458     }
459     animadata = (struct animation_data *)usurf->animation.animadata;
460
461     if (animation_count > 0)    {
462         animation_count --;
463     }
464     ev = ico_ivi_get_primary_view(usurf);
465
466     if (animadata)  {
467         if (animadata->end_function)    {
468             (*animadata->end_function)(&usurf->animation.animation);
469         }
470         wl_list_remove(&usurf->animation.animation.link);
471         if (animadata->transform_set)   {
472             wl_list_remove(&animadata->transform.link);
473             animadata->transform_set = 0;
474         }
475         if (ev) {
476             weston_view_geometry_dirty(ev);
477         }
478     }
479     if (disp)   {
480         uifw_trace("animation_end: %08x vis=%d(%x)",
481                    usurf->surfaceid, usurf->visible, usurf->animation.visible);
482         usurf->internal_propchange |= 0x10;
483         if ((usurf->animation.visible == ICO_WINDOW_MGR_ANIMA_HIDE_AT_END) &&
484             (usurf->visible != 0))  {
485             usurf->visible = 0;
486             ivi_layout_surface_set_visibility(usurf->ivisurf, 0);
487             ivi_layout_commit_changes();
488             weston_surface_damage(usurf->surface);
489             if (ev) {
490                 weston_view_geometry_dirty(ev);
491             }
492         }
493         if ((usurf->animation.visible == ICO_WINDOW_MGR_ANIMA_SHOW_AT_END) &&
494             (usurf->visible == 0))  {
495             usurf->visible = 1;
496             ivi_layout_surface_set_visibility(usurf->ivisurf, 1);
497             ivi_layout_commit_changes();
498             weston_surface_damage(usurf->surface);
499             if (ev) {
500                 weston_view_geometry_dirty(ev);
501             }
502         }
503         usurf->internal_propchange &= ~0x10;
504         usurf->restrain_configure = 0;
505     }
506     usurf->animation.visible = ICO_WINDOW_MGR_ANIMA_NOCONTROL_AT_END;
507     if (usurf->animation.next_anima != ICO_WINDOW_MGR_ANIMATION_NONE)    {
508         switch(usurf->animation.type)   {
509         case ICO_WINDOW_MGR_ANIMATION_OPHIDE:
510         case ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS:
511             usurf->animation.hide_anima = usurf->animation.next_anima;
512             break;
513         case ICO_WINDOW_MGR_ANIMATION_OPSHOW:
514         case ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS:
515             usurf->animation.show_anima = usurf->animation.next_anima;
516             break;
517         case ICO_WINDOW_MGR_ANIMATION_OPMOVE:
518             usurf->animation.move_anima = usurf->animation.next_anima;
519             break;
520         case ICO_WINDOW_MGR_ANIMATION_OPRESIZE:
521             usurf->animation.resize_anima = usurf->animation.next_anima;
522             break;
523         default:
524             break;
525         }
526         usurf->animation.next_anima = ICO_WINDOW_MGR_ANIMATION_NONE;
527     }
528     if (animadata)   {
529         usurf->animation.animadata = NULL;
530         animadata->next_free = free_data;
531         free_data = animadata;
532     }
533     usurf->animation.type = ICO_WINDOW_MGR_ANIMATION_OPNONE;
534 #if  PERFORMANCE_EVALUATIONS > 0
535     uifw_perf("SWAP_BUFFER End Animation appid=%s surface=%08x anima=%d",
536               usurf->uclient->appid, usurf->surfaceid, usurf->animation.anima);
537 #endif /*PERFORMANCE_EVALUATIONS*/
538 }
539
540 /*--------------------------------------------------------------------------*/
541 /**
542  * @brief   animation_slide: slide animation
543  *
544  * @param[in]   animation   weston animation table
545  * @param[in]   outout      weston output table
546  * @param[in]   mseces      current time(unused)
547  * @return      none
548  */
549 /*--------------------------------------------------------------------------*/
550 static void
551 animation_slide(struct weston_animation *animation,
552                 struct weston_output *output, uint32_t msecs)
553 {
554     struct uifw_win_surface *usurf;
555     struct animation_data   *animadata;
556     const struct ivi_layout_surface_properties  *prop;
557     int         dwidth, dheight;
558     int         par, x, y;
559
560     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
561
562     par = animation_cont(animation, output, msecs);
563     if (par > 0)    {
564         /* continue animation   */
565         if( par <= 100) {
566             weston_compositor_schedule_repaint(weston_ec);
567         }
568         return;
569     }
570     if (animation->frame_counter == 1)  {
571         animadata = (struct animation_data *)usurf->animation.animadata;
572         animadata->end_function = animation_slide_end;
573     }
574     par = usurf->animation.current;
575
576     uifw_debug("animation_slide: %08x count=%d %d%% anima=%d state=%d",
577                usurf->surfaceid, animation->frame_counter, par,
578                usurf->animation.anima, usurf->animation.state);
579
580     x = usurf->x;
581     y = usurf->y;
582
583     switch (usurf->animation.anima)  {
584     case ANIMA_SLIDE_TORIGHT:           /* slide in left to right           */
585         if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
586             /* slide in left to right   */
587             x = 0 - usurf->animation.pos_width +
588                 ((usurf->animation.pos_x + usurf->animation.pos_width) * par / 100);
589         }
590         else    {
591             /* slide out right to left  */
592             x = 0 - usurf->animation.pos_width +
593                 ((usurf->animation.pos_x + usurf->animation.pos_width) * (100 - par) / 100);
594         }
595         break;
596     case ANIMA_SLIDE_TOLEFT:            /* slide in right to left           */
597         dwidth = usurf->node_tbl->disp_width;
598         if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
599             /* slide in right to left   */
600             x = usurf->animation.pos_x +
601                 (dwidth - usurf->animation.pos_x) * (100 - par) / 100;
602         }
603         else    {
604             /* slide out left to right  */
605             x = usurf->animation.pos_x + (dwidth - usurf->animation.pos_x) * par / 100;
606         }
607         break;
608     case ANIMA_SLIDE_TOBOTTOM:          /* slide in top to bottom           */
609         if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
610             /* slide in top to bottom   */
611             y = 0 - usurf->animation.pos_height +
612                 ((usurf->animation.pos_y + usurf->animation.pos_height) * par / 100);
613         }
614         else    {
615             /* slide out bottom to top  */
616             y = 0 - usurf->animation.pos_height +
617                 ((usurf->animation.pos_y + usurf->animation.pos_height) * (100 - par) / 100);
618         }
619         break;
620     default: /*ANIMA_SLIDE_TOTOP*/      /* slide in bottom to top           */
621         dheight = usurf->node_tbl->disp_height;
622         if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
623             /* slide in bottom to top   */
624             y = usurf->animation.pos_y +
625                 (dheight - usurf->animation.pos_y) * (100 - par) / 100;
626         }
627         else    {
628             /* slide out top to bottom  */
629             y = usurf->animation.pos_y + (dheight - usurf->animation.pos_y) * par / 100;
630         }
631         break;
632     }
633     if ((par < 8) || (par > 92))    {
634         uifw_debug("animation_slide: %08x %d%% %d/%d(target %d/%d) %08x",
635                    usurf->surfaceid, par, x, y, usurf->x, usurf->y, (int)usurf->ivisurf);
636     }
637     if ((prop = ivi_layout_get_properties_of_surface(usurf->ivisurf)))   {
638         usurf->internal_propchange |= 0x20;
639         if (ivi_layout_surface_set_destination_rectangle(usurf->ivisurf, x, y,
640                                              prop->dest_width, prop->dest_height) == 0) {
641             ivi_layout_commit_changes();
642         }
643         usurf->internal_propchange &= ~0x20;
644     }
645     if (par >= 100) {
646         /* end of animation     */
647         animation_end(usurf, 1);
648         uifw_trace("animation_slide: End of animation");
649     }
650     else    {
651         /* continue animation   */
652         weston_compositor_schedule_repaint(weston_ec);
653     }
654 }
655
656 /*--------------------------------------------------------------------------*/
657 /**
658  * @brief   animation_slide_end: slide animation end
659  *
660  * @param[in]   animation   weston animation table
661  * @return      none
662  */
663 /*--------------------------------------------------------------------------*/
664 static void
665 animation_slide_end(struct weston_animation *animation)
666 {
667     struct uifw_win_surface *usurf;
668
669     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
670     if (usurf)  {
671         ico_window_mgr_set_weston_surface(usurf,
672                                           usurf->animation.pos_x, usurf->animation.pos_y,
673                                           usurf->animation.pos_width,
674                                           usurf->animation.pos_height);
675     }
676 }
677
678 /*--------------------------------------------------------------------------*/
679 /**
680  * @brief   animation_wipe: wipe animation
681  *
682  * @param[in]   animation   weston animation table
683  * @param[in]   outout      weston output table
684  * @param[in]   mseces      current time(unused)
685  * @return      none
686  */
687 /*--------------------------------------------------------------------------*/
688 static void
689 animation_wipe(struct weston_animation *animation,
690                struct weston_output *output, uint32_t msecs)
691 {
692     struct uifw_win_surface *usurf;
693     struct weston_surface   *es;
694     struct weston_view      *ev;
695     int         par;
696     int         x;
697     int         y;
698     int         width;
699     int         height;
700
701     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
702
703     par = animation_cont(animation, output, msecs);
704     if (par > 0)    {
705         /* continue animation   */
706         if( par <= 100) {
707             weston_compositor_schedule_repaint(weston_ec);
708         }
709         return;
710     }
711     ev = ico_ivi_get_primary_view(usurf);
712     par = usurf->animation.current;
713
714     uifw_debug("animation_wipe: %08x count=%d %d%% anima=%d state=%d",
715                usurf->surfaceid, animation->frame_counter, par,
716                usurf->animation.anima, usurf->animation.state);
717
718     es = usurf->surface;
719     x = usurf->x;
720     y = usurf->y;
721     width = usurf->width;
722     height = usurf->width;
723
724     if (par < 100)  {
725         switch (usurf->animation.anima)  {
726         case ANIMA_WIPE_TORIGHT:            /* wipe in left to right            */
727             if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
728                 /* wipe in left to right    */
729                 width = ((float)width) * ((float)par + 5.0f) / 105.0f;
730             }
731             else    {
732                 /* wipe out right to left   */
733                 width = width - (((float)width) * ((float)par + 5.0f) / 105.0f);
734             }
735             if (width <= 0) width = 1;
736             break;
737         case ANIMA_WIPE_TOLEFT:             /* wipe in right to left            */
738             if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
739                 /* wipe in right to left    */
740                 width = ((float)width) * ((float)par + 5.0f) / 105.0f;
741             }
742             else    {
743                 /* wipe out left to right   */
744                 width = width - (((float)width) * ((float)par + 5.0f) / 105.0f);
745             }
746             if (width <= 0) width = 1;
747             x = x + (usurf->width - width);
748             break;
749         case ANIMA_WIPE_TOBOTTOM:           /* wipe in top to bottom            */
750             if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
751                 /* wipe in top to bottom    */
752                 height = ((float)height) * ((float)par + 5.0f) / 105.0f;
753             }
754             else    {
755                 /* wipe out bottom to top   */
756                 height = height - (((float)height) * ((float)par + 5.0f) / 105.0f);
757             }
758             if (height <= 0)    height = 1;
759             break;
760         default: /*ANIMA_WIPE_TOTOP*/       /* wipe in bottom to top            */
761             if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
762                 /* wipe in bottom to top    */
763                 height = ((float)height) * ((float)par + 5.0f) / 105.0f;
764             }
765             else    {
766                 /* wipe out top to bottom   */
767                 height = height - (((float)height) * ((float)par + 5.0f) / 105.0f);
768             }
769             if (height <= 0)    height = 1;
770             y = y + (usurf->height - height);
771             break;
772         }
773     }
774
775     es->width = width;
776     es->height = height;
777     if (ev) {
778         ev->geometry.x = usurf->node_tbl->disp_x + x;
779         ev->geometry.y = usurf->node_tbl->disp_y + y;
780         if ((ev->output) && (es->buffer_ref.buffer))    {
781             weston_view_geometry_dirty(ev);
782             weston_surface_damage(es);
783         }
784     }
785     if (par >= 100) {
786         /* end of animation     */
787         animation_end(usurf, 1);
788         uifw_trace("animation_wipe: End of animation");
789     }
790     else    {
791         /* continue animation   */
792         weston_compositor_schedule_repaint(weston_ec);
793     }
794 }
795
796 /*--------------------------------------------------------------------------*/
797 /**
798  * @brief   animation_swing: swing animation
799  *
800  * @param[in]   animation   weston animation table
801  * @param[in]   outout      weston output table
802  * @param[in]   mseces      current time(unused)
803  * @return      none
804  */
805 /*--------------------------------------------------------------------------*/
806 static void
807 animation_swing(struct weston_animation *animation,
808                 struct weston_output *output, uint32_t msecs)
809 {
810     struct uifw_win_surface *usurf;
811     struct weston_surface   *es;
812     struct weston_view      *ev;
813     struct animation_data   *animadata;
814     int         par;
815     int         x;
816     int         y;
817     float       scalex;
818     float       scaley;
819
820     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
821
822     par = animation_cont(animation, output, msecs);
823     if (par > 0)    {
824         /* continue animation   */
825         if( par <= 100) {
826             weston_compositor_schedule_repaint(weston_ec);
827         }
828         return;
829     }
830
831     uifw_debug("animation_swing: %08x count=%d %d%% anima=%d state=%d",
832                usurf->surfaceid, animation->frame_counter, par,
833                usurf->animation.anima, usurf->animation.state);
834
835     animadata = (struct animation_data *)usurf->animation.animadata;
836     es = usurf->surface;
837     ev = ico_ivi_get_primary_view(usurf);
838     par = usurf->animation.current;
839     if (animation->frame_counter == 1)  {
840         if (animadata->transform_set == 0)  {
841             animadata->transform_set = 1;
842             weston_matrix_init(&animadata->transform.matrix);
843             wl_list_init(&animadata->transform.link);
844             if (ev) {
845                 wl_list_insert(&ev->geometry.transformation_list,
846                                &animadata->transform.link);
847             }
848         }
849         animadata->end_function = animation_swing_end;
850     }
851
852     x = usurf->x;
853     y = usurf->y;
854     scalex = 1.0;
855     scaley = 1.0;
856
857     if (par < 100)  {
858         switch (usurf->animation.anima)  {
859         case ANIMA_SWING_TORIGHT:           /* swing in left to right           */
860             if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
861                 /* swing in left to right   */
862                 scalex = ((float)par + 5.0f) / 105.0f;
863             }
864             else    {
865                 /* swing out right to left  */
866                 scalex = 1.0 - (((float)par + 5.0f) / 105.0f);
867             }
868             if (scalex <= 0.0)  scalex = 0.01;
869             break;
870         case ANIMA_SWING_TOLEFT:            /* seing in right to left           */
871             if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
872                 /* swing in right to left   */
873                 scalex = ((float)par + 5.0f) / 105.0f;
874             }
875             else    {
876                 /* swing out left to right  */
877                 scalex = 1.0 - (((float)par + 5.0f) / 105.0f);
878             }
879             if (scalex <= 0.0)  scalex = 0.01;
880             x = x + (int)((float)usurf->width * (1.0f - scalex));
881             break;
882         case ANIMA_SWING_TOBOTTOM:          /* swing in top to bottom           */
883             if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
884                 /* swing in top to bottom   */
885                 scaley = ((float)par + 5.0f) / 105.0f;
886             }
887             else    {
888                 /* swing out bottom to top  */
889                 scalex = 1.0 - (((float)par + 5.0f) / 105.0f);
890             }
891             if (scaley <= 0.0)  scaley = 0.01;
892             break;
893         default: /*ANIMA_SWING*/        /* swing in bottom to top               */
894             if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
895                 /* wipe in bottom to top    */
896                 scaley = ((float)par + 5.0f) / 105.0f;
897             }
898             else    {
899                 /* wipe out top to bottom   */
900                 scalex = 1.0 - (((float)par + 5.0f) / 105.0f);
901             }
902             if (scaley <= 0.0)  scaley = 0.01;
903             y = y + (int)((float)usurf->height * (1.0f - scaley));
904             break;
905         }
906     }
907
908     weston_matrix_init(&animadata->transform.matrix);
909     weston_matrix_translate(&animadata->transform.matrix,
910                             -0.5f * usurf->width, -0.5f * usurf->height, 0);
911     weston_matrix_scale(&animadata->transform.matrix, scalex, scaley, 1.0f);
912     weston_matrix_translate(&animadata->transform.matrix,
913                             0.5f * usurf->width, 0.5f * usurf->height, 0);
914
915     if (ev) {
916         ev->geometry.x = usurf->node_tbl->disp_x + x;
917         ev->geometry.y = usurf->node_tbl->disp_y + y;
918         if ((ev->output) && (es->buffer_ref.buffer))    {
919             weston_view_geometry_dirty(ev);
920             weston_surface_damage(es);
921         }
922     }
923     if (par >= 100) {
924         /* end of animation     */
925         animation_end(usurf, 1);
926         uifw_trace("animation_swing: End of animation");
927     }
928     else    {
929         /* continue animation   */
930         weston_compositor_schedule_repaint(weston_ec);
931     }
932 }
933
934 /*--------------------------------------------------------------------------*/
935 /**
936  * @brief   animation_swing_end: swing animation end
937  *
938  * @param[in]   animation   weston animation table
939  * @return      none
940  */
941 /*--------------------------------------------------------------------------*/
942 static void
943 animation_swing_end(struct weston_animation *animation)
944 {
945     struct uifw_win_surface *usurf;
946     struct weston_surface   *es;
947     struct weston_view      *ev;
948
949     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
950     if (usurf && usurf->surface)    {
951         es = usurf->surface;
952         ev = ico_ivi_get_primary_view(usurf);
953         if (ev) {
954             ev->alpha = usurf->animation.alpha;
955             uifw_debug("animation_swing_end: %08x set alpha=%.2f",
956                        usurf->surfaceid, usurf->animation.alpha);
957             if ((ev->output) && (es->buffer_ref.buffer))    {
958                 weston_surface_damage(es);
959             }
960         }
961     }
962 }
963
964 /*--------------------------------------------------------------------------*/
965 /**
966  * @brief   animation_fade: fade animation
967  *
968  * @param[in]   animation   weston animation table
969  * @param[in]   outout      weston output table
970  * @param[in]   mseces      current time(unused)
971  * @return      none
972  */
973 /*--------------------------------------------------------------------------*/
974 static void
975 animation_fade(struct weston_animation *animation,
976                struct weston_output *output, uint32_t msecs)
977 {
978     struct uifw_win_surface *usurf;
979     struct animation_data   *animadata;
980     struct weston_surface   *es;
981     struct weston_view      *ev;
982     int         par;
983
984     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
985
986     par = animation_cont(animation, output, msecs);
987     if (par > 0)    {
988         /* continue animation   */
989         if( par <= 100) {
990             weston_compositor_schedule_repaint(weston_ec);
991         }
992         return;
993     }
994
995     animadata = (struct animation_data *)usurf->animation.animadata;
996     es = usurf->surface;
997     ev = ico_ivi_get_primary_view(usurf);
998     par = usurf->animation.current;
999     if (animation->frame_counter == 1)  {
1000         if (animadata->transform_set == 0)  {
1001             animadata->transform_set = 1;
1002             weston_matrix_init(&animadata->transform.matrix);
1003             wl_list_init(&animadata->transform.link);
1004             if (ev) {
1005                 wl_list_insert(&ev->geometry.transformation_list,
1006                                &animadata->transform.link);
1007             }
1008         }
1009         animadata->end_function = animation_fade_end;
1010
1011         if ((usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS) ||
1012             (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS))  {
1013             ico_window_mgr_set_weston_surface(usurf,
1014                                               usurf->animation.pos_x,
1015                                               usurf->animation.pos_y,
1016                                               usurf->animation.pos_width,
1017                                               usurf->animation.pos_height);
1018         }
1019     }
1020
1021     if (ev) {
1022         if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
1023             /* fade in                  */
1024             ev->alpha = ((float)par) / 100.0f;
1025         }
1026         else if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_HIDE)    {
1027             /* fade out                 */
1028             ev->alpha = 1.0f - (((float)par) / 100.0f);
1029         }
1030         else    {
1031             /* fade move/resize         */
1032             if ((par >= 50) || (usurf->animation.ahalf))    {
1033                 ev->alpha = ((float)(par*2 - 100)) / 100.0f;
1034                 if (usurf->animation.ahalf == 0)    {
1035                     uifw_trace("animation_fade: fade move chaneg to show");
1036                     usurf->animation.ahalf = 1;
1037                     ev->alpha = 0.0;
1038                     ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
1039                                                       usurf->width, usurf->height);
1040                 }
1041             }
1042             else    {
1043                 ev->alpha = 1.0f - (((float)(par*2)) / 100.0f);
1044             }
1045         }
1046         if (ev->alpha < 0.0f)       ev->alpha = 0.0f;
1047         else if (ev->alpha > 1.0f)  ev->alpha = 1.0f;
1048
1049         if ((par < 8) || (par > 92))    {
1050             uifw_debug("animation_fade: %08x count=%d %d%% alpha=%1.2f anima=%d state=%d",
1051                        usurf->surfaceid, animation->frame_counter, par,
1052                        ev->alpha, usurf->animation.anima, usurf->animation.state);
1053         }
1054         if ((ev->output) && (es->buffer_ref.buffer) &&
1055             (es->width > 0) && (es->height > 0))    {
1056             weston_surface_damage(es);
1057         }
1058     }
1059     if (par >= 100) {
1060         /* end of animation     */
1061         animation_end(usurf, 1);
1062         uifw_trace("animation_fade: End of animation");
1063     }
1064     else    {
1065         /* continue animation   */
1066         weston_compositor_schedule_repaint(weston_ec);
1067     }
1068 }
1069
1070 /*--------------------------------------------------------------------------*/
1071 /**
1072  * @brief   animation_fade_end: fade animation end
1073  *
1074  * @param[in]   animation   weston animation table
1075  * @return      none
1076  */
1077 /*--------------------------------------------------------------------------*/
1078 static void
1079 animation_fade_end(struct weston_animation *animation)
1080 {
1081     struct uifw_win_surface *usurf;
1082     struct weston_surface   *es;
1083     struct weston_view      *ev;
1084
1085     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
1086     if (usurf && usurf->surface)    {
1087         es = usurf->surface;
1088         ev = ico_ivi_get_primary_view(usurf);
1089         if (ev) {
1090             ev->alpha = usurf->animation.alpha;
1091             uifw_debug("animation_fade_end: %08x set alpha=%.2f",
1092                        usurf->surfaceid, usurf->animation.alpha);
1093             if ((ev->output) && (es->buffer_ref.buffer) &&
1094                 (es->width > 0) && (es->height > 0))    {
1095                 weston_surface_damage(es);
1096             }
1097         }
1098     }
1099 }
1100
1101 /*--------------------------------------------------------------------------*/
1102 /**
1103  * @brief   animation_zoom: zoom animation
1104  *
1105  * @param[in]   animation   weston animation table
1106  * @param[in]   outout      weston output table
1107  * @param[in]   mseces      current time(unused)
1108  * @return      none
1109  */
1110 /*--------------------------------------------------------------------------*/
1111 static void
1112 animation_zoom(struct weston_animation *animation,
1113                struct weston_output *output, uint32_t msecs)
1114 {
1115     struct uifw_win_surface *usurf;
1116     struct animation_data   *animadata;
1117     struct weston_surface   *es;
1118     struct weston_view      *ev;
1119     int         par;
1120     float       scalex, scaley;
1121     float       fu, fa, fp;
1122     int         x, y;
1123
1124     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
1125
1126     par = animation_cont(animation, output, msecs);
1127     if (par > 0)    {
1128         /* continue animation   */
1129         if( par <= 100) {
1130             weston_compositor_schedule_repaint(weston_ec);
1131         }
1132         return;
1133     }
1134
1135     animadata = (struct animation_data *)usurf->animation.animadata;
1136     es = usurf->surface;
1137     ev = ico_ivi_get_primary_view(usurf);
1138     par = usurf->animation.current;
1139     if (animation->frame_counter == 1)  {
1140         if (animadata->transform_set == 0)  {
1141             animadata->transform_set = 1;
1142             weston_matrix_init(&animadata->transform.matrix);
1143             wl_list_init(&animadata->transform.link);
1144             if (ev) {
1145                 wl_list_insert(&ev->geometry.transformation_list,
1146                                &animadata->transform.link);
1147             }
1148         }
1149         animadata->end_function = animation_zoom_end;
1150
1151         if ((usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS) ||
1152             (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS))  {
1153             ico_window_mgr_set_weston_surface(usurf,
1154                                               usurf->animation.pos_x, usurf->animation.pos_y,
1155                                               usurf->animation.pos_width,
1156                                               usurf->animation.pos_height);
1157         }
1158     }
1159
1160     if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
1161         /* zoom in                  */
1162         scalex = ((float)par + 5.0f) / 105.0f;
1163         scaley = scalex;
1164     }
1165     else if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_HIDE)    {
1166         /* zoom out                 */
1167         scalex = 1.0f - (((float)par + 5.0f) / 105.0f);
1168         scaley = scalex;
1169     }
1170     else    {
1171         /* zoom move/resize         */
1172         ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
1173                                           usurf->width, usurf->height);
1174         fu = (float)usurf->width;
1175         fa = (float)usurf->animation.pos_width;
1176         fp = (100.0f - (float)par) / 100.0f;
1177         scalex = (fu - (fu - fa) * fp) / fu;
1178         fu = (float)usurf->height;
1179         fa = (float)usurf->animation.pos_height;
1180         scaley = (fu - (fu - fa) * fp) / fu;
1181
1182         x = (((float)usurf->animation.pos_x) - ((float)usurf->x)) * fp + (float)usurf->x
1183             + (((float)usurf->width * scalex) - (float)usurf->width) / 2.0f;
1184         y = (((float)usurf->animation.pos_y) - ((float)usurf->y)) * fp + (float)usurf->y
1185             + (((float)usurf->height * scaley) - (float) usurf->height) / 2.0f;
1186         uifw_trace("animation_zoom: %08x %d%% x=%d/%d y=%d/%d",
1187                    usurf->surfaceid, par, x, usurf->x, y, usurf->y);
1188         uifw_trace("animation_zoom: sx=%4.2f sy=%4.2f x=%d->%d y=%d->%d cur=%d,%d",
1189                    scalex, scaley, usurf->animation.pos_x, usurf->x,
1190                    usurf->animation.pos_y, usurf->y, x, y);
1191         ico_window_mgr_set_weston_surface(usurf, x, y, usurf->width, usurf->height);
1192     }
1193     weston_matrix_init(&animadata->transform.matrix);
1194     weston_matrix_translate(&animadata->transform.matrix,
1195                             -0.5f * usurf->width, -0.5f * usurf->height, 0);
1196     weston_matrix_scale(&animadata->transform.matrix, scalex, scaley, 1.0f);
1197     weston_matrix_translate(&animadata->transform.matrix,
1198                             0.5f * usurf->width, 0.5f * usurf->height, 0);
1199
1200     uifw_trace("animation_zoom: %08x count=%d %d%% w=%d/%d h=%d/%d anima=%d state=%d",
1201                usurf->surfaceid, animation->frame_counter, par,
1202                (int)(usurf->width * scalex), usurf->width,
1203                (int)(usurf->height * scaley), usurf->height,
1204                usurf->animation.anima, usurf->animation.state);
1205
1206     if (ev) {
1207         if ((ev->output) && (es->buffer_ref.buffer) &&
1208             (es->width > 0) && (es->height > 0))    {
1209             weston_view_geometry_dirty(ev);
1210             weston_surface_damage(es);
1211         }
1212     }
1213     if (par >= 100) {
1214         /* end of animation     */
1215         animation_end(usurf, 1);
1216         uifw_trace("animation_zoom: End of animation");
1217     }
1218     else    {
1219         /* continue animation   */
1220         weston_compositor_schedule_repaint(weston_ec);
1221     }
1222 }
1223
1224 /*--------------------------------------------------------------------------*/
1225 /**
1226  * @brief   animation_zoom_end: zoom animation end
1227  *
1228  * @param[in]   animation   weston animation table
1229  * @return      none
1230  */
1231 /*--------------------------------------------------------------------------*/
1232 static void
1233 animation_zoom_end(struct weston_animation *animation)
1234 {
1235     struct uifw_win_surface *usurf;
1236     struct weston_surface   *es;
1237     struct weston_view      *ev;
1238
1239     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
1240     if (usurf && usurf->surface)    {
1241         es = usurf->surface;
1242         ev = ico_ivi_get_primary_view(usurf);
1243         if (ev) {
1244             ev->alpha = usurf->animation.alpha;
1245             if ((ev->output) && (es->buffer_ref.buffer) &&
1246                 (es->width > 0) && (es->height > 0))    {
1247                 weston_surface_damage(es);
1248             }
1249         }
1250     }
1251 }
1252
1253 /*--------------------------------------------------------------------------*/
1254 /**
1255  * @brief   module_init: initialize ico_window_animation
1256  *                       this function called from ico_pluign_loader
1257  *
1258  * @param[in]   es          weston compositor
1259  * @param[in]   argc        number of arguments(unused)
1260  * @param[in]   argv        argument list(unused)
1261  * @return      result
1262  * @retval      0           sccess
1263  * @retval      -1          error
1264  */
1265 /*--------------------------------------------------------------------------*/
1266 WL_EXPORT int
1267 module_init(struct weston_compositor *ec, int *argc, char *argv[])
1268 {
1269     int     i;
1270     struct animation_data   *animadata;
1271
1272     uifw_info("ico_window_animation: Enter(module_init)");
1273
1274     /* allocate animation datas     */
1275     free_data = NULL;
1276     for (i = 0; i < 50; i++)    {
1277         animadata = (struct animation_data *)malloc(sizeof(struct animation_data));
1278         if (! animadata)    {
1279             uifw_error("ico_window_animation: No Memory(module_init)");
1280             return -1;
1281         }
1282         animadata->next_free = free_data;
1283         free_data = animadata;
1284     }
1285
1286     weston_ec = ec;
1287     default_animation = (char *)ico_ivi_default_animation_name();
1288     animation_time = ico_ivi_default_animation_time();
1289     animation_fps = ico_ivi_default_animation_fps();
1290     animation_count = 0;
1291
1292     ico_window_mgr_set_hook_animation(ico_window_animation);
1293
1294     uifw_info("ico_window_animation: Leave(module_init)");
1295
1296     return 0;
1297 }