DRI2: expose OML_sync_control if possible
[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
189 DRI2CreateDrawable(psc->dpy, xDrawable);
190
191 /* Create a new drawable */
192 pdraw->base.driDrawable =
193 (*psc->dri2->createNewDrawable) (psc->__driScreen,
194 config->driConfig, pdraw);
195
196 if (!pdraw->base.driDrawable) {
197 DRI2DestroyDrawable(psc->dpy, xDrawable);
198 Xfree(pdraw);
199 return NULL;
200 }
201
202 return &pdraw->base;
203 }
204
205 static int
206 dri2DrawableGetMSC(__GLXscreenConfigs *psc, __GLXDRIdrawable *pdraw,
207 int64_t *ust, int64_t *msc, int64_t *sbc)
208 {
209 return DRI2GetMSC(psc->dpy, pdraw->xDrawable, ust, msc, sbc);
210 }
211
212 static int
213 dri2WaitForMSC(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
214 int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc)
215 {
216 return DRI2WaitMSC(pdraw->psc->dpy, pdraw->xDrawable, target_msc, divisor,
217 remainder, ust, msc, sbc);
218 }
219
220 static int
221 dri2WaitForSBC(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust,
222 int64_t *msc, int64_t *sbc)
223 {
224 return DRI2WaitSBC(pdraw->psc->dpy, pdraw->xDrawable, target_sbc, ust, msc,
225 sbc);
226 }
227
228 static void
229 dri2CopySubBuffer(__GLXDRIdrawable *pdraw, int x, int y, int width, int height)
230 {
231 __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
232 XRectangle xrect;
233 XserverRegion region;
234
235 /* Check we have the right attachments */
236 if (!priv->have_back)
237 return;
238
239 xrect.x = x;
240 xrect.y = priv->height - y - height;
241 xrect.width = width;
242 xrect.height = height;
243
244 #ifdef __DRI2_FLUSH
245 if (pdraw->psc->f)
246 (*pdraw->psc->f->flush) (pdraw->driDrawable);
247 #endif
248
249 region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1);
250 /* should get a fence ID back from here at some point */
251 DRI2CopyRegion(pdraw->psc->dpy, pdraw->xDrawable, region,
252 DRI2BufferFrontLeft, DRI2BufferBackLeft);
253 XFixesDestroyRegion(pdraw->psc->dpy, region);
254
255 /* Refresh the fake front (if present) after we just damaged the real
256 * front.
257 */
258 dri2WaitX(pdraw);
259 }
260
261 static void
262 dri2WaitX(__GLXDRIdrawable *pdraw)
263 {
264 __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
265 XRectangle xrect;
266 XserverRegion region;
267
268 /* Check we have the right attachments */
269 if (!priv->have_fake_front)
270 return;
271
272 xrect.x = 0;
273 xrect.y = 0;
274 xrect.width = priv->width;
275 xrect.height = priv->height;
276
277 #ifdef __DRI2_FLUSH
278 if (pdraw->psc->f)
279 (*pdraw->psc->f->flush) (pdraw->driDrawable);
280 #endif
281
282 region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1);
283 DRI2CopyRegion(pdraw->psc->dpy, pdraw->xDrawable, region,
284 DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft);
285 XFixesDestroyRegion(pdraw->psc->dpy, region);
286 }
287
288 static void
289 dri2WaitGL(__GLXDRIdrawable * pdraw)
290 {
291 __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
292 XRectangle xrect;
293 XserverRegion region;
294
295 if (!priv->have_fake_front)
296 return;
297
298 xrect.x = 0;
299 xrect.y = 0;
300 xrect.width = priv->width;
301 xrect.height = priv->height;
302
303 #ifdef __DRI2_FLUSH
304 if (pdraw->psc->f)
305 (*pdraw->psc->f->flush) (pdraw->driDrawable);
306 #endif
307
308 region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1);
309 DRI2CopyRegion(pdraw->psc->dpy, pdraw->xDrawable, region,
310 DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
311 XFixesDestroyRegion(pdraw->psc->dpy, region);
312 }
313
314 static void
315 dri2FlushFrontBuffer(__DRIdrawable *driDrawable, void *loaderPrivate)
316 {
317 __GLXDRIdrawablePrivate *pdraw = loaderPrivate;
318 __GLXdisplayPrivate *priv = __glXInitialize(pdraw->base.psc->dpy);
319 __GLXDRIdisplayPrivate *pdp = (__GLXDRIdisplayPrivate *)priv->dri2Display;
320
321 /* Old servers don't send invalidate events */
322 if (!pdp->invalidateAvailable)
323 dri2InvalidateBuffers(priv->dpy, pdraw->base.xDrawable);
324
325 dri2WaitGL(loaderPrivate);
326 }
327
328
329 static void
330 dri2DestroyScreen(__GLXscreenConfigs * psc)
331 {
332 /* Free the direct rendering per screen data */
333 (*psc->core->destroyScreen) (psc->__driScreen);
334 close(psc->fd);
335 psc->__driScreen = NULL;
336 }
337
338 /**
339 * Process list of buffer received from the server
340 *
341 * Processes the list of buffers received in a reply from the server to either
342 * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat.
343 */
344 static void
345 process_buffers(__GLXDRIdrawablePrivate * pdraw, DRI2Buffer * buffers,
346 unsigned count)
347 {
348 int i;
349
350 pdraw->bufferCount = count;
351 pdraw->have_fake_front = 0;
352 pdraw->have_back = 0;
353
354 /* This assumes the DRI2 buffer attachment tokens matches the
355 * __DRIbuffer tokens. */
356 for (i = 0; i < count; i++) {
357 pdraw->buffers[i].attachment = buffers[i].attachment;
358 pdraw->buffers[i].name = buffers[i].name;
359 pdraw->buffers[i].pitch = buffers[i].pitch;
360 pdraw->buffers[i].cpp = buffers[i].cpp;
361 pdraw->buffers[i].flags = buffers[i].flags;
362 if (pdraw->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT)
363 pdraw->have_fake_front = 1;
364 if (pdraw->buffers[i].attachment == __DRI_BUFFER_BACK_LEFT)
365 pdraw->have_back = 1;
366 }
367
368 }
369
370 static int64_t
371 dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
372 int64_t remainder)
373 {
374 __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
375 __GLXdisplayPrivate *dpyPriv = __glXInitialize(priv->base.psc->dpy);
376 __GLXDRIdisplayPrivate *pdp =
377 (__GLXDRIdisplayPrivate *)dpyPriv->dri2Display;
378 int64_t ret;
379
380 #ifdef __DRI2_FLUSH
381 if (pdraw->psc->f)
382 (*pdraw->psc->f->flush)(pdraw->driDrawable);
383 #endif
384
385 /* Old servers don't send invalidate events */
386 if (!pdp->invalidateAvailable)
387 dri2InvalidateBuffers(dpyPriv->dpy, pdraw->xDrawable);
388
389 /* Old servers can't handle swapbuffers */
390 if (!pdp->swapAvailable) {
391 dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height);
392 return 0;
393 }
394
395 #ifdef X_DRI2SwapBuffers
396 DRI2SwapBuffers(pdraw->psc->dpy, pdraw->xDrawable, target_msc, divisor,
397 remainder, &ret);
398 #endif
399
400 return ret;
401 }
402
403 static __DRIbuffer *
404 dri2GetBuffers(__DRIdrawable * driDrawable,
405 int *width, int *height,
406 unsigned int *attachments, int count,
407 int *out_count, void *loaderPrivate)
408 {
409 __GLXDRIdrawablePrivate *pdraw = loaderPrivate;
410 DRI2Buffer *buffers;
411
412 buffers = DRI2GetBuffers(pdraw->base.psc->dpy, pdraw->base.xDrawable,
413 width, height, attachments, count, out_count);
414 if (buffers == NULL)
415 return NULL;
416
417 pdraw->width = *width;
418 pdraw->height = *height;
419 process_buffers(pdraw, buffers, *out_count);
420
421 Xfree(buffers);
422
423 return pdraw->buffers;
424 }
425
426 static __DRIbuffer *
427 dri2GetBuffersWithFormat(__DRIdrawable * driDrawable,
428 int *width, int *height,
429 unsigned int *attachments, int count,
430 int *out_count, void *loaderPrivate)
431 {
432 __GLXDRIdrawablePrivate *pdraw = loaderPrivate;
433 DRI2Buffer *buffers;
434
435 buffers = DRI2GetBuffersWithFormat(pdraw->base.psc->dpy,
436 pdraw->base.xDrawable,
437 width, height, attachments,
438 count, out_count);
439 if (buffers == NULL)
440 return NULL;
441
442 pdraw->width = *width;
443 pdraw->height = *height;
444 process_buffers(pdraw, buffers, *out_count);
445
446 Xfree(buffers);
447
448 return pdraw->buffers;
449 }
450
451 static void
452 dri2SetSwapInterval(__GLXDRIdrawable *pdraw, int interval)
453 {
454 __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
455
456 DRI2SwapInterval(priv->base.psc->dpy, pdraw->xDrawable, interval);
457 priv->swap_interval = interval;
458 }
459
460 static unsigned int
461 dri2GetSwapInterval(__GLXDRIdrawable *pdraw)
462 {
463 __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
464
465 return priv->swap_interval;
466 }
467
468 static const __DRIdri2LoaderExtension dri2LoaderExtension = {
469 {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION},
470 dri2GetBuffers,
471 dri2FlushFrontBuffer,
472 dri2GetBuffersWithFormat,
473 };
474
475 static const __DRIdri2LoaderExtension dri2LoaderExtension_old = {
476 {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION},
477 dri2GetBuffers,
478 dri2FlushFrontBuffer,
479 NULL,
480 };
481
482 static const __DRIextension *loader_extensions[] = {
483 &dri2LoaderExtension.base,
484 &systemTimeExtension.base,
485 NULL
486 };
487
488 static const __DRIextension *loader_extensions_old[] = {
489 &dri2LoaderExtension_old.base,
490 &systemTimeExtension.base,
491 NULL
492 };
493
494 _X_HIDDEN void
495 dri2InvalidateBuffers(Display *dpy, XID drawable)
496 {
497 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
498
499 #if __DRI2_FLUSH_VERSION >= 3
500 if (pdraw && pdraw->psc->f)
501 pdraw->psc->f->invalidate(pdraw->driDrawable);
502 #endif
503 }
504
505 static __GLXDRIscreen *
506 dri2CreateScreen(__GLXscreenConfigs * psc, int screen,
507 __GLXdisplayPrivate * priv)
508 {
509 const __DRIconfig **driver_configs;
510 const __DRIextension **extensions;
511 const __GLXDRIdisplayPrivate *const pdp = (__GLXDRIdisplayPrivate *)
512 priv->dri2Display;
513 __GLXDRIscreen *psp;
514 char *driverName, *deviceName;
515 drm_magic_t magic;
516 int i;
517
518 psp = Xmalloc(sizeof *psp);
519 if (psp == NULL)
520 return NULL;
521
522 /* Initialize per screen dynamic client GLX extensions */
523 psc->ext_list_first_time = GL_TRUE;
524
525 if (!DRI2Connect(psc->dpy, RootWindow(psc->dpy, screen),
526 &driverName, &deviceName)) {
527 XFree(psp);
528 return NULL;
529 }
530
531 psc->driver = driOpenDriver(driverName);
532 if (psc->driver == NULL) {
533 ErrorMessageF("driver pointer missing\n");
534 goto handle_error;
535 }
536
537 extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS);
538 if (extensions == NULL) {
539 ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
540 goto handle_error;
541 }
542
543 for (i = 0; extensions[i]; i++) {
544 if (strcmp(extensions[i]->name, __DRI_CORE) == 0)
545 psc->core = (__DRIcoreExtension *) extensions[i];
546 if (strcmp(extensions[i]->name, __DRI_DRI2) == 0)
547 psc->dri2 = (__DRIdri2Extension *) extensions[i];
548 }
549
550 if (psc->core == NULL || psc->dri2 == NULL) {
551 ErrorMessageF("core dri or dri2 extension not found\n");
552 goto handle_error;
553 }
554
555 psc->fd = open(deviceName, O_RDWR);
556 if (psc->fd < 0) {
557 ErrorMessageF("failed to open drm device: %s\n", strerror(errno));
558 goto handle_error;
559 }
560
561 if (drmGetMagic(psc->fd, &magic)) {
562 ErrorMessageF("failed to get magic\n");
563 goto handle_error;
564 }
565
566 if (!DRI2Authenticate(psc->dpy, RootWindow(psc->dpy, screen), magic)) {
567 ErrorMessageF("failed to authenticate magic %d\n", magic);
568 goto handle_error;
569 }
570
571 /* If the server does not support the protocol for
572 * DRI2GetBuffersWithFormat, don't supply that interface to the driver.
573 */
574 psc->__driScreen =
575 psc->dri2->createNewScreen(screen, psc->fd, ((pdp->driMinor < 1)
576 ? loader_extensions_old
577 : loader_extensions),
578 &driver_configs, psc);
579
580 if (psc->__driScreen == NULL) {
581 ErrorMessageF("failed to create dri screen\n");
582 goto handle_error;
583 }
584
585 driBindCommonExtensions(psc);
586 dri2BindExtensions(psc);
587
588 psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs);
589 psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs);
590
591 psc->driver_configs = driver_configs;
592
593 psp->destroyScreen = dri2DestroyScreen;
594 psp->createContext = dri2CreateContext;
595 psp->createDrawable = dri2CreateDrawable;
596 psp->swapBuffers = dri2SwapBuffers;
597 psp->waitGL = dri2WaitGL;
598 psp->waitX = dri2WaitX;
599 psp->getDrawableMSC = NULL;
600 psp->waitForMSC = NULL;
601 psp->waitForSBC = NULL;
602 psp->setSwapInterval = NULL;
603 psp->getSwapInterval = NULL;
604
605 if (pdp->driMinor >= 2) {
606 #ifdef X_DRI2GetMSC
607 psp->getDrawableMSC = dri2DrawableGetMSC;
608 #endif
609 #ifdef X_DRI2WaitMSC
610 psp->waitForMSC = dri2WaitForMSC;
611 psp->waitForSBC = dri2WaitForSBC;
612 #endif
613 #ifdef X_DRI2SwapInterval
614 psp->setSwapInterval = dri2SetSwapInterval;
615 psp->getSwapInterval = dri2GetSwapInterval;
616 #endif
617 #if defined(X_DRI2GetMSC) && defined(X_DRI2WaitMSC) && defined(X_DRI2SwapInterval)
618 __glXEnableDirectExtension(psc, "GLX_OML_sync_control");
619 #endif
620 }
621
622 /* DRI2 suports SubBuffer through DRI2CopyRegion, so it's always
623 * available.*/
624 psp->copySubBuffer = dri2CopySubBuffer;
625 __glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer");
626
627 Xfree(driverName);
628 Xfree(deviceName);
629
630 return psp;
631
632 handle_error:
633 Xfree(driverName);
634 Xfree(deviceName);
635 XFree(psp);
636
637 /* FIXME: clean up here */
638
639 return NULL;
640 }
641
642 /* Called from __glXFreeDisplayPrivate.
643 */
644 static void
645 dri2DestroyDisplay(__GLXDRIdisplay * dpy)
646 {
647 Xfree(dpy);
648 }
649
650 /*
651 * Allocate, initialize and return a __DRIdisplayPrivate object.
652 * This is called from __glXInitialize() when we are given a new
653 * display pointer.
654 */
655 _X_HIDDEN __GLXDRIdisplay *
656 dri2CreateDisplay(Display * dpy)
657 {
658 __GLXDRIdisplayPrivate *pdp;
659 int eventBase, errorBase;
660
661 if (!DRI2QueryExtension(dpy, &eventBase, &errorBase))
662 return NULL;
663
664 pdp = Xmalloc(sizeof *pdp);
665 if (pdp == NULL)
666 return NULL;
667
668 if (!DRI2QueryVersion(dpy, &pdp->driMajor, &pdp->driMinor)) {
669 Xfree(pdp);
670 return NULL;
671 }
672
673 pdp->driPatch = 0;
674 pdp->swapAvailable = (pdp->driMinor >= 2);
675 pdp->invalidateAvailable = (pdp->driMinor >= 3);
676
677 pdp->base.destroyDisplay = dri2DestroyDisplay;
678 pdp->base.createScreen = dri2CreateScreen;
679
680 return &pdp->base;
681 }
682
683 #endif /* GLX_DIRECT_RENDERING */