Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dri2_glx.c 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  2. * Copyright © 2008 Red Hat, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Soft-
  6. * ware"), to deal in the Software without restriction, including without
  7. * limitation the rights to use, copy, modify, merge, publish, distribute,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, provided that the above copyright
  10. * notice(s) and this permission notice appear in all copies of the Soft-
  11. * ware and that both the above copyright notice(s) and this permission
  12. * notice appear in supporting documentation.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
  16. * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
  17. * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
  18. * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
  19. * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  20. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  21. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
  22. * MANCE OF THIS SOFTWARE.
  23. *
  24. * Except as contained in this notice, the name of a copyright holder shall
  25. * not be used in advertising or otherwise to promote the sale, use or
  26. * other dealings in this Software without prior written authorization of
  27. * the copyright holder.
  28. *
  29. * Authors:
  30. * Kristian Høgsberg (krh@redhat.com)
  31. */
  32. #ifdef GLX_DIRECT_RENDERING
  33. #include <X11/Xlib.h>
  34. #include <X11/extensions/Xfixes.h>
  35. #include <X11/extensions/Xdamage.h>
  36. #include "glapi.h"
  37. #include "glxclient.h"
  38. #include <X11/extensions/dri2proto.h>
  39. #include "xf86dri.h"
  40. #include <dlfcn.h>
  41. #include <fcntl.h>
  42. #include <unistd.h>
  43. #include <sys/types.h>
  44. #include <sys/mman.h>
  45. #include "xf86drm.h"
  46. #include "dri2.h"
  47. #include "dri_common.h"
  48. #include "../../mesa/drivers/dri/common/dri_util.h"
  49. #undef DRI2_MINOR
  50. #define DRI2_MINOR 1
  51. typedef struct __GLXDRIdisplayPrivateRec __GLXDRIdisplayPrivate;
  52. typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate;
  53. typedef struct __GLXDRIdrawablePrivateRec __GLXDRIdrawablePrivate;
  54. struct __GLXDRIdisplayPrivateRec
  55. {
  56. __GLXDRIdisplay base;
  57. /*
  58. ** XFree86-DRI version information
  59. */
  60. int driMajor;
  61. int driMinor;
  62. int driPatch;
  63. int swapAvailable;
  64. };
  65. struct __GLXDRIcontextPrivateRec
  66. {
  67. __GLXDRIcontext base;
  68. __DRIcontext *driContext;
  69. __GLXscreenConfigs *psc;
  70. };
  71. struct __GLXDRIdrawablePrivateRec
  72. {
  73. __GLXDRIdrawable base;
  74. __DRIbuffer buffers[5];
  75. int bufferCount;
  76. int width, height;
  77. int have_back;
  78. int have_fake_front;
  79. int swap_interval;
  80. };
  81. static void dri2WaitX(__GLXDRIdrawable * pdraw);
  82. static void
  83. dri2DestroyContext(__GLXDRIcontext * context,
  84. __GLXscreenConfigs * psc, Display * dpy)
  85. {
  86. __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context;
  87. const __DRIcoreExtension *core = pcp->psc->core;
  88. (*core->destroyContext) (pcp->driContext);
  89. Xfree(pcp);
  90. }
  91. static Bool
  92. dri2BindContext(__GLXDRIcontext * context,
  93. __GLXDRIdrawable * draw, __GLXDRIdrawable * read)
  94. {
  95. __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context;
  96. const __DRIcoreExtension *core = pcp->psc->core;
  97. return (*core->bindContext) (pcp->driContext,
  98. draw->driDrawable, read->driDrawable);
  99. }
  100. static void
  101. dri2UnbindContext(__GLXDRIcontext * context)
  102. {
  103. __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context;
  104. const __DRIcoreExtension *core = pcp->psc->core;
  105. (*core->unbindContext) (pcp->driContext);
  106. }
  107. static __GLXDRIcontext *
  108. dri2CreateContext(__GLXscreenConfigs * psc,
  109. const __GLcontextModes * mode,
  110. GLXContext gc, GLXContext shareList, int renderType)
  111. {
  112. __GLXDRIcontextPrivate *pcp, *pcp_shared;
  113. __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode;
  114. __DRIcontext *shared = NULL;
  115. if (shareList) {
  116. pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext;
  117. shared = pcp_shared->driContext;
  118. }
  119. pcp = Xmalloc(sizeof *pcp);
  120. if (pcp == NULL)
  121. return NULL;
  122. pcp->psc = psc;
  123. pcp->driContext =
  124. (*psc->dri2->createNewContext) (psc->__driScreen,
  125. config->driConfig, shared, pcp);
  126. gc->__driContext = pcp->driContext;
  127. if (pcp->driContext == NULL) {
  128. Xfree(pcp);
  129. return NULL;
  130. }
  131. pcp->base.destroyContext = dri2DestroyContext;
  132. pcp->base.bindContext = dri2BindContext;
  133. pcp->base.unbindContext = dri2UnbindContext;
  134. return &pcp->base;
  135. }
  136. static void
  137. dri2DestroyDrawable(__GLXDRIdrawable * pdraw)
  138. {
  139. const __DRIcoreExtension *core = pdraw->psc->core;
  140. (*core->destroyDrawable) (pdraw->driDrawable);
  141. DRI2DestroyDrawable(pdraw->psc->dpy, pdraw->xDrawable);
  142. Xfree(pdraw);
  143. }
  144. static __GLXDRIdrawable *
  145. dri2CreateDrawable(__GLXscreenConfigs * psc,
  146. XID xDrawable,
  147. GLXDrawable drawable, const __GLcontextModes * modes)
  148. {
  149. __GLXDRIdrawablePrivate *pdraw;
  150. __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes;
  151. pdraw = Xmalloc(sizeof(*pdraw));
  152. if (!pdraw)
  153. return NULL;
  154. pdraw->base.destroyDrawable = dri2DestroyDrawable;
  155. pdraw->base.xDrawable = xDrawable;
  156. pdraw->base.drawable = drawable;
  157. pdraw->base.psc = psc;
  158. pdraw->bufferCount = 0;
  159. DRI2CreateDrawable(psc->dpy, xDrawable);
  160. /* Create a new drawable */
  161. pdraw->base.driDrawable =
  162. (*psc->dri2->createNewDrawable) (psc->__driScreen,
  163. config->driConfig, pdraw);
  164. if (!pdraw->base.driDrawable) {
  165. DRI2DestroyDrawable(psc->dpy, xDrawable);
  166. Xfree(pdraw);
  167. return NULL;
  168. }
  169. return &pdraw->base;
  170. }
  171. static int
  172. dri2DrawableGetMSC(__GLXscreenConfigs *psc, __GLXDRIdrawable *pdraw,
  173. int64_t *ust, int64_t *msc, int64_t *sbc)
  174. {
  175. return DRI2GetMSC(psc->dpy, pdraw->xDrawable, ust, msc, sbc);
  176. }
  177. static int
  178. dri2WaitForMSC(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
  179. int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc)
  180. {
  181. return DRI2WaitMSC(pdraw->psc->dpy, pdraw->xDrawable, target_msc, divisor,
  182. remainder, ust, msc, sbc);
  183. }
  184. static int
  185. dri2WaitForSBC(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust,
  186. int64_t *msc, int64_t *sbc)
  187. {
  188. return DRI2WaitSBC(pdraw->psc->dpy, pdraw->xDrawable, target_sbc, ust, msc,
  189. sbc);
  190. }
  191. static void
  192. dri2CopySubBuffer(__GLXDRIdrawable *pdraw, int x, int y, int width, int height)
  193. {
  194. __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
  195. XRectangle xrect;
  196. XserverRegion region;
  197. /* Check we have the right attachments */
  198. if (!priv->have_back)
  199. return;
  200. xrect.x = x;
  201. xrect.y = priv->height - y - height;
  202. xrect.width = width;
  203. xrect.height = height;
  204. #ifdef __DRI2_FLUSH
  205. if (pdraw->psc->f)
  206. (*pdraw->psc->f->flush) (pdraw->driDrawable);
  207. #endif
  208. region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1);
  209. /* should get a fence ID back from here at some point */
  210. DRI2CopyRegion(pdraw->psc->dpy, pdraw->xDrawable, region,
  211. DRI2BufferFrontLeft, DRI2BufferBackLeft);
  212. XFixesDestroyRegion(pdraw->psc->dpy, region);
  213. /* Refresh the fake front (if present) after we just damaged the real
  214. * front.
  215. */
  216. dri2WaitX(pdraw);
  217. }
  218. static void
  219. dri2WaitX(__GLXDRIdrawable *pdraw)
  220. {
  221. __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
  222. XRectangle xrect;
  223. XserverRegion region;
  224. /* Check we have the right attachments */
  225. if (!priv->have_fake_front)
  226. return;
  227. xrect.x = 0;
  228. xrect.y = 0;
  229. xrect.width = priv->width;
  230. xrect.height = priv->height;
  231. #ifdef __DRI2_FLUSH
  232. if (pdraw->psc->f)
  233. (*pdraw->psc->f->flush) (pdraw->driDrawable);
  234. #endif
  235. region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1);
  236. DRI2CopyRegion(pdraw->psc->dpy, pdraw->xDrawable, region,
  237. DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft);
  238. XFixesDestroyRegion(pdraw->psc->dpy, region);
  239. }
  240. static void
  241. dri2WaitGL(__GLXDRIdrawable * pdraw)
  242. {
  243. __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
  244. XRectangle xrect;
  245. XserverRegion region;
  246. if (!priv->have_fake_front)
  247. return;
  248. xrect.x = 0;
  249. xrect.y = 0;
  250. xrect.width = priv->width;
  251. xrect.height = priv->height;
  252. #ifdef __DRI2_FLUSH
  253. if (pdraw->psc->f)
  254. (*pdraw->psc->f->flush) (pdraw->driDrawable);
  255. #endif
  256. region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1);
  257. DRI2CopyRegion(pdraw->psc->dpy, pdraw->xDrawable, region,
  258. DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
  259. XFixesDestroyRegion(pdraw->psc->dpy, region);
  260. }
  261. static void
  262. dri2FlushFrontBuffer(__DRIdrawable * driDrawable, void *loaderPrivate)
  263. {
  264. (void) driDrawable;
  265. dri2WaitGL((__GLXDRIdrawable *) loaderPrivate);
  266. }
  267. static void
  268. dri2DestroyScreen(__GLXscreenConfigs * psc)
  269. {
  270. /* Free the direct rendering per screen data */
  271. (*psc->core->destroyScreen) (psc->__driScreen);
  272. close(psc->fd);
  273. psc->__driScreen = NULL;
  274. }
  275. /**
  276. * Process list of buffer received from the server
  277. *
  278. * Processes the list of buffers received in a reply from the server to either
  279. * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat.
  280. */
  281. static void
  282. process_buffers(__GLXDRIdrawablePrivate * pdraw, DRI2Buffer * buffers,
  283. unsigned count)
  284. {
  285. int i;
  286. pdraw->bufferCount = count;
  287. pdraw->have_fake_front = 0;
  288. pdraw->have_back = 0;
  289. /* This assumes the DRI2 buffer attachment tokens matches the
  290. * __DRIbuffer tokens. */
  291. for (i = 0; i < count; i++) {
  292. pdraw->buffers[i].attachment = buffers[i].attachment;
  293. pdraw->buffers[i].name = buffers[i].name;
  294. pdraw->buffers[i].pitch = buffers[i].pitch;
  295. pdraw->buffers[i].cpp = buffers[i].cpp;
  296. pdraw->buffers[i].flags = buffers[i].flags;
  297. if (pdraw->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT)
  298. pdraw->have_fake_front = 1;
  299. if (pdraw->buffers[i].attachment == __DRI_BUFFER_BACK_LEFT)
  300. pdraw->have_back = 1;
  301. }
  302. }
  303. static int64_t
  304. dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
  305. int64_t remainder)
  306. {
  307. __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
  308. __GLXdisplayPrivate *dpyPriv = __glXInitialize(priv->base.psc->dpy);
  309. __GLXDRIdisplayPrivate *pdp =
  310. (__GLXDRIdisplayPrivate *)dpyPriv->dri2Display;
  311. int64_t ret;
  312. #ifdef __DRI2_FLUSH
  313. if (pdraw->psc->f)
  314. (*pdraw->psc->f->flush)(pdraw->driDrawable);
  315. #endif
  316. /* Old servers can't handle swapbuffers */
  317. if (!pdp->swapAvailable) {
  318. dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height);
  319. return 0;
  320. }
  321. #ifdef X_DRI2SwapBuffers
  322. DRI2SwapBuffers(pdraw->psc->dpy, pdraw->xDrawable, target_msc, divisor,
  323. remainder, &ret);
  324. #endif
  325. #if __DRI2_FLUSH_VERSION >= 2
  326. if (pdraw->psc->f)
  327. (*pdraw->psc->f->flushInvalidate)(pdraw->driDrawable);
  328. #endif
  329. return ret;
  330. }
  331. static __DRIbuffer *
  332. dri2GetBuffers(__DRIdrawable * driDrawable,
  333. int *width, int *height,
  334. unsigned int *attachments, int count,
  335. int *out_count, void *loaderPrivate)
  336. {
  337. __GLXDRIdrawablePrivate *pdraw = loaderPrivate;
  338. DRI2Buffer *buffers;
  339. buffers = DRI2GetBuffers(pdraw->base.psc->dpy, pdraw->base.xDrawable,
  340. width, height, attachments, count, out_count);
  341. if (buffers == NULL)
  342. return NULL;
  343. pdraw->width = *width;
  344. pdraw->height = *height;
  345. process_buffers(pdraw, buffers, *out_count);
  346. Xfree(buffers);
  347. return pdraw->buffers;
  348. }
  349. static __DRIbuffer *
  350. dri2GetBuffersWithFormat(__DRIdrawable * driDrawable,
  351. int *width, int *height,
  352. unsigned int *attachments, int count,
  353. int *out_count, void *loaderPrivate)
  354. {
  355. __GLXDRIdrawablePrivate *pdraw = loaderPrivate;
  356. DRI2Buffer *buffers;
  357. buffers = DRI2GetBuffersWithFormat(pdraw->base.psc->dpy,
  358. pdraw->base.xDrawable,
  359. width, height, attachments,
  360. count, out_count);
  361. if (buffers == NULL)
  362. return NULL;
  363. pdraw->width = *width;
  364. pdraw->height = *height;
  365. process_buffers(pdraw, buffers, *out_count);
  366. Xfree(buffers);
  367. return pdraw->buffers;
  368. }
  369. static void
  370. dri2SetSwapInterval(__GLXDRIdrawable *pdraw, int interval)
  371. {
  372. __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
  373. DRI2SwapInterval(priv->base.psc->dpy, pdraw->xDrawable, interval);
  374. priv->swap_interval = interval;
  375. }
  376. static unsigned int
  377. dri2GetSwapInterval(__GLXDRIdrawable *pdraw)
  378. {
  379. __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
  380. return priv->swap_interval;
  381. }
  382. static const __DRIdri2LoaderExtension dri2LoaderExtension = {
  383. {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION},
  384. dri2GetBuffers,
  385. dri2FlushFrontBuffer,
  386. dri2GetBuffersWithFormat,
  387. };
  388. static const __DRIdri2LoaderExtension dri2LoaderExtension_old = {
  389. {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION},
  390. dri2GetBuffers,
  391. dri2FlushFrontBuffer,
  392. NULL,
  393. };
  394. static const __DRIextension *loader_extensions[] = {
  395. &dri2LoaderExtension.base,
  396. &systemTimeExtension.base,
  397. NULL
  398. };
  399. static const __DRIextension *loader_extensions_old[] = {
  400. &dri2LoaderExtension_old.base,
  401. &systemTimeExtension.base,
  402. NULL
  403. };
  404. static __GLXDRIscreen *
  405. dri2CreateScreen(__GLXscreenConfigs * psc, int screen,
  406. __GLXdisplayPrivate * priv)
  407. {
  408. const __DRIconfig **driver_configs;
  409. const __DRIextension **extensions;
  410. const __GLXDRIdisplayPrivate *const pdp = (__GLXDRIdisplayPrivate *)
  411. priv->dri2Display;
  412. __GLXDRIscreen *psp;
  413. char *driverName, *deviceName;
  414. drm_magic_t magic;
  415. int i;
  416. psp = Xmalloc(sizeof *psp);
  417. if (psp == NULL)
  418. return NULL;
  419. /* Initialize per screen dynamic client GLX extensions */
  420. psc->ext_list_first_time = GL_TRUE;
  421. if (!DRI2Connect(psc->dpy, RootWindow(psc->dpy, screen),
  422. &driverName, &deviceName)) {
  423. XFree(psp);
  424. return NULL;
  425. }
  426. psc->driver = driOpenDriver(driverName);
  427. if (psc->driver == NULL) {
  428. ErrorMessageF("driver pointer missing\n");
  429. goto handle_error;
  430. }
  431. extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS);
  432. if (extensions == NULL) {
  433. ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
  434. goto handle_error;
  435. }
  436. for (i = 0; extensions[i]; i++) {
  437. if (strcmp(extensions[i]->name, __DRI_CORE) == 0)
  438. psc->core = (__DRIcoreExtension *) extensions[i];
  439. if (strcmp(extensions[i]->name, __DRI_DRI2) == 0)
  440. psc->dri2 = (__DRIdri2Extension *) extensions[i];
  441. }
  442. if (psc->core == NULL || psc->dri2 == NULL) {
  443. ErrorMessageF("core dri or dri2 extension not found\n");
  444. goto handle_error;
  445. }
  446. psc->fd = open(deviceName, O_RDWR);
  447. if (psc->fd < 0) {
  448. ErrorMessageF("failed to open drm device: %s\n", strerror(errno));
  449. goto handle_error;
  450. }
  451. if (drmGetMagic(psc->fd, &magic)) {
  452. ErrorMessageF("failed to get magic\n");
  453. goto handle_error;
  454. }
  455. if (!DRI2Authenticate(psc->dpy, RootWindow(psc->dpy, screen), magic)) {
  456. ErrorMessageF("failed to authenticate magic %d\n", magic);
  457. goto handle_error;
  458. }
  459. /* If the server does not support the protocol for
  460. * DRI2GetBuffersWithFormat, don't supply that interface to the driver.
  461. */
  462. psc->__driScreen =
  463. psc->dri2->createNewScreen(screen, psc->fd, ((pdp->driMinor < 1)
  464. ? loader_extensions_old
  465. : loader_extensions),
  466. &driver_configs, psc);
  467. if (psc->__driScreen == NULL) {
  468. ErrorMessageF("failed to create dri screen\n");
  469. goto handle_error;
  470. }
  471. driBindCommonExtensions(psc);
  472. dri2BindExtensions(psc);
  473. psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs);
  474. psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs);
  475. psc->driver_configs = driver_configs;
  476. psp->destroyScreen = dri2DestroyScreen;
  477. psp->createContext = dri2CreateContext;
  478. psp->createDrawable = dri2CreateDrawable;
  479. psp->swapBuffers = dri2SwapBuffers;
  480. psp->waitGL = dri2WaitGL;
  481. psp->waitX = dri2WaitX;
  482. psp->getDrawableMSC = NULL;
  483. psp->waitForMSC = NULL;
  484. psp->waitForSBC = NULL;
  485. psp->setSwapInterval = NULL;
  486. psp->getSwapInterval = NULL;
  487. if (pdp->driMinor >= 2) {
  488. #ifdef X_DRI2GetMSC
  489. psp->getDrawableMSC = dri2DrawableGetMSC;
  490. #endif
  491. #ifdef X_DRI2WaitMSC
  492. psp->waitForMSC = dri2WaitForMSC;
  493. psp->waitForSBC = dri2WaitForSBC;
  494. #endif
  495. #ifdef X_DRI2SwapInterval
  496. psp->setSwapInterval = dri2SetSwapInterval;
  497. psp->getSwapInterval = dri2GetSwapInterval;
  498. #endif
  499. }
  500. /* DRI2 suports SubBuffer through DRI2CopyRegion, so it's always
  501. * available.*/
  502. psp->copySubBuffer = dri2CopySubBuffer;
  503. __glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer");
  504. Xfree(driverName);
  505. Xfree(deviceName);
  506. return psp;
  507. handle_error:
  508. Xfree(driverName);
  509. Xfree(deviceName);
  510. XFree(psp);
  511. /* FIXME: clean up here */
  512. return NULL;
  513. }
  514. /* Called from __glXFreeDisplayPrivate.
  515. */
  516. static void
  517. dri2DestroyDisplay(__GLXDRIdisplay * dpy)
  518. {
  519. Xfree(dpy);
  520. }
  521. /*
  522. * Allocate, initialize and return a __DRIdisplayPrivate object.
  523. * This is called from __glXInitialize() when we are given a new
  524. * display pointer.
  525. */
  526. _X_HIDDEN __GLXDRIdisplay *
  527. dri2CreateDisplay(Display * dpy)
  528. {
  529. __GLXDRIdisplayPrivate *pdp;
  530. int eventBase, errorBase;
  531. if (!DRI2QueryExtension(dpy, &eventBase, &errorBase))
  532. return NULL;
  533. pdp = Xmalloc(sizeof *pdp);
  534. if (pdp == NULL)
  535. return NULL;
  536. if (!DRI2QueryVersion(dpy, &pdp->driMajor, &pdp->driMinor)) {
  537. Xfree(pdp);
  538. return NULL;
  539. }
  540. pdp->driPatch = 0;
  541. pdp->swapAvailable = 0;
  542. #ifdef X_DRI2SwapBuffers
  543. if (pdp->driMinor >= 2)
  544. pdp->swapAvailable = 1;
  545. #endif
  546. pdp->base.destroyDisplay = dri2DestroyDisplay;
  547. pdp->base.createScreen = dri2CreateScreen;
  548. return &pdp->base;
  549. }
  550. #endif /* GLX_DIRECT_RENDERING */