PageRenderTime 60ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/nx-3.5.0/nx-X11/lib/Xext/XSync.c

#
C | 817 lines | 640 code | 113 blank | 64 comment | 29 complexity | 1131691d4f0391d65245967d2cd9eb89 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0
  1. /* $Xorg: XSync.c,v 1.5 2001/02/09 02:03:49 xorgcvs Exp $ */
  2. /*
  3. Copyright 1991, 1993, 1998 The Open Group
  4. Permission to use, copy, modify, distribute, and sell this software and its
  5. documentation for any purpose is hereby granted without fee, provided that
  6. the above copyright notice appear in all copies and that both that
  7. copyright notice and this permission notice appear in supporting
  8. documentation.
  9. The above copyright notice and this permission notice shall be included
  10. in all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  14. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
  15. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  16. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  17. OTHER DEALINGS IN THE SOFTWARE.
  18. Except as contained in this notice, the name of The Open Group shall
  19. not be used in advertising or otherwise to promote the sale, use or
  20. other dealings in this Software without prior written authorization
  21. from The Open Group.
  22. */
  23. /***********************************************************
  24. Copyright 1991,1993 by Digital Equipment Corporation, Maynard, Massachusetts,
  25. and Olivetti Research Limited, Cambridge, England.
  26. All Rights Reserved
  27. Permission to use, copy, modify, and distribute this software and its
  28. documentation for any purpose and without fee is hereby granted,
  29. provided that the above copyright notice appear in all copies and that
  30. both that copyright notice and this permission notice appear in
  31. supporting documentation, and that the names of Digital or Olivetti
  32. not be used in advertising or publicity pertaining to distribution of the
  33. software without specific, written prior permission.
  34. DIGITAL AND OLIVETTI DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  35. SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. FITNESS, IN NO EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  37. CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  38. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  39. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  40. PERFORMANCE OF THIS SOFTWARE.
  41. ******************************************************************/
  42. /* $XFree86: xc/lib/Xext/XSync.c,v 1.7tsi Exp $ */
  43. #ifdef HAVE_CONFIG_H
  44. #include <config.h>
  45. #endif
  46. #include <stdio.h>
  47. #define NEED_EVENTS
  48. #define NEED_REPLIES
  49. #include <X11/Xlibint.h>
  50. #include <X11/extensions/Xext.h>
  51. #include <X11/extensions/extutil.h>
  52. #include <X11/extensions/syncstr.h>
  53. static XExtensionInfo _sync_info_data;
  54. static XExtensionInfo *sync_info = &_sync_info_data;
  55. static char *sync_extension_name = SYNC_NAME;
  56. #define SyncCheckExtension(dpy,i,val) \
  57. XextCheckExtension(dpy, i, sync_extension_name, val)
  58. #define SyncSimpleCheckExtension(dpy,i) \
  59. XextSimpleCheckExtension(dpy, i, sync_extension_name)
  60. static int close_display(Display *dpy, XExtCodes *codes);
  61. static Bool wire_to_event(Display *dpy, XEvent *event, xEvent *wire);
  62. static Status event_to_wire(Display *dpy, XEvent *event, xEvent *wire);
  63. static char *error_string(Display *dpy, int code, XExtCodes *codes,
  64. char *buf, int n);
  65. static XExtensionHooks sync_extension_hooks = {
  66. NULL, /* create_gc */
  67. NULL, /* copy_gc */
  68. NULL, /* flush_gc */
  69. NULL, /* free_gc */
  70. NULL, /* create_font */
  71. NULL, /* free_font */
  72. close_display, /* close_display */
  73. wire_to_event, /* wire_to_event */
  74. event_to_wire, /* event_to_wire */
  75. NULL, /* error */
  76. error_string, /* error_string */
  77. };
  78. static char *sync_error_list[] = {
  79. "BadCounter",
  80. "BadAlarm",
  81. };
  82. static
  83. XEXT_GENERATE_FIND_DISPLAY(find_display, sync_info,
  84. sync_extension_name,
  85. &sync_extension_hooks,
  86. XSyncNumberEvents, (XPointer) NULL)
  87. static
  88. XEXT_GENERATE_CLOSE_DISPLAY(close_display, sync_info)
  89. static
  90. XEXT_GENERATE_ERROR_STRING(error_string, sync_extension_name,
  91. XSyncNumberErrors, sync_error_list)
  92. static Bool
  93. wire_to_event(Display *dpy, XEvent *event, xEvent *wire)
  94. {
  95. XExtDisplayInfo *info = find_display(dpy);
  96. XSyncCounterNotifyEvent *aevent;
  97. xSyncCounterNotifyEvent *awire;
  98. XSyncAlarmNotifyEvent *anl;
  99. xSyncAlarmNotifyEvent *ane;
  100. SyncCheckExtension(dpy, info, False);
  101. switch ((wire->u.u.type & 0x7F) - info->codes->first_event)
  102. {
  103. case XSyncCounterNotify:
  104. awire = (xSyncCounterNotifyEvent *) wire;
  105. aevent = (XSyncCounterNotifyEvent *) event;
  106. aevent->type = awire->type & 0x7F;
  107. aevent->serial = _XSetLastRequestRead(dpy,
  108. (xGenericReply *) wire);
  109. aevent->send_event = (awire->type & 0x80) != 0;
  110. aevent->display = dpy;
  111. aevent->counter = awire->counter;
  112. XSyncIntsToValue(&aevent->wait_value, awire->wait_value_lo,
  113. awire->wait_value_hi);
  114. XSyncIntsToValue(&aevent->counter_value,
  115. awire->counter_value_lo,
  116. awire->counter_value_hi);
  117. aevent->time = awire->time;
  118. aevent->count = awire->count;
  119. aevent->destroyed = awire->destroyed;
  120. return True;
  121. case XSyncAlarmNotify:
  122. ane = (xSyncAlarmNotifyEvent *) wire; /* ENCODING EVENT PTR */
  123. anl = (XSyncAlarmNotifyEvent *) event; /* LIBRARY EVENT PTR */
  124. anl->type = ane->type & 0x7F;
  125. anl->serial = _XSetLastRequestRead(dpy,
  126. (xGenericReply *) wire);
  127. anl->send_event = (ane->type & 0x80) != 0;
  128. anl->display = dpy;
  129. anl->alarm = ane->alarm;
  130. XSyncIntsToValue(&anl->counter_value,
  131. ane->counter_value_lo,
  132. ane->counter_value_hi);
  133. XSyncIntsToValue(&anl->alarm_value,
  134. ane->alarm_value_lo,
  135. ane->alarm_value_hi);
  136. anl->state = (XSyncAlarmState)ane->state;
  137. anl->time = ane->time;
  138. return True;
  139. }
  140. return False;
  141. }
  142. static Status
  143. event_to_wire(Display *dpy, XEvent *event, xEvent *wire)
  144. {
  145. XExtDisplayInfo *info = find_display(dpy);
  146. XSyncCounterNotifyEvent *aevent;
  147. xSyncCounterNotifyEvent *awire;
  148. XSyncAlarmNotifyEvent *anl;
  149. xSyncAlarmNotifyEvent *ane;
  150. SyncCheckExtension(dpy, info, False);
  151. switch ((event->type & 0x7F) - info->codes->first_event)
  152. {
  153. case XSyncCounterNotify:
  154. awire = (xSyncCounterNotifyEvent *) wire;
  155. aevent = (XSyncCounterNotifyEvent *) event;
  156. awire->type = aevent->type | (aevent->send_event ? 0x80 : 0);
  157. awire->sequenceNumber = aevent->serial & 0xFFFF;
  158. awire->counter = aevent->counter;
  159. awire->wait_value_lo = XSyncValueLow32(aevent->wait_value);
  160. awire->wait_value_hi = XSyncValueHigh32(aevent->wait_value);
  161. awire->counter_value_lo = XSyncValueLow32(aevent->counter_value);
  162. awire->counter_value_hi = XSyncValueHigh32(aevent->counter_value);
  163. awire->time = aevent->time;
  164. awire->count = aevent->count;
  165. awire->destroyed = aevent->destroyed;
  166. return True;
  167. case XSyncAlarmNotify:
  168. ane = (xSyncAlarmNotifyEvent *) wire; /* ENCODING EVENT PTR */
  169. anl = (XSyncAlarmNotifyEvent *) event; /* LIBRARY EVENT PTR */
  170. ane->type = anl->type | (anl->send_event ? 0x80 : 0);
  171. ane->sequenceNumber = anl->serial & 0xFFFF;
  172. ane->alarm = anl->alarm;
  173. ane->counter_value_lo = XSyncValueLow32(anl->counter_value);
  174. ane->counter_value_hi = XSyncValueHigh32(anl->counter_value);
  175. ane->alarm_value_lo = XSyncValueLow32(anl->alarm_value);
  176. ane->alarm_value_hi = XSyncValueHigh32(anl->alarm_value);
  177. ane->state = anl->state;
  178. ane->time = anl->time;
  179. return True;
  180. }
  181. return False;
  182. }
  183. Status
  184. XSyncQueryExtension(
  185. Display *dpy,
  186. int *event_base_return, int *error_base_return)
  187. {
  188. XExtDisplayInfo *info = find_display(dpy);
  189. if (XextHasExtension(info))
  190. {
  191. *event_base_return = info->codes->first_event;
  192. *error_base_return = info->codes->first_error;
  193. return True;
  194. }
  195. else
  196. return False;
  197. }
  198. Status
  199. XSyncInitialize(
  200. Display *dpy,
  201. int *major_version_return, int *minor_version_return)
  202. {
  203. XExtDisplayInfo *info = find_display(dpy);
  204. xSyncInitializeReply rep;
  205. xSyncInitializeReq *req;
  206. SyncCheckExtension(dpy, info, False);
  207. LockDisplay(dpy);
  208. GetReq(SyncInitialize, req);
  209. req->reqType = info->codes->major_opcode;
  210. req->syncReqType = X_SyncInitialize;
  211. req->majorVersion = SYNC_MAJOR_VERSION;
  212. req->minorVersion = SYNC_MINOR_VERSION;
  213. if (!_XReply(dpy, (xReply *) & rep, 0, xTrue))
  214. {
  215. UnlockDisplay(dpy);
  216. SyncHandle();
  217. return False;
  218. }
  219. UnlockDisplay(dpy);
  220. SyncHandle();
  221. *major_version_return = rep.majorVersion;
  222. *minor_version_return = rep.minorVersion;
  223. return ((rep.majorVersion == SYNC_MAJOR_VERSION)
  224. #if SYNC_MINOR_VERSION > 0 /* avoid compiler warning */
  225. && (rep.minorVersion >= SYNC_MINOR_VERSION)
  226. #endif
  227. );
  228. }
  229. XSyncSystemCounter *
  230. XSyncListSystemCounters(Display *dpy, int *n_counters_return)
  231. {
  232. XExtDisplayInfo *info = find_display(dpy);
  233. xSyncListSystemCountersReply rep;
  234. xSyncListSystemCountersReq *req;
  235. XSyncSystemCounter *list = NULL;
  236. SyncCheckExtension(dpy, info, NULL);
  237. LockDisplay(dpy);
  238. GetReq(SyncListSystemCounters, req);
  239. req->reqType = info->codes->major_opcode;
  240. req->syncReqType = X_SyncListSystemCounters;
  241. if (!_XReply(dpy, (xReply *) & rep, 0, xFalse))
  242. goto bail;
  243. *n_counters_return = rep.nCounters;
  244. if (rep.nCounters > 0)
  245. {
  246. xSyncSystemCounter *pWireSysCounter, *pNextWireSysCounter;
  247. XSyncCounter counter;
  248. int replylen;
  249. int i;
  250. list = (XSyncSystemCounter *)Xmalloc(
  251. rep.nCounters * sizeof(XSyncSystemCounter));
  252. replylen = rep.length << 2;
  253. pWireSysCounter = (xSyncSystemCounter *) Xmalloc ((unsigned) replylen + 1);
  254. /* +1 to leave room for last null-terminator */
  255. if ((!list) || (!pWireSysCounter))
  256. {
  257. if (list) Xfree((char *) list);
  258. if (pWireSysCounter) Xfree((char *) pWireSysCounter);
  259. _XEatData(dpy, (unsigned long) replylen);
  260. list = NULL;
  261. goto bail;
  262. }
  263. _XReadPad(dpy, (char *)pWireSysCounter, replylen);
  264. counter = pWireSysCounter->counter;
  265. for (i = 0; i < rep.nCounters; i++)
  266. {
  267. list[i].counter = counter;
  268. XSyncIntsToValue(&list[i].resolution,
  269. pWireSysCounter->resolution_lo,
  270. pWireSysCounter->resolution_hi);
  271. /* we may be about to clobber the counter field of the
  272. * next syscounter because we have to add a null terminator
  273. * to the counter name string. So we save the next counter
  274. * here.
  275. */
  276. pNextWireSysCounter = (xSyncSystemCounter *)
  277. (((char *)pWireSysCounter) + ((SIZEOF(xSyncSystemCounter) +
  278. pWireSysCounter->name_length + 3) & ~3));
  279. counter = pNextWireSysCounter->counter;
  280. list[i].name = ((char *)pWireSysCounter) +
  281. SIZEOF(xSyncSystemCounter);
  282. /* null-terminate the string */
  283. *(list[i].name + pWireSysCounter->name_length) = '\0';
  284. pWireSysCounter = pNextWireSysCounter;
  285. }
  286. }
  287. bail:
  288. UnlockDisplay(dpy);
  289. SyncHandle();
  290. return list;
  291. }
  292. void
  293. XSyncFreeSystemCounterList(XSyncSystemCounter *list)
  294. {
  295. if (list)
  296. {
  297. Xfree( ((char *)list[0].name) - SIZEOF(xSyncSystemCounter));
  298. Xfree(list);
  299. }
  300. }
  301. XSyncCounter
  302. XSyncCreateCounter(Display *dpy, XSyncValue initial_value)
  303. {
  304. XExtDisplayInfo *info = find_display(dpy);
  305. xSyncCreateCounterReq *req;
  306. SyncCheckExtension(dpy, info, None);
  307. LockDisplay(dpy);
  308. GetReq(SyncCreateCounter, req);
  309. req->reqType = info->codes->major_opcode;
  310. req->syncReqType = X_SyncCreateCounter;
  311. req->cid = XAllocID(dpy);
  312. req->initial_value_lo = XSyncValueLow32(initial_value);
  313. req->initial_value_hi = XSyncValueHigh32(initial_value);
  314. UnlockDisplay(dpy);
  315. SyncHandle();
  316. return req->cid;
  317. }
  318. Status
  319. XSyncSetCounter(Display *dpy, XSyncCounter counter, XSyncValue value)
  320. {
  321. XExtDisplayInfo *info = find_display(dpy);
  322. xSyncSetCounterReq *req;
  323. SyncCheckExtension(dpy, info, False);
  324. LockDisplay(dpy);
  325. GetReq(SyncSetCounter, req);
  326. req->reqType = info->codes->major_opcode;
  327. req->syncReqType = X_SyncSetCounter;
  328. req->cid = counter;
  329. req->value_lo = XSyncValueLow32(value);
  330. req->value_hi = XSyncValueHigh32(value);
  331. UnlockDisplay(dpy);
  332. SyncHandle();
  333. return True;
  334. }
  335. Status
  336. XSyncChangeCounter(Display *dpy, XSyncCounter counter, XSyncValue value)
  337. {
  338. XExtDisplayInfo *info = find_display(dpy);
  339. xSyncChangeCounterReq *req;
  340. SyncCheckExtension(dpy, info, False);
  341. LockDisplay(dpy);
  342. GetReq(SyncChangeCounter, req);
  343. req->reqType = info->codes->major_opcode;
  344. req->syncReqType = X_SyncChangeCounter;
  345. req->cid = counter;
  346. req->value_lo = XSyncValueLow32(value);
  347. req->value_hi = XSyncValueHigh32(value);
  348. UnlockDisplay(dpy);
  349. SyncHandle();
  350. return True;
  351. }
  352. Status
  353. XSyncDestroyCounter(Display *dpy, XSyncCounter counter)
  354. {
  355. XExtDisplayInfo *info = find_display(dpy);
  356. xSyncDestroyCounterReq *req;
  357. SyncCheckExtension(dpy, info, False);
  358. LockDisplay(dpy);
  359. GetReq(SyncDestroyCounter, req);
  360. req->reqType = info->codes->major_opcode;
  361. req->syncReqType = X_SyncDestroyCounter;
  362. req->counter = counter;
  363. UnlockDisplay(dpy);
  364. SyncHandle();
  365. return True;
  366. }
  367. Status
  368. XSyncQueryCounter(Display *dpy, XSyncCounter counter, XSyncValue *value_return)
  369. {
  370. XExtDisplayInfo *info = find_display(dpy);
  371. xSyncQueryCounterReply rep;
  372. xSyncQueryCounterReq *req;
  373. SyncCheckExtension(dpy, info, False);
  374. LockDisplay(dpy);
  375. GetReq(SyncQueryCounter, req);
  376. req->reqType = info->codes->major_opcode;
  377. req->syncReqType = X_SyncQueryCounter;
  378. req->counter = counter;
  379. if (!_XReply(dpy, (xReply *) & rep, 0, xTrue))
  380. {
  381. UnlockDisplay(dpy);
  382. SyncHandle();
  383. return False;
  384. }
  385. XSyncIntsToValue(value_return, rep.value_lo, rep.value_hi);
  386. UnlockDisplay(dpy);
  387. SyncHandle();
  388. return True;
  389. }
  390. Status
  391. XSyncAwait(Display *dpy, XSyncWaitCondition *wait_list, int n_conditions)
  392. {
  393. XExtDisplayInfo *info = find_display(dpy);
  394. XSyncWaitCondition *wait_item = wait_list;
  395. xSyncAwaitReq *req;
  396. unsigned int len;
  397. SyncCheckExtension(dpy, info, False);
  398. LockDisplay(dpy);
  399. GetReq(SyncAwait, req);
  400. req->reqType = info->codes->major_opcode;
  401. req->syncReqType = X_SyncAwait;
  402. len = (n_conditions * SIZEOF(xSyncWaitCondition)) >> 2;
  403. SetReqLen(req, len, len /* XXX */ );
  404. while (n_conditions--)
  405. {
  406. xSyncWaitCondition wc;
  407. wc.counter = wait_item->trigger.counter;
  408. wc.value_type = wait_item->trigger.value_type;
  409. wc.wait_value_lo = XSyncValueLow32(wait_item->trigger.wait_value);
  410. wc.wait_value_hi = XSyncValueHigh32(wait_item->trigger.wait_value);
  411. wc.test_type = wait_item->trigger.test_type;
  412. wc.event_threshold_lo = XSyncValueLow32(wait_item->event_threshold);
  413. wc.event_threshold_hi = XSyncValueHigh32(wait_item->event_threshold);
  414. Data(dpy, (char *)&wc, SIZEOF(xSyncWaitCondition));
  415. wait_item++; /* get next trigger */
  416. }
  417. UnlockDisplay(dpy);
  418. SyncHandle();
  419. return True;
  420. }
  421. static void
  422. _XProcessAlarmAttributes(Display *dpy, xSyncChangeAlarmReq *req,
  423. unsigned long valuemask,
  424. XSyncAlarmAttributes *attributes)
  425. {
  426. unsigned long values[32];
  427. unsigned long *value = values;
  428. unsigned int nvalues;
  429. if (valuemask & XSyncCACounter)
  430. *value++ = attributes->trigger.counter;
  431. if (valuemask & XSyncCAValueType)
  432. *value++ = attributes->trigger.value_type;
  433. if (valuemask & XSyncCAValue)
  434. {
  435. *value++ = XSyncValueHigh32(attributes->trigger.wait_value);
  436. *value++ = XSyncValueLow32(attributes->trigger.wait_value);
  437. }
  438. if (valuemask & XSyncCATestType)
  439. *value++ = attributes->trigger.test_type;
  440. if (valuemask & XSyncCADelta)
  441. {
  442. *value++ = XSyncValueHigh32(attributes->delta);
  443. *value++ = XSyncValueLow32(attributes->delta);
  444. }
  445. if (valuemask & XSyncCAEvents)
  446. *value++ = attributes->events;
  447. /* N.B. the 'state' field cannot be set or changed */
  448. req->length += (nvalues = value - values);
  449. nvalues <<= 2; /* watch out for macros... */
  450. Data32(dpy, (long *) values, (long) nvalues);
  451. }
  452. XSyncAlarm
  453. XSyncCreateAlarm(
  454. Display *dpy,
  455. unsigned long values_mask,
  456. XSyncAlarmAttributes *values)
  457. {
  458. XExtDisplayInfo *info = find_display(dpy);
  459. xSyncCreateAlarmReq *req;
  460. XSyncAlarm aid;
  461. SyncCheckExtension(dpy, info, False);
  462. LockDisplay(dpy);
  463. GetReq(SyncCreateAlarm, req);
  464. req->reqType = info->codes->major_opcode;
  465. req->syncReqType = X_SyncCreateAlarm;
  466. req->id = aid = XAllocID(dpy);
  467. values_mask &= XSyncCACounter | XSyncCAValueType | XSyncCAValue
  468. | XSyncCATestType | XSyncCADelta | XSyncCAEvents;
  469. if ((req->valueMask = values_mask))
  470. _XProcessAlarmAttributes(dpy, (xSyncChangeAlarmReq *) req,
  471. values_mask, values);
  472. UnlockDisplay(dpy);
  473. SyncHandle();
  474. return aid;
  475. }
  476. Status
  477. XSyncDestroyAlarm(Display *dpy, XSyncAlarm alarm)
  478. {
  479. XExtDisplayInfo *info = find_display(dpy);
  480. xSyncDestroyAlarmReq *req;
  481. SyncCheckExtension(dpy, info, False);
  482. LockDisplay(dpy);
  483. GetReq(SyncDestroyAlarm, req);
  484. req->reqType = info->codes->major_opcode;
  485. req->syncReqType = X_SyncDestroyAlarm;
  486. req->alarm = alarm;
  487. UnlockDisplay(dpy);
  488. SyncHandle();
  489. return True;
  490. }
  491. Status
  492. XSyncQueryAlarm(
  493. Display *dpy,
  494. XSyncAlarm alarm,
  495. XSyncAlarmAttributes *values_return)
  496. {
  497. XExtDisplayInfo *info = find_display(dpy);
  498. xSyncQueryAlarmReq *req;
  499. xSyncQueryAlarmReply rep;
  500. SyncCheckExtension(dpy, info, False);
  501. LockDisplay(dpy);
  502. GetReq(SyncQueryAlarm, req);
  503. req->reqType = info->codes->major_opcode;
  504. req->syncReqType = X_SyncQueryAlarm;
  505. req->alarm = alarm;
  506. if (!(_XReply(dpy, (xReply *) & rep,
  507. ((SIZEOF(xSyncQueryAlarmReply) - SIZEOF(xGenericReply)) >> 2), xFalse)))
  508. {
  509. UnlockDisplay(dpy);
  510. SyncHandle();
  511. return False;
  512. }
  513. values_return->trigger.counter = rep.counter;
  514. values_return->trigger.value_type = (XSyncValueType)rep.value_type;
  515. XSyncIntsToValue(&values_return->trigger.wait_value,
  516. rep.wait_value_lo, rep.wait_value_hi);
  517. values_return->trigger.test_type = (XSyncTestType)rep.test_type;
  518. XSyncIntsToValue(&values_return->delta, rep.delta_lo,
  519. rep.delta_hi);
  520. values_return->events = rep.events;
  521. values_return->state = (XSyncAlarmState)rep.state;
  522. UnlockDisplay(dpy);
  523. SyncHandle();
  524. return True;
  525. }
  526. Status
  527. XSyncChangeAlarm(
  528. Display *dpy,
  529. XSyncAlarm alarm,
  530. unsigned long values_mask,
  531. XSyncAlarmAttributes *values)
  532. {
  533. XExtDisplayInfo *info = find_display(dpy);
  534. xSyncChangeAlarmReq *req;
  535. SyncCheckExtension(dpy, info, False);
  536. LockDisplay(dpy);
  537. GetReq(SyncChangeAlarm, req);
  538. req->reqType = info->codes->major_opcode;
  539. req->syncReqType = X_SyncChangeAlarm;
  540. req->alarm = alarm;
  541. values_mask &= XSyncCACounter | XSyncCAValueType | XSyncCAValue
  542. | XSyncCATestType | XSyncCADelta | XSyncCAEvents;
  543. if ((req->valueMask = values_mask))
  544. _XProcessAlarmAttributes(dpy, req, values_mask, values);
  545. UnlockDisplay(dpy);
  546. SyncHandle();
  547. return True;
  548. }
  549. Status
  550. XSyncSetPriority(
  551. Display *dpy,
  552. XID client_resource_id,
  553. int priority)
  554. {
  555. XExtDisplayInfo *info = find_display(dpy);
  556. xSyncSetPriorityReq *req;
  557. SyncCheckExtension(dpy, info, False);
  558. LockDisplay(dpy);
  559. GetReq(SyncSetPriority, req);
  560. req->reqType = info->codes->major_opcode;
  561. req->syncReqType = X_SyncSetPriority;
  562. req->id = client_resource_id;
  563. req->priority = priority;
  564. UnlockDisplay(dpy);
  565. SyncHandle();
  566. return True;
  567. }
  568. Status
  569. XSyncGetPriority(Display *dpy, XID client_resource_id, int *return_priority)
  570. {
  571. XExtDisplayInfo *info = find_display(dpy);
  572. xSyncGetPriorityReply rep;
  573. xSyncGetPriorityReq *req;
  574. SyncCheckExtension(dpy, info, False);
  575. LockDisplay(dpy);
  576. GetReq(SyncGetPriority, req);
  577. req->reqType = info->codes->major_opcode;
  578. req->syncReqType = X_SyncGetPriority;
  579. req->id = client_resource_id;
  580. if (!_XReply(dpy, (xReply *) & rep, 0, xFalse))
  581. {
  582. UnlockDisplay(dpy);
  583. SyncHandle();
  584. return False;
  585. }
  586. if (return_priority)
  587. *return_priority = rep.priority;
  588. UnlockDisplay(dpy);
  589. SyncHandle();
  590. return True;
  591. }
  592. /*
  593. * Functions corresponding to the macros for manipulating 64-bit values
  594. */
  595. /* get rid of macros so we can define corresponding functions */
  596. #undef XSyncIntToValue
  597. #undef XSyncIntsToValue
  598. #undef XSyncValueGreaterThan
  599. #undef XSyncValueLessThan
  600. #undef XSyncValueGreaterOrEqual
  601. #undef XSyncValueLessOrEqual
  602. #undef XSyncValueEqual
  603. #undef XSyncValueIsNegative
  604. #undef XSyncValueIsZero
  605. #undef XSyncValueIsPositive
  606. #undef XSyncValueLow32
  607. #undef XSyncValueHigh32
  608. #undef XSyncValueAdd
  609. #undef XSyncValueSubtract
  610. #undef XSyncMaxValue
  611. #undef XSyncMinValue
  612. void
  613. XSyncIntToValue(XSyncValue *pv, int i)
  614. {
  615. _XSyncIntToValue(pv,i);
  616. }
  617. void
  618. XSyncIntsToValue(XSyncValue *pv, unsigned int l, int h)
  619. {
  620. _XSyncIntsToValue(pv, l, h);
  621. }
  622. Bool
  623. XSyncValueGreaterThan(XSyncValue a, XSyncValue b)
  624. {
  625. return _XSyncValueGreaterThan(a, b);
  626. }
  627. Bool
  628. XSyncValueLessThan(XSyncValue a, XSyncValue b)
  629. {
  630. return _XSyncValueLessThan(a, b);
  631. }
  632. Bool
  633. XSyncValueGreaterOrEqual(XSyncValue a, XSyncValue b)
  634. {
  635. return _XSyncValueGreaterOrEqual(a, b);
  636. }
  637. Bool
  638. XSyncValueLessOrEqual(XSyncValue a, XSyncValue b)
  639. {
  640. return _XSyncValueLessOrEqual(a, b);
  641. }
  642. Bool
  643. XSyncValueEqual(XSyncValue a, XSyncValue b)
  644. {
  645. return _XSyncValueEqual(a, b);
  646. }
  647. Bool
  648. XSyncValueIsNegative(XSyncValue v)
  649. {
  650. return _XSyncValueIsNegative(v);
  651. }
  652. Bool
  653. XSyncValueIsZero(XSyncValue a)
  654. {
  655. return _XSyncValueIsZero(a);
  656. }
  657. Bool
  658. XSyncValueIsPositive(XSyncValue v)
  659. {
  660. return _XSyncValueIsPositive(v);
  661. }
  662. unsigned int
  663. XSyncValueLow32(XSyncValue v)
  664. {
  665. return _XSyncValueLow32(v);
  666. }
  667. int
  668. XSyncValueHigh32(XSyncValue v)
  669. {
  670. return _XSyncValueHigh32(v);
  671. }
  672. void
  673. XSyncValueAdd(XSyncValue *presult, XSyncValue a, XSyncValue b, Bool *poverflow)
  674. {
  675. _XSyncValueAdd(presult, a, b, poverflow);
  676. }
  677. void
  678. XSyncValueSubtract(
  679. XSyncValue *presult,
  680. XSyncValue a, XSyncValue b,
  681. Bool *poverflow)
  682. {
  683. _XSyncValueSubtract(presult, a, b, poverflow);
  684. }
  685. void
  686. XSyncMaxValue(XSyncValue *pv)
  687. {
  688. _XSyncMaxValue(pv);
  689. }
  690. void
  691. XSyncMinValue(XSyncValue *pv)
  692. {
  693. _XSyncMinValue(pv);
  694. }