6b86ff1bc9a0423bb15007235fb70f6da26d5089
[profile/ivi/ico-uxf-homescreen.git] / lib / system-controller / CicoSCWlWinMgrIF.cpp
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 //==========================================================================
11 /**
12  *  @file   CicoSCWlWinMgrIF.cpp
13  *
14  *  @brief  This file implementation of CicoSCWlInputMgrIF class
15  */
16 //==========================================================================
17
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <sys/types.h>
21 #include <fcntl.h>
22 #include <cstring>
23
24 #include "ico_syc_type.h"
25 #include "CicoSCWlWinMgrIF.h"
26 #include "CicoLog.h"
27 #include "CicoSystemConfig.h"
28 #include "CicoConf.h"
29 #include "CicoSCWindowController.h"
30
31 //==========================================================================
32 //  static variables
33 //==========================================================================
34 struct ico_window_mgr *CicoSCWlWinMgrIF::m_winmgr = NULL;
35 struct ivi_application *CicoSCWlWinMgrIF::m_ivi_app = NULL;
36 struct ivi_controller *CicoSCWlWinMgrIF::m_ivi_ctrl = NULL;
37 struct wl_output *CicoSCWlWinMgrIF::m_wloutput = NULL;
38
39 int CicoSCWlWinMgrIF::m_id_surface = 0;
40
41 struct creation_surface_wait    *CicoSCWlWinMgrIF::m_wait_surface_creation = NULL;
42 struct creation_surface_wait    *CicoSCWlWinMgrIF::m_free_surface_creation = NULL;
43
44 //--------------------------------------------------------------------------
45 /**
46  *  @brief  default constructor
47  */
48 //--------------------------------------------------------------------------
49 CicoSCWlWinMgrIF::CicoSCWlWinMgrIF()
50 {
51     // ico_window_mgr listener
52     m_listener.window_active    = wlActiveCB;
53     m_listener.map_surface      = wlMapSurfaceCB;
54     m_listener.update_surface   = wlUpdateSurfaceCB;
55     m_listener.destroy_surface  = wlDestroySurfaceCB;
56
57     // genivi ivi_application listener
58     m_ivi_app_listener.error = wlIviAppErrorCB;
59     m_ivi_app_listener.wl_shell_info = wlIviAppNativeShellInfoCB;
60
61     // genivi ivi_controller listener
62     m_ivi_ctrl_listener.screen = wlIviCtrlScreenCB;
63     m_ivi_ctrl_listener.layer = wlIviCtrlLayerCB;
64     m_ivi_ctrl_listener.surface = wlIviCtrlSurfaceCB;
65     m_ivi_ctrl_listener.error = wlIviCtrlErrorCB;
66     m_ivi_ctrl_listener.native_handle = wlIviCtrlNativeHandleCB;
67
68     // wayland output listener
69     m_wlOutputListener.geometry = wlOutputGeometryCB;
70     m_wlOutputListener.mode     = wlOutputModeCB;
71 }
72
73 //--------------------------------------------------------------------------
74 /**
75  *  @brief  destructor
76  */
77 //--------------------------------------------------------------------------
78 CicoSCWlWinMgrIF::~CicoSCWlWinMgrIF()
79 {
80 }
81
82 //--------------------------------------------------------------------------
83 /**
84  *  @brief  initialize ico_window_mgr interfaces
85  *
86  *  @param [in] data        user data
87  *  @param [in] registry    wayland registry
88  *  @param [in] name        wayland display id
89  *  @parma [in] interface   wayland interface name
90  *  @parma [in] version     wayland interface version number
91  */
92 //--------------------------------------------------------------------------
93 void
94 CicoSCWlWinMgrIF::initInterface(void               *data,
95                                 struct wl_registry *registry,
96                                 uint32_t           name,
97                                 const char         *interface,
98                                 uint32_t           version)
99 {
100     ICO_TRA("CicoSCWlWinMgrIF::initInterface Enter(interface=%s)", interface);
101
102     // check interface name
103     if (0 == strcmp(interface, ICO_WL_WIN_MGR_IF)) {
104         // get interface instance
105         ICO_DBG("called: wl_registry_bind");
106         void *wlProxy = wl_registry_bind(registry,
107                                          name,
108                                          &ico_window_mgr_interface,
109                                          1);
110         if (NULL == wlProxy) {
111             ICO_WRN("interface(%s) wl_registry_bind failed.",
112                     interface);
113             ICO_TRA("CicoSCWlWinMgrIF::initInterface Leave(binding failed)");
114             return;
115         }
116
117
118         m_winmgr = (struct ico_window_mgr *)wlProxy;
119         ico_window_mgr_add_listener(m_winmgr,
120                                     &m_listener,
121                                     this);
122     }
123     else if (0 == strcmp(interface, ICO_WL_IVI_APPLICATION_IF)) {
124         // get interface instance
125         ICO_DBG("called: wl_registry_bind for ivi_application");
126         void *wlProxy = wl_registry_bind(registry,
127                                          name,
128                                          &ivi_application_interface,
129                                          1);
130         if (NULL == wlProxy) {
131             ICO_WRN("interface(%s) wl_registry_bind failed.",
132                     interface);
133             ICO_TRA("CicoSCWlWinMgrIF::initInterface Leave(binding failed)");
134             return;
135         }
136         m_ivi_app = (struct ivi_application *)wlProxy;
137         ivi_application_add_listener(m_ivi_app,
138                                      &m_ivi_app_listener,
139                                      this);
140     }
141     else if (0 == strcmp(interface, ICO_WL_IVI_CONTROLLER_IF)) {
142         // get interface instance
143         ICO_DBG("called: wl_registry_bind for ivi_controller");
144         void *wlProxy = wl_registry_bind(registry,
145                                          name,
146                                          &ivi_controller_interface,
147                                          1);
148         if (NULL == wlProxy) {
149             ICO_WRN("interface(%s) wl_registry_bind failed.",
150                     interface);
151             ICO_TRA("CicoSCWlWinMgrIF::initInterface Leave(binding failed)");
152             return;
153         }
154         m_ivi_ctrl = (struct ivi_controller *)wlProxy;
155         ivi_controller_add_listener(m_ivi_ctrl,
156                                     &m_ivi_ctrl_listener,
157                                     this);
158     }
159     else if (0 == strcmp(interface, ICO_WL_OUTPUT_IF)) {
160         // get interface instance
161         ICO_DBG("called: wl_registry_bind");
162         void *wlProxy = wl_registry_bind(registry,
163                                          name,
164                                          &wl_output_interface,
165                                          1);
166         if (NULL == wlProxy) {
167             ICO_WRN("interface(%s) wl_registry_bind failed.",
168                     interface);
169             ICO_TRA("CicoSCWlWinMgrIF::initInterface Leave(binding failed)");
170             return;
171         }
172
173         m_wloutput = (struct wl_output*)wlProxy;
174         wl_output_add_listener(m_wloutput,
175                                &m_wlOutputListener,
176                                this);
177     }
178     else {
179         ICO_WRN("unmatch interface");
180         ICO_TRA("CicoSCWlWinMgrIF::initInterface Leave(unmatch interface)");
181         return;
182     }
183
184     if((NULL != m_winmgr) && (NULL != m_wloutput)) {
185         m_initialized = true;
186     }
187
188     ICO_TRA("CicoSCWlWinMgrIF::initInterface Leave");
189 }
190
191 //--------------------------------------------------------------------------
192 /**
193  *  @brief   wrapper function of ilm_layerAddSurface
194  *
195  *  @param [in] surfaceid       wayland surface id
196  *  @param [in] layer           layer id
197  *  @param [in] oldlayer        old layer id(if 0xffffffff, no old layer)
198  */
199 //--------------------------------------------------------------------------
200 void
201 CicoSCWlWinMgrIF::setWindowLayer(uint32_t surfaceid, uint32_t layer, uint32_t oldlayer)
202 {
203     // set window layer request to Multi Window Manager
204     ICO_DBG("CicoSCWlWinMgrIF::setWindowLayer: "
205             "surfaceid=0x%08X layer=%d->%d", surfaceid, oldlayer, layer);
206
207     if (oldlayer == layer)  {
208         ICO_DBG("CicoSCWlWinMgrIF::setWindowLayer: new layer same as old, NOP");
209         return;
210     }
211
212     // remove original layer
213     if (oldlayer <= 0x7fffffff) {
214         ICO_TRA("CicoSCWlWinMgrIF::setWindowLayer: remove surface %08x "
215                 "from layer(%d)", surfaceid, oldlayer);
216         if (ilm_layerRemoveSurface(oldlayer, surfaceid) != ILM_SUCCESS) {
217             ICO_ERR("CicoSCWlWinMgrIF::setWindowLayer ilm_layerRemoveSurface(%d,%08x) "
218                     "Error", oldlayer, surfaceid);
219         }
220         // must need ilm_commitChanges() after ilm_layerRemoveSurface()
221         if (ilm_commitChanges() != ILM_SUCCESS) {
222             ICO_ERR("CicoSCWlWinMgrIF::setWindowLayer ilm_commitChanges Error");
223         }
224     }
225     else    {
226         ICO_TRA("CicoSCWlWinMgrIF::setWindowLayer: surface %08x has no old layer(%d)",
227                 surfaceid, oldlayer);
228     }
229
230     // add new layer
231     if (ilm_layerAddSurface(layer, surfaceid) != ILM_SUCCESS)   {
232         ICO_ERR("CicoSCWlWinMgrIF::setWindowLayer ilm_layerAddSurface(%d,%08x) Error",
233                 layer, surfaceid);
234     }
235     if (ilm_commitChanges() != ILM_SUCCESS) {
236         ICO_ERR("CicoSCWlWinMgrIF::setWindowLayer ilm_commitChanges Error");
237     }
238 }
239
240 //--------------------------------------------------------------------------
241 /**
242  *  @brief   wrapper function of ilm_surfaceSetDestinationRectangle
243  *
244  *  @param [in] surfaceid       wayland surface id
245  *  @param [in] layer           number of layer
246  *  @param [in] x
247  *  @param [in] y
248  *  @param [in] width
249  *  @param [in] height
250  */
251 //--------------------------------------------------------------------------
252 void
253 CicoSCWlWinMgrIF::setPositionsize(uint32_t surfaceid, uint32_t node,
254                                   int32_t x, int32_t y, int32_t width, int32_t height)
255 {
256     // set position size request to Multi Window Manager
257     ICO_DBG("called: ilm_surfaceSetDestinationRectangle"
258             "(surfaceid=0x%08X node=%d x=%d y=%d w=%d h=%d)",
259             surfaceid, node, x, y, width, height);
260
261     if (ilm_surfaceSetDestinationRectangle(surfaceid, x, y, width, height)
262             != ILM_SUCCESS) {
263         ICO_ERR("CicoSCWlWinMgrIF::setPositionsize ilm_surfaceSetDestinationRectangle"
264                 "(%08x,%d,%d,%d,%d) Error", surfaceid, x, y, width, height);
265     }
266     else if (ilm_surfaceSetSourceRectangle(surfaceid, 0, 0, width, height)
267             != ILM_SUCCESS) {
268         ICO_ERR("CicoSCWlWinMgrIF::setPositionsize ilm_surfaceSetSourceRectangle"
269                 "(%08x,0,0,%d,%d) Error", surfaceid, width, height);
270     }
271     else if (ilm_commitChanges() != ILM_SUCCESS)    {
272         ICO_ERR("CicoSCWlWinMgrIF::setPositionsize ilm_commitChanges() Error");
273     }
274 }
275
276 //--------------------------------------------------------------------------
277 /**
278  *  @brief   wrapper function of ilm_surfaceSetVisibility
279  *
280  *  @param [in] surfaceid       wayland surface id
281  *  @param [in] visible         visible state
282  */
283 //--------------------------------------------------------------------------
284 void
285 CicoSCWlWinMgrIF::setVisible(uint32_t surfaceid, int32_t visible)
286 {
287     // set visible request to Multi Window Manager
288     ICO_DBG("called: ilm_surfaceSetVisibility(surfaceid=0x%08X visible=%d)",
289             surfaceid, visible);
290     if ((visible == ICO_SYC_WIN_VISIBLE_SHOW) || (visible == ICO_SYC_WIN_VISIBLE_HIDE)) {
291         ilm_surfaceSetVisibility(surfaceid, visible);
292         if (ilm_commitChanges() != ILM_SUCCESS) {
293             ICO_ERR("CicoSCWlWinMgrIF::setVisible: ilm_commitChanges() Error");
294         }
295     }
296 }
297
298 //--------------------------------------------------------------------------
299 /**
300  *  @brief   wrapper function of ico_window_mgr_set_animation
301  *
302  *  @param [in] surfaceid       wayland surface id
303  *  @param [in] type            transition type
304  *  @param [in] animation       name of animation
305  *  @param [in] time            time of animation
306  */
307 //--------------------------------------------------------------------------
308 void
309 CicoSCWlWinMgrIF::setAnimation(uint32_t surfaceid, int32_t type,
310                                const char *animation, int32_t time)
311 {
312     ICO_DBG("called: ico_window_mgr_set_animation"
313             "(surfaceid=0x%08X type=%d anima=%s time=%d)",
314             surfaceid, type, animation, time);
315     ico_window_mgr_set_animation(m_winmgr, surfaceid, type, animation, time);
316 }
317
318 //--------------------------------------------------------------------------
319 /**
320  *  @brief   wrapper function of ilm_SetKeyboardFocusOn
321  *
322  *  @param [in] surfaceid       wayland surface id
323  *  @param [in] active          flags or active device(unused)
324  */
325 //--------------------------------------------------------------------------
326 void
327 CicoSCWlWinMgrIF::setActive(uint32_t surfaceid, int32_t active)
328 {
329     ICO_DBG("called: ilm_SetKeyboardFocusOn"
330             "(surfaceid=0x%08X active=%d)", surfaceid, active);
331     if ((ilm_SetKeyboardFocusOn(surfaceid) != ILM_SUCCESS) ||
332         (ilm_commitChanges() != ILM_SUCCESS))   {
333         ICO_ERR("CicoSCWlWinMgrIF::setActive ilm_SetKeyboardFocusOn(%08x) Error", surfaceid);
334     }
335 }
336
337 //--------------------------------------------------------------------------
338 /**
339  *  @brief   wrapper function of ilm_layerSetVisibility
340  *
341  *  @param [in] surfaceid       wayland surface id
342  *  @param [in] layer           id of layer
343  *  @param [in] visible         visible state
344  */
345 //--------------------------------------------------------------------------
346 void
347 CicoSCWlWinMgrIF::setLayerVisible(uint32_t layer, int32_t visible)
348 {
349     ICO_DBG("called: ilm_layerSetVisibility"
350             "(layer=%d visible=%d)", layer, visible);
351     if ((ilm_layerSetVisibility(layer, visible) != ILM_SUCCESS) ||
352         (ilm_commitChanges() != ILM_SUCCESS))   {
353         ICO_ERR("CicoSCWlWinMgrIF::setLayerVisible ilm_layerSetVisibility(%d,%d) Error",
354                 layer, visible);
355     }
356 }
357
358 //--------------------------------------------------------------------------
359 /**
360  *  @brief   wrapper function of ilm_takeSurfaceScreenshot
361  *
362  *  @param [in] surface     id of wayland surface
363  *  @param [in] filepath    surface image pixel file path
364  */
365 //--------------------------------------------------------------------------
366 void
367 CicoSCWlWinMgrIF::setmapGet(int surfaceid, const char *filepath)
368 {
369     ICO_DBG("called: ilm_takeSurfaceScreenshot(filepath=%s,, surface=0x%08x)",
370             filepath ? filepath : "(null)", surfaceid);
371     if ((ilm_takeSurfaceScreenshot(filepath, surfaceid) != ILM_SUCCESS) ||
372         (ilm_commitChanges() != ILM_SUCCESS))   {
373         ICO_ERR("CicoSCWlWinMgrIF::setmapGet ilm_takeSurfaceScreenshot(%s,%x) Error",
374                 filepath ? filepath : "(null)", surfaceid);
375     }
376 }
377
378 //--------------------------------------------------------------------------
379 /**
380  *  @brief   wrapper function of ico_window_mgr_map_surface
381  *
382  *  @param [in] surface     id of wayland surface
383  *  @param [in] framerate   interval of changed notify[frame per second]
384  *  @param [in] filepath    surface image pixel file path
385  */
386 //--------------------------------------------------------------------------
387 void
388 CicoSCWlWinMgrIF::mapSurface(uint32_t surfaceid, int32_t framerate, const char *filepath)
389 {
390     ICO_DBG("called: ico_window_mgr_map_surface(surfaceid=0x%08X framerate=%d file=%s)",
391             surfaceid, framerate, filepath ? filepath : "(null)");
392     // currently GENIVI genivi-shell not support contents change, so use ico_window_mgr
393     if ((filepath != NULL) && (*filepath != 0) && (*filepath != ' '))   {
394         ico_window_mgr_map_surface(m_winmgr, surfaceid, framerate, filepath);
395     }
396     else    {
397         ico_window_mgr_map_surface(m_winmgr, surfaceid, framerate, " ");
398     }
399 }
400
401 //--------------------------------------------------------------------------
402 /**
403  *  @brief   wrapper function of ico_window_mgr_unmap_surface
404  *
405  *  @param [in] surface     id of wayland surface
406  */
407 //--------------------------------------------------------------------------
408 void
409 CicoSCWlWinMgrIF::unmapSurface(uint32_t surfaceid)
410 {
411     ICO_DBG("called: ico_window_mgr_unmap_surface"
412             "(surfaceid=0x%08X)", surfaceid);
413     // currently GENIVI genivi-shell not support contents change, so use ico_window_mgr
414     ico_window_mgr_unmap_surface(m_winmgr, surfaceid);
415 }
416
417 //--------------------------------------------------------------------------
418 /**
419  *  @brief   get creation surface window name(title) and pid
420  *
421  *  @param [in]  id_surface surface id
422  *  @param [out] pid        application process id
423  */
424 //--------------------------------------------------------------------------
425 const char *
426 CicoSCWlWinMgrIF::wlIviCtrlGetSurfaceWaiting(uint32_t id_surface, int *pid)
427 {
428     struct creation_surface_wait    *tp = m_wait_surface_creation;
429
430     while (tp)   {
431         if (tp->id_surface == id_surface)   {
432             ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlGetSurfaceWaiting(%x) pid=%d title=<%s>",
433                     id_surface, tp->pid, tp->title);
434             *pid = tp->pid;
435             return tp->title;
436         }
437         tp = tp->next;
438     }
439     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlGetSurfaceWaiting(%x) dose not exist", id_surface);
440     return NULL;
441 }
442
443 //--------------------------------------------------------------------------
444 /**
445  *  @brief   remove surface window
446  *
447  *  @param [in]  id_surface surface id
448  */
449 //--------------------------------------------------------------------------
450 void
451 CicoSCWlWinMgrIF::wlIviCtrlRemoveSurface(uint32_t id_surface)
452 {
453     struct creation_surface_wait    *tp = m_wait_surface_creation;
454     struct creation_surface_wait    *bp = NULL;
455
456     while (tp)   {
457         if (tp->id_surface == id_surface)   {
458             if (bp) {
459                 bp->next = tp->next;
460             }
461             else    {
462                 m_wait_surface_creation = tp->next;
463             }
464             tp->next = m_free_surface_creation;
465             m_free_surface_creation = tp;
466
467             ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlRemoveSurface(%x) removed", id_surface);
468             return;
469         }
470     }
471     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlRemoveSurface(%x) dose not exist", id_surface);
472 }
473
474 //--------------------------------------------------------------------------
475 /**
476  *  @brief  wayland surface active callback
477  *
478  *  @param [in] data            user data(unused)
479  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
480  *  @param [in] surfaceid       ico_window_mgr surface Id
481  *  @param [in] select          select device(unused)
482  *                              (0=not active/1=pointer/2=touch)
483  */
484 //--------------------------------------------------------------------------
485 void
486 CicoSCWlWinMgrIF::activeCB(void                  *data,
487                            struct ico_window_mgr *ico_window_mgr,
488                            uint32_t              surfaceid,
489                            int32_t               select)
490 {
491     ICO_WRN("CicoSCWlWinMgrIF::activeCB called.");
492 }
493
494 //--------------------------------------------------------------------------
495 /**
496  *  @brief   surface map event callback
497  *
498  *  @param [in] data            user data(unused)
499  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
500  *  @param [in] event           event
501  *  @param [in] surfaceid       surface Id
502  *  @param [in] type            surface buffer type(EGL buffer/Shared memory)
503  *  @param [in] width           surface width
504  *  @param [in] height          surface height
505  *  @param [in] stride          surface buffer(frame buffer) stride
506  *  @param [in] format          surface buffer format
507  */
508 //--------------------------------------------------------------------------
509 void
510 CicoSCWlWinMgrIF::mapSurfaceCB(void                  *data,
511                                struct ico_window_mgr *ico_window_mgr,
512                                int32_t               event,
513                                uint32_t              surfaceid,
514                                uint32_t              type,
515                                int32_t               width,
516                                int32_t               height,
517                                int32_t               stride,
518                                uint32_t              format)
519 {
520     ICO_WRN("CicoSCWlWinMgrIF::mapSurfaceCB called.");
521 }
522
523 //--------------------------------------------------------------------------
524 /**
525  *  @brief   surface update event callback
526  *
527  *  @param [in] data            user data(unused)
528  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
529  *  @param [in] surfaceid       surface Id
530  *  @param [in] visible         visibility
531  *  @param [in] srcwidth        application buffer width
532  *  @param [in] srcheight       application buffer height
533  *  @param [in] x               X
534  *  @param [in] y               Y
535  *  @param [in] width           width
536  *  @param [in] height          height
537  */
538 //--------------------------------------------------------------------------
539 void
540 CicoSCWlWinMgrIF::updateSurfaceCB(void                  *data,
541                                   struct ico_window_mgr *ico_window_mgr,
542                                   uint32_t              surfaceid,
543                                   int                   visible,
544                                   int                   srcwidth,
545                                   int                   srcheight,
546                                   int                   x,
547                                   int                   y,
548                                   int                   width,
549                                   int                   height)
550 {
551     ICO_WRN("CicoSCWlWinMgrIF::updateSurfaceCB called.");
552 }
553
554 //--------------------------------------------------------------------------
555 /**
556  *  @brief  wayland surface destroy callback
557  *
558  *  @param [in] data            user data(unused)
559  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
560  *  @param [in] surfaceid       surface Id
561  */
562 //--------------------------------------------------------------------------
563 void
564 CicoSCWlWinMgrIF::destroySurfaceCB(void                  *data,
565                                    struct ico_window_mgr *ico_window_mgr,
566                                    uint32_t              surfaceid)
567 {
568     ICO_WRN("CicoSCWlWinMgrIF::destroySurfaceCB called.");
569 }
570
571 //--------------------------------------------------------------------------
572 /**
573  *  @brief  wayland update surface name callback
574  *
575  *  @param [in] surfaceid       surface Id
576  *  @param [in] winname         surface name (title)
577  */
578 //--------------------------------------------------------------------------
579 void
580 CicoSCWlWinMgrIF::updateWinnameCB(uint32_t surfaceid,
581                                   const char *winname)
582 {
583     ICO_WRN("CicoSCWlWinMgrIF::updateWinnameCB called.");
584 }
585
586 //--------------------------------------------------------------------------
587 /**
588  *  @brief   wayland display attribute callback
589  *
590  *  @param [in] data            user data(unused)
591  *  @param [in] wl_output       wayland wl_output interface
592  *  @param [in] x               display upper-left X coordinate
593  *  @param [in] y               display upper-left Y coordinate
594  *  @param [in] physical_width  display physical width
595  *  @param [in] physical_height display physical height
596  *  @param [in] subpixel        display sub pixel
597  *  @param [in] make            display maker
598  *  @param [in] model           display model
599  *  @param [in] transform       transform
600  */
601 //--------------------------------------------------------------------------
602 void
603 CicoSCWlWinMgrIF::outputGeometryCB(void             *data,
604                                    struct wl_output *wl_output,
605                                    int32_t          x,
606                                    int32_t          y,
607                                    int32_t          physical_width,
608                                    int32_t          physical_height,
609                                    int32_t          subpixel,
610                                    const char       *make,
611                                    const char       *model,
612                                    int32_t          transform)
613 {
614     ICO_WRN("CicoSCWlWinMgrIF::outputGeometryCB called.");
615 }
616
617 //--------------------------------------------------------------------------
618 /**
619  *  @brief  wayland display mode callback
620  *
621  *  @param [in] data        user data(unused)
622  *  @param [in] wl_output   wayland wl_output interface
623  *  @param [in] flags       flags
624  *  @param [in] width       display width
625  *  @param [in] height      display height
626  *  @param [in] refresh     display refresh rate
627  */
628 //--------------------------------------------------------------------------
629 void
630 CicoSCWlWinMgrIF::outputModeCB(void             *data,
631                                struct wl_output *wl_output,
632                                uint32_t         flags,
633                                int32_t          width,
634                                int32_t          height,
635                                int32_t          refresh)
636 {
637     ICO_WRN("CicoSCWlWinMgrIF::outputModeCB called.");
638 };
639
640 //--------------------------------------------------------------------------
641 /**
642  *  @brief   wayland genivi ivi-surface create callback
643  *
644  *  @param [in] data            user data(unused)
645  *  @param [in] ivi_controller  wayland ivi-controller plugin interface
646  *  @param [in] id_surface      surface id
647  */
648 //--------------------------------------------------------------------------
649 void
650 CicoSCWlWinMgrIF::createSurfaceCB(void                  *data,
651                                   struct ivi_controller *ivi_controller,
652                                   uint32_t id_surface)
653 {
654     ICO_WRN("CicoSCWlWinMgrIF::createSurfaceCB called.");
655 }
656
657 //==========================================================================
658 // private method
659 //==========================================================================
660
661 //--------------------------------------------------------------------------
662 /**
663  *  @brief  wayland surface active callback
664  *
665  *  @param [in] data            user data(unused)
666  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
667  *  @param [in] surfaceid       ico_window_mgr surface Id
668  *  @param [in] select          select device(unused)
669  *                              (0=not active/1=pointer/2=touch)
670  */
671 //--------------------------------------------------------------------------
672 void
673 CicoSCWlWinMgrIF::wlActiveCB(void                  *data,
674                              struct ico_window_mgr *ico_window_mgr,
675                              uint32_t              surfaceid,
676                              int32_t               select)
677 {
678 //    ICO_TRA("CicoSCWlWinMgrIF::wlActiveCB Enter");
679
680     if (NULL == data) {
681         ICO_WRN("wlActiveCB: data is null");
682         return;
683     }
684     static_cast<CicoSCWlWinMgrIF*>(data)->activeCB(data, ico_window_mgr,
685                                                    surfaceid, select);
686 //    ICO_TRA("CicoSCWlWinMgrIF::wlActiveCB Leave");
687 }
688
689 //--------------------------------------------------------------------------
690 /**
691  *  @brief   surface map event callback
692  *
693  *  @param [in] data            user data
694  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
695  *  @param [in] event           event
696  *  @param [in] surfaceid       surface Id
697  *  @param [IN] type            buffer type(fixed ICO_WINDOW_MGR_MAP_TYPE_EGL)
698  *  @param [in] width           surface width
699  *  @param [in] height          surface height
700  *  @param [in] stride          surface buffer(frame buffer) stride
701  *  @param [in] format          surface buffer format
702  */
703 //--------------------------------------------------------------------------
704 void
705 CicoSCWlWinMgrIF::wlMapSurfaceCB(void                  *data,
706                                  struct ico_window_mgr *ico_window_mgr,
707                                  int32_t               event,
708                                  uint32_t              surfaceid,
709                                  uint32_t              type,
710                                  int32_t               width,
711                                  int32_t               height,
712                                  int32_t               stride,
713                                  uint32_t              format)
714 {
715 //    ICO_TRA("CicoSCWlWinMgrIF::wlMapSurfaceCB Enter");
716
717     if (NULL == data) {
718         ICO_WRN("wlMapSurfaceCB: data is null");
719         return;
720     }
721     static_cast<CicoSCWlWinMgrIF*>(data)->mapSurfaceCB(data, ico_window_mgr,
722                                                        event, surfaceid,
723                                                        type,
724                                                        width, height,
725                                                        stride, format);
726 //    ICO_TRA("CicoSCWlWinMgrIF::wlMapSurfaceCB Leave");
727 }
728
729 //--------------------------------------------------------------------------
730 /**
731  *  @brief   surface update event callback
732  *
733  *  @param [in] data            user data
734  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
735  *  @param [in] surfaceid       surface Id
736  *  @param [in] visible         visibility
737  *  @param [in] srcwidth        application buffer width
738  *  @param [in] srcheight       application buffer height
739  *  @param [in] x               X
740  *  @param [in] y               Y
741  *  @param [in] width           width
742  *  @param [in] height          height
743  */
744 //--------------------------------------------------------------------------
745 void
746 CicoSCWlWinMgrIF::wlUpdateSurfaceCB(void                  *data,
747                                     struct ico_window_mgr *ico_window_mgr,
748                                     uint32_t              surfaceid,
749                                     int                   visible,
750                                     int                   srcwidth,
751                                     int                   srcheight,
752                                     int                   x,
753                                     int                   y,
754                                     int                   width,
755                                     int                   height)
756 {
757 //    ICO_TRA("CicoSCWlWinMgrIF::wlUpdateSurfaceCB Enter");
758
759     if (NULL == data) {
760         ICO_WRN("wlUpdateSurfaceCB: data is null");
761         return;
762     }
763     static_cast<CicoSCWlWinMgrIF*>(data)->updateSurfaceCB(data, ico_window_mgr,
764                                                           surfaceid, visible,
765                                                           srcwidth, srcheight,
766                                                           x, y, width, height);
767 //    ICO_TRA("CicoSCWlWinMgrIF::wlUpdateSurfaceCB Leave");
768 }
769
770 //--------------------------------------------------------------------------
771 /**
772  *  @brief   surface destroy event callback
773  *
774  *  @param [in] data            user data
775  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
776  *  @param [in] surfaceid       surface Id
777  */
778 //--------------------------------------------------------------------------
779 void
780 CicoSCWlWinMgrIF::wlDestroySurfaceCB(void                  *data,
781                                      struct ico_window_mgr *ico_window_mgr,
782                                      uint32_t             surfaceid)
783 {
784 //    ICO_TRA("CicoSCWlWinMgrIF::wlDestroySurfaceCB Enter");
785
786     if (NULL == data) {
787         ICO_WRN("wlDestroySurfaceCB: data is null");
788         return;
789     }
790     wlIviCtrlRemoveSurface(surfaceid);
791
792     static_cast<CicoSCWlWinMgrIF*>(data)->destroySurfaceCB(data, ico_window_mgr,
793                                                            surfaceid);
794 //    ICO_TRA("CicoSCWlWinMgrIF::wlDestroySurfaceCB Leave");
795 }
796
797 //--------------------------------------------------------------------------
798 /**
799  *  @brief   wayland display attribute callback
800  *
801  *  @param [in] data            user data(unused)
802  *  @param [in] wl_output       wayland wl_output interface
803  *  @param [in] x               display upper-left X coordinate
804  *  @param [in] y               display upper-left Y coordinate
805  *  @param [in] physical_width  display physical width
806  *  @param [in] physical_height display physical height
807  *  @param [in] subpixel        display sub pixel
808  *  @param [in] make            display maker
809  *  @param [in] model           display model
810  *  @param [in] transform       transform
811  */
812 //--------------------------------------------------------------------------
813 void
814 CicoSCWlWinMgrIF::wlOutputGeometryCB(void             *data,
815                                      struct wl_output *wl_output,
816                                      int32_t          x,
817                                      int32_t          y,
818                                      int32_t          physical_width,
819                                      int32_t          physical_height,
820                                      int32_t          subpixel,
821                                      const char       *make,
822                                      const char       *model,
823                                      int32_t          transform)
824 {
825 //    ICO_TRA("CicoSCWlWinMgrIF::wlOutputGeometryCB Enter");
826
827     if (NULL == data) {
828         ICO_WRN("wlOutputGeometryCB: data is null");
829         return;
830     }
831     static_cast<CicoSCWlWinMgrIF*>(data)->outputGeometryCB(data, wl_output,
832                                                            x, y,
833                                                            physical_width,
834                                                            physical_height,
835                                                            subpixel,
836                                                            make,
837                                                            model,
838                                                            transform);
839 //    ICO_TRA("CicoSCWlWinMgrIF::wlOutputGeometryCB Leave");
840 }
841
842 //--------------------------------------------------------------------------
843 /**
844  *  @brief  wayland display mode callback
845  *
846  *  @param [in] data        user data(unused)
847  *  @param [in] wl_output   wayland wl_output interface
848  *  @param [in] flags       flags
849  *  @param [in] width       display width
850  *  @param [in] height      display height
851  *  @param [in] refresh     display refresh rate
852  */
853 //--------------------------------------------------------------------------
854 void
855 CicoSCWlWinMgrIF::wlOutputModeCB(void             *data,
856                                  struct wl_output *wl_output,
857                                  uint32_t         flags,
858                                  int32_t          width,
859                                  int32_t          height,
860                                  int32_t          refresh)
861 {
862 //    ICO_TRA("CicoSCWlWinMgrIF::wlOutputModeCB Enter");
863
864     if (NULL == data) {
865         ICO_WRN("wlOutputGeometryCB: data is null");
866         return;
867     }
868     static_cast<CicoSCWlWinMgrIF*>(data)->outputModeCB(data, wl_output, flags,
869                                                        width, height, refresh);
870 //    ICO_TRA("CicoSCWlWinMgrIF::wlOutputModeCB Leave");
871 }
872
873 //--------------------------------------------------------------------------
874 /**
875  *  @brief  wayland ivi-shell ivi-application protocol error callback
876  *
877  *  @param [in] data            user data(unused)
878  *  @param [in] ivi_application wayland ivi-application interface
879  *  @param [in] error_code      error code
880  *  @param [in] error_text      error message
881  */
882 //--------------------------------------------------------------------------
883 void
884 CicoSCWlWinMgrIF::wlIviAppErrorCB(void *data,
885                                  struct ivi_application *ivi_application,
886                                  int32_t error_code, const char *error_text)
887 {
888     ICO_TRA("CicoSCWlWinMgrIF::wlIviAppErrorCB: Enter(%d,%s)",
889             error_code, error_text ? error_text : "(null)");
890
891     if (NULL == data) {
892         ICO_WRN("CicoSCWlWinMgrIF::wlIviAppErrorCB: data is null");
893         return;
894     }
895     ICO_TRA("CicoSCWlWinMgrIF::wlIviAppErrorCB: Leave");
896 }
897
898 //--------------------------------------------------------------------------
899 /**
900  *  @brief  wayland ivi-shell ivi-application protocol create wl_surface callback
901  *
902  *  @param [in] data            user data(unused)
903  *  @param [in] ivi_application wayland ivi-application interface
904  *  @param [in] pid             application process id
905  *  @param [in] title           surface title name
906  */
907 //--------------------------------------------------------------------------
908 void
909 CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB(void *data,
910                                             struct ivi_application *ivi_application,
911                                             int32_t pid, const char *title)
912 {
913     struct creation_surface_wait    *tp;
914     struct creation_surface_wait    *tp2;
915
916     ICO_TRA("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: Enter(%d,<%s>)",
917             pid, title ? title : "(null)");
918
919     if (NULL == data) {
920         ICO_WRN("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: Leave(data is null)");
921         return;
922     }
923     if (title == NULL)  {
924         ICO_TRA("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: Leave(no title)");
925         return;
926     }
927
928     // bind wl_surface to ivi_surface
929     tp = m_free_surface_creation;
930     if (tp)  {
931         m_free_surface_creation = tp->next;
932     }
933     else    {
934         tp = (struct creation_surface_wait *)malloc(sizeof(struct creation_surface_wait));
935         if (! tp)    {
936             ICO_ERR("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: out of memory");
937             return;
938         }
939         memset(tp, 0, sizeof(struct creation_surface_wait));
940     }
941     tp2 = m_wait_surface_creation;
942     tp->next = tp2;
943     m_wait_surface_creation = tp;
944     tp->pid = pid;
945     strncpy(tp->title, title, ICO_SYC_MAX_WINNAME_LEN-1);
946     tp->busy = SCWINMGR_GENIVI_BUSY_WAIT;
947     while (tp2)  {
948         if (tp2->busy != SCWINMGR_GENIVI_BUSY_NONE) break;
949         tp2 = tp2->next;
950     }
951     if (! tp2)   {
952         tp->busy = SCWINMGR_GENIVI_BUSY_REQSURF;
953         ICO_TRA("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: "
954                 "call ivi_controller_get_native_handle(%d,<%s>)", pid, title);
955         ivi_controller_get_native_handle(m_ivi_ctrl, pid, title);
956     }
957     ICO_TRA("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: Leave");
958 }
959
960 //--------------------------------------------------------------------------
961 /**
962  *  @brief  wayland ivi-shell ivi-controller protocol create screen callback
963  *
964  *  @param [in] data            user data(unused)
965  *  @param [in] ivi_controller  wayland ivi-controller interface
966  *  @param [in] id_screen       screen id
967  *  @param [in] screen          screen information
968  */
969 //--------------------------------------------------------------------------
970 void
971 CicoSCWlWinMgrIF::wlIviCtrlScreenCB(void *data,
972                                     struct ivi_controller *ivi_controller,
973                                     uint32_t id_screen,
974                                     struct ivi_controller_screen *screen)
975 {
976     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlScreenCB: Enter(%x)", id_screen);
977
978     if (NULL == data) {
979         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlScreenCB: data is null");
980         return;
981     }
982     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlScreenCB: Leave");
983 }
984
985 //--------------------------------------------------------------------------
986 /**
987  *  @brief  wayland ivi-shell ivi-controller protocol create layer callback
988  *
989  *  @param [in] data            user data(unused)
990  *  @param [in] ivi_controller  wayland ivi-controller interface
991  *  @param [in] id_layer        layer id
992  */
993 //--------------------------------------------------------------------------
994 void
995 CicoSCWlWinMgrIF::wlIviCtrlLayerCB(void *data,
996                                    struct ivi_controller *ivi_controller,
997                                    uint32_t id_layer)
998 {
999     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlLayerCB: Enter(%x)", id_layer);
1000
1001     if (NULL == data) {
1002         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlLayerCB: data is null");
1003         return;
1004     }
1005     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlLayerCB: Leave");
1006 }
1007
1008 //--------------------------------------------------------------------------
1009 /**
1010  *  @brief  wayland ivi-shell ivi-controller protocol create surface callback
1011  *
1012  *  @param [in] data            user data(unused)
1013  *  @param [in] ivi_controller  wayland ivi-controller interface
1014  *  @param [in] id_surface      surface id
1015  */
1016 //--------------------------------------------------------------------------
1017 void
1018 CicoSCWlWinMgrIF::wlIviCtrlSurfaceCB(void *data,
1019                                      struct ivi_controller *ivi_controller,
1020                                      uint32_t id_surface)
1021 {
1022     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlSurfaceCB: Enter(%x)", id_surface);
1023
1024     if (NULL == data) {
1025         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlSurfaceCB: data is null");
1026         return;
1027     }
1028
1029     static_cast<CicoSCWlWinMgrIF*>(data)->createSurfaceCB(data, ivi_controller, id_surface);
1030
1031     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlSurfaceCB: Leave");
1032 }
1033
1034 //--------------------------------------------------------------------------
1035 /**
1036  *  @brief  wayland ivi-shell ivi-controller protocol error callback
1037  *
1038  *  @param [in] data            user data(unused)
1039  *  @param [in] ivi_controller  wayland ivi-controller interface
1040  *  @param [in] error_code      error code
1041  *  @param [in] error_text      error message
1042  */
1043 //--------------------------------------------------------------------------
1044 void
1045 CicoSCWlWinMgrIF::wlIviCtrlErrorCB(void *data,
1046                                    struct ivi_controller *ivi_controller,
1047                                    int32_t object_id, int32_t object_type,
1048                                    int32_t error_code, const char *error_text)
1049 {
1050     struct creation_surface_wait    *tp;
1051     struct creation_surface_wait    *tp2;
1052
1053     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlErrorCB: Enter(%d[%d],%d,<%s>)",
1054             object_id, object_type, error_code, error_text ? error_text : "(null)");
1055
1056     if (NULL == data) {
1057         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlErrorCB: data is null");
1058         return;
1059     }
1060
1061     // search request wait
1062     tp = m_wait_surface_creation;
1063     tp2 = NULL;
1064     while (tp)  {
1065         if (tp->busy == SCWINMGR_GENIVI_BUSY_WAIT)  {
1066             tp2 = tp;
1067         }
1068         else if (tp->busy != SCWINMGR_GENIVI_BUSY_NONE) {
1069             tp->busy = SCWINMGR_GENIVI_BUSY_NONE;
1070         }
1071         tp = tp->next;
1072     }
1073     if (tp2 != NULL)    {
1074         tp2->busy = SCWINMGR_GENIVI_BUSY_REQSURF;
1075         ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlErrorCB: "
1076                 "call ivi_controller_get_native_handle(%d,<%s>)", tp2->pid, tp2->title);
1077         ivi_controller_get_native_handle(m_ivi_ctrl, tp2->pid, tp2->title);
1078     }
1079     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlErrorCB: Leave");
1080 }
1081
1082 //--------------------------------------------------------------------------
1083 /**
1084  *  @brief  wayland ivi-shell ivi-controller protocol error callback
1085  *
1086  *  @param [in] data            user data(unused)
1087  *  @param [in] ivi_controller  wayland ivi-controller interface
1088  *  @param [in] error_code      error code
1089  *  @param [in] error_text      error message
1090  */
1091 //--------------------------------------------------------------------------
1092 void
1093 CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB(void *data,
1094                                           struct ivi_controller *ivi_controller,
1095                                           struct wl_surface *surface)
1096 {
1097     uint32_t                        id_surface;
1098     struct creation_surface_wait    *tp;
1099     struct creation_surface_wait    *tp2;
1100     struct creation_surface_wait    *bp;
1101
1102     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: Enter(surf=%08x)", (int)surface);
1103
1104     if (NULL == data) {
1105         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: Leave(data is null)");
1106         return;
1107     }
1108
1109     // check same surface
1110     tp = m_wait_surface_creation;
1111     bp = NULL;
1112     while (tp)  {
1113         if (tp->busy == SCWINMGR_GENIVI_BUSY_REQSURF)   break;
1114         bp = tp;
1115         tp = tp->next;
1116     }
1117     if (! tp)   {
1118         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: Leave(no request)");
1119         return;
1120     }
1121     if (tp->surface == surface) {
1122         tp->busy = SCWINMGR_GENIVI_BUSY_NONE;
1123         ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: winname change(%08x,<%s>)",
1124                 tp->id_surface, tp->title);
1125         id_surface = tp->id_surface;
1126         static_cast<CicoSCWlWinMgrIF*>(data)->updateWinnameCB(id_surface, tp->title);
1127
1128         // title change, delete old table
1129         tp2 = m_wait_surface_creation;
1130         bp = NULL;
1131         while (tp2) {
1132             if (tp2 != tp)  {
1133                 if (tp2->surface == surface)    {
1134                     if (bp) {
1135                         bp->next = tp2->next;
1136                     }
1137                     else    {
1138                         m_wait_surface_creation = tp2->next;
1139                     }
1140                     tp2->next = m_free_surface_creation;
1141                     m_free_surface_creation = tp2;
1142                     tp2 = m_wait_surface_creation;
1143                     bp = NULL;
1144                     continue;
1145                 }
1146             }
1147             bp = tp2;
1148             tp2 = tp2->next;
1149         }
1150     }
1151     else    {
1152         // create ivi-surface and bind to wl_surface
1153         m_id_surface ++;
1154         if (m_id_surface >= 0x00ffffff)     m_id_surface = 1;
1155         id_surface = m_id_surface | 0x40000000;
1156
1157         ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: "
1158                 "call ivi_application_surface_create(%08x)", id_surface);
1159         if (ivi_application_surface_create(m_ivi_app, id_surface, surface) == NULL) {
1160             ICO_ERR("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: "
1161                     "ivi_application_surface_create(%08x) Error", id_surface);
1162             if (bp) {
1163                 bp->next = tp->next;
1164             }
1165             else    {
1166                 m_wait_surface_creation = tp->next;
1167             }
1168             tp->next = m_free_surface_creation;
1169             m_free_surface_creation = tp;
1170         }
1171         else    {
1172             tp->surface = surface;
1173             tp->id_surface = id_surface;
1174             tp->busy = SCWINMGR_GENIVI_BUSY_REQBIND;
1175         }
1176     }
1177
1178     // search request wait
1179     tp = m_wait_surface_creation;
1180     tp2 = NULL;
1181     while (tp)  {
1182         if (tp->busy == SCWINMGR_GENIVI_BUSY_WAIT)  {
1183             tp2 = tp;
1184         }
1185         else if (tp->busy != SCWINMGR_GENIVI_BUSY_NONE) {
1186             break;
1187         }
1188         tp = tp->next;
1189     }
1190     if ((tp == NULL) && (tp2 != NULL))  {
1191         tp2->busy = SCWINMGR_GENIVI_BUSY_REQSURF;
1192         ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: "
1193                 "call ivi_controller_get_native_handle(%d,<%s>)", tp2->pid, tp2->title);
1194         ivi_controller_get_native_handle(m_ivi_ctrl, tp2->pid, tp2->title);
1195     }
1196     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: Leave(id_surface=%08x)", id_surface);
1197 }
1198 // vim:set expandtab ts=4 sw=4: