80ddf9cf753c6ae57ae051fab4fc268a7eb88e06
[mesa.git] / src / glx / drisw_glx.c
1 /*
2 * Copyright 2008 George Sapountzis
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
25
26 #include <X11/Xlib.h>
27 #include "glxclient.h"
28 #include <dlfcn.h>
29 #include "dri_common.h"
30
31 struct drisw_display
32 {
33 __GLXDRIdisplay base;
34 };
35
36 struct drisw_context
37 {
38 struct glx_context base;
39 __DRIcontext *driContext;
40
41 };
42
43 struct drisw_screen
44 {
45 struct glx_screen base;
46
47 __DRIscreen *driScreen;
48 __GLXDRIscreen vtable;
49 const __DRIcoreExtension *core;
50 const __DRIswrastExtension *swrast;
51 const __DRItexBufferExtension *texBuffer;
52
53 const __DRIconfig **driver_configs;
54
55 void *driver;
56 };
57
58 struct drisw_drawable
59 {
60 __GLXDRIdrawable base;
61
62 GC gc;
63 GC swapgc;
64
65 __DRIdrawable *driDrawable;
66 XVisualInfo *visinfo;
67 XImage *ximage;
68 };
69
70 static Bool
71 XCreateDrawable(struct drisw_drawable * pdp,
72 Display * dpy, XID drawable, int visualid)
73 {
74 XGCValues gcvalues;
75 long visMask;
76 XVisualInfo visTemp;
77 int num_visuals;
78
79 /* create GC's */
80 pdp->gc = XCreateGC(dpy, drawable, 0, NULL);
81 pdp->swapgc = XCreateGC(dpy, drawable, 0, NULL);
82
83 gcvalues.function = GXcopy;
84 gcvalues.graphics_exposures = False;
85 XChangeGC(dpy, pdp->gc, GCFunction, &gcvalues);
86 XChangeGC(dpy, pdp->swapgc, GCFunction, &gcvalues);
87 XChangeGC(dpy, pdp->swapgc, GCGraphicsExposures, &gcvalues);
88
89 /* visual */
90 visTemp.visualid = visualid;
91 visMask = VisualIDMask;
92 pdp->visinfo = XGetVisualInfo(dpy, visMask, &visTemp, &num_visuals);
93
94 if (!pdp->visinfo || num_visuals == 0)
95 return False;
96
97 /* create XImage */
98 pdp->ximage = XCreateImage(dpy,
99 pdp->visinfo->visual,
100 pdp->visinfo->depth,
101 ZPixmap, 0, /* format, offset */
102 NULL, /* data */
103 0, 0, /* width, height */
104 32, /* bitmap_pad */
105 0); /* bytes_per_line */
106
107 /**
108 * swrast does not handle 24-bit depth with 24 bpp, so let X do the
109 * the conversion for us.
110 */
111 if (pdp->ximage->bits_per_pixel == 24)
112 pdp->ximage->bits_per_pixel = 32;
113
114 return True;
115 }
116
117 static void
118 XDestroyDrawable(struct drisw_drawable * pdp, Display * dpy, XID drawable)
119 {
120 XDestroyImage(pdp->ximage);
121 free(pdp->visinfo);
122
123 XFreeGC(dpy, pdp->gc);
124 XFreeGC(dpy, pdp->swapgc);
125 }
126
127 /**
128 * swrast loader functions
129 */
130
131 static void
132 swrastGetDrawableInfo(__DRIdrawable * draw,
133 int *x, int *y, int *w, int *h,
134 void *loaderPrivate)
135 {
136 struct drisw_drawable *pdp = loaderPrivate;
137 __GLXDRIdrawable *pdraw = &(pdp->base);
138 Display *dpy = pdraw->psc->dpy;
139 Drawable drawable;
140
141 Window root;
142 unsigned uw, uh, bw, depth;
143
144 drawable = pdraw->xDrawable;
145
146 XGetGeometry(dpy, drawable, &root, x, y, &uw, &uh, &bw, &depth);
147 *w = uw;
148 *h = uh;
149 }
150
151 /**
152 * Align renderbuffer pitch.
153 *
154 * This should be chosen by the driver and the loader (libGL, xserver/glx)
155 * should use the driver provided pitch.
156 *
157 * It seems that the xorg loader (that is the xserver loading swrast_dri for
158 * indirect rendering, not client-side libGL) requires that the pitch is
159 * exactly the image width padded to 32 bits. XXX
160 *
161 * The above restriction can probably be overcome by using ScratchPixmap and
162 * CopyArea in the xserver, similar to ShmPutImage, and setting the width of
163 * the scratch pixmap to 'pitch / cpp'.
164 */
165 static inline int
166 bytes_per_line(unsigned pitch_bits, unsigned mul)
167 {
168 unsigned mask = mul - 1;
169
170 return ((pitch_bits + mask) & ~mask) / 8;
171 }
172
173 static void
174 swrastPutImage(__DRIdrawable * draw, int op,
175 int x, int y, int w, int h,
176 char *data, void *loaderPrivate)
177 {
178 struct drisw_drawable *pdp = loaderPrivate;
179 __GLXDRIdrawable *pdraw = &(pdp->base);
180 Display *dpy = pdraw->psc->dpy;
181 Drawable drawable;
182 XImage *ximage;
183 GC gc;
184
185 switch (op) {
186 case __DRI_SWRAST_IMAGE_OP_DRAW:
187 gc = pdp->gc;
188 break;
189 case __DRI_SWRAST_IMAGE_OP_SWAP:
190 gc = pdp->swapgc;
191 break;
192 default:
193 return;
194 }
195
196 drawable = pdraw->xDrawable;
197
198 ximage = pdp->ximage;
199 ximage->data = data;
200 ximage->width = w;
201 ximage->height = h;
202 ximage->bytes_per_line = bytes_per_line(w * ximage->bits_per_pixel, 32);
203
204 XPutImage(dpy, drawable, gc, ximage, 0, 0, x, y, w, h);
205
206 ximage->data = NULL;
207 }
208
209 static void
210 swrastGetImage(__DRIdrawable * read,
211 int x, int y, int w, int h,
212 char *data, void *loaderPrivate)
213 {
214 struct drisw_drawable *prp = loaderPrivate;
215 __GLXDRIdrawable *pread = &(prp->base);
216 Display *dpy = pread->psc->dpy;
217 Drawable readable;
218 XImage *ximage;
219
220 readable = pread->xDrawable;
221
222 ximage = prp->ximage;
223 ximage->data = data;
224 ximage->width = w;
225 ximage->height = h;
226 ximage->bytes_per_line = bytes_per_line(w * ximage->bits_per_pixel, 32);
227
228 XGetSubImage(dpy, readable, x, y, w, h, ~0L, ZPixmap, ximage, 0, 0);
229
230 ximage->data = NULL;
231 }
232
233 static const __DRIswrastLoaderExtension swrastLoaderExtension = {
234 {__DRI_SWRAST_LOADER, __DRI_SWRAST_LOADER_VERSION},
235 swrastGetDrawableInfo,
236 swrastPutImage,
237 swrastGetImage
238 };
239
240 static const __DRIextension *loader_extensions[] = {
241 &systemTimeExtension.base,
242 &swrastLoaderExtension.base,
243 NULL
244 };
245
246 /**
247 * GLXDRI functions
248 */
249
250 static void
251 drisw_destroy_context(struct glx_context *context)
252 {
253 struct drisw_context *pcp = (struct drisw_context *) context;
254 struct drisw_screen *psc = (struct drisw_screen *) context->psc;
255
256 driReleaseDrawables(&pcp->base);
257
258 free((char *) context->extensions);
259
260 (*psc->core->destroyContext) (pcp->driContext);
261
262 free(pcp);
263 }
264
265 static int
266 drisw_bind_context(struct glx_context *context, struct glx_context *old,
267 GLXDrawable draw, GLXDrawable read)
268 {
269 struct drisw_context *pcp = (struct drisw_context *) context;
270 struct drisw_screen *psc = (struct drisw_screen *) pcp->base.psc;
271 struct drisw_drawable *pdraw, *pread;
272
273 pdraw = (struct drisw_drawable *) driFetchDrawable(context, draw);
274 pread = (struct drisw_drawable *) driFetchDrawable(context, read);
275
276 driReleaseDrawables(&pcp->base);
277
278 if (pdraw == NULL || pread == NULL)
279 return GLXBadDrawable;
280
281 if ((*psc->core->bindContext) (pcp->driContext,
282 pdraw->driDrawable, pread->driDrawable))
283 return Success;
284
285 return GLXBadContext;
286 }
287
288 static void
289 drisw_unbind_context(struct glx_context *context, struct glx_context *new)
290 {
291 struct drisw_context *pcp = (struct drisw_context *) context;
292 struct drisw_screen *psc = (struct drisw_screen *) pcp->base.psc;
293
294 (*psc->core->unbindContext) (pcp->driContext);
295 }
296
297 static void
298 drisw_bind_tex_image(Display * dpy,
299 GLXDrawable drawable,
300 int buffer, const int *attrib_list)
301 {
302 struct glx_context *gc = __glXGetCurrentContext();
303 struct drisw_context *pcp = (struct drisw_context *) gc;
304 __GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable);
305 struct drisw_drawable *pdraw = (struct drisw_drawable *) base;
306 struct drisw_screen *psc;
307
308 __glXInitialize(dpy);
309
310 if (pdraw != NULL) {
311 psc = (struct drisw_screen *) base->psc;
312
313 if (!psc->texBuffer)
314 return;
315
316 if (psc->texBuffer->base.version >= 2 &&
317 psc->texBuffer->setTexBuffer2 != NULL) {
318 (*psc->texBuffer->setTexBuffer2) (pcp->driContext,
319 pdraw->base.textureTarget,
320 pdraw->base.textureFormat,
321 pdraw->driDrawable);
322 }
323 else {
324 (*psc->texBuffer->setTexBuffer) (pcp->driContext,
325 pdraw->base.textureTarget,
326 pdraw->driDrawable);
327 }
328 }
329 }
330
331 static void
332 drisw_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer)
333 {
334 #if __DRI_TEX_BUFFER_VERSION >= 3
335 struct glx_context *gc = __glXGetCurrentContext();
336 struct dri2_context *pcp = (struct dri2_context *) gc;
337 __GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable);
338 struct glx_display *dpyPriv = __glXInitialize(dpy);
339 struct dri2_drawable *pdraw = (struct dri2_drawable *) base;
340 struct dri2_screen *psc;
341
342 if (pdraw != NULL) {
343 psc = (struct dri2_screen *) base->psc;
344
345 if (!psc->texBuffer)
346 return;
347
348 if (psc->texBuffer->base.version >= 3 &&
349 psc->texBuffer->releaseTexBuffer != NULL) {
350 (*psc->texBuffer->releaseTexBuffer) (pcp->driContext,
351 pdraw->base.textureTarget,
352 pdraw->driDrawable);
353 }
354 }
355 #endif
356 }
357
358 static const struct glx_context_vtable drisw_context_vtable = {
359 drisw_destroy_context,
360 drisw_bind_context,
361 drisw_unbind_context,
362 NULL,
363 NULL,
364 DRI_glXUseXFont,
365 drisw_bind_tex_image,
366 drisw_release_tex_image,
367 NULL, /* get_proc_address */
368 };
369
370 static struct glx_context *
371 drisw_create_context(struct glx_screen *base,
372 struct glx_config *config_base,
373 struct glx_context *shareList, int renderType)
374 {
375 struct drisw_context *pcp, *pcp_shared;
376 __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
377 struct drisw_screen *psc = (struct drisw_screen *) base;
378 __DRIcontext *shared = NULL;
379
380 if (!psc->base.driScreen)
381 return NULL;
382
383 if (shareList) {
384 /* If the shareList context is not a DRISW context, we cannot possibly
385 * create a DRISW context that shares it.
386 */
387 if (shareList->vtable->destroy != drisw_destroy_context) {
388 return NULL;
389 }
390
391 pcp_shared = (struct drisw_context *) shareList;
392 shared = pcp_shared->driContext;
393 }
394
395 pcp = calloc(1, sizeof *pcp);
396 if (pcp == NULL)
397 return NULL;
398
399 if (!glx_context_init(&pcp->base, &psc->base, &config->base)) {
400 free(pcp);
401 return NULL;
402 }
403
404 pcp->base.renderType = renderType;
405
406 pcp->driContext =
407 (*psc->core->createNewContext) (psc->driScreen,
408 config->driConfig, shared, pcp);
409 if (pcp->driContext == NULL) {
410 free(pcp);
411 return NULL;
412 }
413
414 pcp->base.vtable = &drisw_context_vtable;
415
416 return &pcp->base;
417 }
418
419 static struct glx_context *
420 drisw_create_context_attribs(struct glx_screen *base,
421 struct glx_config *config_base,
422 struct glx_context *shareList,
423 unsigned num_attribs,
424 const uint32_t *attribs,
425 unsigned *error)
426 {
427 struct drisw_context *pcp, *pcp_shared;
428 __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
429 struct drisw_screen *psc = (struct drisw_screen *) base;
430 __DRIcontext *shared = NULL;
431
432 uint32_t minor_ver = 1;
433 uint32_t major_ver = 0;
434 uint32_t renderType = GLX_RGBA_TYPE;
435 uint32_t flags = 0;
436 unsigned api;
437 int reset = __DRI_CTX_RESET_NO_NOTIFICATION;
438 uint32_t ctx_attribs[2 * 4];
439 unsigned num_ctx_attribs = 0;
440
441 if (!psc->base.driScreen)
442 return NULL;
443
444 if (psc->swrast->base.version < 3)
445 return NULL;
446
447 /* Remap the GLX tokens to DRI2 tokens.
448 */
449 if (!dri2_convert_glx_attribs(num_attribs, attribs,
450 &major_ver, &minor_ver, &flags, &api, &reset,
451 error))
452 return NULL;
453
454 if (reset != __DRI_CTX_RESET_NO_NOTIFICATION)
455 return NULL;
456
457 if (shareList) {
458 pcp_shared = (struct drisw_context *) shareList;
459 shared = pcp_shared->driContext;
460 }
461
462 pcp = calloc(1, sizeof *pcp);
463 if (pcp == NULL)
464 return NULL;
465
466 if (!glx_context_init(&pcp->base, &psc->base, &config->base)) {
467 free(pcp);
468 return NULL;
469 }
470
471 ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
472 ctx_attribs[num_ctx_attribs++] = major_ver;
473 ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MINOR_VERSION;
474 ctx_attribs[num_ctx_attribs++] = minor_ver;
475
476 if (flags != 0) {
477 ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_FLAGS;
478
479 /* The current __DRI_CTX_FLAG_* values are identical to the
480 * GLX_CONTEXT_*_BIT values.
481 */
482 ctx_attribs[num_ctx_attribs++] = flags;
483 }
484
485 pcp->base.renderType = renderType;
486
487 pcp->driContext =
488 (*psc->swrast->createContextAttribs) (psc->driScreen,
489 api,
490 config->driConfig,
491 shared,
492 num_ctx_attribs / 2,
493 ctx_attribs,
494 error,
495 pcp);
496 if (pcp->driContext == NULL) {
497 free(pcp);
498 return NULL;
499 }
500
501 pcp->base.vtable = &drisw_context_vtable;
502
503 return &pcp->base;
504 }
505
506 static void
507 driswDestroyDrawable(__GLXDRIdrawable * pdraw)
508 {
509 struct drisw_drawable *pdp = (struct drisw_drawable *) pdraw;
510 struct drisw_screen *psc = (struct drisw_screen *) pdp->base.psc;
511
512 (*psc->core->destroyDrawable) (pdp->driDrawable);
513
514 XDestroyDrawable(pdp, pdraw->psc->dpy, pdraw->drawable);
515 free(pdp);
516 }
517
518 static __GLXDRIdrawable *
519 driswCreateDrawable(struct glx_screen *base, XID xDrawable,
520 GLXDrawable drawable, struct glx_config *modes)
521 {
522 struct drisw_drawable *pdp;
523 __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes;
524 struct drisw_screen *psc = (struct drisw_screen *) base;
525 Bool ret;
526 const __DRIswrastExtension *swrast = psc->swrast;
527
528 pdp = calloc(1, sizeof(*pdp));
529 if (!pdp)
530 return NULL;
531
532 pdp->base.xDrawable = xDrawable;
533 pdp->base.drawable = drawable;
534 pdp->base.psc = &psc->base;
535
536 ret = XCreateDrawable(pdp, psc->base.dpy, xDrawable, modes->visualID);
537 if (!ret) {
538 free(pdp);
539 return NULL;
540 }
541
542 /* Create a new drawable */
543 pdp->driDrawable =
544 (*swrast->createNewDrawable) (psc->driScreen, config->driConfig, pdp);
545
546 if (!pdp->driDrawable) {
547 XDestroyDrawable(pdp, psc->base.dpy, xDrawable);
548 free(pdp);
549 return NULL;
550 }
551
552 pdp->base.destroyDrawable = driswDestroyDrawable;
553
554 return &pdp->base;
555 }
556
557 static int64_t
558 driswSwapBuffers(__GLXDRIdrawable * pdraw,
559 int64_t target_msc, int64_t divisor, int64_t remainder,
560 Bool flush)
561 {
562 struct drisw_drawable *pdp = (struct drisw_drawable *) pdraw;
563 struct drisw_screen *psc = (struct drisw_screen *) pdp->base.psc;
564
565 (void) target_msc;
566 (void) divisor;
567 (void) remainder;
568
569 if (flush) {
570 glFlush();
571 }
572
573 (*psc->core->swapBuffers) (pdp->driDrawable);
574
575 return 0;
576 }
577
578 static void
579 driswDestroyScreen(struct glx_screen *base)
580 {
581 struct drisw_screen *psc = (struct drisw_screen *) base;
582
583 /* Free the direct rendering per screen data */
584 (*psc->core->destroyScreen) (psc->driScreen);
585 driDestroyConfigs(psc->driver_configs);
586 psc->driScreen = NULL;
587 if (psc->driver)
588 dlclose(psc->driver);
589 }
590
591 #define SWRAST_DRIVER_NAME "swrast"
592
593 static void *
594 driOpenSwrast(void)
595 {
596 void *driver = NULL;
597
598 if (driver == NULL)
599 driver = driOpenDriver(SWRAST_DRIVER_NAME);
600
601 return driver;
602 }
603
604 static const struct glx_screen_vtable drisw_screen_vtable = {
605 drisw_create_context,
606 drisw_create_context_attribs
607 };
608
609 static void
610 driswBindExtensions(struct drisw_screen *psc, const __DRIextension **extensions)
611 {
612 int i;
613
614 __glXEnableDirectExtension(&psc->base, "GLX_SGI_make_current_read");
615
616 if (psc->swrast->base.version >= 3) {
617 __glXEnableDirectExtension(&psc->base, "GLX_ARB_create_context");
618 __glXEnableDirectExtension(&psc->base, "GLX_ARB_create_context_profile");
619
620 /* DRISW version >= 2 implies support for OpenGL ES 2.0.
621 */
622 __glXEnableDirectExtension(&psc->base,
623 "GLX_EXT_create_context_es2_profile");
624 }
625
626 /* FIXME: Figure out what other extensions can be ported here from dri2. */
627 for (i = 0; extensions[i]; i++) {
628 if ((strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0)) {
629 psc->texBuffer = (__DRItexBufferExtension *) extensions[i];
630 __glXEnableDirectExtension(&psc->base, "GLX_EXT_texture_from_pixmap");
631 }
632 }
633 }
634
635 static struct glx_screen *
636 driswCreateScreen(int screen, struct glx_display *priv)
637 {
638 __GLXDRIscreen *psp;
639 const __DRIconfig **driver_configs;
640 const __DRIextension **extensions;
641 struct drisw_screen *psc;
642 struct glx_config *configs = NULL, *visuals = NULL;
643 int i;
644
645 psc = calloc(1, sizeof *psc);
646 if (psc == NULL)
647 return NULL;
648
649 if (!glx_screen_init(&psc->base, screen, priv)) {
650 free(psc);
651 return NULL;
652 }
653
654 psc->driver = driOpenSwrast();
655 if (psc->driver == NULL)
656 goto handle_error;
657
658 extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS);
659 if (extensions == NULL) {
660 ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
661 goto handle_error;
662 }
663
664 for (i = 0; extensions[i]; i++) {
665 if (strcmp(extensions[i]->name, __DRI_CORE) == 0)
666 psc->core = (__DRIcoreExtension *) extensions[i];
667 if (strcmp(extensions[i]->name, __DRI_SWRAST) == 0)
668 psc->swrast = (__DRIswrastExtension *) extensions[i];
669 }
670
671 if (psc->core == NULL || psc->swrast == NULL) {
672 ErrorMessageF("core dri extension not found\n");
673 goto handle_error;
674 }
675
676 psc->driScreen =
677 psc->swrast->createNewScreen(screen, loader_extensions,
678 &driver_configs, psc);
679 if (psc->driScreen == NULL) {
680 ErrorMessageF("failed to create dri screen\n");
681 goto handle_error;
682 }
683
684 extensions = psc->core->getExtensions(psc->driScreen);
685 driswBindExtensions(psc, extensions);
686
687 configs = driConvertConfigs(psc->core, psc->base.configs, driver_configs);
688 visuals = driConvertConfigs(psc->core, psc->base.visuals, driver_configs);
689
690 if (!configs || !visuals)
691 goto handle_error;
692
693 glx_config_destroy_list(psc->base.configs);
694 psc->base.configs = configs;
695 glx_config_destroy_list(psc->base.visuals);
696 psc->base.visuals = visuals;
697
698 psc->driver_configs = driver_configs;
699
700 psc->base.vtable = &drisw_screen_vtable;
701 psp = &psc->vtable;
702 psc->base.driScreen = psp;
703 psp->destroyScreen = driswDestroyScreen;
704 psp->createDrawable = driswCreateDrawable;
705 psp->swapBuffers = driswSwapBuffers;
706
707 return &psc->base;
708
709 handle_error:
710 if (configs)
711 glx_config_destroy_list(configs);
712 if (visuals)
713 glx_config_destroy_list(visuals);
714 if (psc->driScreen)
715 psc->core->destroyScreen(psc->driScreen);
716 psc->driScreen = NULL;
717
718 if (psc->driver)
719 dlclose(psc->driver);
720 glx_screen_cleanup(&psc->base);
721 free(psc);
722
723 CriticalErrorMessageF("failed to load driver: %s\n", SWRAST_DRIVER_NAME);
724
725 return NULL;
726 }
727
728 /* Called from __glXFreeDisplayPrivate.
729 */
730 static void
731 driswDestroyDisplay(__GLXDRIdisplay * dpy)
732 {
733 free(dpy);
734 }
735
736 /*
737 * Allocate, initialize and return a __DRIdisplayPrivate object.
738 * This is called from __glXInitialize() when we are given a new
739 * display pointer.
740 */
741 _X_HIDDEN __GLXDRIdisplay *
742 driswCreateDisplay(Display * dpy)
743 {
744 struct drisw_display *pdpyp;
745
746 pdpyp = malloc(sizeof *pdpyp);
747 if (pdpyp == NULL)
748 return NULL;
749
750 pdpyp->base.destroyDisplay = driswDestroyDisplay;
751 pdpyp->base.createScreen = driswCreateScreen;
752
753 return &pdpyp->base;
754 }
755
756 #endif /* GLX_DIRECT_RENDERING */