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 swrastGetImageShm2(__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
))
307 if (prp
->shminfo
.shmid
== -1)
309 readable
= pread
->xDrawable
;
311 ximage
= prp
->ximage
;
312 ximage
->data
= prp
->shminfo
.shmaddr
; /* no offset */
315 ximage
->bytes_per_line
= bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
317 XShmGetImage(dpy
, readable
, ximage
, x
, y
, ~0L);
322 swrastGetImageShm(__DRIdrawable
* read
,
323 int x
, int y
, int w
, int h
,
324 int shmid
, void *loaderPrivate
)
326 swrastGetImageShm2(read
, x
, y
, w
, h
, shmid
, loaderPrivate
);
329 static const __DRIswrastLoaderExtension swrastLoaderExtension_shm
= {
330 .base
= {__DRI_SWRAST_LOADER
, 6 },
332 .getDrawableInfo
= swrastGetDrawableInfo
,
333 .putImage
= swrastPutImage
,
334 .getImage
= swrastGetImage
,
335 .putImage2
= swrastPutImage2
,
336 .getImage2
= swrastGetImage2
,
337 .putImageShm
= swrastPutImageShm
,
338 .getImageShm
= swrastGetImageShm
,
339 .putImageShm2
= swrastPutImageShm2
,
340 .getImageShm2
= swrastGetImageShm2
,
343 static const __DRIextension
*loader_extensions_shm
[] = {
344 &swrastLoaderExtension_shm
.base
,
348 static const __DRIswrastLoaderExtension swrastLoaderExtension
= {
349 .base
= {__DRI_SWRAST_LOADER
, 3 },
351 .getDrawableInfo
= swrastGetDrawableInfo
,
352 .putImage
= swrastPutImage
,
353 .getImage
= swrastGetImage
,
354 .putImage2
= swrastPutImage2
,
355 .getImage2
= swrastGetImage2
,
358 static const __DRIextension
*loader_extensions_noshm
[] = {
359 &swrastLoaderExtension
.base
,
368 drisw_destroy_context(struct glx_context
*context
)
370 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
371 struct drisw_screen
*psc
= (struct drisw_screen
*) context
->psc
;
373 driReleaseDrawables(&pcp
->base
);
375 free((char *) context
->extensions
);
377 (*psc
->core
->destroyContext
) (pcp
->driContext
);
383 drisw_bind_context(struct glx_context
*context
, struct glx_context
*old
,
384 GLXDrawable draw
, GLXDrawable read
)
386 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
387 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
388 struct drisw_drawable
*pdraw
, *pread
;
390 pdraw
= (struct drisw_drawable
*) driFetchDrawable(context
, draw
);
391 pread
= (struct drisw_drawable
*) driFetchDrawable(context
, read
);
393 driReleaseDrawables(&pcp
->base
);
395 if ((*psc
->core
->bindContext
) (pcp
->driContext
,
396 pdraw
? pdraw
->driDrawable
: NULL
,
397 pread
? pread
->driDrawable
: NULL
))
400 return GLXBadContext
;
404 drisw_unbind_context(struct glx_context
*context
, struct glx_context
*new)
406 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
407 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
409 (*psc
->core
->unbindContext
) (pcp
->driContext
);
413 drisw_bind_tex_image(Display
* dpy
,
414 GLXDrawable drawable
,
415 int buffer
, const int *attrib_list
)
417 struct glx_context
*gc
= __glXGetCurrentContext();
418 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
419 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
420 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
421 struct drisw_screen
*psc
;
423 __glXInitialize(dpy
);
426 psc
= (struct drisw_screen
*) base
->psc
;
431 if (psc
->texBuffer
->base
.version
>= 2 &&
432 psc
->texBuffer
->setTexBuffer2
!= NULL
) {
433 (*psc
->texBuffer
->setTexBuffer2
) (pcp
->driContext
,
434 pdraw
->base
.textureTarget
,
435 pdraw
->base
.textureFormat
,
439 (*psc
->texBuffer
->setTexBuffer
) (pcp
->driContext
,
440 pdraw
->base
.textureTarget
,
447 drisw_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
449 struct glx_context
*gc
= __glXGetCurrentContext();
450 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
451 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
452 struct glx_display
*dpyPriv
= __glXInitialize(dpy
);
453 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
454 struct drisw_screen
*psc
;
456 if (dpyPriv
!= NULL
&& pdraw
!= NULL
) {
457 psc
= (struct drisw_screen
*) base
->psc
;
462 if (psc
->texBuffer
->base
.version
>= 3 &&
463 psc
->texBuffer
->releaseTexBuffer
!= NULL
) {
464 (*psc
->texBuffer
->releaseTexBuffer
) (pcp
->driContext
,
465 pdraw
->base
.textureTarget
,
471 static const struct glx_context_vtable drisw_context_vtable
= {
472 .destroy
= drisw_destroy_context
,
473 .bind
= drisw_bind_context
,
474 .unbind
= drisw_unbind_context
,
477 .use_x_font
= DRI_glXUseXFont
,
478 .bind_tex_image
= drisw_bind_tex_image
,
479 .release_tex_image
= drisw_release_tex_image
,
480 .get_proc_address
= NULL
,
483 static struct glx_context
*
484 drisw_create_context(struct glx_screen
*base
,
485 struct glx_config
*config_base
,
486 struct glx_context
*shareList
, int renderType
)
488 struct drisw_context
*pcp
, *pcp_shared
;
489 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
490 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
491 __DRIcontext
*shared
= NULL
;
493 if (!psc
->base
.driScreen
)
496 /* Check the renderType value */
497 if (!validate_renderType_against_config(config_base
, renderType
))
501 /* If the shareList context is not a DRISW context, we cannot possibly
502 * create a DRISW context that shares it.
504 if (shareList
->vtable
->destroy
!= drisw_destroy_context
) {
508 pcp_shared
= (struct drisw_context
*) shareList
;
509 shared
= pcp_shared
->driContext
;
512 pcp
= calloc(1, sizeof *pcp
);
516 if (!glx_context_init(&pcp
->base
, &psc
->base
, &config
->base
)) {
521 pcp
->base
.renderType
= renderType
;
524 (*psc
->core
->createNewContext
) (psc
->driScreen
,
525 config
->driConfig
, shared
, pcp
);
526 if (pcp
->driContext
== NULL
) {
531 pcp
->base
.vtable
= &drisw_context_vtable
;
536 static struct glx_context
*
537 drisw_create_context_attribs(struct glx_screen
*base
,
538 struct glx_config
*config_base
,
539 struct glx_context
*shareList
,
540 unsigned num_attribs
,
541 const uint32_t *attribs
,
544 struct drisw_context
*pcp
, *pcp_shared
;
545 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
546 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
547 __DRIcontext
*shared
= NULL
;
556 uint32_t ctx_attribs
[2 * 5];
557 unsigned num_ctx_attribs
= 0;
559 if (!psc
->base
.driScreen
)
562 if (psc
->swrast
->base
.version
< 3)
565 /* Remap the GLX tokens to DRI2 tokens.
567 if (!dri2_convert_glx_attribs(num_attribs
, attribs
,
568 &major_ver
, &minor_ver
, &renderType
, &flags
,
569 &api
, &reset
, &release
, error
))
572 if (!dri2_check_no_error(flags
, shareList
, major_ver
, error
))
575 /* Check the renderType value */
576 if (!validate_renderType_against_config(config_base
, renderType
)) {
580 if (reset
!= __DRI_CTX_RESET_NO_NOTIFICATION
)
583 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
&&
584 release
!= __DRI_CTX_RELEASE_BEHAVIOR_NONE
)
588 pcp_shared
= (struct drisw_context
*) shareList
;
589 shared
= pcp_shared
->driContext
;
592 pcp
= calloc(1, sizeof *pcp
);
596 if (!glx_context_init(&pcp
->base
, &psc
->base
, config_base
)) {
601 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
602 ctx_attribs
[num_ctx_attribs
++] = major_ver
;
603 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
604 ctx_attribs
[num_ctx_attribs
++] = minor_ver
;
605 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
) {
606 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
607 ctx_attribs
[num_ctx_attribs
++] = release
;
611 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_FLAGS
;
613 /* The current __DRI_CTX_FLAG_* values are identical to the
614 * GLX_CONTEXT_*_BIT values.
616 ctx_attribs
[num_ctx_attribs
++] = flags
;
618 if (flags
& __DRI_CTX_FLAG_NO_ERROR
)
619 pcp
->base
.noError
= GL_TRUE
;
622 pcp
->base
.renderType
= renderType
;
625 (*psc
->swrast
->createContextAttribs
) (psc
->driScreen
,
627 config
? config
->driConfig
: 0,
633 if (pcp
->driContext
== NULL
) {
638 pcp
->base
.vtable
= &drisw_context_vtable
;
644 driswDestroyDrawable(__GLXDRIdrawable
* pdraw
)
646 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
647 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
649 (*psc
->core
->destroyDrawable
) (pdp
->driDrawable
);
651 XDestroyDrawable(pdp
, pdraw
->psc
->dpy
, pdraw
->drawable
);
655 static __GLXDRIdrawable
*
656 driswCreateDrawable(struct glx_screen
*base
, XID xDrawable
,
657 GLXDrawable drawable
, struct glx_config
*modes
)
659 struct drisw_drawable
*pdp
;
660 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) modes
;
661 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
662 const __DRIswrastExtension
*swrast
= psc
->swrast
;
663 Display
*dpy
= psc
->base
.dpy
;
665 pdp
= calloc(1, sizeof(*pdp
));
669 pdp
->base
.xDrawable
= xDrawable
;
670 pdp
->base
.drawable
= drawable
;
671 pdp
->base
.psc
= &psc
->base
;
673 pdp
->gc
= XCreateGC(dpy
, xDrawable
, 0, NULL
);
676 /* Use the visual depth, if this fbconfig corresponds to a visual */
677 if (pdp
->config
->visualID
!= 0) {
679 XVisualInfo
*visinfo
, template;
681 template.visualid
= pdp
->config
->visualID
;
682 template.screen
= pdp
->config
->screen
;
683 visinfo
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
,
684 &template, &matches
);
686 if (visinfo
&& matches
) {
687 pdp
->xDepth
= visinfo
->depth
;
692 /* Otherwise, or if XGetVisualInfo failed, ask the server */
693 if (pdp
->xDepth
== 0) {
696 unsigned uw
, uh
, bw
, depth
;
698 XGetGeometry(dpy
, xDrawable
, &root
, &x
, &y
, &uw
, &uh
, &bw
, &depth
);
702 /* Create a new drawable */
704 (*swrast
->createNewDrawable
) (psc
->driScreen
, config
->driConfig
, pdp
);
706 if (!pdp
->driDrawable
) {
707 XDestroyDrawable(pdp
, psc
->base
.dpy
, xDrawable
);
712 pdp
->base
.destroyDrawable
= driswDestroyDrawable
;
718 driswSwapBuffers(__GLXDRIdrawable
* pdraw
,
719 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
722 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
723 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
733 (*psc
->core
->swapBuffers
) (pdp
->driDrawable
);
739 driswCopySubBuffer(__GLXDRIdrawable
* pdraw
,
740 int x
, int y
, int width
, int height
, Bool flush
)
742 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
743 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
749 (*psc
->copySubBuffer
->copySubBuffer
) (pdp
->driDrawable
,
750 x
, y
, width
, height
);
754 driswDestroyScreen(struct glx_screen
*base
)
756 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
758 /* Free the direct rendering per screen data */
759 (*psc
->core
->destroyScreen
) (psc
->driScreen
);
760 driDestroyConfigs(psc
->driver_configs
);
761 psc
->driScreen
= NULL
;
763 dlclose(psc
->driver
);
767 #define SWRAST_DRIVER_NAME "swrast"
769 static const struct glx_screen_vtable drisw_screen_vtable
= {
770 .create_context
= drisw_create_context
,
771 .create_context_attribs
= drisw_create_context_attribs
,
772 .query_renderer_integer
= drisw_query_renderer_integer
,
773 .query_renderer_string
= drisw_query_renderer_string
,
777 driswBindExtensions(struct drisw_screen
*psc
, const __DRIextension
**extensions
)
781 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_make_current_read");
783 if (psc
->swrast
->base
.version
>= 3) {
784 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context");
785 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context_profile");
787 /* DRISW version >= 2 implies support for OpenGL ES.
789 __glXEnableDirectExtension(&psc
->base
,
790 "GLX_EXT_create_context_es_profile");
791 __glXEnableDirectExtension(&psc
->base
,
792 "GLX_EXT_create_context_es2_profile");
795 if (psc
->copySubBuffer
)
796 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
798 /* FIXME: Figure out what other extensions can be ported here from dri2. */
799 for (i
= 0; extensions
[i
]; i
++) {
800 if ((strcmp(extensions
[i
]->name
, __DRI_TEX_BUFFER
) == 0)) {
801 psc
->texBuffer
= (__DRItexBufferExtension
*) extensions
[i
];
802 __glXEnableDirectExtension(&psc
->base
, "GLX_EXT_texture_from_pixmap");
804 /* DRISW version 3 is also required because GLX_MESA_query_renderer
805 * requires GLX_ARB_create_context_profile.
807 if (psc
->swrast
->base
.version
>= 3
808 && strcmp(extensions
[i
]->name
, __DRI2_RENDERER_QUERY
) == 0) {
809 psc
->rendererQuery
= (__DRI2rendererQueryExtension
*) extensions
[i
];
810 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_query_renderer");
812 if (strcmp(extensions
[i
]->name
, __DRI2_FLUSH_CONTROL
) == 0) {
813 __glXEnableDirectExtension(&psc
->base
,
814 "GLX_ARB_context_flush_control");
820 check_xshm(Display
*dpy
)
822 int (*old_handler
)(Display
*, XErrorEvent
*);
825 XShmSegmentInfo info
= { 0, };
827 if (!XQueryExtension(dpy
, "MIT-SHM", &xshm_opcode
, &ignore
, &ignore
))
830 old_handler
= XSetErrorHandler(handle_xerror
);
831 XShmDetach(dpy
, &info
);
833 (void) XSetErrorHandler(old_handler
);
835 /* BadRequest means we're a remote client. If we were local we'd
836 * expect BadValue since 'info' has an invalid segment name.
838 if (xshm_error
== BadRequest
)
845 static struct glx_screen
*
846 driswCreateScreen(int screen
, struct glx_display
*priv
)
849 const __DRIconfig
**driver_configs
;
850 const __DRIextension
**extensions
;
851 struct drisw_screen
*psc
;
852 struct glx_config
*configs
= NULL
, *visuals
= NULL
;
854 const __DRIextension
**loader_extensions_local
;
856 psc
= calloc(1, sizeof *psc
);
860 if (!glx_screen_init(&psc
->base
, screen
, priv
)) {
865 extensions
= driOpenDriver(SWRAST_DRIVER_NAME
, &psc
->driver
);
866 if (extensions
== NULL
)
869 if (!check_xshm(psc
->base
.dpy
))
870 loader_extensions_local
= loader_extensions_noshm
;
872 loader_extensions_local
= loader_extensions_shm
;
874 for (i
= 0; extensions
[i
]; i
++) {
875 if (strcmp(extensions
[i
]->name
, __DRI_CORE
) == 0)
876 psc
->core
= (__DRIcoreExtension
*) extensions
[i
];
877 if (strcmp(extensions
[i
]->name
, __DRI_SWRAST
) == 0)
878 psc
->swrast
= (__DRIswrastExtension
*) extensions
[i
];
879 if (strcmp(extensions
[i
]->name
, __DRI_COPY_SUB_BUFFER
) == 0)
880 psc
->copySubBuffer
= (__DRIcopySubBufferExtension
*) extensions
[i
];
883 if (psc
->core
== NULL
|| psc
->swrast
== NULL
) {
884 ErrorMessageF("core dri extension not found\n");
888 if (psc
->swrast
->base
.version
>= 4) {
890 psc
->swrast
->createNewScreen2(screen
, loader_extensions_local
,
892 &driver_configs
, psc
);
895 psc
->swrast
->createNewScreen(screen
, loader_extensions_local
,
896 &driver_configs
, psc
);
898 if (psc
->driScreen
== NULL
) {
899 ErrorMessageF("failed to create dri screen\n");
903 extensions
= psc
->core
->getExtensions(psc
->driScreen
);
904 driswBindExtensions(psc
, extensions
);
906 configs
= driConvertConfigs(psc
->core
, psc
->base
.configs
, driver_configs
);
907 visuals
= driConvertConfigs(psc
->core
, psc
->base
.visuals
, driver_configs
);
909 if (!configs
|| !visuals
) {
910 ErrorMessageF("No matching fbConfigs or visuals found\n");
914 glx_config_destroy_list(psc
->base
.configs
);
915 psc
->base
.configs
= configs
;
916 glx_config_destroy_list(psc
->base
.visuals
);
917 psc
->base
.visuals
= visuals
;
919 psc
->driver_configs
= driver_configs
;
921 psc
->base
.vtable
= &drisw_screen_vtable
;
923 psc
->base
.driScreen
= psp
;
924 psp
->destroyScreen
= driswDestroyScreen
;
925 psp
->createDrawable
= driswCreateDrawable
;
926 psp
->swapBuffers
= driswSwapBuffers
;
928 if (psc
->copySubBuffer
)
929 psp
->copySubBuffer
= driswCopySubBuffer
;
935 glx_config_destroy_list(configs
);
937 glx_config_destroy_list(visuals
);
939 psc
->core
->destroyScreen(psc
->driScreen
);
940 psc
->driScreen
= NULL
;
943 dlclose(psc
->driver
);
944 glx_screen_cleanup(&psc
->base
);
947 CriticalErrorMessageF("failed to load driver: %s\n", SWRAST_DRIVER_NAME
);
952 /* Called from __glXFreeDisplayPrivate.
955 driswDestroyDisplay(__GLXDRIdisplay
* dpy
)
961 * Allocate, initialize and return a __DRIdisplayPrivate object.
962 * This is called from __glXInitialize() when we are given a new
965 _X_HIDDEN __GLXDRIdisplay
*
966 driswCreateDisplay(Display
* dpy
)
968 struct drisw_display
*pdpyp
;
970 pdpyp
= malloc(sizeof *pdpyp
);
974 pdpyp
->base
.destroyDisplay
= driswDestroyDisplay
;
975 pdpyp
->base
.createScreen
= driswCreateScreen
;
980 #endif /* GLX_DIRECT_RENDERING */