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