0.9.21 release -- It changes so that the layer controlling function of GENIVI may...
[profile/ivi/ico-uxf-homescreen.git] / lib / system-controller / CicoSCWlWinMgrIF.cpp
1 /*
2  * Copyright (c) 2013-2014, 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
55     // genivi ivi_application listener
56     m_ivi_app_listener.error = wlIviAppErrorCB;
57     m_ivi_app_listener.wl_shell_info = wlIviAppNativeShellInfoCB;
58
59     // genivi ivi_controller listener
60     m_ivi_ctrl_listener.screen = wlIviCtrlScreenCB;
61     m_ivi_ctrl_listener.layer = wlIviCtrlLayerCB;
62     m_ivi_ctrl_listener.surface = wlIviCtrlSurfaceCB;
63     m_ivi_ctrl_listener.error = wlIviCtrlErrorCB;
64     m_ivi_ctrl_listener.native_handle = wlIviCtrlNativeHandleCB;
65
66     // wayland output listener
67     m_wlOutputListener.geometry = wlOutputGeometryCB;
68     m_wlOutputListener.mode     = wlOutputModeCB;
69 }
70
71 //--------------------------------------------------------------------------
72 /**
73  *  @brief  destructor
74  */
75 //--------------------------------------------------------------------------
76 CicoSCWlWinMgrIF::~CicoSCWlWinMgrIF()
77 {
78 }
79
80 //--------------------------------------------------------------------------
81 /**
82  *  @brief  initialize ico_window_mgr interfaces
83  *
84  *  @param [in] data        user data
85  *  @param [in] registry    wayland registry
86  *  @param [in] name        wayland display id
87  *  @parma [in] interface   wayland interface name
88  *  @parma [in] version     wayland interface version number
89  */
90 //--------------------------------------------------------------------------
91 void
92 CicoSCWlWinMgrIF::initInterface(void               *data,
93                                 struct wl_registry *registry,
94                                 uint32_t           name,
95                                 const char         *interface,
96                                 uint32_t           version)
97 {
98     ICO_TRA("CicoSCWlWinMgrIF::initInterface Enter(interface=%s)", interface);
99
100     // check interface name
101     if (0 == strcmp(interface, ICO_WL_WIN_MGR_IF)) {
102         // get interface instance
103         ICO_DBG("called: wl_registry_bind");
104         void *wlProxy = wl_registry_bind(registry,
105                                          name,
106                                          &ico_window_mgr_interface,
107                                          1);
108         if (NULL == wlProxy) {
109             ICO_WRN("interface(%s) wl_registry_bind failed.",
110                     interface);
111             ICO_TRA("CicoSCWlWinMgrIF::initInterface Leave(binding failed)");
112             return;
113         }
114
115
116         m_winmgr = (struct ico_window_mgr *)wlProxy;
117         ico_window_mgr_add_listener(m_winmgr,
118                                     &m_listener,
119                                     this);
120     }
121     else if (0 == strcmp(interface, ICO_WL_IVI_APPLICATION_IF)) {
122         // get interface instance
123         ICO_DBG("called: wl_registry_bind for ivi_application");
124         void *wlProxy = wl_registry_bind(registry,
125                                          name,
126                                          &ivi_application_interface,
127                                          1);
128         if (NULL == wlProxy) {
129             ICO_WRN("interface(%s) wl_registry_bind failed.",
130                     interface);
131             ICO_TRA("CicoSCWlWinMgrIF::initInterface Leave(binding failed)");
132             return;
133         }
134         m_ivi_app = (struct ivi_application *)wlProxy;
135         ivi_application_add_listener(m_ivi_app,
136                                      &m_ivi_app_listener,
137                                      this);
138     }
139     else if (0 == strcmp(interface, ICO_WL_IVI_CONTROLLER_IF)) {
140         // get interface instance
141         ICO_DBG("called: wl_registry_bind for ivi_controller");
142         void *wlProxy = wl_registry_bind(registry,
143                                          name,
144                                          &ivi_controller_interface,
145                                          1);
146         if (NULL == wlProxy) {
147             ICO_WRN("interface(%s) wl_registry_bind failed.",
148                     interface);
149             ICO_TRA("CicoSCWlWinMgrIF::initInterface Leave(binding failed)");
150             return;
151         }
152         m_ivi_ctrl = (struct ivi_controller *)wlProxy;
153         ivi_controller_add_listener(m_ivi_ctrl,
154                                     &m_ivi_ctrl_listener,
155                                     this);
156     }
157     else if (0 == strcmp(interface, ICO_WL_OUTPUT_IF)) {
158         // get interface instance
159         ICO_DBG("called: wl_registry_bind");
160         void *wlProxy = wl_registry_bind(registry,
161                                          name,
162                                          &wl_output_interface,
163                                          1);
164         if (NULL == wlProxy) {
165             ICO_WRN("interface(%s) wl_registry_bind failed.",
166                     interface);
167             ICO_TRA("CicoSCWlWinMgrIF::initInterface Leave(binding failed)");
168             return;
169         }
170
171         m_wloutput = (struct wl_output*)wlProxy;
172         wl_output_add_listener(m_wloutput,
173                                &m_wlOutputListener,
174                                this);
175     }
176     else {
177         ICO_WRN("unmatch interface");
178         ICO_TRA("CicoSCWlWinMgrIF::initInterface Leave(unmatch interface)");
179         return;
180     }
181
182     if((NULL != m_winmgr) && (NULL != m_wloutput)) {
183         m_initialized = true;
184     }
185
186     ICO_TRA("CicoSCWlWinMgrIF::initInterface Leave");
187 }
188
189 //--------------------------------------------------------------------------
190 /**
191  *  @brief   wrapper function of ilm_layerAddSurface
192  *
193  *  @param [in] surfaceid       wayland surface id
194  *  @param [in] layer           layer id
195  *  @param [in] oldlayer        old layer id(if 0xffffffff, no old layer)
196  */
197 //--------------------------------------------------------------------------
198 void
199 CicoSCWlWinMgrIF::setWindowLayer(uint32_t surfaceid, uint32_t layer, uint32_t oldlayer)
200 {
201     // set window layer request to Multi Window Manager
202     ICO_DBG("CicoSCWlWinMgrIF::setWindowLayer: "
203             "surfaceid=0x%08X layer=%d->%d", surfaceid, oldlayer, layer);
204
205     // remove original layer
206     if (oldlayer <= 0x7fffffff) {
207         ICO_TRA("CicoSCWlWinMgrIF::setWindowLayer: remove surface %08x "
208                 "from layer(%d)", surfaceid, oldlayer);
209         (void) ilm_layerRemoveSurface(oldlayer, surfaceid);
210     }
211     else    {
212         ICO_TRA("CicoSCWlWinMgrIF::setWindowLayer: surface %08x has no old layer(%d)",
213                 surfaceid, oldlayer);
214     }
215
216     // add new layer
217     if (ilm_layerAddSurface(layer, surfaceid) != ILM_SUCCESS)   {
218         ICO_ERR("CicoSCWlWinMgrIF::setWindowLayer ilm_layerAddSurface(%d,%08x) Error",
219                 layer, surfaceid);
220     }
221     if (ilm_commitChanges() != ILM_SUCCESS) {
222         ICO_ERR("CicoSCWlWinMgrIF::setWindowLayer ilm_commitChanges Error");
223     }
224 }
225
226 //--------------------------------------------------------------------------
227 /**
228  *  @brief   wrapper function of ilm_surfaceSetDestinationRectangle
229  *
230  *  @param [in] surfaceid       wayland surface id
231  *  @param [in] layer           number of layer
232  *  @param [in] x
233  *  @param [in] y
234  *  @param [in] width
235  *  @param [in] height
236  *  @param [in] flags           (unused)
237  */
238 //--------------------------------------------------------------------------
239 void
240 CicoSCWlWinMgrIF::setPositionsize(uint32_t surfaceid, uint32_t node,
241                                   int32_t x, int32_t y, int32_t width,
242                                   int32_t height, int32_t flags)
243 {
244     // set position size request to Multi Window Manager
245     ICO_DBG("called: ilm_surfaceSetDestinationRectangle"
246             "(surfaceid=0x%08X node=%d x=%d y=%d w=%d h=%d flags=%d)",
247             surfaceid, node, x, y, width, height, flags);
248     if ((ilm_surfaceSetDestinationRectangle(surfaceid, x, y, width, height)
249             != ILM_SUCCESS) ||
250         (ilm_commitChanges() != ILM_SUCCESS))   {
251         ICO_ERR("CicoSCWlWinMgrIF::setPositionsize ilm_surfaceSetDestinationRectangle"
252                 "(%08x,%d,%d,%d,%d) Error",
253                 surfaceid, x, y, width, height);
254     }
255 }
256
257 //--------------------------------------------------------------------------
258 /**
259  *  @brief   wrapper function of ilm_surfaceSetVisibility
260  *
261  *  @param [in] surfaceid       wayland surface id
262  *  @param [in] visible         visible state
263  *  @param [in] raise           raise state
264  *  @param [in] flags           (unused)
265  */
266 //--------------------------------------------------------------------------
267 void
268 CicoSCWlWinMgrIF::setVisible(uint32_t surfaceid, int32_t visible,
269                              int32_t raise, int32_t flags)
270 {
271     // set visible request to Multi Window Manager
272     ICO_DBG("called: ilm_surfaceSetVisibility"
273             "(surfaceid=0x%08X visible=%d raise=%d anima=%d)",
274             surfaceid, visible, raise, flags);
275     if ((visible == ICO_SYC_WIN_VISIBLE_SHOW) || (visible == ICO_SYC_WIN_VISIBLE_HIDE)) {
276         ilm_surfaceSetVisibility(surfaceid, visible);
277     }
278     if ((raise == ICO_SYC_WIN_RAISE_RAISE) || (raise == ICO_SYC_WIN_RAISE_LOWER))   {
279         // TODO: need raise/lower control
280     }
281     if (ilm_commitChanges() != ILM_SUCCESS) {
282         ICO_ERR("CicoSCWlWinMgrIF::setVisible: ilm_commitChanges() Error");
283     }
284 }
285
286 //--------------------------------------------------------------------------
287 /**
288  *  @brief   wrapper function of ico_window_mgr_set_animation
289  *
290  *  @param [in] surfaceid       wayland surface id
291  *  @param [in] type            transition type
292  *  @param [in] animation       name of animation
293  *  @param [in] time            time of animation
294  */
295 //--------------------------------------------------------------------------
296 void
297 CicoSCWlWinMgrIF::setAnimation(uint32_t surfaceid, int32_t type,
298                                const char *animation, int32_t time)
299 {
300     ICO_DBG("called: ico_window_mgr_set_animation"
301             "(surfaceid=0x%08X type=%d anima=%s time=%d)",
302             surfaceid, type, animation, time);
303     ico_window_mgr_set_animation(m_winmgr, surfaceid, type, animation, time);
304 }
305
306 //--------------------------------------------------------------------------
307 /**
308  *  @brief   wrapper function of ilm_SetKeyboardFocusOn
309  *
310  *  @param [in] surfaceid       wayland surface id
311  *  @param [in] active          flags or active device(unused)
312  */
313 //--------------------------------------------------------------------------
314 void
315 CicoSCWlWinMgrIF::setActive(uint32_t surfaceid, int32_t active)
316 {
317     ICO_DBG("called: ilm_SetKeyboardFocusOn"
318             "(surfaceid=0x%08X active=%d)", surfaceid, active);
319     if ((ilm_SetKeyboardFocusOn(surfaceid) != ILM_SUCCESS) ||
320         (ilm_commitChanges() != ILM_SUCCESS))   {
321         ICO_ERR("CicoSCWlWinMgrIF::setActive ilm_SetKeyboardFocusOn(%08x) Error", surfaceid);
322     }
323 }
324
325 //--------------------------------------------------------------------------
326 /**
327  *  @brief   wrapper function of ilm_layerSetVisibility
328  *
329  *  @param [in] surfaceid       wayland surface id
330  *  @param [in] layer           id of layer
331  *  @param [in] visible         visible state
332  */
333 //--------------------------------------------------------------------------
334 void
335 CicoSCWlWinMgrIF::setLayerVisible(uint32_t layer, int32_t visible)
336 {
337     ICO_DBG("called: ilm_layerSetVisibility"
338             "(layer=%d visible=%d)", layer, visible);
339     if ((ilm_layerSetVisibility(layer, visible) != ILM_SUCCESS) ||
340         (ilm_commitChanges() != ILM_SUCCESS))   {
341         ICO_ERR("CicoSCWlWinMgrIF::setLayerVisible ilm_layerSetVisibility(%d,%d) Error",
342                 layer, visible);
343     }
344 }
345
346 //--------------------------------------------------------------------------
347 /**
348  *  @brief   wrapper function of ilm_takeSurfaceScreenshot
349  *
350  *  @param [in] surface     id of wayland surface
351  *  @param [in] filepath    surface image pixel file path
352  */
353 //--------------------------------------------------------------------------
354 void
355 CicoSCWlWinMgrIF::setmapGet(int surfaceid, const char *filepath)
356 {
357     ICO_DBG("called: ilm_takeSurfaceScreenshot(filepath=%s,, surface=0x%08x)",
358             filepath ? filepath : "(null)", surfaceid);
359     if ((ilm_takeSurfaceScreenshot(filepath, surfaceid) != ILM_SUCCESS) ||
360         (ilm_commitChanges() != ILM_SUCCESS))   {
361         ICO_ERR("CicoSCWlWinMgrIF::setmapGet ilm_takeSurfaceScreenshot(%s,%x) Error",
362                 filepath ? filepath : "(null)", surfaceid);
363     }
364 }
365
366 //--------------------------------------------------------------------------
367 /**
368  *  @brief   wrapper function of ico_window_mgr_map_surface
369  *
370  *  @param [in] surface     id of wayland surface
371  *  @param [in] framerate   interval of changed notify[frame per second]
372  *  @param [in] filepath    surface image pixel file path
373  */
374 //--------------------------------------------------------------------------
375 void
376 CicoSCWlWinMgrIF::mapSurface(uint32_t surfaceid, int32_t framerate, const char *filepath)
377 {
378     ICO_DBG("called: ico_window_mgr_map_surface(surfaceid=0x%08X framerate=%d file=%s)",
379             surfaceid, framerate, filepath ? filepath : "(null)");
380     // currently GENIVI genivi-shell not support contents change, so use ico_window_mgr
381     if ((filepath != NULL) && (*filepath != 0) && (*filepath != ' '))   {
382         ico_window_mgr_map_surface(m_winmgr, surfaceid, framerate, filepath);
383     }
384     else    {
385         ico_window_mgr_map_surface(m_winmgr, surfaceid, framerate, " ");
386     }
387 }
388
389 //--------------------------------------------------------------------------
390 /**
391  *  @brief   wrapper function of ico_window_mgr_unmap_surface
392  *
393  *  @param [in] surface     id of wayland surface
394  */
395 //--------------------------------------------------------------------------
396 void
397 CicoSCWlWinMgrIF::unmapSurface(uint32_t surfaceid)
398 {
399     ICO_DBG("called: ico_window_mgr_unmap_surface"
400             "(surfaceid=0x%08X)", surfaceid);
401     // currently GENIVI genivi-shell not support contents change, so use ico_window_mgr
402     ico_window_mgr_unmap_surface(m_winmgr, surfaceid);
403 }
404
405 //--------------------------------------------------------------------------
406 /**
407  *  @brief   get creation surface window name(title) and pid
408  *
409  *  @param [in]  id_surface surface id
410  *  @param [out] pid        application process id
411  */
412 //--------------------------------------------------------------------------
413 const char *
414 CicoSCWlWinMgrIF::wlIviCtrlGetSurfaceWaiting(uint32_t id_surface, int *pid)
415 {
416     struct creation_surface_wait    *tp = m_wait_surface_creation;
417
418     while (tp)   {
419         if (tp->id_surface == id_surface)   {
420             ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlGetSurfaceWaiting(%x) pid=%d title=<%s>",
421                     id_surface, tp->pid, tp->title);
422             *pid = tp->pid;
423             return tp->title;
424         }
425         tp = tp->next;
426     }
427     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlGetSurfaceWaiting(%x) dose not exist", id_surface);
428     return NULL;
429 }
430
431 //--------------------------------------------------------------------------
432 /**
433  *  @brief   remove surface window
434  *
435  *  @param [in]  id_surface surface id
436  */
437 //--------------------------------------------------------------------------
438 void
439 CicoSCWlWinMgrIF::wlIviCtrlRemoveSurface(uint32_t id_surface)
440 {
441     struct creation_surface_wait    *tp = m_wait_surface_creation;
442     struct creation_surface_wait    *bp = NULL;
443
444     while (tp)   {
445         if (tp->id_surface == id_surface)   {
446             if (bp) {
447                 bp->next = tp->next;
448             }
449             else    {
450                 m_wait_surface_creation = tp->next;
451             }
452             tp->next = m_free_surface_creation;
453             m_free_surface_creation = tp;
454
455             ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlRemoveSurface(%x) removed", id_surface);
456             return;
457         }
458     }
459     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlRemoveSurface(%x) dose not exist", id_surface);
460 }
461
462 //--------------------------------------------------------------------------
463 /**
464  *  @brief  wayland surface active callback
465  *
466  *  @param [in] data            user data(unused)
467  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
468  *  @param [in] surfaceid       ico_window_mgr surface Id
469  *  @param [in] select          select device(unused)
470  *                              (0=not active/1=pointer/2=touch)
471  */
472 //--------------------------------------------------------------------------
473 void
474 CicoSCWlWinMgrIF::activeCB(void                  *data,
475                            struct ico_window_mgr *ico_window_mgr,
476                            uint32_t              surfaceid,
477                            int32_t               select)
478 {
479     ICO_WRN("CicoSCWlWinMgrIF::activeCB called.");
480 }
481
482 //--------------------------------------------------------------------------
483 /**
484  *  @brief   surface map event callback
485  *
486  *  @param [in] data            user data(unused)
487  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
488  *  @param [in] event           event
489  *  @param [in] surfaceid       surface Id
490  *  @param [in] type            surface buffer type(EGL buffer/Shared memory)
491  *  @param [in] width           surface width
492  *  @param [in] height          surface height
493  *  @param [in] stride          surface buffer(frame buffer) stride
494  *  @param [in] format          surface buffer format
495  */
496 //--------------------------------------------------------------------------
497 void
498 CicoSCWlWinMgrIF::mapSurfaceCB(void                  *data,
499                                struct ico_window_mgr *ico_window_mgr,
500                                int32_t               event,
501                                uint32_t              surfaceid,
502                                uint32_t              type,
503                                int32_t               width,
504                                int32_t               height,
505                                int32_t               stride,
506                                uint32_t              format)
507 {
508     ICO_WRN("CicoSCWlWinMgrIF::mapSurfaceCB called.");
509 }
510
511 //--------------------------------------------------------------------------
512 /**
513  *  @brief   wayland display attribute callback
514  *
515  *  @param [in] data            user data(unused)
516  *  @param [in] wl_output       wayland wl_output interface
517  *  @param [in] x               display upper-left X coordinate
518  *  @param [in] y               display upper-left Y coordinate
519  *  @param [in] physical_width  display physical width
520  *  @param [in] physical_height display physical height
521  *  @param [in] subpixel        display sub pixel
522  *  @param [in] make            display maker
523  *  @param [in] model           display model
524  *  @param [in] transform       transform
525  */
526 //--------------------------------------------------------------------------
527 void
528 CicoSCWlWinMgrIF::outputGeometryCB(void             *data,
529                                    struct wl_output *wl_output,
530                                    int32_t          x,
531                                    int32_t          y,
532                                    int32_t          physical_width,
533                                    int32_t          physical_height,
534                                    int32_t          subpixel,
535                                    const char       *make,
536                                    const char       *model,
537                                    int32_t          transform)
538 {
539     ICO_WRN("CicoSCWlWinMgrIF::outputGeometryCB called.");
540 }
541
542 //--------------------------------------------------------------------------
543 /**
544  *  @brief  wayland display mode callback
545  *
546  *  @param [in] data        user data(unused)
547  *  @param [in] wl_output   wayland wl_output interface
548  *  @param [in] flags       flags
549  *  @param [in] width       display width
550  *  @param [in] height      display height
551  *  @param [in] refresh     display refresh rate
552  */
553 //--------------------------------------------------------------------------
554 void
555 CicoSCWlWinMgrIF::outputModeCB(void             *data,
556                                struct wl_output *wl_output,
557                                uint32_t         flags,
558                                int32_t          width,
559                                int32_t          height,
560                                int32_t          refresh)
561 {
562     ICO_WRN("CicoSCWlWinMgrIF::outputModeCB called.");
563 };
564
565 //--------------------------------------------------------------------------
566 /**
567  *  @brief   wayland genivi ivi-surface create callback
568  *
569  *  @param [in] data            user data(unused)
570  *  @param [in] ivi_controller  wayland ivi-controller plugin interface
571  *  @param [in] id_surface      surface id
572  */
573 //--------------------------------------------------------------------------
574 void
575 CicoSCWlWinMgrIF::createSurfaceCB(void                  *data,
576                                   struct ivi_controller *ivi_controller,
577                                   uint32_t id_surface)
578 {
579     ICO_WRN("CicoSCWlWinMgrIF::createSurfaceCB called.");
580 }
581
582 //==========================================================================
583 // private method
584 //==========================================================================
585
586 //--------------------------------------------------------------------------
587 /**
588  *  @brief  wayland surface active callback
589  *
590  *  @param [in] data            user data(unused)
591  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
592  *  @param [in] surfaceid       ico_window_mgr surface Id
593  *  @param [in] select          select device(unused)
594  *                              (0=not active/1=pointer/2=touch)
595  */
596 //--------------------------------------------------------------------------
597 void
598 CicoSCWlWinMgrIF::wlActiveCB(void                  *data,
599                              struct ico_window_mgr *ico_window_mgr,
600                              uint32_t              surfaceid,
601                              int32_t               select)
602 {
603 //    ICO_TRA("CicoSCWlWinMgrIF::wlActiveCB Enter");
604
605     if (NULL == data) {
606         ICO_WRN("wlActiveCB: data is null");
607         return;
608     }
609     static_cast<CicoSCWlWinMgrIF*>(data)->activeCB(data, ico_window_mgr,
610                                                    surfaceid, select);
611 //    ICO_TRA("CicoSCWlWinMgrIF::wlActiveCB Leave");
612 }
613
614 //--------------------------------------------------------------------------
615 /**
616  *  @brief   surface map event callback
617  *
618  *  @param [in] data            user data
619  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
620  *  @param [in] event           event
621  *  @param [in] surfaceid       surface Id
622  *  @param [IN] type            buffer type(fixed ICO_WINDOW_MGR_MAP_TYPE_EGL)
623  *  @param [in] width           surface width
624  *  @param [in] height          surface height
625  *  @param [in] stride          surface buffer(frame buffer) stride
626  *  @param [in] format          surface buffer format
627  */
628 //--------------------------------------------------------------------------
629 void
630 CicoSCWlWinMgrIF::wlMapSurfaceCB(void                  *data,
631                                  struct ico_window_mgr *ico_window_mgr,
632                                  int32_t               event,
633                                  uint32_t              surfaceid,
634                                  uint32_t              type,
635                                  int32_t               width,
636                                  int32_t               height,
637                                  int32_t               stride,
638                                  uint32_t              format)
639 {
640 //    ICO_TRA("CicoSCWlWinMgrIF::wlMapSurfaceCB Enter");
641
642     if (NULL == data) {
643         ICO_WRN("wlMapSurfaceCB: data is null");
644         return;
645     }
646     static_cast<CicoSCWlWinMgrIF*>(data)->mapSurfaceCB(data, ico_window_mgr,
647                                                        event, surfaceid,
648                                                        type,
649                                                        width, height,
650                                                        stride, format);
651 //    ICO_TRA("CicoSCWlWinMgrIF::wlMapSurfaceCB Leave");
652 }
653
654 //--------------------------------------------------------------------------
655 /**
656  *  @brief   wayland display attribute callback
657  *
658  *  @param [in] data            user data(unused)
659  *  @param [in] wl_output       wayland wl_output interface
660  *  @param [in] x               display upper-left X coordinate
661  *  @param [in] y               display upper-left Y coordinate
662  *  @param [in] physical_width  display physical width
663  *  @param [in] physical_height display physical height
664  *  @param [in] subpixel        display sub pixel
665  *  @param [in] make            display maker
666  *  @param [in] model           display model
667  *  @param [in] transform       transform
668  */
669 //--------------------------------------------------------------------------
670 void
671 CicoSCWlWinMgrIF::wlOutputGeometryCB(void             *data,
672                                      struct wl_output *wl_output,
673                                      int32_t          x,
674                                      int32_t          y,
675                                      int32_t          physical_width,
676                                      int32_t          physical_height,
677                                      int32_t          subpixel,
678                                      const char       *make,
679                                      const char       *model,
680                                      int32_t          transform)
681 {
682 //    ICO_TRA("CicoSCWlWinMgrIF::wlOutputGeometryCB Enter");
683
684     if (NULL == data) {
685         ICO_WRN("wlOutputGeometryCB: data is null");
686         return;
687     }
688     static_cast<CicoSCWlWinMgrIF*>(data)->outputGeometryCB(data, wl_output,
689                                                            x, y,
690                                                            physical_width,
691                                                            physical_height,
692                                                            subpixel,
693                                                            make,
694                                                            model,
695                                                            transform);
696 //    ICO_TRA("CicoSCWlWinMgrIF::wlOutputGeometryCB Leave");
697 }
698
699 //--------------------------------------------------------------------------
700 /**
701  *  @brief  wayland display mode callback
702  *
703  *  @param [in] data        user data(unused)
704  *  @param [in] wl_output   wayland wl_output interface
705  *  @param [in] flags       flags
706  *  @param [in] width       display width
707  *  @param [in] height      display height
708  *  @param [in] refresh     display refresh rate
709  */
710 //--------------------------------------------------------------------------
711 void
712 CicoSCWlWinMgrIF::wlOutputModeCB(void             *data,
713                                  struct wl_output *wl_output,
714                                  uint32_t         flags,
715                                  int32_t          width,
716                                  int32_t          height,
717                                  int32_t          refresh)
718 {
719 //    ICO_TRA("CicoSCWlWinMgrIF::wlOutputModeCB Enter");
720
721     if (NULL == data) {
722         ICO_WRN("wlOutputGeometryCB: data is null");
723         return;
724     }
725     static_cast<CicoSCWlWinMgrIF*>(data)->outputModeCB(data, wl_output, flags,
726                                                        width, height, refresh);
727 //    ICO_TRA("CicoSCWlWinMgrIF::wlOutputModeCB Leave");
728 }
729
730 //--------------------------------------------------------------------------
731 /**
732  *  @brief  wayland ivi-shell ivi-application protocol error callback
733  *
734  *  @param [in] data            user data(unused)
735  *  @param [in] ivi_application wayland ivi-application interface
736  *  @param [in] error_code      error code
737  *  @param [in] error_text      error message
738  */
739 //--------------------------------------------------------------------------
740 void
741 CicoSCWlWinMgrIF::wlIviAppErrorCB(void *data,
742                                  struct ivi_application *ivi_application,
743                                  int32_t error_code, const char *error_text)
744 {
745     ICO_TRA("CicoSCWlWinMgrIF::wlIviAppErrorCB: Enter(%d,%s)",
746             error_code, error_text ? error_text : "(null)");
747
748     if (NULL == data) {
749         ICO_WRN("CicoSCWlWinMgrIF::wlIviAppErrorCB: data is null");
750         return;
751     }
752     ICO_TRA("CicoSCWlWinMgrIF::wlIviAppErrorCB: Leave");
753 }
754
755 //--------------------------------------------------------------------------
756 /**
757  *  @brief  wayland ivi-shell ivi-application protocol create wl_surface callback
758  *
759  *  @param [in] data            user data(unused)
760  *  @param [in] ivi_application wayland ivi-application interface
761  *  @param [in] pid             application process id
762  *  @param [in] title           surface title name
763  */
764 //--------------------------------------------------------------------------
765 void
766 CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB(void *data,
767                                             struct ivi_application *ivi_application,
768                                             int32_t pid, const char *title)
769 {
770     struct creation_surface_wait    *tp;
771     struct creation_surface_wait    *bp;
772     uint32_t        nowtime;
773
774     ICO_TRA("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: Enter(%d,<%s>)",
775             pid, title ? title : "(null)");
776
777     if (NULL == data) {
778         ICO_WRN("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: data is null");
779         return;
780     }
781
782     // bind wl_surface to ivi_surface
783     ivi_controller_get_native_handle(m_ivi_ctrl, pid, title ? title : "");
784
785     // save pid and title(window name)
786     nowtime = (time(NULL) >> 2) & 0x3fffffff;
787     tp = m_wait_surface_creation;
788     while (tp)  {
789         if ((tp->pid == pid) && (tp->title[0] == 0))    break;
790         tp = tp->next;
791     }
792     if (! tp)   {
793         tp = m_free_surface_creation;
794         if (tp)  {
795             m_free_surface_creation = tp->next;
796         }
797         else    {
798             tp = m_wait_surface_creation;
799             bp = NULL;
800             while (tp)  {
801                 if (((nowtime >= tp->create_time)
802                          && ((nowtime - tp->create_time) > 15)) ||
803                     ((nowtime < tp->create_time)
804                          && ((nowtime + 0x40000000 - tp->create_time) > 15)))   {
805                     if (bp) {
806                         bp->next = tp->next;
807                     }
808                     else    {
809                         m_wait_surface_creation = tp->next;
810                     }
811                     break;
812                 }
813                 bp = tp;
814                 tp = tp->next;
815             }
816             if (! tp)   {
817                 tp = (struct creation_surface_wait *)
818                        malloc(sizeof(struct creation_surface_wait));
819                 if (! tp)    {
820                     ICO_ERR("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: out of memory");
821                     return;
822                 }
823             }
824         }
825         memset(tp, 0, sizeof(struct creation_surface_wait));
826         tp->next = m_wait_surface_creation;
827         m_wait_surface_creation = tp;
828     }
829     tp->pid = pid;
830     strncpy(tp->title, title, ICO_SYC_MAX_WINNAME_LEN-1);
831     tp->create_time = nowtime;
832
833     ICO_TRA("CicoSCWlWinMgrIF::wlIviAppNativeShellInfoCB: Leave");
834 }
835
836 //--------------------------------------------------------------------------
837 /**
838  *  @brief  wayland ivi-shell ivi-controller protocol create screen callback
839  *
840  *  @param [in] data            user data(unused)
841  *  @param [in] ivi_controller  wayland ivi-controller interface
842  *  @param [in] id_screen       screen id
843  *  @param [in] screen          screen information
844  */
845 //--------------------------------------------------------------------------
846 void
847 CicoSCWlWinMgrIF::wlIviCtrlScreenCB(void *data,
848                                     struct ivi_controller *ivi_controller,
849                                     uint32_t id_screen,
850                                     struct ivi_controller_screen *screen)
851 {
852     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlScreenCB: Enter(%x)", id_screen);
853
854     if (NULL == data) {
855         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlScreenCB: data is null");
856         return;
857     }
858     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlScreenCB: Leave");
859 }
860
861 //--------------------------------------------------------------------------
862 /**
863  *  @brief  wayland ivi-shell ivi-controller protocol create layer callback
864  *
865  *  @param [in] data            user data(unused)
866  *  @param [in] ivi_controller  wayland ivi-controller interface
867  *  @param [in] id_layer        layer id
868  */
869 //--------------------------------------------------------------------------
870 void
871 CicoSCWlWinMgrIF::wlIviCtrlLayerCB(void *data,
872                                    struct ivi_controller *ivi_controller,
873                                    uint32_t id_layer)
874 {
875     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlLayerCB: Enter(%x)", id_layer);
876
877     if (NULL == data) {
878         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlLayerCB: data is null");
879         return;
880     }
881     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlLayerCB: Leave");
882 }
883
884 //--------------------------------------------------------------------------
885 /**
886  *  @brief  wayland ivi-shell ivi-controller protocol create surface callback
887  *
888  *  @param [in] data            user data(unused)
889  *  @param [in] ivi_controller  wayland ivi-controller interface
890  *  @param [in] id_surface      surface id
891  */
892 //--------------------------------------------------------------------------
893 void
894 CicoSCWlWinMgrIF::wlIviCtrlSurfaceCB(void *data,
895                                      struct ivi_controller *ivi_controller,
896                                      uint32_t id_surface)
897 {
898     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlSurfaceCB: Enter(%x)", id_surface);
899
900     if (NULL == data) {
901         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlSurfaceCB: data is null");
902         return;
903     }
904
905     static_cast<CicoSCWlWinMgrIF*>(data)->createSurfaceCB(data, ivi_controller, id_surface);
906
907     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlSurfaceCB: Leave");
908 }
909
910 //--------------------------------------------------------------------------
911 /**
912  *  @brief  wayland ivi-shell ivi-controller protocol error callback
913  *
914  *  @param [in] data            user data(unused)
915  *  @param [in] ivi_controller  wayland ivi-controller interface
916  *  @param [in] error_code      error code
917  *  @param [in] error_text      error message
918  */
919 //--------------------------------------------------------------------------
920 void
921 CicoSCWlWinMgrIF::wlIviCtrlErrorCB(void *data,
922                                    struct ivi_controller *ivi_controller,
923                                    int32_t object_id, int32_t object_type,
924                                    int32_t error_code, const char *error_text)
925 {
926     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlErrorCB: Enter(%d[%d],%d,<%s>)",
927             object_id, object_type, error_code, error_text ? error_text : "(null)");
928
929     if (NULL == data) {
930         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlErrorCB: data is null");
931         return;
932     }
933     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlErrorCB: Leave");
934 }
935
936 //--------------------------------------------------------------------------
937 /**
938  *  @brief  wayland ivi-shell ivi-controller protocol error callback
939  *
940  *  @param [in] data            user data(unused)
941  *  @param [in] ivi_controller  wayland ivi-controller interface
942  *  @param [in] error_code      error code
943  *  @param [in] error_text      error message
944  */
945 //--------------------------------------------------------------------------
946 void
947 CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB(void *data,
948                                           struct ivi_controller *ivi_controller,
949                                           struct wl_surface *surface)
950 {
951     uint32_t                        id_surface;
952     struct creation_surface_wait    *tp;
953
954     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: Enter(surface=%08x)", (int)surface);
955
956     if (NULL == data) {
957         ICO_WRN("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: data is null");
958         return;
959     }
960
961     // check same surface
962     tp = m_wait_surface_creation;
963     while (tp)  {
964         if (tp->surface == surface) {
965             ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: Leave(same surface)");
966             return;
967         }
968         tp = tp->next;
969     }
970
971     // create ivi-surface and bind to wl_surface
972     m_id_surface ++;
973     if (m_id_surface >= 0x00ffffff)     m_id_surface = 1;
974     id_surface = m_id_surface | 0x40000000;
975
976     if (ivi_application_surface_create(m_ivi_app, id_surface, surface) == NULL) {
977         ICO_ERR("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: "
978                 "ivi_application_surface_create(%x) Error", id_surface);
979         if (m_wait_surface_creation)    {
980             tp = m_wait_surface_creation;
981             m_wait_surface_creation = tp->next;
982             tp->next = m_free_surface_creation;
983             m_free_surface_creation = tp;
984         }
985     }
986     else    {
987         tp = m_wait_surface_creation;
988         while (tp)  {
989             if (tp->id_surface == 0)    {
990                 tp->id_surface = id_surface;
991                 tp->surface = surface;
992                 break;
993             }
994             tp = tp->next;
995         }
996         if (! tp)   {
997             ICO_ERR("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: waiting surface dose not exist");
998         }
999     }
1000     ICO_TRA("CicoSCWlWinMgrIF::wlIviCtrlNativeHandleCB: Leave(id_surface=%08x)", id_surface);
1001 }
1002 // vim:set expandtab ts=4 sw=4: