summaryrefslogtreecommitdiff
path: root/src/ico_window_animation.c
blob: 12ff474c1cd389a08ef85d1f0a911acee2feffa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
/*
 * Copyright © 2010-2011 Intel Corporation
 * Copyright © 2008-2011 Kristian Høgsberg
 * Copyright © 2013 TOYOTA MOTOR CORPORATION.
 *
 * Permission to use, copy, modify, distribute, and sell this software and
 * its documentation for any purpose is hereby granted without fee, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of the copyright holders not be used in
 * advertising or publicity pertaining to distribution of the software
 * without specific, written prior permission.  The copyright holders make
 * no representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
/**
 * @brief   Window Animation (Weston(Wayland) PlugIn)
 *
 * @date    Jul-26-2013
 */

#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <time.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>

#include <weston/compositor.h>
#include "ico_ivi_common.h"
#include "ico_ivi_shell.h"
#include "ico_window_mgr.h"

/* Animation type               */
#define ANIMA_ZOOM              1           /* ZoomIn/ZoomOut                       */
#define ANIMA_FADE              2           /* FadeIn/FadeOut                       */
#define ANIMA_SLIDE_TORIGHT     3           /* SlideIn left to right/SlideOut right to left*/
#define ANIMA_SLIDE_TOLEFT      4           /* SlideIn right to left/SlideOut left to right*/
#define ANIMA_SLIDE_TOBOTTOM    5           /* SlideIn top to bottom/SlideOut bottom to top*/
#define ANIMA_SLIDE_TOTOP       6           /* SlideIn bottom to top/SlideOut top to bottom*/

/* Visible control at end of animation  */
#define ANIMA_NOCONTROL_AT_END  0           /* no need surface show/hide at end of animation*/
#define ANIMA_SHOW_AT_END       1           /* surface show at end of animation     */
#define ANIMA_HIDE_AT_END       2           /* surface hide at end of animation     */

/* animation data               */
struct animation_data   {
    struct animation_data   *next_free;     /* free data list                       */
    char    transform_set;                  /* need transform reset at end          */
    char    res[3];                         /* (unused)                             */
    struct weston_transform transform;      /* transform matrix                     */
    void    (*end_function)(struct weston_animation *animation);
                                            /* animation end function               */
};

/* static valiables             */
static struct weston_compositor *weston_ec; /* Weston compositor                    */
static char *default_animation;             /* default animation name               */
static int  animation_fps;                  /* animation frame rate(frame/sec)      */
static int  animation_time;                 /* default animation time(ms)           */
static struct animation_data    *free_data; /* free data list                       */

/* static function              */
                                            /* slide animation                      */
static void animation_slide(struct weston_animation *animation,
                            struct weston_output *output, uint32_t msecs);
                                            /* fade animation                       */
static void animation_fade(struct weston_animation *animation,
                           struct weston_output *output, uint32_t msecs);
                                            /* fade animation end                   */
static void animation_fade_end(struct weston_animation *animation);
                                            /* zoom animation                       */
static void animation_zoom(struct weston_animation *animation,
                           struct weston_output *output, uint32_t msecs);
                                            /* zoom animation end                   */
static void animation_zoom_end(struct weston_animation *animation);
                                            /* continue animation                   */
static int animation_cont(struct weston_animation *animation,
                          struct weston_output *output, uint32_t msecs);
                                            /* terminate animation                  */
static void animation_end(struct uifw_win_surface *usurf, const int disp);

/*--------------------------------------------------------------------------*/
/**
 * @brief   ico_window_animation: Animation addin entry
 *
 * @param[in]   op      animation operation
 * @param[in]   data    data
 * @return      result
 * @retval      ICO_WINDOW_MGR_ANIMATION_RET_ANIMA      success
 * @retval      ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL success(no control)
 * @retval      ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA    error(no animation)
 */
/*--------------------------------------------------------------------------*/
static int
ico_window_animation(const int op, void *data)
{
    struct uifw_win_surface *usurf;
    struct weston_output *output;
    int         ret;
    uint32_t    nowsec;
    int         animaid;

    if (op == ICO_WINDOW_MGR_ANIMATION_NAME)    {
        /* convert animation name to animation type value   */
        if (strcasecmp((char *)data, "fade") == 0)  {
            uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_FADE);
            return ANIMA_FADE;
        }
        else if (strcasecmp((char *)data, "zoom") == 0) {
            uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_ZOOM);
            return ANIMA_ZOOM;
        }
        else if (strcasecmp((char *)data, "slide.toleft") == 0) {
            uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_SLIDE_TOLEFT);
            return ANIMA_SLIDE_TOLEFT;
        }
        else if (strcasecmp((char *)data, "slide.toright") == 0)    {
            uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_SLIDE_TORIGHT);
            return ANIMA_SLIDE_TORIGHT;
        }
        else if ((strcasecmp((char *)data, "slide.totop") == 0) ||
                 (strcasecmp((char *)data, "slide") == 0))  {
            uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_SLIDE_TOTOP);
            return ANIMA_SLIDE_TOTOP;
        }
        else if (strcasecmp((char *)data, "slide.tobottom") == 0)   {
            uifw_trace("ico_window_animation: Type %s(%d)", (char *)data, ANIMA_SLIDE_TOBOTTOM);
            return ANIMA_SLIDE_TOBOTTOM;
        }
        uifw_warn("ico_window_animation: Unknown Type %s", (char *)data);
        return ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
    }

    usurf = (struct uifw_win_surface *)data;

    if (op == ICO_WINDOW_MGR_ANIMATION_DESTROY) {
        if ((usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE) ||
            (usurf->animation.animadata != NULL)) {
            uifw_trace("ico_window_animation: Destroy %08x", (int)usurf);
            animation_end(usurf, 0);
        }
        return ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
    }

    usurf->animation.visible = ANIMA_NOCONTROL_AT_END;

    if (op == ICO_WINDOW_MGR_ANIMATION_OPCANCEL)    {
        /* cancel animation                     */
        if ((usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE) &&
            (usurf->animation.animation.frame != NULL)) {
            uifw_trace("ico_window_animation: cancel %s.%08x",
                       usurf->uclient->appid, usurf->surfaceid);
            (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 0);
        }
        animation_end(usurf, 1);
        ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
    }
    else    {
        /* setup animation              */
        if ((usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_NONE) ||
            (usurf->animation.current > 95))    {
            usurf->animation.animation.frame_counter = 1;
            usurf->animation.current = 0;
            usurf->animation.ahalf = 0;
            if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_NONE)  {
                wl_list_init(&usurf->animation.animation.link);
                output = container_of(weston_ec->output_list.next,
                                      struct weston_output, link);
                wl_list_insert(output->animation_list.prev,
                               &usurf->animation.animation.link);
            }
        }
        else if (((usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW) &&
                  ((op == ICO_WINDOW_MGR_ANIMATION_OPHIDE) ||
                   (op == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS))) ||
                 ((usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_HIDE) &&
                  ((op == ICO_WINDOW_MGR_ANIMATION_OPSHOW) ||
                   (op == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS))))   {
            /* change ...In(ex.FadeIn) to ...Out(FadeOut) or ...Out to ...In    */
            nowsec = weston_compositor_get_time();
            usurf->animation.current = 100 - usurf->animation.current;
            if ((op == ICO_WINDOW_MGR_ANIMATION_OPHIDE)||
                (op == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS)) {
                usurf->animation.time = usurf->animation.hide_time;
            }
            else    {
                usurf->animation.time = usurf->animation.show_time;
            }
            if (usurf->animation.time == 0) {
                usurf->animation.time = animation_time;
            }
            ret = ((usurf->animation.current) * usurf->animation.time) / 100;
            if (nowsec >= (uint32_t)ret)    {
                usurf->animation.starttime = nowsec - ret;
            }
            else    {
                usurf->animation.starttime = ((long long)nowsec) + ((long long)0x100000000L)
                                             - ((long long)ret);
            }
            usurf->animation.animation.frame_counter = 2;
        }

        /* set animation function       */
        if ((op == ICO_WINDOW_MGR_ANIMATION_OPSHOW) ||
            (op == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS)) {
            usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_SHOW;
            animaid = usurf->animation.show_anima;
            usurf->animation.anima = animaid;
            uifw_trace("ico_window_animation: show(in) %s.%08x anima=%d",
                       usurf->uclient->appid, usurf->surfaceid, animaid);
            ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
        }
        else if ((op == ICO_WINDOW_MGR_ANIMATION_OPHIDE) ||
                 (op == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS))    {
            usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_HIDE;
            animaid = usurf->animation.hide_anima;
            usurf->animation.anima = animaid;
            uifw_trace("ico_window_animation: hide(out) %s.%08x anima=%d",
                       usurf->uclient->appid, usurf->surfaceid, animaid);
            ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL;
            usurf->animation.visible = ANIMA_HIDE_AT_END;
        }
        else if (op == ICO_WINDOW_MGR_ANIMATION_OPMOVE)    {
            usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_MOVE;
            animaid = usurf->animation.move_anima;
            usurf->animation.anima = animaid;
            uifw_trace("ico_window_animation: move %s.%08x anima=%d",
                       usurf->uclient->appid, usurf->surfaceid, animaid);
            ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL;
        }
        else if (op == ICO_WINDOW_MGR_ANIMATION_OPRESIZE)    {
            usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_RESIZE;
            animaid = usurf->animation.resize_anima;
            usurf->animation.anima = animaid;
            uifw_trace("ico_window_animation: resize %s.%08x anima=%d",
                       usurf->uclient->appid, usurf->surfaceid, animaid);
            ret = ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL;
        }
        else    {
            uifw_trace("ico_window_animation: Op=%d unknown", op);
            return ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
        }
        if ((animaid == ANIMA_SLIDE_TOLEFT) || (animaid == ANIMA_SLIDE_TORIGHT) ||
            (animaid == ANIMA_SLIDE_TOTOP) || (animaid == ANIMA_SLIDE_TOBOTTOM))  {
            usurf->animation.animation.frame = animation_slide;
            usurf->restrain_configure = 1;
            (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 1);
        }
        else if (animaid == ANIMA_FADE)   {
            usurf->animation.animation.frame = animation_fade;
            usurf->restrain_configure = 1;
            (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 1);
        }
        else if (animaid == ANIMA_ZOOM)   {
            usurf->animation.animation.frame = animation_zoom;
            usurf->restrain_configure = 1;
            (*usurf->animation.animation.frame)(&usurf->animation.animation, NULL, 1);
        }
        else    {
            /* no yet support   */
            usurf->animation.animation.frame = NULL;
            usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_NONE;
            usurf->restrain_configure = 0;
            usurf->animation.anima = 0;
            wl_list_remove(&usurf->animation.animation.link);
            ret = ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
        }
        usurf->animation.type = op;
    }
    weston_compositor_schedule_repaint(weston_ec);
    return ret;
}

/*--------------------------------------------------------------------------*/
/**
 * @brief   animation_cont: continue animation
 *
 * @param[in]   animation   weston animation table
 * @param[in]   output      weston output table
 * @param[in]   msecs       current time stamp
 * @return      time has come
 * @retval      =0          time has come
 * @retval      >0          time has not yet come(return value is current parcent)
 */
/*--------------------------------------------------------------------------*/
static int
animation_cont(struct weston_animation *animation, struct weston_output *output,
               uint32_t msecs)
{
    struct uifw_win_surface *usurf;
    int         par;
    uint32_t    nowsec;

    nowsec = weston_compositor_get_time();

    usurf = container_of(animation, struct uifw_win_surface, animation.animation);

    if (animation->frame_counter <= 1)  {
        /* first call, initialize           */
        animation->frame_counter = 1;
        usurf->animation.starttime = nowsec;
        usurf->animation.current = 1000;
        if (! usurf->animation.animadata) {
            if (free_data)  {
                usurf->animation.animadata = (void *)free_data;
                free_data = free_data->next_free;
            }
            else    {
                usurf->animation.animadata = (void *)malloc(sizeof(struct animation_data));
            }
            memset(usurf->animation.animadata, 0, sizeof(struct animation_data));
        }
    }
    else if (! usurf->animation.animadata)    {
        animation_end(usurf, 0);
        return 999;
    }

    if (nowsec >= usurf->animation.starttime)   {
        nowsec = nowsec - usurf->animation.starttime;   /* elapsed time(ms) */
    }
    else    {
        nowsec = (uint32_t)(((long long)0x100000000L) +
                            ((long long)nowsec) - ((long long)usurf->animation.starttime));
    }
    switch (usurf->animation.state) {
    case ICO_WINDOW_MGR_ANIMATION_STATE_SHOW:
        usurf->animation.time = usurf->animation.show_time;
        break;
    case ICO_WINDOW_MGR_ANIMATION_STATE_HIDE:
        usurf->animation.time = usurf->animation.hide_time;
        break;
    case ICO_WINDOW_MGR_ANIMATION_STATE_MOVE:
        usurf->animation.time = usurf->animation.move_time;
        break;
    default:
        usurf->animation.time = usurf->animation.resize_time;
        break;
    }
    if (usurf->animation.time == 0) {
        usurf->animation.time = animation_time;
    }
    if (((output == NULL) && (msecs == 0)) || (nowsec >= ((uint32_t)usurf->animation.time))) {
        par = 100;
    }
    else    {
        par = (nowsec * 100 + usurf->animation.time / 2) / usurf->animation.time;
        if (par < 2)    par = 2;
    }
    if ((par >= 100) ||
        (abs(usurf->animation.current - par) >=
         (((1000 * 100) / animation_fps) / usurf->animation.time))) {
        usurf->animation.current = par;
        return 0;
    }
    return par;
}

/*--------------------------------------------------------------------------*/
/**
 * @brief   animation_end: terminate animation
 *
 * @param[in]   usurf       UIFW surface table
 * @param[in]   disp        display control(1)/no display(0)
 * @return      none
 */
/*--------------------------------------------------------------------------*/
static void
animation_end(struct uifw_win_surface *usurf, const int disp)
{
    struct animation_data   *animadata;

    usurf->animation.state = ICO_WINDOW_MGR_ANIMATION_STATE_NONE;
    animadata = (struct animation_data *)usurf->animation.animadata;

    if (animadata)  {
        if (animadata->end_function)    {
            (*animadata->end_function)(&usurf->animation.animation);
        }
        wl_list_remove(&usurf->animation.animation.link);
        if (animadata->transform_set)   {
            wl_list_remove(&animadata->transform.link);
            animadata->transform_set = 0;
        }
        weston_surface_geometry_dirty(usurf->surface);
    }
    if (disp)   {
        if ((usurf->animation.visible == ANIMA_HIDE_AT_END) &&
            (usurf->visible != 0))  {
            ico_window_mgr_set_visible(usurf, 0);
            weston_surface_damage(usurf->surface);
        }
        if ((usurf->animation.visible == ANIMA_SHOW_AT_END) &&
            (usurf->visible == 0))  {
            ico_window_mgr_set_visible(usurf, 1);
            weston_surface_damage(usurf->surface);
        }
        usurf->restrain_configure = 0;
        weston_surface_geometry_dirty(usurf->surface);
        weston_compositor_schedule_repaint(weston_ec);
    }
    usurf->animation.visible = ANIMA_NOCONTROL_AT_END;
    if (usurf->animation.next_anima != ICO_WINDOW_MGR_ANIMATION_NONE)    {
        switch(usurf->animation.type)   {
        case ICO_WINDOW_MGR_ANIMATION_OPHIDE:
        case ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS:
            usurf->animation.hide_anima = usurf->animation.next_anima;
            break;
        case ICO_WINDOW_MGR_ANIMATION_OPSHOW:
        case ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS:
            usurf->animation.show_anima = usurf->animation.next_anima;
            break;
        case ICO_WINDOW_MGR_ANIMATION_OPMOVE:
            usurf->animation.move_anima = usurf->animation.next_anima;
            break;
        case ICO_WINDOW_MGR_ANIMATION_OPRESIZE:
            usurf->animation.resize_anima = usurf->animation.next_anima;
            break;
        default:
            break;
        }
        usurf->animation.next_anima = ICO_WINDOW_MGR_ANIMATION_NONE;
    }
    if (animadata)   {
        usurf->animation.animadata = NULL;
        animadata->next_free = free_data;
        free_data = animadata;
    }
    usurf->animation.type = ICO_WINDOW_MGR_ANIMATION_OPNONE;
}

/*--------------------------------------------------------------------------*/
/**
 * @brief   animation_slide: slide animation
 *
 * @param[in]   animation   weston animation table
 * @param[in]   outout      weston output table
 * @param[in]   mseces      current time(unused)
 * @return      none
 */
/*--------------------------------------------------------------------------*/
static void
animation_slide(struct weston_animation *animation,
                struct weston_output *output, uint32_t msecs)
{
    struct uifw_win_surface *usurf;
    struct weston_surface   *es;
    int         dwidth, dheight;
    int         par;
    int         x;
    int         y;

    usurf = container_of(animation, struct uifw_win_surface, animation.animation);

    par = animation_cont(animation, output, msecs);
    if (par > 0)    {
        /* continue animation   */
        if( par <= 100) {
            weston_compositor_schedule_repaint(weston_ec);
        }
        return;
    }
    par = usurf->animation.current;

    uifw_trace("animation_slide: usurf=%08x count=%d %d%% anima=%d state=%d",
               (int)usurf, animation->frame_counter, par,
               usurf->animation.anima, usurf->animation.state);

    es = usurf->surface;
    x = usurf->x;
    y = usurf->y;

    switch (usurf->animation.anima)  {
    case ANIMA_SLIDE_TORIGHT:           /* slide in left to right           */
        if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
            /* slide in left to right   */
            x = 0 - usurf->animation.pos_width +
                ((usurf->animation.pos_x + usurf->animation.pos_width) * par / 100);
        }
        else    {
            /* slide out right to left  */
            x = 0 - usurf->animation.pos_width +
                ((usurf->animation.pos_x + usurf->animation.pos_width) * (100 - par) / 100);
        }
        break;
    case ANIMA_SLIDE_TOLEFT:            /* slide in right to left           */
        dwidth = (container_of(weston_ec->output_list.next,
                               struct weston_output, link))->width;
        if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
            /* slide in right to left   */
            x = usurf->animation.pos_x +
                (dwidth - usurf->animation.pos_x) * (100 - par) / 100;
        }
        else    {
            /* slide out left to right  */
            x = usurf->animation.pos_x + (dwidth - usurf->animation.pos_x) * par / 100;
        }
        break;
    case ANIMA_SLIDE_TOBOTTOM:          /* slide in top to bottom           */
        if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
            /* slide in top to bottom   */
            y = 0 - usurf->animation.pos_height +
                ((usurf->animation.pos_y + usurf->animation.pos_height) * par / 100);
        }
        else    {
            /* slide out bottom to top  */
            y = 0 - usurf->animation.pos_height +
                ((usurf->animation.pos_y + usurf->animation.pos_height) * (100 - par) / 100);
        }
        break;
    default: /*ANIMA_SLIDE_TOTOP*/      /* slide in bottom to top           */
        dheight = (container_of(weston_ec->output_list.next,
                                struct weston_output, link))->height;
        if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
            /* slide in bottom to top   */
            y = usurf->animation.pos_y +
                (dheight - usurf->animation.pos_y) * (100 - par) / 100;
        }
        else    {
            /* slide out top to bottom  */
            y = usurf->animation.pos_y + (dheight - usurf->animation.pos_y) * par / 100;
        }
        break;
    }

    es->geometry.x = usurf->node_tbl->disp_x + x;
    es->geometry.y = usurf->node_tbl->disp_y + y;
    if ((es->output) && (es->buffer_ref.buffer) &&
        (es->geometry.width > 0) && (es->geometry.height > 0)) {
        weston_surface_geometry_dirty(es);
        weston_surface_damage(es);
    }
    if (par >= 100) {
        /* end of animation     */
        animation_end(usurf, 1);
        uifw_trace("animation_slide: End of animation");
    }
    else    {
        /* continue animation   */
        weston_compositor_schedule_repaint(weston_ec);
    }
}

/*--------------------------------------------------------------------------*/
/**
 * @brief   animation_fade: fade animation
 *
 * @param[in]   animation   weston animation table
 * @param[in]   outout      weston output table
 * @param[in]   mseces      current time(unused)
 * @return      none
 */
/*--------------------------------------------------------------------------*/
static void
animation_fade(struct weston_animation *animation,
               struct weston_output *output, uint32_t msecs)
{
    struct uifw_win_surface *usurf;
    struct animation_data   *animadata;
    struct weston_surface   *es;
    int         par;

    usurf = container_of(animation, struct uifw_win_surface, animation.animation);

    par = animation_cont(animation, output, msecs);
    if (par > 0)    {
        /* continue animation   */
        if( par <= 100) {
            weston_compositor_schedule_repaint(weston_ec);
        }
        return;
    }

    animadata = (struct animation_data *)usurf->animation.animadata;
    es = usurf->surface;
    par = usurf->animation.current;
    if (animation->frame_counter == 1)  {
        if (animadata->transform_set == 0)  {
            animadata->transform_set = 1;
            weston_matrix_init(&animadata->transform.matrix);
            wl_list_init(&animadata->transform.link);
            wl_list_insert(&es->geometry.transformation_list,
                           &animadata->transform.link);
        }
        animadata->end_function = animation_fade_end;

        if ((usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS) ||
            (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS))  {
            ico_window_mgr_set_weston_surface(usurf,
                                              usurf->animation.pos_x, usurf->animation.pos_y,
                                              usurf->animation.pos_width,
                                              usurf->animation.pos_height);
        }
    }

    if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
        /* fade in                  */
        es->alpha = ((float)par) / 100.0f;
    }
    else if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_HIDE)    {
        /* fade out                 */
        es->alpha = 1.0f - (((float)par) / 100.0f);
    }
    else    {
        /* fade move/resize         */
        if ((par >= 50) || (usurf->animation.ahalf))    {
            es->alpha = ((float)(par*2 - 100)) / 100.0f;
            if (usurf->animation.ahalf == 0)    {
                uifw_trace("animation_fade: fade move chaneg to show");
                usurf->animation.ahalf = 1;
                es->alpha = 0.0;
                ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
                                                  usurf->width, usurf->height);
                ico_window_mgr_change_surface(usurf,
                                              usurf->animation.no_configure ? -1 : 0, 1);
            }
        }
        else    {
            es->alpha = 1.0f - (((float)(par*2)) / 100.0f);
        }
    }
    if (es->alpha < 0.0)        es->alpha = 0.0;
    else if (es->alpha > 1.0)   es->alpha = 1.0;

    uifw_trace("animation_fade: usurf=%08x count=%d %d%% alpha=%1.2f anima=%d state=%d",
               (int)usurf, animation->frame_counter, par, es->alpha,
               usurf->animation.anima, usurf->animation.state);

    if ((es->output) && (es->buffer_ref.buffer) &&
        (es->geometry.width > 0) && (es->geometry.height > 0)) {
        weston_surface_damage(es);
    }
    if (par >= 100) {
        /* end of animation     */
        animation_end(usurf, 1);
        uifw_trace("animation_fade: End of animation");
    }
    else    {
        /* continue animation   */
        weston_compositor_schedule_repaint(weston_ec);
    }
}

/*--------------------------------------------------------------------------*/
/**
 * @brief   animation_fade_end: fade animation end
 *
 * @param[in]   animation   weston animation table
 * @return      none
 */
/*--------------------------------------------------------------------------*/
static void
animation_fade_end(struct weston_animation *animation)
{
    struct uifw_win_surface *usurf;
    struct weston_surface   *es;

    usurf = container_of(animation, struct uifw_win_surface, animation.animation);
    if (usurf && usurf->surface)    {
        es = usurf->surface;
        es->alpha = 1.0;

        if ((es->output) && (es->buffer_ref.buffer) &&
            (es->geometry.width > 0) && (es->geometry.height > 0)) {
            weston_surface_damage(es);
        }
    }
}

/*--------------------------------------------------------------------------*/
/**
 * @brief   animation_zoom: zoom animation
 *
 * @param[in]   animation   weston animation table
 * @param[in]   outout      weston output table
 * @param[in]   mseces      current time(unused)
 * @return      none
 */
/*--------------------------------------------------------------------------*/
static void
animation_zoom(struct weston_animation *animation,
               struct weston_output *output, uint32_t msecs)
{
    struct uifw_win_surface *usurf;
    struct animation_data   *animadata;
    struct weston_surface   *es;
    int         par;
    float       scalex, scaley;
    float       fu, fa, fp;
    int         x, y;

    usurf = container_of(animation, struct uifw_win_surface, animation.animation);

    par = animation_cont(animation, output, msecs);
    if (par > 0)    {
        /* continue animation   */
        if( par <= 100) {
            weston_compositor_schedule_repaint(weston_ec);
        }
        return;
    }

    animadata = (struct animation_data *)usurf->animation.animadata;
    es = usurf->surface;
    par = usurf->animation.current;
    if (animation->frame_counter == 1)  {
        if (animadata->transform_set == 0)  {
            animadata->transform_set = 1;
            weston_matrix_init(&animadata->transform.matrix);
            wl_list_init(&animadata->transform.link);
            wl_list_insert(&es->geometry.transformation_list,
                           &animadata->transform.link);
        }
        animadata->end_function = animation_zoom_end;

        if ((usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS) ||
            (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS))  {
            ico_window_mgr_set_weston_surface(usurf,
                                              usurf->animation.pos_x, usurf->animation.pos_y,
                                              usurf->animation.pos_width,
                                              usurf->animation.pos_height);
        }
    }

    if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_SHOW)    {
        /* zoom in                  */
        scalex = ((float)par + 5.0f) / 105.0f;
        scaley = scalex;
    }
    else if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_HIDE)    {
        /* zoom out                 */
        scalex = 1.0f - (((float)par + 5.0f) / 105.0f);
        scaley = scalex;
    }
    else    {
        /* zoom move/resize         */
        ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
                                          usurf->width, usurf->height);
        ico_window_mgr_change_surface(usurf, usurf->animation.no_configure ? -1 : 0, 1);

        fu = (float)usurf->width;
        fa = (float)usurf->animation.pos_width;
        fp = (100.0f - (float)par) / 100.0f;
        scalex = (fu - (fu - fa) * fp) / fu;
        fu = (float)usurf->height;
        fa = (float)usurf->animation.pos_height;
        scaley = (fu - (fu - fa) * fp) / fu;

        x = (((float)usurf->animation.pos_x) - ((float)usurf->x)) * fp + (float)usurf->x
            + (((float)usurf->width * scalex) - (float)usurf->width) / 2.0f;
        y = (((float)usurf->animation.pos_y) - ((float)usurf->y)) * fp + (float)usurf->y
            + (((float)usurf->height * scaley) - (float) usurf->height) / 2.0f;
        uifw_trace("animation_zoom: usurf=%08x %d%% x=%d/%d y=%d/%d",
                   (int)usurf, par, x, usurf->x, y, usurf->y);
        uifw_trace("animation_zoom: sx=%4.2f sy=%4.2f x=%d->%d y=%d->%d cur=%d,%d",
                   scalex, scaley, usurf->animation.pos_x, usurf->x,
                   usurf->animation.pos_y, usurf->y, x, y);
        ico_window_mgr_set_weston_surface(usurf, x, y, usurf->width, usurf->height);
    }
    weston_matrix_init(&animadata->transform.matrix);
    weston_matrix_translate(&animadata->transform.matrix,
                            -0.5f * usurf->width, -0.5f * usurf->height, 0);
    weston_matrix_scale(&animadata->transform.matrix, scalex, scaley, 1.0f);
    weston_matrix_translate(&animadata->transform.matrix,
                            0.5f * usurf->width, 0.5f * usurf->height, 0);
    
    uifw_trace("animation_zoom: usurf=%08x count=%d %d%% w=%d/%d h=%d/%d anima=%d state=%d",
               (int)usurf, animation->frame_counter, par,
               (int)(usurf->width * scalex), usurf->width,
               (int)(usurf->height * scaley), usurf->height,
               usurf->animation.anima, usurf->animation.state);

    if ((es->output) && (es->buffer_ref.buffer) &&
        (es->geometry.width > 0) && (es->geometry.height > 0)) {
        weston_surface_geometry_dirty(es);
        weston_surface_damage(es);
    }
    if (par >= 100) {
        /* end of animation     */
        animation_end(usurf, 1);
        uifw_trace("animation_zoom: End of animation");
    }
    else    {
        /* continue animation   */
        weston_compositor_schedule_repaint(weston_ec);
    }
}

/*--------------------------------------------------------------------------*/
/**
 * @brief   animation_zoom_end: zoom animation end
 *
 * @param[in]   animation   weston animation table
 * @return      none
 */
/*--------------------------------------------------------------------------*/
static void
animation_zoom_end(struct weston_animation *animation)
{
    struct uifw_win_surface *usurf;
    struct weston_surface   *es;

    usurf = container_of(animation, struct uifw_win_surface, animation.animation);
    if (usurf && usurf->surface)    {
        es = usurf->surface;
        es->alpha = 1.0;

        if ((es->output) && (es->buffer_ref.buffer) &&
            (es->geometry.width > 0) && (es->geometry.height > 0)) {
            weston_surface_damage(es);
        }
    }
}

/*--------------------------------------------------------------------------*/
/**
 * @brief   module_init: initialize ico_window_animation
 *                       this function called from ico_pluign_loader
 *
 * @param[in]   es          weston compositor
 * @param[in]   argc        number of arguments(unused)
 * @param[in]   argv        argument list(unused)
 * @return      result
 * @retval      0           sccess
 * @retval      -1          error
 */
/*--------------------------------------------------------------------------*/
WL_EXPORT int
module_init(struct weston_compositor *ec, int *argc, char *argv[])
{
    int     i;
    struct animation_data   *animadata;

    uifw_info("ico_window_animation: Enter(module_init)");

    /* allocate animation datas     */
    free_data = NULL;
    for (i = 0; i < 50; i++)    {
        animadata = (struct animation_data *)malloc(sizeof(struct animation_data));
        if (! animadata)    {
            uifw_error("ico_window_animation: No Memory(module_init)");
            return -1;
        }
        animadata->next_free = free_data;
        free_data = animadata;
    }

    weston_ec = ec;
    default_animation = (char *)ico_ivi_default_animation_name();
    animation_time = ico_ivi_default_animation_time();
    animation_fps = ico_ivi_default_animation_fps();

    ico_window_mgr_set_hook_animation(ico_window_animation);

    uifw_info("ico_window_animation: Leave(module_init)");

    return 0;
}