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