Bugfix for TIVI-1997, TIVI-2244, TIVI-2256, A ivi cursor layer may pick up a touch...
[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 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    Jul-26-2013
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 <limits.h>
47 #include <pixman.h>
48 #include <wayland-server.h>
49 #include <dirent.h>
50 #include <aul/aul.h>
51 #include <bundle.h>
52
53 #include <EGL/egl.h>
54 #include <GLES2/gl2.h>
55 #include <GLES2/gl2ext.h>
56 #include <GL/internal/dri_interface.h>
57
58 #include <weston/compositor.h>
59 #include <libdrm/intel_bufmgr.h>
60
61 /* detail debug log */
62 #define UIFW_DETAIL_OUT 0                   /* 1=detail debug log/0=no detail log   */
63
64 #include "ico_ivi_common_private.h"
65 #include "ico_ivi_shell_private.h"
66 #include "ico_window_mgr_private.h"
67 #include "ico_window_mgr.h"
68 #include "desktop-shell-server-protocol.h"
69 #include "ico_window_mgr-server-protocol.h"
70
71 /* SurfaceID                            */
72 #define INIT_SURFACE_IDS    1024            /* SurfaceId table initiale size        */
73 #define ADD_SURFACE_IDS     512             /* SurfaceId table additional size      */
74 #define SURCAFE_ID_MASK     0x0ffff         /* SurfaceId bit mask pattern           */
75 #define UIFW_HASH           64              /* Hash value (2's compliment)          */
76
77 /* Internal fixed value                 */
78 #define ICO_WINDOW_MGR_APPID_FIXCOUNT   5   /* retry count of appid fix             */
79                                             /* show/hide animation with position    */
80 #define ICO_WINDOW_MGR_ANIMATION_POS    0x10000000
81
82 /* GPU type code                        */
83 #define ICO_GPUTYPE_NOACCELERATION      0   /* Do not use GPU-dependent acceleration*/
84 #define ICO_GPUTYPE_INTEL_SANDYBRIDGE   1   /* Intel Sandybridge Mobile             */
85
86 /* Code for Intel Sandybridge Mobile GPU dependent acceleration */
87
88 /* wl_drm_buffer (inport from mesa-9.1.3 & mesa-9.2.1/          */
89 /*                src/egl/wayland/wayland-drm/wayland-drm.h)    */
90 struct uifw_drm_buffer {
91     struct wl_resource *resource;
92     void *drm;                  /* struct wl_drm    */
93     int32_t width, height;
94     uint32_t format;
95     const void *driver_format;
96     int32_t offset[3];
97     int32_t stride[3];
98     void *driver_buffer;
99 };
100
101 /* __DRIimage (inport from mesa-9.1.3/src/mesa/drivers/dri/intel/intel_regions.h    */
102 /*                         mesa-9.2.1/src/mesa/drivers/dri/i915/intel_regions.h     */
103 /*                         mesa-9.2.1/src/mesa/drivers/dri/i965/intel_regions.h)    */
104 struct uifw_intel_region    {   /* struct intel_region for mesa 9.2.1   */
105    void *bo;                /**< buffer manager's buffer */
106    uint32_t refcount;       /**< Reference count for region */
107    uint32_t cpp;            /**< bytes per pixel */
108    uint32_t width;          /**< in pixels */
109    uint32_t height;         /**< in pixels */
110    uint32_t pitch;          /**< in bytes */
111    uint32_t tiling;         /**< Which tiling mode the region is in */
112    uint32_t name;           /**< Global name for the bo */
113 };
114
115 struct uifw_dri_image   {       /* struct __DRIimageRec */
116    struct uifw_intel_region *region;
117    int internal_format;
118    uint32_t dri_format;
119    uint32_t format;
120    uint32_t offset;
121    uint32_t strides[3];
122    uint32_t offsets[3];
123    void *planar_format; /* intel_image_format */
124    uint32_t width;
125    uint32_t height;
126    uint32_t tile_x;
127    uint32_t tile_y;
128    bool has_depthstencil;           /* i965 only    */
129    void *data;
130 };
131
132 /* gl_surface_state (inport from weston-1.2.1/src/gl-renderer.c,    */
133 /*                               weston-1.3.1/src/gl-renderer.c     */
134 enum buffer_type {
135     BUFFER_TYPE_NULL,
136     BUFFER_TYPE_SHM,
137     BUFFER_TYPE_EGL
138 };
139 struct uifw_gl_surface_state {      /* struct gl_surface_state  */
140     GLfloat color[4];
141     struct gl_shader *shader;
142
143     GLuint textures[3];
144     int num_textures;
145     int needs_full_upload;
146     pixman_region32_t texture_damage;
147
148     void *images[3];            /* EGLImageKHR */
149     GLenum target;
150     int num_images;
151
152     struct weston_buffer_reference buffer_ref;
153     enum buffer_type buffer_type;
154     int pitch; /* in pixels */
155     int height; /* in pixels */
156     int y_inverted;         /* add weston 1.3.x */
157 };
158
159 /* Multi Windiw Manager                 */
160 struct ico_win_mgr {
161     struct weston_compositor *compositor;   /* Weston compositor                    */
162     void    *shell;                         /* shell(ico_ivi_shell) table address   */
163     int32_t surface_head;                   /* (HostID << 24) | (DisplayNo << 16)   */
164
165     struct wl_list  client_list;            /* Clients                              */
166     struct wl_list  manager_list;           /* Manager(ex.HomeScreen) list          */
167     int             num_manager;            /* Number of managers                   */
168
169     struct wl_list  ivi_layer_list;         /* Layer management table list          */
170     struct uifw_win_layer *touch_layer;     /* layer table for touch panel layer    */
171
172     struct wl_list  map_list;               /* surface map list                     */
173     struct uifw_surface_map *free_maptable; /* free maped surface table list        */
174     struct weston_animation map_animation[ICO_IVI_MAX_DISPLAY];
175                                             /* animation for map check              */
176     struct wl_event_source  *wait_mapevent; /* map event send wait timer            */
177
178     struct uifw_win_surface *active_pointer_usurf;  /* Active Pointer Surface       */
179     struct uifw_win_surface *active_keyboard_usurf; /* Active Keyboard Surface      */
180
181     struct uifw_win_surface *idhash[UIFW_HASH];  /* UIFW SerfaceID                  */
182     struct uifw_win_surface *wshash[UIFW_HASH];  /* Weston Surface                  */
183
184     uint32_t surfaceid_count;               /* Number of surface id                 */
185     uint32_t surfaceid_max;                 /* Maximum number of surface id         */
186     uint16_t *surfaceid_map;                /* SurfaceId assign bit map             */
187
188     char    shell_init;                     /* shell initialize flag                */
189     char    res[3];                         /* (unused)                             */
190 };
191
192 /* Internal macros                      */
193 /* UIFW SurfaceID                       */
194 #define MAKE_IDHASH(v)  (((uint32_t)v) & (UIFW_HASH-1))
195 /* Weston Surface                       */
196 #define MAKE_WSHASH(v)  ((((uint32_t)v) >> 5) & (UIFW_HASH-1))
197
198 /* function prototype                   */
199                                             /* get surface table from weston surface*/
200 static struct uifw_win_surface *find_uifw_win_surface_by_ws(
201                     struct weston_surface *wsurf);
202                                             /* get client table from weston client  */
203 static struct uifw_client* find_client_from_client(struct wl_client *client);
204                                             /* assign new surface id                */
205 static uint32_t generate_id(void);
206                                             /* bind shell client                    */
207 static void win_mgr_bind_client(struct wl_client *client, void *shell);
208                                             /* unind shell client                   */
209 static void win_mgr_unbind_client(struct wl_client *client);
210 #if 0       /* work around: Walk through child processes until app ID is found  */
211                                             /* get parent pid                       */
212 static pid_t win_mgr_get_ppid(pid_t pid);
213 #endif      /* work around: Walk through child processes until app ID is found  */
214                                             /* get appid from pid                   */
215 static void win_mgr_get_client_appid(struct uifw_client *uclient);
216                                             /* create new surface                   */
217 static void win_mgr_register_surface(
218                     int layertype, struct wl_client *client, struct wl_resource *resource,
219                     struct weston_surface *surface, struct shell_surface *shsurf);
220                                             /* surface destroy                      */
221 static void win_mgr_destroy_surface(struct weston_surface *surface);
222                                             /* map new surface                      */
223 static void win_mgr_surface_map(struct weston_surface *surface, int32_t *width,
224                                 int32_t *height, int32_t *sx, int32_t *sy);
225                                             /* send surface change event to manager */
226 static void win_mgr_change_surface(struct weston_surface *surface,
227                                    const int to, const int manager);
228                                             /* window manager surface configure     */
229 static void win_mgr_surface_configure(struct uifw_win_surface *usurf,
230                                       int x, int y, int width, int height);
231                                             /* shell surface configure              */
232 static void win_mgr_shell_configure(struct weston_surface *surface);
233                                             /* surface select                       */
234 static void win_mgr_select_surface(struct weston_surface *surface);
235                                             /* surface set title                    */
236 static char *win_mgr_set_title(struct weston_surface *surface, const char *title);
237                                             /* surface move request from shell      */
238 static void win_mgr_surface_move(struct weston_surface *surface, int *dx, int *dy);
239                                             /* shell layer visible control          */
240 static void win_mgr_show_layer(int layertype, int show, void *data);
241                                             /* shell full screen surface control    */
242 static int win_mgr_fullscreen(int event, struct weston_surface *surface);
243                                             /* set raise                            */
244 static void win_mgr_set_raise(struct uifw_win_surface *usurf, const int raise);
245                                             /* surface change from manager          */
246 static int win_mgr_surface_change_mgr(struct weston_surface *surface, const int x,
247                                       const int y, const int width, const int height);
248                                             /* reset surface focus                  */
249 static void win_mgr_reset_focus(struct uifw_win_surface *usurf);
250                                             /* create new layer                     */
251 static struct uifw_win_layer *win_mgr_create_layer(struct uifw_win_surface *usurf,
252                                                    const uint32_t layer, const int layertype);
253                                             /* set surface layer                    */
254 static void win_mgr_set_layer(struct uifw_win_surface *usurf, const uint32_t layer);
255                                             /* set active surface                   */
256 static void win_mgr_set_active(struct uifw_win_surface *usurf, const int target);
257
258                                             /* declare manager                      */
259 static void uifw_declare_manager(struct wl_client *client, struct wl_resource *resource,
260                                  int manager);
261                                             /* set window layer                     */
262 static void uifw_set_window_layer(struct wl_client *client,
263                                   struct wl_resource *resource,
264                                   uint32_t surfaceid, uint32_t layer);
265                                             /* set surface size and position        */
266 static void uifw_set_positionsize(struct wl_client *client, struct wl_resource *resource,
267                                   uint32_t surfaceid, uint32_t node, int32_t x, int32_t y,
268                                   int32_t width, int32_t height, int32_t flags);
269                                             /* show/hide and raise/lower surface    */
270 static void uifw_set_visible(struct wl_client *client, struct wl_resource *resource,
271                              uint32_t surfaceid, int32_t visible, int32_t raise,
272                              int32_t flag);
273                                             /* set surface animation                */
274 static void uifw_set_animation(struct wl_client *client, struct wl_resource *resource,
275                                uint32_t surfaceid, int32_t type,
276                                const char *animation, int32_t time);
277                                             /* set surface attributes               */
278 static void uifw_set_attributes(struct wl_client *client, struct wl_resource *resource,
279                                 uint32_t surfaceid, uint32_t attributes);
280                                             /* surface visibility control with animation*/
281 static void uifw_visible_animation(struct wl_client *client, struct wl_resource *resource,
282                                    uint32_t surfaceid, int32_t visible,
283                                    int32_t x, int32_t y, int32_t width, int32_t height);
284                                             /* set active surface (form HomeScreen) */
285 static void uifw_set_active(struct wl_client *client, struct wl_resource *resource,
286                             uint32_t surfaceid, int32_t active);
287                                             /* layer visibility control             */
288 static void uifw_set_layer_visible(struct wl_client *client, struct wl_resource *resource,
289                                    uint32_t layer, int32_t visible);
290                                             /* get application surfaces             */
291 static void uifw_get_surfaces(struct wl_client *client, struct wl_resource *resource,
292                               const char *appid, int32_t pid);
293                                             /* check and change all mapped surface  */
294 static void win_mgr_check_mapsurface(struct weston_animation *animation,
295                                      struct weston_output *output, uint32_t msecs);
296                                             /* check timer of mapped surface        */
297 static int win_mgr_timer_mapsurface(void *data);
298                                             /* check and change mapped surface      */
299 static void win_mgr_change_mapsurface(struct uifw_surface_map *sm, int event,
300                                       uint32_t curtime);
301                                             /* set map buffer                       */
302 static void uifw_set_map_buffer(struct wl_client *client, struct wl_resource *resource,
303                                 const char *shmname, uint32_t bufsize, uint32_t bufnum);
304                                             /* map surface to system application    */
305 static void uifw_map_surface(struct wl_client *client, struct wl_resource *resource,
306                              uint32_t surfaceid, int32_t framerate);
307                                             /* unmap surface                        */
308 static void uifw_unmap_surface(struct wl_client *client, struct wl_resource *resource,
309                                uint32_t surfaceid);
310                                             /* bind manager                         */
311 static void bind_ico_win_mgr(struct wl_client *client,
312                              void *data, uint32_t version, uint32_t id);
313                                             /* unbind manager                       */
314 static void unbind_ico_win_mgr(struct wl_resource *resource);
315                                             /* send event to manager                */
316 static int ico_win_mgr_send_to_mgr(const int event, struct uifw_win_surface *usurf,
317                                    const int param1, const int param2, const int param3,
318                                    const int param4, const int param5);
319                                             /* set surface transform                */
320 static int win_mgr_set_scale(struct uifw_win_surface *usurf);
321                                             /* convert animation name to Id value   */
322 static int ico_get_animation_name(const char *animation);
323                                             /* hook for animation                   */
324 static int  (*win_mgr_hook_animation)(const int op, void *data) = NULL;
325                                             /* hook for input region                */
326 static void (*win_mgr_hook_change)(struct uifw_win_surface *usurf) = NULL;
327 static void (*win_mgr_hook_destory)(struct uifw_win_surface *usurf) = NULL;
328 static void (*win_mgr_hook_inputregion)(int set, struct uifw_win_surface *usurf,
329                                         int32_t x, int32_t y, int32_t width,
330                                         int32_t height, int32_t hotspot_x, int32_t hotspot_y,
331                                         int32_t cursor_x, int32_t cursor_y,
332                                         int32_t cursor_width, int32_t cursor_height,
333                                         uint32_t attr) = NULL;
334
335 /* static tables                        */
336 /* Multi Window Manager interface       */
337 static const struct ico_window_mgr_interface ico_window_mgr_implementation = {
338     uifw_declare_manager,
339     uifw_set_window_layer,
340     uifw_set_positionsize,
341     uifw_set_visible,
342     uifw_set_animation,
343     uifw_set_attributes,
344     uifw_visible_animation,
345     uifw_set_active,
346     uifw_set_layer_visible,
347     uifw_get_surfaces,
348     uifw_set_map_buffer,
349     uifw_map_surface,
350     uifw_unmap_surface
351 };
352
353
354 /* GPU driver name          */
355 static const struct _ico_gputype_table  {
356     int     gpu_type;                           /* GPU type code                    */
357     char    *gpu_name;                          /* GPU driver name                  */
358 }   ico_window_mgr_gpu_type[] = {
359     { ICO_GPUTYPE_INTEL_SANDYBRIDGE, "Mesa DRI Intel(R) Sandybridge Mobile" },
360     { 0, "\0" }
361 };
362
363 /* plugin common value(without ico_plugin_loader)   */
364 static int  _ico_ivi_option_flag = 0;           /* option flags                     */
365 static int  _ico_ivi_debug_level = 3;           /* debug Level                      */
366 static char *_ico_ivi_animation_name = NULL;    /* default animation name           */
367 static int  _ico_ivi_animation_time = 500;      /* default animation time           */
368 static int  _ico_ivi_animation_fps = 30;        /* animation frame rate             */
369 static char *_ico_ivi_inputpanel_animation = NULL; /* default animation name for input panel*/
370 static int  _ico_ivi_inputpanel_anima_time = 0; /* default animation time for input panel*/
371
372 static int  _ico_ivi_inputpanel_display = 0;    /* input panel display number       */
373 static int  _ico_ivi_inputdeco_mag = 100;       /* input panel magnification rate(%)*/
374 static int  _ico_ivi_inputdeco_diff = 0;        /* input panel difference from the bottom*/
375
376 static int  _ico_ivi_background_layer = 0;      /* background layer                 */
377 static int  _ico_ivi_default_layer = 1;         /* deafult layer id at surface create*/
378 static int  _ico_ivi_touch_layer = 101;         /* touch panel layer id             */
379 static int  _ico_ivi_cursor_layer = 102;        /* cursor layer id                  */
380 static int  _ico_ivi_startup_layer = 109;       /* deafult layer id at system startup*/
381
382 static int  _ico_ivi_gpu_type = 0;              /* GPU type for get EGL buffer      */
383 static int  _ico_ivi_map_framerate_gpu = 30;    /* framerate of map surface for GPU*/
384 static int  _ico_ivi_map_framerate_shm = 2;     /* framerate of map surface for shm buffer*/
385 static int  _ico_ivi_map_framerate_pixel = 5;   /* framerate of map surface for ReadPixels*/
386
387 /* static management table              */
388 static struct ico_win_mgr       *_ico_win_mgr = NULL;
389 static int                      _ico_num_nodes = 0;
390 static struct uifw_node_table   _ico_node_table[ICO_IVI_MAX_DISPLAY];
391 static struct weston_seat       *touch_check_seat = NULL;
392
393
394 /*--------------------------------------------------------------------------*/
395 /**
396  * @brief   ico_ivi_optionflag: get option flags
397  *
398  * @param       None
399  * @return      option flags
400  */
401 /*--------------------------------------------------------------------------*/
402 WL_EXPORT   int
403 ico_ivi_optionflag(void)
404 {
405     return _ico_ivi_option_flag;
406 }
407
408 /*--------------------------------------------------------------------------*/
409 /**
410  * @brief   ico_ivi_debuglevel: answer debug output level.
411  *
412  * @param       none
413  * @return      debug output level
414  * @retval      0       No debug output
415  * @retval      1       Only error output
416  * @retval      2       Error and Warning output
417  * @retval      3       Error, Warning and information output
418  * @retval      4       Error, Warning, information and Debug Trace output
419  * @retval      5       All output with debug write
420  */
421 /*--------------------------------------------------------------------------*/
422 WL_EXPORT   int
423 ico_ivi_debuglevel(void)
424 {
425     return (_ico_ivi_debug_level & 0x0ffff);
426 }
427
428 /*--------------------------------------------------------------------------*/
429 /**
430  * @brief   ico_ivi_debugflag: get debug flags
431  *
432  * @param       None
433  * @return      debug flags
434  */
435 /*--------------------------------------------------------------------------*/
436 WL_EXPORT   int
437 ico_ivi_debugflag(void)
438 {
439     return ((_ico_ivi_debug_level >> 16) & 0x0ffff);
440 }
441
442 /*--------------------------------------------------------------------------*/
443 /**
444  * @brief   ico_ivi_default_animation_name: get default animation name
445  *
446  * @param       None
447  * @return      Default animation name
448  */
449 /*--------------------------------------------------------------------------*/
450 WL_EXPORT   const char *
451 ico_ivi_default_animation_name(void)
452 {
453     return _ico_ivi_animation_name;
454 }
455
456 /*--------------------------------------------------------------------------*/
457 /**
458  * @brief   ico_ivi_default_animation_time: get default animation time
459  *
460  * @param       None
461  * @return      Default animation time(miri sec)
462  */
463 /*--------------------------------------------------------------------------*/
464 WL_EXPORT   int
465 ico_ivi_default_animation_time(void)
466 {
467     return _ico_ivi_animation_time;
468 }
469
470 /*--------------------------------------------------------------------------*/
471 /**
472  * @brief   ico_ivi_default_animation_fps: get default animation frame rate
473  *
474  * @param       None
475  * @return      Default animation frame rate(frames/sec)
476  */
477 /*--------------------------------------------------------------------------*/
478 WL_EXPORT   int
479 ico_ivi_default_animation_fps(void)
480 {
481     return _ico_ivi_animation_fps;
482 }
483
484 /*--------------------------------------------------------------------------*/
485 /**
486  * @brief   ico_ivi_get_mynode: Get my NodeId
487  *
488  * @param       None
489  * @return      NodeId of my node
490  */
491 /*--------------------------------------------------------------------------*/
492 WL_EXPORT   int
493 ico_ivi_get_mynode(void)
494 {
495     /* Reference Platform 0.90 only support 1 ECU   */
496     return 0;
497 }
498
499 /*--------------------------------------------------------------------------*/
500 /**
501  * @brief   ico_window_mgr_set_weston_surface: set weston surface
502  *
503  * @param[in]   usurf       UIFW surface
504  * @param[in]   x           X coordinate on screen
505  * @param[in]   y           Y coordinate on screen
506  * @param[in]   width       width
507  * @param[in]   height      height
508  * @return      none
509  */
510 /*--------------------------------------------------------------------------*/
511 WL_EXPORT   void
512 ico_window_mgr_set_weston_surface(struct uifw_win_surface *usurf,
513                                   int x, int y, int width, int height)
514 {
515     struct weston_surface *es = usurf->surface;
516     int     buf_width, buf_height;
517
518     if (es == NULL) {
519         uifw_trace("ico_window_mgr_set_weston_surface: usurf(%08x) has no surface",
520                    (int)usurf);
521         return;
522     }
523
524     if (es->buffer_ref.buffer != NULL)   {
525         buf_width = weston_surface_buffer_width(es);
526         buf_height = weston_surface_buffer_height(es);
527         if ((width <= 0) || (height <= 0))    {
528             width = buf_width;
529             usurf->width = buf_width;
530             height = buf_height;
531             usurf->height = buf_height;
532         }
533         if ((usurf->width > buf_width) && (usurf->scalex <= 1.0f))  {
534             width = buf_width;
535             x += (usurf->width - buf_width)/2;
536         }
537         if ((usurf->height > buf_height) && (usurf->scaley <= 1.0f))    {
538             height = buf_height;
539             y += (usurf->height - buf_height)/2;
540         }
541         if (usurf->visible) {
542             x += usurf->node_tbl->disp_x;
543             y += usurf->node_tbl->disp_y;
544         }
545         else    {
546             x = ICO_IVI_MAX_COORDINATE+1;
547             y = ICO_IVI_MAX_COORDINATE+1;
548         }
549         if ((es->geometry.x != x) || (es->geometry.y != y) ||
550             (es->geometry.width != width) || (es->geometry.height != height))    {
551             weston_surface_damage_below(es);
552             win_mgr_surface_configure(usurf, x, y, width, height);
553         }
554         weston_surface_damage(es);
555         weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
556     }
557 }
558
559 /*--------------------------------------------------------------------------*/
560 /**
561  * @brief   ico_window_mgr_set_weston_surface: set weston surface
562  *
563  * @param[in]   usurf       UIFW surface
564  * @param[in]   x           X coordinate on screen
565  * @param[in]   y           Y coordinate on screen
566  * @param[in]   width       width
567  * @param[in]   height      height
568  * @return      none
569  */
570 /*--------------------------------------------------------------------------*/
571 WL_EXPORT   void
572 ico_window_mgr_change_surface(struct uifw_win_surface *usurf,
573                               const int to, const int manager)
574 {
575     uifw_trace("ico_window_mgr_change_surface: Enter(%08x,%d,%d)",
576                usurf->surfaceid, to, manager);
577     win_mgr_change_surface(usurf->surface, to, manager);
578     uifw_trace("ico_window_mgr_change_surface: Leave");
579 }
580
581 /*--------------------------------------------------------------------------*/
582 /**
583  * @brief   ico_window_mgr_get_usurf: find UIFW surface by surface id
584  *
585  * @param[in]   surfaceid   UIFW surface id
586  * @return      UIFW surface table address
587  * @retval      !=NULL      success(surface table address)
588  * @retval      NULL        error(surface id dose not exist)
589  */
590 /*--------------------------------------------------------------------------*/
591 WL_EXPORT   struct uifw_win_surface *
592 ico_window_mgr_get_usurf(const uint32_t surfaceid)
593 {
594     struct uifw_win_surface *usurf;
595
596     usurf = _ico_win_mgr->idhash[MAKE_IDHASH(surfaceid)];
597
598     while (usurf)   {
599         if (usurf->surfaceid == surfaceid) {
600             return usurf;
601         }
602         usurf = usurf->next_idhash;
603     }
604     uifw_trace("ico_window_mgr_get_usurf: NULL");
605     return NULL;
606 }
607
608 /*--------------------------------------------------------------------------*/
609 /**
610  * @brief   ico_window_mgr_get_usurf_client: find UIFW surface by surface id/or client
611  *
612  * @param[in]   surfaceid   UIFW surface id
613  * @param[in]   client      Wayland client
614  * @return      UIFW surface table address
615  * @retval      !=NULL      success(surface table address)
616  * @retval      NULL        error(surface id or client dose not exist)
617  */
618 /*--------------------------------------------------------------------------*/
619 WL_EXPORT   struct uifw_win_surface *
620 ico_window_mgr_get_usurf_client(const uint32_t surfaceid, struct wl_client *client)
621 {
622     struct uifw_win_surface *usurf;
623     struct uifw_client *uclient;
624
625     if (surfaceid == ICO_WINDOW_MGR_V_MAINSURFACE) {
626         uclient = find_client_from_client(client);
627         if (uclient)    {
628             if (&uclient->surface_link != uclient->surface_link.next)   {
629                 usurf = container_of (uclient->surface_link.next,
630                                       struct uifw_win_surface, client_link);
631             }
632             else    {
633                 usurf = NULL;
634             }
635         }
636         else    {
637             usurf = NULL;
638         }
639     }
640     else    {
641         usurf = ico_window_mgr_get_usurf(surfaceid);
642     }
643     return usurf;
644 }
645
646 /*--------------------------------------------------------------------------*/
647 /**
648  * @brief   find_uifw_win_surface_by_ws: find UIFW surface by weston surface
649  *
650  * @param[in]   wsurf       Weston surface
651  * @return      UIFW surface table address
652  * @retval      !=NULL      success(surface table address)
653  * @retval      NULL        error(surface dose not exist)
654  */
655 /*--------------------------------------------------------------------------*/
656 static struct uifw_win_surface *
657 find_uifw_win_surface_by_ws(struct weston_surface *wsurf)
658 {
659     struct uifw_win_surface *usurf;
660
661     usurf = _ico_win_mgr->wshash[MAKE_WSHASH(wsurf)];
662
663     while (usurf)   {
664         if (usurf->surface == wsurf) {
665             return usurf;
666         }
667         usurf = usurf->next_wshash;
668     }
669     uifw_trace("find_uifw_win_surface_by_ws: NULL");
670     return NULL;
671 }
672
673 /*--------------------------------------------------------------------------*/
674 /**
675  * @brief   find_client_from_client: find UIFW client by wayland client
676  *
677  * @param[in]   client      Wayland client
678  * @return      UIFW client table address
679  * @retval      !=NULL      success(client table address)
680  * @retval      NULL        error(client dose not exist)
681  */
682 /*--------------------------------------------------------------------------*/
683 static struct uifw_client*
684 find_client_from_client(struct wl_client *client)
685 {
686     struct uifw_client  *uclient;
687
688     wl_list_for_each (uclient, &_ico_win_mgr->client_list, link)    {
689         if (uclient->client == client)  {
690             return(uclient);
691         }
692     }
693     uifw_trace("find_client_from_client: client.%08x is NULL", (int)client);
694     return NULL;
695 }
696
697 /*--------------------------------------------------------------------------*/
698 /**
699  * @brief   ico_window_mgr_get_appid: find application id by wayland client
700  *
701  * @param[in]   client      Wayland client
702  * @return      application id
703  * @retval      !=NULL      success(application id)
704  * @retval      NULL        error(client dose not exist)
705  */
706 /*--------------------------------------------------------------------------*/
707 WL_EXPORT   char *
708 ico_window_mgr_get_appid(struct wl_client* client)
709 {
710     struct uifw_client  *uclient;
711
712     uclient = find_client_from_client(client);
713
714     if (! uclient)  {
715         return NULL;
716     }
717     return uclient->appid;
718 }
719
720 /*--------------------------------------------------------------------------*/
721 /**
722  * @brief   ico_window_mgr_get_display_coordinate: get display coordinate
723  *
724  * @param[in]   displayno   display number
725  * @param[out]  x           relative X coordinate
726  * @param[out]  y           relative Y coordinate
727  * @return      none
728  */
729 /*--------------------------------------------------------------------------*/
730 WL_EXPORT   void
731 ico_window_mgr_get_display_coordinate(int displayno, int *x, int *y)
732 {
733     if ((displayno <= _ico_num_nodes) || (displayno < 0))   {
734         displayno = 0;
735     }
736     *x = _ico_node_table[displayno].disp_x;
737     *y = _ico_node_table[displayno].disp_y;
738 }
739
740 /*--------------------------------------------------------------------------*/
741 /**
742  * @brief   generate_id: generate uniq id for UIFW surface id
743  *
744  * @param       none
745  * @return      uniq id for UIFW surface id
746  */
747 /*--------------------------------------------------------------------------*/
748 static uint32_t
749 generate_id(void)
750 {
751     int     rep;
752     int     i;
753     int     map;
754     uint16_t *new_map;
755     uint32_t surfaceId;
756
757     /* next assign id                           */
758     _ico_win_mgr->surfaceid_count ++;
759
760     /* serach free id from bitmap               */
761     for (rep = 0; rep < (int)(_ico_win_mgr->surfaceid_max/16); rep++)   {
762         if (_ico_win_mgr->surfaceid_count >= _ico_win_mgr->surfaceid_max)   {
763             _ico_win_mgr->surfaceid_count = 0;
764         }
765         if (_ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] != 0xffff)    {
766             /* find free id from bitmap         */
767             map = 1 << (_ico_win_mgr->surfaceid_count % 16);
768             for (i = (_ico_win_mgr->surfaceid_count % 16); i < 16; i++) {
769                 if ((_ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] & map)
770                         == 0) {
771                     _ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] |= map;
772                     _ico_win_mgr->surfaceid_count
773                         = (_ico_win_mgr->surfaceid_count/16)*16 + i;
774
775                     surfaceId = (_ico_win_mgr->surfaceid_count + 1)
776                                 | _ico_win_mgr->surface_head;
777                     uifw_trace("generate_id: SurfaceId=%08x", surfaceId);
778                     return(surfaceId);
779                 }
780                 map = map << 1;
781             }
782         }
783         _ico_win_mgr->surfaceid_count += 16;
784     }
785
786     /* no free id in bitmap, extend bitmap      */
787     if ((_ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS) > SURCAFE_ID_MASK)  {
788         /* too many surfaces, system error      */
789         uifw_trace("generate_id: SurffaceId Overflow(%d, Max=%d), Abort",
790                    _ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS, SURCAFE_ID_MASK);
791         fprintf(stderr, "generate_id: SurffaceId Overflow(%d, Max=%d), Abort\n",
792                 _ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS, SURCAFE_ID_MASK);
793         abort();
794     }
795
796     new_map = (uint16_t *) malloc((_ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS) / 8);
797     memcpy(new_map, _ico_win_mgr->surfaceid_map, _ico_win_mgr->surfaceid_max/8);
798     memset(&new_map[_ico_win_mgr->surfaceid_max/16], 0, ADD_SURFACE_IDS/8);
799     _ico_win_mgr->surfaceid_count = _ico_win_mgr->surfaceid_max;
800     new_map[_ico_win_mgr->surfaceid_count/16] |= 1;
801     _ico_win_mgr->surfaceid_max += ADD_SURFACE_IDS;
802     free(_ico_win_mgr->surfaceid_map);
803     _ico_win_mgr->surfaceid_map = new_map;
804
805     uifw_trace("generate_id: Extent SurfaceId=%d(Max.%d)",
806                _ico_win_mgr->surfaceid_count+1, _ico_win_mgr->surfaceid_max);
807     surfaceId = (_ico_win_mgr->surfaceid_count + 1) | _ico_win_mgr->surface_head;
808
809     uifw_trace("generate_id: SurfaceId=%08x", surfaceId);
810     return(surfaceId);
811 }
812
813 /*--------------------------------------------------------------------------*/
814 /**
815  * @brief   win_mgr_bind_client: desktop_shell from client
816  *
817  * @param[in]   client          Wayland client
818  * @param[in]   shell           shell(ico_ivi_shell) table address
819  * @return      none
820  */
821 /*--------------------------------------------------------------------------*/
822 static void
823 win_mgr_bind_client(struct wl_client *client, void *shell)
824 {
825     struct uifw_client  *uclient;
826     int     newclient;
827     pid_t   pid;
828     uid_t   uid;
829     gid_t   gid;
830
831     uifw_trace("win_mgr_bind_client: Enter(client=%08x, shell=%08x)",
832                (int)client, (int)shell);
833
834     /* save shell table address             */
835     if (shell)  {
836         _ico_win_mgr->shell = shell;
837     }
838
839     /* set client                           */
840     uclient = find_client_from_client(client);
841     if (! uclient)  {
842         /* client not exist, create client management table             */
843         uifw_trace("win_mgr_bind_client: Create Client");
844         uclient = (struct uifw_client *)malloc(sizeof(struct uifw_client));
845         if (!uclient)   {
846             uifw_error("win_mgr_bind_client: Error, No Memory");
847             return;
848         }
849         memset(uclient, 0, sizeof(struct uifw_client));
850         uclient->client = client;
851         wl_list_init(&uclient->surface_link);
852         newclient = 1;
853     }
854     else    {
855         newclient = 0;
856     }
857     wl_client_get_credentials(client, &pid, &uid, &gid);
858     uifw_trace("win_mgr_bind_client: client=%08x pid=%d uid=%d gid=%d",
859                (int)client, (int)pid, (int)uid, (int)gid);
860     if (pid > 0)    {
861         uclient->pid = (int)pid;
862         /* get applicationId from AppCore(AUL)  */
863         win_mgr_get_client_appid(uclient);
864
865         if (newclient > 0)  {
866             wl_list_insert(&_ico_win_mgr->client_list, &uclient->link);
867         }
868     }
869     else    {
870         uifw_trace("win_mgr_bind_client: client=%08x pid dose not exist", (int)client);
871     }
872     uifw_trace("win_mgr_bind_client: Leave");
873 }
874
875 /*--------------------------------------------------------------------------*/
876 /**
877  * @brief   win_mgr_unbind_client: unbind desktop_shell from client
878  *
879  * @param[in]   client          Wayland client
880  * @return      none
881  */
882 /*--------------------------------------------------------------------------*/
883 static void
884 win_mgr_unbind_client(struct wl_client *client)
885 {
886     struct uifw_client  *uclient;
887
888     uifw_trace("win_mgr_unbind_client: Enter(client=%08x)", (int)client);
889
890     uclient = find_client_from_client(client);
891     if (uclient)    {
892         /* Client exist, Destory client management table             */
893         wl_list_remove(&uclient->link);
894         free(uclient);
895     }
896     uifw_trace("win_mgr_unbind_client: Leave");
897 }
898
899 #if 0       /* work around: Walk through child processes until app ID is found  */
900 /*--------------------------------------------------------------------------*/
901 /**
902  * @brief   win_mgr_get_ppid: Get parent process ID.
903  *
904  * Similar to getppid(), except that this implementation accepts an
905  * arbitrary process ID.
906  *
907  * @param[in]   pid     Process ID of child process
908  * @return      parent process ID on success, -1 on failure
909  */
910 /*--------------------------------------------------------------------------*/
911 static pid_t
912 win_mgr_get_ppid(pid_t pid)
913 {
914     pid_t ppid = -1;
915     char procpath[PATH_MAX] = { 0 };
916
917     snprintf(procpath, sizeof(procpath)-1, "/proc/%d/status", pid);
918
919     /* We better have read permissions! */
920     int const fd = open(procpath, O_RDONLY);
921
922     if (fd < 0)
923         return ppid;
924
925     char buffer[1024] = { 0 };
926
927     ssize_t const size = read(fd, buffer, sizeof(buffer));
928     close(fd);
929
930     if (size <= 0)
931         return ppid;
932
933     /* Find line containing the parent process ID. */
934     char const * const ppid_line = strstr(buffer, "PPid");
935
936     if (ppid_line != NULL)
937         sscanf(ppid_line, "PPid:    %d", &ppid);
938
939     return ppid;
940 }
941 #endif      /* work around: Walk through child processes until app ID is found  */
942
943 /*--------------------------------------------------------------------------*/
944 /**
945  * @brief   win_mgr_get_client_appid: get applicationId from pid
946  *
947  * @param[in]   uclient     UIFW client management table
948  * @return      none
949  */
950 /*--------------------------------------------------------------------------*/
951 static void
952 win_mgr_get_client_appid(struct uifw_client *uclient)
953 {
954     int status = AUL_R_ERROR;
955
956     memset(uclient->appid, 0, ICO_IVI_APPID_LENGTH);
957
958 #if 0       /* work around: Walk through child processes until app ID is found  */
959     /*
960      * Walk the parent process chain until we find a parent process
961      * with an app ID.
962      */
963     int pid;
964
965     for (pid = uclient->pid;
966          pid > 1 && status != AUL_R_OK;
967          pid = win_mgr_get_ppid(pid)) {
968
969         status = aul_app_get_appid_bypid(pid,
970                                          uclient->appid,
971                                          ICO_IVI_APPID_LENGTH);
972
973         uifw_trace("win_mgr_get_client_appid: aul_app_get_appid_bypid ret=%d "
974                    "pid=%d appid=<%s>", status, pid, uclient->appid);
975     }
976     /*
977      * Walk the child process chain as well since app ID was not yet found
978      */
979     if (status != AUL_R_OK) {
980
981         DIR *dr;
982         struct dirent *de;
983         struct stat ps;
984         pid_t   tpid;
985         uid_t   uid;
986         gid_t   gid;
987
988         dr = opendir("/proc/");
989
990         /* get uid */
991         wl_client_get_credentials(uclient->client, &tpid, &uid, &gid);
992
993         while(((de = readdir(dr)) != NULL) && (status != AUL_R_OK)) {
994
995             char fullpath[PATH_MAX] = { 0 };
996             int is_child = 0;
997             int tmppid;
998
999             snprintf(fullpath, sizeof(fullpath)-1, "/proc/%s", de->d_name);
1000
1001             if (stat(fullpath, &ps) == -1) {
1002                 continue;
1003             }
1004
1005             /* find pid dirs for this user (uid) only */
1006             if (ps.st_uid != uid)
1007                 continue;
1008
1009             pid = atoi(de->d_name);
1010
1011             /* check if it's a valid child */
1012             if (pid < uclient->pid)
1013                 continue;
1014
1015             /* scan up to pid to find if a chain exists */
1016             for (tmppid = pid; tmppid > uclient->pid;) {
1017                 tmppid = win_mgr_get_ppid(tmppid);
1018                 if (tmppid == uclient->pid)
1019                     is_child = 1;
1020             }
1021
1022             if (is_child) {
1023                 status = aul_app_get_appid_bypid(pid, uclient->appid,
1024                                                       ICO_IVI_APPID_LENGTH);
1025
1026                 uifw_debug("win_mgr_get_client_appid: aul_app_get_appid_bypid "
1027                            "ret=%d pid=%d appid=<%s>", status, pid,
1028                            uclient->appid);
1029             }
1030         }
1031     }
1032 #else       /* work around: Walk through child processes until app ID is found  */
1033     status = aul_app_get_appid_bypid(uclient->pid, uclient->appid, ICO_IVI_APPID_LENGTH);
1034     uifw_trace("win_mgr_get_client_appid: aul_app_get_appid_bypid ret=%d "
1035                "pid=%d appid=<%s>", status, uclient->pid, uclient->appid);
1036 #endif      /* work around: Walk through child processes until app ID is found  */
1037
1038     if (uclient->appid[0] != 0) {
1039         /* OK, end of get appid         */
1040         uclient->fixed_appid = ICO_WINDOW_MGR_APPID_FIXCOUNT;
1041     }
1042     else    {
1043         /* client does not exist in AppCore, search Linux process table */
1044
1045         int     fd;
1046         int     size;
1047         int     i;
1048         int     j;
1049         char    procpath[128];
1050
1051         uclient->fixed_appid ++;
1052         memset(uclient->appid, 0, ICO_IVI_APPID_LENGTH);
1053         snprintf(procpath, sizeof(procpath)-1, "/proc/%d/cmdline", uclient->pid);
1054         fd = open(procpath, O_RDONLY);
1055         if (fd >= 0)    {
1056             size = read(fd, procpath, sizeof(procpath));
1057             for (; size > 0; size--)    {
1058                 if (procpath[size-1])   break;
1059             }
1060             if (size > 0)   {
1061                 /* get program base name    */
1062                 i = 0;
1063                 for (j = 0; j < size; j++)  {
1064                     if (procpath[j] == 0)   break;
1065                     if (procpath[j] == '/') i = j + 1;
1066                 }
1067                 j = 0;
1068                 for (; i < size; i++)   {
1069                     uclient->appid[j] = procpath[i];
1070                     if ((uclient->appid[j] == 0) ||
1071                         (j >= (ICO_IVI_APPID_LENGTH-1)))    break;
1072                     j++;
1073                 }
1074                 /* search application number in apprication start option    */
1075                 if ((uclient->appid[j] == 0) && (j < (ICO_IVI_APPID_LENGTH-2))) {
1076                     for (; i < size; i++)   {
1077                         if ((procpath[i] == 0) &&
1078                             (procpath[i+1] == '@')) {
1079                             strncpy(&uclient->appid[j], &procpath[i+1],
1080                                     ICO_IVI_APPID_LENGTH - j - 2);
1081                         }
1082                     }
1083                 }
1084             }
1085             close(fd);
1086         }
1087         for (i = strlen(uclient->appid)-1; i >= 0; i--) {
1088             if (uclient->appid[i] != ' ')   break;
1089         }
1090         uclient->appid[i+1] = 0;
1091         if (uclient->appid[0])  {
1092             uifw_trace("win_mgr_get_client_appid: pid=%d appid=<%s> from "
1093                        "Process table(%d)",
1094                        uclient->pid, uclient->appid, uclient->fixed_appid );
1095         }
1096         else    {
1097             uifw_trace("win_mgr_get_client_appid: pid=%d dose not exist in Process table",
1098                        uclient->pid);
1099             sprintf(uclient->appid, "?%d?", uclient->pid);
1100         }
1101     }
1102 }
1103
1104 /*--------------------------------------------------------------------------*/
1105 /**
1106  * @brief   ico_get_animation_name: convert animation name to Id value
1107  *
1108  * @param[in]   animation       animation name
1109  * @return      animation Id value
1110  */
1111 /*--------------------------------------------------------------------------*/
1112 static int
1113 ico_get_animation_name(const char *animation)
1114 {
1115     int anima = ICO_WINDOW_MGR_ANIMATION_NONE;
1116
1117     if (strcasecmp(animation, "none") == 0) {
1118         return ICO_WINDOW_MGR_ANIMATION_NONE;
1119     }
1120
1121     if (win_mgr_hook_animation) {
1122         anima = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_NAME, (void *)animation);
1123     }
1124     if (anima <= 0) {
1125         anima = ICO_WINDOW_MGR_ANIMATION_NONE;
1126     }
1127     return anima;
1128 }
1129
1130 /*--------------------------------------------------------------------------*/
1131 /**
1132  * @brief   win_mgr_register_surface: create UIFW surface
1133  *
1134  * @param[in]   layertype       surface layer type
1135  * @param[in]   client          Wayland client
1136  * @param[in]   resource        client resource
1137  * @param[in]   surface         Weston surface
1138  * @param[in]   shsurf          shell surface
1139  * @return      none
1140  */
1141 /*--------------------------------------------------------------------------*/
1142 static void
1143 win_mgr_register_surface(int layertype, struct wl_client *client,
1144                          struct wl_resource *resource, struct weston_surface *surface,
1145                          struct shell_surface *shsurf)
1146 {
1147     struct uifw_win_surface *usurf;
1148     struct uifw_win_surface *phash;
1149     struct uifw_win_surface *bhash;
1150     int         layer;
1151     uint32_t    hash;
1152
1153     uifw_trace("win_mgr_register_surface: Enter(surf=%08x,client=%08x,res=%08x,layertype=%x)",
1154                (int)surface, (int)client, (int)resource, layertype);
1155
1156     /* check new surface                    */
1157     if (find_uifw_win_surface_by_ws(surface))   {
1158         /* surface exist, NOP               */
1159         uifw_trace("win_mgr_register_surface: Leave(Already Exist)");
1160         return;
1161     }
1162
1163     /* set default color and shader */
1164     weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
1165
1166     /* create UIFW surface management table */
1167     usurf = malloc(sizeof(struct uifw_win_surface));
1168     if (! usurf)    {
1169         uifw_error("win_mgr_register_surface: No Memory");
1170         return;
1171     }
1172
1173     memset(usurf, 0, sizeof(struct uifw_win_surface));
1174
1175     usurf->surfaceid = generate_id();
1176     usurf->surface = surface;
1177     usurf->shsurf = shsurf;
1178     usurf->layertype = layertype;
1179     usurf->node_tbl = &_ico_node_table[0];  /* set default node table (display no=0)    */
1180     wl_list_init(&usurf->ivi_layer);
1181     wl_list_init(&usurf->client_link);
1182     wl_list_init(&usurf->animation.animation.link);
1183     wl_list_init(&usurf->surf_map);
1184     wl_list_init(&usurf->input_region);
1185     usurf->animation.hide_anima = ico_get_animation_name(ico_ivi_default_animation_name());
1186     usurf->animation.hide_time = ico_ivi_default_animation_time();
1187     usurf->animation.show_anima = usurf->animation.hide_anima;
1188     usurf->animation.show_time = usurf->animation.hide_time;
1189     usurf->animation.move_anima = usurf->animation.hide_anima;
1190     usurf->animation.move_time = usurf->animation.hide_time;
1191     usurf->animation.resize_anima = usurf->animation.hide_anima;
1192     usurf->animation.resize_time = usurf->animation.hide_time;
1193     if (layertype == LAYER_TYPE_INPUTPANEL) {
1194         usurf->attributes = ICO_WINDOW_MGR_ATTR_FIXED_ASPECT;
1195         usurf->animation.hide_anima = ico_get_animation_name(_ico_ivi_inputpanel_animation);
1196         usurf->animation.hide_time = _ico_ivi_inputpanel_anima_time;
1197         usurf->animation.show_anima = usurf->animation.hide_anima;
1198         usurf->animation.show_time = usurf->animation.hide_time;
1199     }
1200     if ((layertype != LAYER_TYPE_INPUTPANEL) &&
1201         ((_ico_win_mgr->num_manager <= 0) ||
1202          (ico_ivi_optionflag() & ICO_IVI_OPTION_SHOW_SURFACE))) {
1203         uifw_trace("win_mgr_register_surface: No Manager, Force visible");
1204         usurf->visible = 1;
1205     }
1206     else    {
1207         uifw_trace("win_mgr_register_surface: Manager exist, Not visible");
1208         usurf->visible = 0;
1209     }
1210
1211     /* set client                           */
1212     usurf->uclient = find_client_from_client(client);
1213     if (! usurf->uclient)  {
1214         /* client not exist, create client management table */
1215         uifw_trace("win_mgr_register_surface: Create Client");
1216         win_mgr_bind_client(client, NULL);
1217         usurf->uclient = find_client_from_client(client);
1218         if (! usurf->uclient)  {
1219             uifw_error("win_mgr_register_surface: No Memory");
1220             return;
1221         }
1222     }
1223     wl_list_insert(usurf->uclient->surface_link.prev, &usurf->client_link);
1224
1225     /* make surface id hash table       */
1226     hash = MAKE_IDHASH(usurf->surfaceid);
1227     phash = _ico_win_mgr->idhash[hash];
1228     bhash = NULL;
1229     while (phash)   {
1230         bhash = phash;
1231         phash = phash->next_idhash;
1232     }
1233     if (bhash)  {
1234         bhash->next_idhash = usurf;
1235     }
1236     else    {
1237         _ico_win_mgr->idhash[hash] = usurf;
1238     }
1239
1240     /* make weston surface hash table   */
1241     hash = MAKE_WSHASH(usurf->surface);
1242     phash = _ico_win_mgr->wshash[hash];
1243     bhash = NULL;
1244     while (phash)   {
1245         bhash = phash;
1246         phash = phash->next_wshash;
1247     }
1248     if (bhash)  {
1249         bhash->next_wshash = usurf;
1250     }
1251     else    {
1252         _ico_win_mgr->wshash[hash] = usurf;
1253     }
1254
1255     /* set default layer id             */
1256     switch (layertype)  {
1257     case LAYER_TYPE_BACKGROUND:
1258         layer = _ico_ivi_background_layer;
1259         break;
1260     case LAYER_TYPE_TOUCH:
1261         layer = _ico_ivi_touch_layer;
1262         break;
1263     case LAYER_TYPE_CURSOR:
1264         layer = _ico_ivi_cursor_layer;
1265         break;
1266     default:
1267         if (_ico_win_mgr->num_manager > 0)  {
1268             layer = _ico_ivi_default_layer;
1269         }
1270         else    {
1271             layer = _ico_ivi_startup_layer;
1272         }
1273         break;
1274     }
1275     win_mgr_set_layer(usurf, layer);
1276
1277     uifw_trace("win_mgr_register_surface: Leave(surfaceId=%08x)", usurf->surfaceid);
1278 }
1279
1280 /*--------------------------------------------------------------------------*/
1281 /**
1282  * @brief   win_mgr_surface_map: map surface to display
1283  *
1284  * @param[in]   surface         Weston surface
1285  * @param[in]   width           surface width
1286  * @param[in]   height          surface height
1287  * @param[in]   sx              X coordinate on screen
1288  * @param[in]   sy              Y coordinate on screen
1289  * @return      none
1290  */
1291 /*--------------------------------------------------------------------------*/
1292 static void
1293 win_mgr_surface_map(struct weston_surface *surface, int32_t *width, int32_t *height,
1294                     int32_t *sx, int32_t *sy)
1295 {
1296     struct uifw_win_surface *usurf;
1297
1298     uifw_trace("win_mgr_surface_map: Enter(%08x, x/y=%d/%d w/h=%d/%d)",
1299                (int)surface, *sx, *sy, *width, *height);
1300
1301     usurf = find_uifw_win_surface_by_ws(surface);
1302
1303     if (usurf) {
1304         uifw_trace("win_mgr_surface_map: surf=%08x w/h=%d/%d vis=%d",
1305                    usurf->surfaceid, usurf->width, usurf->height, usurf->visible);
1306         if ((usurf->width > 0) && (usurf->height > 0)) {
1307             uifw_trace("win_mgr_surface_map: HomeScreen registed, PositionSize"
1308                        "(surf=%08x x/y=%d/%d w/h=%d/%d vis=%d",
1309                        usurf->surfaceid, usurf->x, usurf->y, usurf->width, usurf->height,
1310                        usurf->visible);
1311             *width = usurf->width;
1312             *height = usurf->height;
1313             win_mgr_surface_configure(usurf, usurf->node_tbl->disp_x + usurf->x,
1314                                       usurf->node_tbl->disp_y + usurf->y,
1315                                       usurf->width, usurf->height);
1316         }
1317         else    {
1318             uifw_trace("win_mgr_surface_map: HomeScreen not regist Surface, "
1319                        "Change PositionSize(surf=%08x x/y=%d/%d w/h=%d/%d)",
1320                        usurf->surfaceid, *sx, *sy, *width, *height);
1321             usurf->width = *width;
1322             usurf->height = *height;
1323             usurf->x = *sx;
1324             usurf->y = *sy;
1325             if (usurf->x < 0)   usurf->x = 0;
1326             if (usurf->y < 0)   usurf->y = 0;
1327             if (usurf->layertype == LAYER_TYPE_INPUTPANEL)  {
1328                 /* set position */
1329                 usurf->node_tbl = &_ico_node_table[_ico_ivi_inputpanel_display];
1330
1331                 usurf->width = (float)usurf->surface->geometry.width
1332                                * (float)_ico_ivi_inputdeco_mag / 100.0f;
1333                 usurf->height = (float)usurf->surface->geometry.height
1334                                 * (float)_ico_ivi_inputdeco_mag / 100.0f;
1335
1336                 if ((usurf->width > (usurf->node_tbl->disp_width - 16)) ||
1337                     (usurf->height > (usurf->node_tbl->disp_height - 16)))  {
1338                     usurf->x = (usurf->node_tbl->disp_width
1339                                - usurf->surface->geometry.width) / 2;
1340                     usurf->y = usurf->node_tbl->disp_height
1341                                - usurf->surface->geometry.height - 16
1342                                - _ico_ivi_inputdeco_diff;
1343                     if (usurf->x < 0)   usurf->x = 0;
1344                     if (usurf->y < 0)   usurf->y = 0;
1345                 }
1346                 else    {
1347                     win_mgr_set_scale(usurf);
1348
1349                     usurf->x = (usurf->node_tbl->disp_width
1350                                 - usurf->width) / 2;
1351                     usurf->y = usurf->node_tbl->disp_height
1352                                - usurf->height - 16 - _ico_ivi_inputdeco_diff;
1353                     if (usurf->x < 0)   usurf->x = 0;
1354                     if (usurf->y < 0)   usurf->y = 0;
1355                 }
1356                 uifw_trace("win_mgr_surface_map: set position %08x %d.%d/%d",
1357                            usurf->surfaceid, usurf->node_tbl->node, usurf->x, usurf->y);
1358             }
1359             if (((ico_ivi_optionflag() & ICO_IVI_OPTION_SHOW_SURFACE) == 0) &&
1360                 (_ico_win_mgr->num_manager > 0))    {
1361                 /* HomeScreen exist, coodinate set by HomeScreen                */
1362                 if (usurf->visible) {
1363                     win_mgr_surface_configure(usurf, usurf->node_tbl->disp_x + usurf->x,
1364                                               usurf->node_tbl->disp_y + usurf->y,
1365                                               usurf->width, usurf->height);
1366                 }
1367                 else    {
1368                     win_mgr_surface_configure(usurf, ICO_IVI_MAX_COORDINATE+1,
1369                                               ICO_IVI_MAX_COORDINATE+1,
1370                                               usurf->width, usurf->height);
1371                 }
1372                 uifw_trace("win_mgr_surface_map: Change size/position x/y=%d/%d w/h=%d/%d",
1373                            (int)surface->geometry.x, (int)surface->geometry.y,
1374                            surface->geometry.width, surface->geometry.height);
1375             }
1376             else if (usurf->layertype != LAYER_TYPE_INPUTPANEL) {
1377                 uifw_trace("win_mgr_surface_map: No HomeScreen, chaneg to Visible");
1378                 ico_window_mgr_set_visible(usurf, 1);
1379             }
1380             else    {
1381                 if (usurf->visible) {
1382                     win_mgr_surface_configure(usurf, usurf->node_tbl->disp_x + usurf->x,
1383                                               usurf->node_tbl->disp_y + usurf->y,
1384                                               usurf->width, usurf->height);
1385                 }
1386                 else    {
1387                     win_mgr_surface_configure(usurf, ICO_IVI_MAX_COORDINATE+1,
1388                                               ICO_IVI_MAX_COORDINATE+1,
1389                                               usurf->width, usurf->height);
1390                 }
1391             }
1392         }
1393         usurf->mapped = 1;
1394         if (usurf->visible) {
1395             ico_window_mgr_restack_layer(NULL);
1396         }
1397         uifw_trace("win_mgr_surface_map: Leave");
1398     }
1399     else    {
1400         uifw_trace("win_mgr_surface_map: Leave(No UIFW Surface)");
1401     }
1402 }
1403
1404 /*--------------------------------------------------------------------------*/
1405 /**
1406  * @brief   ico_window_mgr_restack_layer: restack surface list
1407  *
1408  * @param[in]   usurf           UIFW surface (if NULL, no surface)
1409  * @return      none
1410  */
1411 /*--------------------------------------------------------------------------*/
1412 WL_EXPORT   void
1413 ico_window_mgr_restack_layer(struct uifw_win_surface *usurf)
1414 {
1415     struct uifw_win_surface  *eu;
1416     struct uifw_win_layer *el;
1417     int32_t buf_width, buf_height;
1418     float   new_x, new_y;
1419     struct weston_layer *wlayer;
1420     struct weston_surface  *surface, *surfacetmp;
1421     int     num_visible = 0;
1422     int     layertype;
1423
1424     /* make compositor surface list     */
1425     wlayer = ico_ivi_shell_weston_layer();
1426
1427     uifw_trace("ico_window_mgr_restack_layer: Enter(surf=%08x) layer=%08x",
1428                (int)usurf, (int)wlayer);
1429
1430     /* remove all surfaces in panel_layer   */
1431     wl_list_for_each_safe (surface, surfacetmp, &wlayer->surface_list, layer_link)   {
1432         wl_list_remove(&surface->layer_link);
1433         wl_list_init(&surface->layer_link);
1434     }
1435     wl_list_init(&wlayer->surface_list);
1436
1437     wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link)  {
1438         wl_list_for_each (eu, &el->surface_list, ivi_layer) {
1439             if (eu->surface == NULL)    continue;
1440
1441             /* target only panel or unknown layer   */
1442             layertype = ico_ivi_shell_layertype(eu->surface);
1443             if ((layertype != LAYER_TYPE_PANEL) && (layertype != LAYER_TYPE_INPUTPANEL) &&
1444                 (layertype != LAYER_TYPE_FULLSCREEN) && (layertype != LAYER_TYPE_CURSOR) &&
1445                 (layertype != LAYER_TYPE_UNKNOWN))  {
1446                 continue;
1447             }
1448             wl_list_remove(&eu->surface->layer_link);
1449             wl_list_init(&eu->surface->layer_link);
1450
1451             if (eu->mapped != 0)    {
1452                 if ((el->visible == FALSE) || (eu->visible == FALSE))   {
1453                     new_x = (float)(ICO_IVI_MAX_COORDINATE+1);
1454                     new_y = (float)(ICO_IVI_MAX_COORDINATE+1);
1455                 }
1456                 else if (eu->surface->buffer_ref.buffer)    {
1457                     buf_width = weston_surface_buffer_width(eu->surface);
1458                     buf_height = weston_surface_buffer_height(eu->surface);
1459                     if ((eu->width > buf_width) && (eu->scalex <= 1.0f))    {
1460                         new_x = (float)(eu->x +
1461                                 (eu->width - eu->surface->geometry.width)/2);
1462                     }
1463                     else    {
1464                         new_x = (float)eu->x;
1465                     }
1466                     if ((eu->height > buf_height) && (eu->scaley <= 1.0f))  {
1467                         new_y = (float) (eu->y +
1468                                 (eu->height - eu->surface->geometry.height)/2);
1469                     }
1470                     else    {
1471                         new_y = (float)eu->y;
1472                     }
1473                     new_x += eu->node_tbl->disp_x + eu->xadd;
1474                     new_y += eu->node_tbl->disp_y + eu->yadd;
1475                     num_visible ++;
1476                 }
1477                 else    {
1478                     new_x = (float)(eu->x + eu->node_tbl->disp_x + eu->xadd);
1479                     new_y = (float)(eu->y + eu->node_tbl->disp_y + eu->yadd);
1480                 }
1481                 wl_list_insert(wlayer->surface_list.prev, &eu->surface->layer_link);
1482                 if ((eu->restrain_configure == 0) &&
1483                     ((new_x != eu->surface->geometry.x) ||
1484                      (new_y != eu->surface->geometry.y)))   {
1485                     weston_surface_damage_below(eu->surface);
1486                     weston_surface_set_position(eu->surface, (float)new_x, (float)new_y);
1487                     weston_surface_damage(eu->surface);
1488                 }
1489                 uifw_debug("ico_window_mgr_restack_layer:%3d(%d).%08x(%08x:%d) "
1490                            "x/y=%d/%d w/h=%d/%d %x",
1491                            el->layer, el->visible, eu->surfaceid, (int)eu->surface,
1492                            eu->visible, (int)eu->surface->geometry.x,
1493                            (int)eu->surface->geometry.y, eu->surface->geometry.width,
1494                            eu->surface->geometry.height, eu->layertype);
1495             }
1496         }
1497     }
1498
1499     /* damage(redraw) target surfacem if target exist   */
1500     if (usurf) {
1501         weston_surface_damage(usurf->surface);
1502     }
1503
1504     /* composit and draw screen(plane)  */
1505     weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
1506
1507     if ((_ico_win_mgr->shell_init == 0) && (num_visible > 0) &&
1508         (_ico_win_mgr->shell != NULL) && (_ico_win_mgr->num_manager > 0))   {
1509         /* start shell fade         */
1510         _ico_win_mgr->shell_init = 1;
1511         ico_ivi_shell_startup(_ico_win_mgr->shell);
1512     }
1513     uifw_trace("ico_window_mgr_restack_layer: Leave");
1514 }
1515
1516 /*--------------------------------------------------------------------------*/
1517 /**
1518  * @brief   ico_window_mgr_touch_layer: touch panel layer control
1519  *
1520  * @param[in]   omit        omit touch layer flag (TRUE=omit/FALSE=not omit)
1521  * @return      none
1522  */
1523 /*--------------------------------------------------------------------------*/
1524 WL_EXPORT   void
1525 ico_window_mgr_touch_layer(int omit)
1526 {
1527     struct uifw_win_surface  *eu;
1528
1529     /* check current touch layer mode   */
1530     if ((_ico_win_mgr->touch_layer == NULL) ||
1531         ((omit != FALSE) && (_ico_win_mgr->touch_layer->visible == FALSE))) {
1532         uifw_trace("ico_window_mgr_touch_layer: touch layer not exist or hide");
1533         return;
1534     }
1535
1536     wl_list_for_each (eu, &_ico_win_mgr->touch_layer->surface_list, ivi_layer) {
1537         if ((eu->surface == NULL) || (eu->mapped == 0)) continue;
1538         if (omit != FALSE)  {
1539             eu->animation.pos_x = (int)eu->surface->geometry.x;
1540             eu->animation.pos_y = (int)eu->surface->geometry.y;
1541             eu->surface->geometry.x = (float)(ICO_IVI_MAX_COORDINATE+1);
1542             eu->surface->geometry.y = (float)(ICO_IVI_MAX_COORDINATE+1);
1543         }
1544         else    {
1545             eu->surface->geometry.x = (float)eu->animation.pos_x;
1546             eu->surface->geometry.y = (float)eu->animation.pos_y;
1547         }
1548     }
1549 }
1550
1551 /*--------------------------------------------------------------------------*/
1552 /**
1553  * @brief   win_mgr_create_layer: create new layer
1554  *
1555  * @param[in]   usurf       UIFW surface, (if need)
1556  * @param[in]   layer       layer id
1557  * @param[in]   layertype   layer type if need
1558  * @return      new layer
1559  * @retval      != NULL     success(layer management table)
1560  * @retval      == NULL     error(No Memory)
1561  */
1562 /*--------------------------------------------------------------------------*/
1563 static struct uifw_win_layer *
1564 win_mgr_create_layer(struct uifw_win_surface *usurf, const uint32_t layer,
1565                      const int layertype)
1566 {
1567     struct uifw_win_layer *el;
1568     struct uifw_win_layer *new_el;
1569
1570     new_el = malloc(sizeof(struct uifw_win_layer));
1571     if (! new_el)   {
1572         uifw_trace("win_mgr_create_layer: Leave(No Memory)");
1573         return NULL;
1574     }
1575
1576     memset(new_el, 0, sizeof(struct uifw_win_layer));
1577     new_el->layer = layer;
1578     if ((int)layer == _ico_ivi_background_layer )   {
1579         new_el->layertype = LAYER_TYPE_BACKGROUND;
1580     }
1581     else if ((int)layer == _ico_ivi_touch_layer )   {
1582         new_el->layertype = LAYER_TYPE_TOUCH;
1583         _ico_win_mgr->touch_layer = new_el;
1584     }
1585     else if ((int)layer == _ico_ivi_cursor_layer )  {
1586         new_el->layertype = LAYER_TYPE_CURSOR;
1587     }
1588     else    {
1589         new_el->layertype = LAYER_TYPE_PANEL;
1590     }
1591     new_el->visible = TRUE;
1592     wl_list_init(&new_el->surface_list);
1593     wl_list_init(&new_el->link);
1594
1595     wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
1596         if (layer >= el->layer) break;
1597     }
1598     if (&el->link == &_ico_win_mgr->ivi_layer_list)    {
1599         wl_list_insert(_ico_win_mgr->ivi_layer_list.prev, &new_el->link);
1600     }
1601     else    {
1602         wl_list_insert(el->link.prev, &new_el->link);
1603     }
1604
1605     if (usurf)  {
1606         wl_list_remove(&usurf->ivi_layer);
1607         wl_list_insert(&new_el->surface_list, &usurf->ivi_layer);
1608         usurf->win_layer = new_el;
1609         if (new_el->layertype == LAYER_TYPE_CURSOR) {
1610             usurf->layertype = LAYER_TYPE_CURSOR;
1611         }
1612     }
1613     return new_el;
1614 }
1615
1616 /*--------------------------------------------------------------------------*/
1617 /**
1618  * @brief   win_mgr_set_layer: set(or change) surface layer
1619  *
1620  * @param[in]   usurf       UIFW surface
1621  * @param[in]   layer       layer id
1622  * @return      none
1623  */
1624 /*--------------------------------------------------------------------------*/
1625 static void
1626 win_mgr_set_layer(struct uifw_win_surface *usurf, const uint32_t layer)
1627 {
1628     struct uifw_win_layer *el;
1629     struct uifw_win_layer *new_el;
1630     uint32_t    oldlayer;
1631
1632     uifw_trace("win_mgr_set_layer: Enter(%08x,%08x,%x)",
1633                usurf->surfaceid, (int)usurf->surface, layer);
1634
1635     /* check if same layer                      */
1636     if (usurf->win_layer != NULL)   {
1637         oldlayer = usurf->win_layer->layer ;
1638         if (oldlayer == layer)  {
1639             uifw_trace("win_mgr_set_layer: Leave(Same Layer)");
1640             return;
1641         }
1642     }
1643     else    {
1644         oldlayer = 0;
1645     }
1646
1647     /* search existing layer                    */
1648     wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
1649         if (el->layer == layer) break;
1650     }
1651
1652     if (&el->link == &_ico_win_mgr->ivi_layer_list)    {
1653         /* layer not exist, create new layer    */
1654         uifw_trace("win_mgr_set_layer: New Layer %d(%d)", layer, usurf->layertype);
1655         new_el = win_mgr_create_layer(usurf, layer, usurf->layertype);
1656         if (! new_el)   {
1657             uifw_trace("win_mgr_set_layer: Leave(No Memory)");
1658             return;
1659         }
1660     }
1661     else    {
1662         uifw_trace("win_mgr_set_layer: Add surface to Layer %d", layer);
1663         usurf->win_layer = el;
1664         win_mgr_set_raise(usurf, 3);
1665     }
1666
1667     /* set input region                     */
1668     if (layer == (uint32_t)_ico_ivi_cursor_layer)   {
1669         uifw_trace("win_mgr_set_layer: %08x cursor Change to cursor layer (%d,%d)-(%d,%d)",
1670                    usurf->surfaceid,
1671                    usurf->surface->input.extents.x1, usurf->surface->input.extents.y1,
1672                    usurf->surface->input.extents.x2, usurf->surface->input.extents.y2);
1673         pixman_region32_fini(&usurf->surface->pending.input);
1674         pixman_region32_init_rect(&usurf->surface->pending.input,
1675                                   ICO_IVI_MAX_COORDINATE + 1, ICO_IVI_MAX_COORDINATE + 1,
1676                                   1, 1);
1677     }
1678     else if (oldlayer == (uint32_t)_ico_ivi_cursor_layer)   {
1679         uifw_trace("win_mgr_set_layer: %08x cursor Change to normal layer (%d,%d)-(%d,%d)",
1680                    usurf->surfaceid,
1681                    usurf->surface->input.extents.x1, usurf->surface->input.extents.y1,
1682                    usurf->surface->input.extents.x2, usurf->surface->input.extents.y2);
1683         pixman_region32_fini(&usurf->surface->pending.input);
1684         pixman_region32_init_rect(&usurf->surface->pending.input,
1685                                   INT32_MIN, INT32_MIN, UINT32_MAX, UINT32_MAX);
1686     }
1687
1688     /* rebild compositor surface list       */
1689     if (usurf->visible) {
1690         ico_window_mgr_restack_layer(usurf);
1691     }
1692     uifw_trace("win_mgr_set_layer: Leave");
1693 }
1694
1695 /*--------------------------------------------------------------------------*/
1696 /**
1697  * @brief   win_mgr_set_active: set(or change) active surface
1698  *
1699  * @param[in]   usurf       UIFW surface
1700  * @param[in]   target      target device
1701  * @return      none
1702  */
1703 /*--------------------------------------------------------------------------*/
1704 static void
1705 win_mgr_set_active(struct uifw_win_surface *usurf, const int target)
1706 {
1707     struct weston_seat *seat;
1708     struct weston_surface *surface;
1709     int     object = target;
1710 #if 0               /* pointer grab can not release */
1711     int     savetp, i;
1712 #endif              /* pointer grab can not release */
1713
1714     uifw_trace("win_mgr_set_active: Enter(%08x,%x)", (int)usurf, target);
1715
1716     if ((usurf) && (usurf->shsurf) && (usurf->surface)) {
1717         surface = usurf->surface;
1718         if ((object & (ICO_WINDOW_MGR_ACTIVE_POINTER|ICO_WINDOW_MGR_ACTIVE_KEYBOARD)) == 0) {
1719             surface = NULL;
1720             if (_ico_win_mgr->active_pointer_usurf == usurf) {
1721                 object |= ICO_WINDOW_MGR_ACTIVE_POINTER;
1722             }
1723             if (_ico_win_mgr->active_keyboard_usurf == usurf)    {
1724                 object |= ICO_WINDOW_MGR_ACTIVE_KEYBOARD;
1725             }
1726         }
1727         else    {
1728             if (object & ICO_WINDOW_MGR_ACTIVE_POINTER) {
1729                 _ico_win_mgr->active_pointer_usurf = usurf;
1730             }
1731             if (object & ICO_WINDOW_MGR_ACTIVE_KEYBOARD)    {
1732                 _ico_win_mgr->active_keyboard_usurf = usurf;
1733             }
1734         }
1735     }
1736     else    {
1737         surface = NULL;
1738         if (object == 0)    {
1739             object = ICO_WINDOW_MGR_ACTIVE_POINTER | ICO_WINDOW_MGR_ACTIVE_KEYBOARD;
1740         }
1741         if (object & ICO_WINDOW_MGR_ACTIVE_POINTER) {
1742             _ico_win_mgr->active_pointer_usurf = NULL;
1743         }
1744         if (object & ICO_WINDOW_MGR_ACTIVE_KEYBOARD)    {
1745             _ico_win_mgr->active_keyboard_usurf = NULL;
1746         }
1747     }
1748
1749     wl_list_for_each (seat, &_ico_win_mgr->compositor->seat_list, link) {
1750 #if 0               /* pointer grab can not release */
1751         if (object & ICO_WINDOW_MGR_ACTIVE_POINTER) {
1752             if (surface)    {
1753                 if ((seat->pointer != NULL) && (seat->pointer->focus != surface))   {
1754                     uifw_trace("win_mgr_set_active: pointer reset focus(%08x)",
1755                                (int)seat->pointer->focus);
1756                     if (seat->pointer->button_count > 0)    {
1757                         /* emulate button release   */
1758                         notify_button(seat, weston_compositor_get_time(),
1759                                       seat->pointer->grab_button,
1760                                       WL_POINTER_BUTTON_STATE_RELEASED);
1761                         /* count up button, because real mouse botan release    */
1762                         seat->pointer->button_count ++;
1763                     }
1764                     weston_pointer_set_focus(seat->pointer, NULL,
1765                                              wl_fixed_from_int(0), wl_fixed_from_int(0));
1766                 }
1767                 else    {
1768                     uifw_trace("win_mgr_set_active: pointer nochange surface(%08x)",
1769                                (int)surface);
1770                 }
1771                 if ((seat->touch != NULL) && (seat->touch->focus != surface))   {
1772                     uifw_trace("win_mgr_set_active: touch reset surface(%08x)",
1773                                (int)seat->touch->focus);
1774                     if (seat->num_tp > 10)  {
1775                         seat->num_tp = 0;       /* safty gard   */
1776                     }
1777                     else if (seat->num_tp > 0)   {
1778                         /* emulate touch up         */
1779                         savetp = seat->num_tp;
1780                         for (i = 0; i < savetp; i++)    {
1781                             notify_touch(seat, weston_compositor_get_time(), i+1,
1782                                          seat->touch->grab_x, seat->touch->grab_y,
1783                                          WL_TOUCH_UP);
1784                         }
1785                         /* touch count up, becase real touch release    */
1786                         seat->num_tp = savetp;
1787                     }
1788                     weston_touch_set_focus(seat, NULL);
1789                 }
1790                 else    {
1791                     uifw_trace("win_mgr_set_active: touch nochange surface(%08x)",
1792                                (int)surface);
1793                 }
1794             }
1795             else    {
1796                 uifw_trace("win_mgr_set_active: pointer reset surface(%08x)",
1797                            (int)seat->pointer->focus);
1798                 if ((seat->pointer != NULL) && (seat->pointer->focus != NULL))  {
1799                     if (seat->pointer->button_count > 0)    {
1800                         /* emulate button release   */
1801                         notify_button(seat, weston_compositor_get_time(),
1802                                       seat->pointer->grab_button,
1803                                       WL_POINTER_BUTTON_STATE_RELEASED);
1804                         seat->pointer->button_count ++;
1805                     }
1806                     weston_pointer_set_focus(seat->pointer, NULL,
1807                                              wl_fixed_from_int(0), wl_fixed_from_int(0));
1808                 }
1809                 if ((seat->touch != NULL) && (seat->touch->focus != NULL))  {
1810                     if (seat->num_tp > 10)  {
1811                         seat->num_tp = 0;       /* safty gard   */
1812                     }
1813                     else if (seat->num_tp > 0)   {
1814                         /* emulate touch up         */
1815                         savetp = seat->num_tp;
1816                         for (i = 0; i < savetp; i++)    {
1817                             notify_touch(seat, weston_compositor_get_time(), i+1,
1818                                          seat->touch->grab_x, seat->touch->grab_y,
1819                                          WL_TOUCH_UP);
1820                         }
1821                         /* touch count up, becase real touch release    */
1822                         seat->num_tp = savetp;
1823                     }
1824                     weston_touch_set_focus(seat, NULL);
1825                 }
1826             }
1827         }
1828 #endif              /* pointer grab can not release */
1829         if ((object & ICO_WINDOW_MGR_ACTIVE_KEYBOARD) && (seat->keyboard))  {
1830             if (surface)    {
1831                 if (seat->keyboard->focus != surface)    {
1832                     weston_keyboard_set_focus(seat->keyboard, surface);
1833                     uifw_trace("win_mgr_set_active: keyboard change surface(%08x=>%08x)",
1834                                (int)seat->keyboard->focus, (int)surface);
1835                 }
1836                 else    {
1837                     uifw_trace("win_mgr_set_active: keyboard nochange surface(%08x)",
1838                                (int)surface);
1839                 }
1840             }
1841             else    {
1842                 uifw_trace("win_mgr_set_active: keyboard reset surface(%08x)",
1843                            (int)seat->keyboard);
1844                 weston_keyboard_set_focus(seat->keyboard, NULL);
1845             }
1846         }
1847     }
1848     uifw_trace("win_mgr_set_active: Leave(%08x)", (int)usurf);
1849 }
1850
1851 /*--------------------------------------------------------------------------*/
1852 /**
1853  * @brief   ico_window_mgr_ismykeyboard: check active keyboard
1854  *
1855  * @param[in]   usurf       UIFW surface
1856  * @return      check result
1857  * @retval      =1          usurf is active keyboard surface
1858  * @retval      =0          usurf is not active
1859  */
1860 /*--------------------------------------------------------------------------*/
1861 WL_EXPORT   int
1862 ico_window_mgr_ismykeyboard(struct uifw_win_surface *usurf)
1863 {
1864     return (_ico_win_mgr->active_keyboard_usurf == usurf) ? 1 : 0;
1865 }
1866
1867 /*--------------------------------------------------------------------------*/
1868 /**
1869  * @brief   uifw_declare_manager: declare manager(ex.SystemController) client
1870  *
1871  * @param[in]   client      Weyland client
1872  * @param[in]   resource    resource of request
1873  * @param[in]   manager     manager(1=manager, 0=not manager)
1874  * @return      none
1875  */
1876 /*--------------------------------------------------------------------------*/
1877 static void
1878 uifw_declare_manager(struct wl_client *client, struct wl_resource *resource, int manager)
1879 {
1880     struct uifw_manager* mgr;
1881     struct uifw_win_surface *usurf;
1882     struct uifw_client *uclient;
1883     struct uifw_win_layer *el;
1884
1885     uifw_trace("uifw_declare_manager: Enter client=%08x manager=%d",
1886                (int)client, manager);
1887
1888     uclient = find_client_from_client(client);
1889     if (! uclient)  {
1890         uifw_trace("uifw_declare_manager: Leave(unknown client=%08x)", (int)client);
1891         return;
1892     }
1893
1894     uclient->manager = manager;
1895
1896     /* client set to manager            */
1897     _ico_win_mgr->num_manager = 0;
1898     wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link)   {
1899         if (mgr->resource == resource)  {
1900             if (mgr->manager != manager)    {
1901                 uifw_trace("uifw_declare_manager: Event Client.%08x Callback %d=>%d",
1902                            (int)client, mgr->manager, manager);
1903                 mgr->manager = manager;
1904
1905                 if (manager)    {
1906                     wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
1907                         wl_list_for_each (usurf, &el->surface_list, ivi_layer) {
1908                             /* send window create event to manager  */
1909                             if (usurf->created != 0)    {
1910                                 uifw_trace("uifw_declare_manager: Send manager(%08x) "
1911                                            "WINDOW_CREATED(surf=%08x,pid=%d,appid=%s)",
1912                                            (int)resource, usurf->surfaceid,
1913                                            usurf->uclient->pid, usurf->uclient->appid);
1914                                 ico_window_mgr_send_window_created(resource,
1915                                                                    usurf->surfaceid,
1916                                                                    usurf->winname,
1917                                                                    usurf->uclient->pid,
1918                                                                    usurf->uclient->appid,
1919                                                                    usurf->layertype << 12);
1920                             }
1921                         }
1922                     }
1923                 }
1924             }
1925         }
1926         if (mgr->manager)   {
1927             _ico_win_mgr->num_manager++;
1928         }
1929     }
1930     uifw_trace("uifw_declare_manager: Leave(managers=%d)", _ico_win_mgr->num_manager);
1931 }
1932
1933 /*--------------------------------------------------------------------------*/
1934 /**
1935  * @brief   uifw_set_window_layer: set layer id to surface
1936  *
1937  * @param[in]   client      Weyland client
1938  * @param[in]   resource    resource of request
1939  * @param[in]   surfaceid   UIFW surface id
1940  * @param[in]   layer       layer id
1941  * @return      none
1942  */
1943 /*--------------------------------------------------------------------------*/
1944 static void
1945 uifw_set_window_layer(struct wl_client *client, struct wl_resource *resource,
1946                       uint32_t surfaceid, uint32_t layer)
1947 {
1948     if (layer == ICO_WINDOW_MGR_LAYERTYPE_BACKGROUND)  {
1949         layer = _ico_ivi_background_layer;
1950     }
1951     else if (layer == ICO_WINDOW_MGR_LAYERTYPE_TOUCH)  {
1952         layer = _ico_ivi_touch_layer;
1953     }
1954     else if (layer == ICO_WINDOW_MGR_LAYERTYPE_CURSOR)    {
1955         layer = _ico_ivi_cursor_layer;
1956     }
1957     else if (layer == ICO_WINDOW_MGR_LAYERTYPE_STARTUP)    {
1958         layer = _ico_ivi_startup_layer;
1959     }
1960
1961     uifw_trace("uifw_set_window_layer: Enter res=%08x surfaceid=%08x layer=%d",
1962                (int)resource, surfaceid, layer);
1963
1964     struct uifw_win_surface *usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
1965
1966     if (! usurf)    {
1967         uifw_trace("uifw_set_window_layer: Leave(No Surface(id=%08x))", surfaceid);
1968         return;
1969     }
1970
1971     if (usurf->win_layer->layer != layer) {
1972         win_mgr_set_layer(usurf, layer);
1973         win_mgr_change_surface(usurf->surface, -1, 1);
1974     }
1975     uifw_trace("uifw_set_window_layer: Leave");
1976 }
1977
1978 /*--------------------------------------------------------------------------*/
1979 /**
1980  * @brief   uifw_set_positionsize: set surface position and size
1981  *
1982  * @param[in]   client      Weyland client
1983  * @param[in]   resource    resource of request
1984  * @param[in]   surfaceid   UIFW surface id
1985  * @param[in]   node        surface node id
1986  * @param[in]   x           X coordinate on screen(if bigger than 16383, no change)
1987  * @param[in]   y           Y coordinate on screen(if bigger than 16383, no change)
1988  * @param[in]   width       surface width(if bigger than 16383, no change)
1989  * @param[in]   height      surface height(if bigger than 16383, no change)
1990  * @param[in]   flags       with/without animation and client configure flag
1991  * @return      none
1992  */
1993 /*--------------------------------------------------------------------------*/
1994 static void
1995 uifw_set_positionsize(struct wl_client *client, struct wl_resource *resource,
1996                       uint32_t surfaceid, uint32_t node, int32_t x, int32_t y,
1997                       int32_t width, int32_t height, int32_t flags)
1998 {
1999     struct uifw_client *uclient;
2000     struct uifw_win_surface *usurf;
2001     struct weston_surface *es;
2002     int     op;
2003     int     retanima;
2004     int     oldx, oldy;
2005     struct uifw_node_table  *oldnode;
2006
2007     uifw_trace("uifw_set_positionsize: Enter surf=%08x node=%x x/y/w/h=%d/%d/%d/%d flag=%x",
2008                surfaceid, node, x, y, width, height, flags);
2009
2010     usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
2011     if (! usurf)    {
2012         uifw_trace("uifw_set_positionsize: Leave(surf=%08x NOT Found)", surfaceid);
2013         return;
2014     }
2015     oldx = usurf->x;
2016     oldy = usurf->y;
2017     oldnode = usurf->node_tbl;
2018
2019     uclient = find_client_from_client(client);
2020
2021     usurf->disable = 0;
2022     if (((int)node) >= _ico_num_nodes)  {
2023         uifw_trace("uifw_set_positionsize: node=%d dose not exist(max=%d)",
2024                    node, _ico_num_nodes);
2025         if ((ico_ivi_optionflag() & ICO_IVI_OPTION_SHOW_NODISP) == 0)   {
2026             if (usurf->visible) {
2027                 /* no display, change to hide   */
2028                 uifw_set_visible(client, resource, surfaceid, ICO_WINDOW_MGR_VISIBLE_HIDE,
2029                                  ICO_WINDOW_MGR_V_NOCHANGE, 0);
2030             }
2031             usurf->disable = 1;
2032         }
2033         node = 0;
2034     }
2035     usurf->node_tbl = &_ico_node_table[node];
2036
2037     es = usurf->surface;
2038     if (es)  {
2039         /* weston surface exist             */
2040         es = usurf->surface;
2041         retanima = ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
2042
2043         /* if x,y,width,height bigger then ICO_IVI_MAX_COORDINATE, no change    */
2044         if (x > ICO_IVI_MAX_COORDINATE)         x = usurf->x;
2045         if (y > ICO_IVI_MAX_COORDINATE)         y = usurf->y;
2046         if (width > ICO_IVI_MAX_COORDINATE)     width = usurf->width;
2047         if (height > ICO_IVI_MAX_COORDINATE)    height = usurf->height;
2048
2049         /* check animation                  */
2050         if ((usurf->animation.restrain_configure != 0) &&
2051             (x == usurf->x) && (y == usurf->y) &&
2052             (width == usurf->width) && (height == usurf->height))   {
2053             uifw_trace("uifw_set_positionsize: Leave(same position size at animation)");
2054             return;
2055         }
2056
2057         if (uclient)    {
2058             if ((surfaceid != ICO_WINDOW_MGR_V_MAINSURFACE) &&
2059                 (uclient->manager == 0) && (uclient->privilege == 0))   uclient = NULL;
2060         }
2061         if (! uclient)  {
2062             if ((usurf->width > 0) && (usurf->height > 0))  {
2063                 win_mgr_surface_change_mgr(es, x, y, width, height);
2064                 uifw_trace("uifw_set_positionsize: Leave(Request from App)");
2065                 return;
2066             }
2067
2068             uifw_trace("uifw_set_positionsize: Initial Position/Size visible=%d",
2069                        usurf->visible);
2070             /* Initiale position is (0,0)   */
2071             weston_surface_set_position(es, (float)(usurf->node_tbl->disp_x),
2072                                         (float)(usurf->node_tbl->disp_y));
2073         }
2074
2075         uifw_trace("uifw_set_positionsize: Old geometry x/y=%d/%d,w/h=%d/%d",
2076                    (int)es->geometry.x, (int)es->geometry.y,
2077                    (int)es->geometry.width, (int)es->geometry.height);
2078
2079         usurf->animation.pos_x = usurf->x;
2080         usurf->animation.pos_y = usurf->y;
2081         usurf->animation.pos_width = usurf->width;
2082         usurf->animation.pos_height = usurf->height;
2083         usurf->animation.no_configure = (flags & ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE) ? 1 : 0;
2084
2085         usurf->x = x;
2086         usurf->y = y;
2087         usurf->width = width;
2088         usurf->height = height;
2089         if (_ico_win_mgr->num_manager <= 0) {
2090             /* no manager(HomeScreen), set geometory    */
2091             weston_surface_set_position(es, (float)(usurf->node_tbl->disp_x + x),
2092                                         (float)(usurf->node_tbl->disp_y + y));
2093         }
2094         if ((es->output) && (es->buffer_ref.buffer) &&
2095             (es->geometry.width > 0) && (es->geometry.height > 0)) {
2096             uifw_trace("uifw_set_positionsize: Fixed Geometry, Change(Vis=%d)",
2097                        usurf->visible);
2098             if (usurf->visible) {
2099                 if ((flags & ICO_WINDOW_MGR_FLAGS_ANIMATION) &&
2100                     (win_mgr_hook_animation != NULL))   {
2101                     /* with animation   */
2102                     if ((x != (usurf->surface->geometry.x - usurf->node_tbl->disp_x)) ||
2103                         (y != (usurf->surface->geometry.y - usurf->node_tbl->disp_y)))  {
2104                         op = ICO_WINDOW_MGR_ANIMATION_OPMOVE;
2105                     }
2106                     else if ((width != usurf->surface->geometry.width) ||
2107                              (height != usurf->surface->geometry.height))   {
2108                         op = ICO_WINDOW_MGR_ANIMATION_OPRESIZE;
2109                     }
2110                     else    {
2111                         op = ICO_WINDOW_MGR_ANIMATION_OPNONE;
2112                     }
2113                     if (((op == ICO_WINDOW_MGR_ANIMATION_OPMOVE) &&
2114                          (usurf->animation.move_anima != ICO_WINDOW_MGR_ANIMATION_NONE)) ||
2115                         ((op == ICO_WINDOW_MGR_ANIMATION_OPRESIZE) &&
2116                          (usurf->animation.resize_anima != ICO_WINDOW_MGR_ANIMATION_NONE))) {
2117                         retanima = (*win_mgr_hook_animation)(op, (void *)usurf);
2118                         uifw_trace("uifw_set_positionsize: ret call anima = %d", retanima);
2119                     }
2120                 }
2121                 if ((retanima == ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA) ||
2122                     (retanima != ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL))  {
2123                     ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
2124                                                       usurf->width, usurf->height);
2125                 }
2126             }
2127         }
2128         if ((retanima == ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA) ||
2129             (retanima != ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL))  {
2130             win_mgr_change_surface(es,
2131                                    (flags & ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE) ? -1 : 0, 1);
2132         }
2133         uifw_trace("uifw_set_positionsize: Leave(OK,output=%08x)", (int)es->output);
2134     }
2135     else    {
2136         usurf->x = x;
2137         usurf->y = y;
2138         usurf->width = width;
2139         usurf->height = height;
2140         uifw_trace("uifw_set_positionsize: Leave(OK, but no buffer)");
2141     }
2142
2143     /* if position change, call hook for input region   */
2144     if (win_mgr_hook_change != NULL)    {
2145         if ((oldx != usurf->x) || (oldy != usurf->y) || (oldnode != usurf->node_tbl))   {
2146             (*win_mgr_hook_change)(usurf);
2147         }
2148     }
2149 }
2150
2151 /*--------------------------------------------------------------------------*/
2152 /**
2153  * @brief   uifw_set_visible: surface visible/raise control
2154  *
2155  * @param[in]   client      Weyland client
2156  * @param[in]   resource    resource of request
2157  * @param[in]   surfaceid   UIFW surface id
2158  * @param[in]   visible     visible(1=show/0=hide/other=no change)
2159  * @param[in]   raise       raise(1=raise/0=lower/other=no change)
2160  * @param[in]   flags       with/without animation
2161  * @return      none
2162  */
2163 /*--------------------------------------------------------------------------*/
2164 static void
2165 uifw_set_visible(struct wl_client *client, struct wl_resource *resource,
2166                  uint32_t surfaceid, int32_t visible, int32_t raise, int32_t flags)
2167 {
2168     struct uifw_win_surface *usurf;
2169     struct uifw_client *uclient;
2170     int     restack;
2171     int     retanima;
2172     int     oldvisible;
2173
2174     uifw_trace("uifw_set_visible: Enter(surf=%08x,%d,%d,%x)",
2175                surfaceid, visible, raise, flags);
2176
2177     usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
2178     if ((! usurf) || (! usurf->surface))    {
2179         uifw_trace("uifw_set_visible: Leave(Surface Not Exist)");
2180         return;
2181     }
2182     oldvisible = ico_window_mgr_is_visible(usurf);
2183
2184     uclient = find_client_from_client(client);
2185     if (uclient)    {
2186         if ((surfaceid != ICO_WINDOW_MGR_V_MAINSURFACE) &&
2187             (uclient->manager == 0) && (uclient->privilege == 0))   {
2188             uifw_trace("uifw_set_visible: Request from App(%s), not Manager",
2189                        uclient->appid);
2190             uclient = NULL;
2191         }
2192         else    {
2193             uifw_trace("uifw_set_visible: Request from Manager(%s)", uclient->appid);
2194         }
2195     }
2196     else    {
2197         uifw_trace("uifw_set_visible: Request from Unknown App, not Manager");
2198     }
2199
2200     restack = 0;
2201
2202     if ((usurf->disable == 0) && (visible == ICO_WINDOW_MGR_VISIBLE_SHOW))  {
2203
2204 #if  PERFORMANCE_EVALUATIONS > 0
2205         if (! usurf->visible)   {
2206             uifw_perf("SWAP_BUFFER Show appid=%s surface=%08x",
2207                       usurf->uclient->appid, usurf->surfaceid);
2208         }
2209 #endif /*PERFORMANCE_EVALUATIONS*/
2210         if ((! usurf->visible) ||
2211             (usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE))    {
2212             usurf->visible = 1;
2213             uifw_trace("uifw_set_visible: Change to Visible");
2214
2215             ico_ivi_shell_set_toplevel(usurf->shsurf);
2216
2217             /* Weston surface configure                     */
2218             uifw_trace("uifw_set_visible: Visible to Weston WSurf=%08x,%d.%d/%d/%d/%d",
2219                        (int)usurf->surface, usurf->node_tbl->node, usurf->x, usurf->y,
2220                        usurf->width, usurf->height);
2221             ico_ivi_shell_set_surface_type(usurf->shsurf);
2222             ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
2223                                               usurf->width, usurf->height);
2224
2225             restack = 1;                    /* need damage      */
2226
2227             if ((flags & (ICO_WINDOW_MGR_ANIMATION_POS|ICO_WINDOW_MGR_FLAGS_ANIMATION)) &&
2228                 (usurf->animation.show_anima != ICO_WINDOW_MGR_ANIMATION_NONE) &&
2229                 (win_mgr_hook_animation != NULL))   {
2230                 usurf->animation.pos_x = usurf->x;
2231                 usurf->animation.pos_y = usurf->y;
2232                 usurf->animation.pos_width = usurf->width;
2233                 usurf->animation.pos_height = usurf->height;
2234                 usurf->animation.no_configure = 0;
2235                 retanima = (*win_mgr_hook_animation)(
2236                                 (flags & ICO_WINDOW_MGR_ANIMATION_POS) ?
2237                                     ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS :
2238                                     ICO_WINDOW_MGR_ANIMATION_OPSHOW,
2239                                 (void *)usurf);
2240                 uifw_trace("uifw_set_visible: ret call anima = %d", retanima);
2241             }
2242         }
2243         else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
2244                  (raise != ICO_WINDOW_MGR_RAISE_RAISE))  {
2245             uifw_trace("uifw_set_visible: Leave(No Change)");
2246             return;
2247         }
2248     }
2249     else if (visible == ICO_WINDOW_MGR_VISIBLE_HIDE)    {
2250
2251 #if  PERFORMANCE_EVALUATIONS > 0
2252         if (usurf->visible) {
2253             uifw_perf("SWAP_BUFFER Hide appid=%s surface=%08x",
2254                       usurf->uclient->appid, usurf->surfaceid);
2255         }
2256 #endif /*PERFORMANCE_EVALUATIONS*/
2257         if ((usurf->visible) ||
2258             (usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE))    {
2259
2260             /* Reset focus                                  */
2261             win_mgr_reset_focus(usurf);
2262
2263             /* Weston surface configure                     */
2264             weston_surface_damage_below(usurf->surface);
2265             ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
2266                                               usurf->width, usurf->height);
2267
2268             retanima = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
2269             if ((flags & (ICO_WINDOW_MGR_FLAGS_ANIMATION|ICO_WINDOW_MGR_ANIMATION_POS)) &&
2270                 (usurf->animation.hide_anima != ICO_WINDOW_MGR_ANIMATION_NONE) &&
2271                 (win_mgr_hook_animation != NULL))   {
2272                 usurf->animation.pos_x = usurf->x;
2273                 usurf->animation.pos_y = usurf->y;
2274                 usurf->animation.pos_width = usurf->width;
2275                 usurf->animation.pos_height = usurf->height;
2276                 usurf->animation.no_configure = 0;
2277                 retanima = (*win_mgr_hook_animation)(
2278                                 (flags & ICO_WINDOW_MGR_ANIMATION_POS) ?
2279                                     ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS :
2280                                     ICO_WINDOW_MGR_ANIMATION_OPHIDE,
2281                                 (void *)usurf);
2282             }
2283             if (retanima != ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL)    {
2284                 usurf->visible = 0;
2285                 uifw_trace("uifw_set_visible: Change to UnVisible");
2286                 /* change visible to unvisible, restack surface list    */
2287                 restack = 1;
2288                 /* Weston surface configure                     */
2289                 ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
2290                                                   usurf->width, usurf->height);
2291             }
2292             else    {
2293                 uifw_trace("uifw_set_visible: UnVisible but animation");
2294             }
2295         }
2296         else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
2297                  (raise != ICO_WINDOW_MGR_RAISE_RAISE))  {
2298             uifw_trace("uifw_set_visible: Leave(No Change)");
2299             return;
2300         }
2301     }
2302     else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
2303              (raise != ICO_WINDOW_MGR_RAISE_RAISE))  {
2304         uifw_trace("uifw_set_visible: Leave(No Change)");
2305         return;
2306     }
2307
2308     /* raise/lower                              */
2309     if ((raise == ICO_WINDOW_MGR_RAISE_LOWER) || (raise == ICO_WINDOW_MGR_RAISE_RAISE))  {
2310         win_mgr_set_raise(usurf, raise);
2311         if (usurf->visible == 0)    {
2312             restack |= 2;
2313         }
2314     }
2315     else    {
2316         raise = ICO_WINDOW_MGR_V_NOCHANGE;
2317     }
2318
2319     if (restack)    {
2320         ico_window_mgr_restack_layer(usurf);
2321     }
2322
2323     /* send event(VISIBLE) to manager           */
2324     if (restack)    {
2325         ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_VISIBLE,
2326                                 usurf,
2327                                 (visible == ICO_WINDOW_MGR_VISIBLE_SHOW) ? 1 :
2328                                     ((visible == ICO_WINDOW_MGR_VISIBLE_HIDE) ? 0 :
2329                                         ICO_WINDOW_MGR_V_NOCHANGE),
2330                                 raise, uclient ? 0 : 1, 0,0);
2331     }
2332
2333     /* if visible change, call hook for input region    */
2334     if (win_mgr_hook_change != NULL)    {
2335         if (oldvisible != ico_window_mgr_is_visible(usurf))    {
2336             (*win_mgr_hook_change)(usurf);
2337         }
2338     }
2339     uifw_trace("uifw_set_visible: Leave(OK)");
2340 }
2341
2342 /*--------------------------------------------------------------------------*/
2343 /**
2344  * @brief   uifw_set_animation: set animation of surface visible/unvisible
2345  *
2346  * @param[in]   client      Weyland client
2347  * @param[in]   resource    resource of request
2348  * @param[in]   surfaceid   UIFW surface id
2349  * @param[in]   type        how to change surface
2350  * @param[in]   anmation    animation name
2351  * @param[in]   time        animation time(ms), if 0, default time
2352  * @return      none
2353  */
2354 /*--------------------------------------------------------------------------*/
2355 static void
2356 uifw_set_animation(struct wl_client *client, struct wl_resource *resource,
2357                    uint32_t surfaceid, int32_t type, const char *animation, int32_t time)
2358 {
2359     int animaid;
2360     struct uifw_win_surface *usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
2361
2362     uifw_trace("uifw_set_transition: surf=%08x,type=%x,anim=%s,time=%d",
2363                surfaceid, type, animation, time);
2364
2365     if (usurf) {
2366         if ((*animation != 0) && (*animation != ' '))   {
2367             animaid = ico_get_animation_name(animation);
2368             uifw_trace("uifw_set_animation: Leave(OK) type=%d", animaid);
2369             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE)  {
2370                 if ((usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPHIDE) ||
2371                     (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS))  {
2372                     usurf->animation.next_anima = animaid;
2373                 }
2374                 else    {
2375                     usurf->animation.hide_anima = animaid;
2376                 }
2377             }
2378             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW)  {
2379                 if ((usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPSHOW) ||
2380                     (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS))  {
2381                     usurf->animation.next_anima = animaid;
2382                 }
2383                 else    {
2384                     usurf->animation.show_anima = animaid;
2385                 }
2386             }
2387             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE)  {
2388                 if (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPMOVE)    {
2389                     usurf->animation.next_anima = animaid;
2390                 }
2391                 else    {
2392                     usurf->animation.move_anima = animaid;
2393                 }
2394             }
2395             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE)    {
2396                 if (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPRESIZE)  {
2397                     usurf->animation.next_anima = animaid;
2398                 }
2399                 else    {
2400                     usurf->animation.resize_anima = animaid;
2401                 }
2402             }
2403         }
2404         if ((time > 0) && (time != ICO_WINDOW_MGR_V_NOCHANGE))  {
2405             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE)  {
2406                 usurf->animation.hide_time = time;
2407             }
2408             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW)  {
2409                 usurf->animation.show_time = time;
2410             }
2411             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE)  {
2412                 usurf->animation.move_time = time;
2413             }
2414             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE)    {
2415                 usurf->animation.resize_time = time;
2416             }
2417         }
2418     }
2419     else    {
2420         uifw_trace("uifw_set_animation: Surface(%08x) Not exist", surfaceid);
2421     }
2422 }
2423
2424 /*--------------------------------------------------------------------------*/
2425 /**
2426  * @brief   uifw_set_attributes: set surface attributes
2427  *
2428  * @param[in]   client      Weyland client
2429  * @param[in]   resource    resource of request
2430  * @param[in]   surfaceid   UIFW surface id
2431  * @param[in]   attributes  surface attributes
2432  * @return      none
2433  */
2434 /*--------------------------------------------------------------------------*/
2435 static void
2436 uifw_set_attributes(struct wl_client *client, struct wl_resource *resource,
2437                     uint32_t surfaceid, uint32_t attributes)
2438 {
2439     struct uifw_win_surface *usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
2440
2441     uifw_trace("uifw_set_attributes: Enter(surf=%08x,attributes=%x)", surfaceid, attributes);
2442
2443     if (usurf) {
2444         usurf->attributes = attributes;
2445         if ((attributes & (ICO_WINDOW_MGR_ATTR_ALIGN_LEFT|ICO_WINDOW_MGR_ATTR_ALIGN_RIGHT)) ==
2446             (ICO_WINDOW_MGR_ATTR_ALIGN_LEFT|ICO_WINDOW_MGR_ATTR_ALIGN_RIGHT))   {
2447             usurf->attributes &=
2448                 ~(ICO_WINDOW_MGR_ATTR_ALIGN_LEFT|ICO_WINDOW_MGR_ATTR_ALIGN_RIGHT);
2449         }
2450         if ((attributes & (ICO_WINDOW_MGR_ATTR_ALIGN_TOP|ICO_WINDOW_MGR_ATTR_ALIGN_BOTTOM)) ==
2451             (ICO_WINDOW_MGR_ATTR_ALIGN_TOP|ICO_WINDOW_MGR_ATTR_ALIGN_BOTTOM))   {
2452             usurf->attributes &=
2453                 ~(ICO_WINDOW_MGR_ATTR_ALIGN_TOP|ICO_WINDOW_MGR_ATTR_ALIGN_BOTTOM);
2454         }
2455     }
2456     uifw_trace("uifw_set_attributes: Leave");
2457 }
2458
2459 /*--------------------------------------------------------------------------*/
2460 /**
2461  * @brief   uifw_visible_animation: surface visibility control with animation
2462  *
2463  * @param[in]   client      Weyland client
2464  * @param[in]   resource    resource of request
2465  * @param[in]   surfaceid   surface id
2466  * @param[in]   visible     visible(1=show/0=hide)
2467  * @param[in]   x           X coordinate on screen(if bigger than 16383, no change)
2468  * @param[in]   y           Y coordinate on screen(if bigger than 16383, no change)
2469  * @param[in]   width       surface width(if bigger than 16383, no change)
2470  * @param[in]   height      surface height(if bigger than 16383, no change)
2471  * @return      none
2472  */
2473 /*--------------------------------------------------------------------------*/
2474 static void
2475 uifw_visible_animation(struct wl_client *client, struct wl_resource *resource,
2476                        uint32_t surfaceid, int32_t visible,
2477                        int32_t x, int32_t y, int32_t width, int32_t height)
2478 {
2479     struct uifw_win_surface *usurf;
2480
2481     uifw_trace("uifw_visible_animation: Enter(%08x,%d,x/y=%d/%d,w/h=%d/%d)",
2482                surfaceid, visible, x, y, width, height);
2483
2484     usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
2485
2486     if ((! usurf) || (! usurf->surface))    {
2487         uifw_trace("uifw_visible_animation: Leave(Surface Not Exist)");
2488         return;
2489     }
2490
2491     usurf->animation.pos_x = x;
2492     usurf->animation.pos_y = y;
2493     if (width > 0)  usurf->animation.pos_width = width;
2494     else            usurf->animation.pos_width = 1;
2495     if (height > 0) usurf->animation.pos_height = height;
2496     else            usurf->animation.pos_height = 1;
2497     usurf->animation.no_configure = 0;
2498
2499     uifw_set_visible(client, resource, surfaceid, visible,
2500                      ICO_WINDOW_MGR_V_NOCHANGE, ICO_WINDOW_MGR_ANIMATION_POS);
2501
2502     uifw_trace("uifw_visible_animation: Leave");
2503 }
2504
2505 /*--------------------------------------------------------------------------*/
2506 /**
2507  * @brief   uifw_set_active: set active surface
2508  *
2509  * @param[in]   client      Weyland client
2510  * @param[in]   resource    resource of request
2511  * @param[in]   surfaceid   UIFW surface id
2512  * @param[in]   active      target device
2513  * @return      none
2514  */
2515 /*--------------------------------------------------------------------------*/
2516 static void
2517 uifw_set_active(struct wl_client *client, struct wl_resource *resource,
2518                 uint32_t surfaceid, int32_t active)
2519 {
2520     struct uifw_win_surface *usurf;
2521
2522     uifw_trace("uifw_set_active: Enter(surf=%08x,active=%x)", surfaceid, active);
2523
2524     if ((surfaceid > 0) &&
2525         ((active & (ICO_WINDOW_MGR_ACTIVE_POINTER|ICO_WINDOW_MGR_ACTIVE_KEYBOARD)) != 0)) {
2526         usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
2527     }
2528     else    {
2529         usurf = NULL;
2530     }
2531     if (usurf) {
2532         switch (active & (ICO_WINDOW_MGR_ACTIVE_POINTER|ICO_WINDOW_MGR_ACTIVE_KEYBOARD)) {
2533         case ICO_WINDOW_MGR_ACTIVE_POINTER:
2534             if (usurf != _ico_win_mgr->active_pointer_usurf)  {
2535                 uifw_trace("uifw_set_active: pointer active change %08x->%08x",
2536                            _ico_win_mgr->active_pointer_usurf ?
2537                                _ico_win_mgr->active_pointer_usurf->surfaceid : 0,
2538                            usurf ? usurf->surfaceid : 0);
2539                 if (_ico_win_mgr->active_pointer_usurf)   {
2540                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2541                                             _ico_win_mgr->active_pointer_usurf,
2542                                             (_ico_win_mgr->active_keyboard_usurf ==
2543                                              _ico_win_mgr->active_pointer_usurf) ?
2544                                                 ICO_WINDOW_MGR_ACTIVE_KEYBOARD :
2545                                                 ICO_WINDOW_MGR_ACTIVE_NONE,
2546                                             0,0,0,0);
2547                 }
2548                 _ico_win_mgr->active_pointer_usurf = usurf;
2549                 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2550                                         usurf,
2551                                         ICO_WINDOW_MGR_ACTIVE_POINTER |
2552                                         (_ico_win_mgr->active_keyboard_usurf == usurf) ?
2553                                             ICO_WINDOW_MGR_ACTIVE_KEYBOARD : 0,
2554                                         0,0,0,0);
2555                 win_mgr_set_active(usurf, ICO_WINDOW_MGR_ACTIVE_POINTER);
2556             }
2557             break;
2558         case ICO_WINDOW_MGR_ACTIVE_KEYBOARD:
2559             if (usurf != _ico_win_mgr->active_keyboard_usurf) {
2560                 uifw_trace("uifw_set_active: keyboard active change %08x->%08x",
2561                            _ico_win_mgr->active_keyboard_usurf ?
2562                                _ico_win_mgr->active_keyboard_usurf->surfaceid : 0,
2563                            usurf ? usurf->surfaceid : 0);
2564                 if (_ico_win_mgr->active_keyboard_usurf)   {
2565                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2566                                             _ico_win_mgr->active_keyboard_usurf,
2567                                             (_ico_win_mgr->active_keyboard_usurf ==
2568                                              _ico_win_mgr->active_pointer_usurf) ?
2569                                                 ICO_WINDOW_MGR_ACTIVE_POINTER :
2570                                                 ICO_WINDOW_MGR_ACTIVE_NONE,
2571                                             0,0,0,0);
2572                 }
2573                 _ico_win_mgr->active_keyboard_usurf = usurf;
2574                 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2575                                         usurf,
2576                                         ICO_WINDOW_MGR_ACTIVE_KEYBOARD |
2577                                         (_ico_win_mgr->active_pointer_usurf == usurf) ?
2578                                             ICO_WINDOW_MGR_ACTIVE_POINTER : 0,
2579                                         0,0,0,0);
2580                 win_mgr_set_active(usurf, ICO_WINDOW_MGR_ACTIVE_KEYBOARD);
2581             }
2582             break;
2583         default:
2584             if ((usurf != _ico_win_mgr->active_pointer_usurf) ||
2585                 (usurf != _ico_win_mgr->active_keyboard_usurf))   {
2586                 uifw_trace("uifw_set_active: active change %08x/%08x->%08x",
2587                            _ico_win_mgr->active_pointer_usurf ?
2588                                _ico_win_mgr->active_pointer_usurf->surfaceid : 0,
2589                            _ico_win_mgr->active_keyboard_usurf ?
2590                                _ico_win_mgr->active_keyboard_usurf->surfaceid : 0,
2591                            usurf ? usurf->surfaceid : 0);
2592                 if (_ico_win_mgr->active_pointer_usurf)   {
2593                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2594                                             _ico_win_mgr->active_pointer_usurf,
2595                                             ICO_WINDOW_MGR_ACTIVE_NONE,
2596                                             0,0,0,0);
2597                     if (_ico_win_mgr->active_keyboard_usurf ==
2598                         _ico_win_mgr->active_pointer_usurf)   {
2599                         _ico_win_mgr->active_keyboard_usurf = NULL;
2600                     }
2601                 }
2602                 if (_ico_win_mgr->active_keyboard_usurf)   {
2603                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2604                                             _ico_win_mgr->active_keyboard_usurf,
2605                                             ICO_WINDOW_MGR_ACTIVE_NONE,
2606                                             0,0,0,0);
2607                 }
2608                 _ico_win_mgr->active_pointer_usurf = usurf;
2609                 _ico_win_mgr->active_keyboard_usurf = usurf;
2610                 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2611                                         usurf,
2612                                         ICO_WINDOW_MGR_ACTIVE_POINTER |
2613                                             ICO_WINDOW_MGR_ACTIVE_KEYBOARD,
2614                                         0,0,0,0);
2615                 win_mgr_set_active(usurf, ICO_WINDOW_MGR_ACTIVE_POINTER |
2616                                               ICO_WINDOW_MGR_ACTIVE_KEYBOARD);
2617             }
2618             break;
2619         }
2620         uifw_trace("uifw_set_active: Leave(Change Active)");
2621     }
2622     else    {
2623         win_mgr_set_active(NULL, active);
2624         uifw_trace("uifw_set_active: Leave(Reset active surface)");
2625     }
2626 }
2627
2628 /*--------------------------------------------------------------------------*/
2629 /**
2630  * @brief   uifw_set_layer_visible: layer visible control
2631  *
2632  * @param[in]   client      Weyland client
2633  * @param[in]   resource    resource of request
2634  * @param[in]   layer       layer id
2635  * @param[in]   visible     visible(1=show/0=hide)
2636  * @return      none
2637  */
2638 /*--------------------------------------------------------------------------*/
2639 static void
2640 uifw_set_layer_visible(struct wl_client *client, struct wl_resource *resource,
2641                        uint32_t layer, int32_t visible)
2642 {
2643     struct uifw_win_layer   *el;
2644     struct uifw_win_layer   *new_el;
2645     struct uifw_win_surface *usurf;
2646     int     layertype = 0;
2647
2648     if ((layer == ICO_WINDOW_MGR_LAYERTYPE_BACKGROUND) ||
2649         (layer == (uint32_t)_ico_ivi_background_layer))   {
2650         layer = _ico_ivi_background_layer;
2651         layertype = LAYER_TYPE_BACKGROUND;
2652     }
2653     else if ((layer == ICO_WINDOW_MGR_LAYERTYPE_TOUCH) ||
2654              (layer == (uint32_t)_ico_ivi_touch_layer))   {
2655         layer = _ico_ivi_touch_layer;
2656         layertype = LAYER_TYPE_TOUCH;
2657     }
2658     else if ((layer == ICO_WINDOW_MGR_LAYERTYPE_CURSOR) ||
2659              (layer == (uint32_t)_ico_ivi_cursor_layer))  {
2660         layer = _ico_ivi_cursor_layer;
2661         layertype = LAYER_TYPE_CURSOR;
2662     }
2663     else if (layer == ICO_WINDOW_MGR_LAYERTYPE_STARTUP)    {
2664         layer = _ico_ivi_startup_layer;
2665     }
2666
2667     uifw_trace("uifw_set_layer_visible: Enter(layer=%d, visilbe=%d)", layer, visible);
2668
2669     /* Search Layer                             */
2670     wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
2671         if (el->layer == layer) break;
2672     }
2673
2674     if (&el->link == &_ico_win_mgr->ivi_layer_list)    {
2675         /* layer not exist, create new layer    */
2676         uifw_trace("uifw_set_layer_visible: New Layer %d", layer);
2677         new_el = win_mgr_create_layer(NULL, layer, layertype);
2678         if (! new_el)   {
2679             uifw_trace("uifw_set_layer_visible: Leave(No Memory)");
2680             return;
2681         }
2682         new_el->visible = (visible != 0) ? TRUE : FALSE;
2683         ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_LAYER_VISIBLE, NULL,
2684                                 layer, new_el->visible, 0,0,0);
2685         uifw_trace("uifw_set_layer_visible: Leave(new layer)");
2686         return;
2687     }
2688
2689     /* control all surface in layer */
2690     if ((el->visible != FALSE) && (visible == 0))   {
2691         /* layer change to NOT visible  */
2692         uifw_trace("uifw_set_layer_visible: change to not visible");
2693         el->visible = FALSE;
2694     }
2695     else if ((el->visible == FALSE) && (visible != 0))  {
2696         /* layer change to visible      */
2697         uifw_trace("uifw_set_layer_visible: change to visible");
2698         el->visible = TRUE;
2699     }
2700     else    {
2701         /* no change    */
2702         uifw_trace("uifw_set_layer_visible: Leave(no Change %d=>%d)",
2703                    el->visible, visible);
2704         return;
2705     }
2706
2707     /* set damege area          */
2708     wl_list_for_each (usurf, &el->surface_list, ivi_layer) {
2709         if ((usurf->visible != FALSE) && (usurf->surface != NULL) &&
2710             (usurf->surface->output != NULL))  {
2711             /* Reset focus if hide              */
2712             if (visible == 0)   {
2713                 win_mgr_reset_focus(usurf);
2714             }
2715             /* Damage(redraw) target surface    */
2716             weston_surface_damage_below(usurf->surface);
2717         }
2718     }
2719
2720     /* rebild compositor surface list       */
2721     ico_window_mgr_restack_layer(NULL);
2722
2723     /* send layer visible event to manager  */
2724     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_LAYER_VISIBLE, NULL,
2725                             layer, el->visible, 0,0,0);
2726
2727     uifw_trace("uifw_set_layer_visible: Leave");
2728 }
2729
2730 /*--------------------------------------------------------------------------*/
2731 /**
2732  * @brief   uifw_get_surfaces: get application surfaces
2733  *
2734  * @param[in]   client      Weyland client
2735  * @param[in]   resource    resource of request
2736  * @param[in]   appid       application id
2737  * @param[in]   pid         process id
2738  * @return      none
2739  */
2740 /*--------------------------------------------------------------------------*/
2741 static void
2742 uifw_get_surfaces(struct wl_client *client, struct wl_resource *resource,
2743                   const char *appid, int32_t pid)
2744 {
2745     struct uifw_client  *uclient;
2746     struct uifw_win_layer *el;
2747     struct uifw_win_surface *usurf;
2748     struct wl_array     reply;
2749     uint32_t            *up;
2750
2751     uifw_trace("uifw_get_surfaces: Enter(appid=%s, pid=%d)", appid ? appid : " ", pid);
2752
2753     wl_array_init(&reply);
2754
2755     wl_list_for_each (uclient, &_ico_win_mgr->client_list, link)    {
2756         if ((appid != NULL) && (*appid != ' ')) {
2757             if (strcmp(uclient->appid, appid) == 0) break;
2758         }
2759         if (pid != 0)   {
2760             if (uclient->pid == pid)    break;
2761         }
2762     }
2763     if (&uclient->link == &_ico_win_mgr->client_list)    {
2764         uifw_trace("uifw_get_surfaces: appid=%s pid=%d dose not exist",
2765                    appid ? appid : " ", pid);
2766     }
2767     else    {
2768         wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
2769             wl_list_for_each (usurf, &el->surface_list, ivi_layer) {
2770                 if (usurf->uclient == uclient)  {
2771                     uifw_trace("uifw_get_surfaces: %s(%d) surf=%08x",
2772                                uclient->appid, uclient->pid, usurf->surfaceid);
2773                     up = (uint32_t *)wl_array_add(&reply, sizeof(uint32_t));
2774                     if (up) {
2775                         *up = usurf->surfaceid;
2776                     }
2777                 }
2778             }
2779         }
2780     }
2781     ico_window_mgr_send_app_surfaces(resource, uclient->appid, uclient->pid, &reply);
2782
2783     wl_array_release(&reply);
2784     uifw_trace("uifw_get_surfaces: Leave");
2785 }
2786
2787 /*--------------------------------------------------------------------------*/
2788 /**
2789  * @brief   win_mgr_check_mapsurface: check and change all surface
2790  *
2791  * @param[in]   animation   weston animation table(unused)
2792  * @param[in]   outout      weston output table(unused)
2793  * @param[in]   mseces      current time(unused)
2794  * @return      none
2795  */
2796 /*--------------------------------------------------------------------------*/
2797 static void
2798 win_mgr_check_mapsurface(struct weston_animation *animation,
2799                          struct weston_output *output, uint32_t msecs)
2800 {
2801     struct uifw_surface_map *sm;
2802     uint32_t    curtime;
2803     int         wait = 99999999;
2804
2805     /* check touch down counter     */
2806     if (touch_check_seat)   {
2807         if (touch_check_seat->num_tp > 10)  {
2808             uifw_trace("win_mgr_check_mapsurface: illegal touch counter(num=%d), reset",
2809                        (int)touch_check_seat->num_tp);
2810             touch_check_seat->num_tp = 0;
2811         }
2812     }
2813
2814     /* check all mapped surfaces    */
2815     curtime = weston_compositor_get_time();
2816     wl_list_for_each (sm, &_ico_win_mgr->map_list, map_link) {
2817         uifw_detail("win_mgr_check_mapsurface: sm=%08x surf=%08x",
2818                     (int)sm, sm->usurf->surfaceid);
2819         win_mgr_change_mapsurface(sm, 0, curtime);
2820         if (sm->eventque)   {
2821             if (sm->interval < wait)    {
2822                 wait = sm->interval;
2823             }
2824         }
2825     }
2826
2827     /* check frame interval         */
2828     if (wait < 2000)    {
2829         wait = wait / 2;
2830     }
2831     else    {
2832         wait = 1000;
2833     }
2834     wl_event_source_timer_update(_ico_win_mgr->wait_mapevent, wait);
2835 }
2836
2837 /*--------------------------------------------------------------------------*/
2838 /**
2839  * @brief   win_mgr_timer_mapsurface: mapped surface check timer
2840  *
2841  * @param[in]   data        user data(unused)
2842  * @return      fixed 1
2843  */
2844 /*--------------------------------------------------------------------------*/
2845 static int
2846 win_mgr_timer_mapsurface(void *data)
2847 {
2848     win_mgr_check_mapsurface(NULL, NULL, 0);
2849     return 1;
2850 }
2851
2852 /*--------------------------------------------------------------------------*/
2853 /**
2854  * @brief   win_mgr_change_mapsurface: check and change mapped surface
2855  *
2856  * @param[in]   sm          map surface table
2857  * @param[in]   event       send event (if 0, send if changed)
2858  * @param[in]   curtime     current time(ms)
2859  * @return      none
2860  */
2861 /*--------------------------------------------------------------------------*/
2862 static void
2863 win_mgr_change_mapsurface(struct uifw_surface_map *sm, int event, uint32_t curtime)
2864 {
2865     struct uifw_drm_buffer  *drm_buffer;
2866     struct uifw_dri_image   *dri_image;
2867     struct uifw_intel_region  *dri_region;
2868     struct uifw_gl_surface_state *gl_state;
2869     struct weston_surface   *es;
2870     uint32_t    eglname;
2871     int         width;
2872     int         height;
2873     int         stride;
2874     uint32_t    format;
2875     uint32_t    dtime;
2876     int         idx, idx2;
2877     int         delta, settime2;
2878     struct ico_uifw_image_buffer    *p;
2879
2880     uifw_detail("win_mgr_change_mapsurface: surf=%08x event=%d", sm->usurf->surfaceid, event);
2881     if (event == 0) {
2882         event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_CONTENTS;
2883     }
2884
2885     /* check if buffered        */
2886     drm_buffer = NULL;
2887     es = sm->usurf->surface;
2888     if ((es == NULL) ||
2889         ((sm->type == ICO_WINDOW_MGR_MAP_TYPE_EGL) &&
2890          ((es->buffer_ref.buffer == NULL) ||
2891           (es->buffer_ref.buffer->width <= 0) || (es->buffer_ref.buffer->height <= 0)))) {
2892         /* surface has no buffer    */
2893         uifw_debug("win_mgr_change_mapsurface: surface(%08x) has no buffer %08x %08x",
2894                    sm->usurf->surfaceid, (int)es,
2895                    es ? (int)es->buffer_ref.buffer : 0);
2896         if (sm->initflag)   {
2897             event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP;
2898         }
2899         else    {
2900             event = 0;
2901         }
2902     }
2903     else if (sm->type == ICO_WINDOW_MGR_MAP_TYPE_EGL)   {
2904         if ((es->buffer_ref.buffer->legacy_buffer != NULL) && (es->renderer_state != NULL)) {
2905             drm_buffer = (struct uifw_drm_buffer *)wl_resource_get_user_data(
2906                                 (struct wl_resource *)es->buffer_ref.buffer->legacy_buffer);
2907             if ((drm_buffer != NULL) && (drm_buffer->driver_buffer == NULL))    {
2908                 drm_buffer = NULL;
2909             }
2910         }
2911         if (drm_buffer == NULL) {
2912             /* surface has no buffer    */
2913             uifw_debug("win_mgr_change_mapsurface: surface(%08x) has no buffer",
2914                        sm->usurf->surfaceid);
2915             if (sm->initflag)   {
2916                 event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP;
2917             }
2918             else    {
2919                 event = 0;
2920             }
2921         }
2922     }
2923     else if (sm->uclient->shmbuf == NULL)   {
2924         /* no GPU acceleration but no buffer    */
2925         uifw_debug("win_mgr_change_mapsurface: client has no shared memory buffer");
2926         if (sm->initflag)   {
2927             event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP;
2928         }
2929         else    {
2930             event = 0;
2931         }
2932     }
2933
2934     if ((event != 0) && (event != ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP))  {
2935
2936         if (sm->type == ICO_WINDOW_MGR_MAP_TYPE_EGL)    {
2937             gl_state = (struct uifw_gl_surface_state *)es->renderer_state;
2938             if (gl_state->buffer_type == BUFFER_TYPE_SHM)   {
2939                 event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR;
2940             }
2941             else if (gl_state->buffer_type != BUFFER_TYPE_EGL)   {
2942                 event = 0;
2943             }
2944             else    {
2945                 dri_image = (struct uifw_dri_image *)drm_buffer->driver_buffer;
2946                 dri_region = dri_image->region;
2947                 width = es->buffer_ref.buffer->width;
2948                 height = es->buffer_ref.buffer->height;
2949                 stride = drm_buffer->stride[0];
2950                 if (drm_buffer->format == __DRI_IMAGE_FOURCC_XRGB8888)  {
2951                     format = EGL_TEXTURE_RGB;
2952                 }
2953                 else if (drm_buffer->format == __DRI_IMAGE_FOURCC_ARGB8888) {
2954                     format = EGL_TEXTURE_RGBA;
2955                 }
2956                 else    {
2957                     /* unknown format, error    */
2958                     format = EGL_NO_TEXTURE;
2959                 }
2960                 eglname = dri_region->name;
2961                 if (eglname == 0)   {
2962                     if (drm_intel_bo_flink((drm_intel_bo *)dri_region->bo, &eglname))   {
2963                         uifw_warn("win_mgr_change_mapsurface: drm_intel_bo_flink() Error");
2964                         eglname = 0;
2965                     }
2966                 }
2967                 if ((sm->initflag == 0) && (eglname != 0) &&
2968                     (width > 0) && (height > 0) && (stride > 0))    {
2969                     sm->initflag = 1;
2970                     event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_MAP;
2971                 }
2972                 else    {
2973                     if ((eglname == 0) || (width <= 0) || (height <= 0) || (stride <= 0))   {
2974                         event = 0;
2975                     }
2976                     else if (event == ICO_WINDOW_MGR_MAP_SURFACE_EVENT_CONTENTS)    {
2977                         if ((sm->width != width) || (sm->height != height) ||
2978                             (sm->stride != stride) || (format != sm->format))   {
2979                             event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_RESIZE;
2980                         }
2981                         else if (eglname != sm->eglname)    {
2982 #if  PERFORMANCE_EVALUATIONS > 0
2983                             uifw_perf("SWAP_BUFFER appid=%s surface=%08x name=%d",
2984                                       sm->usurf->uclient->appid, sm->usurf->surfaceid,
2985                                       sm->eglname);
2986 #endif /*PERFORMANCE_EVALUATIONS*/
2987                             dtime = curtime - sm->lasttime;
2988                             if ((sm->interval > 0) && (dtime < sm->interval))   {
2989                                 sm->eventque = 1;
2990                                 event = 0;
2991                             }
2992                         }
2993                         else if (sm->eventque)  {
2994                             dtime = curtime - sm->lasttime;
2995                             if ((sm->interval > 0) && (dtime < sm->interval))   {
2996                                 event = 0;
2997                             }
2998                         }
2999                         else    {
3000                             event =0;
3001                         }
3002                     }
3003                 }
3004                 sm->width = width;
3005                 sm->height = height;
3006                 sm->stride = stride;
3007                 sm->eglname = eglname;
3008                 sm->format = format;
3009             }
3010         }
3011         else    {
3012             if ((sm->type != ICO_WINDOW_MGR_MAP_TYPE_PIXEL) || (sm->eventque != 0) ||
3013                 (es->buffer_ref.buffer == NULL) || (es->buffer_ref.buffer != sm->curbuf)) {
3014                 sm->curbuf = es->buffer_ref.buffer;
3015                 if (es->buffer_ref.buffer != NULL)  {
3016                     width = es->buffer_ref.buffer->width;
3017                     height = es->buffer_ref.buffer->height;
3018                 }
3019                 else    {
3020                     width = sm->usurf->client_width;
3021                     height = sm->usurf->client_height;
3022                 }
3023                 /* get shared memory buffer area    */
3024                 idx2 = sm->uclient->bufnum;
3025                 settime2 = 0x7fffffff;
3026                 for (idx = 0; idx < sm->uclient->bufnum; idx++) {
3027                     p = (struct ico_uifw_image_buffer *)
3028                         (((char *)sm->uclient->shmbuf) + idx * sm->uclient->bufsize);
3029                     if (p->settime == p->reftime)   break;
3030                     delta = curtime - p->settime;
3031                     if (delta < 0)  {
3032                         delta = delta + 0x80000000;
3033                     }
3034                     if ((delta > 3000) && (delta < settime2))   {
3035                         idx2 = idx;
3036                         settime2 = p->settime;
3037                     }
3038                 }
3039                 uifw_detail("win_mgr_change_mapsurface: PIX %08x idx=%d idx2=%d w/h=%d/%d",
3040                             sm->usurf->surfaceid, idx, idx2, width, height);
3041                 if (idx >= sm->uclient->bufnum) {
3042                     idx = idx2;
3043                 }
3044                 if (idx >= sm->uclient->bufnum) {
3045                     uifw_debug("win_mgr_change_mapsurface: shared buffer full");
3046                     event = 0;
3047                     sm->curbuf = NULL;
3048                     sm->eventque = 1;
3049                 }
3050                 else if ((sm->initflag == 0) && (width > 0) && (height > 0))    {
3051                     sm->initflag = 1;
3052                     event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_MAP;
3053                     uifw_detail("win_mgr_change_mapsurface: PIX MAP event %08x",
3054                                 sm->usurf->surfaceid);
3055                 }
3056                 else    {
3057                     if ((width <= 0) || (height <= 0))  {
3058                         event = 0;
3059                         sm->curbuf = NULL;
3060                         uifw_detail("win_mgr_change_mapsurface: PIX %08x w/h=0/0",
3061                                     sm->usurf->surfaceid);
3062                     }
3063                     else if (event == ICO_WINDOW_MGR_MAP_SURFACE_EVENT_CONTENTS)    {
3064 #if  PERFORMANCE_EVALUATIONS > 0
3065                         if (sm->type != ICO_WINDOW_MGR_MAP_TYPE_SHM)    {
3066                             uifw_perf("SWAP_BUFFER appid=%s surface=%08x",
3067                                       sm->usurf->uclient->appid, sm->usurf->surfaceid);
3068                         }
3069 #endif /*PERFORMANCE_EVALUATIONS*/
3070                         if ((sm->width != width) || (sm->height != height)) {
3071                             event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_RESIZE;
3072                         }
3073                         else    {
3074                             dtime = curtime - sm->lasttime;
3075                             if ((sm->interval > 0) && (dtime < sm->interval))   {
3076                                 sm->eventque = 1;
3077                                 event = 0;
3078                                 uifw_detail("win_mgr_change_mapsurface: PIX %08x new queue",
3079                                             sm->usurf->surfaceid);
3080                             }
3081                             else if (sm->eventque)  {
3082                                 dtime = curtime - sm->lasttime;
3083                                 if ((sm->interval > 0) && (dtime < sm->interval))   {
3084                                     event = 0;
3085                                     uifw_detail("win_mgr_change_mapsurface: PIX %08x queued",
3086                                                 sm->usurf->surfaceid);
3087                                 }
3088                             }
3089                         }
3090                     }
3091                 }
3092                 sm->width = width;
3093                 sm->height = height;
3094                 sm->stride = width;
3095                 sm->format = EGL_TEXTURE_RGBA;
3096                 if (event != 0) {
3097                     /* read pixel           */
3098                     p = (struct ico_uifw_image_buffer *)
3099                         (((char *)sm->uclient->shmbuf) + idx * sm->uclient->bufsize);
3100                     height = (sm->uclient->bufsize - sizeof(struct ico_uifw_image_buffer))
3101                              / (width * 4);
3102                     uifw_detail("win_mgr_change_mapsurface: PIX read buf=%08x height=%d(%d)",
3103                                 (int)p, height, sm->height);
3104                     if ((height < sm->height) &&
3105                         (sm->type == ICO_WINDOW_MGR_MAP_TYPE_SHM))  {
3106                         uifw_warn("win_mgr_change_mapsurface: Buffer SHM, "
3107                                   "but buffer overflow(%d>%d)", sm->height, height);
3108                         event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR;
3109                         sm->eventque = 0;
3110                     }
3111                     else    {
3112                         if (height > sm->height)    {
3113                             height = sm->height;
3114                         }
3115                         if ((*(_ico_win_mgr->compositor->renderer->read_surface_pixels))
3116                                     (es, PIXMAN_a8r8g8b8, p->image,
3117                                      0, 0, sm->width, height) != 0) {
3118                             uifw_debug("win_mgr_change_mapsurface: Error read pixel %s.%08x",
3119                                        sm->usurf->uclient->appid, sm->usurf->surfaceid);
3120                             event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR;
3121                             sm->eventque = 0;
3122                         }
3123                         else    {
3124                             uifw_detail("win_mgr_change_mapsurface: PIX read pixels(%d)",
3125                                         idx+1);
3126                             p->surfaceid = sm->usurf->surfaceid;
3127                             p->settime = curtime;
3128                             p->width = sm->width;
3129                             p->height = height;
3130                             sm->eglname = idx + 1;
3131                         }
3132                     }
3133                 }
3134             }
3135             else    {
3136                 event = 0;
3137             }
3138         }
3139     }
3140
3141     if (event != 0) {
3142         uifw_detail("win_mgr_change_mapsurface: send MAP event(ev=%d surf=%08x type=%d "
3143                     "name=%d w/h/s=%d/%d/%d format=%x",
3144                     event, sm->usurf->surfaceid, sm->type, sm->eglname,
3145                     sm->width, sm->height, sm->stride, sm->format);
3146         sm->lasttime = curtime;
3147         sm->eventque = 0;
3148         ico_window_mgr_send_map_surface(sm->uclient->mgr->resource, event,
3149                                         sm->usurf->surfaceid, sm->type, sm->eglname,
3150                                         sm->width, sm->height, sm->stride, sm->format);
3151         if (event == ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR)    {
3152             /* free map table if error  */
3153             wl_list_remove(&sm->surf_link);
3154             wl_list_remove(&sm->map_link);
3155             sm->usurf = (struct uifw_win_surface *)_ico_win_mgr->free_maptable;
3156             _ico_win_mgr->free_maptable = sm;
3157         }
3158     }
3159 }
3160
3161 /*--------------------------------------------------------------------------*/
3162 /**
3163  * @brief   uifw_set_map_buffer: set map surface image buffer
3164  *
3165  * @param[in]   client      Weyland client
3166  * @param[in]   resource    resource of request
3167  * @param[in]   shmname     shared memory name(POSIX I/F)
3168  * @param[in]   bufsize     buffer size in byte
3169  * @param[in]   bufnum      number of buffers
3170  * @return      none
3171  */
3172 /*--------------------------------------------------------------------------*/
3173 static void
3174 uifw_set_map_buffer(struct wl_client *client, struct wl_resource *resource,
3175                     const char *shmname, uint32_t bufsize, uint32_t bufnum)
3176 {
3177     struct uifw_client              *uclient;
3178     struct ico_uifw_image_buffer    *p;
3179     char    *shmbuf;
3180     int     shmfd;
3181     int     i;
3182
3183     uifw_trace("uifw_set_map_buffer: Enter(%s,%d,%d)",
3184                shmname ? shmname : "(null)", bufsize, bufnum);
3185
3186     uclient = find_client_from_client(client);
3187     if ((! uclient) || (! uclient->mgr))    {
3188         /* client dose not exist, error         */
3189         uifw_trace("uifw_set_map_buffer: Leave(client=%08x dose not exist)", (int)client);
3190         return;
3191     }
3192
3193     if ((shmname == NULL) || (*shmname == 0) || (*shmname == ' ') ||
3194         (bufsize == 0) || (bufnum == 0))    {
3195         /* delete shared memory buffer          */
3196         if (uclient->shmbuf)    {
3197             munmap(uclient->shmbuf, uclient->bufsize * uclient->bufnum);
3198             uclient->shmbuf = NULL;
3199         }
3200         uifw_trace("uifw_set_map_buffer: Leave(delete shared memory buffer)");
3201         return;
3202     }
3203
3204     shmfd = shm_open(shmname, O_RDWR, 0600);
3205     if (shmfd == -1)    {
3206         /* shared memory dose not exist         */
3207         uifw_trace("uifw_set_map_buffer: Leave(shared memory(%s) dose not exist)", shmname);
3208         return;
3209     }
3210
3211     shmbuf = (char *)mmap(NULL, bufsize * bufnum, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
3212     close(shmfd);
3213
3214     if (shmbuf == NULL) {
3215         /* can not map shared memory            */
3216         uifw_trace("uifw_set_map_buffer: Leave(can not map shared memory(%s))", shmname);
3217         return;
3218     }
3219     if (uclient->shmbuf)    {
3220         munmap(uclient->shmbuf, uclient->bufsize * uclient->bufnum);
3221     }
3222
3223     uclient->shmbuf = shmbuf;
3224     uclient->bufsize = bufsize;
3225     uclient->bufnum = bufnum;
3226     for (i = 0; i < (int)bufnum; i++)    {
3227         p = (struct ico_uifw_image_buffer *)(((char *)shmbuf) + bufsize * i);
3228         memset((char *)p, 0, sizeof(struct ico_uifw_image_buffer));
3229         memcpy((char *)&p->magich, ICO_UIFW_IMAGE_BUFFER_MAGICH, 4);
3230         memcpy((char *)&p->magict, ICO_UIFW_IMAGE_BUFFER_MAGICT, 4);
3231     }
3232     uifw_trace("uifw_set_map_buffer: Leave(shm addr=%08x)", (int)uclient->shmbuf);
3233 }
3234
3235 /*--------------------------------------------------------------------------*/
3236 /**
3237  * @brief   uifw_map_surface: mapped surface buffer to system application
3238  *
3239  * @param[in]   client      Weyland client
3240  * @param[in]   resource    resource of request
3241  * @param[in]   surfaceid   surface id
3242  * @param[in]   framerate   frame rate of surface update(frame/sec)
3243  * @return      none
3244  */
3245 /*--------------------------------------------------------------------------*/
3246 static void
3247 uifw_map_surface(struct wl_client *client, struct wl_resource *resource,
3248                  uint32_t surfaceid, int32_t framerate)
3249 {
3250     struct uifw_win_surface     *usurf;
3251     struct weston_surface       *es;
3252     struct uifw_surface_map     *sm;
3253     struct weston_buffer        *buffer;
3254     struct uifw_client          *uclient;
3255     struct uifw_drm_buffer      *drm_buffer;
3256     struct uifw_gl_surface_state *gl_state;
3257     int     maptype;
3258
3259     uifw_trace("uifw_map_surface: Enter(surface=%08x,fps=%d)", surfaceid, framerate);
3260
3261     usurf = ico_window_mgr_get_usurf(surfaceid);
3262     if (! usurf)    {
3263         /* surface dose not exist, error        */
3264         ico_window_mgr_send_map_surface(resource, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
3265                                         surfaceid, 1, 0, 0, 0, 0, 0);
3266         uifw_trace("uifw_map_surface: Leave(surface=%08x dose not exist)", surfaceid);
3267         return;
3268     }
3269     uclient = find_client_from_client(client);
3270     if ((! uclient) || (! uclient->mgr))    {
3271         /* client dose not exist, error         */
3272         ico_window_mgr_send_map_surface(resource, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
3273                                         surfaceid, 2, 0, 0, 0, 0, 0);
3274         uifw_trace("uifw_map_surface: Leave(client=%08x dose not exist)", (int)client);
3275         return;
3276     }
3277
3278     /* check if buffered        */
3279     es = usurf->surface;
3280     if (es == NULL) {
3281         /* surface has no buffer, error         */
3282         ico_window_mgr_send_map_surface(resource, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
3283                                         surfaceid, 3, 0, 0, 0, 0, 0);
3284         uifw_trace("uifw_map_surface: Leave(surface(%08x) has no surface)", surfaceid);
3285         return;
3286     }
3287
3288     /* check buffer type        */
3289     gl_state = (struct uifw_gl_surface_state *)es->renderer_state;
3290     if ((_ico_ivi_gpu_type == ICO_GPUTYPE_NOACCELERATION) ||
3291         (gl_state == NULL) || (gl_state->buffer_type == BUFFER_TYPE_SHM))   {
3292         /* wl_shm_buffer support ReadPixels     */
3293         if ((_ico_win_mgr->compositor->renderer == NULL) ||
3294             (_ico_win_mgr->compositor->renderer->read_surface_pixels == NULL))  {
3295             ico_window_mgr_send_map_surface(resource, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
3296                                             surfaceid, 4, 0, 0, 0, 0, 0);
3297             uifw_trace("uifw_map_surface: Leave(surface(%08x) not support ReadPixels)",
3298                        surfaceid);
3299             return;
3300         }
3301         else if ((gl_state != NULL) && (gl_state->buffer_type == BUFFER_TYPE_SHM) &&
3302                 (es->buffer_ref.buffer != NULL))    {
3303             maptype = ICO_WINDOW_MGR_MAP_TYPE_SHM;
3304         }
3305         else    {
3306             maptype = ICO_WINDOW_MGR_MAP_TYPE_PIXEL;
3307         }
3308         if (uclient->shmbuf == NULL)    {
3309             /* ReadPixcels but client has no shared memory buffer   */
3310             ico_window_mgr_send_map_surface(resource, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
3311                                             surfaceid, 5, 0, 0, 0, 0, 0);
3312             uifw_trace("uifw_map_surface: Leave(client has no shared memory buffer)");
3313             return;
3314         }
3315     }
3316     else    {
3317         /* H/W(GPU) driver EGL buffer (Intel only)  */
3318         maptype = ICO_WINDOW_MGR_MAP_TYPE_EGL;
3319     }
3320
3321     /* maximum framerate        */
3322     if (maptype == ICO_WINDOW_MGR_MAP_TYPE_EGL) {
3323         if ((framerate <= 0) || (framerate > _ico_ivi_map_framerate_gpu))
3324             framerate = _ico_ivi_map_framerate_gpu;
3325     }
3326     else if (maptype == ICO_WINDOW_MGR_MAP_TYPE_SHM) {
3327         if ((framerate <= 0) || (framerate > _ico_ivi_map_framerate_shm))
3328             framerate = _ico_ivi_map_framerate_shm;
3329     }
3330     else    {
3331         if ((framerate <= 0) || (framerate > _ico_ivi_map_framerate_pixel))
3332             framerate = _ico_ivi_map_framerate_pixel;
3333     }
3334
3335     /* check same surface       */
3336     wl_list_for_each(sm, &usurf->surf_map, surf_link) {
3337         if ((sm->usurf == usurf) && (sm->uclient == uclient))   {
3338             break;
3339         }
3340     }
3341
3342     if (&sm->surf_link == &usurf->surf_map) {
3343         /* create map table         */
3344         sm = _ico_win_mgr->free_maptable;
3345         if (sm) {
3346             _ico_win_mgr->free_maptable = (struct uifw_surface_map *)sm->usurf;
3347         }
3348         else    {
3349             sm = (struct uifw_surface_map *)malloc(sizeof(struct uifw_surface_map));
3350             if (! sm)   {
3351                 ico_window_mgr_send_map_surface(resource,
3352                                                 ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
3353                                                 surfaceid, 6, 0, 0, 0, 0, 0);
3354                 uifw_trace("uifw_map_surface: Leave(malloc error)");
3355                 return;
3356             }
3357         }
3358         memset(sm, 0, sizeof(struct uifw_surface_map));
3359
3360         wl_list_init(&sm->map_link);
3361         wl_list_init(&sm->surf_link);
3362         sm->usurf = usurf;
3363         sm->uclient = uclient;
3364         sm->type = maptype;
3365         sm->framerate = framerate;
3366         sm->interval = (1000 / sm->framerate) - 1;
3367         wl_list_insert(_ico_win_mgr->map_list.next, &sm->map_link);
3368         wl_list_insert(usurf->surf_map.prev, &sm->surf_link);
3369     }
3370     else    {
3371         /* change frame rate    */
3372         uifw_trace("uifw_map_surface: Leave(chagne frame rate %d->%d",
3373                    sm->framerate, framerate);
3374         if (sm->framerate != framerate) {
3375             sm->framerate = framerate;
3376             sm->interval = (1000 / sm->framerate) - 1;
3377             win_mgr_change_mapsurface(sm, 0, weston_compositor_get_time());
3378         }
3379         return;
3380     }
3381
3382     buffer = es->buffer_ref.buffer;
3383     if (buffer != NULL) {
3384         sm->width = buffer->width;
3385         sm->height = buffer->height;
3386         if (maptype != ICO_WINDOW_MGR_MAP_TYPE_EGL) {
3387             sm->stride = sm->width;
3388             sm->format = EGL_TEXTURE_RGBA;
3389             if ((sm->width > 0) && (sm->height > 0))    {
3390                 sm->initflag = 1;
3391             }
3392             uifw_debug("uifw_map_surface: map type=%d,surface=%08x,fps=%d,w/h=%d/%d",
3393                        maptype, surfaceid, framerate, buffer->width, buffer->height);
3394         }
3395         else    {
3396             drm_buffer = (struct uifw_drm_buffer *)wl_resource_get_user_data(
3397                                             (struct wl_resource *)buffer->legacy_buffer);
3398             if (drm_buffer != NULL) {
3399                 sm->stride = drm_buffer->stride[0];
3400                 if (drm_buffer->format == __DRI_IMAGE_FOURCC_XRGB8888)  {
3401                     sm->format = EGL_TEXTURE_RGB;
3402                 }
3403                 else if (drm_buffer->format == __DRI_IMAGE_FOURCC_ARGB8888) {
3404                     sm->format = EGL_TEXTURE_RGBA;
3405                 }
3406                 else    {
3407                     /* unknown format, error    */
3408                     sm->format = EGL_NO_TEXTURE;
3409                 }
3410                 if ((sm->width > 0) && (sm->height > 0) && (sm->stride > 0) &&
3411                     (gl_state != NULL))  {
3412                     sm->initflag = 1;
3413                 }
3414                 uifw_debug("uifw_map_surface: map EGL surface=%08x,fps=%d,w/h=%d/%d",
3415                            surfaceid, framerate, buffer->width, buffer->height);
3416             }
3417             else    {
3418                 uifw_debug("uifw_map_surface: map EGL but no buffer surface=%08x,fps=%d",
3419                            surfaceid, framerate);
3420             }
3421         }
3422     }
3423     else if (maptype != ICO_WINDOW_MGR_MAP_TYPE_EGL)    {
3424         sm->width = usurf->client_width;
3425         sm->height = usurf->client_height;
3426         sm->stride = sm->width;
3427         sm->format = EGL_TEXTURE_RGBA;
3428         if ((sm->width > 0) && (sm->height > 0))    {
3429             sm->initflag = 1;
3430         }
3431         uifw_debug("uifw_map_surface: map type=%d,surface=%08x,fps=%d,w/h=%d/%d",
3432                    maptype, surfaceid, framerate, sm->width, sm->height);
3433     }
3434     else    {
3435         uifw_debug("uifw_map_surface: map EGL but no buffer surface=%08x,fps=%d",
3436                    surfaceid, framerate);
3437     }
3438
3439     /* send map event                       */
3440     if (sm->initflag)   {
3441         win_mgr_change_mapsurface(sm, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_MAP,
3442                                   weston_compositor_get_time());
3443     }
3444     uifw_trace("uifw_map_surface: Leave");
3445 }
3446
3447 /*--------------------------------------------------------------------------*/
3448 /**
3449  * @brief   uifw_unmap_surface: unmap surface buffer
3450  *
3451  * @param[in]   client      Weyland client
3452  * @param[in]   resource    resource of request
3453  * @param[in]   surfaceid   surface id
3454  * @return      none
3455  */
3456 /*--------------------------------------------------------------------------*/
3457 static void
3458 uifw_unmap_surface(struct wl_client *client, struct wl_resource *resource,
3459                    uint32_t surfaceid)
3460 {
3461     struct uifw_win_surface *usurf;
3462     struct uifw_surface_map *sm, *sm_tmp;
3463     struct uifw_client      *uclient;
3464     struct ico_uifw_image_buffer    *p;
3465     int     idx;
3466
3467     uifw_trace("uifw_unmap_surface: Enter(surface=%08x)", surfaceid);
3468
3469     usurf = ico_window_mgr_get_usurf(surfaceid);
3470     if (! usurf)    {
3471         /* surface dose not exist, error        */
3472         uifw_trace("uifw_unmap_surface: Leave(surface=%08x dose not exist)", surfaceid);
3473         return;
3474     }
3475     if (client) {
3476         uclient = find_client_from_client(client);
3477         if ((! uclient) || (! uclient->mgr))    {
3478             /* client dose not exist, error         */
3479             uifw_trace("uifw_unmap_surface: Leave(client=%08x dose not exist)", (int)client);
3480             return;
3481         }
3482     }
3483     else    {
3484         uclient = NULL;
3485         wl_list_for_each (sm, &usurf->surf_map, surf_link) {
3486             if (sm->uclient->mgr != NULL) {
3487                 uifw_trace("uifw_unmap_surface: send UNMAP event(ev=%d surf=%08x name=%08x "
3488                            "w/h/s=%d/%d/%d format=%x",
3489                            ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP, surfaceid,
3490                            sm->eglname, sm->width, sm->height, sm->stride, sm->format);
3491                 ico_window_mgr_send_map_surface(sm->uclient->mgr->resource,
3492                                                 ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP,
3493                                                 surfaceid, sm->type, sm->eglname, sm->width,
3494                                                 sm->height, sm->stride, sm->format);
3495             }
3496         }
3497     }
3498
3499     wl_list_for_each_safe (sm, sm_tmp, &usurf->surf_map, surf_link) {
3500         if (((uclient != NULL) && (sm->uclient != uclient)))   continue;
3501         /* send unmap event                     */
3502         if ((uclient != NULL) && (uclient->mgr != NULL))    {
3503             uifw_trace("uifw_unmap_surface: send UNMAP event(ev=%d surf=%08x name=%08x "
3504                        "w/h/s=%d/%d/%d format=%x",
3505                        ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP, surfaceid,
3506                        sm->eglname, sm->width, sm->height, sm->stride, sm->format);
3507             ico_window_mgr_send_map_surface(uclient->mgr->resource,
3508                                             ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP,
3509                                             surfaceid, sm->type, sm->eglname, sm->width,
3510                                             sm->height, sm->stride, sm->format);
3511         }
3512         if ((sm->type != ICO_WINDOW_MGR_MAP_TYPE_EGL) &&
3513             (sm->uclient->shmbuf != NULL))  {
3514             /* reset shared memory buffer   */
3515             for (idx = 0; idx < sm->uclient->bufnum; idx++) {
3516                 p = (struct ico_uifw_image_buffer *)
3517                     (((char *)sm->uclient->shmbuf) + idx * sm->uclient->bufsize);
3518                 if (p->surfaceid == surfaceid)  {
3519                     p->surfaceid = 0;
3520                     p->settime = 0;
3521                     p->reftime = 0;
3522                 }
3523             }
3524         }
3525         wl_list_remove(&sm->surf_link);
3526         wl_list_remove(&sm->map_link);
3527         sm->usurf = (struct uifw_win_surface *)_ico_win_mgr->free_maptable;
3528         _ico_win_mgr->free_maptable = sm;
3529     }
3530     uifw_trace("uifw_unmap_surface: Leave");
3531 }
3532
3533 /*--------------------------------------------------------------------------*/
3534 /**
3535  * @brief   win_mgr_surface_change_mgr: surface chagen from manager(HomeScreen)
3536  *
3537  * @param[in]   surface     Weston surface
3538  * @param[in]   x           X coordinate on screen
3539  * @param[in]   y           Y coordinate on screen
3540  * @param[in]   width       surface width
3541  * @param[in]   height      surface height
3542  * @return      number of managers
3543  * @retval      > 0         number of managers
3544  * @retval      0           manager not exist
3545  */
3546 /*--------------------------------------------------------------------------*/
3547 static int
3548 win_mgr_surface_change_mgr(struct weston_surface *surface,
3549                            const int x, const int y, const int width, const int height)
3550 {
3551     int     num_mgr;
3552     struct uifw_win_surface *usurf;
3553
3554     uifw_trace("win_mgr_surface_change_mgr: Enter(%08x,x/y=%d/%d,w/h=%d/%d)",
3555                (int)surface, x, y, width, height);
3556
3557     usurf = find_uifw_win_surface_by_ws(surface);
3558     if (! usurf) {
3559         uifw_trace("win_mgr_surface_change_mgr: Leave(Not Exist)");
3560         return 0;
3561     }
3562
3563     num_mgr = ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
3564                                       usurf, x, y, width, height, 1);
3565
3566     uifw_trace("win_mgr_surface_change_mgr: Leave(%d)", num_mgr);
3567     return num_mgr;
3568 }
3569
3570 /*--------------------------------------------------------------------------*/
3571 /**
3572  * @brief   win_mgr_change_surface: surface change
3573  *
3574  * @param[in]   surface     Weston surface
3575  * @param[in]   to          destination(0=Client&Manager,1=Client,-1=Manager)
3576  * @param[in]   manager     request from manager(0=Client,1=Manager)
3577  * @return      none
3578  */
3579 /*--------------------------------------------------------------------------*/
3580 static void
3581 win_mgr_change_surface(struct weston_surface *surface, const int to, const int manager)
3582 {
3583     struct uifw_win_surface *usurf;
3584     struct weston_surface   *es;
3585     int     x;
3586     int     y;
3587     int     repaint = 0;
3588
3589     uifw_trace("win_mgr_change_surface: Enter(%08x,%d,%d)", (int)surface, to, manager);
3590
3591     /* Find surface         */
3592     usurf = find_uifw_win_surface_by_ws(surface);
3593     if (! usurf) {
3594         uifw_trace("win_mgr_change_surface: Leave(Not Exist)");
3595         return;
3596     }
3597     es = usurf->surface;
3598     if (! es)   {
3599         uifw_trace("win_mgr_change_surface: Leave(No weston surface)");
3600         return;
3601     }
3602
3603     /* set surface size     */
3604     uifw_debug("win_mgr_change_surface: set surface x/y=%d/%d=>%d/%d w/h=%d/%d=>%d/%d",
3605                (int)es->geometry.x, (int)es->geometry.y, usurf->x, usurf->y,
3606                usurf->width, usurf->height, es->geometry.width, es->geometry.height);
3607     if ((usurf->width <= 0) || (usurf->height <= 0))    {
3608         usurf->width = es->geometry.width;
3609         usurf->height = es->geometry.height;
3610     }
3611     win_mgr_set_scale(usurf);
3612     if (usurf->visible) {
3613         weston_surface_set_position(usurf->surface,
3614                                     (float)(usurf->node_tbl->disp_x +
3615                                             usurf->x + usurf->xadd),
3616                                     (float)(usurf->node_tbl->disp_y +
3617                                             usurf->y + usurf->yadd));
3618         ico_window_mgr_restack_layer(usurf);
3619     }
3620     else    {
3621         weston_surface_set_position(usurf->surface, (float)(ICO_IVI_MAX_COORDINATE+1),
3622                                     (float)(ICO_IVI_MAX_COORDINATE+1));
3623     }
3624
3625     /* send wayland event to client     */
3626     if ((to >= 0) && (usurf->shsurf != NULL) && (manager !=0) &&
3627         (usurf->width > 0) && (usurf->height > 0))  {
3628         if ((usurf->width != usurf->conf_width) ||
3629             (usurf->height != usurf->conf_height))  {
3630             usurf->conf_width = usurf->width;
3631             usurf->conf_height = usurf->height;
3632             uifw_trace("win_mgr_change_surface: SURFACE_CONFIGURE %08x(%08x),w/h=%d/%d ",
3633                        usurf->surfaceid, (int)es, usurf->width, usurf->height);
3634             ico_ivi_shell_send_configure(es,
3635                                          WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT,
3636                                          usurf->width, usurf->height);
3637         }
3638     }
3639
3640     if (usurf->visible) {
3641         x = usurf->node_tbl->disp_x + usurf->x;
3642         y = usurf->node_tbl->disp_y + usurf->y;
3643     }
3644     else    {
3645         x = ICO_IVI_MAX_COORDINATE+1;
3646         y = ICO_IVI_MAX_COORDINATE+1;
3647     }
3648     /* change geometry if request from manager  */
3649     if (manager)    {
3650         if ((usurf->width != es->geometry.width) ||
3651             (usurf->height != es->geometry.height) ||
3652             (es->geometry.x != (float)x) || (es->geometry.y != (float)y))   {
3653             win_mgr_surface_configure(usurf, (float)x, (float)y, usurf->width, usurf->height);
3654             repaint ++;
3655         }
3656     }
3657
3658     /* send manager event to HomeScreen */
3659     if (to <= 0)    {
3660         if (manager)    {
3661             ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
3662                                     usurf, usurf->x, usurf->y,
3663                                     usurf->width, usurf->height, 0);
3664         }
3665         else    {
3666             ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
3667                                     usurf, (int)es->geometry.x, (int)es->geometry.y,
3668                                     es->geometry.width, es->geometry.height, 1);
3669         }
3670     }
3671
3672     /* change geometry if request from client   */
3673     if (! manager)  {
3674         if ((usurf->width != es->geometry.width) || (usurf->height != es->geometry.height) ||
3675             (es->geometry.x != (float)x) || (es->geometry.y != (float)y))   {
3676             win_mgr_surface_configure(usurf, x, y, usurf->width, usurf->height);
3677             repaint ++;
3678         }
3679     }
3680
3681     if (repaint)    {
3682         uifw_trace("win_mgr_change_surface: repaint");
3683         weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
3684     }
3685     uifw_trace("win_mgr_change_surface: Leave(OK)");
3686 }
3687
3688 /*--------------------------------------------------------------------------*/
3689 /**
3690  * @brief   win_mgr_surface_configure: UIFW surface configure
3691  *
3692  * @param[in]   usurf       UIFW surface
3693  * @param[in]   x           X coordinate on screen
3694  * @param[in]   y           Y coordinate on screen
3695  * @param[in]   width       surface width
3696  * @param[in]   height      surface height
3697  * @return      none
3698  */
3699 /*--------------------------------------------------------------------------*/
3700 static void
3701 win_mgr_surface_configure(struct uifw_win_surface *usurf,
3702                           int x, int y, int width, int height)
3703 {
3704     struct weston_surface   *es;
3705
3706     es = usurf->surface;
3707     if ((es != NULL) && (es->buffer_ref.buffer))  {
3708         if (usurf->client_width == 0)   {
3709             usurf->client_width = es->geometry.width;
3710             if (usurf->client_width == 0)
3711                 usurf->client_width = weston_surface_buffer_width(es);
3712         }
3713         if (usurf->client_height == 0)  {
3714             usurf->client_height = es->geometry.height;
3715             if (usurf->client_height == 0)
3716                 usurf->client_height = weston_surface_buffer_height(es);
3717         }
3718
3719         /* not set geometry width/height    */
3720         win_mgr_set_scale(usurf);
3721         weston_surface_set_position(es, x + usurf->xadd, y + usurf->yadd);
3722     }
3723 }
3724
3725 /*--------------------------------------------------------------------------*/
3726 /**
3727  * @brief   win_mgr_shell_configure: shell surface configure
3728  *
3729  * @param[in]   surface     Weston surface
3730  * @return      none
3731  */
3732 /*--------------------------------------------------------------------------*/
3733 static void
3734 win_mgr_shell_configure(struct weston_surface *surface)
3735 {
3736     struct uifw_win_surface *usurf;
3737     int     buf_width;
3738     int     buf_height;
3739
3740     uifw_trace("win_mgr_shell_configure: Enter(%08x)", (int)surface);
3741
3742     /* Find UIFW surface        */
3743     usurf = find_uifw_win_surface_by_ws(surface);
3744     if (! usurf) {
3745         uifw_trace("win_mgr_shell_configure: Leave(Not Exist)");
3746         return;
3747     }
3748
3749     usurf->client_width = surface->geometry.width;
3750     usurf->client_height = surface->geometry.height;
3751     buf_width = weston_surface_buffer_width(surface);
3752     buf_height = weston_surface_buffer_height(surface);
3753     uifw_trace("win_mgr_shell_configure: %08x client w/h=%d/%d buf=%d/%d",
3754                usurf->surfaceid,
3755                usurf->client_width, usurf->client_height, buf_width, buf_height);
3756     if (usurf->client_width > buf_width)    usurf->client_width = buf_width;
3757     if (usurf->client_height > buf_height)  usurf->client_height = buf_height;
3758
3759     /* send event to manager    */
3760     win_mgr_change_surface(surface, -1, 0);
3761
3762     uifw_trace("win_mgr_shell_configure: Leave");
3763 }
3764
3765 /*--------------------------------------------------------------------------*/
3766 /**
3767  * @brief   win_mgr_select_surface: select surface by Bottun/Touch
3768  *
3769  * @param[in]   surface     Weston surface
3770  * @return      none
3771  */
3772 /*--------------------------------------------------------------------------*/
3773 static void
3774 win_mgr_select_surface(struct weston_surface *surface)
3775 {
3776     struct uifw_win_surface *usurf;
3777
3778     uifw_trace("win_mgr_select_surface: Enter(%08x)", (int)surface);
3779
3780     /* find surface         */
3781     usurf = find_uifw_win_surface_by_ws(surface);
3782     if (! usurf) {
3783         uifw_trace("win_mgr_select_surface: Leave(Not Exist)");
3784         return;
3785     }
3786     if (usurf != _ico_win_mgr->active_pointer_usurf)  {
3787
3788         /* send active event to manager     */
3789         if (ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
3790                                     usurf, ICO_WINDOW_MGR_ACTIVE_SELECTED, 0,0,0,0) <= 0) {
3791             uifw_trace("win_mgr_select_surface: not found manager, set active");
3792             win_mgr_set_active(usurf, ICO_WINDOW_MGR_ACTIVE_POINTER |
3793                                         ICO_WINDOW_MGR_ACTIVE_KEYBOARD);
3794         }
3795     }
3796     uifw_trace("win_mgr_select_surface: Leave(OK)");
3797 }
3798
3799 /*--------------------------------------------------------------------------*/
3800 /**
3801  * @brief   win_mgr_set_title: set tile name to surface
3802  *
3803  * @param[in]   surface     weston surface
3804  * @param[in]   title       title name
3805  * @return      title string
3806  * @retval      != NULL     title string
3807  * @retval      NULL        no title string
3808  */
3809 /*--------------------------------------------------------------------------*/
3810 static char *
3811 win_mgr_set_title(struct weston_surface *surface, const char *title)
3812 {
3813     struct uifw_win_surface *usurf;
3814     char    *optpoint, *ppoint, *bpoint, *cpoint;
3815     int     layer, visible, raise, node, x, y, width, height, attribute;
3816     int     rx, ry, rw, rh;
3817     char    wktitle[ICO_IVI_WINNAME_LENGTH + 256];
3818
3819     uifw_trace("win_mgr_set_title: Enter(%08x) name=%s", (int)surface, title);
3820
3821     usurf = find_uifw_win_surface_by_ws(surface);
3822     if (! usurf) {
3823         uifw_trace("win_mgr_set_title: Leave(Not Exist)");
3824         return (char *)title;
3825     }
3826
3827     layer = -1;
3828     visible = -1;
3829     raise = -1;
3830     node = -1;
3831     x = -1;
3832     y = -1;
3833     width = -1;
3834     height = -1;
3835     attribute = -1;
3836
3837     strncpy(wktitle, title, ICO_IVI_WINNAME_LENGTH+256-1);
3838     wktitle[ICO_IVI_WINNAME_LENGTH+256-1] = 0;
3839
3840     /* get option parameters    */
3841     optpoint = strstr(wktitle, "@@");
3842
3843     if (optpoint != NULL)   {
3844         *optpoint = 0;
3845
3846         usurf->uclient->privilege = 1;  /* privilege application    */
3847         ppoint = optpoint + 2;
3848         while (1)   {
3849             bpoint = strtok(ppoint, "=;");
3850             ppoint = NULL;
3851             if (! bpoint)   break;
3852             if (strcasecmp(bpoint, "layer") == 0)   {
3853                 /* layer name or number */
3854                 bpoint = strtok(ppoint, "=;");
3855                 if (bpoint) {
3856                     if (strcasecmp(bpoint, "background") == 0)  {
3857                         layer = _ico_ivi_background_layer;
3858                     }
3859                     else if (strcasecmp(bpoint, "default") == 0)    {
3860                         layer = _ico_ivi_default_layer;
3861                     }
3862                     else if (strcasecmp(bpoint, "touch") == 0)  {
3863                         layer = _ico_ivi_touch_layer;
3864                     }
3865                     else if (strcasecmp(bpoint, "cursor") == 0) {
3866                         layer = _ico_ivi_cursor_layer;
3867                     }
3868                     else if (strcasecmp(bpoint, "startup") == 0)    {
3869                         layer = _ico_ivi_startup_layer;
3870                     }
3871                     else    {
3872                         layer = strtol(bpoint, (char **)0, 0);
3873                     }
3874                 }
3875             }
3876             else if (strcasecmp(bpoint, "show") == 0)   {
3877                 /* show     */
3878                 visible = 1;
3879             }
3880             else if (strcasecmp(bpoint, "hide") == 0)   {
3881                 /* hide     */
3882                 visible = 0;
3883             }
3884             else if (strcasecmp(bpoint, "raise") == 0)  {
3885                 /* raiee    */
3886                 raise = 1;
3887             }
3888             else if (strcasecmp(bpoint, "lower") == 0)  {
3889                 /* lower    */
3890                 raise = 0;
3891             }
3892             else if (strcasecmp(bpoint, "node") == 0)   {
3893                 /* node     */
3894                 bpoint = strtok(ppoint, ",");
3895                 if (bpoint) {
3896                     node = strtol(bpoint, (char **)0, 0);
3897                 }
3898             }
3899             else if (strcasecmp(bpoint, "position") == 0)   {
3900                 /* position */
3901                 bpoint = strtok(ppoint, ",");
3902                 if (bpoint) {
3903                     cpoint = strtok(ppoint, ";");
3904                     if (cpoint) {
3905                         x = strtol(bpoint, (char **)0, 0);
3906                         y = strtol(cpoint, (char **)0, 0);
3907                     }
3908                 }
3909             }
3910             else if (strcasecmp(bpoint, "size") == 0)   {
3911                 /* size     */
3912                 bpoint = strtok(ppoint, ",");
3913                 if (bpoint) {
3914                     cpoint = strtok(ppoint, ";");
3915                     if (cpoint) {
3916                         width = strtol(bpoint, (char **)0, 0);
3917                         height = strtol(cpoint, (char **)0, 0);
3918                     }
3919                 }
3920             }
3921             else if (strcasecmp(bpoint, "attribute") == 0)  {
3922                 /* attribute flags  */
3923                 bpoint = strtok(ppoint, ",");
3924                 if (bpoint) {
3925                     attribute = strtol(bpoint, (char **)0, 0);
3926                 }
3927             }
3928             else if (strcasecmp(bpoint, "region") == 0) {
3929                 /* set input region     */
3930                 bpoint = strtok(ppoint, ",");
3931                 if (bpoint) {
3932                     ry = 0;
3933                     rw = 100;
3934                     rh = 50;
3935                     rx = strtol(bpoint, (char **)0, 0);
3936                     bpoint = strtok(ppoint, ",");
3937                     if (bpoint) {
3938                         ry = strtol(bpoint, (char **)0, 0);
3939                     }
3940                     bpoint = strtok(ppoint, ",");
3941                     if (bpoint) {
3942                         rw = strtol(bpoint, (char **)0, 0);
3943                     }
3944                     bpoint = strtok(ppoint, ";");
3945                     if (bpoint) {
3946                         rh = strtol(bpoint, (char **)0, 0);
3947                     }
3948                     if (win_mgr_hook_inputregion)   {
3949                         (*win_mgr_hook_inputregion)(1, usurf, rx, ry, rw, rh, 0, 0,
3950                                                     0, 0, 0, 0, 0);
3951                     }
3952                 }
3953             }
3954             else if (strcasecmp(bpoint, "unregion") == 0)   {
3955                 /* unset input region   */
3956                 bpoint = strtok(ppoint, ",");
3957                 if (bpoint) {
3958                     ry = 0;
3959                     rw = 100;
3960                     rh = 50;
3961                     rx = strtol(bpoint, (char **)0, 0);
3962                     bpoint = strtok(ppoint, ",");
3963                     if (bpoint) {
3964                         ry = strtol(bpoint, (char **)0, 0);
3965                     }
3966                     bpoint = strtok(ppoint, ",");
3967                     if (bpoint) {
3968                         rw = strtol(bpoint, (char **)0, 0);
3969                     }
3970                     bpoint = strtok(ppoint, ";");
3971                     if (bpoint) {
3972                         rh = strtol(bpoint, (char **)0, 0);
3973                     }
3974                     if (win_mgr_hook_inputregion)   {
3975                         (*win_mgr_hook_inputregion)(0, usurf, rx, ry, rw, rh, 0, 0,
3976                                                     0, 0, 0, 0, 0);
3977                     }
3978                 }
3979             }
3980         }
3981     }
3982
3983     if ((optpoint == NULL) || (wktitle[0] != 0))  {
3984         if (((usurf->width > 0) && (usurf->height > 0)) &&
3985             ((usurf->created == 0) ||
3986              (strncmp(wktitle, usurf->winname, ICO_IVI_WINNAME_LENGTH-1) != 0)))    {
3987             strncpy(usurf->winname, wktitle, ICO_IVI_WINNAME_LENGTH-1);
3988             usurf->winname[ICO_IVI_WINNAME_LENGTH-1] = 0;
3989             if (usurf->created == 0)    {
3990                 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CREATED, usurf, 0,0,0,0,0);
3991                 usurf->created = 1;
3992             }
3993             else    {
3994                 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_NAME, usurf, 0,0,0,0,0);
3995             }
3996         }
3997         else    {
3998             strncpy(usurf->winname, wktitle, ICO_IVI_WINNAME_LENGTH-1);
3999             usurf->winname[ICO_IVI_WINNAME_LENGTH-1] = 0;
4000         }
4001     }
4002
4003     if (optpoint)   {
4004         if (layer >= 0) {
4005             uifw_set_window_layer(usurf->uclient->client, NULL, usurf->surfaceid, layer);
4006         }
4007         if (attribute >= 0) {
4008             uifw_set_attributes(usurf->uclient->client, NULL, usurf->surfaceid, attribute);
4009         }
4010         if ((node >= 0) || (x >=0) || (y >= 0) || (width >=0) || (height >= 0)) {
4011             if (node < 0)   node = usurf->node_tbl->node;
4012             if (x < 0)      x = ICO_IVI_MAX_COORDINATE + 1;
4013             if (y < 0)      y = ICO_IVI_MAX_COORDINATE + 1;
4014             if (width < 0)  width = ICO_IVI_MAX_COORDINATE + 1;
4015             if (height < 0) height = ICO_IVI_MAX_COORDINATE + 1;
4016             uifw_set_positionsize(usurf->uclient->client, NULL, usurf->surfaceid,
4017                                   node, x, y, width, height, 0);
4018         }
4019         if ((visible >= 0)  || (raise >= 0))    {
4020             if (visible < 0)    visible = ICO_WINDOW_MGR_V_NOCHANGE;
4021             if (raise < 0)      raise = ICO_WINDOW_MGR_V_NOCHANGE;
4022             uifw_set_visible(usurf->uclient->client, NULL, usurf->surfaceid,
4023                              visible, raise, 0);
4024         }
4025     }
4026     uifw_trace("win_mgr_set_title: Leave");
4027
4028     return usurf->winname;
4029 }
4030
4031 /*--------------------------------------------------------------------------*/
4032 /**
4033  * @brief   win_mgr_surface_move: set tile name to surface
4034  *
4035  * @param[in]   surface     weston surface
4036  * @param[in]   title       title name
4037  * @return      none
4038  */
4039 /*--------------------------------------------------------------------------*/
4040 static void
4041 win_mgr_surface_move(struct weston_surface *surface, int *dx, int *dy)
4042 {
4043     struct uifw_win_surface *usurf;
4044
4045     uifw_trace("win_mgr_surface_move: Enter(%08x) x/y=%d,%d", (int)surface, *dx, *dy);
4046
4047     usurf = find_uifw_win_surface_by_ws(surface);
4048     if (! usurf) {
4049         uifw_trace("win_mgr_surface_move: Leave(Not Exist)");
4050         return;
4051     }
4052     if (usurf->visible) {
4053         *dx = usurf->node_tbl->disp_x + usurf->x;
4054         *dy = usurf->node_tbl->disp_y + usurf->y;
4055     }
4056     else    {
4057         *dx = ICO_IVI_MAX_COORDINATE+1;
4058         *dy = ICO_IVI_MAX_COORDINATE+1;
4059     }
4060     uifw_trace("win_mgr_surface_move: Leave(change to x/y=%d/%d)", *dx, *dy);
4061 }
4062
4063 /*--------------------------------------------------------------------------*/
4064 /**
4065  * @brief   win_mgr_show_layer: shell layer visible control
4066  *
4067  * @param[in]   layertype   shell layer type
4068  * @param[in]   show        show(1)/hide(0)
4069  * @param[in]   data        requested weston surface in show
4070  * @return      none
4071  */
4072 /*--------------------------------------------------------------------------*/
4073 static void
4074 win_mgr_show_layer(int layertype, int show, void *data)
4075 {
4076     struct uifw_win_layer   *el;
4077     struct uifw_win_surface *usurf;
4078     struct uifw_win_surface *inusurf = NULL;
4079
4080     uifw_trace("win_mgr_show_layer: Enter(type=%d, show=%d, data=%08x)",
4081                layertype, show, (int)data);
4082
4083     if (layertype != LAYER_TYPE_INPUTPANEL) {
4084         uifw_trace("win_mgr_show_layer: Leave(layertype npt InputPanel)");
4085         return;
4086     }
4087     if (show)   {
4088         if (data == NULL)   {
4089             uifw_trace("win_mgr_show_layer: Leave(show but input surface not exist)");
4090             return;
4091         }
4092         inusurf = find_uifw_win_surface_by_ws((struct weston_surface *)data);
4093         if (! inusurf)  {
4094             uifw_trace("win_mgr_show_layer: Leave(show but unknown input surface)");
4095             return;
4096         }
4097     }
4098
4099     /*  all input panel surface show/hide   */
4100     wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link)  {
4101         if ((el->layertype == LAYER_TYPE_CURSOR) ||
4102             (el->layertype == LAYER_TYPE_TOUCH))    continue;
4103         wl_list_for_each (usurf, &el->surface_list, ivi_layer) {
4104             if ((usurf->layertype == LAYER_TYPE_INPUTPANEL) &&
4105                 (usurf->surface != NULL) && (usurf->mapped != 0) &&
4106                 (usurf->surface->buffer_ref.buffer != NULL))    {
4107
4108                 if ((inusurf != NULL) && (usurf->win_layer != inusurf->win_layer))  {
4109                     win_mgr_set_layer(usurf, usurf->win_layer->layer);
4110                     usurf->raise = 1;
4111                     win_mgr_change_surface(usurf->surface, -1, 1);
4112                 }
4113                 if ((show == 0) || (ico_ivi_optionflag() & ICO_IVI_OPTION_SHOW_INPUTLAYER)) {
4114                     /* show input panel automatically   */
4115                     ico_window_mgr_set_visible(usurf, show | 2);
4116                 }
4117                 else    {
4118                     /* send hint event to HomeScreen    */
4119                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_VISIBLE,
4120                                             usurf, show, ICO_WINDOW_MGR_RAISE_RAISE, 1, 0,0);
4121                 }
4122             }
4123         }
4124     }
4125     uifw_trace("win_mgr_show_layer: Leave");
4126 }
4127
4128 /*--------------------------------------------------------------------------*/
4129 /**
4130  * @brief   win_mgr_fullscreen: shell full screen surface control
4131  *
4132  * @param[in]   event       control event
4133  * @param[in]   surface     target weston surface
4134  * @return      result
4135  */
4136 /*--------------------------------------------------------------------------*/
4137 static int
4138 win_mgr_fullscreen(int event, struct weston_surface *surface)
4139 {
4140     struct uifw_win_surface *usurf;
4141     struct uifw_win_surface *tmpusurf;
4142     struct uifw_win_layer   *ulayer;
4143     int     width, height;
4144     int     sx, sy;
4145
4146     uifw_trace("win_mgr_fullscreen: Enter(event=%d, surface=%08x)", event, (int)surface);
4147
4148     if (event == SHELL_FULLSCREEN_HIDEALL)  {
4149         /* hide all fullscreen srface       */
4150         uifw_trace("win_mgr_fullscreen: SHELL_FULLSCREEN_HIDEALL");
4151
4152         wl_list_for_each (ulayer, &_ico_win_mgr->ivi_layer_list, link)  {
4153             if (ulayer->layertype >= LAYER_TYPE_TOUCH)  continue;
4154             wl_list_for_each_safe (usurf, tmpusurf, &ulayer->surface_list, ivi_layer)   {
4155                 if (usurf->layertype == LAYER_TYPE_FULLSCREEN)  {
4156                     ico_window_mgr_set_visible(usurf, 2);
4157                     usurf->layertype = usurf->old_layertype;
4158                     win_mgr_set_layer(usurf, usurf->old_layer->layer);
4159                     win_mgr_change_surface(usurf->surface, -1, 1);
4160                     /* send event to HomeScreen         */
4161                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
4162                                             usurf, usurf->x, usurf->y,
4163                                             usurf->width, usurf->height, 0);
4164                 }
4165             }
4166         }
4167         uifw_trace("win_mgr_fullscreen: Leave");
4168         return 0;
4169     }
4170
4171     usurf = find_uifw_win_surface_by_ws(surface);
4172     if (! usurf)    {
4173         uifw_trace("win_mgr_fullscreen: Leave(surface dose not exist)");
4174         return -1;
4175     }
4176
4177     switch(event)   {
4178     case SHELL_FULLSCREEN_ISTOP:        /* check if top surface             */
4179         if (usurf->layertype == LAYER_TYPE_FULLSCREEN)  {
4180             wl_list_for_each (ulayer, &_ico_win_mgr->ivi_layer_list, link)  {
4181                 if (ulayer->layertype >= LAYER_TYPE_TOUCH)  continue;
4182                 wl_list_for_each(tmpusurf, &ulayer->surface_list, ivi_layer)    {
4183                     if (usurf == tmpusurf)  {
4184                         uifw_trace("win_mgr_fullscreen: %08x SHELL_FULLSCREEN_ISTOP"
4185                                    "(fullscreen surface)", usurf->surfaceid);
4186                         return 1;
4187                     }
4188                     if (tmpusurf->layertype == LAYER_TYPE_FULLSCREEN)   {
4189                         uifw_trace("win_mgr_fullscreen: %08x SHELL_FULLSCREEN_ISTOP"
4190                                    "(fullscreen surface but not top)", usurf->surfaceid);
4191                         return 0;
4192                     }
4193                 }
4194             }
4195         }
4196         uifw_trace("win_mgr_fullscreen: %08x SHELL_FULLSCREEN_ISTOP"
4197                    "(not fullscreen surface)", usurf->surfaceid);
4198         return 0;
4199     case SHELL_FULLSCREEN_SET:          /* change surface to full screen    */
4200         uifw_trace("win_mgr_fullscreen: %08x SHELL_FULLSCREEN_SET", usurf->surfaceid);
4201         if (usurf->layertype != LAYER_TYPE_FULLSCREEN)  {
4202             usurf->old_layertype = usurf->layertype;
4203             usurf->layertype = LAYER_TYPE_FULLSCREEN;
4204             usurf->old_layer = usurf->win_layer;
4205             /* send hint event to HomeScreen    */
4206             ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
4207                                     usurf, usurf->x, usurf->y,
4208                                     usurf->width, usurf->height, 1);
4209         }
4210         break;
4211     case SHELL_FULLSCREEN_STACK:        /* change surface to top of layer   */
4212         uifw_trace("win_mgr_fullscreen: %08x SHELL_FULLSCREEN_STACK", usurf->surfaceid);
4213         if (usurf->mapped == 0) {
4214             uifw_trace("win_mgr_fullscreen: not map, change to map");
4215             width = usurf->node_tbl->disp_width;
4216             height = usurf->node_tbl->disp_height;
4217             sx = 0;
4218             sy = 0;
4219             win_mgr_surface_map(usurf->surface, &width, &height, &sx, &sy);
4220         }
4221         if ((usurf->surface != NULL) && (usurf->mapped != 0) &&
4222             (usurf->surface->buffer_ref.buffer != NULL))    {
4223             /* fullscreen surface raise         */
4224             win_mgr_set_raise(usurf, 1);
4225         }
4226         break;
4227     case SHELL_FULLSCREEN_CONF:         /* configure full screen surface    */
4228         uifw_trace("win_mgr_fullscreen: %08x SHELL_FULLSCREEN_CONF", usurf->surfaceid);
4229         if (usurf->mapped == 0) {
4230             width = usurf->node_tbl->disp_width;
4231             height = usurf->node_tbl->disp_height;
4232             sx = 0;
4233             sy = 0;
4234             win_mgr_surface_map(usurf->surface, &width, &height, &sx, &sy);
4235         }
4236         break;
4237     default:
4238         uifw_trace("win_mgr_fullscreen: Leave(unknown event %d)", event);
4239         return -1;
4240     }
4241     uifw_trace("win_mgr_fullscreen: Leave");
4242     return 0;
4243 }
4244
4245 /*--------------------------------------------------------------------------*/
4246 /**
4247  * @brief   win_mgr_reset_focus: reset surface focus
4248  *
4249  * @param[in]   usurf       UIFW surface
4250  * @return      none
4251  */
4252 /*--------------------------------------------------------------------------*/
4253 static void
4254 win_mgr_reset_focus(struct uifw_win_surface *usurf)
4255 {
4256     struct weston_seat      *seat;
4257     struct weston_surface   *surface;
4258
4259     uifw_trace("win_mgr_reset_focus: Enter(%08x)", usurf->surfaceid);
4260
4261     seat = container_of (_ico_win_mgr->compositor->seat_list.next, struct weston_seat, link);
4262     surface = usurf->surface;
4263     if ((seat != NULL) && (surface != NULL))    {
4264 #if 0               /* pointer grab can not release */
4265         /* reset pointer focus          */
4266         if ((seat->pointer != NULL) && (seat->pointer->focus == surface))   {
4267             weston_pointer_set_focus(seat->pointer, NULL,
4268                                      wl_fixed_from_int(0), wl_fixed_from_int(0));
4269         }
4270         /* reset touch focus            */
4271         if ((seat->touch != NULL) && (seat->touch->focus == surface))   {
4272             weston_touch_set_focus(seat, NULL);
4273         }
4274 #endif              /* pointer grab can not release */
4275         /* reset keyboard focus         */
4276         if ((seat->keyboard != NULL) && (seat->keyboard->focus == surface)) {
4277             weston_keyboard_set_focus(seat->keyboard, NULL);
4278         }
4279     }
4280     uifw_trace("win_mgr_reset_focus: Leave");
4281 }
4282
4283 /*--------------------------------------------------------------------------*/
4284 /**
4285  * @brief   ico_window_mgr_set_visible: change surface visibility
4286  *
4287  * @param[in]   usurf       UIFW surface
4288  * @param[in]   visible     bit 0: visible(=1)/unvisible(=0)
4289  *                          bit 1: widht anima(=1)/without anima(=0)
4290  * @return      none
4291  */
4292 /*--------------------------------------------------------------------------*/
4293 WL_EXPORT   void
4294 ico_window_mgr_set_visible(struct uifw_win_surface *usurf, const int visible)
4295 {
4296     int     retanima;
4297
4298     if (visible & 1)    {
4299         if ((usurf->visible == 0) ||
4300             (usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE))    {
4301             uifw_trace("ico_window_mgr_set_visible: Chagne to Visible(%08x) x/y=%d/%d",
4302                        usurf->surfaceid, usurf->x, usurf->y);
4303             usurf->visible = 1;
4304             ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
4305                                               usurf->width, usurf->height);
4306             if ((visible & 2) && (win_mgr_hook_animation != NULL))  {
4307                 usurf->animation.pos_x = usurf->x;
4308                 usurf->animation.pos_y = usurf->y;
4309                 usurf->animation.pos_width = usurf->width;
4310                 usurf->animation.pos_height = usurf->height;
4311                 usurf->animation.no_configure = 0;
4312                 retanima = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_OPSHOW,
4313                                                  (void *)usurf);
4314                 uifw_trace("ico_window_mgr_set_visible: show animation = %d", retanima);
4315             }
4316             /* change unvisible to visible, restack surface list    */
4317             ico_window_mgr_restack_layer(usurf);
4318         }
4319     }
4320     else    {
4321         if ((usurf->visible != 0) ||
4322             (usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE))    {
4323
4324             uifw_trace("ico_window_mgr_set_visible: Chagne to Unvisible(%08x)",
4325                        usurf->surfaceid);
4326
4327             /* Reset focus              */
4328             win_mgr_reset_focus(usurf);
4329
4330             retanima = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
4331             if ((visible & 2) && (win_mgr_hook_animation != NULL))  {
4332                 usurf->animation.pos_x = usurf->x;
4333                 usurf->animation.pos_y = usurf->y;
4334                 usurf->animation.pos_width = usurf->width;
4335                 usurf->animation.pos_height = usurf->height;
4336                 usurf->animation.no_configure = 0;
4337                 retanima = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_OPHIDE,
4338                                                     (void *)usurf);
4339                 uifw_trace("ico_window_mgr_set_visible: hide animation = %d", retanima);
4340                 if (retanima != ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL)    {
4341                     usurf->visible = 0;
4342                     /* Weston surface configure                     */
4343                     ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
4344                                                       usurf->width, usurf->height);
4345                 }
4346             }
4347             else    {
4348                 usurf->visible = 0;
4349                 /* Weston surface configure                     */
4350                 ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
4351                                                   usurf->width, usurf->height);
4352             }
4353             ico_window_mgr_restack_layer(usurf);
4354         }
4355     }
4356     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_VISIBLE,
4357                             usurf, usurf->visible, usurf->raise, 0, 0, 0);
4358 }
4359
4360 /*--------------------------------------------------------------------------*/
4361 /**
4362  * @brief   win_mgr_set_raise: change surface raise/lower
4363  *
4364  * @param[in]   usurf       UIFW surface
4365  * @param[in]   raise       raise(=1)/lower(0)
4366  * @return      none
4367  */
4368 /*--------------------------------------------------------------------------*/
4369 static void
4370 win_mgr_set_raise(struct uifw_win_surface *usurf, const int raise)
4371 {
4372     struct uifw_win_surface *eu;
4373
4374     uifw_trace("win_mgr_set_raise: Enter(%08x,%d) layer=%d type=%x",
4375                (int)usurf, raise, (int)usurf->win_layer->layer, usurf->layertype);
4376
4377     wl_list_remove(&usurf->ivi_layer);
4378     if (raise & 1)  {
4379         /* raise ... surface stack to top of layer          */
4380         if (usurf->layertype == LAYER_TYPE_INPUTPANEL)  {
4381             /* if input panel, top of surface list          */
4382             uifw_trace("win_mgr_set_raise: Raise Link to Top(InputPanel)");
4383             wl_list_insert(&usurf->win_layer->surface_list, &usurf->ivi_layer);
4384         }
4385         else    {
4386             /* if not input panel, search not input panel   */
4387             wl_list_for_each (eu, &usurf->win_layer->surface_list, ivi_layer)   {
4388                 if (eu->layertype != LAYER_TYPE_INPUTPANEL) break;
4389             }
4390             uifw_trace("win_mgr_set_raise: Raise Link to Top(Normal)");
4391             wl_list_insert(eu->ivi_layer.prev, &usurf->ivi_layer);
4392         }
4393         usurf->raise = 1;
4394     }
4395     else    {
4396         /* Lower ... surface stack to bottom of layer       */
4397         if (usurf->layertype == LAYER_TYPE_INPUTPANEL)  {
4398             /* if input panel, search not input panel       */
4399             uifw_trace("win_mgr_set_raise: Lower Link to Bottom(InputPanel)");
4400             wl_list_for_each (eu, &usurf->win_layer->surface_list, ivi_layer)   {
4401                 if (eu->layertype != LAYER_TYPE_INPUTPANEL) break;
4402             }
4403             wl_list_insert(eu->ivi_layer.prev, &usurf->ivi_layer);
4404         }
4405         else    {
4406             /* if not input panel, bottom of surface list   */
4407             uifw_trace("win_mgr_set_raise: Lower Link to Bottom(Normal)");
4408             wl_list_insert(usurf->win_layer->surface_list.prev, &usurf->ivi_layer);
4409         }
4410         usurf->raise = 0;
4411     }
4412
4413     /* rebild compositor surface list               */
4414     if ((raise & 2) == 0)   {
4415         if (usurf->visible) {
4416             ico_window_mgr_restack_layer(usurf);
4417         }
4418         ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_VISIBLE,
4419                                 usurf, usurf->visible, usurf->raise, 0, 0,0);
4420     }
4421     uifw_trace("win_mgr_set_raise: Leave");
4422 }
4423
4424 /*--------------------------------------------------------------------------*/
4425 /**
4426  * @brief   win_mgr_destroy_surface: surface destroy
4427  *
4428  * @param[in]   surface     Weston surface
4429  * @return      none
4430  */
4431 /*--------------------------------------------------------------------------*/
4432 static void
4433 win_mgr_destroy_surface(struct weston_surface *surface)
4434 {
4435     struct uifw_win_surface *usurf;
4436     struct uifw_win_surface *phash;
4437     struct uifw_win_surface *bhash;
4438     uint32_t    hash;
4439
4440     usurf = find_uifw_win_surface_by_ws(surface);
4441     if (! usurf) {
4442         uifw_trace("win_mgr_destroy_surface: UIFW surface Not Exist");
4443         return;
4444     }
4445     uifw_trace("win_mgr_destroy_surface: Enter(%08x) %08x", (int)surface, usurf->surfaceid);
4446
4447     /* Reset focus                  */
4448     win_mgr_reset_focus(usurf);
4449
4450     /* destory input region         */
4451     if (win_mgr_hook_destory)   {
4452         (*win_mgr_hook_destory)(usurf);
4453     }
4454
4455     /* unmap surface                */
4456     if (&usurf->surf_map != usurf->surf_map.next)   {
4457         uifw_unmap_surface(NULL, NULL, usurf->surfaceid);
4458     }
4459
4460     /* destroy active surface       */
4461     if (usurf == _ico_win_mgr->active_pointer_usurf)  {
4462         _ico_win_mgr->active_pointer_usurf = NULL;
4463     }
4464     if (usurf == _ico_win_mgr->active_keyboard_usurf) {
4465         _ico_win_mgr->active_keyboard_usurf = NULL;
4466     }
4467
4468     /* destroy animation extenson   */
4469     if (win_mgr_hook_animation) {
4470         (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_DESTROY, (void *)usurf);
4471     }
4472
4473     /* delete from layer list       */
4474     wl_list_remove(&usurf->ivi_layer);
4475     ico_window_mgr_restack_layer(NULL);
4476
4477     /* delete from cleint list      */
4478     wl_list_remove(&usurf->client_link);
4479
4480     /* delete from hash table       */
4481     hash = MAKE_IDHASH(usurf->surfaceid);
4482     phash = _ico_win_mgr->idhash[hash];
4483     bhash = NULL;
4484     while ((phash) && (phash != usurf)) {
4485         bhash = phash;
4486         phash = phash->next_idhash;
4487     }
4488     if (bhash)  {
4489         bhash->next_idhash = usurf->next_idhash;
4490     }
4491     else    {
4492         _ico_win_mgr->idhash[hash] = usurf->next_idhash;
4493     }
4494
4495     hash = MAKE_WSHASH(usurf->surface);
4496     phash = _ico_win_mgr->wshash[hash];
4497     bhash = NULL;
4498     while ((phash) && (phash != usurf)) {
4499         bhash = phash;
4500         phash = phash->next_wshash;
4501     }
4502     if (bhash)  {
4503         bhash->next_wshash = usurf->next_wshash;
4504     }
4505     else    {
4506         _ico_win_mgr->wshash[hash] = usurf->next_wshash;
4507     }
4508
4509     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_DESTROYED,
4510                            usurf, 0,0,0,0,0);
4511
4512     hash = usurf->surfaceid & SURCAFE_ID_MASK;
4513     _ico_win_mgr->surfaceid_map[(hash - 1)/16] &= ~(1 << ((hash - 1) % 16));
4514
4515     free(usurf);
4516     uifw_trace("win_mgr_destroy_surface: Leave(OK)");
4517 }
4518
4519 /*--------------------------------------------------------------------------*/
4520 /**
4521  * @brief   bind_ico_win_mgr: bind Multi Window Manager from client
4522  *
4523  * @param[in]   client      client
4524  * @param[in]   data        user data(unused)
4525  * @param[in]   version     protocol version(unused)
4526  * @param[in]   id          client object id
4527  * @return      none
4528  */
4529 /*--------------------------------------------------------------------------*/
4530 static void
4531 bind_ico_win_mgr(struct wl_client *client,
4532                  void *data, uint32_t version, uint32_t id)
4533 {
4534     struct wl_resource  *add_resource;
4535     struct uifw_manager *mgr;
4536     struct uifw_client  *uclient;
4537
4538     uifw_trace("bind_ico_win_mgr: Enter(client=%08x, id=%x)", (int)client, (int)id);
4539
4540     add_resource = wl_resource_create(client, &ico_window_mgr_interface, 1, id);
4541     if (add_resource)   {
4542         wl_resource_set_implementation(add_resource, &ico_window_mgr_implementation,
4543                                        _ico_win_mgr, unbind_ico_win_mgr);
4544     }
4545
4546     /* Create client management tabel       */
4547     uclient = find_client_from_client(client);
4548     if (! uclient)  {
4549         win_mgr_bind_client(client, NULL);
4550         uclient = find_client_from_client(client);
4551     }
4552
4553     /* Manager                              */
4554     mgr = (struct uifw_manager *)malloc(sizeof(struct uifw_manager));
4555     if (! mgr)  {
4556         uifw_error("bind_ico_win_mgr: Error, No Memory");
4557         return;
4558     }
4559     memset(mgr, 0, sizeof(struct uifw_manager));
4560     mgr->resource = add_resource;
4561     if (uclient)    {
4562         uclient->mgr = mgr;
4563     }
4564     wl_list_insert(&_ico_win_mgr->manager_list, &mgr->link);
4565
4566     uifw_trace("bind_ico_win_mgr: Leave");
4567 }
4568
4569 /*--------------------------------------------------------------------------*/
4570 /**
4571  * @brief   unbind_ico_win_mgr: unbind Multi Window Manager from client
4572  *
4573  * @param[in]   resource    client resource
4574  * @return      none
4575  */
4576 /*--------------------------------------------------------------------------*/
4577 static void
4578 unbind_ico_win_mgr(struct wl_resource *resource)
4579 {
4580     struct uifw_manager *mgr, *itmp;
4581
4582     uifw_trace("unbind_ico_win_mgr: Enter");
4583
4584     /* Remove manager from manager list */
4585     _ico_win_mgr->num_manager = 0;
4586     wl_list_for_each_safe (mgr, itmp, &_ico_win_mgr->manager_list, link)    {
4587         if (mgr->resource == resource) {
4588             wl_list_remove(&mgr->link);
4589             free(mgr);
4590         }
4591         else    {
4592             if (mgr->manager)   {
4593                 _ico_win_mgr->num_manager++;
4594             }
4595         }
4596     }
4597     uifw_trace("unbind_ico_win_mgr: Leave");
4598 }
4599
4600 /*--------------------------------------------------------------------------*/
4601 /**
4602  * @brief   ico_win_mgr_send_to_mgr: send event to manager(HomeScreen)
4603  *
4604  * @param[in]   event       event code(if -1, not send event)
4605  * @param[in]   usurf       UIFW surface table
4606  * @param[in]   param1      parameter 1
4607  * @param[in]      :             :
4608  * @param[in]   param5      parameter 5
4609  * @return      number of managers
4610  * @retval      > 0         number of managers
4611  * @retval      0           manager not exist
4612  */
4613 /*--------------------------------------------------------------------------*/
4614 static int
4615 ico_win_mgr_send_to_mgr(const int event, struct uifw_win_surface *usurf,
4616                         const int param1, const int param2, const int param3,
4617                         const int param4, const int param5)
4618 {
4619     int     num_mgr = 0;
4620     struct uifw_manager* mgr;
4621
4622     /* if DESTROY and no send CREATE, Nop       */
4623     if ((event == ICO_WINDOW_MGR_WINDOW_DESTROYED) &&
4624         (usurf != NULL) && (usurf->created == 0))   {
4625         return 0;
4626     }
4627
4628     /* if appid not fix, check and fix appid    */
4629     if ((usurf != NULL) &&
4630         (usurf->uclient->fixed_appid < ICO_WINDOW_MGR_APPID_FIXCOUNT)) {
4631         win_mgr_get_client_appid(usurf->uclient);
4632     }
4633
4634     /* send created if not send created event   */
4635     if ((usurf != NULL) && (usurf->created == 0) &&
4636         (((usurf->width > 0) && (usurf->height > 0)) ||
4637          ((event != ICO_WINDOW_MGR_WINDOW_CREATED) &&
4638           (event != ICO_WINDOW_MGR_WINDOW_NAME))))  {
4639         wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link)   {
4640             if (mgr->manager)   {
4641                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) WINDOW_CREATED"
4642                            "(surf=%08x,name=%s,pid=%d,appid=%s,type=%x)", (int)mgr->resource,
4643                            usurf->surfaceid, usurf->winname, usurf->uclient->pid,
4644                            usurf->uclient->appid, usurf->layertype);
4645                 ico_window_mgr_send_window_created(mgr->resource, usurf->surfaceid,
4646                                                    usurf->winname, usurf->uclient->pid,
4647                                                    usurf->uclient->appid,
4648                                                    usurf->layertype << 12);
4649             }
4650         }
4651         usurf->created = 1;
4652     }
4653
4654     wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link)   {
4655         if (mgr->manager)   {
4656             num_mgr ++;
4657
4658             switch(event)   {
4659             case ICO_WINDOW_MGR_WINDOW_CREATED:
4660                 /* Do nothing anymore because sended window create event    */
4661                 break;
4662
4663             case ICO_WINDOW_MGR_WINDOW_NAME:
4664                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) WINDOW_NAME"
4665                            "(surf=%08x,name=%s)", (int)mgr->resource,
4666                            usurf->surfaceid, usurf->winname);
4667                 ico_window_mgr_send_window_name(mgr->resource, usurf->surfaceid,
4668                                                 usurf->winname);
4669                 break;
4670
4671             case ICO_WINDOW_MGR_WINDOW_DESTROYED:
4672                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) DESTROYED"
4673                            "(surf=%08x)", (int)mgr->resource, usurf->surfaceid);
4674                 ico_window_mgr_send_window_destroyed(mgr->resource, usurf->surfaceid);
4675                 break;
4676
4677             case ICO_WINDOW_MGR_WINDOW_VISIBLE:
4678                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) VISIBLE"
4679                            "(surf=%08x,vis=%d,raise=%d,hint=%d)",
4680                            (int)mgr->resource, usurf->surfaceid, param1, param2, param3);
4681                 ico_window_mgr_send_window_visible(mgr->resource,
4682                                                    usurf->surfaceid, param1, param2, param3);
4683                 break;
4684
4685             case ICO_WINDOW_MGR_WINDOW_CONFIGURE:
4686                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) CONFIGURE"
4687                            "(surf=%08x,app=%s,node=%x,type=%x,layer=%d,"
4688                            "x/y=%d/%d,w/h=%d/%d,hint=%d)",
4689                            (int)mgr->resource, usurf->surfaceid, usurf->uclient->appid,
4690                            usurf->node_tbl->node, usurf->layertype,
4691                            usurf->win_layer->layer, param1, param2, param3, param4, param5);
4692                 ico_window_mgr_send_window_configure(mgr->resource, usurf->surfaceid,
4693                                                      usurf->node_tbl->node,
4694                                                      usurf->layertype << 12,
4695                                                      usurf->win_layer->layer,
4696                                                      param1, param2, param3, param4, param5);
4697                 break;
4698
4699             case ICO_WINDOW_MGR_WINDOW_ACTIVE:
4700                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) ACTIVE"
4701                            "(surf=%08x,active=%d)", (int)mgr->resource, usurf->surfaceid,
4702                            param1);
4703                 ico_window_mgr_send_window_active(mgr->resource, usurf->surfaceid,
4704                                                   (uint32_t)param1);
4705                 break;
4706
4707             case ICO_WINDOW_MGR_LAYER_VISIBLE:
4708                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) LAYER_VISIBLE"
4709                            "(layer=%d,visivle=%d)", (int)mgr->resource, param1, param2);
4710                 ico_window_mgr_send_layer_visible(mgr->resource, (uint32_t)param1, param2);
4711                 break;
4712
4713             default:
4714                 uifw_error("ico_win_mgr_send_to_mgr: Illegal event(%08x)", event);
4715                 break;
4716             }
4717         }
4718     }
4719     return num_mgr;
4720 }
4721
4722 /*--------------------------------------------------------------------------*/
4723 /**
4724  * @brief   win_mgr_set_scale: set surface transform scale
4725  *
4726  * @param[in]   usurf       UIFW surface
4727  * @return      chagne display
4728  * @retval      =1          change display
4729  * @retval      =0          no change
4730  */
4731 /*--------------------------------------------------------------------------*/
4732 static int
4733 win_mgr_set_scale(struct uifw_win_surface *usurf)
4734 {
4735     struct weston_surface   *es;
4736     float   scalex;
4737     float   scaley;
4738     int     ret = 0;
4739
4740     es = usurf->surface;
4741     if ((es != NULL) && (es->buffer_ref.buffer))  {
4742         if (usurf->client_width == 0)   usurf->client_width = es->geometry.width;
4743         if (usurf->client_height == 0)  usurf->client_height = es->geometry.height;
4744         if ((usurf->client_width > 0) && (usurf->client_height > 0))    {
4745             scalex = (float)usurf->width / (float)usurf->client_width;
4746             scaley = (float)usurf->height / (float)usurf->client_height;
4747         }
4748         else    {
4749             scalex = 1.0f;
4750             scaley = 1.0f;
4751         }
4752         uifw_debug("win_mgr_set_scale: %08x X=%4.2f(%d/%d) Y=%4.2f(%d/%d)",
4753                    usurf->surfaceid, scalex, usurf->width, usurf->client_width,
4754                    scaley, usurf->height, usurf->client_height);
4755         usurf->xadd = 0;
4756         usurf->yadd = 0;
4757         if ((ico_ivi_optionflag() & ICO_IVI_OPTION_FIXED_ASPECT) ||
4758             (usurf->attributes & ICO_WINDOW_MGR_ATTR_FIXED_ASPECT)) {
4759             if (scalex > scaley)    {
4760                 scalex = scaley;
4761                 if ((usurf->attributes & ICO_WINDOW_MGR_ATTR_ALIGN_LEFT) == 0)  {
4762                     usurf->xadd = (float)usurf->width - ((float)usurf->client_width * scalex);
4763                     if ((usurf->attributes & ICO_WINDOW_MGR_ATTR_ALIGN_RIGHT) == 0) {
4764                         usurf->xadd /= 2;
4765                     }
4766                 }
4767             }
4768             else if (scalex < scaley)   {
4769                 scaley = scalex;
4770                 if ((usurf->attributes & ICO_WINDOW_MGR_ATTR_ALIGN_TOP) == 0)   {
4771                     usurf->yadd = (float)usurf->height - ((float)usurf->client_height * scaley);
4772                     if ((usurf->attributes & ICO_WINDOW_MGR_ATTR_ALIGN_BOTTOM) == 0)    {
4773                         usurf->yadd /= 2;
4774                     }
4775                 }
4776             }
4777             uifw_trace("win_mgr_set_scale: %08x fixed aspect x/yadd=%d/%d",
4778                        usurf->surfaceid, usurf->xadd, usurf->yadd);
4779         }
4780         if ((scalex != usurf->scalex) || (scaley != usurf->scaley)) {
4781             usurf->scalex = scalex;
4782             usurf->scaley = scaley;
4783             if ((scalex != 1.0f) || (scaley != 1.0f))   {
4784                 weston_matrix_init(&usurf->transform.matrix);
4785                 weston_matrix_scale(&usurf->transform.matrix, scalex, scaley, 1.0f);
4786                 uifw_trace("win_mgr_set_scale: change scale(%d)", usurf->set_transform);
4787                 if (usurf->set_transform == 0)  {
4788                     usurf->set_transform = 1;
4789                     wl_list_init(&usurf->transform.link);
4790                     wl_list_insert(&es->geometry.transformation_list, &usurf->transform.link);
4791                 }
4792             }
4793             else if (usurf->set_transform != 0) {
4794                 uifw_trace("win_mgr_set_scale: reset transform");
4795                 usurf->set_transform = 0;
4796                 wl_list_remove(&usurf->transform.link);
4797             }
4798             weston_surface_geometry_dirty(es);
4799             weston_surface_update_transform(es);
4800             weston_surface_damage_below(es);
4801             weston_surface_damage(es);
4802             ret = 1;
4803         }
4804     }
4805     return ret;
4806 }
4807
4808 /*--------------------------------------------------------------------------*/
4809 /**
4810  * @brief   ico_window_mgr_get_uclient: get UIFW client table
4811  *
4812  * @param[in]   appid       application Id
4813  * @return      UIFW client table
4814  * @retval      !=NULL      success(UIFW client table address)
4815  * @retval      = NULL      error(appid not exist)
4816  */
4817 /*--------------------------------------------------------------------------*/
4818 WL_EXPORT   struct uifw_client *
4819 ico_window_mgr_get_uclient(const char *appid)
4820 {
4821     struct uifw_client *uclient;
4822
4823     wl_list_for_each (uclient, &_ico_win_mgr->client_list, link)    {
4824         if (strcmp(uclient->appid, appid) == 0) {
4825             return uclient;
4826         }
4827     }
4828     return NULL;
4829 }
4830
4831 /*--------------------------------------------------------------------------*/
4832 /**
4833  * @brief   ico_window_mgr_get_client_usurf: get client UIFW surface table
4834  *
4835  * @param[in]   target      surface window name and application Id(winname@appid)
4836  * @return      UIFW surface table
4837  * @retval      !=NULL      success(UIFW surface table address)
4838  * @retval      = NULL      error(appid or winname not exist)
4839  */
4840 /*--------------------------------------------------------------------------*/
4841 WL_EXPORT   struct uifw_win_surface *
4842 ico_window_mgr_get_client_usurf(const char *target)
4843 {
4844     struct uifw_client      *uclient;
4845     struct uifw_win_surface *usurf;
4846     int     i, j;
4847     char    winname[ICO_IVI_WINNAME_LENGTH];
4848     char    appid[ICO_IVI_APPID_LENGTH];
4849
4850     /* get window name and application id   */
4851     j = 0;
4852     for (i = 0; target[i]; i++) {
4853         if (target[i] == '@')   {
4854             if (target[i+1] != '@') break;
4855             i ++;
4856         }
4857         if (j < (ICO_IVI_WINNAME_LENGTH-1)) {
4858             winname[j++] = target[i];
4859         }
4860     }
4861     winname[j] = 0;
4862     if (target[i] == '@')   {
4863         i ++;
4864     }
4865     else    {
4866         winname[0] = 0;
4867         i = 0;
4868     }
4869     j = 0;
4870     for ( ; target[i]; i++) {
4871         if ((target[i] == '@') && (target[i+1] == '@')) i ++;
4872         if (j < (ICO_IVI_APPID_LENGTH-1))  {
4873             appid[j++] = target[i];
4874         }
4875     }
4876     appid[j] = 0;
4877     uifw_debug("ico_window_mgr_get_client_usurf: target=<%s> appid=<%s> win=<%s>",
4878                target, appid, winname);
4879
4880     wl_list_for_each (uclient, &_ico_win_mgr->client_list, link)    {
4881         if (strcmp(uclient->appid, appid) == 0) {
4882             wl_list_for_each (usurf, &uclient->surface_link, client_link)   {
4883                 if ((winname[0] == 0) ||
4884                     (strcmp(winname, usurf->winname) == 0)) {
4885                     return usurf;
4886                 }
4887             }
4888         }
4889     }
4890     return NULL;
4891 }
4892
4893 /*--------------------------------------------------------------------------*/
4894 /**
4895  * @brief   ico_window_mgr_is_visible: check surface visible
4896  *
4897  * @param[in]   usurf       UIFW surface
4898  * @return      visibility
4899  * @retval      =1          visible
4900  * @retval      =0          not visible
4901  * @retval      =-1         surface visible but layer not vlsible
4902  * @retval      =-2         surface visible but lower(currently not support)
4903  */
4904 /*--------------------------------------------------------------------------*/
4905 WL_EXPORT   int
4906 ico_window_mgr_is_visible(struct uifw_win_surface *usurf)
4907 {
4908     if ((usurf->visible == 0) || (usurf->surface == NULL) || (usurf->mapped == 0))  {
4909         return 0;
4910     }
4911     if (usurf->win_layer->visible == 0) {
4912         return -1;
4913     }
4914     return 1;
4915 }
4916
4917 /*--------------------------------------------------------------------------*/
4918 /**
4919  * @brief   ico_window_mgr_active_surface: set active surface
4920  *
4921  * @param[in]   surface     Weston surface
4922  * @return      none
4923  */
4924 /*--------------------------------------------------------------------------*/
4925 WL_EXPORT   void
4926 ico_window_mgr_active_surface(struct weston_surface *surface)
4927 {
4928     struct uifw_win_surface *usurf;
4929
4930     /* find surface         */
4931     usurf = find_uifw_win_surface_by_ws(surface);
4932     if (! usurf) {
4933         uifw_trace("ico_window_mgr_active_surface: Enter(%08x)", (int)surface);
4934         uifw_trace("ico_window_mgr_active_surface: Leave(Not Exist)");
4935         return;
4936     }
4937     uifw_trace("ico_window_mgr_active_surface: Enter(%08x)", usurf->surfaceid);
4938
4939     if ((usurf != _ico_win_mgr->active_pointer_usurf) ||
4940         (usurf != _ico_win_mgr->active_keyboard_usurf)) {
4941
4942         /* set weston active surface    */
4943         win_mgr_set_active(usurf, ICO_WINDOW_MGR_ACTIVE_POINTER |
4944                            ICO_WINDOW_MGR_ACTIVE_KEYBOARD);
4945         /* send active event to manager     */
4946         (void) ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
4947                                     usurf, ICO_WINDOW_MGR_ACTIVE_SELECTED, 0,0,0,0);
4948     }
4949     uifw_trace("ico_window_mgr_active_surface: Leave(OK)");
4950 }
4951
4952 /*--------------------------------------------------------------------------*/
4953 /**
4954  * @brief   ico_window_mgr_set_hook_animation: set animation hook routine
4955  *
4956  * @param[in]   hook_animation  hook routine
4957  * @return      none
4958  */
4959 /*--------------------------------------------------------------------------*/
4960 WL_EXPORT   void
4961 ico_window_mgr_set_hook_animation(int (*hook_animation)(const int op, void *data))
4962 {
4963     win_mgr_hook_animation = hook_animation;
4964 }
4965
4966 /*--------------------------------------------------------------------------*/
4967 /**
4968  * @brief   ico_window_mgr_set_hook_change: set input region hook routine
4969  *
4970  * @param[in]   hook_change     hook routine
4971  * @return      none
4972  */
4973 /*--------------------------------------------------------------------------*/
4974 WL_EXPORT   void
4975 ico_window_mgr_set_hook_change(void (*hook_change)(struct uifw_win_surface *usurf))
4976 {
4977     win_mgr_hook_change = hook_change;
4978 }
4979
4980 /*--------------------------------------------------------------------------*/
4981 /**
4982  * @brief   ico_window_mgr_set_hook_destory: set input region hook routine
4983  *
4984  * @param[in]   hook_destroy    hook routine
4985  * @return      none
4986  */
4987 /*--------------------------------------------------------------------------*/
4988 WL_EXPORT   void
4989 ico_window_mgr_set_hook_destory(void (*hook_destroy)(struct uifw_win_surface *usurf))
4990 {
4991     win_mgr_hook_destory = hook_destroy;
4992 }
4993
4994 /*--------------------------------------------------------------------------*/
4995 /**
4996  * @brief   ico_window_mgr_set_hook_inputregion: set input region hook routine
4997  *
4998  * @param[in]   hook_inputregion    hook routine
4999  * @return      none
5000  */
5001 /*--------------------------------------------------------------------------*/
5002 WL_EXPORT   void
5003 ico_window_mgr_set_hook_inputregion(
5004         void (*hook_inputregion)(int set, struct uifw_win_surface *usurf,
5005                                  int32_t x, int32_t y, int32_t width,
5006                                  int32_t height, int32_t hotspot_x, int32_t hotspot_y,
5007                                  int32_t cursor_x, int32_t cursor_y, int32_t cursor_width,
5008                                  int32_t cursor_height, uint32_t attr))
5009 {
5010     win_mgr_hook_inputregion = hook_inputregion;
5011 }
5012
5013 /*--------------------------------------------------------------------------*/
5014 /**
5015  * @brief   module_init: initialize ico_window_mgr
5016  *                       this function called from ico_pluign_loader
5017  *
5018  * @param[in]   es          weston compositor
5019  * @param[in]   argc        number of arguments(unused)
5020  * @param[in]   argv        argument list(unused)
5021  * @return      result
5022  * @retval      0           sccess
5023  * @retval      -1          error
5024  */
5025 /*--------------------------------------------------------------------------*/
5026 WL_EXPORT   int
5027 module_init(struct weston_compositor *ec, int *argc, char *argv[])
5028 {
5029     int     nodeId;
5030     int     i;
5031     int     idx;
5032     struct weston_output *output;
5033     struct weston_config_section *section;
5034     char    *displayno = NULL;
5035     char    *p;
5036     char    *wrkstrp;
5037     struct wl_event_loop *loop;
5038
5039     uifw_info("ico_window_mgr: Enter(module_init)");
5040
5041     /* get ivi debug level                      */
5042     section = weston_config_get_section(ec->config, "ivi-option", NULL, NULL);
5043     if (section)    {
5044         weston_config_section_get_int(section, "flag", &_ico_ivi_option_flag, 0);
5045         weston_config_section_get_int(section, "log", &_ico_ivi_debug_level, 3);
5046     }
5047
5048     /* get display number                       */
5049     section = weston_config_get_section(ec->config, "ivi-display", NULL, NULL);
5050     if (section)    {
5051         weston_config_section_get_string(section, "displayno", &displayno, NULL);
5052         weston_config_section_get_int(section, "inputpanel",
5053                                       &_ico_ivi_inputpanel_display, 0);
5054     }
5055
5056     /* get layer id                             */
5057     section = weston_config_get_section(ec->config, "ivi-layer", NULL, NULL);
5058     if (section)    {
5059         weston_config_section_get_int(section, "default", &_ico_ivi_default_layer, 1);
5060         weston_config_section_get_int(section, "background", &_ico_ivi_background_layer, 0);
5061         weston_config_section_get_int(section, "touch", &_ico_ivi_touch_layer, 101);
5062         weston_config_section_get_int(section, "cursor", &_ico_ivi_cursor_layer, 102);
5063         weston_config_section_get_int(section, "startup", &_ico_ivi_startup_layer, 103);
5064         weston_config_section_get_string(section, "inputpaneldeco", &wrkstrp, NULL);
5065         if (wrkstrp)  {
5066             p = strtok(wrkstrp, ";,");
5067             if (p)  {
5068                 _ico_ivi_inputdeco_mag = strtol(p, (char **)0, 0);
5069                 p = strtok(NULL, ";,");
5070                 if (p)  {
5071                     _ico_ivi_inputdeco_diff = strtol(p, (char **)0, 0);
5072                 }
5073             }
5074             free(wrkstrp);
5075         }
5076     }
5077     if (_ico_ivi_inputdeco_mag < 20)    _ico_ivi_inputdeco_mag = 100;
5078
5079     /* get animation default                    */
5080     section = weston_config_get_section(ec->config, "ivi-animation", NULL, NULL);
5081     if (section)    {
5082         weston_config_section_get_string(section, "default", &_ico_ivi_animation_name, NULL);
5083         weston_config_section_get_string(section, "inputpanel",
5084                                          &_ico_ivi_inputpanel_animation, NULL);
5085         weston_config_section_get_int(section, "time", &_ico_ivi_animation_time, 500);
5086         weston_config_section_get_int(section, "fps", &_ico_ivi_animation_fps, 30);
5087         if (_ico_ivi_animation_name)    {
5088             p = strtok(_ico_ivi_animation_name, ";,");
5089             if (p)  {
5090                 p = strtok(NULL, ";.");
5091                 if (p)  {
5092                     _ico_ivi_animation_time = strtol(p, (char **)0, 0);
5093                     p = strtok(NULL, ";.");
5094                     if (p)  {
5095                         _ico_ivi_animation_fps = strtol(p, (char **)0, 0);
5096                     }
5097                 }
5098             }
5099         }
5100         if (_ico_ivi_inputpanel_animation)  {
5101             p = strtok(_ico_ivi_inputpanel_animation, ";,");
5102             if (p)  {
5103                 p = strtok(NULL, ",;");
5104                 if (p)  {
5105                     _ico_ivi_inputpanel_anima_time = strtol(p, (char **)0, 0);
5106                 }
5107             }
5108         }
5109     }
5110     if (_ico_ivi_animation_name == NULL)
5111         _ico_ivi_animation_name = (char *)"fade";
5112     if (_ico_ivi_inputpanel_animation == NULL)
5113         _ico_ivi_inputpanel_animation = (char *)"fade";
5114     if (_ico_ivi_animation_time < 100)  _ico_ivi_animation_time = 500;
5115     if (_ico_ivi_animation_fps < 3)     _ico_ivi_animation_fps = 30;
5116     if (_ico_ivi_inputpanel_anima_time < 100)
5117         _ico_ivi_inputpanel_anima_time = _ico_ivi_animation_time;
5118
5119     /* get thumbnail maximum frame rate     */
5120     section = weston_config_get_section(ec->config, "ivi-thumbnail", NULL, NULL);
5121     if (section)    {
5122         weston_config_section_get_int(section, "gpu_accel_fps",
5123                                       &_ico_ivi_map_framerate_gpu, 30);
5124         if ((_ico_ivi_map_framerate_gpu <= 0) || (_ico_ivi_map_framerate_gpu > 60)) {
5125             _ico_ivi_map_framerate_gpu = 30;
5126         }
5127         weston_config_section_get_int(section, "shm_buffer_fps",
5128                                       &_ico_ivi_map_framerate_shm, 5);
5129         if ((_ico_ivi_map_framerate_shm <= 0) || (_ico_ivi_map_framerate_shm > 10)) {
5130             _ico_ivi_map_framerate_shm = 5;
5131         }
5132         weston_config_section_get_int(section, "no_accel_fps",
5133                                       &_ico_ivi_map_framerate_pixel, 10);
5134         if ((_ico_ivi_map_framerate_pixel <= 0) || (_ico_ivi_map_framerate_pixel > 20)) {
5135             _ico_ivi_map_framerate_pixel = 10;
5136         }
5137     }
5138
5139     /* create ico_window_mgr management table   */
5140     _ico_win_mgr = (struct ico_win_mgr *)malloc(sizeof(struct ico_win_mgr));
5141     if (_ico_win_mgr == NULL)   {
5142         uifw_error("ico_window_mgr: malloc failed");
5143         return -1;
5144     }
5145
5146     memset(_ico_win_mgr, 0, sizeof(struct ico_win_mgr));
5147     _ico_win_mgr->surfaceid_map = (uint16_t *) malloc(INIT_SURFACE_IDS/8);
5148     if (! _ico_win_mgr->surfaceid_map)  {
5149         uifw_error("ico_window_mgr: malloc failed");
5150         return -1;
5151     }
5152     memset(_ico_win_mgr->surfaceid_map, 0, INIT_SURFACE_IDS/8);
5153
5154     _ico_win_mgr->compositor = ec;
5155
5156     _ico_win_mgr->surfaceid_max = INIT_SURFACE_IDS;
5157     _ico_win_mgr->surfaceid_count = INIT_SURFACE_IDS;
5158
5159     uifw_trace("ico_window_mgr: wl_global_create(bind_ico_win_mgr)");
5160     if (wl_global_create(ec->wl_display, &ico_window_mgr_interface, 1,
5161                          _ico_win_mgr, bind_ico_win_mgr) == NULL)  {
5162         uifw_error("ico_window_mgr: Error(wl_global_create)");
5163         return -1;
5164     }
5165
5166     wl_list_init(&_ico_win_mgr->client_list);
5167     wl_list_init(&_ico_win_mgr->manager_list);
5168     wl_list_init(&_ico_win_mgr->ivi_layer_list);
5169     wl_list_init(&_ico_win_mgr->map_list);
5170
5171     _ico_win_mgr->free_maptable = NULL;
5172
5173     /* create display list                  */
5174     if (displayno != NULL)   {
5175         p = displayno;
5176     }
5177     else    {
5178         p = NULL;
5179     }
5180     _ico_num_nodes = 0;
5181     wl_list_for_each (output, &ec->output_list, link) {
5182         wl_list_init(&_ico_win_mgr->map_animation[_ico_num_nodes].link);
5183         _ico_win_mgr->map_animation[_ico_num_nodes].frame = win_mgr_check_mapsurface;
5184         wl_list_insert(output->animation_list.prev,
5185                        &_ico_win_mgr->map_animation[_ico_num_nodes].link);
5186         _ico_num_nodes++;
5187         if (_ico_num_nodes >= ICO_IVI_MAX_DISPLAY)   break;
5188     }
5189     memset(&_ico_node_table[0], 0, sizeof(_ico_node_table));
5190     i = 0;
5191     wl_list_for_each (output, &ec->output_list, link) {
5192         p = strtok(p, ",");
5193         if (p)  {
5194             idx = strtol(p, (char **)0, 0);
5195             uifw_trace("ico_window_mgr: config Display.%d is weston display.%d", i, idx);
5196             p = NULL;
5197             if ((idx < 0) || (idx >= _ico_num_nodes))   {
5198                 idx = i;
5199             }
5200         }
5201         else    {
5202             idx = i;
5203         }
5204         if (_ico_node_table[idx].node)  {
5205             for (idx = 0; idx < _ico_num_nodes; idx++)  {
5206                 if (_ico_node_table[idx].node == 0) break;
5207             }
5208             if (idx >= _ico_num_nodes)  {
5209                 uifw_error("ico_window_mgr: number of display overflow");
5210                 idx = 0;
5211             }
5212         }
5213         _ico_node_table[idx].node = idx + 0x100;
5214         _ico_node_table[idx].displayno = i;
5215         _ico_node_table[idx].output = output;
5216         _ico_node_table[idx].disp_x = output->x;
5217         _ico_node_table[idx].disp_y = output->y;
5218         _ico_node_table[idx].disp_width = output->width;
5219         _ico_node_table[idx].disp_height = output->height;
5220         i ++;
5221         if (i >= _ico_num_nodes) break;
5222     }
5223     idx = 0;
5224     for (i = 0; i < _ico_num_nodes; i++)    {
5225         _ico_node_table[i].node &= 0x0ff;
5226         uifw_info("ico_window_mgr: Display.%d no=%d x/y=%d/%d w/h=%d/%d",
5227                   i, _ico_node_table[i].displayno,
5228                   _ico_node_table[i].disp_x, _ico_node_table[i].disp_y,
5229                   _ico_node_table[i].disp_width, _ico_node_table[i].disp_height);
5230     }
5231     if (displayno)  free(displayno);
5232
5233     if (_ico_ivi_inputpanel_display >= _ico_num_nodes)  {
5234         _ico_ivi_inputpanel_display = 0;
5235     }
5236     uifw_info("ico_window_mgr: inputpanel_display=%d", _ico_ivi_inputpanel_display);
5237
5238     /* set default display to ico_ivi_shell */
5239     ivi_shell_set_default_display(_ico_node_table[_ico_ivi_inputpanel_display].output);
5240
5241     /* my node Id ... this version fixed 0  */
5242     nodeId = ico_ivi_get_mynode();
5243
5244     _ico_win_mgr->surface_head = ICO_IVI_SURFACEID_BASE(nodeId);
5245     uifw_trace("ico_window_mgr: NoedId=%04x SurfaceIdBase=%08x",
5246                 nodeId, _ico_win_mgr->surface_head);
5247
5248     /* get seat for touch down counter check    */
5249     touch_check_seat = container_of(ec->seat_list.next, struct weston_seat, link);
5250     loop = wl_display_get_event_loop(ec->wl_display);
5251     _ico_win_mgr->wait_mapevent =
5252             wl_event_loop_add_timer(loop, win_mgr_timer_mapsurface, NULL);
5253     wl_event_source_timer_update(_ico_win_mgr->wait_mapevent, 1000);
5254
5255     /* Hook to IVI-Shell                            */
5256     ico_ivi_shell_hook_bind(win_mgr_bind_client);
5257     ico_ivi_shell_hook_unbind(win_mgr_unbind_client);
5258     ico_ivi_shell_hook_create(win_mgr_register_surface);
5259     ico_ivi_shell_hook_destroy(win_mgr_destroy_surface);
5260     ico_ivi_shell_hook_map(win_mgr_surface_map);
5261     ico_ivi_shell_hook_configure(win_mgr_shell_configure);
5262     ico_ivi_shell_hook_select(win_mgr_select_surface);
5263     ico_ivi_shell_hook_title(win_mgr_set_title);
5264     ico_ivi_shell_hook_move(win_mgr_surface_move);
5265     ico_ivi_shell_hook_show_layer(win_mgr_show_layer);
5266     ico_ivi_shell_hook_fullscreen(win_mgr_fullscreen);
5267
5268     uifw_info("ico_window_mgr: animation name=%s/%s time=%d/%d fps=%d",
5269               _ico_ivi_animation_name, _ico_ivi_inputpanel_animation,
5270               _ico_ivi_animation_time, _ico_ivi_inputpanel_anima_time,
5271               _ico_ivi_animation_fps);
5272     uifw_info("ico_window_mgr: input panel mag=%d%% diff=%d",
5273               _ico_ivi_inputdeco_mag,_ico_ivi_inputdeco_diff);
5274     uifw_info("ico_window_mgr: layer default=%d background=%d",
5275               _ico_ivi_default_layer, _ico_ivi_background_layer);
5276     uifw_info("ico_window_mgr: layer touch=%d cursor=%d startup=%d",
5277               _ico_ivi_touch_layer, _ico_ivi_cursor_layer, _ico_ivi_startup_layer);
5278     uifw_info("ico_window_mgr: thumbnail framerate gpu_accel=%d shm_buff=%d no_accel=%d",
5279               _ico_ivi_map_framerate_gpu, _ico_ivi_map_framerate_shm,
5280               _ico_ivi_map_framerate_pixel);
5281     uifw_info("ico_window_mgr: option flag=0x%04x log level=%d debug flag=0x%04x",
5282               _ico_ivi_option_flag, _ico_ivi_debug_level & 0x0ffff,
5283               (_ico_ivi_debug_level >> 16) & 0x0ffff);
5284
5285     /* get GPU type for H/W support of the thumbnail acquisition    */
5286     if (ico_ivi_optionflag() & ICO_IVI_OPTION_GPU_NODEPEND) {
5287         /* can not use GPU H/W dependent acceleration   */
5288         _ico_ivi_gpu_type = ICO_GPUTYPE_NOACCELERATION;
5289         uifw_info("ico_window_mgr: GPU type=No Acceleration by option flag");
5290     }
5291     else if (ico_ivi_optionflag() & ICO_IVI_OPTION_GPU_DEPENDINTEL) {
5292         /* use Intel GPU H/W dependent acceleration     */
5293         _ico_ivi_gpu_type = ICO_GPUTYPE_INTEL_SANDYBRIDGE;
5294         uifw_info("ico_window_mgr: GPU type=Acceleration Intel GPU by option flag");
5295     }
5296     else    {
5297         _ico_ivi_gpu_type = ICO_GPUTYPE_NOACCELERATION;
5298
5299         p = (char *)glGetString(GL_RENDERER);
5300         if (p)  {
5301             uifw_info("ico_window_mgr: Renderer=<%s>", p);
5302             for (i = 0; ico_window_mgr_gpu_type[i].gpu_type; i++)   {
5303                 if (strncmp(p, ico_window_mgr_gpu_type[i].gpu_name,
5304                             strlen(ico_window_mgr_gpu_type[i].gpu_name)) == 0)  {
5305                     _ico_ivi_gpu_type = ico_window_mgr_gpu_type[i].gpu_type;
5306                     uifw_info("ico_window_mgr: GPU type=Acceleration %d", _ico_ivi_gpu_type);
5307                     break;
5308                 }
5309             }
5310         }
5311         if (_ico_ivi_gpu_type == ICO_GPUTYPE_NOACCELERATION)    {
5312             uifw_info("ico_window_mgr: GPU type=No Acceleration(can not find GPU)");
5313         }
5314     }
5315     uifw_info("ico_window_mgr: Leave(module_init)");
5316
5317     return 0;
5318 }