Support Tizen 3.0
[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 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    Jul-26-2013
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 "ico_ivi_common.h"
43 #include "ico_ivi_shell.h"
44 #include "ico_window_mgr.h"
45
46 /* Animation type               */
47 #define ANIMA_ZOOM              1           /* ZoomIn/ZoomOut                       */
48 #define ANIMA_FADE              2           /* FadeIn/FadeOut                       */
49 #define ANIMA_SLIDE_TORIGHT     3           /* SlideIn left to right/SlideOut right to left*/
50 #define ANIMA_SLIDE_TOLEFT      4           /* SlideIn right to left/SlideOut left to right*/
51 #define ANIMA_SLIDE_TOBOTTOM    5           /* SlideIn top to bottom/SlideOut bottom to top*/
52 #define ANIMA_SLIDE_TOTOP       6           /* SlideIn bottom to top/SlideOut top to bottom*/
53
54 /* Visible control at end of animation  */
55 #define ANIMA_NOCONTROL_AT_END  0           /* no need surface show/hide at end of animation*/
56 #define ANIMA_SHOW_AT_END       1           /* surface show at end of animation     */
57 #define ANIMA_HIDE_AT_END       2           /* surface hide at end of animation     */
58
59 /* animation data               */
60 struct animation_data   {
61     struct animation_data   *next_free;     /* free data list                       */
62     int     x;                              /* original X coordinate                */
63     int     y;                              /* original Y coordinate                */
64     int     width;                          /* original width                       */
65     int     height;                         /* original height                      */
66     char    geometry_saved;                 /* need geometry restore at end         */
67     char    transform_set;                  /* need transform reset at end          */
68     char    res[2];                         /* (unused)                             */
69     struct weston_transform transform;      /* transform matrix                     */
70     void    (*end_function)(struct weston_animation *animation);
71                                             /* animation end function               */
72 };
73
74 /* static valiables             */
75 static struct weston_compositor *weston_ec; /* Weston compositor                    */
76 static char *default_animation;             /* default animation name               */
77 static int  animation_time;                 /* animation time(ms)                   */
78 static int  animation_fpar;                 /* animation frame parcent(%)           */
79 static struct animation_data    *free_data; /* free data list                       */
80
81 /* static function              */
82                                             /* slide animation                      */
83 static void animation_slide(struct weston_animation *animation,
84                             struct weston_output *output, uint32_t msecs);
85                                             /* fade animation                       */
86 static void animation_fade(struct weston_animation *animation,
87                            struct weston_output *output, uint32_t msecs);
88                                             /* fade animation end                   */
89 static void animation_fade_end(struct weston_animation *animation);
90                                             /* continue animation                   */
91 static int animation_cont(struct weston_animation *animation,
92                           struct weston_output *output, uint32_t msecs);
93                                             /* terminate animation                  */
94 static void animation_end(struct uifw_win_surface *usurf, const int disp);
95
96 /*--------------------------------------------------------------------------*/
97 /**
98  * @brief   ico_window_animation: Animation addin entry
99  *
100  * @param[in]   op      animation operation
101  * @param[in]   data    data
102  * @return      result
103  * @retval      ICO_WINDOW_MGR_ANIMATION_RET_ANIMA      success
104  * @retval      ICO_WINDOW_MGR_ANIMATION_RET_ANIMASHOW  success(force visible)
105  * @retval      ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA    error(no animation)
106  */
107 /*--------------------------------------------------------------------------*/
108 static int
109 ico_window_animation(const int op, void *data)
110 {
111     struct uifw_win_surface *usurf;
112     struct weston_output *output;
113     int         ret;
114     uint32_t    nowsec;
115     struct timeval  nowtv;
116     int         time;
117     int         name;
118
119     if (op == ICO_WINDOW_MGR_ANIMATION_NAME)    {
120         /* convert animation name to animation type value   */
121         if (strcasecmp((char *)data, "fade") == 0)  {
122             uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_FADE);
123             return ANIMA_FADE;
124         }
125         else if (strcasecmp((char *)data, "zoom") == 0) {
126             uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_ZOOM);
127             return ANIMA_ZOOM;
128         }
129         else if (strcasecmp((char *)data, "slide.toleft") == 0) {
130             uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_SLIDE_TOLEFT);
131             return ANIMA_SLIDE_TOLEFT;
132         }
133         else if (strcasecmp((char *)data, "slide.toright") == 0)    {
134             uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_SLIDE_TORIGHT);
135             return ANIMA_SLIDE_TORIGHT;
136         }
137         else if (strcasecmp((char *)data, "slide.totop") == 0)  {
138             uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_SLIDE_TOTOP);
139             return ANIMA_SLIDE_TOTOP;
140         }
141         else if (strcasecmp((char *)data, "slide.tobottom") == 0)   {
142             uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_SLIDE_TOBOTTOM);
143             return ANIMA_SLIDE_TOBOTTOM;
144         }
145         uifw_warn("ico_window_animation: Unknown Type %s", (char *)data);
146         return ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
147     }
148
149     usurf = (struct uifw_win_surface *)data;
150
151     if (op == ICO_WINDOW_MGR_ANIMATION_DESTROY) {
152         if ((usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE) ||
153             (usurf->animation.animadata != NULL)) {
154             uifw_trace("ico_window_animation: Destroy %08x", (int)usurf);
155             animation_end(usurf, 0);
156         }
157         return ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
158     }
159
160     if (op == ICO_WINDOW_MGR_ANIMATION_OPCANCEL)    {
161         /* cancel animation                     */
162         if ((usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE) &&
163             (usurf->animation.animation.frame != NULL)) {
164             uifw_trace("ico_window_animation: cancel %s.%08x",
165                        usurf->uclient->appid, usurf->surfaceid);
166             (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 0);
167         }
168         animation_end(usurf, 1);
169         ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
170     }
171     else    {
172         /* setup animation              */
173         if ((usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_NONE) ||
174             (usurf->animation.current > 95))    {
175             usurf->animation.animation.frame_counter = 1;
176             usurf->animation.current = 0;
177             if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_NONE)  {
178                 wl_list_init(&usurf->animation.animation.link);
179                 output = container_of(weston_ec->output_list.next,
180                                       struct weston_output, link);
181                 wl_list_insert(output->animation_list.prev,
182                                &usurf->animation.animation.link);
183             }
184         }
185         else if (((usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW) &&
186                   (op == ICO_WINDOW_MGR_ANIMATION_OPHIDE)) ||
187                  ((usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_HIDE) &&
188                   (op == ICO_WINDOW_MGR_ANIMATION_OPSHOW)))   {
189             /* change ...In(ex.FadeIn) to ...Out(FadeOut) or ...Out to ...In    */
190             gettimeofday(&nowtv, NULL);
191             nowsec = (uint32_t)(((long long)nowtv.tv_sec) * 1000L +
192                                 ((long long)nowtv.tv_usec) / 1000L);
193             usurf->animation.current = 100 - usurf->animation.current;
194             if (op == ICO_WINDOW_MGR_ANIMATION_OPHIDE)  {
195                 time = usurf->animation.hide_time;
196             }
197             else    {
198                 time = usurf->animation.show_time;
199             }
200             time = (time > 0) ? time : animation_time;
201             ret = ((usurf->animation.current) * time) / 100;
202             if (nowsec >= (uint32_t)ret)    {
203                 usurf->animation.starttime = nowsec - ret;
204             }
205             else    {
206                 usurf->animation.starttime = ((long long)nowsec) + ((long long)0x100000000L)
207                                              - ((long long)ret);
208             }
209             usurf->animation.animation.frame_counter = 2;
210         }
211
212         /* set animation function       */
213         if (op == ICO_WINDOW_MGR_ANIMATION_OPSHOW)    {
214             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_SHOW;
215             name = usurf->animation.show_name;
216             usurf->animation.name = name;
217             uifw_trace("ico_window_animation: show(in) %s.%08x anima=%d",
218                        usurf->uclient->appid, usurf->surfaceid, name);
219             ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
220         }
221         else if (op == ICO_WINDOW_MGR_ANIMATION_OPHIDE)    {
222             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_HIDE;
223             name = usurf->animation.hide_name;
224             usurf->animation.name = name;
225             uifw_trace("ico_window_animation: hide(out) %s.%08x anima=%d",
226                        usurf->uclient->appid, usurf->surfaceid, name);
227             ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMASHOW;
228         }
229         else if (op == ICO_WINDOW_MGR_ANIMATION_OPMOVE)    {
230             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_MOVE;
231             name = usurf->animation.move_name;
232             usurf->animation.name = name;
233             uifw_trace("ico_window_animation: move %s.%08x anima=%d",
234                        usurf->uclient->appid, usurf->surfaceid, name);
235             ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
236         }
237         else    {
238             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_RESIZE;
239             name = usurf->animation.resize_name;
240             usurf->animation.name = name;
241             uifw_trace("ico_window_animation: resize %s.%08x anima=%d",
242                        usurf->uclient->appid, usurf->surfaceid, name);
243             ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
244         }
245         if ((name == ANIMA_SLIDE_TOLEFT) || (name == ANIMA_SLIDE_TORIGHT) ||
246             (name == ANIMA_SLIDE_TOTOP) || (name == ANIMA_SLIDE_TOBOTTOM))  {
247             usurf->animation.animation.frame = animation_slide;
248             usurf->restrain_configure = 1;
249             (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 1);
250         }
251         else if (name == ANIMA_FADE)   {
252             usurf->animation.animation.frame = animation_fade;
253             (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 1);
254         }
255         else    {
256             /* no yet support   */
257             usurf->animation.animation.frame = NULL;
258             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_NONE;
259             usurf->restrain_configure = 0;
260             usurf->animation.name = 0;
261             wl_list_remove(&usurf->animation.animation.link);
262             ret = ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
263         }
264         usurf->animation.type = op;
265     }
266     if (ret == ICO_WINDOW_MGR_ANIMATION_RET_ANIMASHOW)  {
267         usurf->animation.visible = ANIMA_HIDE_AT_END;
268     }
269     else    {
270         usurf->animation.visible = ANIMA_NOCONTROL_AT_END;
271     }
272     weston_compositor_schedule_repaint(weston_ec);
273     return ret;
274 }
275
276 /*--------------------------------------------------------------------------*/
277 /**
278  * @brief   animation_cont: continue animation
279  *
280  * @param[in]   animation   weston animation table
281  * @param[in]   output      weston output table
282  * @param[in]   msecs       current time stamp
283  * @return      time has come
284  * @retval      =0          time has come
285  * @retval      >0          time has not yet come(return value is current parcent)
286  */
287 /*--------------------------------------------------------------------------*/
288 static int
289 animation_cont(struct weston_animation *animation, struct weston_output *output,
290                uint32_t msecs)
291 {
292     struct uifw_win_surface *usurf;
293     struct animation_data   *animadata;
294     int         par;
295     uint32_t    nowsec;
296     struct timeval  nowtv;
297     int         time;
298
299     gettimeofday(&nowtv, NULL);
300     nowsec = (uint32_t)(((long long)nowtv.tv_sec) * 1000L +
301                         ((long long)nowtv.tv_usec) / 1000L);
302
303     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
304
305     if (animation->frame_counter <= 1)  {
306         /* first call, initialize           */
307         animation->frame_counter = 1;
308         usurf->animation.starttime = nowsec;
309         usurf->animation.current = 1000;
310         if (! usurf->animation.animadata) {
311             if (free_data)  {
312                 usurf->animation.animadata = (void *)free_data;
313                 free_data = free_data->next_free;
314             }
315             else    {
316                 usurf->animation.animadata = (void *)malloc(sizeof(struct animation_data));
317             }
318             memset(usurf->animation.animadata, 0, sizeof(struct animation_data));
319         }
320         animadata = (struct animation_data *)usurf->animation.animadata;
321         animadata->x = usurf->x;
322         animadata->y = usurf->y;
323         animadata->width = usurf->width;
324         animadata->height = usurf->height;
325         animadata->geometry_saved = 1;
326     }
327     else if (! usurf->animation.animadata)    {
328         animation_end(usurf, 0);
329         return 999;
330     }
331
332     if (nowsec >= usurf->animation.starttime)   {
333         nowsec = nowsec - usurf->animation.starttime;   /* elapsed time(ms) */
334     }
335     else    {
336         nowsec = (uint32_t)(((long long)0x100000000L) +
337                             ((long long)nowsec) - ((long long)usurf->animation.starttime));
338     }
339     switch (usurf->animation.state) {
340     case ICO_WINDOW_MGR_ANIMATION_STATE_SHOW:
341         time = usurf->animation.show_time;
342         break;
343     case ICO_WINDOW_MGR_ANIMATION_STATE_HIDE:
344         time = usurf->animation.hide_time;
345         break;
346     case ICO_WINDOW_MGR_ANIMATION_STATE_MOVE:
347         time = usurf->animation.move_time;
348         break;
349     default:
350         time = usurf->animation.resize_time;
351         break;
352     }
353     time = (time > 0) ? time : animation_time;
354     if (((output == NULL) && (msecs == 0)) || (nowsec >= ((uint32_t)time))) {
355         par = 100;
356     }
357     else    {
358         par = (nowsec * 100 + time / 2) / time;
359         if (par < 2)    par = 2;
360     }
361     if ((par >= 100) ||
362         (abs(usurf->animation.current - par) >= animation_fpar)) {
363         usurf->animation.current = par;
364         return 0;
365     }
366     return par;
367 }
368
369 /*--------------------------------------------------------------------------*/
370 /**
371  * @brief   animation_end: terminate animation
372  *
373  * @param[in]   usurf       UIFW surface table
374  * @param[in]   disp        display control(1)/no display(0)
375  * @return      none
376  */
377 /*--------------------------------------------------------------------------*/
378 static void
379 animation_end(struct uifw_win_surface *usurf, const int disp)
380 {
381     struct animation_data   *animadata;
382
383     usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_NONE;
384     animadata = (struct animation_data *)usurf->animation.animadata;
385
386     if (animadata)  {
387         if (animadata->end_function)    {
388             (*animadata->end_function)(&usurf->animation.animation);
389         }
390         if (animadata->geometry_saved > 1)  {
391             usurf->x = animadata->x;
392             usurf->y = animadata->y;
393             usurf->width = animadata->width;
394             usurf->height = animadata->height;
395             animadata->geometry_saved = 0;
396         }
397         wl_list_remove(&usurf->animation.animation.link);
398         if (animadata->transform_set)   {
399             wl_list_remove(&animadata->transform.link);
400             animadata->transform_set = 0;
401         }
402         weston_surface_geometry_dirty(usurf->surface);
403     }
404     if (disp)   {
405         if ((usurf->animation.visible == ANIMA_HIDE_AT_END) &&
406             (usurf->visible != 0))  {
407             ico_window_mgr_set_visible(usurf, 0);
408             weston_surface_damage(usurf->surface);
409         }
410         if ((usurf->animation.visible == ANIMA_SHOW_AT_END) &&
411             (usurf->visible == 0))  {
412             ico_window_mgr_set_visible(usurf, 1);
413             weston_surface_damage(usurf->surface);
414         }
415         usurf->restrain_configure = 0;
416         weston_surface_geometry_dirty(usurf->surface);
417         weston_compositor_schedule_repaint(weston_ec);
418     }
419     usurf->animation.visible = ANIMA_NOCONTROL_AT_END;
420     if (usurf->animation.next_name != ICO_WINDOW_MGR_ANIMATION_NONE)    {
421         switch(usurf->animation.type)   {
422         case ICO_WINDOW_MGR_ANIMATION_OPHIDE:
423             usurf->animation.hide_name = usurf->animation.next_name;
424             break;
425         case ICO_WINDOW_MGR_ANIMATION_OPSHOW:
426             usurf->animation.show_name = usurf->animation.next_name;
427             break;
428         case ICO_WINDOW_MGR_ANIMATION_OPMOVE:
429             usurf->animation.move_name = usurf->animation.next_name;
430             break;
431         case ICO_WINDOW_MGR_ANIMATION_OPRESIZE:
432             usurf->animation.resize_name = usurf->animation.next_name;
433             break;
434         default:
435             break;
436         }
437         usurf->animation.next_name = ICO_WINDOW_MGR_ANIMATION_NONE;
438     }
439     if (animadata)   {
440         usurf->animation.animadata = NULL;
441         animadata->next_free = free_data;
442         free_data = animadata;
443     }
444     usurf->animation.type = ICO_WINDOW_MGR_ANIMATION_OPNONE;
445 }
446
447 /*--------------------------------------------------------------------------*/
448 /**
449  * @brief   animation_slide: slide animation
450  *
451  * @param[in]   animation   weston animation table
452  * @param[in]   outout      weston output table
453  * @param[in]   mseces      current time(unused)
454  * @return      none
455  */
456 /*--------------------------------------------------------------------------*/
457 static void
458 animation_slide(struct weston_animation *animation,
459                 struct weston_output *output, uint32_t msecs)
460 {
461     struct uifw_win_surface *usurf;
462     struct animation_data   *animadata;
463     struct weston_surface   *es;
464     int         dwidth, dheight;
465     int         par;
466     int         x;
467     int         y;
468
469     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
470
471     par = animation_cont(animation, output, msecs);
472     if (par > 0)    {
473         /* continue animation   */
474         if( par <= 100) {
475             weston_compositor_schedule_repaint(weston_ec);
476         }
477         return;
478     }
479     par = usurf->animation.current;
480     animadata = (struct animation_data *)usurf->animation.animadata;
481
482     uifw_trace("animation_slide: usurf=%08x count=%d %d%% name=%d state=%d",
483                (int)usurf, animation->frame_counter, par,
484                usurf->animation.name, usurf->animation.state);
485
486     es = usurf->surface;
487     x = usurf->x;
488     y = usurf->y;
489
490     switch (usurf->animation.name)  {
491     case ANIMA_SLIDE_TORIGHT:           /* slide in left to right           */
492         if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
493             /* slide in left to right   */
494             x = 0 - animadata->width +
495                 ((animadata->x + animadata->width) * par / 100);
496         }
497         else    {
498             /* slide out right to left  */
499             x = 0 - animadata->width +
500                 ((animadata->x + animadata->width) * (100 - par) / 100);
501         }
502         break;
503     case ANIMA_SLIDE_TOLEFT:            /* slide in right to left           */
504         dwidth = (container_of(weston_ec->output_list.next,
505                                struct weston_output, link))->width;
506         if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
507             /* slide in right to left   */
508             x = animadata->x + (dwidth - animadata->x) * (100 - par) / 100;
509         }
510         else    {
511             /* slide out left to right  */
512             x = animadata->x + (dwidth - animadata->x) * par / 100;
513         }
514         break;
515     case ANIMA_SLIDE_TOBOTTOM:          /* slide in top to bottom           */
516         if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
517             /* slide in top to bottom   */
518             y = 0 - animadata->height +
519                 ((animadata->y + animadata->height) * par / 100);
520         }
521         else    {
522             /* slide out bottom to top  */
523             y = 0 - animadata->height +
524                 ((animadata->y + animadata->height) * (100 - par) / 100);
525         }
526         break;
527     default: /*ANIMA_SLIDE_TOTOP*/      /* slide in bottom to top           */
528         dheight = (container_of(weston_ec->output_list.next,
529                                 struct weston_output, link))->height;
530         if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
531             /* slide in bottom to top   */
532             y = animadata->y + (dheight - animadata->y) * (100 - par) / 100;
533         }
534         else    {
535             /* slide out top to bottom  */
536             y = animadata->y + (dheight - animadata->y) * par / 100;
537         }
538         break;
539     }
540
541     es->geometry.x = usurf->node_tbl->disp_x + x;
542     es->geometry.y = usurf->node_tbl->disp_y + y;
543     if ((es->output) && (es->buffer_ref.buffer) &&
544         (es->geometry.width > 0) && (es->geometry.height > 0)) {
545         weston_surface_geometry_dirty(es);
546         weston_surface_damage(es);
547     }
548     if (par >= 100) {
549         /* end of animation     */
550         animadata->geometry_saved ++;       /* restore geometry     */
551         animation_end(usurf, 1);
552         uifw_trace("animation_slide: End of animation");
553     }
554     else    {
555         /* continue animation   */
556         weston_compositor_schedule_repaint(weston_ec);
557     }
558 }
559
560 /*--------------------------------------------------------------------------*/
561 /**
562  * @brief   animation_fade: fade animation
563  *
564  * @param[in]   animation   weston animation table
565  * @param[in]   outout      weston output table
566  * @param[in]   mseces      current time(unused)
567  * @return      none
568  */
569 /*--------------------------------------------------------------------------*/
570 static void
571 animation_fade(struct weston_animation *animation,
572                struct weston_output *output, uint32_t msecs)
573 {
574     struct uifw_win_surface *usurf;
575     struct animation_data   *animadata;
576     struct weston_surface   *es;
577     int         par;
578
579     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
580
581     par = animation_cont(animation, output, msecs);
582     if (par > 0)    {
583         /* continue animation   */
584         if( par <= 100) {
585             weston_compositor_schedule_repaint(weston_ec);
586         }
587         return;
588     }
589
590     animadata = (struct animation_data *)usurf->animation.animadata;
591     es = usurf->surface;
592     par = usurf->animation.current;
593     if (animation->frame_counter == 1)  {
594         if (animadata->transform_set == 0)  {
595             animadata->transform_set = 1;
596             weston_matrix_init(&animadata->transform.matrix);
597             wl_list_init(&animadata->transform.link);
598             wl_list_insert(&es->geometry.transformation_list,
599                            &animadata->transform.link);
600         }
601         animadata->end_function = animation_fade_end;
602     }
603
604     uifw_trace("animation_fade: usurf=%08x count=%d %d%% name=%d state=%d",
605                (int)usurf, animation->frame_counter, par,
606                usurf->animation.name, usurf->animation.state);
607
608     if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
609         /* fade in                  */
610         es->alpha = ((double)par) / ((double)100.0);
611     }
612     else    {
613         /* fade out                 */
614         es->alpha = ((double)1.0) - (((double)par) / ((double)100.0));
615     }
616     if (es->alpha < 0.0)        es->alpha = 0.0;
617     else if (es->alpha > 1.0)   es->alpha = 1.0;
618
619     if ((es->output) && (es->buffer_ref.buffer) &&
620         (es->geometry.width > 0) && (es->geometry.height > 0)) {
621         weston_surface_damage(es);
622     }
623     if (par >= 100) {
624         /* end of animation     */
625         animation_end(usurf, 1);
626         uifw_trace("animation_fade: End of animation");
627     }
628     else    {
629         /* continue animation   */
630         weston_compositor_schedule_repaint(weston_ec);
631     }
632 }
633
634 /*--------------------------------------------------------------------------*/
635 /**
636  * @brief   animation_fade_end: fade animation end
637  *
638  * @param[in]   animation   weston animation table
639  * @return      none
640  */
641 /*--------------------------------------------------------------------------*/
642 static void
643 animation_fade_end(struct weston_animation *animation)
644 {
645     struct uifw_win_surface *usurf;
646     struct weston_surface   *es;
647
648     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
649     es = usurf->surface;
650     es->alpha = 1.0;
651
652     if ((es->output) && (es->buffer_ref.buffer) &&
653         (es->geometry.width > 0) && (es->geometry.height > 0)) {
654         weston_surface_damage(es);
655     }
656 }
657
658 /*--------------------------------------------------------------------------*/
659 /**
660  * @brief   module_init: initialize ico_window_animation
661  *                       this function called from ico_pluign_loader
662  *
663  * @param[in]   es          weston compositor
664  * @param[in]   argc        number of arguments(unused)
665  * @param[in]   argv        argument list(unused)
666  * @return      result
667  * @retval      0           sccess
668  * @retval      -1          error
669  */
670 /*--------------------------------------------------------------------------*/
671 WL_EXPORT int
672 module_init(struct weston_compositor *ec, int *argc, char *argv[])
673 {
674     int     i;
675     struct animation_data   *animadata;
676
677     uifw_info("ico_window_animation: Enter(module_init)");
678
679     /* allocate animation datas     */
680     free_data = NULL;
681     for (i = 0; i < 50; i++)    {
682         animadata = (struct animation_data *)malloc(sizeof(struct animation_data));
683         if (! animadata)    {
684             uifw_error("ico_window_animation: No Memory(module_init)");
685             return -1;
686         }
687         animadata->next_free = free_data;
688         free_data = animadata;
689     }
690
691     weston_ec = ec;
692     default_animation = (char *)ico_ivi_default_animation_name();
693     animation_time = ico_ivi_default_animation_time();
694     animation_fpar = ico_ivi_default_animation_fps();
695
696     animation_fpar = ((1000 * 100) / animation_fpar) / animation_time;
697
698     ico_window_mgr_set_hook_animation(ico_window_animation);
699
700     uifw_info("ico_window_animation: Leave(module_init)");
701
702     return 0;
703 }
704