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