12ff474c1cd389a08ef85d1f0a911acee2feffa1
[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     char    transform_set;                  /* need transform reset at end          */
63     char    res[3];                         /* (unused)                             */
64     struct weston_transform transform;      /* transform matrix                     */
65     void    (*end_function)(struct weston_animation *animation);
66                                             /* animation end function               */
67 };
68
69 /* static valiables             */
70 static struct weston_compositor *weston_ec; /* Weston compositor                    */
71 static char *default_animation;             /* default animation name               */
72 static int  animation_fps;                  /* animation frame rate(frame/sec)      */
73 static int  animation_time;                 /* default animation time(ms)           */
74 static struct animation_data    *free_data; /* free data list                       */
75
76 /* static function              */
77                                             /* slide animation                      */
78 static void animation_slide(struct weston_animation *animation,
79                             struct weston_output *output, uint32_t msecs);
80                                             /* fade animation                       */
81 static void animation_fade(struct weston_animation *animation,
82                            struct weston_output *output, uint32_t msecs);
83                                             /* fade animation end                   */
84 static void animation_fade_end(struct weston_animation *animation);
85                                             /* zoom animation                       */
86 static void animation_zoom(struct weston_animation *animation,
87                            struct weston_output *output, uint32_t msecs);
88                                             /* zoom animation end                   */
89 static void animation_zoom_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_ANIMANOCTL success(no control)
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     int         animaid;
116
117     if (op == ICO_WINDOW_MGR_ANIMATION_NAME)    {
118         /* convert animation name to animation type value   */
119         if (strcasecmp((char *)data, "fade") == 0)  {
120             uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_FADE);
121             return ANIMA_FADE;
122         }
123         else if (strcasecmp((char *)data, "zoom") == 0) {
124             uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_ZOOM);
125             return ANIMA_ZOOM;
126         }
127         else if (strcasecmp((char *)data, "slide.toleft") == 0) {
128             uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_SLIDE_TOLEFT);
129             return ANIMA_SLIDE_TOLEFT;
130         }
131         else if (strcasecmp((char *)data, "slide.toright") == 0)    {
132             uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_SLIDE_TORIGHT);
133             return ANIMA_SLIDE_TORIGHT;
134         }
135         else if ((strcasecmp((char *)data, "slide.totop") == 0) ||
136                  (strcasecmp((char *)data, "slide") == 0))  {
137             uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_SLIDE_TOTOP);
138             return ANIMA_SLIDE_TOTOP;
139         }
140         else if (strcasecmp((char *)data, "slide.tobottom") == 0)   {
141             uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_SLIDE_TOBOTTOM);
142             return ANIMA_SLIDE_TOBOTTOM;
143         }
144         uifw_warn("ico_window_animation: Unknown Type %s", (char *)data);
145         return ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
146     }
147
148     usurf = (struct uifw_win_surface *)data;
149
150     if (op == ICO_WINDOW_MGR_ANIMATION_DESTROY) {
151         if ((usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE) ||
152             (usurf->animation.animadata != NULL)) {
153             uifw_trace("ico_window_animation: Destroy %08x", (int)usurf);
154             animation_end(usurf, 0);
155         }
156         return ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
157     }
158
159     usurf->animation.visible = ANIMA_NOCONTROL_AT_END;
160
161     if (op == ICO_WINDOW_MGR_ANIMATION_OPCANCEL)    {
162         /* cancel animation                     */
163         if ((usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE) &&
164             (usurf->animation.animation.frame != NULL)) {
165             uifw_trace("ico_window_animation: cancel %s.%08x",
166                        usurf->uclient->appid, usurf->surfaceid);
167             (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 0);
168         }
169         animation_end(usurf, 1);
170         ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
171     }
172     else    {
173         /* setup animation              */
174         if ((usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_NONE) ||
175             (usurf->animation.current > 95))    {
176             usurf->animation.animation.frame_counter = 1;
177             usurf->animation.current = 0;
178             usurf->animation.ahalf = 0;
179             if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_NONE)  {
180                 wl_list_init(&usurf->animation.animation.link);
181                 output = container_of(weston_ec->output_list.next,
182                                       struct weston_output, link);
183                 wl_list_insert(output->animation_list.prev,
184                                &usurf->animation.animation.link);
185             }
186         }
187         else if (((usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW) &&
188                   ((op == ICO_WINDOW_MGR_ANIMATION_OPHIDE) ||
189                    (op == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS))) ||
190                  ((usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_HIDE) &&
191                   ((op == ICO_WINDOW_MGR_ANIMATION_OPSHOW) ||
192                    (op == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS))))   {
193             /* change ...In(ex.FadeIn) to ...Out(FadeOut) or ...Out to ...In    */
194             nowsec = weston_compositor_get_time();
195             usurf->animation.current = 100 - usurf->animation.current;
196             if ((op == ICO_WINDOW_MGR_ANIMATION_OPHIDE)||
197                 (op == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS)) {
198                 usurf->animation.time = usurf->animation.hide_time;
199             }
200             else    {
201                 usurf->animation.time = usurf->animation.show_time;
202             }
203             if (usurf->animation.time == 0) {
204                 usurf->animation.time = animation_time;
205             }
206             ret = ((usurf->animation.current) * usurf->animation.time) / 100;
207             if (nowsec >= (uint32_t)ret)    {
208                 usurf->animation.starttime = nowsec - ret;
209             }
210             else    {
211                 usurf->animation.starttime = ((long long)nowsec) + ((long long)0x100000000L)
212                                              - ((long long)ret);
213             }
214             usurf->animation.animation.frame_counter = 2;
215         }
216
217         /* set animation function       */
218         if ((op == ICO_WINDOW_MGR_ANIMATION_OPSHOW) ||
219             (op == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS)) {
220             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_SHOW;
221             animaid = usurf->animation.show_anima;
222             usurf->animation.anima = animaid;
223             uifw_trace("ico_window_animation: show(in) %s.%08x anima=%d",
224                        usurf->uclient->appid, usurf->surfaceid, animaid);
225             ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
226         }
227         else if ((op == ICO_WINDOW_MGR_ANIMATION_OPHIDE) ||
228                  (op == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS))    {
229             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_HIDE;
230             animaid = usurf->animation.hide_anima;
231             usurf->animation.anima = animaid;
232             uifw_trace("ico_window_animation: hide(out) %s.%08x anima=%d",
233                        usurf->uclient->appid, usurf->surfaceid, animaid);
234             ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL;
235             usurf->animation.visible = ANIMA_HIDE_AT_END;
236         }
237         else if (op == ICO_WINDOW_MGR_ANIMATION_OPMOVE)    {
238             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_MOVE;
239             animaid = usurf->animation.move_anima;
240             usurf->animation.anima = animaid;
241             uifw_trace("ico_window_animation: move %s.%08x anima=%d",
242                        usurf->uclient->appid, usurf->surfaceid, animaid);
243             ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL;
244         }
245         else if (op == ICO_WINDOW_MGR_ANIMATION_OPRESIZE)    {
246             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_RESIZE;
247             animaid = usurf->animation.resize_anima;
248             usurf->animation.anima = animaid;
249             uifw_trace("ico_window_animation: resize %s.%08x anima=%d",
250                        usurf->uclient->appid, usurf->surfaceid, animaid);
251             ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL;
252         }
253         else    {
254             uifw_trace("ico_window_animation: Op=%d unknown", op);
255             return ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
256         }
257         if ((animaid == ANIMA_SLIDE_TOLEFT) || (animaid == ANIMA_SLIDE_TORIGHT) ||
258             (animaid == ANIMA_SLIDE_TOTOP) || (animaid == ANIMA_SLIDE_TOBOTTOM))  {
259             usurf->animation.animation.frame = animation_slide;
260             usurf->restrain_configure = 1;
261             (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 1);
262         }
263         else if (animaid == ANIMA_FADE)   {
264             usurf->animation.animation.frame = animation_fade;
265             usurf->restrain_configure = 1;
266             (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 1);
267         }
268         else if (animaid == ANIMA_ZOOM)   {
269             usurf->animation.animation.frame = animation_zoom;
270             usurf->restrain_configure = 1;
271             (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 1);
272         }
273         else    {
274             /* no yet support   */
275             usurf->animation.animation.frame = NULL;
276             usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_NONE;
277             usurf->restrain_configure = 0;
278             usurf->animation.anima = 0;
279             wl_list_remove(&usurf->animation.animation.link);
280             ret = ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
281         }
282         usurf->animation.type = op;
283     }
284     weston_compositor_schedule_repaint(weston_ec);
285     return ret;
286 }
287
288 /*--------------------------------------------------------------------------*/
289 /**
290  * @brief   animation_cont: continue animation
291  *
292  * @param[in]   animation   weston animation table
293  * @param[in]   output      weston output table
294  * @param[in]   msecs       current time stamp
295  * @return      time has come
296  * @retval      =0          time has come
297  * @retval      >0          time has not yet come(return value is current parcent)
298  */
299 /*--------------------------------------------------------------------------*/
300 static int
301 animation_cont(struct weston_animation *animation, struct weston_output *output,
302                uint32_t msecs)
303 {
304     struct uifw_win_surface *usurf;
305     int         par;
306     uint32_t    nowsec;
307
308     nowsec = weston_compositor_get_time();
309
310     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
311
312     if (animation->frame_counter <= 1)  {
313         /* first call, initialize           */
314         animation->frame_counter = 1;
315         usurf->animation.starttime = nowsec;
316         usurf->animation.current = 1000;
317         if (! usurf->animation.animadata) {
318             if (free_data)  {
319                 usurf->animation.animadata = (void *)free_data;
320                 free_data = free_data->next_free;
321             }
322             else    {
323                 usurf->animation.animadata = (void *)malloc(sizeof(struct animation_data));
324             }
325             memset(usurf->animation.animadata, 0, sizeof(struct animation_data));
326         }
327     }
328     else if (! usurf->animation.animadata)    {
329         animation_end(usurf, 0);
330         return 999;
331     }
332
333     if (nowsec >= usurf->animation.starttime)   {
334         nowsec = nowsec - usurf->animation.starttime;   /* elapsed time(ms) */
335     }
336     else    {
337         nowsec = (uint32_t)(((long long)0x100000000L) +
338                             ((long long)nowsec) - ((long long)usurf->animation.starttime));
339     }
340     switch (usurf->animation.state) {
341     case ICO_WINDOW_MGR_ANIMATION_STATE_SHOW:
342         usurf->animation.time = usurf->animation.show_time;
343         break;
344     case ICO_WINDOW_MGR_ANIMATION_STATE_HIDE:
345         usurf->animation.time = usurf->animation.hide_time;
346         break;
347     case ICO_WINDOW_MGR_ANIMATION_STATE_MOVE:
348         usurf->animation.time = usurf->animation.move_time;
349         break;
350     default:
351         usurf->animation.time = usurf->animation.resize_time;
352         break;
353     }
354     if (usurf->animation.time == 0) {
355         usurf->animation.time = animation_time;
356     }
357     if (((output == NULL) && (msecs == 0)) || (nowsec >= ((uint32_t)usurf->animation.time))) {
358         par = 100;
359     }
360     else    {
361         par = (nowsec * 100 + usurf->animation.time / 2) / usurf->animation.time;
362         if (par < 2)    par = 2;
363     }
364     if ((par >= 100) ||
365         (abs(usurf->animation.current - par) >=
366          (((1000 * 100) / animation_fps) / usurf->animation.time))) {
367         usurf->animation.current = par;
368         return 0;
369     }
370     return par;
371 }
372
373 /*--------------------------------------------------------------------------*/
374 /**
375  * @brief   animation_end: terminate animation
376  *
377  * @param[in]   usurf       UIFW surface table
378  * @param[in]   disp        display control(1)/no display(0)
379  * @return      none
380  */
381 /*--------------------------------------------------------------------------*/
382 static void
383 animation_end(struct uifw_win_surface *usurf, const int disp)
384 {
385     struct animation_data   *animadata;
386
387     usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_NONE;
388     animadata = (struct animation_data *)usurf->animation.animadata;
389
390     if (animadata)  {
391         if (animadata->end_function)    {
392             (*animadata->end_function)(&usurf->animation.animation);
393         }
394         wl_list_remove(&usurf->animation.animation.link);
395         if (animadata->transform_set)   {
396             wl_list_remove(&animadata->transform.link);
397             animadata->transform_set = 0;
398         }
399         weston_surface_geometry_dirty(usurf->surface);
400     }
401     if (disp)   {
402         if ((usurf->animation.visible == ANIMA_HIDE_AT_END) &&
403             (usurf->visible != 0))  {
404             ico_window_mgr_set_visible(usurf, 0);
405             weston_surface_damage(usurf->surface);
406         }
407         if ((usurf->animation.visible == ANIMA_SHOW_AT_END) &&
408             (usurf->visible == 0))  {
409             ico_window_mgr_set_visible(usurf, 1);
410             weston_surface_damage(usurf->surface);
411         }
412         usurf->restrain_configure = 0;
413         weston_surface_geometry_dirty(usurf->surface);
414         weston_compositor_schedule_repaint(weston_ec);
415     }
416     usurf->animation.visible = ANIMA_NOCONTROL_AT_END;
417     if (usurf->animation.next_anima != ICO_WINDOW_MGR_ANIMATION_NONE)    {
418         switch(usurf->animation.type)   {
419         case ICO_WINDOW_MGR_ANIMATION_OPHIDE:
420         case ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS:
421             usurf->animation.hide_anima = usurf->animation.next_anima;
422             break;
423         case ICO_WINDOW_MGR_ANIMATION_OPSHOW:
424         case ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS:
425             usurf->animation.show_anima = usurf->animation.next_anima;
426             break;
427         case ICO_WINDOW_MGR_ANIMATION_OPMOVE:
428             usurf->animation.move_anima = usurf->animation.next_anima;
429             break;
430         case ICO_WINDOW_MGR_ANIMATION_OPRESIZE:
431             usurf->animation.resize_anima = usurf->animation.next_anima;
432             break;
433         default:
434             break;
435         }
436         usurf->animation.next_anima = ICO_WINDOW_MGR_ANIMATION_NONE;
437     }
438     if (animadata)   {
439         usurf->animation.animadata = NULL;
440         animadata->next_free = free_data;
441         free_data = animadata;
442     }
443     usurf->animation.type = ICO_WINDOW_MGR_ANIMATION_OPNONE;
444 }
445
446 /*--------------------------------------------------------------------------*/
447 /**
448  * @brief   animation_slide: slide animation
449  *
450  * @param[in]   animation   weston animation table
451  * @param[in]   outout      weston output table
452  * @param[in]   mseces      current time(unused)
453  * @return      none
454  */
455 /*--------------------------------------------------------------------------*/
456 static void
457 animation_slide(struct weston_animation *animation,
458                 struct weston_output *output, uint32_t msecs)
459 {
460     struct uifw_win_surface *usurf;
461     struct weston_surface   *es;
462     int         dwidth, dheight;
463     int         par;
464     int         x;
465     int         y;
466
467     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
468
469     par = animation_cont(animation, output, msecs);
470     if (par > 0)    {
471         /* continue animation   */
472         if( par <= 100) {
473             weston_compositor_schedule_repaint(weston_ec);
474         }
475         return;
476     }
477     par = usurf->animation.current;
478
479     uifw_trace("animation_slide: usurf=%08x count=%d %d%% anima=%d state=%d",
480                (int)usurf, animation->frame_counter, par,
481                usurf->animation.anima, usurf->animation.state);
482
483     es = usurf->surface;
484     x = usurf->x;
485     y = usurf->y;
486
487     switch (usurf->animation.anima)  {
488     case ANIMA_SLIDE_TORIGHT:           /* slide in left to right           */
489         if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
490             /* slide in left to right   */
491             x = 0 - usurf->animation.pos_width +
492                 ((usurf->animation.pos_x + usurf->animation.pos_width) * par / 100);
493         }
494         else    {
495             /* slide out right to left  */
496             x = 0 - usurf->animation.pos_width +
497                 ((usurf->animation.pos_x + usurf->animation.pos_width) * (100 - par) / 100);
498         }
499         break;
500     case ANIMA_SLIDE_TOLEFT:            /* slide in right to left           */
501         dwidth = (container_of(weston_ec->output_list.next,
502                                struct weston_output, link))->width;
503         if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
504             /* slide in right to left   */
505             x = usurf->animation.pos_x +
506                 (dwidth - usurf->animation.pos_x) * (100 - par) / 100;
507         }
508         else    {
509             /* slide out left to right  */
510             x = usurf->animation.pos_x + (dwidth - usurf->animation.pos_x) * par / 100;
511         }
512         break;
513     case ANIMA_SLIDE_TOBOTTOM:          /* slide in top to bottom           */
514         if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
515             /* slide in top to bottom   */
516             y = 0 - usurf->animation.pos_height +
517                 ((usurf->animation.pos_y + usurf->animation.pos_height) * par / 100);
518         }
519         else    {
520             /* slide out bottom to top  */
521             y = 0 - usurf->animation.pos_height +
522                 ((usurf->animation.pos_y + usurf->animation.pos_height) * (100 - par) / 100);
523         }
524         break;
525     default: /*ANIMA_SLIDE_TOTOP*/      /* slide in bottom to top           */
526         dheight = (container_of(weston_ec->output_list.next,
527                                 struct weston_output, link))->height;
528         if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
529             /* slide in bottom to top   */
530             y = usurf->animation.pos_y +
531                 (dheight - usurf->animation.pos_y) * (100 - par) / 100;
532         }
533         else    {
534             /* slide out top to bottom  */
535             y = usurf->animation.pos_y + (dheight - usurf->animation.pos_y) * par / 100;
536         }
537         break;
538     }
539
540     es->geometry.x = usurf->node_tbl->disp_x + x;
541     es->geometry.y = usurf->node_tbl->disp_y + y;
542     if ((es->output) && (es->buffer_ref.buffer) &&
543         (es->geometry.width > 0) && (es->geometry.height > 0)) {
544         weston_surface_geometry_dirty(es);
545         weston_surface_damage(es);
546     }
547     if (par >= 100) {
548         /* end of animation     */
549         animation_end(usurf, 1);
550         uifw_trace("animation_slide: End of animation");
551     }
552     else    {
553         /* continue animation   */
554         weston_compositor_schedule_repaint(weston_ec);
555     }
556 }
557
558 /*--------------------------------------------------------------------------*/
559 /**
560  * @brief   animation_fade: fade animation
561  *
562  * @param[in]   animation   weston animation table
563  * @param[in]   outout      weston output table
564  * @param[in]   mseces      current time(unused)
565  * @return      none
566  */
567 /*--------------------------------------------------------------------------*/
568 static void
569 animation_fade(struct weston_animation *animation,
570                struct weston_output *output, uint32_t msecs)
571 {
572     struct uifw_win_surface *usurf;
573     struct animation_data   *animadata;
574     struct weston_surface   *es;
575     int         par;
576
577     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
578
579     par = animation_cont(animation, output, msecs);
580     if (par > 0)    {
581         /* continue animation   */
582         if( par <= 100) {
583             weston_compositor_schedule_repaint(weston_ec);
584         }
585         return;
586     }
587
588     animadata = (struct animation_data *)usurf->animation.animadata;
589     es = usurf->surface;
590     par = usurf->animation.current;
591     if (animation->frame_counter == 1)  {
592         if (animadata->transform_set == 0)  {
593             animadata->transform_set = 1;
594             weston_matrix_init(&animadata->transform.matrix);
595             wl_list_init(&animadata->transform.link);
596             wl_list_insert(&es->geometry.transformation_list,
597                            &animadata->transform.link);
598         }
599         animadata->end_function = animation_fade_end;
600
601         if ((usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS) ||
602             (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS))  {
603             ico_window_mgr_set_weston_surface(usurf,
604                                               usurf->animation.pos_x, usurf->animation.pos_y,
605                                               usurf->animation.pos_width,
606                                               usurf->animation.pos_height);
607         }
608     }
609
610     if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
611         /* fade in                  */
612         es->alpha = ((float)par) / 100.0f;
613     }
614     else if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_HIDE)    {
615         /* fade out                 */
616         es->alpha = 1.0f - (((float)par) / 100.0f);
617     }
618     else    {
619         /* fade move/resize         */
620         if ((par >= 50) || (usurf->animation.ahalf))    {
621             es->alpha = ((float)(par*2 - 100)) / 100.0f;
622             if (usurf->animation.ahalf == 0)    {
623                 uifw_trace("animation_fade: fade move chaneg to show");
624                 usurf->animation.ahalf = 1;
625                 es->alpha = 0.0;
626                 ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
627                                                   usurf->width, usurf->height);
628                 ico_window_mgr_change_surface(usurf,
629                                               usurf->animation.no_configure ? -1 : 0, 1);
630             }
631         }
632         else    {
633             es->alpha = 1.0f - (((float)(par*2)) / 100.0f);
634         }
635     }
636     if (es->alpha < 0.0)        es->alpha = 0.0;
637     else if (es->alpha > 1.0)   es->alpha = 1.0;
638
639     uifw_trace("animation_fade: usurf=%08x count=%d %d%% alpha=%1.2f anima=%d state=%d",
640                (int)usurf, animation->frame_counter, par, es->alpha,
641                usurf->animation.anima, usurf->animation.state);
642
643     if ((es->output) && (es->buffer_ref.buffer) &&
644         (es->geometry.width > 0) && (es->geometry.height > 0)) {
645         weston_surface_damage(es);
646     }
647     if (par >= 100) {
648         /* end of animation     */
649         animation_end(usurf, 1);
650         uifw_trace("animation_fade: End of animation");
651     }
652     else    {
653         /* continue animation   */
654         weston_compositor_schedule_repaint(weston_ec);
655     }
656 }
657
658 /*--------------------------------------------------------------------------*/
659 /**
660  * @brief   animation_fade_end: fade animation end
661  *
662  * @param[in]   animation   weston animation table
663  * @return      none
664  */
665 /*--------------------------------------------------------------------------*/
666 static void
667 animation_fade_end(struct weston_animation *animation)
668 {
669     struct uifw_win_surface *usurf;
670     struct weston_surface   *es;
671
672     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
673     if (usurf && usurf->surface)    {
674         es = usurf->surface;
675         es->alpha = 1.0;
676
677         if ((es->output) && (es->buffer_ref.buffer) &&
678             (es->geometry.width > 0) && (es->geometry.height > 0)) {
679             weston_surface_damage(es);
680         }
681     }
682 }
683
684 /*--------------------------------------------------------------------------*/
685 /**
686  * @brief   animation_zoom: zoom animation
687  *
688  * @param[in]   animation   weston animation table
689  * @param[in]   outout      weston output table
690  * @param[in]   mseces      current time(unused)
691  * @return      none
692  */
693 /*--------------------------------------------------------------------------*/
694 static void
695 animation_zoom(struct weston_animation *animation,
696                struct weston_output *output, uint32_t msecs)
697 {
698     struct uifw_win_surface *usurf;
699     struct animation_data   *animadata;
700     struct weston_surface   *es;
701     int         par;
702     float       scalex, scaley;
703     float       fu, fa, fp;
704     int         x, y;
705
706     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
707
708     par = animation_cont(animation, output, msecs);
709     if (par > 0)    {
710         /* continue animation   */
711         if( par <= 100) {
712             weston_compositor_schedule_repaint(weston_ec);
713         }
714         return;
715     }
716
717     animadata = (struct animation_data *)usurf->animation.animadata;
718     es = usurf->surface;
719     par = usurf->animation.current;
720     if (animation->frame_counter == 1)  {
721         if (animadata->transform_set == 0)  {
722             animadata->transform_set = 1;
723             weston_matrix_init(&animadata->transform.matrix);
724             wl_list_init(&animadata->transform.link);
725             wl_list_insert(&es->geometry.transformation_list,
726                            &animadata->transform.link);
727         }
728         animadata->end_function = animation_zoom_end;
729
730         if ((usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS) ||
731             (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS))  {
732             ico_window_mgr_set_weston_surface(usurf,
733                                               usurf->animation.pos_x, usurf->animation.pos_y,
734                                               usurf->animation.pos_width,
735                                               usurf->animation.pos_height);
736         }
737     }
738
739     if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
740         /* zoom in                  */
741         scalex = ((float)par + 5.0f) / 105.0f;
742         scaley = scalex;
743     }
744     else if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_HIDE)    {
745         /* zoom out                 */
746         scalex = 1.0f - (((float)par + 5.0f) / 105.0f);
747         scaley = scalex;
748     }
749     else    {
750         /* zoom move/resize         */
751         ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
752                                           usurf->width, usurf->height);
753         ico_window_mgr_change_surface(usurf, usurf->animation.no_configure ? -1 : 0, 1);
754
755         fu = (float)usurf->width;
756         fa = (float)usurf->animation.pos_width;
757         fp = (100.0f - (float)par) / 100.0f;
758         scalex = (fu - (fu - fa) * fp) / fu;
759         fu = (float)usurf->height;
760         fa = (float)usurf->animation.pos_height;
761         scaley = (fu - (fu - fa) * fp) / fu;
762
763         x = (((float)usurf->animation.pos_x) - ((float)usurf->x)) * fp + (float)usurf->x
764             + (((float)usurf->width * scalex) - (float)usurf->width) / 2.0f;
765         y = (((float)usurf->animation.pos_y) - ((float)usurf->y)) * fp + (float)usurf->y
766             + (((float)usurf->height * scaley) - (float) usurf->height) / 2.0f;
767         uifw_trace("animation_zoom: usurf=%08x %d%% x=%d/%d y=%d/%d",
768                    (int)usurf, par, x, usurf->x, y, usurf->y);
769         uifw_trace("animation_zoom: sx=%4.2f sy=%4.2f x=%d->%d y=%d->%d cur=%d,%d",
770                    scalex, scaley, usurf->animation.pos_x, usurf->x,
771                    usurf->animation.pos_y, usurf->y, x, y);
772         ico_window_mgr_set_weston_surface(usurf, x, y, usurf->width, usurf->height);
773     }
774     weston_matrix_init(&animadata->transform.matrix);
775     weston_matrix_translate(&animadata->transform.matrix,
776                             -0.5f * usurf->width, -0.5f * usurf->height, 0);
777     weston_matrix_scale(&animadata->transform.matrix, scalex, scaley, 1.0f);
778     weston_matrix_translate(&animadata->transform.matrix,
779                             0.5f * usurf->width, 0.5f * usurf->height, 0);
780     
781     uifw_trace("animation_zoom: usurf=%08x count=%d %d%% w=%d/%d h=%d/%d anima=%d state=%d",
782                (int)usurf, animation->frame_counter, par,
783                (int)(usurf->width * scalex), usurf->width,
784                (int)(usurf->height * scaley), usurf->height,
785                usurf->animation.anima, usurf->animation.state);
786
787     if ((es->output) && (es->buffer_ref.buffer) &&
788         (es->geometry.width > 0) && (es->geometry.height > 0)) {
789         weston_surface_geometry_dirty(es);
790         weston_surface_damage(es);
791     }
792     if (par >= 100) {
793         /* end of animation     */
794         animation_end(usurf, 1);
795         uifw_trace("animation_zoom: End of animation");
796     }
797     else    {
798         /* continue animation   */
799         weston_compositor_schedule_repaint(weston_ec);
800     }
801 }
802
803 /*--------------------------------------------------------------------------*/
804 /**
805  * @brief   animation_zoom_end: zoom animation end
806  *
807  * @param[in]   animation   weston animation table
808  * @return      none
809  */
810 /*--------------------------------------------------------------------------*/
811 static void
812 animation_zoom_end(struct weston_animation *animation)
813 {
814     struct uifw_win_surface *usurf;
815     struct weston_surface   *es;
816
817     usurf = container_of(animation, struct uifw_win_surface, animation.animation);
818     if (usurf && usurf->surface)    {
819         es = usurf->surface;
820         es->alpha = 1.0;
821
822         if ((es->output) && (es->buffer_ref.buffer) &&
823             (es->geometry.width > 0) && (es->geometry.height > 0)) {
824             weston_surface_damage(es);
825         }
826     }
827 }
828
829 /*--------------------------------------------------------------------------*/
830 /**
831  * @brief   module_init: initialize ico_window_animation
832  *                       this function called from ico_pluign_loader
833  *
834  * @param[in]   es          weston compositor
835  * @param[in]   argc        number of arguments(unused)
836  * @param[in]   argv        argument list(unused)
837  * @return      result
838  * @retval      0           sccess
839  * @retval      -1          error
840  */
841 /*--------------------------------------------------------------------------*/
842 WL_EXPORT int
843 module_init(struct weston_compositor *ec, int *argc, char *argv[])
844 {
845     int     i;
846     struct animation_data   *animadata;
847
848     uifw_info("ico_window_animation: Enter(module_init)");
849
850     /* allocate animation datas     */
851     free_data = NULL;
852     for (i = 0; i < 50; i++)    {
853         animadata = (struct animation_data *)malloc(sizeof(struct animation_data));
854         if (! animadata)    {
855             uifw_error("ico_window_animation: No Memory(module_init)");
856             return -1;
857         }
858         animadata->next_free = free_data;
859         free_data = animadata;
860     }
861
862     weston_ec = ec;
863     default_animation = (char *)ico_ivi_default_animation_name();
864     animation_time = ico_ivi_default_animation_time();
865     animation_fps = ico_ivi_default_animation_fps();
866
867     ico_window_mgr_set_hook_animation(ico_window_animation);
868
869     uifw_info("ico_window_animation: Leave(module_init)");
870
871     return 0;
872 }
873