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>
34 static int xshm_error
= 0;
35 static int xshm_opcode
= -1;
38 * Catches potential Xlib errors.
41 handle_xerror(Display
*dpy
, XErrorEvent
*event
)
45 assert(xshm_opcode
!= -1);
46 if (event
->request_code
!= xshm_opcode
)
49 xshm_error
= event
->error_code
;
54 XCreateDrawable(struct drisw_drawable
* pdp
, int shmid
, Display
* dpy
)
57 XDestroyImage(pdp
->ximage
);
59 if ((pdp
->shminfo
.shmid
> 0) && (shmid
!= pdp
->shminfo
.shmid
))
60 XShmDetach(dpy
, &pdp
->shminfo
);
63 if (!xshm_error
&& shmid
>= 0) {
64 pdp
->shminfo
.shmid
= shmid
;
65 pdp
->ximage
= XShmCreateImage(dpy
,
70 &pdp
->shminfo
, /* shminfo */
71 0, 0); /* width, height */
72 if (pdp
->ximage
!= NULL
) {
73 int (*old_handler
)(Display
*, XErrorEvent
*);
75 /* dispatch pending errors */
78 old_handler
= XSetErrorHandler(handle_xerror
);
79 /* This may trigger the X protocol error we're ready to catch: */
80 XShmAttach(dpy
, &pdp
->shminfo
);
84 /* we are on a remote display, this error is normal, don't print it */
85 XDestroyImage(pdp
->ximage
);
89 (void) XSetErrorHandler(old_handler
);
93 if (pdp
->ximage
== NULL
) {
94 pdp
->shminfo
.shmid
= -1;
95 pdp
->ximage
= XCreateImage(dpy
,
98 ZPixmap
, 0, /* format, offset */
100 0, 0, /* width, height */
102 0); /* bytes_per_line */
106 * swrast does not handle 24-bit depth with 24 bpp, so let X do the
107 * the conversion for us.
109 if (pdp
->ximage
->bits_per_pixel
== 24)
110 pdp
->ximage
->bits_per_pixel
= 32;
116 XDestroyDrawable(struct drisw_drawable
* pdp
, Display
* dpy
, XID drawable
)
119 XDestroyImage(pdp
->ximage
);
121 if (pdp
->shminfo
.shmid
> 0)
122 XShmDetach(dpy
, &pdp
->shminfo
);
124 XFreeGC(dpy
, pdp
->gc
);
128 * swrast loader functions
132 swrastGetDrawableInfo(__DRIdrawable
* draw
,
133 int *x
, int *y
, int *w
, int *h
,
136 struct drisw_drawable
*pdp
= loaderPrivate
;
137 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
138 Display
*dpy
= pdraw
->psc
->dpy
;
142 unsigned uw
, uh
, bw
, depth
;
144 drawable
= pdraw
->xDrawable
;
146 XGetGeometry(dpy
, drawable
, &root
, x
, y
, &uw
, &uh
, &bw
, &depth
);
152 * Align renderbuffer pitch.
154 * This should be chosen by the driver and the loader (libGL, xserver/glx)
155 * should use the driver provided pitch.
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
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'.
166 bytes_per_line(unsigned pitch_bits
, unsigned mul
)
168 unsigned mask
= mul
- 1;
170 return ((pitch_bits
+ mask
) & ~mask
) / 8;
174 swrastXPutImage(__DRIdrawable
* draw
, int op
,
175 int srcx
, int srcy
, int x
, int y
,
176 int w
, int h
, int stride
,
177 int shmid
, char *data
, void *loaderPrivate
)
179 struct drisw_drawable
*pdp
= loaderPrivate
;
180 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
181 Display
*dpy
= pdraw
->psc
->dpy
;
186 if (!pdp
->ximage
|| shmid
!= pdp
->shminfo
.shmid
) {
187 if (!XCreateDrawable(pdp
, shmid
, dpy
))
191 drawable
= pdraw
->xDrawable
;
192 ximage
= pdp
->ximage
;
193 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
196 if (pdp
->shminfo
.shmid
>= 0) {
197 ximage
->width
= ximage
->bytes_per_line
/ ((ximage
->bits_per_pixel
+ 7)/ 8);
199 XShmPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
, False
);
204 XPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
);
210 swrastPutImageShm(__DRIdrawable
* draw
, int op
,
211 int x
, int y
, int w
, int h
, int stride
,
212 int shmid
, char *shmaddr
, unsigned offset
,
215 struct drisw_drawable
*pdp
= loaderPrivate
;
217 pdp
->shminfo
.shmaddr
= shmaddr
;
218 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, shmid
,
219 shmaddr
+ offset
, loaderPrivate
);
223 swrastPutImageShm2(__DRIdrawable
* draw
, int op
,
225 int w
, int h
, int stride
,
226 int shmid
, char *shmaddr
, unsigned offset
,
229 struct drisw_drawable
*pdp
= loaderPrivate
;
231 pdp
->shminfo
.shmaddr
= shmaddr
;
232 swrastXPutImage(draw
, op
, x
, 0, x
, y
, w
, h
, stride
, shmid
,
233 shmaddr
+ offset
, loaderPrivate
);
237 swrastPutImage2(__DRIdrawable
* draw
, int op
,
238 int x
, int y
, int w
, int h
, int stride
,
239 char *data
, void *loaderPrivate
)
241 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, -1,
242 data
, loaderPrivate
);
246 swrastPutImage(__DRIdrawable
* draw
, int op
,
247 int x
, int y
, int w
, int h
,
248 char *data
, void *loaderPrivate
)
250 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, 0, -1,
251 data
, loaderPrivate
);
255 swrastGetImage2(__DRIdrawable
* read
,
256 int x
, int y
, int w
, int h
, int stride
,
257 char *data
, void *loaderPrivate
)
259 struct drisw_drawable
*prp
= loaderPrivate
;
260 __GLXDRIdrawable
*pread
= &(prp
->base
);
261 Display
*dpy
= pread
->psc
->dpy
;
265 if (!prp
->ximage
|| prp
->shminfo
.shmid
>= 0) {
266 if (!XCreateDrawable(prp
, -1, dpy
))
270 readable
= pread
->xDrawable
;
272 ximage
= prp
->ximage
;
276 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
278 XGetSubImage(dpy
, readable
, x
, y
, w
, h
, ~0L, ZPixmap
, ximage
, 0, 0);
284 swrastGetImage(__DRIdrawable
* read
,
285 int x
, int y
, int w
, int h
,
286 char *data
, void *loaderPrivate
)
288 swrastGetImage2(read
, x
, y
, w
, h
, 0, data
, loaderPrivate
);
292 swrastGetImageShm(__DRIdrawable
* read
,
293 int x
, int y
, int w
, int h
,
294 int shmid
, void *loaderPrivate
)
296 struct drisw_drawable
*prp
= loaderPrivate
;
297 __GLXDRIdrawable
*pread
= &(prp
->base
);
298 Display
*dpy
= pread
->psc
->dpy
;
302 if (!prp
->ximage
|| shmid
!= prp
->shminfo
.shmid
) {
303 if (!XCreateDrawable(prp
, shmid
, dpy
))
306 readable
= pread
->xDrawable
;
308 ximage
= prp
->ximage
;
309 ximage
->data
= prp
->shminfo
.shmaddr
; /* no offset */
312 ximage
->bytes_per_line
= bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
314 XShmGetImage(dpy
, readable
, ximage
, x
, y
, ~0L);
317 static const __DRIswrastLoaderExtension swrastLoaderExtension_shm
= {
318 .base
= {__DRI_SWRAST_LOADER
, 5 },
320 .getDrawableInfo
= swrastGetDrawableInfo
,
321 .putImage
= swrastPutImage
,
322 .getImage
= swrastGetImage
,
323 .putImage2
= swrastPutImage2
,
324 .getImage2
= swrastGetImage2
,
325 .putImageShm
= swrastPutImageShm
,
326 .getImageShm
= swrastGetImageShm
,
327 .putImageShm2
= swrastPutImageShm2
,
330 static const __DRIextension
*loader_extensions_shm
[] = {
331 &swrastLoaderExtension_shm
.base
,
335 static const __DRIswrastLoaderExtension swrastLoaderExtension
= {
336 .base
= {__DRI_SWRAST_LOADER
, 3 },
338 .getDrawableInfo
= swrastGetDrawableInfo
,
339 .putImage
= swrastPutImage
,
340 .getImage
= swrastGetImage
,
341 .putImage2
= swrastPutImage2
,
342 .getImage2
= swrastGetImage2
,
345 static const __DRIextension
*loader_extensions_noshm
[] = {
346 &swrastLoaderExtension
.base
,
355 drisw_destroy_context(struct glx_context
*context
)
357 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
358 struct drisw_screen
*psc
= (struct drisw_screen
*) context
->psc
;
360 driReleaseDrawables(&pcp
->base
);
362 free((char *) context
->extensions
);
364 (*psc
->core
->destroyContext
) (pcp
->driContext
);
370 drisw_bind_context(struct glx_context
*context
, struct glx_context
*old
,
371 GLXDrawable draw
, GLXDrawable read
)
373 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
374 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
375 struct drisw_drawable
*pdraw
, *pread
;
377 pdraw
= (struct drisw_drawable
*) driFetchDrawable(context
, draw
);
378 pread
= (struct drisw_drawable
*) driFetchDrawable(context
, read
);
380 driReleaseDrawables(&pcp
->base
);
382 if ((*psc
->core
->bindContext
) (pcp
->driContext
,
383 pdraw
? pdraw
->driDrawable
: NULL
,
384 pread
? pread
->driDrawable
: NULL
))
387 return GLXBadContext
;
391 drisw_unbind_context(struct glx_context
*context
, struct glx_context
*new)
393 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
394 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
396 (*psc
->core
->unbindContext
) (pcp
->driContext
);
400 drisw_bind_tex_image(Display
* dpy
,
401 GLXDrawable drawable
,
402 int buffer
, const int *attrib_list
)
404 struct glx_context
*gc
= __glXGetCurrentContext();
405 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
406 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
407 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
408 struct drisw_screen
*psc
;
410 __glXInitialize(dpy
);
413 psc
= (struct drisw_screen
*) base
->psc
;
418 if (psc
->texBuffer
->base
.version
>= 2 &&
419 psc
->texBuffer
->setTexBuffer2
!= NULL
) {
420 (*psc
->texBuffer
->setTexBuffer2
) (pcp
->driContext
,
421 pdraw
->base
.textureTarget
,
422 pdraw
->base
.textureFormat
,
426 (*psc
->texBuffer
->setTexBuffer
) (pcp
->driContext
,
427 pdraw
->base
.textureTarget
,
434 drisw_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
436 struct glx_context
*gc
= __glXGetCurrentContext();
437 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
438 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
439 struct glx_display
*dpyPriv
= __glXInitialize(dpy
);
440 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
441 struct drisw_screen
*psc
;
443 if (dpyPriv
!= NULL
&& pdraw
!= NULL
) {
444 psc
= (struct drisw_screen
*) base
->psc
;
449 if (psc
->texBuffer
->base
.version
>= 3 &&
450 psc
->texBuffer
->releaseTexBuffer
!= NULL
) {
451 (*psc
->texBuffer
->releaseTexBuffer
) (pcp
->driContext
,
452 pdraw
->base
.textureTarget
,
458 static const struct glx_context_vtable drisw_context_vtable
= {
459 .destroy
= drisw_destroy_context
,
460 .bind
= drisw_bind_context
,
461 .unbind
= drisw_unbind_context
,
464 .use_x_font
= DRI_glXUseXFont
,
465 .bind_tex_image
= drisw_bind_tex_image
,
466 .release_tex_image
= drisw_release_tex_image
,
467 .get_proc_address
= NULL
,
470 static struct glx_context
*
471 drisw_create_context(struct glx_screen
*base
,
472 struct glx_config
*config_base
,
473 struct glx_context
*shareList
, int renderType
)
475 struct drisw_context
*pcp
, *pcp_shared
;
476 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
477 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
478 __DRIcontext
*shared
= NULL
;
480 if (!psc
->base
.driScreen
)
483 /* Check the renderType value */
484 if (!validate_renderType_against_config(config_base
, renderType
))
488 /* If the shareList context is not a DRISW context, we cannot possibly
489 * create a DRISW context that shares it.
491 if (shareList
->vtable
->destroy
!= drisw_destroy_context
) {
495 pcp_shared
= (struct drisw_context
*) shareList
;
496 shared
= pcp_shared
->driContext
;
499 pcp
= calloc(1, sizeof *pcp
);
503 if (!glx_context_init(&pcp
->base
, &psc
->base
, &config
->base
)) {
508 pcp
->base
.renderType
= renderType
;
511 (*psc
->core
->createNewContext
) (psc
->driScreen
,
512 config
->driConfig
, shared
, pcp
);
513 if (pcp
->driContext
== NULL
) {
518 pcp
->base
.vtable
= &drisw_context_vtable
;
523 static struct glx_context
*
524 drisw_create_context_attribs(struct glx_screen
*base
,
525 struct glx_config
*config_base
,
526 struct glx_context
*shareList
,
527 unsigned num_attribs
,
528 const uint32_t *attribs
,
531 struct drisw_context
*pcp
, *pcp_shared
;
532 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
533 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
534 __DRIcontext
*shared
= NULL
;
543 uint32_t ctx_attribs
[2 * 5];
544 unsigned num_ctx_attribs
= 0;
546 if (!psc
->base
.driScreen
)
549 if (psc
->swrast
->base
.version
< 3)
552 /* Remap the GLX tokens to DRI2 tokens.
554 if (!dri2_convert_glx_attribs(num_attribs
, attribs
,
555 &major_ver
, &minor_ver
, &renderType
, &flags
,
556 &api
, &reset
, &release
, error
))
559 if (!dri2_check_no_error(flags
, shareList
, major_ver
, error
))
562 /* Check the renderType value */
563 if (!validate_renderType_against_config(config_base
, renderType
)) {
567 if (reset
!= __DRI_CTX_RESET_NO_NOTIFICATION
)
570 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
&&
571 release
!= __DRI_CTX_RELEASE_BEHAVIOR_NONE
)
575 pcp_shared
= (struct drisw_context
*) shareList
;
576 shared
= pcp_shared
->driContext
;
579 pcp
= calloc(1, sizeof *pcp
);
583 if (!glx_context_init(&pcp
->base
, &psc
->base
, config_base
)) {
588 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
589 ctx_attribs
[num_ctx_attribs
++] = major_ver
;
590 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
591 ctx_attribs
[num_ctx_attribs
++] = minor_ver
;
592 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
) {
593 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
594 ctx_attribs
[num_ctx_attribs
++] = release
;
598 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_FLAGS
;
600 /* The current __DRI_CTX_FLAG_* values are identical to the
601 * GLX_CONTEXT_*_BIT values.
603 ctx_attribs
[num_ctx_attribs
++] = flags
;
605 if (flags
& __DRI_CTX_FLAG_NO_ERROR
)
606 pcp
->base
.noError
= GL_TRUE
;
609 pcp
->base
.renderType
= renderType
;
612 (*psc
->swrast
->createContextAttribs
) (psc
->driScreen
,
614 config
? config
->driConfig
: 0,
620 if (pcp
->driContext
== NULL
) {
625 pcp
->base
.vtable
= &drisw_context_vtable
;
631 driswDestroyDrawable(__GLXDRIdrawable
* pdraw
)
633 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
634 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
636 (*psc
->core
->destroyDrawable
) (pdp
->driDrawable
);
638 XDestroyDrawable(pdp
, pdraw
->psc
->dpy
, pdraw
->drawable
);
642 static __GLXDRIdrawable
*
643 driswCreateDrawable(struct glx_screen
*base
, XID xDrawable
,
644 GLXDrawable drawable
, struct glx_config
*modes
)
646 struct drisw_drawable
*pdp
;
647 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) modes
;
648 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
649 const __DRIswrastExtension
*swrast
= psc
->swrast
;
651 pdp
= calloc(1, sizeof(*pdp
));
655 pdp
->base
.xDrawable
= xDrawable
;
656 pdp
->base
.drawable
= drawable
;
657 pdp
->base
.psc
= &psc
->base
;
659 pdp
->gc
= XCreateGC(psc
->base
.dpy
, xDrawable
, 0, NULL
);
661 /* Create a new drawable */
663 (*swrast
->createNewDrawable
) (psc
->driScreen
, config
->driConfig
, pdp
);
665 if (!pdp
->driDrawable
) {
666 XDestroyDrawable(pdp
, psc
->base
.dpy
, xDrawable
);
671 pdp
->base
.destroyDrawable
= driswDestroyDrawable
;
677 driswSwapBuffers(__GLXDRIdrawable
* pdraw
,
678 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
681 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
682 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
692 (*psc
->core
->swapBuffers
) (pdp
->driDrawable
);
698 driswCopySubBuffer(__GLXDRIdrawable
* pdraw
,
699 int x
, int y
, int width
, int height
, Bool flush
)
701 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
702 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
708 (*psc
->copySubBuffer
->copySubBuffer
) (pdp
->driDrawable
,
709 x
, y
, width
, height
);
713 driswDestroyScreen(struct glx_screen
*base
)
715 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
717 /* Free the direct rendering per screen data */
718 (*psc
->core
->destroyScreen
) (psc
->driScreen
);
719 driDestroyConfigs(psc
->driver_configs
);
720 psc
->driScreen
= NULL
;
722 dlclose(psc
->driver
);
726 #define SWRAST_DRIVER_NAME "swrast"
728 static const struct glx_screen_vtable drisw_screen_vtable
= {
729 .create_context
= drisw_create_context
,
730 .create_context_attribs
= drisw_create_context_attribs
,
731 .query_renderer_integer
= drisw_query_renderer_integer
,
732 .query_renderer_string
= drisw_query_renderer_string
,
736 driswBindExtensions(struct drisw_screen
*psc
, const __DRIextension
**extensions
)
740 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_make_current_read");
742 if (psc
->swrast
->base
.version
>= 3) {
743 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context");
744 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context_profile");
746 /* DRISW version >= 2 implies support for OpenGL ES.
748 __glXEnableDirectExtension(&psc
->base
,
749 "GLX_EXT_create_context_es_profile");
750 __glXEnableDirectExtension(&psc
->base
,
751 "GLX_EXT_create_context_es2_profile");
754 if (psc
->copySubBuffer
)
755 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
757 /* FIXME: Figure out what other extensions can be ported here from dri2. */
758 for (i
= 0; extensions
[i
]; i
++) {
759 if ((strcmp(extensions
[i
]->name
, __DRI_TEX_BUFFER
) == 0)) {
760 psc
->texBuffer
= (__DRItexBufferExtension
*) extensions
[i
];
761 __glXEnableDirectExtension(&psc
->base
, "GLX_EXT_texture_from_pixmap");
763 /* DRISW version 3 is also required because GLX_MESA_query_renderer
764 * requires GLX_ARB_create_context_profile.
766 if (psc
->swrast
->base
.version
>= 3
767 && strcmp(extensions
[i
]->name
, __DRI2_RENDERER_QUERY
) == 0) {
768 psc
->rendererQuery
= (__DRI2rendererQueryExtension
*) extensions
[i
];
769 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_query_renderer");
771 if (strcmp(extensions
[i
]->name
, __DRI2_FLUSH_CONTROL
) == 0) {
772 __glXEnableDirectExtension(&psc
->base
,
773 "GLX_ARB_context_flush_control");
779 check_xshm(Display
*dpy
)
781 int (*old_handler
)(Display
*, XErrorEvent
*);
784 XShmSegmentInfo info
= { 0, };
786 if (!XQueryExtension(dpy
, "MIT-SHM", &xshm_opcode
, &ignore
, &ignore
))
789 old_handler
= XSetErrorHandler(handle_xerror
);
790 XShmDetach(dpy
, &info
);
792 (void) XSetErrorHandler(old_handler
);
794 /* BadRequest means we're a remote client. If we were local we'd
795 * expect BadValue since 'info' has an invalid segment name.
797 if (xshm_error
== BadRequest
)
804 static struct glx_screen
*
805 driswCreateScreen(int screen
, struct glx_display
*priv
)
808 const __DRIconfig
**driver_configs
;
809 const __DRIextension
**extensions
;
810 struct drisw_screen
*psc
;
811 struct glx_config
*configs
= NULL
, *visuals
= NULL
;
813 const __DRIextension
**loader_extensions_local
;
815 psc
= calloc(1, sizeof *psc
);
819 if (!glx_screen_init(&psc
->base
, screen
, priv
)) {
824 extensions
= driOpenDriver(SWRAST_DRIVER_NAME
, &psc
->driver
);
825 if (extensions
== NULL
)
828 if (!check_xshm(psc
->base
.dpy
))
829 loader_extensions_local
= loader_extensions_noshm
;
831 loader_extensions_local
= loader_extensions_shm
;
833 for (i
= 0; extensions
[i
]; i
++) {
834 if (strcmp(extensions
[i
]->name
, __DRI_CORE
) == 0)
835 psc
->core
= (__DRIcoreExtension
*) extensions
[i
];
836 if (strcmp(extensions
[i
]->name
, __DRI_SWRAST
) == 0)
837 psc
->swrast
= (__DRIswrastExtension
*) extensions
[i
];
838 if (strcmp(extensions
[i
]->name
, __DRI_COPY_SUB_BUFFER
) == 0)
839 psc
->copySubBuffer
= (__DRIcopySubBufferExtension
*) extensions
[i
];
842 if (psc
->core
== NULL
|| psc
->swrast
== NULL
) {
843 ErrorMessageF("core dri extension not found\n");
847 if (psc
->swrast
->base
.version
>= 4) {
849 psc
->swrast
->createNewScreen2(screen
, loader_extensions_local
,
851 &driver_configs
, psc
);
854 psc
->swrast
->createNewScreen(screen
, loader_extensions_local
,
855 &driver_configs
, psc
);
857 if (psc
->driScreen
== NULL
) {
858 ErrorMessageF("failed to create dri screen\n");
862 extensions
= psc
->core
->getExtensions(psc
->driScreen
);
863 driswBindExtensions(psc
, extensions
);
865 configs
= driConvertConfigs(psc
->core
, psc
->base
.configs
, driver_configs
);
866 visuals
= driConvertConfigs(psc
->core
, psc
->base
.visuals
, driver_configs
);
868 if (!configs
|| !visuals
) {
869 ErrorMessageF("No matching fbConfigs or visuals found\n");
873 glx_config_destroy_list(psc
->base
.configs
);
874 psc
->base
.configs
= configs
;
875 glx_config_destroy_list(psc
->base
.visuals
);
876 psc
->base
.visuals
= visuals
;
878 psc
->driver_configs
= driver_configs
;
880 psc
->base
.vtable
= &drisw_screen_vtable
;
882 psc
->base
.driScreen
= psp
;
883 psp
->destroyScreen
= driswDestroyScreen
;
884 psp
->createDrawable
= driswCreateDrawable
;
885 psp
->swapBuffers
= driswSwapBuffers
;
887 if (psc
->copySubBuffer
)
888 psp
->copySubBuffer
= driswCopySubBuffer
;
894 glx_config_destroy_list(configs
);
896 glx_config_destroy_list(visuals
);
898 psc
->core
->destroyScreen(psc
->driScreen
);
899 psc
->driScreen
= NULL
;
902 dlclose(psc
->driver
);
903 glx_screen_cleanup(&psc
->base
);
906 CriticalErrorMessageF("failed to load driver: %s\n", SWRAST_DRIVER_NAME
);
911 /* Called from __glXFreeDisplayPrivate.
914 driswDestroyDisplay(__GLXDRIdisplay
* dpy
)
920 * Allocate, initialize and return a __DRIdisplayPrivate object.
921 * This is called from __glXInitialize() when we are given a new
924 _X_HIDDEN __GLXDRIdisplay
*
925 driswCreateDisplay(Display
* dpy
)
927 struct drisw_display
*pdpyp
;
929 pdpyp
= malloc(sizeof *pdpyp
);
933 pdpyp
->base
.destroyDisplay
= driswDestroyDisplay
;
934 pdpyp
->base
.createScreen
= driswCreateScreen
;
939 #endif /* GLX_DIRECT_RENDERING */