eolian: rename is_ref API to is_ptr to match syntax
[platform/upstream/efl.git] / src / lib / ecore_x / xcb / ecore_xcb_render.c
1 #include "ecore_xcb_private.h"
2 #include <ctype.h> // for isupper/tolower
3 #ifdef ECORE_XCB_RENDER
4 # include <xcb/render.h>
5 # include <xcb/xcb_renderutil.h>
6 #endif
7
8 /* local function prototypes */
9 static Eina_Bool _ecore_xcb_render_parse_boolean(char *v);
10
11 /* local variables */
12 static Eina_Bool _render_avail = EINA_FALSE;
13 static Eina_Bool _render_argb = EINA_FALSE;
14 static Eina_Bool _render_anim = EINA_FALSE;
15
16 void
17 _ecore_xcb_render_init(void)
18 {
19    LOGFN(__FILE__, __LINE__, __FUNCTION__);
20
21 #ifdef ECORE_XCB_RENDER
22    xcb_prefetch_extension_data(_ecore_xcb_conn, &xcb_render_id);
23 #endif
24 }
25
26 void
27 _ecore_xcb_render_finalize(void)
28 {
29 #ifdef ECORE_XCB_RENDER
30    const xcb_query_extension_reply_t *ext_reply;
31 #endif
32
33    LOGFN(__FILE__, __LINE__, __FUNCTION__);
34
35 #ifdef ECORE_XCB_RENDER
36    ext_reply = xcb_get_extension_data(_ecore_xcb_conn, &xcb_render_id);
37    if ((ext_reply) && (ext_reply->present))
38      {
39         xcb_render_query_version_cookie_t cookie;
40         xcb_render_query_version_reply_t *reply;
41
42         cookie =
43           xcb_render_query_version_unchecked(_ecore_xcb_conn,
44                                              XCB_RENDER_MAJOR_VERSION,
45                                              XCB_RENDER_MINOR_VERSION);
46         reply = xcb_render_query_version_reply(_ecore_xcb_conn, cookie, NULL);
47         if (reply)
48           {
49 //        if ((reply->major_version >= XCB_RENDER_MAJOR_VERSION) &&
50                if (reply->minor_version >= XCB_RENDER_MINOR_VERSION)
51                  {
52                     char *v = NULL;
53
54                     _render_avail = EINA_TRUE;
55                     _ecore_xcb_xdefaults_init();
56                     if ((reply->major_version > 0) || (reply->minor_version >= 5))
57                       {
58                          _render_argb = EINA_TRUE;
59                          v = getenv("XCURSOR_CORE");
60                          if (!v)
61                            v = _ecore_xcb_xdefaults_string_get("Xcursor", "core");
62                          if ((v) && (_ecore_xcb_render_parse_boolean(v)))
63                            _render_argb = EINA_FALSE;
64                       }
65                     if ((_render_argb) &&
66                         ((reply->major_version > 0) || (reply->minor_version >= 8)))
67                       {
68                          _render_anim = EINA_TRUE;
69                          v = getenv("XCURSOR_ANIM");
70                          if (!v)
71                            v = _ecore_xcb_xdefaults_string_get("Xcursor", "anim");
72                          if ((v) && (_ecore_xcb_render_parse_boolean(v)))
73                            _render_anim = EINA_FALSE;
74                       }
75                     _ecore_xcb_xdefaults_shutdown();
76                  }
77           }
78         free(reply);
79      }
80 #endif
81 }
82
83 Eina_Bool
84 _ecore_xcb_render_avail_get(void)
85 {
86    return _render_avail;
87 }
88
89 Eina_Bool
90 _ecore_xcb_render_argb_get(void)
91 {
92    return _render_argb;
93 }
94
95 Eina_Bool
96 _ecore_xcb_render_anim_get(void)
97 {
98    return _render_anim;
99 }
100
101 Eina_Bool
102 _ecore_xcb_render_visual_supports_alpha(Ecore_X_Visual visual)
103 {
104    Eina_Bool ret = EINA_FALSE;
105 #ifdef ECORE_XCB_RENDER
106    const xcb_render_query_pict_formats_reply_t *reply;
107    xcb_render_pictvisual_t *vis;
108 #endif
109
110    LOGFN(__FILE__, __LINE__, __FUNCTION__);
111    CHECK_XCB_CONN;
112
113    if (!visual) return EINA_FALSE;
114    if (!_render_avail) return EINA_FALSE;
115
116 #ifdef ECORE_XCB_RENDER
117    reply = xcb_render_util_query_formats(_ecore_xcb_conn);
118    if (!reply) return EINA_FALSE;
119
120    vis =
121      xcb_render_util_find_visual_format(reply,
122                                         ((xcb_visualtype_t *)visual)->visual_id);
123    if (vis)
124      {
125         xcb_render_pictforminfo_t temp;
126         xcb_render_pictforminfo_t *format;
127
128         temp.id = vis->format;
129         format =
130           xcb_render_util_find_format(reply, XCB_PICT_FORMAT_ID, &temp, 0);
131
132         if ((format->type == XCB_RENDER_PICT_TYPE_DIRECT) &&
133             (format->direct.alpha_mask))
134           ret = EINA_TRUE;
135      }
136
137 #endif
138
139    return ret;
140 }
141
142 uint32_t
143 _ecore_xcb_render_find_visual_id(int       type,
144                                  Eina_Bool check_alpha)
145 {
146 #ifdef ECORE_XCB_RENDER
147    const xcb_render_query_pict_formats_reply_t *reply;
148    xcb_render_pictvisual_t *visual = NULL;
149    xcb_render_pictscreen_iterator_t screens;
150    xcb_render_pictdepth_iterator_t depths;
151    xcb_render_pictvisual_iterator_t visuals;
152 #endif
153
154    LOGFN(__FILE__, __LINE__, __FUNCTION__);
155    CHECK_XCB_CONN;
156
157    if (!_render_avail) return 0;
158
159 #ifdef ECORE_XCB_RENDER
160    reply = xcb_render_util_query_formats(_ecore_xcb_conn);
161    if (!reply) return 0;
162
163    for (screens = xcb_render_query_pict_formats_screens_iterator(reply);
164         screens.rem; xcb_render_pictscreen_next(&screens))
165      {
166         for (depths = xcb_render_pictscreen_depths_iterator(screens.data);
167              depths.rem; xcb_render_pictdepth_next(&depths))
168           {
169              for (visuals = xcb_render_pictdepth_visuals_iterator(depths.data);
170                   visuals.rem; xcb_render_pictvisual_next(&visuals))
171                {
172                   xcb_render_pictforminfo_t temp;
173                   xcb_render_pictforminfo_t *format;
174
175                   visual = visuals.data;
176                   temp.id = visual->format;
177
178                   format =
179                     xcb_render_util_find_format(reply, XCB_PICT_FORMAT_ID,
180                                                 &temp, 0);
181                   if (!format) continue;
182                   if (format->type == type)
183                     {
184                        if (check_alpha)
185                          {
186                             if (format->direct.alpha_mask)
187                               return visual->visual;
188                          }
189                        else
190                          return visual->visual;
191                     }
192                }
193           }
194      }
195 #endif
196
197    return 0;
198 }
199
200 /* local function prototypes */
201 static Eina_Bool
202 _ecore_xcb_render_parse_boolean(char *v)
203 {
204    char c;
205
206    c = *v;
207    if (isupper((int)c))
208      c = tolower(c);
209    if ((c == 't') || (c == 'y') || (c == '1'))
210      return EINA_TRUE;
211    if ((c == 'f') || (c == 'n') || (c == '0'))
212      return EINA_FALSE;
213    if (c == 'o')
214      {
215         char d;
216
217         d = v[1];
218         if (isupper((int)d))
219           d = tolower(d);
220         if (d == 'n') return EINA_TRUE;
221         if (d == 'f') return EINA_FALSE;
222      }
223    return EINA_FALSE;
224 }
225