Initialize DRI2 swap interval to 0
[mesa.git] / src / glx / dri2_glx.c
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
33 #ifdef GLX_DIRECT_RENDERING
34
35 #include <X11/Xlib.h>
36 #include <X11/extensions/Xfixes.h>
37 #include <X11/extensions/Xdamage.h>
38 #include "glapi.h"
39 #include "glxclient.h"
40 #include <X11/extensions/dri2proto.h>
41 #include "xf86dri.h"
42 #include <dlfcn.h>
43 #include <fcntl.h>
44 #include <unistd.h>
45 #include <sys/types.h>
46 #include <sys/mman.h>
47 #include "xf86drm.h"
48 #include "dri2.h"
49 #include "dri_common.h"
50 #include "../../mesa/drivers/dri/common/dri_util.h"
51
52 #undef DRI2_MINOR
53 #define DRI2_MINOR 1
54
55 typedef struct __GLXDRIdisplayPrivateRec __GLXDRIdisplayPrivate;
56 typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate;
57 typedef struct __GLXDRIdrawablePrivateRec __GLXDRIdrawablePrivate;
58
59 struct __GLXDRIdisplayPrivateRec
60 {
61 __GLXDRIdisplay base;
62
63 /*
64 ** XFree86-DRI version information
65 */
66 int driMajor;
67 int driMinor;
68 int driPatch;
69 int swapAvailable;
70 int invalidateAvailable;
71 };
72
73 struct __GLXDRIcontextPrivateRec
74 {
75 __GLXDRIcontext base;
76 __DRIcontext *driContext;
77 __GLXscreenConfigs *psc;
78 };
79
80 struct __GLXDRIdrawablePrivateRec
81 {
82 __GLXDRIdrawable base;
83 __DRIbuffer buffers[5];
84 int bufferCount;
85 int width, height;
86 int have_back;
87 int have_fake_front;
88 int swap_interval;
89 };
90
91 static void dri2WaitX(__GLXDRIdrawable * pdraw);
92
93 static void
94 dri2DestroyContext(__GLXDRIcontext * context,
95 __GLXscreenConfigs * psc, Display * dpy)
96 {
97 __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context;
98 const __DRIcoreExtension *core = pcp->psc->core;
99
100 (*core->destroyContext) (pcp->driContext);
101
102 Xfree(pcp);
103 }
104
105 static Bool
106 dri2BindContext(__GLXDRIcontext * context,
107 __GLXDRIdrawable * draw, __GLXDRIdrawable * read)
108 {
109 __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context;
110 const __DRIcoreExtension *core = pcp->psc->core;
111
112 return (*core->bindContext) (pcp->driContext,
113 draw->driDrawable, read->driDrawable);
114 }
115
116 static void
117 dri2UnbindContext(__GLXDRIcontext * context)
118 {
119 __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context;
120 const __DRIcoreExtension *core = pcp->psc->core;
121
122 (*core->unbindContext) (pcp->driContext);
123 }
124
125 static __GLXDRIcontext *
126 dri2CreateContext(__GLXscreenConfigs * psc,
127 const __GLcontextModes * mode,
128 GLXContext gc, GLXContext shareList, int renderType)
129 {
130 __GLXDRIcontextPrivate *pcp, *pcp_shared;
131 __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode;
132 __DRIcontext *shared = NULL;
133
134 if (shareList) {
135 pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext;
136 shared = pcp_shared->driContext;
137 }
138
139 pcp = Xmalloc(sizeof *pcp);
140 if (pcp == NULL)
141 return NULL;
142
143 pcp->psc = psc;
144 pcp->driContext =
145 (*psc->dri2->createNewContext) (psc->__driScreen,
146 config->driConfig, shared, pcp);
147 gc->__driContext = pcp->driContext;
148
149 if (pcp->driContext == NULL) {
150 Xfree(pcp);
151 return NULL;
152 }
153
154 pcp->base.destroyContext = dri2DestroyContext;
155 pcp->base.bindContext = dri2BindContext;
156 pcp->base.unbindContext = dri2UnbindContext;
157
158 return &pcp->base;
159 }
160
161 static void
162 dri2DestroyDrawable(__GLXDRIdrawable * pdraw)
163 {
164 const __DRIcoreExtension *core = pdraw->psc->core;
165
166 (*core->destroyDrawable) (pdraw->driDrawable);
167 DRI2DestroyDrawable(pdraw->psc->dpy, pdraw->xDrawable);
168 Xfree(pdraw);
169 }
170
171 static __GLXDRIdrawable *
172 dri2CreateDrawable(__GLXscreenConfigs * psc,
173 XID xDrawable,
174 GLXDrawable drawable, const __GLcontextModes * modes)
175 {
176 __GLXDRIdrawablePrivate *pdraw;
177 __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes;
178
179 pdraw = Xmalloc(sizeof(*pdraw));
180 if (!pdraw)
181 return NULL;
182
183 pdraw->base.destroyDrawable = dri2DestroyDrawable;
184 pdraw->base.xDrawable = xDrawable;
185 pdraw->base.drawable = drawable;
186 pdraw->base.psc = psc;
187 pdraw->bufferCount = 0;
188 pdraw->swap_interval = 0;
189
190 DRI2CreateDrawable(psc->dpy, xDrawable);
191
192 /* Create a new drawable */
193 pdraw->base.driDrawable =
194 (*psc->dri2->createNewDrawable) (psc->__driScreen,
195 config->driConfig, pdraw);
196
197 if (!pdraw->base.driDrawable) {
198 DRI2DestroyDrawable(psc->dpy, xDrawable);
199 Xfree(pdraw);
200 return NULL;
201 }
202
203 return &pdraw->base;
204 }
205
206 #ifdef X_DRI2GetMSC
207
208 static int
209 dri2DrawableGetMSC(__GLXscreenConfigs *psc, __GLXDRIdrawable *pdraw,
210 int64_t *ust, int64_t *msc, int64_t *sbc)
211 {
212 return DRI2GetMSC(psc->dpy, pdraw->xDrawable, ust, msc, sbc);
213 }
214
215 #endif
216
217
218 #ifdef X_DRI2WaitMSC
219
220 static int
221 dri2WaitForMSC(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
222 int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc)
223 {
224 return DRI2WaitMSC(pdraw->psc->dpy, pdraw->xDrawable, target_msc, divisor,
225 remainder, ust, msc, sbc);
226 }
227
228 static int
229 dri2WaitForSBC(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust,
230 int64_t *msc, int64_t *sbc)
231 {
232 return DRI2WaitSBC(pdraw->psc->dpy, pdraw->xDrawable, target_sbc, ust, msc,
233 sbc);
234 }
235
236 #endif /* X_DRI2WaitMSC */
237
238 static void
239 dri2CopySubBuffer(__GLXDRIdrawable *pdraw, int x, int y, int width, int height)
240 {
241 __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
242 XRectangle xrect;
243 XserverRegion region;
244
245 /* Check we have the right attachments */
246 if (!priv->have_back)
247 return;
248
249 xrect.x = x;
250 xrect.y = priv->height - y - height;
251 xrect.width = width;
252 xrect.height = height;
253
254 #ifdef __DRI2_FLUSH
255 if (pdraw->psc->f)
256 (*pdraw->psc->f->flush) (pdraw->driDrawable);
257 #endif
258
259 region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1);
260 /* should get a fence ID back from here at some point */
261 DRI2CopyRegion(pdraw->psc->dpy, pdraw->xDrawable, region,
262 DRI2BufferFrontLeft, DRI2BufferBackLeft);
263 XFixesDestroyRegion(pdraw->psc->dpy, region);
264
265 /* Refresh the fake front (if present) after we just damaged the real
266 * front.
267 */
268 dri2WaitX(pdraw);
269 }
270
271 static void
272 dri2WaitX(__GLXDRIdrawable *pdraw)
273 {
274 __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
275 XRectangle xrect;
276 XserverRegion region;
277
278 /* Check we have the right attachments */
279 if (!priv->have_fake_front)
280 return;
281
282 xrect.x = 0;
283 xrect.y = 0;
284 xrect.width = priv->width;
285 xrect.height = priv->height;
286
287 #ifdef __DRI2_FLUSH
288 if (pdraw->psc->f)
289 (*pdraw->psc->f->flush) (pdraw->driDrawable);
290 #endif
291
292 region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1);
293 DRI2CopyRegion(pdraw->psc->dpy, pdraw->xDrawable, region,
294 DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft);
295 XFixesDestroyRegion(pdraw->psc->dpy, region);
296 }
297
298 static void
299 dri2WaitGL(__GLXDRIdrawable * pdraw)
300 {
301 __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
302 XRectangle xrect;
303 XserverRegion region;
304
305 if (!priv->have_fake_front)
306 return;
307
308 xrect.x = 0;
309 xrect.y = 0;
310 xrect.width = priv->width;
311 xrect.height = priv->height;
312
313 #ifdef __DRI2_FLUSH
314 if (pdraw->psc->f)
315 (*pdraw->psc->f->flush) (pdraw->driDrawable);
316 #endif
317
318 region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1);
319 DRI2CopyRegion(pdraw->psc->dpy, pdraw->xDrawable, region,
320 DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
321 XFixesDestroyRegion(pdraw->psc->dpy, region);
322 }
323
324 static void
325 dri2FlushFrontBuffer(__DRIdrawable *driDrawable, void *loaderPrivate)
326 {
327 __GLXDRIdrawablePrivate *pdraw = loaderPrivate;
328 __GLXdisplayPrivate *priv = __glXInitialize(pdraw->base.psc->dpy);
329 __GLXDRIdisplayPrivate *pdp = (__GLXDRIdisplayPrivate *)priv->dri2Display;
330
331 /* Old servers don't send invalidate events */
332 if (!pdp->invalidateAvailable)
333 dri2InvalidateBuffers(priv->dpy, pdraw->base.drawable);
334
335 dri2WaitGL(loaderPrivate);
336 }
337
338
339 static void
340 dri2DestroyScreen(__GLXscreenConfigs * psc)
341 {
342 /* Free the direct rendering per screen data */
343 (*psc->core->destroyScreen) (psc->__driScreen);
344 close(psc->fd);
345 psc->__driScreen = NULL;
346 }
347
348 /**
349 * Process list of buffer received from the server
350 *
351 * Processes the list of buffers received in a reply from the server to either
352 * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat.
353 */
354 static void
355 process_buffers(__GLXDRIdrawablePrivate * pdraw, DRI2Buffer * buffers,
356 unsigned count)
357 {
358 int i;
359
360 pdraw->bufferCount = count;
361 pdraw->have_fake_front = 0;
362 pdraw->have_back = 0;
363
364 /* This assumes the DRI2 buffer attachment tokens matches the
365 * __DRIbuffer tokens. */
366 for (i = 0; i < count; i++) {
367 pdraw->buffers[i].attachment = buffers[i].attachment;
368 pdraw->buffers[i].name = buffers[i].name;
369 pdraw->buffers[i].pitch = buffers[i].pitch;
370 pdraw->buffers[i].cpp = buffers[i].cpp;
371 pdraw->buffers[i].flags = buffers[i].flags;
372 if (pdraw->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT)
373 pdraw->have_fake_front = 1;
374 if (pdraw->buffers[i].attachment == __DRI_BUFFER_BACK_LEFT)
375 pdraw->have_back = 1;
376 }
377
378 }
379
380 static int64_t
381 dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
382 int64_t remainder)
383 {
384 __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
385 __GLXdisplayPrivate *dpyPriv = __glXInitialize(priv->base.psc->dpy);
386 __GLXDRIdisplayPrivate *pdp =
387 (__GLXDRIdisplayPrivate *)dpyPriv->dri2Display;
388 int64_t ret;
389
390 #ifdef __DRI2_FLUSH
391 if (pdraw->psc->f)
392 (*pdraw->psc->f->flush)(pdraw->driDrawable);
393 #endif
394
395 /* Old servers don't send invalidate events */
396 if (!pdp->invalidateAvailable)
397 dri2InvalidateBuffers(dpyPriv->dpy, pdraw->drawable);
398
399 /* Old servers can't handle swapbuffers */
400 if (!pdp->swapAvailable) {
401 dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height);
402 return 0;
403 }
404
405 #ifdef X_DRI2SwapBuffers
406 DRI2SwapBuffers(pdraw->psc->dpy, pdraw->xDrawable, target_msc, divisor,
407 remainder, &ret);
408 #endif
409
410 return ret;
411 }
412
413 static __DRIbuffer *
414 dri2GetBuffers(__DRIdrawable * driDrawable,
415 int *width, int *height,
416 unsigned int *attachments, int count,
417 int *out_count, void *loaderPrivate)
418 {
419 __GLXDRIdrawablePrivate *pdraw = loaderPrivate;
420 DRI2Buffer *buffers;
421
422 buffers = DRI2GetBuffers(pdraw->base.psc->dpy, pdraw->base.xDrawable,
423 width, height, attachments, count, out_count);
424 if (buffers == NULL)
425 return NULL;
426
427 pdraw->width = *width;
428 pdraw->height = *height;
429 process_buffers(pdraw, buffers, *out_count);
430
431 Xfree(buffers);
432
433 return pdraw->buffers;
434 }
435
436 static __DRIbuffer *
437 dri2GetBuffersWithFormat(__DRIdrawable * driDrawable,
438 int *width, int *height,
439 unsigned int *attachments, int count,
440 int *out_count, void *loaderPrivate)
441 {
442 __GLXDRIdrawablePrivate *pdraw = loaderPrivate;
443 DRI2Buffer *buffers;
444
445 buffers = DRI2GetBuffersWithFormat(pdraw->base.psc->dpy,
446 pdraw->base.xDrawable,
447 width, height, attachments,
448 count, out_count);
449 if (buffers == NULL)
450 return NULL;
451
452 pdraw->width = *width;
453 pdraw->height = *height;
454 process_buffers(pdraw, buffers, *out_count);
455
456 Xfree(buffers);
457
458 return pdraw->buffers;
459 }
460
461 #ifdef X_DRI2SwapInterval
462
463 static void
464 dri2SetSwapInterval(__GLXDRIdrawable *pdraw, int interval)
465 {
466 __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
467
468 DRI2SwapInterval(priv->base.psc->dpy, pdraw->xDrawable, interval);
469 priv->swap_interval = interval;
470 }
471
472 static unsigned int
473 dri2GetSwapInterval(__GLXDRIdrawable *pdraw)
474 {
475 __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
476
477 return priv->swap_interval;
478 }
479
480 #endif /* X_DRI2SwapInterval */
481
482 static const __DRIdri2LoaderExtension dri2LoaderExtension = {
483 {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION},
484 dri2GetBuffers,
485 dri2FlushFrontBuffer,
486 dri2GetBuffersWithFormat,
487 };
488
489 static const __DRIdri2LoaderExtension dri2LoaderExtension_old = {
490 {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION},
491 dri2GetBuffers,
492 dri2FlushFrontBuffer,
493 NULL,
494 };
495
496 static const __DRIextension *loader_extensions[] = {
497 &dri2LoaderExtension.base,
498 &systemTimeExtension.base,
499 NULL
500 };
501
502 static const __DRIextension *loader_extensions_old[] = {
503 &dri2LoaderExtension_old.base,
504 &systemTimeExtension.base,
505 NULL
506 };
507
508 _X_HIDDEN void
509 dri2InvalidateBuffers(Display *dpy, XID drawable)
510 {
511 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
512
513 #if __DRI2_FLUSH_VERSION >= 3
514 if (pdraw && pdraw->psc->f)
515 pdraw->psc->f->invalidate(pdraw->driDrawable);
516 #endif
517 }
518
519 static __GLXDRIscreen *
520 dri2CreateScreen(__GLXscreenConfigs * psc, int screen,
521 __GLXdisplayPrivate * priv)
522 {
523 const __DRIconfig **driver_configs;
524 const __DRIextension **extensions;
525 const __GLXDRIdisplayPrivate *const pdp = (__GLXDRIdisplayPrivate *)
526 priv->dri2Display;
527 __GLXDRIscreen *psp;
528 char *driverName, *deviceName;
529 drm_magic_t magic;
530 int i;
531
532 psp = Xmalloc(sizeof *psp);
533 if (psp == NULL)
534 return NULL;
535
536 if (!DRI2Connect(psc->dpy, RootWindow(psc->dpy, screen),
537 &driverName, &deviceName)) {
538 XFree(psp);
539 return NULL;
540 }
541
542 psc->driver = driOpenDriver(driverName);
543 if (psc->driver == NULL) {
544 ErrorMessageF("driver pointer missing\n");
545 goto handle_error;
546 }
547
548 extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS);
549 if (extensions == NULL) {
550 ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
551 goto handle_error;
552 }
553
554 for (i = 0; extensions[i]; i++) {
555 if (strcmp(extensions[i]->name, __DRI_CORE) == 0)
556 psc->core = (__DRIcoreExtension *) extensions[i];
557 if (strcmp(extensions[i]->name, __DRI_DRI2) == 0)
558 psc->dri2 = (__DRIdri2Extension *) extensions[i];
559 }
560
561 if (psc->core == NULL || psc->dri2 == NULL) {
562 ErrorMessageF("core dri or dri2 extension not found\n");
563 goto handle_error;
564 }
565
566 psc->fd = open(deviceName, O_RDWR);
567 if (psc->fd < 0) {
568 ErrorMessageF("failed to open drm device: %s\n", strerror(errno));
569 goto handle_error;
570 }
571
572 if (drmGetMagic(psc->fd, &magic)) {
573 ErrorMessageF("failed to get magic\n");
574 goto handle_error;
575 }
576
577 if (!DRI2Authenticate(psc->dpy, RootWindow(psc->dpy, screen), magic)) {
578 ErrorMessageF("failed to authenticate magic %d\n", magic);
579 goto handle_error;
580 }
581
582 /* If the server does not support the protocol for
583 * DRI2GetBuffersWithFormat, don't supply that interface to the driver.
584 */
585 psc->__driScreen =
586 psc->dri2->createNewScreen(screen, psc->fd, ((pdp->driMinor < 1)
587 ? loader_extensions_old
588 : loader_extensions),
589 &driver_configs, psc);
590
591 if (psc->__driScreen == NULL) {
592 ErrorMessageF("failed to create dri screen\n");
593 goto handle_error;
594 }
595
596 driBindCommonExtensions(psc);
597 dri2BindExtensions(psc);
598
599 psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs);
600 psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs);
601
602 psc->driver_configs = driver_configs;
603
604 psp->destroyScreen = dri2DestroyScreen;
605 psp->createContext = dri2CreateContext;
606 psp->createDrawable = dri2CreateDrawable;
607 psp->swapBuffers = dri2SwapBuffers;
608 psp->waitGL = dri2WaitGL;
609 psp->waitX = dri2WaitX;
610 psp->getDrawableMSC = NULL;
611 psp->waitForMSC = NULL;
612 psp->waitForSBC = NULL;
613 psp->setSwapInterval = NULL;
614 psp->getSwapInterval = NULL;
615
616 if (pdp->driMinor >= 2) {
617 #ifdef X_DRI2GetMSC
618 psp->getDrawableMSC = dri2DrawableGetMSC;
619 #endif
620 #ifdef X_DRI2WaitMSC
621 psp->waitForMSC = dri2WaitForMSC;
622 psp->waitForSBC = dri2WaitForSBC;
623 #endif
624 #ifdef X_DRI2SwapInterval
625 psp->setSwapInterval = dri2SetSwapInterval;
626 psp->getSwapInterval = dri2GetSwapInterval;
627 #endif
628 #if defined(X_DRI2GetMSC) && defined(X_DRI2WaitMSC) && defined(X_DRI2SwapInterval)
629 __glXEnableDirectExtension(psc, "GLX_OML_sync_control");
630 #endif
631 }
632
633 /* DRI2 suports SubBuffer through DRI2CopyRegion, so it's always
634 * available.*/
635 psp->copySubBuffer = dri2CopySubBuffer;
636 __glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer");
637
638 Xfree(driverName);
639 Xfree(deviceName);
640
641 return psp;
642
643 handle_error:
644 Xfree(driverName);
645 Xfree(deviceName);
646 XFree(psp);
647
648 /* FIXME: clean up here */
649
650 return NULL;
651 }
652
653 /* Called from __glXFreeDisplayPrivate.
654 */
655 static void
656 dri2DestroyDisplay(__GLXDRIdisplay * dpy)
657 {
658 Xfree(dpy);
659 }
660
661 /*
662 * Allocate, initialize and return a __DRIdisplayPrivate object.
663 * This is called from __glXInitialize() when we are given a new
664 * display pointer.
665 */
666 _X_HIDDEN __GLXDRIdisplay *
667 dri2CreateDisplay(Display * dpy)
668 {
669 __GLXDRIdisplayPrivate *pdp;
670 int eventBase, errorBase;
671
672 if (!DRI2QueryExtension(dpy, &eventBase, &errorBase))
673 return NULL;
674
675 pdp = Xmalloc(sizeof *pdp);
676 if (pdp == NULL)
677 return NULL;
678
679 if (!DRI2QueryVersion(dpy, &pdp->driMajor, &pdp->driMinor)) {
680 Xfree(pdp);
681 return NULL;
682 }
683
684 pdp->driPatch = 0;
685 pdp->swapAvailable = (pdp->driMinor >= 2);
686 pdp->invalidateAvailable = (pdp->driMinor >= 3);
687
688 pdp->base.destroyDisplay = dri2DestroyDisplay;
689 pdp->base.createScreen = dri2CreateScreen;
690
691 return &pdp->base;
692 }
693
694 #endif /* GLX_DIRECT_RENDERING */