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)
26 #include <xcb/xproto.h>
29 #include <X11/Xlib-xcb.h>
30 #include "glxclient.h"
32 #include "dri_common.h"
33 #include "drisw_priv.h"
34 #include <X11/extensions/shmproto.h>
37 static int xshm_error
= 0;
38 static int xshm_opcode
= -1;
41 * Catches potential Xlib errors.
44 handle_xerror(Display
*dpy
, XErrorEvent
*event
)
48 assert(xshm_opcode
!= -1);
49 if (event
->request_code
!= xshm_opcode
)
52 xshm_error
= event
->error_code
;
57 XCreateDrawable(struct drisw_drawable
* pdp
, int shmid
, Display
* dpy
)
60 XDestroyImage(pdp
->ximage
);
62 if ((pdp
->shminfo
.shmid
> 0) && (shmid
!= pdp
->shminfo
.shmid
))
63 XShmDetach(dpy
, &pdp
->shminfo
);
66 if (!xshm_error
&& shmid
>= 0) {
67 pdp
->shminfo
.shmid
= shmid
;
68 pdp
->ximage
= XShmCreateImage(dpy
,
73 &pdp
->shminfo
, /* shminfo */
74 0, 0); /* width, height */
75 if (pdp
->ximage
!= NULL
) {
76 int (*old_handler
)(Display
*, XErrorEvent
*);
78 /* dispatch pending errors */
81 old_handler
= XSetErrorHandler(handle_xerror
);
82 /* This may trigger the X protocol error we're ready to catch: */
83 XShmAttach(dpy
, &pdp
->shminfo
);
87 /* we are on a remote display, this error is normal, don't print it */
88 XDestroyImage(pdp
->ximage
);
92 (void) XSetErrorHandler(old_handler
);
96 if (pdp
->ximage
== NULL
) {
97 pdp
->shminfo
.shmid
= -1;
98 pdp
->ximage
= XCreateImage(dpy
,
101 ZPixmap
, 0, /* format, offset */
103 0, 0, /* width, height */
105 0); /* bytes_per_line */
109 * swrast does not handle 24-bit depth with 24 bpp, so let X do the
110 * the conversion for us.
112 if (pdp
->ximage
->bits_per_pixel
== 24)
113 pdp
->ximage
->bits_per_pixel
= 32;
119 XDestroyDrawable(struct drisw_drawable
* pdp
, Display
* dpy
, XID drawable
)
122 XDestroyImage(pdp
->ximage
);
124 if (pdp
->shminfo
.shmid
> 0)
125 XShmDetach(dpy
, &pdp
->shminfo
);
127 XFreeGC(dpy
, pdp
->gc
);
131 * swrast loader functions
135 swrastGetDrawableInfo(__DRIdrawable
* draw
,
136 int *x
, int *y
, int *w
, int *h
,
139 struct drisw_drawable
*pdp
= loaderPrivate
;
140 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
141 Display
*dpy
= pdraw
->psc
->dpy
;
145 unsigned uw
, uh
, bw
, depth
;
147 drawable
= pdraw
->xDrawable
;
149 XGetGeometry(dpy
, drawable
, &root
, x
, y
, &uw
, &uh
, &bw
, &depth
);
155 * Align renderbuffer pitch.
157 * This should be chosen by the driver and the loader (libGL, xserver/glx)
158 * should use the driver provided pitch.
160 * It seems that the xorg loader (that is the xserver loading swrast_dri for
161 * indirect rendering, not client-side libGL) requires that the pitch is
162 * exactly the image width padded to 32 bits. XXX
164 * The above restriction can probably be overcome by using ScratchPixmap and
165 * CopyArea in the xserver, similar to ShmPutImage, and setting the width of
166 * the scratch pixmap to 'pitch / cpp'.
169 bytes_per_line(unsigned pitch_bits
, unsigned mul
)
171 unsigned mask
= mul
- 1;
173 return ((pitch_bits
+ mask
) & ~mask
) / 8;
177 swrastXPutImage(__DRIdrawable
* draw
, int op
,
178 int srcx
, int srcy
, int x
, int y
,
179 int w
, int h
, int stride
,
180 int shmid
, char *data
, void *loaderPrivate
)
182 struct drisw_drawable
*pdp
= loaderPrivate
;
183 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
184 Display
*dpy
= pdraw
->psc
->dpy
;
189 if (!pdp
->ximage
|| shmid
!= pdp
->shminfo
.shmid
) {
190 if (!XCreateDrawable(pdp
, shmid
, dpy
))
194 drawable
= pdraw
->xDrawable
;
195 ximage
= pdp
->ximage
;
196 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
199 ximage
->width
= ximage
->bytes_per_line
/ ((ximage
->bits_per_pixel
+ 7)/ 8);
202 if (pdp
->shminfo
.shmid
>= 0) {
203 XShmPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
, False
);
206 XPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
);
212 swrastPutImageShm(__DRIdrawable
* draw
, int op
,
213 int x
, int y
, int w
, int h
, int stride
,
214 int shmid
, char *shmaddr
, unsigned offset
,
217 struct drisw_drawable
*pdp
= loaderPrivate
;
219 pdp
->shminfo
.shmaddr
= shmaddr
;
220 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, shmid
,
221 shmaddr
+ offset
, loaderPrivate
);
225 swrastPutImageShm2(__DRIdrawable
* draw
, int op
,
227 int w
, int h
, int stride
,
228 int shmid
, char *shmaddr
, unsigned offset
,
231 struct drisw_drawable
*pdp
= loaderPrivate
;
233 pdp
->shminfo
.shmaddr
= shmaddr
;
234 swrastXPutImage(draw
, op
, x
, 0, x
, y
, w
, h
, stride
, shmid
,
235 shmaddr
+ offset
, loaderPrivate
);
239 swrastPutImage2(__DRIdrawable
* draw
, int op
,
240 int x
, int y
, int w
, int h
, int stride
,
241 char *data
, void *loaderPrivate
)
243 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, -1,
244 data
, loaderPrivate
);
248 swrastPutImage(__DRIdrawable
* draw
, int op
,
249 int x
, int y
, int w
, int h
,
250 char *data
, void *loaderPrivate
)
252 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, 0, -1,
253 data
, loaderPrivate
);
257 swrastGetImage2(__DRIdrawable
* read
,
258 int x
, int y
, int w
, int h
, int stride
,
259 char *data
, void *loaderPrivate
)
261 struct drisw_drawable
*prp
= loaderPrivate
;
262 __GLXDRIdrawable
*pread
= &(prp
->base
);
263 Display
*dpy
= pread
->psc
->dpy
;
267 if (!prp
->ximage
|| prp
->shminfo
.shmid
>= 0) {
268 if (!XCreateDrawable(prp
, -1, dpy
))
272 readable
= pread
->xDrawable
;
274 ximage
= prp
->ximage
;
278 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
280 XGetSubImage(dpy
, readable
, x
, y
, w
, h
, ~0L, ZPixmap
, ximage
, 0, 0);
286 swrastGetImage(__DRIdrawable
* read
,
287 int x
, int y
, int w
, int h
,
288 char *data
, void *loaderPrivate
)
290 swrastGetImage2(read
, x
, y
, w
, h
, 0, data
, loaderPrivate
);
294 swrastGetImageShm2(__DRIdrawable
* read
,
295 int x
, int y
, int w
, int h
,
296 int shmid
, void *loaderPrivate
)
298 struct drisw_drawable
*prp
= loaderPrivate
;
299 __GLXDRIdrawable
*pread
= &(prp
->base
);
300 Display
*dpy
= pread
->psc
->dpy
;
304 if (!prp
->ximage
|| shmid
!= prp
->shminfo
.shmid
) {
305 if (!XCreateDrawable(prp
, shmid
, dpy
))
309 if (prp
->shminfo
.shmid
== -1)
311 readable
= pread
->xDrawable
;
313 ximage
= prp
->ximage
;
314 ximage
->data
= prp
->shminfo
.shmaddr
; /* no offset */
317 ximage
->bytes_per_line
= bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
319 XShmGetImage(dpy
, readable
, ximage
, x
, y
, ~0L);
324 swrastGetImageShm(__DRIdrawable
* read
,
325 int x
, int y
, int w
, int h
,
326 int shmid
, void *loaderPrivate
)
328 swrastGetImageShm2(read
, x
, y
, w
, h
, shmid
, loaderPrivate
);
331 static const __DRIswrastLoaderExtension swrastLoaderExtension_shm
= {
332 .base
= {__DRI_SWRAST_LOADER
, 6 },
334 .getDrawableInfo
= swrastGetDrawableInfo
,
335 .putImage
= swrastPutImage
,
336 .getImage
= swrastGetImage
,
337 .putImage2
= swrastPutImage2
,
338 .getImage2
= swrastGetImage2
,
339 .putImageShm
= swrastPutImageShm
,
340 .getImageShm
= swrastGetImageShm
,
341 .putImageShm2
= swrastPutImageShm2
,
342 .getImageShm2
= swrastGetImageShm2
,
345 static const __DRIextension
*loader_extensions_shm
[] = {
346 &swrastLoaderExtension_shm
.base
,
350 static const __DRIswrastLoaderExtension swrastLoaderExtension
= {
351 .base
= {__DRI_SWRAST_LOADER
, 3 },
353 .getDrawableInfo
= swrastGetDrawableInfo
,
354 .putImage
= swrastPutImage
,
355 .getImage
= swrastGetImage
,
356 .putImage2
= swrastPutImage2
,
357 .getImage2
= swrastGetImage2
,
360 static const __DRIextension
*loader_extensions_noshm
[] = {
361 &swrastLoaderExtension
.base
,
370 drisw_destroy_context(struct glx_context
*context
)
372 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
373 struct drisw_screen
*psc
= (struct drisw_screen
*) context
->psc
;
375 driReleaseDrawables(&pcp
->base
);
377 free((char *) context
->extensions
);
379 (*psc
->core
->destroyContext
) (pcp
->driContext
);
385 drisw_bind_context(struct glx_context
*context
, struct glx_context
*old
,
386 GLXDrawable draw
, GLXDrawable read
)
388 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
389 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
390 struct drisw_drawable
*pdraw
, *pread
;
392 pdraw
= (struct drisw_drawable
*) driFetchDrawable(context
, draw
);
393 pread
= (struct drisw_drawable
*) driFetchDrawable(context
, read
);
395 driReleaseDrawables(&pcp
->base
);
397 if ((*psc
->core
->bindContext
) (pcp
->driContext
,
398 pdraw
? pdraw
->driDrawable
: NULL
,
399 pread
? pread
->driDrawable
: NULL
))
402 return GLXBadContext
;
406 drisw_unbind_context(struct glx_context
*context
, struct glx_context
*new)
408 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
409 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
411 (*psc
->core
->unbindContext
) (pcp
->driContext
);
415 drisw_bind_tex_image(Display
* dpy
,
416 GLXDrawable drawable
,
417 int buffer
, const int *attrib_list
)
419 struct glx_context
*gc
= __glXGetCurrentContext();
420 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
421 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
422 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
423 struct drisw_screen
*psc
;
425 __glXInitialize(dpy
);
428 psc
= (struct drisw_screen
*) base
->psc
;
433 if (psc
->texBuffer
->base
.version
>= 2 &&
434 psc
->texBuffer
->setTexBuffer2
!= NULL
) {
435 (*psc
->texBuffer
->setTexBuffer2
) (pcp
->driContext
,
436 pdraw
->base
.textureTarget
,
437 pdraw
->base
.textureFormat
,
441 (*psc
->texBuffer
->setTexBuffer
) (pcp
->driContext
,
442 pdraw
->base
.textureTarget
,
449 drisw_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
451 struct glx_context
*gc
= __glXGetCurrentContext();
452 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
453 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
454 struct glx_display
*dpyPriv
= __glXInitialize(dpy
);
455 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
456 struct drisw_screen
*psc
;
458 if (dpyPriv
!= NULL
&& pdraw
!= NULL
) {
459 psc
= (struct drisw_screen
*) base
->psc
;
464 if (psc
->texBuffer
->base
.version
>= 3 &&
465 psc
->texBuffer
->releaseTexBuffer
!= NULL
) {
466 (*psc
->texBuffer
->releaseTexBuffer
) (pcp
->driContext
,
467 pdraw
->base
.textureTarget
,
473 static const struct glx_context_vtable drisw_context_vtable
= {
474 .destroy
= drisw_destroy_context
,
475 .bind
= drisw_bind_context
,
476 .unbind
= drisw_unbind_context
,
479 .use_x_font
= DRI_glXUseXFont
,
480 .bind_tex_image
= drisw_bind_tex_image
,
481 .release_tex_image
= drisw_release_tex_image
,
482 .get_proc_address
= NULL
,
485 static struct glx_context
*
486 drisw_create_context(struct glx_screen
*base
,
487 struct glx_config
*config_base
,
488 struct glx_context
*shareList
, int renderType
)
490 struct drisw_context
*pcp
, *pcp_shared
;
491 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
492 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
493 __DRIcontext
*shared
= NULL
;
495 if (!psc
->base
.driScreen
)
498 /* Check the renderType value */
499 if (!validate_renderType_against_config(config_base
, renderType
))
503 /* If the shareList context is not a DRISW context, we cannot possibly
504 * create a DRISW context that shares it.
506 if (shareList
->vtable
->destroy
!= drisw_destroy_context
) {
510 pcp_shared
= (struct drisw_context
*) shareList
;
511 shared
= pcp_shared
->driContext
;
514 pcp
= calloc(1, sizeof *pcp
);
518 if (!glx_context_init(&pcp
->base
, &psc
->base
, &config
->base
)) {
523 pcp
->base
.renderType
= renderType
;
526 (*psc
->core
->createNewContext
) (psc
->driScreen
,
527 config
->driConfig
, shared
, pcp
);
528 if (pcp
->driContext
== NULL
) {
533 pcp
->base
.vtable
= &drisw_context_vtable
;
538 static struct glx_context
*
539 drisw_create_context_attribs(struct glx_screen
*base
,
540 struct glx_config
*config_base
,
541 struct glx_context
*shareList
,
542 unsigned num_attribs
,
543 const uint32_t *attribs
,
546 struct drisw_context
*pcp
, *pcp_shared
;
547 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
548 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
549 __DRIcontext
*shared
= NULL
;
558 uint32_t ctx_attribs
[2 * 5];
559 unsigned num_ctx_attribs
= 0;
561 if (!psc
->base
.driScreen
)
564 if (psc
->swrast
->base
.version
< 3)
567 /* Remap the GLX tokens to DRI2 tokens.
569 if (!dri2_convert_glx_attribs(num_attribs
, attribs
,
570 &major_ver
, &minor_ver
, &renderType
, &flags
,
571 &api
, &reset
, &release
, error
))
574 if (!dri2_check_no_error(flags
, shareList
, major_ver
, error
))
577 /* Check the renderType value */
578 if (!validate_renderType_against_config(config_base
, renderType
)) {
582 if (reset
!= __DRI_CTX_RESET_NO_NOTIFICATION
)
585 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
&&
586 release
!= __DRI_CTX_RELEASE_BEHAVIOR_NONE
)
590 pcp_shared
= (struct drisw_context
*) shareList
;
591 shared
= pcp_shared
->driContext
;
594 pcp
= calloc(1, sizeof *pcp
);
598 if (!glx_context_init(&pcp
->base
, &psc
->base
, config_base
)) {
603 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
604 ctx_attribs
[num_ctx_attribs
++] = major_ver
;
605 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
606 ctx_attribs
[num_ctx_attribs
++] = minor_ver
;
607 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
) {
608 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
609 ctx_attribs
[num_ctx_attribs
++] = release
;
613 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_FLAGS
;
615 /* The current __DRI_CTX_FLAG_* values are identical to the
616 * GLX_CONTEXT_*_BIT values.
618 ctx_attribs
[num_ctx_attribs
++] = flags
;
620 if (flags
& __DRI_CTX_FLAG_NO_ERROR
)
621 pcp
->base
.noError
= GL_TRUE
;
624 pcp
->base
.renderType
= renderType
;
627 (*psc
->swrast
->createContextAttribs
) (psc
->driScreen
,
629 config
? config
->driConfig
: 0,
635 if (pcp
->driContext
== NULL
) {
640 pcp
->base
.vtable
= &drisw_context_vtable
;
646 driswDestroyDrawable(__GLXDRIdrawable
* pdraw
)
648 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
649 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
651 (*psc
->core
->destroyDrawable
) (pdp
->driDrawable
);
653 XDestroyDrawable(pdp
, pdraw
->psc
->dpy
, pdraw
->drawable
);
657 static __GLXDRIdrawable
*
658 driswCreateDrawable(struct glx_screen
*base
, XID xDrawable
,
659 GLXDrawable drawable
, struct glx_config
*modes
)
661 struct drisw_drawable
*pdp
;
662 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) modes
;
663 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
664 const __DRIswrastExtension
*swrast
= psc
->swrast
;
665 Display
*dpy
= psc
->base
.dpy
;
667 pdp
= calloc(1, sizeof(*pdp
));
671 pdp
->base
.xDrawable
= xDrawable
;
672 pdp
->base
.drawable
= drawable
;
673 pdp
->base
.psc
= &psc
->base
;
675 pdp
->gc
= XCreateGC(dpy
, xDrawable
, 0, NULL
);
678 /* Use the visual depth, if this fbconfig corresponds to a visual */
679 if (pdp
->config
->visualID
!= 0) {
681 XVisualInfo
*visinfo
, template;
683 template.visualid
= pdp
->config
->visualID
;
684 template.screen
= pdp
->config
->screen
;
685 visinfo
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
,
686 &template, &matches
);
688 if (visinfo
&& matches
) {
689 pdp
->xDepth
= visinfo
->depth
;
694 /* Otherwise, or if XGetVisualInfo failed, ask the server */
695 if (pdp
->xDepth
== 0) {
698 unsigned uw
, uh
, bw
, depth
;
700 XGetGeometry(dpy
, xDrawable
, &root
, &x
, &y
, &uw
, &uh
, &bw
, &depth
);
704 /* Create a new drawable */
706 (*swrast
->createNewDrawable
) (psc
->driScreen
, config
->driConfig
, pdp
);
708 if (!pdp
->driDrawable
) {
709 XDestroyDrawable(pdp
, psc
->base
.dpy
, xDrawable
);
714 pdp
->base
.destroyDrawable
= driswDestroyDrawable
;
720 driswSwapBuffers(__GLXDRIdrawable
* pdraw
,
721 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
724 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
725 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
735 (*psc
->core
->swapBuffers
) (pdp
->driDrawable
);
741 driswCopySubBuffer(__GLXDRIdrawable
* pdraw
,
742 int x
, int y
, int width
, int height
, Bool flush
)
744 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
745 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
751 (*psc
->copySubBuffer
->copySubBuffer
) (pdp
->driDrawable
,
752 x
, y
, width
, height
);
756 driswDestroyScreen(struct glx_screen
*base
)
758 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
760 /* Free the direct rendering per screen data */
761 (*psc
->core
->destroyScreen
) (psc
->driScreen
);
762 driDestroyConfigs(psc
->driver_configs
);
763 psc
->driScreen
= NULL
;
765 dlclose(psc
->driver
);
769 #define SWRAST_DRIVER_NAME "swrast"
771 static const struct glx_screen_vtable drisw_screen_vtable
= {
772 .create_context
= drisw_create_context
,
773 .create_context_attribs
= drisw_create_context_attribs
,
774 .query_renderer_integer
= drisw_query_renderer_integer
,
775 .query_renderer_string
= drisw_query_renderer_string
,
779 driswBindExtensions(struct drisw_screen
*psc
, const __DRIextension
**extensions
)
783 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_make_current_read");
785 if (psc
->swrast
->base
.version
>= 3) {
786 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context");
787 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context_profile");
789 /* DRISW version >= 2 implies support for OpenGL ES.
791 __glXEnableDirectExtension(&psc
->base
,
792 "GLX_EXT_create_context_es_profile");
793 __glXEnableDirectExtension(&psc
->base
,
794 "GLX_EXT_create_context_es2_profile");
797 if (psc
->copySubBuffer
)
798 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
800 /* FIXME: Figure out what other extensions can be ported here from dri2. */
801 for (i
= 0; extensions
[i
]; i
++) {
802 if ((strcmp(extensions
[i
]->name
, __DRI_TEX_BUFFER
) == 0)) {
803 psc
->texBuffer
= (__DRItexBufferExtension
*) extensions
[i
];
804 __glXEnableDirectExtension(&psc
->base
, "GLX_EXT_texture_from_pixmap");
806 /* DRISW version 3 is also required because GLX_MESA_query_renderer
807 * requires GLX_ARB_create_context_profile.
809 if (psc
->swrast
->base
.version
>= 3
810 && strcmp(extensions
[i
]->name
, __DRI2_RENDERER_QUERY
) == 0) {
811 psc
->rendererQuery
= (__DRI2rendererQueryExtension
*) extensions
[i
];
812 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_query_renderer");
815 if (strcmp(extensions
[i
]->name
, __DRI2_ROBUSTNESS
) == 0)
816 __glXEnableDirectExtension(&psc
->base
,
817 "GLX_ARB_create_context_robustness");
819 if (strcmp(extensions
[i
]->name
, __DRI2_FLUSH_CONTROL
) == 0) {
820 __glXEnableDirectExtension(&psc
->base
,
821 "GLX_ARB_context_flush_control");
827 check_xshm(Display
*dpy
)
829 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
830 xcb_void_cookie_t cookie
;
831 xcb_generic_error_t
*error
;
835 if (!XQueryExtension(dpy
, "MIT-SHM", &xshm_opcode
, &ignore
, &ignore
))
838 cookie
= xcb_shm_detach_checked(c
, 0);
839 if ((error
= xcb_request_check(c
, cookie
))) {
840 /* BadRequest means we're a remote client. If we were local we'd
841 * expect BadValue since 'info' has an invalid segment name.
843 if (error
->error_code
== BadRequest
)
851 static struct glx_screen
*
852 driswCreateScreen(int screen
, struct glx_display
*priv
)
855 const __DRIconfig
**driver_configs
;
856 const __DRIextension
**extensions
;
857 struct drisw_screen
*psc
;
858 struct glx_config
*configs
= NULL
, *visuals
= NULL
;
860 const __DRIextension
**loader_extensions_local
;
862 psc
= calloc(1, sizeof *psc
);
866 if (!glx_screen_init(&psc
->base
, screen
, priv
)) {
871 extensions
= driOpenDriver(SWRAST_DRIVER_NAME
, &psc
->driver
);
872 if (extensions
== NULL
)
875 if (!check_xshm(psc
->base
.dpy
))
876 loader_extensions_local
= loader_extensions_noshm
;
878 loader_extensions_local
= loader_extensions_shm
;
880 for (i
= 0; extensions
[i
]; i
++) {
881 if (strcmp(extensions
[i
]->name
, __DRI_CORE
) == 0)
882 psc
->core
= (__DRIcoreExtension
*) extensions
[i
];
883 if (strcmp(extensions
[i
]->name
, __DRI_SWRAST
) == 0)
884 psc
->swrast
= (__DRIswrastExtension
*) extensions
[i
];
885 if (strcmp(extensions
[i
]->name
, __DRI_COPY_SUB_BUFFER
) == 0)
886 psc
->copySubBuffer
= (__DRIcopySubBufferExtension
*) extensions
[i
];
889 if (psc
->core
== NULL
|| psc
->swrast
== NULL
) {
890 ErrorMessageF("core dri extension not found\n");
894 if (psc
->swrast
->base
.version
>= 4) {
896 psc
->swrast
->createNewScreen2(screen
, loader_extensions_local
,
898 &driver_configs
, psc
);
901 psc
->swrast
->createNewScreen(screen
, loader_extensions_local
,
902 &driver_configs
, psc
);
904 if (psc
->driScreen
== NULL
) {
905 ErrorMessageF("failed to create dri screen\n");
909 extensions
= psc
->core
->getExtensions(psc
->driScreen
);
910 driswBindExtensions(psc
, extensions
);
912 configs
= driConvertConfigs(psc
->core
, psc
->base
.configs
, driver_configs
);
913 visuals
= driConvertConfigs(psc
->core
, psc
->base
.visuals
, driver_configs
);
915 if (!configs
|| !visuals
) {
916 ErrorMessageF("No matching fbConfigs or visuals found\n");
920 glx_config_destroy_list(psc
->base
.configs
);
921 psc
->base
.configs
= configs
;
922 glx_config_destroy_list(psc
->base
.visuals
);
923 psc
->base
.visuals
= visuals
;
925 psc
->driver_configs
= driver_configs
;
927 psc
->base
.vtable
= &drisw_screen_vtable
;
929 psc
->base
.driScreen
= psp
;
930 psp
->destroyScreen
= driswDestroyScreen
;
931 psp
->createDrawable
= driswCreateDrawable
;
932 psp
->swapBuffers
= driswSwapBuffers
;
934 if (psc
->copySubBuffer
)
935 psp
->copySubBuffer
= driswCopySubBuffer
;
941 glx_config_destroy_list(configs
);
943 glx_config_destroy_list(visuals
);
945 psc
->core
->destroyScreen(psc
->driScreen
);
946 psc
->driScreen
= NULL
;
949 dlclose(psc
->driver
);
950 glx_screen_cleanup(&psc
->base
);
953 CriticalErrorMessageF("failed to load driver: %s\n", SWRAST_DRIVER_NAME
);
958 /* Called from __glXFreeDisplayPrivate.
961 driswDestroyDisplay(__GLXDRIdisplay
* dpy
)
967 * Allocate, initialize and return a __DRIdisplayPrivate object.
968 * This is called from __glXInitialize() when we are given a new
971 _X_HIDDEN __GLXDRIdisplay
*
972 driswCreateDisplay(Display
* dpy
)
974 struct drisw_display
*pdpyp
;
976 pdpyp
= malloc(sizeof *pdpyp
);
980 pdpyp
->base
.destroyDisplay
= driswDestroyDisplay
;
981 pdpyp
->base
.createScreen
= driswCreateScreen
;
986 #endif /* GLX_DIRECT_RENDERING */