88771f2c46ec221a0e04522e73d3640e15ef7e20
[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 "CicoSCWayland.h"
27 #include "CicoLog.h"
28 #include "CicoSystemConfig.h"
29 #include "CicoConf.h"
30 #include "CicoSCWindowController.h"
31
32 //==========================================================================
33 //  static variables
34 //==========================================================================
35 struct ico_window_mgr *CicoSCWlWinMgrIF::m_winmgr = NULL;
36 struct ivi_application *CicoSCWlWinMgrIF::m_ivi_app = NULL;
37 struct ivi_controller *CicoSCWlWinMgrIF::m_ivi_ctrl = NULL;
38 struct wl_output *CicoSCWlWinMgrIF::m_wloutput = NULL;
39
40 int CicoSCWlWinMgrIF::m_id_surface = 0;
41
42 struct creation_surface_wait    *CicoSCWlWinMgrIF::m_wait_surface_creation = NULL;
43 struct creation_surface_wait    *CicoSCWlWinMgrIF::m_free_surface_creation = NULL;
44
45 //--------------------------------------------------------------------------
46 /**
47  *  @brief  default constructor
48  */
49 //--------------------------------------------------------------------------
50 CicoSCWlWinMgrIF::CicoSCWlWinMgrIF()
51 {
52     // ico_window_mgr listener
53     m_listener.window_active    = wlActiveCB;
54     m_listener.map_surface      = wlMapSurfaceCB;
55     m_listener.update_surface   = wlUpdateSurfaceCB;
56     m_listener.destroy_surface  = wlDestroySurfaceCB;
57
58     // genivi ivi_application listener
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=%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=%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=%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=%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     // need wayland flush for GENIVI layer management
317     CicoSCWayland::getInstance()->flushDisplay();
318 }
319
320 //--------------------------------------------------------------------------
321 /**
322  *  @brief   wrapper function of ilm_SetKeyboardFocusOn
323  *
324  *  @param [in] surfaceid       wayland surface id
325  *  @param [in] active          flags or active device(unused)
326  */
327 //--------------------------------------------------------------------------
328 void
329 CicoSCWlWinMgrIF::setActive(uint32_t surfaceid, int32_t active)
330 {
331     ICO_DBG("called: ilm_SetKeyboardFocusOn"
332             "(surfaceid=%08x active=%d)", surfaceid, active);
333     if ((ilm_SetKeyboardFocusOn(surfaceid) != ILM_SUCCESS) ||
334         (ilm_commitChanges() != ILM_SUCCESS))   {
335         ICO_ERR("CicoSCWlWinMgrIF::setActive ilm_SetKeyboardFocusOn(%08x) Error", surfaceid);
336     }
337 }
338
339 //--------------------------------------------------------------------------
340 /**
341  *  @brief   wrapper function of ilm_layerSetVisibility
342  *
343  *  @param [in] surfaceid       wayland surface id
344  *  @param [in] layer           id of layer
345  *  @param [in] visible         visible state
346  */
347 //--------------------------------------------------------------------------
348 void
349 CicoSCWlWinMgrIF::setLayerVisible(uint32_t layer, int32_t visible)
350 {
351     ICO_DBG("called: ilm_layerSetVisibility"
352             "(layer=%d visible=%d)", layer, visible);
353     if ((ilm_layerSetVisibility(layer, visible) != ILM_SUCCESS) ||
354         (ilm_commitChanges() != ILM_SUCCESS))   {
355         ICO_ERR("CicoSCWlWinMgrIF::setLayerVisible ilm_layerSetVisibility(%d,%d) Error",
356                 layer, visible);
357     }
358 }
359
360 //--------------------------------------------------------------------------
361 /**
362  *  @brief   wrapper function of ilm_takeSurfaceScreenshot
363  *
364  *  @param [in] surface     id of wayland surface
365  *  @param [in] filepath    surface image pixel file path
366  */
367 //--------------------------------------------------------------------------
368 void
369 CicoSCWlWinMgrIF::setmapGet(int surfaceid, const char *filepath)
370 {
371     ICO_DBG("called: ilm_takeSurfaceScreenshot(filepath=%s,, surface=%08x)",
372             filepath ? filepath : "(null)", surfaceid);
373     if ((ilm_takeSurfaceScreenshot(filepath, surfaceid) != ILM_SUCCESS) ||
374         (ilm_commitChanges() != ILM_SUCCESS))   {
375         ICO_ERR("CicoSCWlWinMgrIF::setmapGet ilm_takeSurfaceScreenshot(%s,%x) Error",
376                 filepath ? filepath : "(null)", surfaceid);
377     }
378 }
379
380 //--------------------------------------------------------------------------
381 /**
382  *  @brief   wrapper function of ico_window_mgr_map_surface
383  *
384  *  @param [in] surface     id of wayland surface
385  *  @param [in] framerate   interval of changed notify[frame per second]
386  *  @param [in] filepath    surface image pixel file path
387  */
388 //--------------------------------------------------------------------------
389 void
390 CicoSCWlWinMgrIF::mapSurface(uint32_t surfaceid, int32_t framerate, const char *filepath)
391 {
392     ICO_DBG("called: ico_window_mgr_map_surface(surfaceid=%08x framerate=%d file=%s)",
393             surfaceid, framerate, filepath ? filepath : "(null)");
394     // currently GENIVI genivi-shell not support contents change, so use ico_window_mgr
395     if ((filepath != NULL) && (*filepath != 0) && (*filepath != ' '))   {
396         ico_window_mgr_map_surface(m_winmgr, surfaceid, framerate, filepath);
397     }
398     else    {
399         ico_window_mgr_map_surface(m_winmgr, surfaceid, framerate, " ");
400     }
401 }
402
403 //--------------------------------------------------------------------------
404 /**
405  *  @brief   wrapper function of ico_window_mgr_unmap_surface
406  *
407  *  @param [in] surface     id of wayland surface
408  */
409 //--------------------------------------------------------------------------
410 void
411 CicoSCWlWinMgrIF::unmapSurface(uint32_t surfaceid)
412 {
413     ICO_DBG("called: ico_window_mgr_unmap_surface"
414             "(surfaceid=%08x)", surfaceid);
415     // currently GENIVI genivi-shell not support contents change, so use ico_window_mgr
416     ico_window_mgr_unmap_surface(m_winmgr, surfaceid);
417 }
418
419 //--------------------------------------------------------------------------
420 /**
421  *  @brief   get creation surface window name(title) and pid
422  *
423  *  @param [in]  id_surface surface id
424  *  @param [out] pid        application process id
425  */
426 //--------------------------------------------------------------------------
427 const char *
428 CicoSCWlWinMgrIF::wlIviCtrlGetSurfaceWaiting(uint32_t id_surface, int *pid)
429 {
430     struct creation_surface_wait    *tp = m_wait_surface_creation;
431
432     while (tp)   {
433         if (tp->id_surface == id_surface)   {
434             ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlGetSurfaceWaiting(%x) pid=%d title=<%s>",
435                     id_surface, tp->pid, tp->title);
436             *pid = tp->pid;
437             return tp->title;
438         }
439         tp = tp->next;
440     }
441     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlGetSurfaceWaiting(%x) dose not exist", id_surface);
442     return NULL;
443 }
444
445 //--------------------------------------------------------------------------
446 /**
447  *  @brief   remove surface window
448  *
449  *  @param [in]  id_surface surface id
450  */
451 //--------------------------------------------------------------------------
452 void
453 CicoSCWlWinMgrIF::wlIviCtrlRemoveSurface(uint32_t id_surface)
454 {
455     struct creation_surface_wait    *tp = m_wait_surface_creation;
456     struct creation_surface_wait    *bp = NULL;
457
458     while (tp)   {
459         if (tp->id_surface == id_surface)   {
460             if (bp) {
461                 bp->next = tp->next;
462             }
463             else    {
464                 m_wait_surface_creation = tp->next;
465             }
466             tp->next = m_free_surface_creation;
467             m_free_surface_creation = tp;
468
469             ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlRemoveSurface(%x) removed", id_surface);
470             return;
471         }
472         bp = tp;
473         tp = tp->next;
474     }
475     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlRemoveSurface(%x) dose not exist", id_surface);
476 }
477
478 //--------------------------------------------------------------------------
479 /**
480  *  @brief  wayland surface active callback
481  *
482  *  @param [in] data            user data(unused)
483  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
484  *  @param [in] surfaceid       ico_window_mgr surface Id
485  *  @param [in] select          select device(unused)
486  *                              (0=not active/1=pointer/2=touch)
487  */
488 //--------------------------------------------------------------------------
489 void
490 CicoSCWlWinMgrIF::activeCB(void                  *data,
491                            struct ico_window_mgr *ico_window_mgr,
492                            uint32_t              surfaceid,
493                            int32_t               select)
494 {
495     ICO_WRN("CicoSCWlWinMgrIF::activeCB called.");
496 }
497
498 //--------------------------------------------------------------------------
499 /**
500  *  @brief   surface map event callback
501  *
502  *  @param [in] data            user data(unused)
503  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
504  *  @param [in] event           event
505  *  @param [in] surfaceid       surface Id
506  *  @param [in] type            surface buffer type(EGL buffer/Shared memory)
507  *  @param [in] width           surface width
508  *  @param [in] height          surface height
509  *  @param [in] stride          surface buffer(frame buffer) stride
510  *  @param [in] format          surface buffer format
511  */
512 //--------------------------------------------------------------------------
513 void
514 CicoSCWlWinMgrIF::mapSurfaceCB(void                  *data,
515                                struct ico_window_mgr *ico_window_mgr,
516                                int32_t               event,
517                                uint32_t              surfaceid,
518                                uint32_t              type,
519                                int32_t               width,
520                                int32_t               height,
521                                int32_t               stride,
522                                uint32_t              format)
523 {
524     ICO_WRN("CicoSCWlWinMgrIF::mapSurfaceCB called.");
525 }
526
527 //--------------------------------------------------------------------------
528 /**
529  *  @brief   surface update event callback
530  *
531  *  @param [in] data            user data(unused)
532  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
533  *  @param [in] surfaceid       surface Id
534  *  @param [in] visible         visibility
535  *  @param [in] srcwidth        application buffer width
536  *  @param [in] srcheight       application buffer height
537  *  @param [in] x               X
538  *  @param [in] y               Y
539  *  @param [in] width           width
540  *  @param [in] height          height
541  */
542 //--------------------------------------------------------------------------
543 void
544 CicoSCWlWinMgrIF::updateSurfaceCB(void                  *data,
545                                   struct ico_window_mgr *ico_window_mgr,
546                                   uint32_t              surfaceid,
547                                   int                   visible,
548                                   int                   srcwidth,
549                                   int                   srcheight,
550                                   int                   x,
551                                   int                   y,
552                                   int                   width,
553                                   int                   height)
554 {
555     ICO_WRN("CicoSCWlWinMgrIF::updateSurfaceCB called.");
556 }
557
558 //--------------------------------------------------------------------------
559 /**
560  *  @brief  wayland surface destroy callback
561  *
562  *  @param [in] data            user data(unused)
563  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
564  *  @param [in] surfaceid       surface Id
565  */
566 //--------------------------------------------------------------------------
567 void
568 CicoSCWlWinMgrIF::destroySurfaceCB(void                  *data,
569                                    struct ico_window_mgr *ico_window_mgr,
570                                    uint32_t              surfaceid)
571 {
572     ICO_WRN("CicoSCWlWinMgrIF::destroySurfaceCB called.");
573 }
574
575 //--------------------------------------------------------------------------
576 /**
577  *  @brief  wayland update surface name callback
578  *
579  *  @param [in] surfaceid       surface Id
580  *  @param [in] winname         surface name (title)
581  */
582 //--------------------------------------------------------------------------
583 void
584 CicoSCWlWinMgrIF::updateWinnameCB(uint32_t surfaceid,
585                                   const char *winname)
586 {
587     ICO_WRN("CicoSCWlWinMgrIF::updateWinnameCB called.");
588 }
589
590 //--------------------------------------------------------------------------
591 /**
592  *  @brief   wayland display attribute callback
593  *
594  *  @param [in] data            user data(unused)
595  *  @param [in] wl_output       wayland wl_output interface
596  *  @param [in] x               display upper-left X coordinate
597  *  @param [in] y               display upper-left Y coordinate
598  *  @param [in] physical_width  display physical width
599  *  @param [in] physical_height display physical height
600  *  @param [in] subpixel        display sub pixel
601  *  @param [in] make            display maker
602  *  @param [in] model           display model
603  *  @param [in] transform       transform
604  */
605 //--------------------------------------------------------------------------
606 void
607 CicoSCWlWinMgrIF::outputGeometryCB(void             *data,
608                                    struct wl_output *wl_output,
609                                    int32_t          x,
610                                    int32_t          y,
611                                    int32_t          physical_width,
612                                    int32_t          physical_height,
613                                    int32_t          subpixel,
614                                    const char       *make,
615                                    const char       *model,
616                                    int32_t          transform)
617 {
618     ICO_WRN("CicoSCWlWinMgrIF::outputGeometryCB called.");
619 }
620
621 //--------------------------------------------------------------------------
622 /**
623  *  @brief  wayland display mode callback
624  *
625  *  @param [in] data        user data(unused)
626  *  @param [in] wl_output   wayland wl_output interface
627  *  @param [in] flags       flags
628  *  @param [in] width       display width
629  *  @param [in] height      display height
630  *  @param [in] refresh     display refresh rate
631  */
632 //--------------------------------------------------------------------------
633 void
634 CicoSCWlWinMgrIF::outputModeCB(void             *data,
635                                struct wl_output *wl_output,
636                                uint32_t         flags,
637                                int32_t          width,
638                                int32_t          height,
639                                int32_t          refresh)
640 {
641     ICO_WRN("CicoSCWlWinMgrIF::outputModeCB called.");
642 };
643
644 //--------------------------------------------------------------------------
645 /**
646  *  @brief   wayland genivi ivi-surface create callback
647  *
648  *  @param [in] data            user data(unused)
649  *  @param [in] ivi_controller  wayland ivi-controller plugin interface
650  *  @param [in] id_surface      surface id
651  */
652 //--------------------------------------------------------------------------
653 void
654 CicoSCWlWinMgrIF::createSurfaceCB(void                  *data,
655                                   struct ivi_controller *ivi_controller,
656                                   uint32_t id_surface)
657 {
658     ICO_WRN("CicoSCWlWinMgrIF::createSurfaceCB called.");
659 }
660
661 //==========================================================================
662 // private method
663 //==========================================================================
664
665 //--------------------------------------------------------------------------
666 /**
667  *  @brief  wayland surface active callback
668  *
669  *  @param [in] data            user data(unused)
670  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
671  *  @param [in] surfaceid       ico_window_mgr surface Id
672  *  @param [in] select          select device(unused)
673  *                              (0=not active/1=pointer/2=touch)
674  */
675 //--------------------------------------------------------------------------
676 void
677 CicoSCWlWinMgrIF::wlActiveCB(void                  *data,
678                              struct ico_window_mgr *ico_window_mgr,
679                              uint32_t              surfaceid,
680                              int32_t               select)
681 {
682 //    ICO_TRA("CicoSCWlWinMgrIF::wlActiveCB Enter");
683
684     if (NULL == data) {
685         ICO_WRN("wlActiveCB: data is null");
686         return;
687     }
688     static_cast<CicoSCWlWinMgrIF*>(data)->activeCB(data, ico_window_mgr,
689                                                    surfaceid, select);
690 //    ICO_TRA("CicoSCWlWinMgrIF::wlActiveCB Leave");
691 }
692
693 //--------------------------------------------------------------------------
694 /**
695  *  @brief   surface map event callback
696  *
697  *  @param [in] data            user data
698  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
699  *  @param [in] event           event
700  *  @param [in] surfaceid       surface Id
701  *  @param [IN] type            buffer type(fixed ICO_WINDOW_MGR_MAP_TYPE_EGL)
702  *  @param [in] width           surface width
703  *  @param [in] height          surface height
704  *  @param [in] stride          surface buffer(frame buffer) stride
705  *  @param [in] format          surface buffer format
706  */
707 //--------------------------------------------------------------------------
708 void
709 CicoSCWlWinMgrIF::wlMapSurfaceCB(void                  *data,
710                                  struct ico_window_mgr *ico_window_mgr,
711                                  int32_t               event,
712                                  uint32_t              surfaceid,
713                                  uint32_t              type,
714                                  int32_t               width,
715                                  int32_t               height,
716                                  int32_t               stride,
717                                  uint32_t              format)
718 {
719 //    ICO_TRA("CicoSCWlWinMgrIF::wlMapSurfaceCB Enter");
720
721     if (NULL == data) {
722         ICO_WRN("wlMapSurfaceCB: data is null");
723         return;
724     }
725     static_cast<CicoSCWlWinMgrIF*>(data)->mapSurfaceCB(data, ico_window_mgr,
726                                                        event, surfaceid,
727                                                        type,
728                                                        width, height,
729                                                        stride, format);
730 //    ICO_TRA("CicoSCWlWinMgrIF::wlMapSurfaceCB Leave");
731 }
732
733 //--------------------------------------------------------------------------
734 /**
735  *  @brief   surface update event callback
736  *
737  *  @param [in] data            user data
738  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
739  *  @param [in] surfaceid       surface Id
740  *  @param [in] visible         visibility
741  *  @param [in] srcwidth        application buffer width
742  *  @param [in] srcheight       application buffer height
743  *  @param [in] x               X
744  *  @param [in] y               Y
745  *  @param [in] width           width
746  *  @param [in] height          height
747  */
748 //--------------------------------------------------------------------------
749 void
750 CicoSCWlWinMgrIF::wlUpdateSurfaceCB(void                  *data,
751                                     struct ico_window_mgr *ico_window_mgr,
752                                     uint32_t              surfaceid,
753                                     int                   visible,
754                                     int                   srcwidth,
755                                     int                   srcheight,
756                                     int                   x,
757                                     int                   y,
758                                     int                   width,
759                                     int                   height)
760 {
761 //    ICO_TRA("CicoSCWlWinMgrIF::wlUpdateSurfaceCB Enter");
762
763     if (NULL == data) {
764         ICO_WRN("wlUpdateSurfaceCB: data is null");
765         return;
766     }
767     static_cast<CicoSCWlWinMgrIF*>(data)->updateSurfaceCB(data, ico_window_mgr,
768                                                           surfaceid, visible,
769                                                           srcwidth, srcheight,
770                                                           x, y, width, height);
771 //    ICO_TRA("CicoSCWlWinMgrIF::wlUpdateSurfaceCB Leave");
772 }
773
774 //--------------------------------------------------------------------------
775 /**
776  *  @brief   surface destroy event callback
777  *
778  *  @param [in] data            user data
779  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
780  *  @param [in] surfaceid       surface Id
781  */
782 //--------------------------------------------------------------------------
783 void
784 CicoSCWlWinMgrIF::wlDestroySurfaceCB(void                  *data,
785                                      struct ico_window_mgr *ico_window_mgr,
786                                      uint32_t             surfaceid)
787 {
788 //    ICO_TRA("CicoSCWlWinMgrIF::wlDestroySurfaceCB Enter");
789
790     if (NULL == data) {
791         ICO_WRN("wlDestroySurfaceCB: data is null");
792         return;
793     }
794     wlIviCtrlRemoveSurface(surfaceid);
795
796     static_cast<CicoSCWlWinMgrIF*>(data)->destroySurfaceCB(data, ico_window_mgr,
797                                                            surfaceid);
798 //    ICO_TRA("CicoSCWlWinMgrIF::wlDestroySurfaceCB Leave");
799 }
800
801 //--------------------------------------------------------------------------
802 /**
803  *  @brief   wayland display attribute callback
804  *
805  *  @param [in] data            user data(unused)
806  *  @param [in] wl_output       wayland wl_output interface
807  *  @param [in] x               display upper-left X coordinate
808  *  @param [in] y               display upper-left Y coordinate
809  *  @param [in] physical_width  display physical width
810  *  @param [in] physical_height display physical height
811  *  @param [in] subpixel        display sub pixel
812  *  @param [in] make            display maker
813  *  @param [in] model           display model
814  *  @param [in] transform       transform
815  */
816 //--------------------------------------------------------------------------
817 void
818 CicoSCWlWinMgrIF::wlOutputGeometryCB(void             *data,
819                                      struct wl_output *wl_output,
820                                      int32_t          x,
821                                      int32_t          y,
822                                      int32_t          physical_width,
823                                      int32_t          physical_height,
824                                      int32_t          subpixel,
825                                      const char       *make,
826                                      const char       *model,
827                                      int32_t          transform)
828 {
829 //    ICO_TRA("CicoSCWlWinMgrIF::wlOutputGeometryCB Enter");
830
831     if (NULL == data) {
832         ICO_WRN("wlOutputGeometryCB: data is null");
833         return;
834     }
835     static_cast<CicoSCWlWinMgrIF*>(data)->outputGeometryCB(data, wl_output,
836                                                            x, y,
837                                                            physical_width,
838                                                            physical_height,
839                                                            subpixel,
840                                                            make,
841                                                            model,
842                                                            transform);
843 //    ICO_TRA("CicoSCWlWinMgrIF::wlOutputGeometryCB Leave");
844 }
845
846 //--------------------------------------------------------------------------
847 /**
848  *  @brief  wayland display mode callback
849  *
850  *  @param [in] data        user data(unused)
851  *  @param [in] wl_output   wayland wl_output interface
852  *  @param [in] flags       flags
853  *  @param [in] width       display width
854  *  @param [in] height      display height
855  *  @param [in] refresh     display refresh rate
856  */
857 //--------------------------------------------------------------------------
858 void
859 CicoSCWlWinMgrIF::wlOutputModeCB(void             *data,
860                                  struct wl_output *wl_output,
861                                  uint32_t         flags,
862                                  int32_t          width,
863                                  int32_t          height,
864                                  int32_t          refresh)
865 {
866 //    ICO_TRA("CicoSCWlWinMgrIF::wlOutputModeCB Enter");
867
868     if (NULL == data) {
869         ICO_WRN("wlOutputGeometryCB: data is null");
870         return;
871     }
872     static_cast<CicoSCWlWinMgrIF*>(data)->outputModeCB(data, wl_output, flags,
873                                                        width, height, refresh);
874 //    ICO_TRA("CicoSCWlWinMgrIF::wlOutputModeCB Leave");
875 }
876
877 //--------------------------------------------------------------------------
878 /**
879  *  @brief  wayland ivi-shell ivi-application protocol create wl_surface callback
880  *
881  *  @param [in] data            user data(unused)
882  *  @param [in] ivi_application wayland ivi-application interface
883  *  @param [in] pid             application process id
884  *  @param [in] title           surface title name
885  */
886 //--------------------------------------------------------------------------
887 void
888 CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB(void *data,
889                                             struct ivi_application *ivi_application,
890                                             int32_t pid, const char *title)
891 {
892     struct creation_surface_wait    *tp;
893     struct creation_surface_wait    *tp2;
894
895     ICO_TRA("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: Enter(%d,<%s>)",
896             pid, title ? title : "(null)");
897
898     if (NULL == data) {
899         ICO_WRN("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: Leave(data is null)");
900         return;
901     }
902     if (title == NULL)  {
903         ICO_TRA("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: Leave(no title)");
904         return;
905     }
906
907     // if same pid and same title, skip
908     tp = m_wait_surface_creation;
909     while (tp)  {
910         if ((tp->pid == pid) && (strcmp(tp->title, title) == 0))    {
911             ICO_TRA("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: Leave(same title)");
912             return;
913         }
914         tp = tp->next;
915     }
916
917     // get native surface info
918     tp = m_free_surface_creation;
919     if (tp)  {
920         m_free_surface_creation = tp->next;
921     }
922     else    {
923         tp = (struct creation_surface_wait *)malloc(sizeof(struct creation_surface_wait));
924         if (! tp)    {
925             ICO_ERR("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: out of memory");
926             return;
927         }
928     }
929     memset(tp, 0, sizeof(struct creation_surface_wait));
930     tp->next = m_wait_surface_creation;
931     tp->pid = pid;
932     strncpy(tp->title, title, ICO_SYC_MAX_WINNAME_LEN-1);
933     tp->busy = SCWINMGR_GENIVI_BUSY_WAIT;
934     tp2 = m_wait_surface_creation;
935     while (tp2)  {
936         if (tp2->busy != SCWINMGR_GENIVI_BUSY_NONE) break;
937         tp2 = tp2->next;
938     }
939     m_wait_surface_creation = tp;
940     if (! tp2)   {
941         tp->busy = SCWINMGR_GENIVI_BUSY_REQSURF;
942         ICO_TRA("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: "
943                 "call ivi_controller_get_native_handle(%d,<%s>)", pid, title);
944         ivi_controller_get_native_handle(m_ivi_ctrl, pid, title);
945     }
946     ICO_TRA("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: Leave");
947 }
948
949 //--------------------------------------------------------------------------
950 /**
951  *  @brief  wayland ivi-shell ivi-controller protocol create screen callback
952  *
953  *  @param [in] data            user data(unused)
954  *  @param [in] ivi_controller  wayland ivi-controller interface
955  *  @param [in] id_screen       screen id
956  *  @param [in] screen          screen information
957  */
958 //--------------------------------------------------------------------------
959 void
960 CicoSCWlWinMgrIF::wlIviCtrlScreenCB(void *data,
961                                     struct ivi_controller *ivi_controller,
962                                     uint32_t id_screen,
963                                     struct ivi_controller_screen *screen)
964 {
965     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlScreenCB: Enter(%x)", id_screen);
966
967     if (NULL == data) {
968         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlScreenCB: data is null");
969         return;
970     }
971     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlScreenCB: Leave");
972 }
973
974 //--------------------------------------------------------------------------
975 /**
976  *  @brief  wayland ivi-shell ivi-controller protocol create layer callback
977  *
978  *  @param [in] data            user data(unused)
979  *  @param [in] ivi_controller  wayland ivi-controller interface
980  *  @param [in] id_layer        layer id
981  */
982 //--------------------------------------------------------------------------
983 void
984 CicoSCWlWinMgrIF::wlIviCtrlLayerCB(void *data,
985                                    struct ivi_controller *ivi_controller,
986                                    uint32_t id_layer)
987 {
988     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlLayerCB: Enter(%x)", id_layer);
989
990     if (NULL == data) {
991         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlLayerCB: data is null");
992         return;
993     }
994     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlLayerCB: Leave");
995 }
996
997 //--------------------------------------------------------------------------
998 /**
999  *  @brief  wayland ivi-shell ivi-controller protocol create surface callback
1000  *
1001  *  @param [in] data            user data(unused)
1002  *  @param [in] ivi_controller  wayland ivi-controller interface
1003  *  @param [in] id_surface      surface id
1004  */
1005 //--------------------------------------------------------------------------
1006 void
1007 CicoSCWlWinMgrIF::wlIviCtrlSurfaceCB(void *data,
1008                                      struct ivi_controller *ivi_controller,
1009                                      uint32_t id_surface)
1010 {
1011     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlSurfaceCB: Enter(%x)", id_surface);
1012
1013     if (NULL == data) {
1014         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlSurfaceCB: data is null");
1015         return;
1016     }
1017
1018     static_cast<CicoSCWlWinMgrIF*>(data)->createSurfaceCB(data, ivi_controller, id_surface);
1019
1020     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlSurfaceCB: Leave");
1021 }
1022
1023 //--------------------------------------------------------------------------
1024 /**
1025  *  @brief  wayland ivi-shell ivi-controller protocol error callback
1026  *
1027  *  @param [in] data            user data(unused)
1028  *  @param [in] ivi_controller  wayland ivi-controller interface
1029  *  @param [in] error_code      error code
1030  *  @param [in] error_text      error message
1031  */
1032 //--------------------------------------------------------------------------
1033 void
1034 CicoSCWlWinMgrIF::wlIviCtrlErrorCB(void *data,
1035                                    struct ivi_controller *ivi_controller,
1036                                    int32_t object_id, int32_t object_type,
1037                                    int32_t error_code, const char *error_text)
1038 {
1039     struct creation_surface_wait    *tp;
1040     struct creation_surface_wait    *tp2;
1041     struct creation_surface_wait    *deltp;
1042
1043     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlErrorCB: Enter(%d[%d],%d,<%s>)",
1044             object_id, object_type, error_code, error_text ? error_text : "(null)");
1045
1046     if (NULL == data) {
1047         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlErrorCB: data is null");
1048         return;
1049     }
1050
1051     // search request wait
1052     tp = m_wait_surface_creation;
1053     tp2 = NULL;
1054     deltp = NULL;
1055     while (tp)  {
1056         if (tp->busy == SCWINMGR_GENIVI_BUSY_WAIT)  {
1057             tp2 = tp;
1058         }
1059         else if (tp->busy == SCWINMGR_GENIVI_BUSY_REQSURF)  {
1060             deltp = tp;
1061         }
1062         else if (tp->busy != SCWINMGR_GENIVI_BUSY_NONE) {
1063             tp->busy = SCWINMGR_GENIVI_BUSY_NONE;
1064         }
1065         tp = tp->next;
1066     }
1067     if (deltp)  {
1068         if (m_wait_surface_creation == deltp)   {
1069             m_wait_surface_creation = deltp->next;
1070         }
1071         else    {
1072             tp = m_wait_surface_creation;
1073             while(tp->next != deltp)    {
1074                 tp = tp->next;
1075             }
1076             if (tp) {
1077                 tp->next = deltp->next;
1078             }
1079         }
1080         deltp->next = m_free_surface_creation;
1081         m_free_surface_creation = deltp;
1082     }
1083     if (tp2 != NULL)    {
1084         tp2->busy = SCWINMGR_GENIVI_BUSY_REQSURF;
1085         ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlErrorCB: "
1086                 "call ivi_controller_get_native_handle(%d,<%s>)", tp2->pid, tp2->title);
1087         ivi_controller_get_native_handle(m_ivi_ctrl, tp2->pid, tp2->title);
1088     }
1089     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlErrorCB: Leave");
1090 }
1091
1092 //--------------------------------------------------------------------------
1093 /**
1094  *  @brief  wayland ivi-shell ivi-controller protocol native handle callback
1095  *
1096  *  @param [in] data            user data(unused)
1097  *  @param [in] ivi_controller  wayland ivi-controller interface
1098  *  @param [in] surface         weston_surface object
1099  */
1100 //--------------------------------------------------------------------------
1101 void
1102 CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB(void *data,
1103                                           struct ivi_controller *ivi_controller,
1104                                           struct wl_surface *surface)
1105 {
1106     struct creation_surface_wait    *tp;
1107     struct creation_surface_wait    *tp2;
1108     struct creation_surface_wait    *tp3;
1109     struct creation_surface_wait    *bp;
1110     uint32_t                        id_surface;
1111     int                             surface_count;
1112
1113     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: Enter(surf=%08x)", (int)surface);
1114
1115     if (NULL == data) {
1116         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: Leave(data is null)");
1117         return;
1118     }
1119
1120     // check same surface
1121     tp = m_wait_surface_creation;
1122     bp = NULL;
1123     while (tp)  {
1124         if (tp->busy == SCWINMGR_GENIVI_BUSY_REQSURF)   break;
1125         bp = tp;
1126         tp = tp->next;
1127     }
1128     if (! tp)   {
1129         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: Leave(no request)");
1130         return;
1131     }
1132     surface_count = 0;
1133     tp2 = NULL;
1134     tp3 = m_wait_surface_creation;
1135     while (tp3) {
1136         if ((tp != tp3) && (tp3->pid == tp->pid))   {
1137             surface_count ++;
1138             tp2 = tp3;
1139         }
1140         tp3 = tp3->next;
1141     }
1142     if (surface_count == 1) {
1143         // title change, delete old table
1144         id_surface = tp2->id_surface;
1145         ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: winname change"
1146                 "(%08x,<%s>)", id_surface, tp->title);
1147         strcpy(tp2->title, tp->title);
1148         if (bp) {
1149             bp->next = tp->next;
1150         }
1151         else    {
1152             m_wait_surface_creation = tp->next;
1153         }
1154         tp->next = m_free_surface_creation;
1155         m_free_surface_creation = tp;
1156
1157         static_cast<CicoSCWlWinMgrIF*>(data)->updateWinnameCB(tp2->id_surface, tp2->title);
1158     }
1159     else    {
1160         // create ivi-surface and bind to wl_surface
1161         m_id_surface ++;
1162         if (m_id_surface >= 0x00ffffff)     m_id_surface = 1;
1163         id_surface = m_id_surface | 0x40000000;
1164
1165         ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: "
1166                 "call ivi_application_surface_create(%08x)", id_surface);
1167         if (ivi_application_surface_create(m_ivi_app, id_surface, surface) == NULL) {
1168             ICO_ERR("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: "
1169                     "ivi_application_surface_create(%08x) Error", id_surface);
1170             if (bp) {
1171                 bp->next = tp->next;
1172             }
1173             else    {
1174                 m_wait_surface_creation = tp->next;
1175             }
1176             tp->next = m_free_surface_creation;
1177             m_free_surface_creation = tp;
1178         }
1179         else    {
1180             tp->surface = surface;
1181             tp->id_surface = id_surface;
1182             tp->busy = SCWINMGR_GENIVI_BUSY_REQBIND;
1183         }
1184     }
1185
1186     // search request wait
1187     tp = m_wait_surface_creation;
1188     tp2 = NULL;
1189     while (tp)  {
1190         if (tp->busy == SCWINMGR_GENIVI_BUSY_WAIT)  {
1191             tp2 = tp;
1192         }
1193         else if (tp->busy != SCWINMGR_GENIVI_BUSY_NONE) {
1194             break;
1195         }
1196         tp = tp->next;
1197     }
1198     if ((tp == NULL) && (tp2 != NULL))  {
1199         tp2->busy = SCWINMGR_GENIVI_BUSY_REQSURF;
1200         ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: "
1201                 "call ivi_controller_get_native_handle(%d,<%s>)", tp2->pid, tp2->title);
1202         ivi_controller_get_native_handle(m_ivi_ctrl, tp2->pid, tp2->title);
1203     }
1204     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: Leave(id_surface=%08x)", id_surface);
1205 }
1206 // vim:set expandtab ts=4 sw=4: