[ecore] merged svn latest code (svn54830)
[profile/ivi/ecore.git] / src / lib / ecore_fb / ecore_fb.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
4
5 #include "Ecore_Fb.h"
6 #include "ecore_fb_private.h"
7
8 static void _ecore_fb_size_get(int *w, int *h);
9
10 EAPI int ECORE_FB_EVENT_KEY_DOWN = 0;
11 EAPI int ECORE_FB_EVENT_KEY_UP = 0;
12 EAPI int ECORE_FB_EVENT_MOUSE_BUTTON_DOWN = 0;
13 EAPI int ECORE_FB_EVENT_MOUSE_BUTTON_UP = 0;
14 EAPI int ECORE_FB_EVENT_MOUSE_MOVE = 0;
15 EAPI int ECORE_FB_EVENT_MOUSE_WHEEL = 0;
16
17 static int _ecore_fb_init_count = 0;
18 static int _ecore_fb_console_w = 0;
19 static int _ecore_fb_console_h = 0;
20
21 /**
22  * @addtogroup Ecore_FB_Group Ecore_FB - Frame buffer convenience functions.
23  *
24  * @{
25  */
26
27 /**
28  * @brief Initialize the Ecore_Fb library.
29  *
30  * @param name Device target name.
31  * @return 1 or greater on success, 0 on error.
32  *
33  * This function sets up all the Ecore_Fb library. It returns 0 on
34  * failure, otherwise it returns the number of times it has already
35  * been called.
36  *
37  * When Ecore_Fb is not used anymore, call ecore_fb_shutdown() to shut down
38  * the Ecore_Fb library.
39  */
40 EAPI int
41 ecore_fb_init(const char *name __UNUSED__)
42 {
43    if (++_ecore_fb_init_count != 1)
44       return _ecore_fb_init_count;
45    
46    if (!ecore_fb_vt_init())
47       return --_ecore_fb_init_count;
48    
49    ECORE_FB_EVENT_KEY_DOWN          = ecore_event_type_new();
50    ECORE_FB_EVENT_KEY_UP            = ecore_event_type_new();
51    ECORE_FB_EVENT_MOUSE_BUTTON_DOWN = ecore_event_type_new();
52    ECORE_FB_EVENT_MOUSE_BUTTON_UP   = ecore_event_type_new();
53    ECORE_FB_EVENT_MOUSE_MOVE        = ecore_event_type_new();
54    ECORE_FB_EVENT_MOUSE_WHEEL       = ecore_event_type_new();
55    _ecore_fb_size_get(&_ecore_fb_console_w, &_ecore_fb_console_h);
56
57    return _ecore_fb_init_count;
58 }
59
60 /**
61  * @brief Shut down the Ecore_Fb library.
62  *
63  * @return 0 when the library is completely shut down, 1 or
64  * greater otherwise.
65  *
66  * This function shuts down the Ecore_Fb library. It returns 0 when it has
67  * been called the same number of times than ecore_fb_init().
68  */
69 EAPI int
70 ecore_fb_shutdown(void)
71 {    
72    if (--_ecore_fb_init_count != 0)
73       return _ecore_fb_init_count;
74
75    ecore_fb_vt_shutdown();
76
77    return _ecore_fb_init_count;
78 }
79
80
81 /**
82  * @brief Retrieve the width and height of the current frame buffer in
83  * pixels.
84  *
85  * @param w Pointer to an integer in which to store the width.
86  * @param h Pointer to an interge in which to store the height.
87  *
88  * This function retrieves the size of the current frame buffer in
89  * pixels. @p w and @p h can be buffers that will be filled with the
90  * corresponding values. If one of them is @c NULL, nothing will be
91  * done for that parameter.
92  */
93 EAPI void
94 ecore_fb_size_get(int *w, int *h)
95 {
96    if (w) *w = _ecore_fb_console_w;
97    if (h) *h = _ecore_fb_console_h;
98 }
99
100 static void
101 _ecore_fb_size_get(int *w, int *h)
102 {
103    struct fb_var_screeninfo fb_var;
104    int fb;
105    
106    fb = open("/dev/fb0", O_RDWR);
107    if (fb < 0)
108      {
109         if (w) *w = 0;
110         if (h) *h = 0;
111         return;
112      }
113    if (ioctl(fb, FBIOGET_VSCREENINFO, &fb_var) == -1)
114      {
115         if (w) *w = 0;
116         if (h) *h = 0;
117         close(fb);
118         return;
119      }
120    close(fb);
121    if (w) *w = fb_var.xres;
122    if (h) *h = fb_var.yres;
123 }
124
125 /**
126  * @}
127  */