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
)
79 xshm_error
= event
->error_code
;
84 XCreateDrawable(struct drisw_drawable
* pdp
, int shmid
, Display
* dpy
)
87 XDestroyImage(pdp
->ximage
);
91 if (!xshm_error
&& shmid
>= 0) {
92 pdp
->shminfo
.shmid
= shmid
;
93 pdp
->ximage
= XShmCreateImage(dpy
,
98 &pdp
->shminfo
, /* shminfo */
99 0, 0); /* width, height */
100 if (pdp
->ximage
!= NULL
) {
101 int (*old_handler
)(Display
*, XErrorEvent
*);
103 /* dispatch pending errors */
106 old_handler
= XSetErrorHandler(handle_xerror
);
107 /* This may trigger the X protocol error we're ready to catch: */
108 XShmAttach(dpy
, &pdp
->shminfo
);
112 /* we are on a remote display, this error is normal, don't print it */
113 XDestroyImage(pdp
->ximage
);
117 (void) XSetErrorHandler(old_handler
);
121 if (pdp
->ximage
== NULL
) {
122 pdp
->shminfo
.shmid
= -1;
123 pdp
->ximage
= XCreateImage(dpy
,
124 pdp
->visinfo
->visual
,
126 ZPixmap
, 0, /* format, offset */
128 0, 0, /* width, height */
130 0); /* bytes_per_line */
134 * swrast does not handle 24-bit depth with 24 bpp, so let X do the
135 * the conversion for us.
137 if (pdp
->ximage
->bits_per_pixel
== 24)
138 pdp
->ximage
->bits_per_pixel
= 32;
144 XDestroyDrawable(struct drisw_drawable
* pdp
, Display
* dpy
, XID drawable
)
147 XDestroyImage(pdp
->ximage
);
149 if (pdp
->shminfo
.shmid
> 0)
150 XShmDetach(dpy
, &pdp
->shminfo
);
154 XFreeGC(dpy
, pdp
->gc
);
155 XFreeGC(dpy
, pdp
->swapgc
);
159 * swrast loader functions
163 swrastGetDrawableInfo(__DRIdrawable
* draw
,
164 int *x
, int *y
, int *w
, int *h
,
167 struct drisw_drawable
*pdp
= loaderPrivate
;
168 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
169 Display
*dpy
= pdraw
->psc
->dpy
;
173 unsigned uw
, uh
, bw
, depth
;
175 drawable
= pdraw
->xDrawable
;
177 XGetGeometry(dpy
, drawable
, &root
, x
, y
, &uw
, &uh
, &bw
, &depth
);
183 * Align renderbuffer pitch.
185 * This should be chosen by the driver and the loader (libGL, xserver/glx)
186 * should use the driver provided pitch.
188 * It seems that the xorg loader (that is the xserver loading swrast_dri for
189 * indirect rendering, not client-side libGL) requires that the pitch is
190 * exactly the image width padded to 32 bits. XXX
192 * The above restriction can probably be overcome by using ScratchPixmap and
193 * CopyArea in the xserver, similar to ShmPutImage, and setting the width of
194 * the scratch pixmap to 'pitch / cpp'.
197 bytes_per_line(unsigned pitch_bits
, unsigned mul
)
199 unsigned mask
= mul
- 1;
201 return ((pitch_bits
+ mask
) & ~mask
) / 8;
205 swrastXPutImage(__DRIdrawable
* draw
, int op
,
206 int srcx
, int srcy
, int x
, int y
,
207 int w
, int h
, int stride
,
208 int shmid
, char *data
, void *loaderPrivate
)
210 struct drisw_drawable
*pdp
= loaderPrivate
;
211 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
212 Display
*dpy
= pdraw
->psc
->dpy
;
217 if (!pdp
->ximage
|| shmid
!= pdp
->shminfo
.shmid
) {
218 if (!XCreateDrawable(pdp
, shmid
, dpy
))
223 case __DRI_SWRAST_IMAGE_OP_DRAW
:
226 case __DRI_SWRAST_IMAGE_OP_SWAP
:
233 drawable
= pdraw
->xDrawable
;
234 ximage
= pdp
->ximage
;
235 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
238 if (pdp
->shminfo
.shmid
>= 0) {
239 ximage
->width
= ximage
->bytes_per_line
/ ((ximage
->bits_per_pixel
+ 7)/ 8);
241 XShmPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
, False
);
246 XPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
);
252 swrastPutImageShm(__DRIdrawable
* draw
, int op
,
253 int x
, int y
, int w
, int h
, int stride
,
254 int shmid
, char *shmaddr
, unsigned offset
,
257 struct drisw_drawable
*pdp
= loaderPrivate
;
259 pdp
->shminfo
.shmaddr
= shmaddr
;
260 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, shmid
,
261 shmaddr
+ offset
, loaderPrivate
);
265 swrastPutImageShm2(__DRIdrawable
* draw
, int op
,
267 int w
, int h
, int stride
,
268 int shmid
, char *shmaddr
, unsigned offset
,
271 struct drisw_drawable
*pdp
= loaderPrivate
;
273 pdp
->shminfo
.shmaddr
= shmaddr
;
274 swrastXPutImage(draw
, op
, x
, 0, x
, y
, w
, h
, stride
, shmid
,
275 shmaddr
+ offset
, loaderPrivate
);
279 swrastPutImage2(__DRIdrawable
* draw
, int op
,
280 int x
, int y
, int w
, int h
, int stride
,
281 char *data
, void *loaderPrivate
)
283 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, -1,
284 data
, loaderPrivate
);
288 swrastPutImage(__DRIdrawable
* draw
, int op
,
289 int x
, int y
, int w
, int h
,
290 char *data
, void *loaderPrivate
)
292 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, 0, -1,
293 data
, loaderPrivate
);
297 swrastGetImage2(__DRIdrawable
* read
,
298 int x
, int y
, int w
, int h
, int stride
,
299 char *data
, void *loaderPrivate
)
301 struct drisw_drawable
*prp
= loaderPrivate
;
302 __GLXDRIdrawable
*pread
= &(prp
->base
);
303 Display
*dpy
= pread
->psc
->dpy
;
307 if (!prp
->ximage
|| prp
->shminfo
.shmid
>= 0) {
308 if (!XCreateDrawable(prp
, -1, dpy
))
312 readable
= pread
->xDrawable
;
314 ximage
= prp
->ximage
;
318 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
320 XGetSubImage(dpy
, readable
, x
, y
, w
, h
, ~0L, ZPixmap
, ximage
, 0, 0);
326 swrastGetImage(__DRIdrawable
* read
,
327 int x
, int y
, int w
, int h
,
328 char *data
, void *loaderPrivate
)
330 swrastGetImage2(read
, x
, y
, w
, h
, 0, data
, loaderPrivate
);
334 swrastGetImageShm(__DRIdrawable
* read
,
335 int x
, int y
, int w
, int h
,
336 int shmid
, void *loaderPrivate
)
338 struct drisw_drawable
*prp
= loaderPrivate
;
339 __GLXDRIdrawable
*pread
= &(prp
->base
);
340 Display
*dpy
= pread
->psc
->dpy
;
344 if (!prp
->ximage
|| shmid
!= prp
->shminfo
.shmid
) {
345 if (!XCreateDrawable(prp
, shmid
, dpy
))
348 readable
= pread
->xDrawable
;
350 ximage
= prp
->ximage
;
351 ximage
->data
= prp
->shminfo
.shmaddr
; /* no offset */
354 ximage
->bytes_per_line
= bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
356 XShmGetImage(dpy
, readable
, ximage
, x
, y
, ~0L);
359 static const __DRIswrastLoaderExtension swrastLoaderExtension_shm
= {
360 .base
= {__DRI_SWRAST_LOADER
, 5 },
362 .getDrawableInfo
= swrastGetDrawableInfo
,
363 .putImage
= swrastPutImage
,
364 .getImage
= swrastGetImage
,
365 .putImage2
= swrastPutImage2
,
366 .getImage2
= swrastGetImage2
,
367 .putImageShm
= swrastPutImageShm
,
368 .getImageShm
= swrastGetImageShm
,
369 .putImageShm2
= swrastPutImageShm2
,
372 static const __DRIextension
*loader_extensions_shm
[] = {
373 &swrastLoaderExtension_shm
.base
,
377 static const __DRIswrastLoaderExtension swrastLoaderExtension
= {
378 .base
= {__DRI_SWRAST_LOADER
, 3 },
380 .getDrawableInfo
= swrastGetDrawableInfo
,
381 .putImage
= swrastPutImage
,
382 .getImage
= swrastGetImage
,
383 .putImage2
= swrastPutImage2
,
384 .getImage2
= swrastGetImage2
,
387 static const __DRIextension
*loader_extensions_noshm
[] = {
388 &swrastLoaderExtension
.base
,
397 drisw_destroy_context(struct glx_context
*context
)
399 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
400 struct drisw_screen
*psc
= (struct drisw_screen
*) context
->psc
;
402 driReleaseDrawables(&pcp
->base
);
404 free((char *) context
->extensions
);
406 (*psc
->core
->destroyContext
) (pcp
->driContext
);
412 drisw_bind_context(struct glx_context
*context
, struct glx_context
*old
,
413 GLXDrawable draw
, GLXDrawable read
)
415 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
416 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
417 struct drisw_drawable
*pdraw
, *pread
;
419 pdraw
= (struct drisw_drawable
*) driFetchDrawable(context
, draw
);
420 pread
= (struct drisw_drawable
*) driFetchDrawable(context
, read
);
422 driReleaseDrawables(&pcp
->base
);
424 if ((*psc
->core
->bindContext
) (pcp
->driContext
,
425 pdraw
? pdraw
->driDrawable
: NULL
,
426 pread
? pread
->driDrawable
: NULL
))
429 return GLXBadContext
;
433 drisw_unbind_context(struct glx_context
*context
, struct glx_context
*new)
435 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
436 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
438 (*psc
->core
->unbindContext
) (pcp
->driContext
);
442 drisw_bind_tex_image(Display
* dpy
,
443 GLXDrawable drawable
,
444 int buffer
, const int *attrib_list
)
446 struct glx_context
*gc
= __glXGetCurrentContext();
447 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
448 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
449 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
450 struct drisw_screen
*psc
;
452 __glXInitialize(dpy
);
455 psc
= (struct drisw_screen
*) base
->psc
;
460 if (psc
->texBuffer
->base
.version
>= 2 &&
461 psc
->texBuffer
->setTexBuffer2
!= NULL
) {
462 (*psc
->texBuffer
->setTexBuffer2
) (pcp
->driContext
,
463 pdraw
->base
.textureTarget
,
464 pdraw
->base
.textureFormat
,
468 (*psc
->texBuffer
->setTexBuffer
) (pcp
->driContext
,
469 pdraw
->base
.textureTarget
,
476 drisw_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
478 struct glx_context
*gc
= __glXGetCurrentContext();
479 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
480 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
481 struct glx_display
*dpyPriv
= __glXInitialize(dpy
);
482 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
483 struct drisw_screen
*psc
;
485 if (dpyPriv
!= NULL
&& pdraw
!= NULL
) {
486 psc
= (struct drisw_screen
*) base
->psc
;
491 if (psc
->texBuffer
->base
.version
>= 3 &&
492 psc
->texBuffer
->releaseTexBuffer
!= NULL
) {
493 (*psc
->texBuffer
->releaseTexBuffer
) (pcp
->driContext
,
494 pdraw
->base
.textureTarget
,
500 static const struct glx_context_vtable drisw_context_vtable
= {
501 .destroy
= drisw_destroy_context
,
502 .bind
= drisw_bind_context
,
503 .unbind
= drisw_unbind_context
,
506 .use_x_font
= DRI_glXUseXFont
,
507 .bind_tex_image
= drisw_bind_tex_image
,
508 .release_tex_image
= drisw_release_tex_image
,
509 .get_proc_address
= NULL
,
512 static struct glx_context
*
513 drisw_create_context(struct glx_screen
*base
,
514 struct glx_config
*config_base
,
515 struct glx_context
*shareList
, int renderType
)
517 struct drisw_context
*pcp
, *pcp_shared
;
518 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
519 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
520 __DRIcontext
*shared
= NULL
;
522 if (!psc
->base
.driScreen
)
525 /* Check the renderType value */
526 if (!validate_renderType_against_config(config_base
, renderType
))
530 /* If the shareList context is not a DRISW context, we cannot possibly
531 * create a DRISW context that shares it.
533 if (shareList
->vtable
->destroy
!= drisw_destroy_context
) {
537 pcp_shared
= (struct drisw_context
*) shareList
;
538 shared
= pcp_shared
->driContext
;
541 pcp
= calloc(1, sizeof *pcp
);
545 if (!glx_context_init(&pcp
->base
, &psc
->base
, &config
->base
)) {
550 pcp
->base
.renderType
= renderType
;
553 (*psc
->core
->createNewContext
) (psc
->driScreen
,
554 config
->driConfig
, shared
, pcp
);
555 if (pcp
->driContext
== NULL
) {
560 pcp
->base
.vtable
= &drisw_context_vtable
;
565 static struct glx_context
*
566 drisw_create_context_attribs(struct glx_screen
*base
,
567 struct glx_config
*config_base
,
568 struct glx_context
*shareList
,
569 unsigned num_attribs
,
570 const uint32_t *attribs
,
573 struct drisw_context
*pcp
, *pcp_shared
;
574 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
575 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
576 __DRIcontext
*shared
= NULL
;
585 uint32_t ctx_attribs
[2 * 5];
586 unsigned num_ctx_attribs
= 0;
588 if (!psc
->base
.driScreen
)
591 if (psc
->swrast
->base
.version
< 3)
594 /* Remap the GLX tokens to DRI2 tokens.
596 if (!dri2_convert_glx_attribs(num_attribs
, attribs
,
597 &major_ver
, &minor_ver
, &renderType
, &flags
,
598 &api
, &reset
, &release
, error
))
601 if (!dri2_check_no_error(flags
, shareList
, major_ver
, error
))
604 /* Check the renderType value */
605 if (!validate_renderType_against_config(config_base
, renderType
)) {
609 if (reset
!= __DRI_CTX_RESET_NO_NOTIFICATION
)
612 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
&&
613 release
!= __DRI_CTX_RELEASE_BEHAVIOR_NONE
)
617 pcp_shared
= (struct drisw_context
*) shareList
;
618 shared
= pcp_shared
->driContext
;
621 pcp
= calloc(1, sizeof *pcp
);
625 if (!glx_context_init(&pcp
->base
, &psc
->base
, config_base
)) {
630 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
631 ctx_attribs
[num_ctx_attribs
++] = major_ver
;
632 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
633 ctx_attribs
[num_ctx_attribs
++] = minor_ver
;
634 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
) {
635 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
636 ctx_attribs
[num_ctx_attribs
++] = release
;
640 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_FLAGS
;
642 /* The current __DRI_CTX_FLAG_* values are identical to the
643 * GLX_CONTEXT_*_BIT values.
645 ctx_attribs
[num_ctx_attribs
++] = flags
;
647 if (flags
& __DRI_CTX_FLAG_NO_ERROR
)
648 pcp
->base
.noError
= GL_TRUE
;
651 pcp
->base
.renderType
= renderType
;
654 (*psc
->swrast
->createContextAttribs
) (psc
->driScreen
,
656 config
? config
->driConfig
: 0,
662 if (pcp
->driContext
== NULL
) {
667 pcp
->base
.vtable
= &drisw_context_vtable
;
673 driswDestroyDrawable(__GLXDRIdrawable
* pdraw
)
675 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
676 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
678 (*psc
->core
->destroyDrawable
) (pdp
->driDrawable
);
680 XDestroyDrawable(pdp
, pdraw
->psc
->dpy
, pdraw
->drawable
);
684 static __GLXDRIdrawable
*
685 driswCreateDrawable(struct glx_screen
*base
, XID xDrawable
,
686 GLXDrawable drawable
, struct glx_config
*modes
)
688 struct drisw_drawable
*pdp
;
689 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) modes
;
690 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
692 const __DRIswrastExtension
*swrast
= psc
->swrast
;
694 pdp
= calloc(1, sizeof(*pdp
));
698 pdp
->base
.xDrawable
= xDrawable
;
699 pdp
->base
.drawable
= drawable
;
700 pdp
->base
.psc
= &psc
->base
;
702 ret
= XCreateGCs(pdp
, psc
->base
.dpy
, xDrawable
, modes
->visualID
);
708 /* Create a new drawable */
710 (*swrast
->createNewDrawable
) (psc
->driScreen
, config
->driConfig
, pdp
);
712 if (!pdp
->driDrawable
) {
713 XDestroyDrawable(pdp
, psc
->base
.dpy
, xDrawable
);
718 pdp
->base
.destroyDrawable
= driswDestroyDrawable
;
724 driswSwapBuffers(__GLXDRIdrawable
* pdraw
,
725 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
728 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
729 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
739 (*psc
->core
->swapBuffers
) (pdp
->driDrawable
);
745 driswCopySubBuffer(__GLXDRIdrawable
* pdraw
,
746 int x
, int y
, int width
, int height
, Bool flush
)
748 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
749 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
755 (*psc
->copySubBuffer
->copySubBuffer
) (pdp
->driDrawable
,
756 x
, y
, width
, height
);
760 driswDestroyScreen(struct glx_screen
*base
)
762 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
764 /* Free the direct rendering per screen data */
765 (*psc
->core
->destroyScreen
) (psc
->driScreen
);
766 driDestroyConfigs(psc
->driver_configs
);
767 psc
->driScreen
= NULL
;
769 dlclose(psc
->driver
);
773 #define SWRAST_DRIVER_NAME "swrast"
775 static const struct glx_screen_vtable drisw_screen_vtable
= {
776 .create_context
= drisw_create_context
,
777 .create_context_attribs
= drisw_create_context_attribs
,
778 .query_renderer_integer
= drisw_query_renderer_integer
,
779 .query_renderer_string
= drisw_query_renderer_string
,
783 driswBindExtensions(struct drisw_screen
*psc
, const __DRIextension
**extensions
)
787 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_make_current_read");
789 if (psc
->swrast
->base
.version
>= 3) {
790 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context");
791 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context_profile");
793 /* DRISW version >= 2 implies support for OpenGL ES.
795 __glXEnableDirectExtension(&psc
->base
,
796 "GLX_EXT_create_context_es_profile");
797 __glXEnableDirectExtension(&psc
->base
,
798 "GLX_EXT_create_context_es2_profile");
801 if (psc
->copySubBuffer
)
802 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
804 /* FIXME: Figure out what other extensions can be ported here from dri2. */
805 for (i
= 0; extensions
[i
]; i
++) {
806 if ((strcmp(extensions
[i
]->name
, __DRI_TEX_BUFFER
) == 0)) {
807 psc
->texBuffer
= (__DRItexBufferExtension
*) extensions
[i
];
808 __glXEnableDirectExtension(&psc
->base
, "GLX_EXT_texture_from_pixmap");
810 /* DRISW version 3 is also required because GLX_MESA_query_renderer
811 * requires GLX_ARB_create_context_profile.
813 if (psc
->swrast
->base
.version
>= 3
814 && strcmp(extensions
[i
]->name
, __DRI2_RENDERER_QUERY
) == 0) {
815 psc
->rendererQuery
= (__DRI2rendererQueryExtension
*) extensions
[i
];
816 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_query_renderer");
818 if (strcmp(extensions
[i
]->name
, __DRI2_FLUSH_CONTROL
) == 0) {
819 __glXEnableDirectExtension(&psc
->base
,
820 "GLX_ARB_context_flush_control");
826 check_xshm(Display
*dpy
)
828 int (*old_handler
)(Display
*, XErrorEvent
*);
831 XShmSegmentInfo info
= { 0, };
833 if (!XQueryExtension(dpy
, "MIT-SHM", &xshm_opcode
, &ignore
, &ignore
))
836 old_handler
= XSetErrorHandler(handle_xerror
);
837 XShmDetach(dpy
, &info
);
839 (void) XSetErrorHandler(old_handler
);
841 /* BadRequest means we're a remote client. If we were local we'd
842 * expect BadValue since 'info' has an invalid segment name.
844 if (xshm_error
== 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 */