2 * Copyright 2008 George Sapountzis
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:
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
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
24 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
27 #include "glxclient.h"
29 #include "dri_common.h"
30 #include "drisw_priv.h"
31 #include <X11/extensions/shmproto.h>
35 XCreateGCs(struct drisw_drawable
* pdp
,
36 Display
* dpy
, XID drawable
, int visualid
)
44 pdp
->gc
= XCreateGC(dpy
, drawable
, 0, NULL
);
45 pdp
->swapgc
= XCreateGC(dpy
, drawable
, 0, NULL
);
47 gcvalues
.function
= GXcopy
;
48 gcvalues
.graphics_exposures
= False
;
49 XChangeGC(dpy
, pdp
->gc
, GCFunction
, &gcvalues
);
50 XChangeGC(dpy
, pdp
->swapgc
, GCFunction
, &gcvalues
);
51 XChangeGC(dpy
, pdp
->swapgc
, GCGraphicsExposures
, &gcvalues
);
54 visTemp
.visualid
= visualid
;
55 visMask
= VisualIDMask
;
56 pdp
->visinfo
= XGetVisualInfo(dpy
, visMask
, &visTemp
, &num_visuals
);
58 if (!pdp
->visinfo
|| num_visuals
== 0)
64 static int xshm_error
= 0;
65 static int xshm_opcode
= -1;
68 * Catches potential Xlib errors.
71 handle_xerror(Display
*dpy
, XErrorEvent
*event
)
75 assert(xshm_opcode
!= -1);
76 if (event
->request_code
!= xshm_opcode
||
77 event
->minor_code
!= X_ShmAttach
)
85 XCreateDrawable(struct drisw_drawable
* pdp
, int shmid
, Display
* dpy
)
88 XDestroyImage(pdp
->ximage
);
92 if (!xshm_error
&& shmid
>= 0) {
93 pdp
->shminfo
.shmid
= shmid
;
94 pdp
->ximage
= XShmCreateImage(dpy
,
99 &pdp
->shminfo
, /* shminfo */
100 0, 0); /* width, height */
101 if (pdp
->ximage
!= NULL
) {
102 int (*old_handler
)(Display
*, XErrorEvent
*);
104 /* dispatch pending errors */
107 old_handler
= XSetErrorHandler(handle_xerror
);
108 /* This may trigger the X protocol error we're ready to catch: */
109 XShmAttach(dpy
, &pdp
->shminfo
);
113 /* we are on a remote display, this error is normal, don't print it */
114 XDestroyImage(pdp
->ximage
);
118 (void) XSetErrorHandler(old_handler
);
122 if (pdp
->ximage
== NULL
) {
123 pdp
->shminfo
.shmid
= -1;
124 pdp
->ximage
= XCreateImage(dpy
,
125 pdp
->visinfo
->visual
,
127 ZPixmap
, 0, /* format, offset */
129 0, 0, /* width, height */
131 0); /* bytes_per_line */
135 * swrast does not handle 24-bit depth with 24 bpp, so let X do the
136 * the conversion for us.
138 if (pdp
->ximage
->bits_per_pixel
== 24)
139 pdp
->ximage
->bits_per_pixel
= 32;
145 XDestroyDrawable(struct drisw_drawable
* pdp
, Display
* dpy
, XID drawable
)
148 XDestroyImage(pdp
->ximage
);
152 XFreeGC(dpy
, pdp
->gc
);
153 XFreeGC(dpy
, pdp
->swapgc
);
157 * swrast loader functions
161 swrastGetDrawableInfo(__DRIdrawable
* draw
,
162 int *x
, int *y
, int *w
, int *h
,
165 struct drisw_drawable
*pdp
= loaderPrivate
;
166 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
167 Display
*dpy
= pdraw
->psc
->dpy
;
171 unsigned uw
, uh
, bw
, depth
;
173 drawable
= pdraw
->xDrawable
;
175 XGetGeometry(dpy
, drawable
, &root
, x
, y
, &uw
, &uh
, &bw
, &depth
);
181 * Align renderbuffer pitch.
183 * This should be chosen by the driver and the loader (libGL, xserver/glx)
184 * should use the driver provided pitch.
186 * It seems that the xorg loader (that is the xserver loading swrast_dri for
187 * indirect rendering, not client-side libGL) requires that the pitch is
188 * exactly the image width padded to 32 bits. XXX
190 * The above restriction can probably be overcome by using ScratchPixmap and
191 * CopyArea in the xserver, similar to ShmPutImage, and setting the width of
192 * the scratch pixmap to 'pitch / cpp'.
195 bytes_per_line(unsigned pitch_bits
, unsigned mul
)
197 unsigned mask
= mul
- 1;
199 return ((pitch_bits
+ mask
) & ~mask
) / 8;
203 swrastXPutImage(__DRIdrawable
* draw
, int op
,
204 int x
, int y
, int w
, int h
, int stride
,
205 int shmid
, char *data
, void *loaderPrivate
)
207 struct drisw_drawable
*pdp
= loaderPrivate
;
208 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
209 Display
*dpy
= pdraw
->psc
->dpy
;
214 if (!pdp
->ximage
|| shmid
!= pdp
->shminfo
.shmid
) {
215 if (!XCreateDrawable(pdp
, shmid
, dpy
))
220 case __DRI_SWRAST_IMAGE_OP_DRAW
:
223 case __DRI_SWRAST_IMAGE_OP_SWAP
:
230 drawable
= pdraw
->xDrawable
;
231 ximage
= pdp
->ximage
;
232 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
235 if (pdp
->shminfo
.shmid
>= 0) {
236 ximage
->width
= ximage
->bytes_per_line
/ ((ximage
->bits_per_pixel
+ 7)/ 8);
238 XShmPutImage(dpy
, drawable
, gc
, ximage
, 0, 0, x
, y
, w
, h
, False
);
243 XPutImage(dpy
, drawable
, gc
, ximage
, 0, 0, x
, y
, w
, h
);
249 swrastPutImageShm(__DRIdrawable
* draw
, int op
,
250 int x
, int y
, int w
, int h
, int stride
,
251 int shmid
, char *shmaddr
, unsigned offset
,
254 struct drisw_drawable
*pdp
= loaderPrivate
;
256 pdp
->shminfo
.shmaddr
= shmaddr
;
257 swrastXPutImage(draw
, op
, x
, y
, w
, h
, stride
, shmid
,
258 shmaddr
+ offset
, loaderPrivate
);
262 swrastPutImage2(__DRIdrawable
* draw
, int op
,
263 int x
, int y
, int w
, int h
, int stride
,
264 char *data
, void *loaderPrivate
)
266 swrastXPutImage(draw
, op
, x
, y
, w
, h
, stride
, -1,
267 data
, loaderPrivate
);
271 swrastPutImage(__DRIdrawable
* draw
, int op
,
272 int x
, int y
, int w
, int h
,
273 char *data
, void *loaderPrivate
)
275 swrastXPutImage(draw
, op
, x
, y
, w
, h
, 0, -1,
276 data
, loaderPrivate
);
280 swrastGetImage2(__DRIdrawable
* read
,
281 int x
, int y
, int w
, int h
, int stride
,
282 char *data
, void *loaderPrivate
)
284 struct drisw_drawable
*prp
= loaderPrivate
;
285 __GLXDRIdrawable
*pread
= &(prp
->base
);
286 Display
*dpy
= pread
->psc
->dpy
;
290 if (!prp
->ximage
|| prp
->shminfo
.shmid
>= 0) {
291 if (!XCreateDrawable(prp
, -1, dpy
))
295 readable
= pread
->xDrawable
;
297 ximage
= prp
->ximage
;
301 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
303 XGetSubImage(dpy
, readable
, x
, y
, w
, h
, ~0L, ZPixmap
, ximage
, 0, 0);
309 swrastGetImage(__DRIdrawable
* read
,
310 int x
, int y
, int w
, int h
,
311 char *data
, void *loaderPrivate
)
313 swrastGetImage2(read
, x
, y
, w
, h
, 0, data
, loaderPrivate
);
316 static __DRIswrastLoaderExtension swrastLoaderExtension
= {
317 .base
= {__DRI_SWRAST_LOADER
, 4 },
319 .getDrawableInfo
= swrastGetDrawableInfo
,
320 .putImage
= swrastPutImage
,
321 .getImage
= swrastGetImage
,
322 .putImage2
= swrastPutImage2
,
323 .getImage2
= swrastGetImage2
,
324 .putImageShm
= swrastPutImageShm
,
327 static const __DRIextension
*loader_extensions
[] = {
328 &swrastLoaderExtension
.base
,
337 drisw_destroy_context(struct glx_context
*context
)
339 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
340 struct drisw_screen
*psc
= (struct drisw_screen
*) context
->psc
;
342 driReleaseDrawables(&pcp
->base
);
344 free((char *) context
->extensions
);
346 (*psc
->core
->destroyContext
) (pcp
->driContext
);
352 drisw_bind_context(struct glx_context
*context
, struct glx_context
*old
,
353 GLXDrawable draw
, GLXDrawable read
)
355 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
356 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
357 struct drisw_drawable
*pdraw
, *pread
;
359 pdraw
= (struct drisw_drawable
*) driFetchDrawable(context
, draw
);
360 pread
= (struct drisw_drawable
*) driFetchDrawable(context
, read
);
362 driReleaseDrawables(&pcp
->base
);
364 if ((*psc
->core
->bindContext
) (pcp
->driContext
,
365 pdraw
? pdraw
->driDrawable
: NULL
,
366 pread
? pread
->driDrawable
: NULL
))
369 return GLXBadContext
;
373 drisw_unbind_context(struct glx_context
*context
, struct glx_context
*new)
375 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
376 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
378 (*psc
->core
->unbindContext
) (pcp
->driContext
);
382 drisw_bind_tex_image(Display
* dpy
,
383 GLXDrawable drawable
,
384 int buffer
, const int *attrib_list
)
386 struct glx_context
*gc
= __glXGetCurrentContext();
387 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
388 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
389 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
390 struct drisw_screen
*psc
;
392 __glXInitialize(dpy
);
395 psc
= (struct drisw_screen
*) base
->psc
;
400 if (psc
->texBuffer
->base
.version
>= 2 &&
401 psc
->texBuffer
->setTexBuffer2
!= NULL
) {
402 (*psc
->texBuffer
->setTexBuffer2
) (pcp
->driContext
,
403 pdraw
->base
.textureTarget
,
404 pdraw
->base
.textureFormat
,
408 (*psc
->texBuffer
->setTexBuffer
) (pcp
->driContext
,
409 pdraw
->base
.textureTarget
,
416 drisw_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
418 struct glx_context
*gc
= __glXGetCurrentContext();
419 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
420 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
421 struct glx_display
*dpyPriv
= __glXInitialize(dpy
);
422 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
423 struct drisw_screen
*psc
;
425 if (dpyPriv
!= NULL
&& pdraw
!= NULL
) {
426 psc
= (struct drisw_screen
*) base
->psc
;
431 if (psc
->texBuffer
->base
.version
>= 3 &&
432 psc
->texBuffer
->releaseTexBuffer
!= NULL
) {
433 (*psc
->texBuffer
->releaseTexBuffer
) (pcp
->driContext
,
434 pdraw
->base
.textureTarget
,
440 static const struct glx_context_vtable drisw_context_vtable
= {
441 .destroy
= drisw_destroy_context
,
442 .bind
= drisw_bind_context
,
443 .unbind
= drisw_unbind_context
,
446 .use_x_font
= DRI_glXUseXFont
,
447 .bind_tex_image
= drisw_bind_tex_image
,
448 .release_tex_image
= drisw_release_tex_image
,
449 .get_proc_address
= NULL
,
452 static struct glx_context
*
453 drisw_create_context(struct glx_screen
*base
,
454 struct glx_config
*config_base
,
455 struct glx_context
*shareList
, int renderType
)
457 struct drisw_context
*pcp
, *pcp_shared
;
458 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
459 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
460 __DRIcontext
*shared
= NULL
;
462 if (!psc
->base
.driScreen
)
465 /* Check the renderType value */
466 if (!validate_renderType_against_config(config_base
, renderType
))
470 /* If the shareList context is not a DRISW context, we cannot possibly
471 * create a DRISW context that shares it.
473 if (shareList
->vtable
->destroy
!= drisw_destroy_context
) {
477 pcp_shared
= (struct drisw_context
*) shareList
;
478 shared
= pcp_shared
->driContext
;
481 pcp
= calloc(1, sizeof *pcp
);
485 if (!glx_context_init(&pcp
->base
, &psc
->base
, &config
->base
)) {
490 pcp
->base
.renderType
= renderType
;
493 (*psc
->core
->createNewContext
) (psc
->driScreen
,
494 config
->driConfig
, shared
, pcp
);
495 if (pcp
->driContext
== NULL
) {
500 pcp
->base
.vtable
= &drisw_context_vtable
;
505 static struct glx_context
*
506 drisw_create_context_attribs(struct glx_screen
*base
,
507 struct glx_config
*config_base
,
508 struct glx_context
*shareList
,
509 unsigned num_attribs
,
510 const uint32_t *attribs
,
513 struct drisw_context
*pcp
, *pcp_shared
;
514 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
515 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
516 __DRIcontext
*shared
= NULL
;
525 uint32_t ctx_attribs
[2 * 5];
526 unsigned num_ctx_attribs
= 0;
528 if (!psc
->base
.driScreen
)
531 if (psc
->swrast
->base
.version
< 3)
534 /* Remap the GLX tokens to DRI2 tokens.
536 if (!dri2_convert_glx_attribs(num_attribs
, attribs
,
537 &major_ver
, &minor_ver
, &renderType
, &flags
,
538 &api
, &reset
, &release
, error
))
541 /* Check the renderType value */
542 if (!validate_renderType_against_config(config_base
, renderType
)) {
546 if (reset
!= __DRI_CTX_RESET_NO_NOTIFICATION
)
549 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
&&
550 release
!= __DRI_CTX_RELEASE_BEHAVIOR_NONE
)
554 pcp_shared
= (struct drisw_context
*) shareList
;
555 shared
= pcp_shared
->driContext
;
558 pcp
= calloc(1, sizeof *pcp
);
562 if (!glx_context_init(&pcp
->base
, &psc
->base
, config_base
)) {
567 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
568 ctx_attribs
[num_ctx_attribs
++] = major_ver
;
569 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
570 ctx_attribs
[num_ctx_attribs
++] = minor_ver
;
571 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
) {
572 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
573 ctx_attribs
[num_ctx_attribs
++] = release
;
577 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_FLAGS
;
579 /* The current __DRI_CTX_FLAG_* values are identical to the
580 * GLX_CONTEXT_*_BIT values.
582 ctx_attribs
[num_ctx_attribs
++] = flags
;
585 pcp
->base
.renderType
= renderType
;
588 (*psc
->swrast
->createContextAttribs
) (psc
->driScreen
,
590 config
? config
->driConfig
: 0,
596 if (pcp
->driContext
== NULL
) {
601 pcp
->base
.vtable
= &drisw_context_vtable
;
607 driswDestroyDrawable(__GLXDRIdrawable
* pdraw
)
609 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
610 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
612 (*psc
->core
->destroyDrawable
) (pdp
->driDrawable
);
614 XDestroyDrawable(pdp
, pdraw
->psc
->dpy
, pdraw
->drawable
);
618 static __GLXDRIdrawable
*
619 driswCreateDrawable(struct glx_screen
*base
, XID xDrawable
,
620 GLXDrawable drawable
, struct glx_config
*modes
)
622 struct drisw_drawable
*pdp
;
623 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) modes
;
624 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
626 const __DRIswrastExtension
*swrast
= psc
->swrast
;
628 pdp
= calloc(1, sizeof(*pdp
));
632 pdp
->base
.xDrawable
= xDrawable
;
633 pdp
->base
.drawable
= drawable
;
634 pdp
->base
.psc
= &psc
->base
;
636 ret
= XCreateGCs(pdp
, psc
->base
.dpy
, xDrawable
, modes
->visualID
);
642 /* Create a new drawable */
644 (*swrast
->createNewDrawable
) (psc
->driScreen
, config
->driConfig
, pdp
);
646 if (!pdp
->driDrawable
) {
647 XDestroyDrawable(pdp
, psc
->base
.dpy
, xDrawable
);
652 pdp
->base
.destroyDrawable
= driswDestroyDrawable
;
658 driswSwapBuffers(__GLXDRIdrawable
* pdraw
,
659 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
662 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
663 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
673 (*psc
->core
->swapBuffers
) (pdp
->driDrawable
);
679 driswCopySubBuffer(__GLXDRIdrawable
* pdraw
,
680 int x
, int y
, int width
, int height
, Bool flush
)
682 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
683 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
689 (*psc
->copySubBuffer
->copySubBuffer
) (pdp
->driDrawable
,
690 x
, y
, width
, height
);
694 driswDestroyScreen(struct glx_screen
*base
)
696 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
698 /* Free the direct rendering per screen data */
699 (*psc
->core
->destroyScreen
) (psc
->driScreen
);
700 driDestroyConfigs(psc
->driver_configs
);
701 psc
->driScreen
= NULL
;
703 dlclose(psc
->driver
);
707 #define SWRAST_DRIVER_NAME "swrast"
715 driver
= driOpenDriver(SWRAST_DRIVER_NAME
);
720 static const struct glx_screen_vtable drisw_screen_vtable
= {
721 .create_context
= drisw_create_context
,
722 .create_context_attribs
= drisw_create_context_attribs
,
723 .query_renderer_integer
= drisw_query_renderer_integer
,
724 .query_renderer_string
= drisw_query_renderer_string
,
728 driswBindExtensions(struct drisw_screen
*psc
, const __DRIextension
**extensions
)
732 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_make_current_read");
734 if (psc
->swrast
->base
.version
>= 3) {
735 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context");
736 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context_profile");
738 /* DRISW version >= 2 implies support for OpenGL ES.
740 __glXEnableDirectExtension(&psc
->base
,
741 "GLX_EXT_create_context_es_profile");
742 __glXEnableDirectExtension(&psc
->base
,
743 "GLX_EXT_create_context_es2_profile");
746 if (psc
->copySubBuffer
)
747 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
749 /* FIXME: Figure out what other extensions can be ported here from dri2. */
750 for (i
= 0; extensions
[i
]; i
++) {
751 if ((strcmp(extensions
[i
]->name
, __DRI_TEX_BUFFER
) == 0)) {
752 psc
->texBuffer
= (__DRItexBufferExtension
*) extensions
[i
];
753 __glXEnableDirectExtension(&psc
->base
, "GLX_EXT_texture_from_pixmap");
755 /* DRISW version 3 is also required because GLX_MESA_query_renderer
756 * requires GLX_ARB_create_context_profile.
758 if (psc
->swrast
->base
.version
>= 3
759 && strcmp(extensions
[i
]->name
, __DRI2_RENDERER_QUERY
) == 0) {
760 psc
->rendererQuery
= (__DRI2rendererQueryExtension
*) extensions
[i
];
761 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_query_renderer");
763 if (strcmp(extensions
[i
]->name
, __DRI2_FLUSH_CONTROL
) == 0) {
764 __glXEnableDirectExtension(&psc
->base
,
765 "GLX_ARB_context_flush_control");
771 check_xshm(Display
*dpy
)
775 return XQueryExtension(dpy
, "MIT-SHM", &xshm_opcode
, &ignore
, &ignore
);
778 static struct glx_screen
*
779 driswCreateScreen(int screen
, struct glx_display
*priv
)
782 const __DRIconfig
**driver_configs
;
783 const __DRIextension
**extensions
;
784 struct drisw_screen
*psc
;
785 struct glx_config
*configs
= NULL
, *visuals
= NULL
;
788 psc
= calloc(1, sizeof *psc
);
792 if (!glx_screen_init(&psc
->base
, screen
, priv
)) {
797 psc
->driver
= driOpenSwrast();
798 if (psc
->driver
== NULL
)
801 extensions
= driGetDriverExtensions(psc
->driver
, SWRAST_DRIVER_NAME
);
802 if (extensions
== NULL
)
805 if (!check_xshm(psc
->base
.dpy
))
806 swrastLoaderExtension
.putImageShm
= NULL
;
808 for (i
= 0; extensions
[i
]; i
++) {
809 if (strcmp(extensions
[i
]->name
, __DRI_CORE
) == 0)
810 psc
->core
= (__DRIcoreExtension
*) extensions
[i
];
811 if (strcmp(extensions
[i
]->name
, __DRI_SWRAST
) == 0)
812 psc
->swrast
= (__DRIswrastExtension
*) extensions
[i
];
813 if (strcmp(extensions
[i
]->name
, __DRI_COPY_SUB_BUFFER
) == 0)
814 psc
->copySubBuffer
= (__DRIcopySubBufferExtension
*) extensions
[i
];
817 if (psc
->core
== NULL
|| psc
->swrast
== NULL
) {
818 ErrorMessageF("core dri extension not found\n");
822 if (psc
->swrast
->base
.version
>= 4) {
824 psc
->swrast
->createNewScreen2(screen
, loader_extensions
,
826 &driver_configs
, psc
);
829 psc
->swrast
->createNewScreen(screen
, loader_extensions
,
830 &driver_configs
, psc
);
832 if (psc
->driScreen
== NULL
) {
833 ErrorMessageF("failed to create dri screen\n");
837 extensions
= psc
->core
->getExtensions(psc
->driScreen
);
838 driswBindExtensions(psc
, extensions
);
840 configs
= driConvertConfigs(psc
->core
, psc
->base
.configs
, driver_configs
);
841 visuals
= driConvertConfigs(psc
->core
, psc
->base
.visuals
, driver_configs
);
843 if (!configs
|| !visuals
) {
844 ErrorMessageF("No matching fbConfigs or visuals found\n");
848 glx_config_destroy_list(psc
->base
.configs
);
849 psc
->base
.configs
= configs
;
850 glx_config_destroy_list(psc
->base
.visuals
);
851 psc
->base
.visuals
= visuals
;
853 psc
->driver_configs
= driver_configs
;
855 psc
->base
.vtable
= &drisw_screen_vtable
;
857 psc
->base
.driScreen
= psp
;
858 psp
->destroyScreen
= driswDestroyScreen
;
859 psp
->createDrawable
= driswCreateDrawable
;
860 psp
->swapBuffers
= driswSwapBuffers
;
862 if (psc
->copySubBuffer
)
863 psp
->copySubBuffer
= driswCopySubBuffer
;
869 glx_config_destroy_list(configs
);
871 glx_config_destroy_list(visuals
);
873 psc
->core
->destroyScreen(psc
->driScreen
);
874 psc
->driScreen
= NULL
;
877 dlclose(psc
->driver
);
878 glx_screen_cleanup(&psc
->base
);
881 CriticalErrorMessageF("failed to load driver: %s\n", SWRAST_DRIVER_NAME
);
886 /* Called from __glXFreeDisplayPrivate.
889 driswDestroyDisplay(__GLXDRIdisplay
* dpy
)
895 * Allocate, initialize and return a __DRIdisplayPrivate object.
896 * This is called from __glXInitialize() when we are given a new
899 _X_HIDDEN __GLXDRIdisplay
*
900 driswCreateDisplay(Display
* dpy
)
902 struct drisw_display
*pdpyp
;
904 pdpyp
= malloc(sizeof *pdpyp
);
908 pdpyp
->base
.destroyDisplay
= driswDestroyDisplay
;
909 pdpyp
->base
.createScreen
= driswCreateScreen
;
914 #endif /* GLX_DIRECT_RENDERING */