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