It follows in footsteps of change of weston-ivi-shell 0.1.3.
[profile/ivi/ico-uxf-weston-plugin.git] / src / ico_window_mgr.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   Multi Window Manager (Weston(Wayland) PlugIn)
26  *
27  * @date    Feb-21-2014
28  */
29
30 #define _GNU_SOURCE
31
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <stdbool.h>
35 #include <string.h>
36 #include <unistd.h>
37 #include <linux/input.h>
38 #include <assert.h>
39 #include <signal.h>
40 #include <math.h>
41 #include <time.h>
42 #include <sys/mman.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <fcntl.h>
46 #include <errno.h>
47 #include <limits.h>
48 #include <pixman.h>
49 #include <wayland-server.h>
50 #include <wayland-server.h>
51 #include <dirent.h>
52 #include <aul/aul.h>
53 #include <bundle.h>
54
55 #include <EGL/egl.h>
56 #include <GLES2/gl2.h>
57
58 #include <weston/compositor.h>
59 #include <weston/weston-layout.h>
60
61 /* detail debug log */
62 #define UIFW_DETAIL_OUT 1                   /* 1=detail debug log/0=no detail log   */
63
64 #include <weston/weston-layout.h>
65 #include <weston/ivi-shell-ext.h>
66 #include "ico_ivi_common_private.h"
67 #include "ico_window_mgr_private.h"
68 #include "ico_window_mgr-server-protocol.h"
69
70 /* gl_surface_state (inport from weston-1.4.0/src/gl-renderer.c */
71 enum buffer_type {
72     BUFFER_TYPE_NULL,
73     BUFFER_TYPE_SHM,
74     BUFFER_TYPE_EGL
75 };
76 struct uifw_gl_surface_state {      /* struct gl_surface_state  */
77     GLfloat color[4];
78     struct gl_shader *shader;
79
80     GLuint textures[3];
81     int num_textures;
82     int needs_full_upload;
83     pixman_region32_t texture_damage;
84
85     void *images[3];            /* EGLImageKHR */
86     GLenum target;
87     int num_images;
88
89     struct weston_buffer_reference buffer_ref;
90     enum buffer_type buffer_type;
91     int pitch; /* in pixels */
92     int height; /* in pixels */
93     int y_inverted;         /* add weston 1.3.x */
94 };
95
96 /* SurfaceID                            */
97 #define UIFW_HASH           64              /* Hash value (2's compliment)          */
98 #define SURCAFE_ID_MASK     0x0ffff         /* SurfaceId hash mask pattern          */
99
100 /* Internal fixed value                 */
101 #define ICO_WINDOW_MGR_APPID_FIXCOUNT   5   /* retry count of appid fix             */
102                                             /* show/hide animation with position    */
103 #define ICO_WINDOW_MGR_ANIMATION_POS    0x10000000
104
105 /* Multi Windiw Manager                 */
106 struct ico_win_mgr {
107     struct weston_compositor *compositor;   /* Weston compositor                    */
108     void    *shell;                         /* shell table address                  */
109     int32_t surface_head;                   /* (HostID << 24) | (DisplayNo << 16)   */
110
111     struct wl_list  client_list;            /* Clients                              */
112     struct wl_list  manager_list;           /* Manager(ex.HomeScreen) list          */
113
114     struct wl_list  map_list;               /* surface map list                     */
115     struct uifw_surface_map *free_maptable; /* free maped surface table list        */
116     struct weston_animation map_animation[ICO_IVI_MAX_DISPLAY];
117                                             /* animation for map check              */
118     struct wl_event_source  *wait_mapevent; /* map event send wait timer            */
119
120     char    *pixel_readbuf;                 /* surface pixel image read buffer      */
121     int     pixel_readsize;                 /* surface pixel image read buffer size */
122     struct uifw_win_surface *idhash[UIFW_HASH];  /* UIFW SerfaceID                  */
123     struct uifw_win_surface *wshash[UIFW_HASH];  /* Weston Surface                  */
124
125     char    shell_init;                     /* shell initialize flag                */
126     char    res[3];                         /* (unused)                             */
127 };
128
129 /* Internal macros                      */
130 /* UIFW SurfaceID                       */
131 #define MAKE_IDHASH(v)  (((uint32_t)v) & (UIFW_HASH-1))
132 /* Weston Surface                       */
133 #define MAKE_WSHASH(v)  ((((uint32_t)v) >> 5) & (UIFW_HASH-1))
134
135 /* function prototype                   */
136                                             /* get surface table from weston surface*/
137 static struct uifw_win_surface *find_uifw_win_surface_by_ws(
138                     struct weston_surface *wsurf);
139                                             /* bind shell client                    */
140 static void win_mgr_bind_client(struct wl_client *client, void *shell);
141                                             /* destroy client                       */
142 static void win_mgr_destroy_client(struct wl_listener *listener, void *data);
143 #if 0       /* work around: Walk through child processes until app ID is found  */
144                                             /* get parent pid                       */
145 static pid_t win_mgr_get_ppid(pid_t pid);
146 #endif      /* work around: Walk through child processes until app ID is found  */
147                                             /* get appid from pid                   */
148 static void win_mgr_get_client_appid(struct uifw_client *uclient);
149                                             /* create new surface                   */
150 static void win_mgr_register_surface(uint32_t id_surface, struct weston_surface *surface,
151                                      struct wl_client *client,
152                                      struct weston_layout_surface *ivisurf);
153                                             /* surface destroy                      */
154 static void win_mgr_destroy_surface(struct weston_surface *surface);
155                                             /* weston_surface destroy listener      */
156 static void win_mgr_surface_destroy(struct wl_listener *listener, void *data);
157                                             /* read surface pixel                   */
158 static int win_mgr_takeSurfaceScreenshot(const char *filename,
159                                          struct uifw_win_surface *usurf,
160                                          int width, int height);
161                                             /* set surface animation                */
162 static void uifw_set_animation(struct wl_client *client, struct wl_resource *resource,
163                                uint32_t surfaceid, int32_t type,
164                                const char *animation, int32_t time);
165                                             /* check and change all mapped surface  */
166 static void win_mgr_check_mapsurface(struct weston_animation *animation,
167                                      struct weston_output *output, uint32_t msecs);
168                                             /* check timer of mapped surface        */
169 static int win_mgr_timer_mapsurface(void *data);
170                                             /* check and change mapped surface      */
171 static void win_mgr_change_mapsurface(struct uifw_surface_map *sm, int event,
172                                       uint32_t curtime);
173                                             /* map surface to system application    */
174 static void uifw_map_surface(struct wl_client *client, struct wl_resource *resource,
175                              uint32_t surfaceid, int32_t framerate, const char *filepath);
176                                             /* unmap surface                        */
177 static void uifw_unmap_surface(struct wl_client *client, struct wl_resource *resource,
178                                uint32_t surfaceid);
179                                             /* direct layout surface                */
180 static void uifw_layout_surface(struct wl_client *client, struct wl_resource *resource,
181                                 uint32_t surfaceid, uint32_t layerid, int x, int y,
182                                 int width, int height, int visible);
183                                             /* bind manager                         */
184 static void bind_ico_win_mgr(struct wl_client *client,
185                              void *data, uint32_t version, uint32_t id);
186                                             /* unbind manager                       */
187 static void unbind_ico_win_mgr(struct wl_resource *resource);
188                                             /* convert animation name to Id value   */
189 static int ico_get_animation_name(const char *animation);
190                                             /* send event to controller             */
191 static void win_mgr_send_event(int event, uint32_t surfaceid, uint32_t arg1);
192                                             /* touch/click select surface           */
193 static void win_mgr_select_surface(struct weston_seat *seat,
194                                    struct weston_surface *focus, int target);
195 static void win_mgr_click_to_activate(struct weston_seat *seat, uint32_t time,
196                                       uint32_t button, void *data);
197 static void win_mgr_touch_to_activate(struct weston_seat *seat, uint32_t time,
198                                       void *data);
199                                             /* hook for create surface of ivi-shell */
200 static void ico_ivi_surfaceCreateNotification(struct weston_layout_surface *ivisurf,
201                                               void *userdata);
202                                             /* hook for remove surface of ivi-shell */
203 static void ico_ivi_surfaceRemoveNotification(struct weston_layout_surface *ivisurf,
204                                               void *userdata);
205                                             /* hook for property change of ivi-shell*/
206 static void ico_ivi_surfacePropertyNotification(struct weston_layout_surface *ivisurf,
207                                                 struct weston_layout_SurfaceProperties *prop,
208                                                 enum weston_layout_notification_mask mask,
209                                                 void *userdata);
210                                             /* hook for animation                   */
211 static int  (*win_mgr_hook_animation)(const int op, void *data) = NULL;
212                                             /* hook for input region                */
213 static void (*win_mgr_hook_change)(struct uifw_win_surface *usurf) = NULL;
214 static void (*win_mgr_hook_destory)(struct uifw_win_surface *usurf) = NULL;
215 static void (*win_mgr_hook_inputregion)(int set, struct uifw_win_surface *usurf,
216                                         int32_t x, int32_t y, int32_t width,
217                                         int32_t height, int32_t hotspot_x, int32_t hotspot_y,
218                                         int32_t cursor_x, int32_t cursor_y,
219                                         int32_t cursor_width, int32_t cursor_height,
220                                         uint32_t attr) = NULL;
221
222 /* static tables                        */
223 /* Multi Window Manager interface       */
224 static const struct ico_window_mgr_interface ico_window_mgr_implementation = {
225     uifw_set_animation,
226     uifw_map_surface,
227     uifw_unmap_surface,
228     uifw_layout_surface
229 };
230
231
232 /* plugin common value(without ico_plugin_loader)   */
233 static int  _ico_ivi_option_flag = 0;           /* option flags                     */
234 static int  _ico_ivi_debug_level = 3;           /* debug Level                      */
235 static char *_ico_ivi_animation_name = NULL;    /* default animation name           */
236 static int  _ico_ivi_animation_time = 500;      /* default animation time           */
237
238 /* static management table              */
239 static struct ico_win_mgr       *_ico_win_mgr = NULL;
240 static int                      _ico_num_nodes = 0;
241 static struct uifw_node_table   _ico_node_table[ICO_IVI_MAX_DISPLAY];
242 static struct weston_seat       *touch_check_seat = NULL;
243
244
245 /*--------------------------------------------------------------------------*/
246 /**
247  * @brief   ico_ivi_optionflag: get option flags
248  *
249  * @param       None
250  * @return      option flags
251  */
252 /*--------------------------------------------------------------------------*/
253 WL_EXPORT   int
254 ico_ivi_optionflag(void)
255 {
256     return _ico_ivi_option_flag;
257 }
258
259 /*--------------------------------------------------------------------------*/
260 /**
261  * @brief   ico_ivi_debuglevel: answer debug output level.
262  *
263  * @param       none
264  * @return      debug output level
265  * @retval      0       No debug output
266  * @retval      1       Only error output
267  * @retval      2       Error and Warning output
268  * @retval      3       Error, Warning and information output
269  * @retval      4       Error, Warning, information and Debug Trace output
270  * @retval      5       All output with debug write
271  */
272 /*--------------------------------------------------------------------------*/
273 WL_EXPORT   int
274 ico_ivi_debuglevel(void)
275 {
276     return (_ico_ivi_debug_level & 0x0ffff);
277 }
278
279 /*--------------------------------------------------------------------------*/
280 /**
281  * @brief   ico_ivi_debugflag: get debug flags
282  *
283  * @param       None
284  * @return      debug flags
285  */
286 /*--------------------------------------------------------------------------*/
287 WL_EXPORT   int
288 ico_ivi_debugflag(void)
289 {
290     return ((_ico_ivi_debug_level >> 16) & 0x0ffff);
291 }
292
293 /*--------------------------------------------------------------------------*/
294 /**
295  * @brief   ico_ivi_default_animation_name: get default animation name
296  *
297  * @param       None
298  * @return      Default animation name
299  */
300 /*--------------------------------------------------------------------------*/
301 WL_EXPORT   const char *
302 ico_ivi_default_animation_name(void)
303 {
304     return _ico_ivi_animation_name;
305 }
306
307 /*--------------------------------------------------------------------------*/
308 /**
309  * @brief   ico_ivi_default_animation_time: get default animation time
310  *
311  * @param       None
312  * @return      Default animation time(miri sec)
313  */
314 /*--------------------------------------------------------------------------*/
315 WL_EXPORT   int
316 ico_ivi_default_animation_time(void)
317 {
318     return _ico_ivi_animation_time;
319 }
320
321 /*--------------------------------------------------------------------------*/
322 /**
323  * @brief   ico_ivi_get_mynode: Get my NodeId
324  *
325  * @param       None
326  * @return      NodeId of my node
327  */
328 /*--------------------------------------------------------------------------*/
329 WL_EXPORT   int
330 ico_ivi_get_mynode(void)
331 {
332     /* Reference Platform 0.90 only support 1 ECU   */
333     return 0;
334 }
335
336 /*--------------------------------------------------------------------------*/
337 /**
338  * @brief   ico_ivi_surface_buffer_width: get surface buffer width
339  *
340  * @param[in]   es          weston surface
341  * @return      buffer width(if surface has no buffer, return 0)
342  */
343 /*--------------------------------------------------------------------------*/
344 WL_EXPORT   int
345 ico_ivi_surface_buffer_width(struct weston_surface *es)
346 {
347     int v;
348
349     if (! es->buffer_ref.buffer)    {
350         return 0;
351     }
352     if (es->buffer_viewport.viewport_set)   {
353         return es->buffer_viewport.dst_width;
354     }
355     switch (es->buffer_viewport.transform) {
356     case WL_OUTPUT_TRANSFORM_90:
357     case WL_OUTPUT_TRANSFORM_270:
358     case WL_OUTPUT_TRANSFORM_FLIPPED_90:
359     case WL_OUTPUT_TRANSFORM_FLIPPED_270:
360         v = es->buffer_ref.buffer->height;
361         break;
362     default:
363         v = es->buffer_ref.buffer->width;
364         break;
365     }
366     return (v / es->buffer_viewport.scale);
367 }
368
369 /*--------------------------------------------------------------------------*/
370 /**
371  * @brief   ico_ivi_surface_buffer_height: get surface buffer height
372  *
373  * @param[in]   es          weston surface
374  * @return      buffer height(if surface has no buffer, return 0)
375  */
376 /*--------------------------------------------------------------------------*/
377 WL_EXPORT   int
378 ico_ivi_surface_buffer_height(struct weston_surface *es)
379 {
380     int v;
381
382     if (! es->buffer_ref.buffer)    {
383         return 0;
384     }
385     if (es->buffer_viewport.viewport_set)   {
386         return es->buffer_viewport.dst_height;
387     }
388     switch (es->buffer_viewport.transform) {
389     case WL_OUTPUT_TRANSFORM_90:
390     case WL_OUTPUT_TRANSFORM_270:
391     case WL_OUTPUT_TRANSFORM_FLIPPED_90:
392     case WL_OUTPUT_TRANSFORM_FLIPPED_270:
393         v = es->buffer_ref.buffer->width;
394         break;
395     default:
396         v = es->buffer_ref.buffer->height;
397         break;
398     }
399     return (v / es->buffer_viewport.scale);
400 }
401
402 /*--------------------------------------------------------------------------*/
403 /**
404  * @brief   ico_ivi_surface_buffer_size: get surface buffer size
405  *
406  * @param[in]   es          weston surface
407  * @param[out]  width       buffer width
408  * @param[out]  height      buffer height
409  * @return      nothing
410  */
411 /*--------------------------------------------------------------------------*/
412 WL_EXPORT   void
413 ico_ivi_surface_buffer_size(struct weston_surface *es, int *width, int *height)
414 {
415     if (! es->buffer_ref.buffer)    {
416         *width = 0;
417         *height = 0;
418     }
419     else if (es->buffer_viewport.viewport_set)  {
420         *width = es->buffer_viewport.dst_width;
421         *height = es->buffer_viewport.dst_height;
422     }
423     else    {
424         switch (es->buffer_viewport.transform) {
425         case WL_OUTPUT_TRANSFORM_90:
426         case WL_OUTPUT_TRANSFORM_270:
427         case WL_OUTPUT_TRANSFORM_FLIPPED_90:
428         case WL_OUTPUT_TRANSFORM_FLIPPED_270:
429             *width = es->buffer_ref.buffer->height;
430             *height = es->buffer_ref.buffer->width;
431             break;
432         default:
433             *width = es->buffer_ref.buffer->width;
434             *height = es->buffer_ref.buffer->height;
435             break;
436         }
437         *width = *width / es->buffer_viewport.scale;
438         *height = *height / es->buffer_viewport.scale;
439     }
440 }
441
442 /*--------------------------------------------------------------------------*/
443 /**
444  * @brief   ico_ivi_surface_buffer_size: get surface buffer size
445  *
446  * @param[in]   es          weston surface
447  * @param[out]  width       buffer width
448  * @param[out]  height      buffer height
449  * @return      nothing
450  */
451 /*--------------------------------------------------------------------------*/
452 WL_EXPORT   struct weston_view *
453 ico_ivi_get_primary_view(struct uifw_win_surface *usurf)
454 {
455     struct weston_view  *ev = NULL;
456     struct shell_surface *shsurf;
457
458     if (_ico_win_mgr->compositor->shell_interface.get_primary_view) {
459         shsurf = usurf->surface->configure_private;
460         if (shsurf) {
461             ev = (*_ico_win_mgr->compositor->shell_interface.get_primary_view)(NULL, shsurf);
462         }
463     }
464     if (! ev)   {
465         ev = weston_layout_get_weston_view(usurf->ivisurf);
466     }
467     if (! ev)   {
468         uifw_error("ico_ivi_get_primary_view: usurf=%08x(%x) surface=%08x has no view",
469                    (int)usurf, usurf->surfaceid, (int)usurf->surface);
470     }
471     return ev;
472 }
473
474 /*--------------------------------------------------------------------------*/
475 /**
476  * @brief   ico_window_mgr_set_weston_surface: set weston surface
477  *
478  * @param[in]   usurf       UIFW surface
479  * @param[in]   x           X coordinate on screen
480  * @param[in]   y           Y coordinate on screen
481  * @param[in]   width       width
482  * @param[in]   height      height
483  * @return      none
484  */
485 /*--------------------------------------------------------------------------*/
486 WL_EXPORT   void
487 ico_window_mgr_set_weston_surface(struct uifw_win_surface *usurf,
488                                   int x, int y, int width, int height)
489 {
490     struct weston_surface *es = usurf->surface;
491     struct weston_layout_SurfaceProperties  prop;
492     int     buf_width, buf_height;
493
494     if ((es == NULL) || (usurf->ivisurf == NULL))    {
495         uifw_trace("ico_window_mgr_set_weston_surface: usurf(%08x) has no surface",
496                    (int)usurf);
497         return;
498     }
499
500     if (es->buffer_ref.buffer != NULL)   {
501         ico_ivi_surface_buffer_size(es, &buf_width, &buf_height);
502         if ((width <= 0) || (height <= 0))    {
503             width = buf_width;
504             usurf->width = buf_width;
505             height = buf_height;
506             usurf->height = buf_height;
507         }
508         if (usurf->width > buf_width)   {
509             width = buf_width;
510             x += (usurf->width - buf_width)/2;
511         }
512         if (usurf->height > buf_height) {
513             height = buf_height;
514             y += (usurf->height - buf_height)/2;
515         }
516         if (usurf->visible) {
517             x += usurf->node_tbl->disp_x;
518             y += usurf->node_tbl->disp_y;
519         }
520         else    {
521             x = ICO_IVI_MAX_COORDINATE+1;
522             y = ICO_IVI_MAX_COORDINATE+1;
523         }
524         if (weston_layout_getPropertiesOfSurface(usurf->ivisurf, &prop) == 0)   {
525             if ((prop.destX != x) || (prop.destY != y) ||
526                 (prop.destWidth != (uint32_t)width) ||
527                 (prop.destHeight != (uint32_t)height))  {
528                 if (weston_layout_surfaceSetDestinationRectangle(
529                                         usurf->ivisurf, x, y, width, height) == 0)  {
530                     weston_layout_commitChanges();
531                 }
532             }
533         }
534         weston_surface_damage(es);
535     }
536 }
537
538 /*--------------------------------------------------------------------------*/
539 /**
540  * @brief   ico_window_mgr_get_usurf: find UIFW surface by surface id
541  *
542  * @param[in]   surfaceid   UIFW surface id
543  * @return      UIFW surface table address
544  * @retval      !=NULL      success(surface table address)
545  * @retval      NULL        error(surface id dose not exist)
546  */
547 /*--------------------------------------------------------------------------*/
548 WL_EXPORT   struct uifw_win_surface *
549 ico_window_mgr_get_usurf(const uint32_t surfaceid)
550 {
551     struct uifw_win_surface *usurf;
552
553     usurf = _ico_win_mgr->idhash[MAKE_IDHASH(surfaceid)];
554
555     while (usurf)   {
556         if (usurf->surfaceid == surfaceid) {
557             return usurf;
558         }
559         usurf = usurf->next_idhash;
560     }
561     uifw_trace("ico_window_mgr_get_usurf: NULL(%08x)", surfaceid);
562     return NULL;
563 }
564
565 /*--------------------------------------------------------------------------*/
566 /**
567  * @brief   ico_window_mgr_get_usurf_client: find UIFW surface by surface id/or client
568  *
569  * @param[in]   surfaceid   UIFW surface id
570  * @param[in]   client      Wayland client
571  * @return      UIFW surface table address
572  * @retval      !=NULL      success(surface table address)
573  * @retval      NULL        error(surface id or client dose not exist)
574  */
575 /*--------------------------------------------------------------------------*/
576 WL_EXPORT   struct uifw_win_surface *
577 ico_window_mgr_get_usurf_client(const uint32_t surfaceid, struct wl_client *client)
578 {
579     struct uifw_win_surface *usurf;
580     struct uifw_client      *uclient;
581
582     usurf = ico_window_mgr_get_usurf(surfaceid);
583
584     if (! usurf)    {
585         uclient = ico_window_mgr_find_uclient(client);
586         if (! uclient)  {
587             /* client dose not exist, error         */
588             uifw_trace("ico_window_mgr_get_usurf_client: client=%08x dose not exist",
589                        (int)client);
590             return NULL;
591         }
592         if (&uclient->surface_link == uclient->surface_link.next)   {
593             /* client has no surface                */
594             uifw_trace("ico_window_mgr_get_usurf_client: client=%08x has no surface",
595                        (int)client);
596             return NULL;
597         }
598         usurf = (struct uifw_win_surface *)uclient->surface_link.next;
599     }
600     return usurf;
601 }
602
603 /*--------------------------------------------------------------------------*/
604 /**
605  * @brief   find_uifw_win_surface_by_ws: find UIFW surface by weston surface
606  *
607  * @param[in]   wsurf       Weston surface
608  * @return      UIFW surface table address
609  * @retval      !=NULL      success(surface table address)
610  * @retval      NULL        error(surface dose not exist)
611  */
612 /*--------------------------------------------------------------------------*/
613 static struct uifw_win_surface *
614 find_uifw_win_surface_by_ws(struct weston_surface *wsurf)
615 {
616     struct uifw_win_surface *usurf;
617
618     usurf = _ico_win_mgr->wshash[MAKE_WSHASH(wsurf)];
619
620     while (usurf)   {
621         if (usurf->surface == wsurf) {
622             return usurf;
623         }
624         usurf = usurf->next_wshash;
625     }
626     uifw_trace("find_uifw_win_surface_by_ws: NULL");
627     return NULL;
628 }
629
630 /*--------------------------------------------------------------------------*/
631 /**
632  * @brief   ico_window_mgr_find_uclient: find UIFW client by wayland client
633  *
634  * @param[in]   client      Wayland client
635  * @return      UIFW client table address
636  * @retval      !=NULL      success(client table address)
637  * @retval      NULL        error(client dose not exist)
638  */
639 /*--------------------------------------------------------------------------*/
640 WL_EXPORT   struct uifw_client*
641 ico_window_mgr_find_uclient(struct wl_client *client)
642 {
643     struct uifw_client  *uclient;
644
645     wl_list_for_each (uclient, &_ico_win_mgr->client_list, link)    {
646         if (uclient->client == client)  {
647             return(uclient);
648         }
649     }
650     uifw_trace("ico_window_mgr_find_uclient: client.%08x is NULL", (int)client);
651     return NULL;
652 }
653
654 /*--------------------------------------------------------------------------*/
655 /**
656  * @brief   ico_window_mgr_get_appid: find application id by wayland client
657  *
658  * @param[in]   client      Wayland client
659  * @return      application id
660  * @retval      !=NULL      success(application id)
661  * @retval      NULL        error(client dose not exist)
662  */
663 /*--------------------------------------------------------------------------*/
664 WL_EXPORT   char *
665 ico_window_mgr_get_appid(struct wl_client* client)
666 {
667     struct uifw_client  *uclient;
668
669     uclient = ico_window_mgr_find_uclient(client);
670
671     if (! uclient)  {
672         return NULL;
673     }
674     return uclient->appid;
675 }
676
677 /*--------------------------------------------------------------------------*/
678 /**
679  * @brief   ico_window_mgr_get_display_coordinate: get display coordinate
680  *
681  * @param[in]   displayno   display number
682  * @param[out]  x           relative X coordinate
683  * @param[out]  y           relative Y coordinate
684  * @return      none
685  */
686 /*--------------------------------------------------------------------------*/
687 WL_EXPORT   void
688 ico_window_mgr_get_display_coordinate(int displayno, int *x, int *y)
689 {
690     if ((displayno <= _ico_num_nodes) || (displayno < 0))   {
691         displayno = 0;
692     }
693     *x = _ico_node_table[displayno].disp_x;
694     *y = _ico_node_table[displayno].disp_y;
695 }
696
697 /*--------------------------------------------------------------------------*/
698 /**
699  * @brief   win_mgr_bind_client: desktop_shell from client
700  *
701  * @param[in]   client          Wayland client
702  * @param[in]   shell           shell table address
703  * @return      none
704  */
705 /*--------------------------------------------------------------------------*/
706 static void
707 win_mgr_bind_client(struct wl_client *client, void *shell)
708 {
709     struct uifw_client  *uclient;
710     int     newclient;
711     pid_t   pid;
712     uid_t   uid;
713     gid_t   gid;
714
715     uifw_trace("win_mgr_bind_client: Enter(client=%08x, shell=%08x)",
716                (int)client, (int)shell);
717
718     /* save shell table address             */
719     if (shell)  {
720         _ico_win_mgr->shell = shell;
721     }
722
723     /* set client                           */
724     uclient = ico_window_mgr_find_uclient(client);
725     if (! uclient)  {
726         /* client not exist, create client management table             */
727         uifw_trace("win_mgr_bind_client: Create Client");
728         uclient = (struct uifw_client *)malloc(sizeof(struct uifw_client));
729         if (!uclient)   {
730             uifw_error("win_mgr_bind_client: Error, No Memory");
731             return;
732         }
733         memset(uclient, 0, sizeof(struct uifw_client));
734         uclient->client = client;
735         wl_list_init(&uclient->surface_link);
736         newclient = 1;
737         uclient->destroy_listener.notify = win_mgr_destroy_client;
738         wl_client_add_destroy_listener(client, &uclient->destroy_listener);
739     }
740     else    {
741         newclient = 0;
742     }
743     wl_client_get_credentials(client, &pid, &uid, &gid);
744     uifw_trace("win_mgr_bind_client: client=%08x pid=%d uid=%d gid=%d",
745                (int)client, (int)pid, (int)uid, (int)gid);
746     if (pid > 0)    {
747         uclient->pid = (int)pid;
748         /* get applicationId from AppCore(AUL)  */
749         win_mgr_get_client_appid(uclient);
750
751         if (newclient > 0)  {
752             wl_list_insert(&_ico_win_mgr->client_list, &uclient->link);
753         }
754     }
755     else    {
756         uifw_trace("win_mgr_bind_client: client=%08x pid dose not exist", (int)client);
757     }
758     uifw_trace("win_mgr_bind_client: Leave");
759 }
760
761 /*--------------------------------------------------------------------------*/
762 /**
763  * @brief   win_mgr_destroy_client: destroy client
764  *
765  * @param[in]   listener    listener
766  * @param[in]   data        listener
767  * @return      none
768  */
769 /*--------------------------------------------------------------------------*/
770 static void
771 win_mgr_destroy_client(struct wl_listener *listener, void *data)
772 {
773     struct uifw_client  *uclient;
774     struct uifw_win_surface *usurf;
775     struct uifw_win_surface *usurf_tmp;
776
777     uclient = container_of(listener, struct uifw_client, destroy_listener);
778
779     uifw_trace("win_mgr_destroy_client: Enter(uclient=%08x)", (int)uclient);
780
781     if (uclient)    {
782         /* Client exist, Destory client surfaces            */
783         wl_list_for_each_safe (usurf, usurf_tmp, &uclient->surface_link, client_link)   {
784             win_mgr_destroy_surface(usurf->surface);
785         }
786         /* Destory client management table                  */
787         wl_list_remove(&uclient->link);
788         free(uclient);
789     }
790     uifw_trace("win_mgr_destroy_client: Leave");
791 }
792
793 #if 0       /* work around: Walk through child processes until app ID is found  */
794 /*--------------------------------------------------------------------------*/
795 /**
796  * @brief   win_mgr_get_ppid: Get parent process ID.
797  *
798  * Similar to getppid(), except that this implementation accepts an
799  * arbitrary process ID.
800  *
801  * @param[in]   pid     Process ID of child process
802  * @return      parent process ID on success, -1 on failure
803  */
804 /*--------------------------------------------------------------------------*/
805 static pid_t
806 win_mgr_get_ppid(pid_t pid)
807 {
808     pid_t ppid = -1;
809     char procpath[PATH_MAX] = { 0 };
810
811     snprintf(procpath, sizeof(procpath)-1, "/proc/%d/status", pid);
812
813     /* We better have read permissions! */
814     int const fd = open(procpath, O_RDONLY);
815
816     if (fd < 0)
817         return ppid;
818
819     char buffer[1024] = { 0 };
820
821     ssize_t const size = read(fd, buffer, sizeof(buffer));
822     close(fd);
823
824     if (size <= 0)
825         return ppid;
826
827     /* Find line containing the parent process ID. */
828     char const * const ppid_line = strstr(buffer, "PPid");
829
830     if (ppid_line != NULL)
831         sscanf(ppid_line, "PPid:    %d", &ppid);
832
833     return ppid;
834 }
835 #endif      /* work around: Walk through child processes until app ID is found  */
836
837 /*--------------------------------------------------------------------------*/
838 /**
839  * @brief   win_mgr_get_client_appid: get applicationId from pid
840  *
841  * @param[in]   uclient     UIFW client management table
842  * @return      none
843  */
844 /*--------------------------------------------------------------------------*/
845 static void
846 win_mgr_get_client_appid(struct uifw_client *uclient)
847 {
848     int status = AUL_R_ERROR;
849
850     memset(uclient->appid, 0, ICO_IVI_APPID_LENGTH);
851
852 #if 0       /* work around: Walk through child processes until app ID is found  */
853     /*
854      * Walk the parent process chain until we find a parent process
855      * with an app ID.
856      */
857     int pid;
858
859     for (pid = uclient->pid;
860          pid > 1 && status != AUL_R_OK;
861          pid = win_mgr_get_ppid(pid)) {
862
863         status = aul_app_get_appid_bypid(pid,
864                                          uclient->appid,
865                                          ICO_IVI_APPID_LENGTH);
866
867         uifw_trace("win_mgr_get_client_appid: aul_app_get_appid_bypid ret=%d "
868                    "pid=%d appid=<%s>", status, pid, uclient->appid);
869     }
870     /*
871      * Walk the child process chain as well since app ID was not yet found
872      */
873     if (status != AUL_R_OK) {
874
875         DIR *dr;
876         struct dirent *de;
877         struct stat ps;
878         pid_t   tpid;
879         uid_t   uid;
880         gid_t   gid;
881
882         dr = opendir("/proc/");
883
884         /* get uid */
885         wl_client_get_credentials(uclient->client, &tpid, &uid, &gid);
886
887         while(((de = readdir(dr)) != NULL) && (status != AUL_R_OK)) {
888
889             char fullpath[PATH_MAX] = { 0 };
890             int is_child = 0;
891             int tmppid;
892
893             snprintf(fullpath, sizeof(fullpath)-1, "/proc/%s", de->d_name);
894
895             if (stat(fullpath, &ps) == -1) {
896                 continue;
897             }
898
899             /* find pid dirs for this user (uid) only */
900             if (ps.st_uid != uid)
901                 continue;
902
903             pid = atoi(de->d_name);
904
905             /* check if it's a valid child */
906             if (pid < uclient->pid)
907                 continue;
908
909             /* scan up to pid to find if a chain exists */
910             for (tmppid = pid; tmppid > uclient->pid;) {
911                 tmppid = win_mgr_get_ppid(tmppid);
912                 if (tmppid == uclient->pid)
913                     is_child = 1;
914             }
915
916             if (is_child) {
917                 status = aul_app_get_appid_bypid(pid, uclient->appid,
918                                                       ICO_IVI_APPID_LENGTH);
919
920                 uifw_debug("win_mgr_get_client_appid: aul_app_get_appid_bypid "
921                            "ret=%d pid=%d appid=<%s>", status, pid,
922                            uclient->appid);
923             }
924         }
925     }
926 #else       /* work around: Walk through child processes until app ID is found  */
927     status = aul_app_get_appid_bypid(uclient->pid, uclient->appid, ICO_IVI_APPID_LENGTH);
928     uifw_trace("win_mgr_get_client_appid: aul_app_get_appid_bypid ret=%d "
929                "pid=%d appid=<%s>", status, uclient->pid, uclient->appid);
930 #endif      /* work around: Walk through child processes until app ID is found  */
931
932     if (uclient->appid[0] != 0) {
933         /* OK, end of get appid         */
934         uclient->fixed_appid = ICO_WINDOW_MGR_APPID_FIXCOUNT;
935     }
936     else    {
937         /* client does not exist in AppCore, search Linux process table */
938
939         int     fd;
940         int     size;
941         int     i;
942         int     j;
943         char    procpath[128];
944
945         uclient->fixed_appid ++;
946         memset(uclient->appid, 0, ICO_IVI_APPID_LENGTH);
947         snprintf(procpath, sizeof(procpath)-1, "/proc/%d/cmdline", uclient->pid);
948         fd = open(procpath, O_RDONLY);
949         if (fd >= 0)    {
950             size = read(fd, procpath, sizeof(procpath));
951             for (; size > 0; size--)    {
952                 if (procpath[size-1])   break;
953             }
954             if (size > 0)   {
955                 /* get program base name    */
956                 i = 0;
957                 for (j = 0; j < size; j++)  {
958                     if (procpath[j] == 0)   break;
959                     if (procpath[j] == '/') i = j + 1;
960                 }
961                 j = 0;
962                 for (; i < size; i++)   {
963                     uclient->appid[j] = procpath[i];
964                     if ((uclient->appid[j] == 0) ||
965                         (j >= (ICO_IVI_APPID_LENGTH-1)))    break;
966                     j++;
967                 }
968                 /* search application number in apprication start option    */
969                 if ((uclient->appid[j] == 0) && (j < (ICO_IVI_APPID_LENGTH-2))) {
970                     for (; i < size; i++)   {
971                         if ((procpath[i] == 0) &&
972                             (procpath[i+1] == '@')) {
973                             strncpy(&uclient->appid[j], &procpath[i+1],
974                                     ICO_IVI_APPID_LENGTH - j - 2);
975                         }
976                     }
977                 }
978             }
979             close(fd);
980         }
981         for (i = strlen(uclient->appid)-1; i >= 0; i--) {
982             if (uclient->appid[i] != ' ')   break;
983         }
984         uclient->appid[i+1] = 0;
985         if (uclient->appid[0])  {
986             uifw_trace("win_mgr_get_client_appid: pid=%d appid=<%s> from "
987                        "Process table(%d)",
988                        uclient->pid, uclient->appid, uclient->fixed_appid );
989         }
990         else    {
991             uifw_trace("win_mgr_get_client_appid: pid=%d dose not exist in Process table",
992                        uclient->pid);
993             sprintf(uclient->appid, "?%d?", uclient->pid);
994         }
995     }
996 }
997
998 /*--------------------------------------------------------------------------*/
999 /**
1000  * @brief   ico_get_animation_name: convert animation name to Id value
1001  *
1002  * @param[in]   animation       animation name
1003  * @return      animation Id value
1004  */
1005 /*--------------------------------------------------------------------------*/
1006 static int
1007 ico_get_animation_name(const char *animation)
1008 {
1009     int anima = ICO_WINDOW_MGR_ANIMATION_NONE;
1010
1011     if (strcasecmp(animation, "none") == 0) {
1012         return ICO_WINDOW_MGR_ANIMATION_NONE;
1013     }
1014
1015     if (win_mgr_hook_animation) {
1016         anima = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_NAME, (void *)animation);
1017     }
1018     if (anima <= 0) {
1019         anima = ICO_WINDOW_MGR_ANIMATION_NONE;
1020     }
1021     return anima;
1022 }
1023
1024 /*--------------------------------------------------------------------------*/
1025 /**
1026  * @brief   win_mgr_send_event: send event to controller
1027  *
1028  * @param[in]   event           event code
1029  * @param[in]   surfaceid       surface id
1030  * @param[in]   arg1            argument 1
1031  * @return      none
1032  */
1033 /*--------------------------------------------------------------------------*/
1034 static void
1035 win_mgr_send_event(int event, uint32_t surfaceid, uint32_t arg1)
1036 {
1037     struct uifw_manager     *mgr;
1038
1039     /* send event to manager     */
1040     wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link)   {
1041         switch (event)  {
1042         case ICO_WINDOW_MGR_WINDOW_ACTIVE:      /* active event             */
1043             uifw_trace("win_mgr_send_event: Send ACTIVE(surf=%08x, select=%x)",
1044                        surfaceid, arg1);
1045             ico_window_mgr_send_window_active(mgr->resource, surfaceid, arg1);
1046             break;
1047         case ICO_WINDOW_MGR_DESTROY_SURFACE:    /* surface destroy event    */
1048             uifw_trace("win_mgr_send_event: Send DESTROY_SURFACE(surf=%08x) mgr=%08x",
1049                        surfaceid, (int)mgr);
1050             ico_window_mgr_send_destroy_surface(mgr->resource, surfaceid);
1051             break;
1052         default:
1053             uifw_error("win_mgr_send_event: Unknown event(%d)", event);
1054             break;
1055         }
1056     }
1057 }
1058
1059 /*--------------------------------------------------------------------------*/
1060 /**
1061  * @brief   win_mgr_select_surface: select surface by mouse click
1062  *
1063  * @param[in]   seat            weston seat
1064  * @param[in]   focus           selected surface
1065  * @param[in]   select          selected device
1066  * @return      none
1067  */
1068 /*--------------------------------------------------------------------------*/
1069 static void
1070 win_mgr_select_surface(struct weston_seat *seat, struct weston_surface *focus, int select)
1071 {
1072     struct weston_surface   *surface;
1073     struct uifw_win_surface *usurf;
1074     struct uifw_manager     *mgr;
1075
1076     surface = weston_surface_get_main_surface(focus);
1077
1078     uifw_trace("win_mgr_select_surface: Enter(%08x,%d)", (int)surface, select);
1079
1080     if (! surface)  {
1081         uifw_trace("win_mgr_select_surface: Leave(no surface)");
1082         return;
1083     }
1084     /* find surface         */
1085     usurf = find_uifw_win_surface_by_ws(surface);
1086     if (! usurf) {
1087         uifw_trace("win_mgr_select_surface: Leave(usurf not exist)");
1088         return;
1089     }
1090     /* surface active       */
1091     weston_surface_activate(surface, seat);
1092
1093     /* send active event to manager     */
1094     wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link)   {
1095         uifw_trace("win_mgr_select_surface: Send Manager ACTIVE(surf=%08x)",
1096                    usurf->surfaceid);
1097         ico_window_mgr_send_window_active(mgr->resource, usurf->surfaceid,
1098                                           select);
1099     }
1100     uifw_trace("win_mgr_select_surface: Leave");
1101 }
1102
1103 /*--------------------------------------------------------------------------*/
1104 /**
1105  * @brief   win_mgr_click_to_activate: select surface by mouse click
1106  *
1107  * @param[in]   seat            weston seat
1108  * @param[in]   time            click time(current time)
1109  * @param[in]   button          click button
1110  * @param[in]   data            user data(unused)
1111  * @return      none
1112  */
1113 /*--------------------------------------------------------------------------*/
1114 static void
1115 win_mgr_click_to_activate(struct weston_seat *seat, uint32_t time,
1116                           uint32_t button, void *data)
1117 {
1118     if (seat->pointer->grab != &seat->pointer->default_grab)
1119         return;
1120     if (seat->pointer->focus == NULL)
1121         return;
1122
1123     win_mgr_select_surface(seat, seat->pointer->focus->surface,
1124                            ICO_WINDOW_MGR_SELECT_POINTER);
1125 }
1126
1127 /*--------------------------------------------------------------------------*/
1128 /**
1129  * @brief   win_mgr_touch_to_activate: select surface by touch touch-panel
1130  *
1131  * @param[in]   seat            weston seat
1132  * @param[in]   time            click time(current time)
1133  * @param[in]   data            user data(unused)
1134  * @return      none
1135  */
1136 /*--------------------------------------------------------------------------*/
1137 static void
1138 win_mgr_touch_to_activate(struct weston_seat *seat, uint32_t time, void *data)
1139 {
1140     if (seat->touch->grab != &seat->touch->default_grab)
1141         return;
1142     if (seat->touch->focus == NULL)
1143         return;
1144
1145     win_mgr_select_surface(seat, seat->touch->focus->surface, ICO_WINDOW_MGR_SELECT_TOUCH);
1146 }
1147
1148 /*--------------------------------------------------------------------------*/
1149 /**
1150  * @brief   ico_ivi_surfaceCreateNotification: create ivi-surface
1151  *
1152  * @param[in]   ivisurf         ivi surface
1153  * @param[in]   userdata        User Data(Unused)
1154  * @return      none
1155  */
1156 /*--------------------------------------------------------------------------*/
1157 static void
1158 ico_ivi_surfaceCreateNotification(struct weston_layout_surface *ivisurf, void *userdata)
1159 {
1160     uint32_t                id_surface;
1161     struct weston_view      *ev;
1162     struct weston_surface   *es;
1163     struct wl_client        *client;
1164
1165     id_surface = weston_layout_getIdOfSurface(ivisurf);
1166     uifw_trace("ico_ivi_surfaceCreateNotification: Create %x", id_surface);
1167
1168     /* set property notification    */
1169     if (weston_layout_surfaceAddNotification(ivisurf, ico_ivi_surfacePropertyNotification, NULL) != 0)  {
1170         uifw_error("ico_ivi_surfaceCreateNotification: weston_layout_surfaceAddNotification Error");
1171     }
1172     ev = weston_layout_get_weston_view(ivisurf);
1173     if (! ev)   {
1174         uifw_error("ico_ivi_surfaceCreateNotification: weston_layout_get_weston_view Error");
1175     }
1176     else    {
1177         es = ev->surface;
1178         if (! es)   {
1179             uifw_error("ico_ivi_surfaceCreateNotification: no weston_surface");
1180         }
1181         else    {
1182             client = wl_resource_get_client(es->resource);
1183             if (! client)   {
1184                 uifw_error("ico_ivi_surfaceCreateNotification: no wl_client");
1185             }
1186             else    {
1187                 win_mgr_register_surface(id_surface, es, client, ivisurf);
1188             }
1189         }
1190     }
1191 }
1192
1193 /*--------------------------------------------------------------------------*/
1194 /**
1195  * @brief   ico_ivi_surfaceRemoveNotification: remove ivi-surface
1196  *
1197  * @param[in]   ivisurf         ivi surface
1198  * @param[in]   userdata        User Data(Unused)
1199  * @return      none
1200  */
1201 /*--------------------------------------------------------------------------*/
1202 static void
1203 ico_ivi_surfaceRemoveNotification(struct weston_layout_surface *ivisurf, void *userdata)
1204 {
1205     uint32_t    id_surface;
1206     struct weston_view      *ev;
1207     struct weston_surface   *es;
1208
1209     id_surface = weston_layout_getIdOfSurface(ivisurf);
1210     uifw_trace("ico_ivi_surfaceRemoveNotification: Remove %x", id_surface);
1211
1212     ev = weston_layout_get_weston_view(ivisurf);
1213     if (! ev)   {
1214         uifw_error("ico_ivi_surfaceRemoveNotification: weston_layout_get_weston_view Error");
1215     }
1216     else    {
1217         es = ev->surface;
1218         if (! es)   {
1219             uifw_error("ico_ivi_surfaceRemoveNotification: no weston_surface");
1220         }
1221         else    {
1222             win_mgr_destroy_surface(es);
1223         }
1224     }
1225 }
1226
1227 /*--------------------------------------------------------------------------*/
1228 /**
1229  * @brief   ico_ivi_surfacePropertyNotification: property change ivi-surface
1230  *
1231  * @param[in]   ivisurf         ivi surface
1232  * @param[in]   userdata        User Data(Unused)
1233  * @return      none
1234  */
1235 /*--------------------------------------------------------------------------*/
1236 static void
1237 ico_ivi_surfacePropertyNotification(struct weston_layout_surface *ivisurf,
1238                                     struct weston_layout_SurfaceProperties *prop,
1239                                     enum weston_layout_notification_mask mask,
1240                                     void *userdata)
1241 {
1242     struct uifw_manager *mgr;
1243     uint32_t    id_surface;
1244     int         retanima;
1245     uint32_t    newmask;
1246     struct uifw_win_surface *usurf;
1247     struct weston_view      *ev;
1248
1249     newmask = ((uint32_t)mask) & (~(IVI_NOTIFICATION_OPACITY|IVI_NOTIFICATION_ORIENTATION|
1250                                     IVI_NOTIFICATION_PIXELFORMAT));
1251     id_surface = weston_layout_getIdOfSurface(ivisurf);
1252     usurf = ico_window_mgr_get_usurf(id_surface);
1253
1254     if ((newmask != 0) && (usurf != NULL))  {
1255         uifw_trace("ico_ivi_surfacePropertyNotification: Property %x(%08x) usurf=%08x",
1256                    id_surface, newmask, (int)usurf);
1257         if (newmask & (IVI_NOTIFICATION_SOURCE_RECT|IVI_NOTIFICATION_DEST_RECT|
1258                        IVI_NOTIFICATION_POSITION|IVI_NOTIFICATION_DIMENSION))   {
1259             /* change position or size  */
1260             uifw_trace("ico_ivi_surfacePropertyNotification: %08x x/y=%d/%d->%d/%d "
1261                        "w/h=%d/%d->%d/%d(%d/%d)", id_surface, usurf->x, usurf->y,
1262                        prop->destX, prop->destY, usurf->width, usurf->height,
1263                        prop->destWidth, prop->destHeight,
1264                        prop->sourceWidth, prop->sourceHeight);
1265             if ((usurf->client_width == prop->sourceWidth) &&
1266                 (usurf->client_height == prop->sourceHeight))   {
1267                 newmask &= (~IVI_NOTIFICATION_SOURCE_RECT);
1268             }
1269             else    {
1270                 usurf->client_width = prop->sourceWidth;
1271                 usurf->client_height = prop->sourceHeight;
1272             }
1273             if ((usurf->x == prop->destX) && (usurf->y == prop->destY) &&
1274                 (usurf->width == prop->destWidth) && (usurf->height == prop->destHeight)) {
1275                 newmask &= (~(IVI_NOTIFICATION_DEST_RECT|
1276                               IVI_NOTIFICATION_POSITION|IVI_NOTIFICATION_DIMENSION));
1277             }
1278             else    {
1279                 usurf->x = prop->destX;
1280                 usurf->y = prop->destY;
1281                 usurf->width = prop->destWidth;
1282                 usurf->height = prop->destHeight;
1283                 if ((usurf->width != usurf->configure_width) ||
1284                     (usurf->height != usurf->configure_height)) {
1285                     /* send configure to client(App)        */
1286                     uifw_trace("ico_ivi_surfacePropertyNotification: send configure "
1287                                "%08x(%d,%d->%d,%d)", usurf->surfaceid,
1288                                usurf->configure_width, usurf->configure_height,
1289                                usurf->width, usurf->height);
1290                     usurf->configure_width = usurf->width;
1291                     usurf->configure_height = usurf->height;
1292
1293                     struct wl_array surfaces;
1294                     struct shell_surface;
1295                     void    **shsurf;
1296                     if (! usurf->shsurf_resource)   {
1297                         /* get shell surface if not get */
1298                         ivi_shell_get_shell_surfaces(&surfaces);
1299                         wl_array_for_each(shsurf, &surfaces)    {
1300                             if (shell_surface_get_surface(*shsurf) == usurf->surface)   {
1301                                 usurf->shsurf_resource = *((struct wl_resource **)*shsurf);
1302                                 break;
1303                             }
1304                         }
1305                         wl_array_release(&surfaces);
1306                     }
1307                     if (usurf->shsurf_resource) {
1308                         uifw_trace("ico_ivi_surfacePropertyNotification: surface %08x "
1309                                    "resource=%08x",
1310                                    usurf->surfaceid, (int)usurf->shsurf_resource);
1311                         wl_shell_surface_send_configure(usurf->shsurf_resource,
1312                                         WL_SHELL_SURFACE_RESIZE_RIGHT|
1313                                             WL_SHELL_SURFACE_RESIZE_BOTTOM,
1314                                         usurf->configure_width, usurf->configure_height);
1315                     }
1316                     else    {
1317                         uifw_trace("ico_ivi_surfacePropertyNotification: surface %08x "
1318                                    "shell_surface resource not found", usurf->surfaceid);
1319                     }
1320                 }
1321             }
1322         }
1323         if (newmask & IVI_NOTIFICATION_VISIBILITY)  {
1324             if ((usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_NONE) &&
1325                 (win_mgr_hook_animation != NULL))   {
1326                 /* start animation, save original position of surface   */
1327                 usurf->animation.pos_x = usurf->x;
1328                 usurf->animation.pos_y = usurf->y;
1329                 usurf->animation.pos_width = usurf->width;
1330                 usurf->animation.pos_height = usurf->height;
1331                 ev = weston_layout_get_weston_view(ivisurf);
1332                 if (ev) {
1333                     usurf->animation.alpha = ev->alpha;
1334                 }
1335                 else    {
1336                     usurf->animation.alpha = 1.0;
1337                 }
1338             }
1339             if ((usurf->visible == 0) && (prop->visibility)) {
1340                 uifw_trace("ico_ivi_surfacePropertyNotification: %08x Visible 0=>1",
1341                            id_surface);
1342                 usurf->visible = 1;
1343                 if ((usurf->animation.show_anima != ICO_WINDOW_MGR_ANIMATION_NONE) &&
1344                     (win_mgr_hook_animation != NULL))   {
1345                     /* show with animation      */
1346                     retanima =
1347                         (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_OPSHOW,
1348                                                   (void *)usurf);
1349                     uifw_trace("ico_ivi_surfacePropertyNotification: ret call anima = %d",
1350                                retanima);
1351                 }
1352             }
1353             else if ((usurf->visible != 0) && (! prop->visibility))  {
1354                 uifw_trace("ico_ivi_surfacePropertyNotification: %08x Visible 1=>0",
1355                            id_surface);
1356                 usurf->visible = 0;
1357                 if ((usurf->animation.show_anima != ICO_WINDOW_MGR_ANIMATION_NONE) &&
1358                     (win_mgr_hook_animation != NULL))   {
1359                     /* hide with animation      */
1360                     retanima =
1361                         (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_OPHIDE,
1362                                                   (void *)usurf);
1363                 }
1364                 else    {
1365                     retanima = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
1366                 }
1367                 if (retanima != ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL)    {
1368                     usurf->visible = 0;
1369                     uifw_trace("ico_ivi_surfacePropertyNotification: Change to UnVisible");
1370                 }
1371                 else    {
1372                     usurf->visible = 1;
1373                     uifw_trace("ico_ivi_surfacePropertyNotification: Change to Visible");
1374                     weston_layout_surfaceSetVisibility(ivisurf, 1);
1375                     weston_layout_commitChanges();
1376                 }
1377             }
1378             else    {
1379                 uifw_trace("ico_ivi_surfacePropertyNotification: visible no change");
1380                 newmask &= (~IVI_NOTIFICATION_VISIBILITY);
1381             }
1382         }
1383
1384         if (newmask)    {
1385             /* surface changed, send event to controller    */
1386             wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link)   {
1387                 uifw_trace("win_mgr_send_event: Send UPDATE_SURFACE(surf=%08x) "
1388                            "v=%d src=%d/%d dest=%d/%d(%d/%d) mgr=%08x", id_surface,
1389                            usurf->visible, usurf->client_width, usurf->client_height,
1390                            usurf->x, usurf->y, usurf->width, usurf->height, (int)mgr);
1391                 ico_window_mgr_send_update_surface(mgr->resource, id_surface,
1392                                 usurf->visible, usurf->client_width,
1393                                 usurf->client_height, usurf->x, usurf->y,
1394                                 usurf->width, usurf->height);
1395             }
1396         }
1397     }
1398 }
1399
1400 /*--------------------------------------------------------------------------*/
1401 /**
1402  * @brief   win_mgr_register_surface: create UIFW surface
1403  *
1404  * @param[in]   id_surface      surface id (by ivi-shell)
1405  * @param[in]   surface         Weston surface
1406  * @param[in]   client          Wayland client
1407  * @param[in]   ivisurf         weston layout surface
1408  * @return      none
1409  */
1410 /*--------------------------------------------------------------------------*/
1411 static void
1412 win_mgr_register_surface(uint32_t id_surface, struct weston_surface *surface,
1413                          struct wl_client *client, struct weston_layout_surface *ivisurf)
1414 {
1415     struct weston_layout_SurfaceProperties  prop;
1416     struct uifw_win_surface *usurf;
1417     struct uifw_win_surface *phash;
1418     struct uifw_win_surface *bhash;
1419     uint32_t    hash;
1420
1421     uifw_trace("win_mgr_register_surface: Enter(surf=%x[%08x],client=%08x,ivisurf=%08x)",
1422                id_surface, (int)surface, (int)client, (int)ivisurf);
1423
1424     /* check new surface                    */
1425     if (find_uifw_win_surface_by_ws(surface))   {
1426         /* surface exist, NOP               */
1427         uifw_trace("win_mgr_register_surface: Leave(Already Exist)");
1428         return;
1429     }
1430
1431     /* set default color and shader */
1432     weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
1433
1434     /* create UIFW surface management table */
1435     usurf = malloc(sizeof(struct uifw_win_surface));
1436     if (! usurf)    {
1437         uifw_error("win_mgr_register_surface: No Memory");
1438         return;
1439     }
1440
1441     memset(usurf, 0, sizeof(struct uifw_win_surface));
1442
1443     usurf->surfaceid = id_surface;
1444     usurf->surface = surface;
1445     usurf->ivisurf = ivisurf;
1446     usurf->node_tbl = &_ico_node_table[0];  /* set default node table (display no=0)    */
1447
1448     if (weston_layout_getPropertiesOfSurface(ivisurf, &prop) == 0)  {
1449         usurf->x = prop.destX;
1450         usurf->y = prop.destY;
1451         usurf->width = prop.destWidth;
1452         usurf->height = prop.destHeight;
1453         usurf->client_width = prop.sourceWidth;
1454         usurf->client_height = prop.sourceHeight;
1455         usurf->configure_width = usurf->client_width;
1456         usurf->configure_height = usurf->client_height;
1457     }
1458     wl_list_init(&usurf->surface_destroy_listener.link);
1459     usurf->surface_destroy_listener.notify = win_mgr_surface_destroy;
1460     wl_signal_add(&surface->destroy_signal, &usurf->surface_destroy_listener);
1461
1462     wl_list_init(&usurf->client_link);
1463     wl_list_init(&usurf->animation.animation.link);
1464     wl_list_init(&usurf->surf_map);
1465     wl_list_init(&usurf->input_region);
1466     usurf->animation.hide_anima = ico_get_animation_name(ico_ivi_default_animation_name());
1467     usurf->animation.hide_time = ico_ivi_default_animation_time();
1468     usurf->animation.show_anima = usurf->animation.hide_anima;
1469     usurf->animation.show_time = usurf->animation.hide_time;
1470     usurf->animation.move_anima = usurf->animation.hide_anima;
1471     usurf->animation.move_time = usurf->animation.hide_time;
1472     usurf->animation.resize_anima = usurf->animation.hide_anima;
1473     usurf->animation.resize_time = usurf->animation.hide_time;
1474     usurf->visible = 0;
1475
1476     /* set client                           */
1477     usurf->uclient = ico_window_mgr_find_uclient(client);
1478     if (! usurf->uclient)  {
1479         /* client not exist, create client management table */
1480         uifw_trace("win_mgr_register_surface: Create Client");
1481         win_mgr_bind_client(client, NULL);
1482         usurf->uclient = ico_window_mgr_find_uclient(client);
1483         if (! usurf->uclient)  {
1484             uifw_error("win_mgr_register_surface: No Memory");
1485             return;
1486         }
1487     }
1488     wl_list_insert(usurf->uclient->surface_link.prev, &usurf->client_link);
1489
1490     /* make surface id hash table       */
1491     hash = MAKE_IDHASH(usurf->surfaceid);
1492     phash = _ico_win_mgr->idhash[hash];
1493     bhash = NULL;
1494     while (phash)   {
1495         bhash = phash;
1496         phash = phash->next_idhash;
1497     }
1498     if (bhash)  {
1499         bhash->next_idhash = usurf;
1500     }
1501     else    {
1502         _ico_win_mgr->idhash[hash] = usurf;
1503     }
1504
1505     /* make weston surface hash table   */
1506     hash = MAKE_WSHASH(usurf->surface);
1507     phash = _ico_win_mgr->wshash[hash];
1508     bhash = NULL;
1509     while (phash)   {
1510         bhash = phash;
1511         phash = phash->next_wshash;
1512     }
1513     if (bhash)  {
1514         bhash->next_wshash = usurf;
1515     }
1516     else    {
1517         _ico_win_mgr->wshash[hash] = usurf;
1518     }
1519     uifw_trace("win_mgr_register_surface: Leave(surfaceId=%08x)", usurf->surfaceid);
1520 }
1521
1522 /*--------------------------------------------------------------------------*/
1523 /**
1524  * @brief   uifw_set_animation: set animation of surface visible/unvisible
1525  *
1526  * @param[in]   client      Weyland client
1527  * @param[in]   resource    resource of request
1528  * @param[in]   surfaceid   UIFW surface id
1529  * @param[in]   type        how to change surface
1530  * @param[in]   anmation    animation name
1531  * @param[in]   time        animation time(ms), if 0, default time
1532  * @return      none
1533  */
1534 /*--------------------------------------------------------------------------*/
1535 static void
1536 uifw_set_animation(struct wl_client *client, struct wl_resource *resource,
1537                    uint32_t surfaceid, int32_t type, const char *animation, int32_t time)
1538 {
1539     int     animaid;
1540     struct uifw_win_surface *usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
1541
1542     uifw_trace("uifw_set_animation: surf=%08x,type=%x,anim=%s,time=%d",
1543                surfaceid, type, animation, time);
1544
1545     if (usurf) {
1546         if ((*animation != 0) && (*animation != ' '))   {
1547             animaid = ico_get_animation_name(animation);
1548             uifw_trace("uifw_set_animation: Leave(OK) type=%d", animaid);
1549             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT)   {
1550                 if (! usurf->org_animation.saved) {
1551                     usurf->org_animation.type = usurf->animation.type;
1552                     usurf->org_animation.anima = usurf->animation.anima;
1553                     usurf->org_animation.next_anima = usurf->animation.next_anima;
1554                     usurf->org_animation.hide_anima = usurf->animation.hide_anima;
1555                     usurf->org_animation.hide_time = usurf->animation.hide_time;
1556                     usurf->org_animation.show_anima = usurf->animation.show_anima;
1557                     usurf->org_animation.show_time = usurf->animation.show_time;
1558                     usurf->org_animation.move_anima = usurf->animation.move_anima;
1559                     usurf->org_animation.move_time = usurf->animation.move_time;
1560                     usurf->org_animation.resize_anima = usurf->animation.resize_anima;
1561                     usurf->org_animation.resize_time = usurf->animation.resize_time;
1562                     usurf->org_animation.saved = 1;
1563                 }
1564             }
1565             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE)  {
1566                 if ((usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPHIDE) ||
1567                     (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS))  {
1568                     usurf->animation.next_anima = animaid;
1569                     if ((type & ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT) == 0)
1570                         usurf->org_animation.next_anima = animaid;
1571                 }
1572                 else    {
1573                     usurf->animation.hide_anima = animaid;
1574                     if ((type & ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT) == 0)
1575                         usurf->org_animation.hide_anima = animaid;
1576                 }
1577             }
1578             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW)  {
1579                 if ((usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPSHOW) ||
1580                     (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS))  {
1581                     usurf->animation.next_anima = animaid;
1582                     if ((type & ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT) == 0)
1583                         usurf->org_animation.next_anima = animaid;
1584                 }
1585                 else    {
1586                     usurf->animation.show_anima = animaid;
1587                     if ((type & ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT) == 0)
1588                         usurf->org_animation.show_anima = animaid;
1589                 }
1590             }
1591             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE)  {
1592                 if (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPMOVE)    {
1593                     usurf->animation.next_anima = animaid;
1594                     if ((type & ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT) == 0)
1595                         usurf->org_animation.next_anima = animaid;
1596                 }
1597                 else    {
1598                     usurf->animation.move_anima = animaid;
1599                     if ((type & ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT) == 0)
1600                         usurf->org_animation.move_anima = animaid;
1601                 }
1602             }
1603             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE)    {
1604                 if (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPRESIZE)  {
1605                     usurf->animation.next_anima = animaid;
1606                     if ((type & ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT) == 0)
1607                         usurf->org_animation.next_anima = animaid;
1608                 }
1609                 else    {
1610                     usurf->animation.resize_anima = animaid;
1611                     if ((type & ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT) == 0)
1612                         usurf->org_animation.resize_anima = animaid;
1613                 }
1614             }
1615         }
1616         if ((time > 0) && (time < 10000))   {
1617             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE)  {
1618                 usurf->animation.hide_time = time;
1619                 if ((type & ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT) == 0)
1620                     usurf->org_animation.hide_time = time;
1621             }
1622             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW)  {
1623                 usurf->animation.show_time = time;
1624                 if ((type & ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT) == 0)
1625                     usurf->org_animation.show_time = time;
1626             }
1627             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE)  {
1628                 usurf->animation.move_time = time;
1629                 if ((type & ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT) == 0)
1630                     usurf->org_animation.move_time = time;
1631             }
1632             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE)    {
1633                 usurf->animation.resize_time = time;
1634                 if ((type & ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT) == 0)
1635                     usurf->org_animation.resize_time = time;
1636             }
1637         }
1638     }
1639     else    {
1640         uifw_trace("uifw_set_animation: Surface(%08x) Not exist", surfaceid);
1641     }
1642 }
1643
1644 /*--------------------------------------------------------------------------*/
1645 /**
1646  * @brief   win_mgr_check_mapsurface: check and change all surface
1647  *
1648  * @param[in]   animation   weston animation table(unused)
1649  * @param[in]   outout      weston output table(unused)
1650  * @param[in]   mseces      current time(unused)
1651  * @return      none
1652  */
1653 /*--------------------------------------------------------------------------*/
1654 static void
1655 win_mgr_check_mapsurface(struct weston_animation *animation,
1656                          struct weston_output *output, uint32_t msecs)
1657 {
1658     struct uifw_surface_map *sm, *sm_tmp;
1659     uint32_t    curtime;
1660     int         wait = 99999999;
1661
1662     /* check touch down counter     */
1663     if ((touch_check_seat) &&
1664         (touch_check_seat->touch))  {
1665         if (touch_check_seat->touch->num_tp > 10)  {
1666             uifw_trace("win_mgr_check_mapsurface: illegal touch counter(num=%d), reset",
1667                        (int)touch_check_seat->touch->num_tp);
1668             touch_check_seat->touch->num_tp = 0;
1669         }
1670     }
1671
1672     /* check all mapped surfaces    */
1673     curtime = weston_compositor_get_time();
1674     wl_list_for_each_safe (sm, sm_tmp, &_ico_win_mgr->map_list, map_link)   {
1675 #if 0   /* too many log */
1676         uifw_detail("win_mgr_check_mapsurface: sm=%08x surf=%08x",
1677                     (int)sm, sm->usurf->surfaceid);
1678 #endif
1679         if ((sm->interval >= 0) || (sm->eventque == 0)) {
1680             win_mgr_change_mapsurface(sm, 0, curtime);
1681         }
1682         if ((sm->interval >= 0) && (sm->eventque != 0)) {
1683             if (sm->interval < wait)    {
1684                 wait = sm->interval;
1685             }
1686         }
1687     }
1688
1689     /* check frame interval         */
1690     if (wait < 2000)    {
1691         wait = wait / 2;
1692     }
1693     else    {
1694         wait = 1000;
1695     }
1696     wl_event_source_timer_update(_ico_win_mgr->wait_mapevent, wait);
1697 }
1698
1699 /*--------------------------------------------------------------------------*/
1700 /**
1701  * @brief   win_mgr_timer_mapsurface: mapped surface check timer
1702  *
1703  * @param[in]   data        user data(unused)
1704  * @return      fixed 1
1705  */
1706 /*--------------------------------------------------------------------------*/
1707 static int
1708 win_mgr_timer_mapsurface(void *data)
1709 {
1710     win_mgr_check_mapsurface(NULL, NULL, 0);
1711     return 1;
1712 }
1713
1714 /*--------------------------------------------------------------------------*/
1715 /**
1716  * @brief   win_mgr_change_mapsurface: check and change mapped surface
1717  *
1718  * @param[in]   sm          map surface table
1719  * @param[in]   event       send event (if 0, send if changed)
1720  * @param[in]   curtime     current time(ms)
1721  * @return      none
1722  */
1723 /*--------------------------------------------------------------------------*/
1724 static void
1725 win_mgr_change_mapsurface(struct uifw_surface_map *sm, int event, uint32_t curtime)
1726 {
1727     struct weston_surface   *es;
1728     struct wl_shm_buffer    *shm_buffer;
1729     int         width;
1730     int         height;
1731     uint32_t    format;
1732     int         dtime;
1733
1734 #if 0   /* too many log */
1735     uifw_detail("win_mgr_change_mapsurface: surf=%08x event=%d", sm->usurf->surfaceid, event);
1736 #endif
1737     if (event == 0) {
1738         event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_CONTENTS;
1739     }
1740
1741     /* check if buffered        */
1742     es = sm->usurf->surface;
1743     if ((es == NULL) ||
1744         ((sm->type == ICO_WINDOW_MGR_MAP_TYPE_EGL) &&
1745          ((es->buffer_ref.buffer == NULL) ||
1746           (es->buffer_ref.buffer->width <= 0) || (es->buffer_ref.buffer->height <= 0)))) {
1747         /* surface has no buffer    */
1748         uifw_debug("win_mgr_change_mapsurface: surface(%08x) has no buffer %08x %08x",
1749                    sm->usurf->surfaceid, (int)es,
1750                    es ? (int)es->buffer_ref.buffer : 0);
1751         if (sm->initflag)   {
1752             event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP;
1753         }
1754         else    {
1755             event = 0;
1756         }
1757     }
1758     else if (sm->type == ICO_WINDOW_MGR_MAP_TYPE_EGL)   {
1759         if ((es->buffer_ref.buffer->legacy_buffer != NULL) && (es->renderer_state != NULL)) {
1760             if ((void *)wl_resource_get_user_data(
1761                             (struct wl_resource *)es->buffer_ref.buffer->legacy_buffer)
1762                 == NULL)    {
1763                 /* surface has no buffer    */
1764                 uifw_debug("win_mgr_change_mapsurface: surface(%08x) has no buffer",
1765                            sm->usurf->surfaceid);
1766                 if (sm->initflag)   {
1767                     event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP;
1768                 }
1769                 else    {
1770                     event = 0;
1771                 }
1772             }
1773         }
1774     }
1775     else    {
1776         if (es->buffer_ref.buffer != NULL)  {
1777             shm_buffer = wl_shm_buffer_get(es->buffer_ref.buffer->resource);
1778             if (shm_buffer) {
1779                 format = wl_shm_buffer_get_format(shm_buffer);
1780                 if (format != WL_SHM_FORMAT_ARGB8888)   {
1781                     uifw_trace("win_mgr_change_mapsurface: %08x shm_buffer type %x",
1782                                sm->usurf->surfaceid, format);
1783                     event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP;
1784                 }
1785             }
1786         }
1787     }
1788
1789     if ((event != 0) && (event != ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP))  {
1790
1791         if (sm->type == ICO_WINDOW_MGR_MAP_TYPE_EGL)    {
1792             format = EGL_TEXTURE_RGBA;          /* currently only support RGBA  */
1793             width = es->buffer_ref.buffer->width;
1794             height = es->buffer_ref.buffer->height;
1795             if ((sm->initflag == 0) && (width > 0) && (height > 0)) {
1796                 sm->initflag = 1;
1797                 event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_MAP;
1798 #if  PERFORMANCE_EVALUATIONS > 0
1799                 uifw_perf("SWAP_BUFFER appid=%s surface=%08x MAP",
1800                           sm->usurf->uclient->appid, sm->usurf->surfaceid);
1801 #endif /*PERFORMANCE_EVALUATIONS*/
1802             }
1803             else if ((width <= 0) || (height <= 0)) {
1804                 event = 0;
1805             }
1806             else if (event == ICO_WINDOW_MGR_MAP_SURFACE_EVENT_CONTENTS)    {
1807                 if ((sm->width != width) || (sm->height != height) ||
1808                     (format != sm->format)) {
1809                     event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_RESIZE;
1810 #if  PERFORMANCE_EVALUATIONS > 0
1811                     uifw_perf("SWAP_BUFFER appid=%s surface=%08x RESIZE",
1812                               sm->usurf->uclient->appid, sm->usurf->surfaceid);
1813 #endif /*PERFORMANCE_EVALUATIONS*/
1814                 }
1815                 else    {
1816                     if (es->buffer_ref.buffer->legacy_buffer != sm->curbuf) {
1817 #if  PERFORMANCE_EVALUATIONS > 0
1818                         uifw_perf("SWAP_BUFFER appid=%s surface=%08x CONTENTS",
1819                                   sm->usurf->uclient->appid, sm->usurf->surfaceid);
1820 #endif /*PERFORMANCE_EVALUATIONS*/
1821                         if (sm->interval < 0)   {
1822                             sm->eventque = 1;
1823                             event = 0;
1824                         }
1825                         else if (sm->interval > 0)  {
1826                             dtime = (int)(curtime - sm->lasttime);
1827                             if (dtime < sm->interval)   {
1828                                 sm->eventque = 1;
1829                                 event = 0;
1830                             }
1831                         }
1832                     }
1833                     else if (sm->eventque)  {
1834                         if (sm->interval < 0)   {
1835                             event = 0;
1836                         }
1837                         else if (sm->interval > 0)  {
1838                             dtime = (int)(curtime - sm->lasttime);
1839                             if (dtime < sm->interval)   {
1840                                 event = 0;
1841                             }
1842                         }
1843                     }
1844                     else    {
1845                         event =0;
1846                     }
1847                 }
1848             }
1849             sm->width = width;
1850             sm->height = height;
1851             sm->stride = width * 4;
1852             sm->format = format;
1853             sm->curbuf = es->buffer_ref.buffer->legacy_buffer;
1854         }
1855         else    {
1856             if ((sm->eventque != 0) ||
1857                 (es->buffer_ref.buffer == NULL) || (es->buffer_ref.buffer != sm->curbuf)) {
1858                 sm->curbuf = es->buffer_ref.buffer;
1859                 if (es->buffer_ref.buffer != NULL)  {
1860                     width = es->buffer_ref.buffer->width;
1861                     height = es->buffer_ref.buffer->height;
1862                 }
1863                 else    {
1864                     width = es->width;
1865                     height = es->height;
1866                 }
1867                 if ((sm->initflag == 0) && (width > 0) && (height > 0))    {
1868                     sm->initflag = 1;
1869                     event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_MAP;
1870                     uifw_detail("win_mgr_change_mapsurface: PIX MAP event %08x",
1871                                 sm->usurf->surfaceid);
1872                 }
1873                 else    {
1874                     if ((width <= 0) || (height <= 0))  {
1875                         event = 0;
1876                         sm->curbuf = NULL;
1877                         uifw_detail("win_mgr_change_mapsurface: PIX %08x w/h=0/0",
1878                                     sm->usurf->surfaceid);
1879                     }
1880                     else if (event == ICO_WINDOW_MGR_MAP_SURFACE_EVENT_CONTENTS)    {
1881 #if  PERFORMANCE_EVALUATIONS > 0
1882                         if (sm->type != ICO_WINDOW_MGR_MAP_TYPE_SHM)    {
1883                             uifw_perf("SWAP_BUFFER appid=%s surface=%08x CONTENTS",
1884                                       sm->usurf->uclient->appid, sm->usurf->surfaceid);
1885                         }
1886 #endif /*PERFORMANCE_EVALUATIONS*/
1887                         if ((sm->width != width) || (sm->height != height)) {
1888                             event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_RESIZE;
1889                         }
1890                         else    {
1891                             if (sm->interval < 0)   {
1892                                 sm->eventque = 1;
1893                                 event = 0;
1894                             }
1895                             else if (sm->interval > 0)  {
1896                                 dtime = (int)(curtime - sm->lasttime);
1897                                 if (dtime < sm->interval)   {
1898                                     sm->eventque = 1;
1899                                     event = 0;
1900                                 }
1901                             }
1902                         }
1903                     }
1904                 }
1905                 sm->width = width;
1906                 sm->height = height;
1907                 sm->stride = width * 4;
1908                 sm->format = EGL_TEXTURE_RGBA;
1909             }
1910             else    {
1911                 event = 0;
1912             }
1913         }
1914     }
1915
1916     if (event != 0) {
1917         uifw_detail("win_mgr_change_mapsurface: send MAP event(ev=%d surf=%08x type=%d "
1918                     "w/h/s=%d/%d/%d format=%x file=<%s>",
1919                     event, sm->usurf->surfaceid, sm->type,
1920                     sm->width, sm->height, sm->stride, sm->format, sm->filepath);
1921         sm->lasttime = curtime;
1922         sm->eventque = 0;
1923         if ((event != ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR) &&
1924             (event != ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP) &&
1925             (sm->filepath[0] != 0)) {
1926 #if 1       /* weston_layout_takeSurfaceScreenshot(GENIVI) is slowly    */
1927             if (win_mgr_takeSurfaceScreenshot(sm->filepath, sm->usurf,
1928                                               sm->width, sm->height) != 0)
1929 #else       /* weston_layout_takeSurfaceScreenshot(GENIVI) is slowly    */
1930             if (weston_layout_takeSurfaceScreenshot(sm->filepath,
1931                                                     sm->usurf->ivisurf) != 0)
1932 #endif      /* weston_layout_takeSurfaceScreenshot(GENIVI) is slowly    */
1933             {
1934                 uifw_warn("win_mgr_change_mapsurface: surface.%08x image read(%s) Error",
1935                           sm->usurf->surfaceid, sm->filepath);
1936                 event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR;
1937             }
1938             else    {
1939                 uifw_trace("win_mgr_change_mapsurface: surface.%08x image read(%s) OK",
1940                            sm->usurf->surfaceid, sm->filepath);
1941             }
1942         }
1943         ico_window_mgr_send_map_surface(sm->uclient->mgr->resource, event,
1944                                         sm->usurf->surfaceid, sm->type,
1945                                         sm->width, sm->height, sm->stride, sm->format);
1946         if (event == ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR)    {
1947             /* free map table if error  */
1948             wl_list_remove(&sm->surf_link);
1949             wl_list_remove(&sm->map_link);
1950             sm->usurf = (struct uifw_win_surface *)_ico_win_mgr->free_maptable;
1951             _ico_win_mgr->free_maptable = sm;
1952         }
1953     }
1954 }
1955
1956 /*--------------------------------------------------------------------------*/
1957 /**
1958  * @brief   uifw_map_surface: mapped surface buffer to system application
1959  *
1960  * @param[in]   client      Weyland client
1961  * @param[in]   resource    resource of request
1962  * @param[in]   surfaceid   surface id
1963  * @param[in]   framerate   frame rate of surface update(frame/sec)
1964  *                          if over 999, no change
1965  * @param[in]   filepath    surface image file path(if NULL, not create file)
1966  * @return      none
1967  */
1968 /*--------------------------------------------------------------------------*/
1969 static void
1970 uifw_map_surface(struct wl_client *client, struct wl_resource *resource,
1971                  uint32_t surfaceid, int32_t framerate, const char *filepath)
1972 {
1973     struct uifw_win_surface     *usurf;
1974     struct weston_surface       *es;
1975     struct uifw_surface_map     *sm;
1976     struct weston_buffer        *buffer;
1977     struct wl_shm_buffer        *shm_buffer;
1978     struct uifw_client          *uclient;
1979     struct uifw_gl_surface_state *gl_state;
1980     int     maptype;
1981     int     format;
1982
1983     uifw_trace("uifw_map_surface: Enter(surface=%08x,fps=%d,file=%s)",
1984                surfaceid, framerate, filepath ? filepath : "(null)");
1985
1986     uclient = ico_window_mgr_find_uclient(client);
1987     usurf = ico_window_mgr_get_usurf(surfaceid);
1988     if (! usurf)    {
1989         /* surface dose not exist, error        */
1990         ico_window_mgr_send_map_surface(resource, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
1991                                         surfaceid, 1, 0, 0, 0, 0);
1992         uifw_trace("uifw_map_surface: Leave(surface=%08x dose not exist)", surfaceid);
1993         return;
1994     }
1995
1996     /* check if buffered        */
1997     es = usurf->surface;
1998     if (es == NULL) {
1999         /* surface has no buffer, error         */
2000         ico_window_mgr_send_map_surface(resource, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
2001                                         surfaceid, 2, 0, 0, 0, 0);
2002         uifw_trace("uifw_map_surface: Leave(surface(%08x) has no surface)", surfaceid);
2003         return;
2004     }
2005     buffer = es->buffer_ref.buffer;
2006
2007     /* check buffer type        */
2008     gl_state = (struct uifw_gl_surface_state *)es->renderer_state;
2009     if (gl_state == NULL)   {
2010         ico_window_mgr_send_map_surface(resource,
2011                                         ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
2012                                         surfaceid, 3, 0, 0, 0, 0);
2013         uifw_trace("uifw_map_surface: Leave(surface(%08x) has no gl_state)", surfaceid);
2014         return;
2015     }
2016     else if (gl_state->buffer_type == BUFFER_TYPE_SHM)  {
2017         maptype = -1;
2018         format = 0xff;
2019         if (ico_ivi_optionflag() & ICO_IVI_OPTION_SUPPORT_SHM)  {
2020             if (buffer != NULL) {
2021                 shm_buffer = wl_shm_buffer_get(buffer->resource);
2022                 if (shm_buffer) {
2023                     format = wl_shm_buffer_get_format(shm_buffer);
2024                     uifw_detail("uifw_map_surface: %08x shm_buffer type %x",
2025                                 surfaceid, format);
2026                     if (format == WL_SHM_FORMAT_ARGB8888)   {
2027                         maptype = ICO_WINDOW_MGR_MAP_TYPE_SHM;
2028                     }
2029                 }
2030             }
2031             else    {
2032                 maptype = ICO_WINDOW_MGR_MAP_TYPE_SHM;
2033             }
2034         }
2035         if (maptype < 0)    {
2036             ico_window_mgr_send_map_surface(resource,
2037                                             ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
2038                                             surfaceid, 4, 0, 0, 0, 0);
2039             uifw_trace("uifw_map_surface: Leave(surface(%08x) not support shm_buffer(%x))",
2040                        surfaceid, format);
2041             return;
2042         }
2043     }
2044     else    {
2045         maptype = ICO_WINDOW_MGR_MAP_TYPE_EGL;
2046     }
2047
2048     /* maximum framerate        */
2049     if (framerate >= 0) {
2050         if (maptype == ICO_WINDOW_MGR_MAP_TYPE_EGL) {
2051             if (framerate > 30)     framerate = 30;
2052         }
2053         else    {
2054             if ((framerate <= 0) || (framerate > 5))    framerate = 5;
2055         }
2056     }
2057
2058     /* check same surface       */
2059     wl_list_for_each(sm, &usurf->surf_map, surf_link) {
2060         if ((sm->usurf == usurf) && (sm->uclient == uclient))   {
2061             break;
2062         }
2063     }
2064
2065     if (&sm->surf_link == &usurf->surf_map) {
2066         /* create map table         */
2067         sm = _ico_win_mgr->free_maptable;
2068         if (sm) {
2069             _ico_win_mgr->free_maptable = (struct uifw_surface_map *)sm->usurf;
2070         }
2071         else    {
2072             sm = (struct uifw_surface_map *)malloc(sizeof(struct uifw_surface_map));
2073             if (! sm)   {
2074                 ico_window_mgr_send_map_surface(resource,
2075                                                 ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
2076                                                 surfaceid, 5, 0, 0, 0, 0);
2077                 uifw_trace("uifw_map_surface: Leave(malloc error)");
2078                 return;
2079             }
2080         }
2081         memset(sm, 0, sizeof(struct uifw_surface_map));
2082
2083         wl_list_init(&sm->map_link);
2084         wl_list_init(&sm->surf_link);
2085         sm->usurf = usurf;
2086         sm->uclient = uclient;
2087         sm->type = maptype;
2088         sm->framerate = framerate;
2089         if (framerate < 0)  sm->interval = -1;
2090         else                sm->interval = (1000 / sm->framerate) - 1;
2091         wl_list_insert(_ico_win_mgr->map_list.next, &sm->map_link);
2092         wl_list_insert(usurf->surf_map.prev, &sm->surf_link);
2093     }
2094     else    {
2095         /* change frame rate    */
2096         uifw_trace("uifw_map_surface: Leave(chagne frame rate %d->%d",
2097                    sm->framerate, framerate);
2098         if (sm->framerate != framerate) {
2099             sm->framerate = framerate;
2100             if (framerate < 0)  sm->interval = -1;
2101             else                sm->interval = (1000 / sm->framerate) - 1;
2102             win_mgr_change_mapsurface(sm, 0, weston_compositor_get_time());
2103         }
2104         return;
2105     }
2106
2107     memset(sm->filepath, 0, ICO_IVI_FILEPATH_LENGTH);
2108     if ((filepath != NULL) && (*filepath != 0) && (*filepath != ' '))   {
2109         strncpy(sm->filepath, filepath, ICO_IVI_FILEPATH_LENGTH-1);
2110     }
2111
2112     if (buffer != NULL) {
2113         sm->width = buffer->width;
2114         sm->height = buffer->height;
2115         if (maptype != ICO_WINDOW_MGR_MAP_TYPE_EGL) {
2116             sm->stride = sm->width * 4;
2117             sm->format = EGL_TEXTURE_RGBA;
2118             if ((sm->width > 0) && (sm->height > 0))    {
2119                 sm->initflag = 1;
2120             }
2121             uifw_debug("uifw_map_surface: map type=%d,surface=%08x,fps=%d,w/h=%d/%d",
2122                        maptype, surfaceid, framerate, buffer->width, buffer->height);
2123         }
2124         else    {
2125             if (wl_resource_get_user_data((struct wl_resource *)buffer->legacy_buffer)
2126                 != NULL)    {
2127                 sm->format = EGL_TEXTURE_RGBA;
2128                 if ((sm->width > 0) && (sm->height > 0) && (sm->stride > 0) &&
2129                     (gl_state != NULL))  {
2130                     sm->initflag = 1;
2131                 }
2132                 uifw_debug("uifw_map_surface: map EGL surface=%08x,fps=%d,w/h=%d/%d",
2133                            surfaceid, framerate, buffer->width, buffer->height);
2134             }
2135             else    {
2136                 uifw_debug("uifw_map_surface: map EGL but no buffer surface=%08x,fps=%d",
2137                            surfaceid, framerate);
2138             }
2139         }
2140     }
2141     else if (maptype != ICO_WINDOW_MGR_MAP_TYPE_EGL)    {
2142         sm->width = es->width;
2143         sm->height = es->height;
2144         sm->stride = sm->width * 4;
2145         sm->format = EGL_TEXTURE_RGBA;
2146         if ((sm->width > 0) && (sm->height > 0))    {
2147             sm->initflag = 1;
2148         }
2149         uifw_debug("uifw_map_surface: map type=%d,surface=%08x,fps=%d,w/h=%d/%d",
2150                    maptype, surfaceid, framerate, sm->width, sm->height);
2151     }
2152     else    {
2153         uifw_debug("uifw_map_surface: map EGL but no buffer surface=%08x,fps=%d",
2154                    surfaceid, framerate);
2155     }
2156
2157     /* send map event                       */
2158     if (sm->initflag)   {
2159         win_mgr_change_mapsurface(sm, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_MAP,
2160                                   weston_compositor_get_time());
2161     }
2162     uifw_trace("uifw_map_surface: Leave");
2163 }
2164
2165 /*--------------------------------------------------------------------------*/
2166 /**
2167  * @brief   uifw_unmap_surface: unmap surface buffer
2168  *
2169  * @param[in]   client      Weyland client
2170  * @param[in]   resource    resource of request
2171  * @param[in]   surfaceid   surface id
2172  * @return      none
2173  */
2174 /*--------------------------------------------------------------------------*/
2175 static void
2176 uifw_unmap_surface(struct wl_client *client, struct wl_resource *resource,
2177                    uint32_t surfaceid)
2178 {
2179     struct uifw_win_surface *usurf;
2180     struct uifw_surface_map *sm, *sm_tmp;
2181     struct uifw_client      *uclient;
2182
2183     uifw_trace("uifw_unmap_surface: Enter(surface=%08x)", surfaceid);
2184
2185     usurf = ico_window_mgr_get_usurf(surfaceid);
2186     if (! usurf)    {
2187         /* surface dose not exist, error        */
2188         uifw_trace("uifw_unmap_surface: Leave(surface=%08x dose not exist)", surfaceid);
2189         return;
2190     }
2191     if (client) {
2192         uclient = ico_window_mgr_find_uclient(client);
2193         if ((! uclient) || (! uclient->mgr))    {
2194             /* client dose not exist, error         */
2195             uifw_trace("uifw_unmap_surface: Leave(client=%08x dose not exist)", (int)client);
2196             return;
2197         }
2198     }
2199     else    {
2200         uclient = NULL;
2201         wl_list_for_each (sm, &usurf->surf_map, surf_link) {
2202             if (sm->uclient->mgr != NULL) {
2203                 uifw_trace("uifw_unmap_surface: send UNMAP event(ev=%d surf=%08x "
2204                            "w/h/s=%d/%d/%d format=%x",
2205                            ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP, surfaceid,
2206                            sm->width, sm->height, sm->stride, sm->format);
2207                 ico_window_mgr_send_map_surface(sm->uclient->mgr->resource,
2208                                                 ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP,
2209                                                 surfaceid, sm->type, sm->width,
2210                                                 sm->height, sm->stride, sm->format);
2211             }
2212         }
2213     }
2214     wl_list_for_each_safe (sm, sm_tmp, &usurf->surf_map, surf_link) {
2215         if (((uclient != NULL) && (sm->uclient != uclient)))   continue;
2216         wl_list_remove(&sm->surf_link);
2217         wl_list_remove(&sm->map_link);
2218         if (sm->filepath[0])    {
2219             unlink(sm->filepath);
2220         }
2221         sm->usurf = (struct uifw_win_surface *)_ico_win_mgr->free_maptable;
2222         _ico_win_mgr->free_maptable = sm;
2223     }
2224     uifw_trace("uifw_unmap_surface: Leave");
2225 }
2226
2227 /*--------------------------------------------------------------------------*/
2228 /**
2229  * @brief   uifw_layout_surface: direct layout surface
2230  *
2231  * @param[in]   client      Weyland client
2232  * @param[in]   resource    resource of request
2233  * @param[in]   surfaceid   surface id
2234  * @param[in]   layerid     layer id
2235  * @param[in]   x           X
2236  * @param[in]   y           Y
2237  * @param[in]   width       width
2238  * @param[in]   height      height
2239  * @param[in]   visible     visiblity
2240  * @return      none
2241  */
2242 /*--------------------------------------------------------------------------*/
2243 static void
2244 uifw_layout_surface(struct wl_client *client, struct wl_resource *resource,
2245                     uint32_t surfaceid, uint32_t layerid, int x, int y,
2246                     int width, int height, int visible)
2247 {
2248     struct uifw_win_surface     *usurf;
2249     struct weston_layout_layer  *layout_layer;
2250     int32_t                     position[2];
2251     uint32_t                    dimension[2];
2252
2253     uifw_trace("uifw_layout_surface: Enter(surf=%08x,layer=%d,x/y=%d/%d,w/h=%d,%d,vis=%d)",
2254                surfaceid, layerid, x, y, width, height, visible);
2255
2256     usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
2257     if (! usurf)    {
2258         /* surface dose not exist, error        */
2259         uifw_trace("uifw_layout_surface: Leave(surface=%08x dose not exist)", surfaceid);
2260         return;
2261     }
2262     if (layerid)    {
2263         layout_layer = weston_layout_getLayerFromId(layerid);
2264         if (! layout_layer) {
2265             /* layer dose not exist                 */
2266             uifw_trace("uifw_layout_surface: Leave(layer=%d dose not exist)", layerid);
2267             return;
2268         }
2269         if (weston_layout_layerAddSurface(layout_layer, usurf->ivisurf) == 0)   {
2270             if (weston_layout_layerSetVisibility(layout_layer, 1) != 0) {
2271                 uifw_warn("uifw_layout_surface: layer(%d) visible Error", layerid);
2272             }
2273         }
2274         else    {
2275             uifw_warn("uifw_layout_surface: can not add surface(%08x) to layer(%d)",
2276                       usurf->surfaceid, layerid);
2277         }
2278     }
2279
2280     if ((x >= 0) && (y >= 0) && (width > 0) && (height > 0))    {
2281         if (weston_layout_surfaceSetSourceRectangle(usurf->ivisurf,
2282                                                     0, 0, width, height) != 0)  {
2283             uifw_warn("uifw_layout_surface: surface(%08x) can not set source",
2284                       usurf->surfaceid);
2285         }
2286         if (weston_layout_surfaceSetDestinationRectangle(usurf->ivisurf,
2287                                                          x, y, width, height) != 0) {
2288             uifw_warn("uifw_layout_surface: surface(%08x) can not set destination",
2289                       usurf->surfaceid);
2290         }
2291     }
2292     else if ((x >= 0) && (y >= 0))  {
2293         position[0] = x;
2294         position[1] = y;
2295         if (weston_layout_surfaceSetPosition(usurf->ivisurf, position) != 0)    {
2296             uifw_warn("uifw_layout_surface: surface(%08x) can not set source position",
2297                       usurf->surfaceid);
2298         }
2299     }
2300     else if ((width > 0) && (height > 0))   {
2301         if (weston_layout_surfaceSetSourceRectangle(usurf->ivisurf,
2302                                                     0, 0, width, height) != 0)  {
2303             uifw_warn("uifw_layout_surface: surface(%08x) can not set source",
2304                       usurf->surfaceid);
2305         }
2306         dimension[0] = width;
2307         dimension[1] = height;
2308         if (weston_layout_surfaceSetDimension(usurf->ivisurf, dimension) != 0)  {
2309             uifw_warn("uifw_layout_surface: surface(%08x) can not set destination size",
2310                       usurf->surfaceid);
2311         }
2312     }
2313     if (visible >= 0)   {
2314         if (weston_layout_surfaceSetVisibility(usurf->ivisurf, visible) != 0)   {
2315             uifw_warn("uifw_layout_surface: surface(%08x) can not set visibility",
2316                       usurf->surfaceid);
2317         }
2318     }
2319     if (weston_layout_commitChanges() != 0) {
2320         uifw_warn("uifw_layout_surface: surface(%08x) commit Error", usurf->surfaceid);
2321     }
2322     uifw_trace("uifw_layout_surface: Leave");
2323 }
2324
2325 /*--------------------------------------------------------------------------*/
2326 /**
2327  * @brief   win_mgr_destroy_surface: surface destroy
2328  *
2329  * @param[in]   surface     Weston surface
2330  * @return      none
2331  */
2332 /*--------------------------------------------------------------------------*/
2333 static void
2334 win_mgr_destroy_surface(struct weston_surface *surface)
2335 {
2336     struct uifw_win_surface *usurf;
2337     struct uifw_win_surface *phash;
2338     struct uifw_win_surface *bhash;
2339     uint32_t    hash;
2340
2341     usurf = find_uifw_win_surface_by_ws(surface);
2342     if (! usurf) {
2343         uifw_trace("win_mgr_destroy_surface: UIFW surface Not Exist");
2344         return;
2345     }
2346     uifw_trace("win_mgr_destroy_surface: Enter(%08x) %08x", (int)surface, usurf->surfaceid);
2347
2348     /* remove notification listener */
2349     if (weston_layout_surfaceRemoveNotification(usurf->ivisurf) != 0)   {
2350         uifw_warn("win_mgr_destroy_surface: weston_layout_surfaceRemoveNotification(%08x)"
2351                   " Error", usurf->surfaceid);
2352     }
2353
2354     /* destory input region         */
2355     if (win_mgr_hook_destory)   {
2356         (*win_mgr_hook_destory)(usurf);
2357     }
2358
2359     /* unmap surface                */
2360     if (&usurf->surf_map != usurf->surf_map.next)   {
2361         uifw_unmap_surface(NULL, NULL, usurf->surfaceid);
2362     }
2363
2364     /* destroy animation extenson   */
2365     if (win_mgr_hook_animation) {
2366         (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_DESTROY, (void *)usurf);
2367     }
2368
2369     /* remove destroy listener      */
2370     wl_list_remove(&usurf->surface_destroy_listener.link);
2371
2372     /* send destroy event to controller */
2373     win_mgr_send_event(ICO_WINDOW_MGR_DESTROY_SURFACE, usurf->surfaceid, 0);
2374
2375     /* delete from cleint list      */
2376     wl_list_remove(&usurf->client_link);
2377
2378     /* delete from hash table       */
2379     hash = MAKE_IDHASH(usurf->surfaceid);
2380     phash = _ico_win_mgr->idhash[hash];
2381     bhash = NULL;
2382     while ((phash) && (phash != usurf)) {
2383         bhash = phash;
2384         phash = phash->next_idhash;
2385     }
2386     if (bhash)  {
2387         bhash->next_idhash = usurf->next_idhash;
2388     }
2389     else    {
2390         _ico_win_mgr->idhash[hash] = usurf->next_idhash;
2391     }
2392
2393     hash = MAKE_WSHASH(usurf->surface);
2394     phash = _ico_win_mgr->wshash[hash];
2395     bhash = NULL;
2396     while ((phash) && (phash != usurf)) {
2397         bhash = phash;
2398         phash = phash->next_wshash;
2399     }
2400     if (bhash)  {
2401         bhash->next_wshash = usurf->next_wshash;
2402     }
2403     else    {
2404         _ico_win_mgr->wshash[hash] = usurf->next_wshash;
2405     }
2406
2407     free(usurf);
2408     uifw_trace("win_mgr_destroy_surface: Leave(OK)");
2409 }
2410
2411 /*--------------------------------------------------------------------------*/
2412 /**
2413  * @brief   win_mgr_surface_destroy: weston_surface destroy listener
2414  *
2415  * @param[in]   listener    listener
2416  * @param[in]   data        data (unused)
2417  * @return      none
2418  */
2419 /*--------------------------------------------------------------------------*/
2420 static void
2421 win_mgr_surface_destroy(struct wl_listener *listener, void *data)
2422 {
2423     struct uifw_win_surface *usurf = container_of(listener, struct uifw_win_surface,
2424                                                   surface_destroy_listener);
2425
2426     uifw_trace("win_mgr_surface_destroy: Enter(%08x)", usurf->surfaceid);
2427
2428     win_mgr_destroy_surface(usurf->surface);
2429
2430     uifw_trace("win_mgr_surface_destroy: Leave");
2431 }
2432
2433 /*--------------------------------------------------------------------------*/
2434 /**
2435  * @brief   win_mgr_takeSurfaceScreenshot: take screen image pixel
2436  *
2437  * @param[in]   filename    output file path
2438  * @param[in]   usurf       UIFW surface
2439  * @param[in]   width       surface width
2440  * @param[in]   height      surface height
2441  * @return      result
2442  * @retval      0           success
2443  * @retval      -1          error
2444  */
2445 /*--------------------------------------------------------------------------*/
2446 static int
2447 win_mgr_takeSurfaceScreenshot(const char *filename, struct uifw_win_surface *usurf,
2448                               int width, int height)
2449 {
2450     int     datasize;
2451     int     bufsize;
2452     int     bitperpixel;
2453     int     bmphead_size;
2454     int     fd;
2455     int     pathlen;
2456     int     linesize;
2457     char    *sp, *dp;
2458     char    *wkbuf = NULL;
2459 #pragma pack(push, 1)
2460     struct _bmphead {
2461         short   magic;
2462         uint32_t fullsize;
2463         short   res1;
2464         short   res2;
2465         int     offset;
2466         int     headsize;
2467         int     width;
2468         int     height;
2469         short   planes;
2470         short   bitperpixel;
2471         int     compress;
2472         int     datasize;
2473         int     xp;
2474         int     yp;
2475         int     colors;
2476         int     colors2;
2477     }       *bmphead;
2478 #pragma pack(pop)
2479
2480     uifw_trace("win_mgr_takeSurfaceScreenshot: Enter(%08x) <%s>",
2481                usurf->surfaceid, filename);
2482
2483     if (! _ico_win_mgr->compositor->renderer->read_surface_pixels)  {
2484         uifw_trace("win_mgr_takeSurfaceScreenshot: Leave(no read_surface_pixels)");
2485         return -1;
2486     }
2487     bitperpixel = PIXMAN_FORMAT_BPP(_ico_win_mgr->compositor->read_format);
2488     bmphead_size = ((sizeof(struct _bmphead) + 31) / 32) * 32;
2489     datasize = (width * bitperpixel / 8) * height;
2490     bufsize = datasize + bmphead_size;
2491     if ((_ico_win_mgr->pixel_readbuf != NULL) &&
2492         (bufsize > _ico_win_mgr->pixel_readsize))   {
2493         free(_ico_win_mgr->pixel_readbuf);
2494         _ico_win_mgr->pixel_readbuf = NULL;
2495     }
2496     if (_ico_win_mgr->pixel_readbuf == NULL)    {
2497         _ico_win_mgr->pixel_readbuf = malloc(bufsize);
2498         if (! _ico_win_mgr->pixel_readbuf)  {
2499             uifw_error("win_mgr_takeSurfaceScreenshot: Leave(can not allocate buffer)");
2500             return -1;
2501         }
2502         _ico_win_mgr->pixel_readsize = bufsize;
2503     }
2504     pathlen = strlen(filename);
2505     if ((pathlen >= 4) && (strcmp(&filename[pathlen-4], ".bmp") == 0))  {
2506         /* BMP format   */
2507         wkbuf = malloc(datasize);
2508         if (! wkbuf)    {
2509             uifw_error("win_mgr_takeSurfaceScreenshot: Leave(can not allocate buffer)");
2510             return -1;
2511         }
2512     }
2513     fd = open(filename, O_WRONLY|O_CREAT, 0644);
2514     if (fd < 0) {
2515         uifw_warn("win_mgr_takeSurfaceScreenshot: Leave(file<%s> open Error<%d>)",
2516                   filename, errno);
2517         free(wkbuf);
2518         return -1;
2519     }
2520
2521     uifw_detail("win_mgr_takeSurfaceScreenshot: call read_surface_pixels(%d,%d)",
2522                 width, height);
2523     if ((*(_ico_win_mgr->compositor->
2524             renderer->read_surface_pixels))(usurf->surface, PIXMAN_a8r8g8b8,
2525                                             wkbuf ? wkbuf :
2526                                               (_ico_win_mgr->pixel_readbuf + bmphead_size),
2527                                             0, 0, width, height) != 0)  {
2528         close(fd);
2529         uifw_warn("win_mgr_takeSurfaceScreenshot: Leave(read_surface_pixels Error)");
2530         free(wkbuf);
2531         return -1;
2532     }
2533     uifw_detail("win_mgr_takeSurfaceScreenshot: end  read_surface_pixels");
2534
2535     if (wkbuf)  {
2536         /* BMP format   */
2537         bmphead = (struct _bmphead *)(_ico_win_mgr->pixel_readbuf +
2538                                       (bmphead_size - sizeof(struct _bmphead)));
2539         memset(bmphead, 0, sizeof(struct _bmphead));
2540         bmphead->magic = 0x4d42;
2541         bmphead->fullsize = sizeof(struct _bmphead) + datasize;
2542         bmphead->offset = 54;
2543         bmphead->headsize = 40;
2544         bmphead->width = width;
2545         bmphead->height = height;
2546         bmphead->planes = 1;
2547         bmphead->bitperpixel = bitperpixel;
2548         bmphead->compress = 0;
2549         bmphead->datasize = datasize;
2550         bmphead->xp = 100000;
2551         bmphead->yp = 100000;
2552
2553         /* invert Y     */
2554         linesize = width * bitperpixel / 8;
2555         sp = wkbuf;
2556         dp = _ico_win_mgr->pixel_readbuf + bmphead_size + (linesize * (height-1));
2557         for (pathlen = 0; pathlen < height; pathlen++)  {
2558             memcpy(dp, sp, linesize);
2559             sp += linesize;
2560             dp -= linesize;
2561         }
2562         free(wkbuf);
2563
2564         if (write(fd, bmphead, sizeof(struct _bmphead) + datasize) < 0) {
2565             uifw_warn("win_mgr_takeSurfaceScreenshot: Leave(file<%s> write Error<%d>)",
2566                       filename, errno);
2567             close(fd);
2568             return -1;
2569         }
2570     }
2571     else    {
2572         /* Binary format    */
2573         if (write(fd, _ico_win_mgr->pixel_readbuf + bmphead_size, datasize) < 0)    {
2574             uifw_warn("win_mgr_takeSurfaceScreenshot: Leave(file<%s> write Error<%d>)",
2575                       filename, errno);
2576             close(fd);
2577             return -1;
2578         }
2579     }
2580     close(fd);
2581
2582     uifw_trace("win_mgr_takeSurfaceScreenshot: Leave");
2583     return 0;
2584 }
2585
2586 /*--------------------------------------------------------------------------*/
2587 /**
2588  * @brief   bind_ico_win_mgr: bind Multi Window Manager from client
2589  *
2590  * @param[in]   client      client
2591  * @param[in]   data        user data(unused)
2592  * @param[in]   version     protocol version(unused)
2593  * @param[in]   id          client object id
2594  * @return      none
2595  */
2596 /*--------------------------------------------------------------------------*/
2597 static void
2598 bind_ico_win_mgr(struct wl_client *client,
2599                  void *data, uint32_t version, uint32_t id)
2600 {
2601     struct wl_resource  *add_resource;
2602     struct uifw_manager *mgr;
2603     struct uifw_client  *uclient;
2604
2605     uifw_trace("bind_ico_win_mgr: Enter(client=%08x, id=%x)", (int)client, (int)id);
2606
2607     add_resource = wl_resource_create(client, &ico_window_mgr_interface, 1, id);
2608     if (add_resource)   {
2609         wl_resource_set_implementation(add_resource, &ico_window_mgr_implementation,
2610                                        _ico_win_mgr, unbind_ico_win_mgr);
2611     }
2612
2613     /* Create client management tabel       */
2614     uclient = ico_window_mgr_find_uclient(client);
2615     if (! uclient)  {
2616         win_mgr_bind_client(client, NULL);
2617         uclient = ico_window_mgr_find_uclient(client);
2618     }
2619
2620     /* Manager                              */
2621     mgr = (struct uifw_manager *)malloc(sizeof(struct uifw_manager));
2622     if (! mgr)  {
2623         uifw_error("bind_ico_win_mgr: Error, No Memory");
2624         return;
2625     }
2626     memset(mgr, 0, sizeof(struct uifw_manager));
2627     mgr->resource = add_resource;
2628     if (uclient)    {
2629         uclient->mgr = mgr;
2630     }
2631     wl_list_insert(&_ico_win_mgr->manager_list, &mgr->link);
2632
2633     uifw_trace("bind_ico_win_mgr: Leave");
2634 }
2635
2636 /*--------------------------------------------------------------------------*/
2637 /**
2638  * @brief   unbind_ico_win_mgr: unbind Multi Window Manager from client
2639  *
2640  * @param[in]   resource    client resource
2641  * @return      none
2642  */
2643 /*--------------------------------------------------------------------------*/
2644 static void
2645 unbind_ico_win_mgr(struct wl_resource *resource)
2646 {
2647     struct uifw_manager *mgr, *itmp;
2648
2649     uifw_trace("unbind_ico_win_mgr: Enter");
2650
2651     /* Remove manager from manager list */
2652     wl_list_for_each_safe (mgr, itmp, &_ico_win_mgr->manager_list, link)    {
2653         if (mgr->resource == resource) {
2654             wl_list_remove(&mgr->link);
2655             free(mgr);
2656         }
2657     }
2658     uifw_trace("unbind_ico_win_mgr: Leave");
2659 }
2660
2661 /*--------------------------------------------------------------------------*/
2662 /**
2663  * @brief   ico_window_mgr_get_uclient: get UIFW client table
2664  *
2665  * @param[in]   appid       application Id
2666  * @return      UIFW client table
2667  * @retval      !=NULL      success(UIFW client table address)
2668  * @retval      = NULL      error(appid not exist)
2669  */
2670 /*--------------------------------------------------------------------------*/
2671 WL_EXPORT   struct uifw_client *
2672 ico_window_mgr_get_uclient(const char *appid)
2673 {
2674     struct uifw_client *uclient;
2675
2676     wl_list_for_each (uclient, &_ico_win_mgr->client_list, link)    {
2677         if (strcmp(uclient->appid, appid) == 0) {
2678             return uclient;
2679         }
2680     }
2681     return NULL;
2682 }
2683
2684 /*--------------------------------------------------------------------------*/
2685 /**
2686  * @brief   ico_window_mgr_get_client_usurf: get client UIFW surface table
2687  *
2688  * @param[in]   target      surface window name and application Id(winname@appid)
2689  * @return      UIFW surface table
2690  * @retval      !=NULL      success(UIFW surface table address)
2691  * @retval      = NULL      error(appid or winname not exist)
2692  */
2693 /*--------------------------------------------------------------------------*/
2694 WL_EXPORT   struct uifw_win_surface *
2695 ico_window_mgr_get_client_usurf(const char *target)
2696 {
2697     struct uifw_client      *uclient;
2698     struct uifw_win_surface *usurf;
2699     int     i, j;
2700     char    winname[ICO_IVI_WINNAME_LENGTH];
2701     char    appid[ICO_IVI_APPID_LENGTH];
2702
2703     /* get window name and application id   */
2704     j = 0;
2705     for (i = 0; target[i]; i++) {
2706         if (target[i] == '@')   {
2707             if (target[i+1] != '@') break;
2708             i ++;
2709         }
2710         if (j < (ICO_IVI_WINNAME_LENGTH-1)) {
2711             winname[j++] = target[i];
2712         }
2713     }
2714     winname[j] = 0;
2715     if (target[i] == '@')   {
2716         i ++;
2717     }
2718     else    {
2719         winname[0] = 0;
2720         i = 0;
2721     }
2722     j = 0;
2723     for ( ; target[i]; i++) {
2724         if ((target[i] == '@') && (target[i+1] == '@')) i ++;
2725         if (j < (ICO_IVI_APPID_LENGTH-1))  {
2726             appid[j++] = target[i];
2727         }
2728     }
2729     appid[j] = 0;
2730     uifw_debug("ico_window_mgr_get_client_usurf: target=<%s> appid=<%s> win=<%s>",
2731                target, appid, winname);
2732
2733     wl_list_for_each (uclient, &_ico_win_mgr->client_list, link)    {
2734         if (strcmp(uclient->appid, appid) == 0) {
2735             wl_list_for_each (usurf, &uclient->surface_link, client_link)   {
2736                 if ((winname[0] == 0) ||
2737                     (strcmp(winname, usurf->winname) == 0)) {
2738                     return usurf;
2739                 }
2740             }
2741         }
2742     }
2743     return NULL;
2744 }
2745
2746 /*--------------------------------------------------------------------------*/
2747 /**
2748  * @brief   ico_window_mgr_set_hook_animation: set animation hook routine
2749  *
2750  * @param[in]   hook_animation  hook routine
2751  * @return      none
2752  */
2753 /*--------------------------------------------------------------------------*/
2754 WL_EXPORT   void
2755 ico_window_mgr_set_hook_animation(int (*hook_animation)(const int op, void *data))
2756 {
2757     win_mgr_hook_animation = hook_animation;
2758 }
2759
2760 /*--------------------------------------------------------------------------*/
2761 /**
2762  * @brief   ico_window_mgr_set_hook_change: set input region hook routine
2763  *
2764  * @param[in]   hook_change     hook routine
2765  * @return      none
2766  */
2767 /*--------------------------------------------------------------------------*/
2768 WL_EXPORT   void
2769 ico_window_mgr_set_hook_change(void (*hook_change)(struct uifw_win_surface *usurf))
2770 {
2771     win_mgr_hook_change = hook_change;
2772 }
2773
2774 /*--------------------------------------------------------------------------*/
2775 /**
2776  * @brief   ico_window_mgr_set_hook_destory: set input region hook routine
2777  *
2778  * @param[in]   hook_destroy    hook routine
2779  * @return      none
2780  */
2781 /*--------------------------------------------------------------------------*/
2782 WL_EXPORT   void
2783 ico_window_mgr_set_hook_destory(void (*hook_destroy)(struct uifw_win_surface *usurf))
2784 {
2785     win_mgr_hook_destory = hook_destroy;
2786 }
2787
2788 /*--------------------------------------------------------------------------*/
2789 /**
2790  * @brief   ico_window_mgr_set_hook_inputregion: set input region hook routine
2791  *
2792  * @param[in]   hook_inputregion    hook routine
2793  * @return      none
2794  */
2795 /*--------------------------------------------------------------------------*/
2796 WL_EXPORT   void
2797 ico_window_mgr_set_hook_inputregion(
2798         void (*hook_inputregion)(int set, struct uifw_win_surface *usurf,
2799                                  int32_t x, int32_t y, int32_t width,
2800                                  int32_t height, int32_t hotspot_x, int32_t hotspot_y,
2801                                  int32_t cursor_x, int32_t cursor_y, int32_t cursor_width,
2802                                  int32_t cursor_height, uint32_t attr))
2803 {
2804     win_mgr_hook_inputregion = hook_inputregion;
2805 }
2806
2807 /*--------------------------------------------------------------------------*/
2808 /**
2809  * @brief   module_init: initialize ico_window_mgr
2810  *                       this function called from ico_pluign_loader
2811  *
2812  * @param[in]   es          weston compositor
2813  * @param[in]   argc        number of arguments(unused)
2814  * @param[in]   argv        argument list(unused)
2815  * @return      result
2816  * @retval      0           sccess
2817  * @retval      -1          error
2818  */
2819 /*--------------------------------------------------------------------------*/
2820 WL_EXPORT   int
2821 module_init(struct weston_compositor *ec, int *argc, char *argv[])
2822 {
2823     int     nodeId;
2824     int     i;
2825     int     idx;
2826     struct weston_output *output;
2827     struct weston_config_section *section;
2828     char    *displayno = NULL;
2829     char    *p;
2830     struct wl_event_loop *loop;
2831
2832     uifw_info("ico_window_mgr: Enter(module_init)");
2833
2834     /* get ivi debug level                      */
2835     section = weston_config_get_section(ec->config, "ivi-option", NULL, NULL);
2836     if (section)    {
2837         weston_config_section_get_int(section, "flag", &_ico_ivi_option_flag, 0);
2838         weston_config_section_get_int(section, "log", &_ico_ivi_debug_level, 3);
2839     }
2840
2841     /* get display number                       */
2842     section = weston_config_get_section(ec->config, "ivi-display", NULL, NULL);
2843     if (section)    {
2844         weston_config_section_get_string(section, "displayno", &displayno, NULL);
2845     }
2846
2847     /* get animation default                    */
2848     section = weston_config_get_section(ec->config, "ivi-animation", NULL, NULL);
2849     if (section)    {
2850         weston_config_section_get_string(section, "default", &_ico_ivi_animation_name, NULL);
2851         weston_config_section_get_int(section, "time", &_ico_ivi_animation_time, 500);
2852     }
2853     if (_ico_ivi_animation_name == NULL)
2854         _ico_ivi_animation_name = (char *)"fade";
2855     if (_ico_ivi_animation_time < 100)  _ico_ivi_animation_time = 500;
2856
2857     /* create ico_window_mgr management table   */
2858     _ico_win_mgr = (struct ico_win_mgr *)malloc(sizeof(struct ico_win_mgr));
2859     if (_ico_win_mgr == NULL)   {
2860         uifw_error("ico_window_mgr: malloc failed");
2861         return -1;
2862     }
2863
2864     memset(_ico_win_mgr, 0, sizeof(struct ico_win_mgr));
2865
2866     _ico_win_mgr->compositor = ec;
2867
2868     uifw_trace("ico_window_mgr: wl_global_create(bind_ico_win_mgr)");
2869     if (wl_global_create(ec->wl_display, &ico_window_mgr_interface, 1,
2870                          _ico_win_mgr, bind_ico_win_mgr) == NULL)  {
2871         uifw_error("ico_window_mgr: Error(wl_global_create)");
2872         return -1;
2873     }
2874
2875     wl_list_init(&_ico_win_mgr->client_list);
2876     wl_list_init(&_ico_win_mgr->manager_list);
2877     wl_list_init(&_ico_win_mgr->map_list);
2878     _ico_win_mgr->free_maptable = NULL;
2879
2880     /* create display list                  */
2881     if (displayno != NULL)   {
2882         p = displayno;
2883     }
2884     else    {
2885         p = NULL;
2886     }
2887     _ico_num_nodes = 0;
2888     wl_list_for_each (output, &ec->output_list, link) {
2889         wl_list_init(&_ico_win_mgr->map_animation[_ico_num_nodes].link);
2890         _ico_win_mgr->map_animation[_ico_num_nodes].frame = win_mgr_check_mapsurface;
2891         wl_list_insert(output->animation_list.prev,
2892                        &_ico_win_mgr->map_animation[_ico_num_nodes].link);
2893         _ico_num_nodes++;
2894         if (_ico_num_nodes >= ICO_IVI_MAX_DISPLAY)   break;
2895     }
2896     memset(&_ico_node_table[0], 0, sizeof(_ico_node_table));
2897     i = 0;
2898     wl_list_for_each (output, &ec->output_list, link) {
2899         p = strtok(p, ",");
2900         if (p)  {
2901             idx = strtol(p, (char **)0, 0);
2902             uifw_trace("ico_window_mgr: config Display.%d is weston display.%d", i, idx);
2903             p = NULL;
2904             if ((idx < 0) || (idx >= _ico_num_nodes))   {
2905                 idx = i;
2906             }
2907         }
2908         else    {
2909             idx = i;
2910         }
2911         if (_ico_node_table[idx].node)  {
2912             for (idx = 0; idx < _ico_num_nodes; idx++)  {
2913                 if (_ico_node_table[idx].node == 0) break;
2914             }
2915             if (idx >= _ico_num_nodes)  {
2916                 uifw_error("ico_window_mgr: number of display overflow");
2917                 idx = 0;
2918             }
2919         }
2920         _ico_node_table[idx].node = idx + 0x100;
2921         _ico_node_table[idx].displayno = i;
2922         _ico_node_table[idx].output = output;
2923         _ico_node_table[idx].disp_x = output->x;
2924         _ico_node_table[idx].disp_y = output->y;
2925         _ico_node_table[idx].disp_width = output->width;
2926         _ico_node_table[idx].disp_height = output->height;
2927         i ++;
2928         if (i >= _ico_num_nodes) break;
2929     }
2930     idx = 0;
2931     for (i = 0; i < _ico_num_nodes; i++)    {
2932         _ico_node_table[i].node &= 0x0ff;
2933         uifw_info("ico_window_mgr: Display.%d no=%d x/y=%d/%d w/h=%d/%d",
2934                   i, _ico_node_table[i].displayno,
2935                   _ico_node_table[i].disp_x, _ico_node_table[i].disp_y,
2936                   _ico_node_table[i].disp_width, _ico_node_table[i].disp_height);
2937     }
2938     free(displayno);
2939
2940     /* my node Id ... this version fixed 0  */
2941     nodeId = ico_ivi_get_mynode();
2942
2943     _ico_win_mgr->surface_head = ICO_IVI_SURFACEID_BASE(nodeId);
2944     uifw_trace("ico_window_mgr: NoedId=%04x SurfaceIdBase=%08x",
2945                 nodeId, _ico_win_mgr->surface_head);
2946
2947     /* get seat for touch down counter check    */
2948     touch_check_seat = container_of(ec->seat_list.next, struct weston_seat, link);
2949     loop = wl_display_get_event_loop(ec->wl_display);
2950     _ico_win_mgr->wait_mapevent =
2951             wl_event_loop_add_timer(loop, win_mgr_timer_mapsurface, NULL);
2952     wl_event_source_timer_update(_ico_win_mgr->wait_mapevent, 1000);
2953
2954     uifw_info("ico_window_mgr: animation name=%s time=%d",
2955               _ico_ivi_animation_name, _ico_ivi_animation_time);
2956     uifw_info("ico_window_mgr: option flag=0x%04x log level=%d debug flag=0x%04x",
2957               _ico_ivi_option_flag, _ico_ivi_debug_level & 0x0ffff,
2958               (_ico_ivi_debug_level >> 16) & 0x0ffff);
2959
2960     /* touch/click binding for select surface           */
2961     weston_compositor_add_button_binding(ec, BTN_LEFT, 0, win_mgr_click_to_activate, NULL);
2962     weston_compositor_add_touch_binding(ec, 0, win_mgr_touch_to_activate, NULL);
2963
2964     /* set Notification function for GENIVI ivi-shell   */
2965     if (weston_layout_setNotificationCreateSurface(ico_ivi_surfaceCreateNotification, NULL) != 0)   {
2966         uifw_error("ico_window_mgr: weston_layout_setNotificationCreateSurface Error");
2967     }
2968     if (weston_layout_setNotificationRemoveSurface(ico_ivi_surfaceRemoveNotification, NULL) != 0)   {
2969         uifw_error("ico_window_mgr: weston_layout_setNotificationRemoveSurface Error");
2970     }
2971     uifw_info("ico_window_mgr: Leave(module_init)");
2972
2973     return 0;
2974 }