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