1 #include "ecore_xcb_private.h"
4 * @defgroup Ecore_X_Sync_Group X Sync Extension Functions
6 * Functions related to the X Sync extension.
10 static int _sync_available = 0;
11 static xcb_sync_initialize_cookie_t _ecore_xcb_sync_init_cookie;
12 #endif /* ECORE_XCB_SYNC */
14 /* To avoid round trips, the initialization is separated in 2
15 functions: _ecore_xcb_sync_init and
16 _ecore_xcb_sync_init_finalize. The first one gets the cookies and
17 the second one gets the replies and set the atoms. */
20 _ecore_x_sync_init(const xcb_query_extension_reply_t *reply)
23 if (reply && (reply->present))
24 _ecore_xcb_sync_init_cookie = xcb_sync_initialize_unchecked(_ecore_xcb_conn,
25 XCB_SYNC_MAJOR_VERSION,
26 XCB_SYNC_MINOR_VERSION);
28 #endif /* ECORE_XCB_SYNC */
29 } /* _ecore_x_sync_init */
32 _ecore_x_sync_init_finalize(void)
35 xcb_sync_initialize_reply_t *reply;
37 reply = xcb_sync_initialize_reply(_ecore_xcb_conn,
38 _ecore_xcb_sync_init_cookie, NULL);
42 if (reply->major_version >= 3)
48 #endif /* ECORE_XCB_SYNC */
49 } /* _ecore_x_sync_init_finalize */
52 * Return whether the X server supports the Sync Extension.
53 * @return 1 if the X Sync Extension is available, 0 otherwise.
55 * Return 1 if the X server supports the Sync Extension version 3.0,
57 * @ingroup Ecore_X_Sync_Group
60 ecore_x_sync_query(void)
63 return _sync_available;
64 #else /* ifdef ECORE_XCB_SYNC */
66 #endif /* ECORE_XCB_SYNC */
67 } /* ecore_x_sync_query */
71 * @param counter A counter.
72 * @return A newly created alarm.
75 * @ingroup Ecore_X_Sync_Group
77 EAPI Ecore_X_Sync_Alarm
78 ecore_x_sync_alarm_new(Ecore_X_Sync_Counter counter)
81 uint32_t value_list[6];
82 xcb_sync_int64_t init;
83 Ecore_X_Sync_Alarm alarm;
88 xcb_sync_set_counter(_ecore_xcb_conn, counter, init);
91 XCB_SYNC_CA_COUNTER | XCB_SYNC_CA_VALUE_TYPE |
92 XCB_SYNC_CA_VALUE | XCB_SYNC_CA_TEST_TYPE |
93 XCB_SYNC_CA_DELTA | XCB_SYNC_CA_EVENTS;
94 value_list[0] = counter;
95 value_list[1] = XCB_SYNC_VALUETYPE_ABSOLUTE;
97 value_list[3] = XCB_SYNC_TESTTYPE_POSITIVE_COMPARISON;
100 alarm = xcb_generate_id(_ecore_xcb_conn);
101 xcb_sync_create_alarm(_ecore_xcb_conn,
104 (const uint32_t *)value_list);
108 #else /* ifdef ECORE_XCB_SYNC */
110 #endif /* ECORE_XCB_SYNC */
111 } /* ecore_x_sync_alarm_new */
115 * @param alarm The alarm to delete.
116 * @return 1 on success, 0 otherwise.
118 * Delete the @p alarm. Returns 1 on success, 0 otherwise.
119 * @ingroup Ecore_X_Sync_Group
122 ecore_x_sync_alarm_free(Ecore_X_Sync_Alarm alarm)
124 #ifdef ECORE_XCB_SYNC
125 xcb_sync_destroy_alarm(_ecore_xcb_conn, alarm);
127 #else /* ifdef ECORE_XCB_SYNC */
129 #endif /* ECORE_XCB_SYNC */
130 } /* ecore_x_sync_alarm_free */
132 /* FIXME: round trip */
135 ecore_x_sync_counter_query(Ecore_X_Sync_Counter counter, unsigned int *val)
137 #ifdef ECORE_XCB_SYNC
138 xcb_sync_query_counter_cookie_t cookie;
139 xcb_sync_query_counter_reply_t *reply;
141 cookie = xcb_sync_query_counter_unchecked(_ecore_xcb_conn, counter);
142 reply = xcb_sync_query_counter_reply(_ecore_xcb_conn, cookie, NULL);
145 *val = (unsigned int)reply->counter_value.lo;
150 #endif /* ECORE_XCB_SYNC */
153 } /* ecore_x_sync_counter_query */
155 EAPI Ecore_X_Sync_Counter
156 ecore_x_sync_counter_new(int val)
158 #ifdef ECORE_XCB_SYNC
159 xcb_sync_counter_t counter;
162 counter = xcb_generate_id(_ecore_xcb_conn);
163 v.hi = (val < 0) ? ~0 : 0;
165 xcb_sync_create_counter(_ecore_xcb_conn, counter, v);
167 #else /* ! ECORE_XCB_SYNC */
169 #endif /* ! ECORE_XCB_SYNC */
170 } /* ecore_x_sync_counter_new */
173 ecore_x_sync_counter_free(Ecore_X_Sync_Counter counter)
175 #ifdef ECORE_XCB_SYNC
176 xcb_sync_destroy_counter(_ecore_xcb_conn, counter);
177 #endif /* ECORE_XCB_SYNC */
178 } /* ecore_x_sync_counter_free */
181 ecore_x_sync_counter_inc(Ecore_X_Sync_Counter counter, int by)
183 #ifdef ECORE_XCB_SYNC
186 v.hi = (by < 0) ? ~0 : 0;
188 xcb_sync_change_counter(_ecore_xcb_conn, counter, v);
189 #endif /* ECORE_XCB_SYNC */
190 } /* ecore_x_sync_counter_inc */
193 ecore_x_sync_counter_val_wait(Ecore_X_Sync_Counter counter, int val)
195 #ifdef ECORE_XCB_SYNC
196 xcb_sync_query_counter_cookie_t cookie;
197 xcb_sync_query_counter_reply_t *reply;
200 xcb_sync_waitcondition_t cond;
202 /* what's the purpose of that call ?? as the value is erased... */
203 cookie = xcb_sync_query_counter_unchecked(_ecore_xcb_conn, counter);
204 reply = xcb_sync_query_counter_reply(_ecore_xcb_conn, cookie, NULL);
205 v1 = reply->counter_value;
208 v1.hi = (val < 0) ? ~0 : 0;
210 v2.hi = ((val + 1) < 0) ? ~0 : 0;
212 cond.trigger.counter = counter;
213 cond.trigger.wait_type = XCB_SYNC_VALUETYPE_ABSOLUTE;
214 cond.trigger.wait_value = v1;
215 cond.trigger.test_type = XCB_SYNC_TESTTYPE_POSITIVE_COMPARISON;
216 cond.event_threshold = v2;
218 xcb_sync_await(_ecore_xcb_conn, 1, (const xcb_sync_waitcondition_t *)&cond);
219 #endif /* ECORE_XCB_SYNC */
220 } /* ecore_x_sync_counter_val_wait */