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 ximage
->width
= ximage
->bytes_per_line
/ ((ximage
->bits_per_pixel
+ 7)/ 8);
199 if (pdp
->shminfo
.shmid
>= 0) {
200 XShmPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
, False
);
203 XPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
);
209 swrastPutImageShm(__DRIdrawable
* draw
, int op
,
210 int x
, int y
, int w
, int h
, int stride
,
211 int shmid
, char *shmaddr
, unsigned offset
,
214 struct drisw_drawable
*pdp
= loaderPrivate
;
216 pdp
->shminfo
.shmaddr
= shmaddr
;
217 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, shmid
,
218 shmaddr
+ offset
, loaderPrivate
);
222 swrastPutImageShm2(__DRIdrawable
* draw
, int op
,
224 int w
, int h
, int stride
,
225 int shmid
, char *shmaddr
, unsigned offset
,
228 struct drisw_drawable
*pdp
= loaderPrivate
;
230 pdp
->shminfo
.shmaddr
= shmaddr
;
231 swrastXPutImage(draw
, op
, x
, 0, x
, y
, w
, h
, stride
, shmid
,
232 shmaddr
+ offset
, loaderPrivate
);
236 swrastPutImage2(__DRIdrawable
* draw
, int op
,
237 int x
, int y
, int w
, int h
, int stride
,
238 char *data
, void *loaderPrivate
)
240 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, -1,
241 data
, loaderPrivate
);
245 swrastPutImage(__DRIdrawable
* draw
, int op
,
246 int x
, int y
, int w
, int h
,
247 char *data
, void *loaderPrivate
)
249 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, 0, -1,
250 data
, loaderPrivate
);
254 swrastGetImage2(__DRIdrawable
* read
,
255 int x
, int y
, int w
, int h
, int stride
,
256 char *data
, void *loaderPrivate
)
258 struct drisw_drawable
*prp
= loaderPrivate
;
259 __GLXDRIdrawable
*pread
= &(prp
->base
);
260 Display
*dpy
= pread
->psc
->dpy
;
264 if (!prp
->ximage
|| prp
->shminfo
.shmid
>= 0) {
265 if (!XCreateDrawable(prp
, -1, dpy
))
269 readable
= pread
->xDrawable
;
271 ximage
= prp
->ximage
;
275 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
277 XGetSubImage(dpy
, readable
, x
, y
, w
, h
, ~0L, ZPixmap
, ximage
, 0, 0);
283 swrastGetImage(__DRIdrawable
* read
,
284 int x
, int y
, int w
, int h
,
285 char *data
, void *loaderPrivate
)
287 swrastGetImage2(read
, x
, y
, w
, h
, 0, data
, loaderPrivate
);
291 swrastGetImageShm2(__DRIdrawable
* read
,
292 int x
, int y
, int w
, int h
,
293 int shmid
, void *loaderPrivate
)
295 struct drisw_drawable
*prp
= loaderPrivate
;
296 __GLXDRIdrawable
*pread
= &(prp
->base
);
297 Display
*dpy
= pread
->psc
->dpy
;
301 if (!prp
->ximage
|| shmid
!= prp
->shminfo
.shmid
) {
302 if (!XCreateDrawable(prp
, shmid
, dpy
))
306 if (prp
->shminfo
.shmid
== -1)
308 readable
= pread
->xDrawable
;
310 ximage
= prp
->ximage
;
311 ximage
->data
= prp
->shminfo
.shmaddr
; /* no offset */
314 ximage
->bytes_per_line
= bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
316 XShmGetImage(dpy
, readable
, ximage
, x
, y
, ~0L);
321 swrastGetImageShm(__DRIdrawable
* read
,
322 int x
, int y
, int w
, int h
,
323 int shmid
, void *loaderPrivate
)
325 swrastGetImageShm2(read
, x
, y
, w
, h
, shmid
, loaderPrivate
);
328 static const __DRIswrastLoaderExtension swrastLoaderExtension_shm
= {
329 .base
= {__DRI_SWRAST_LOADER
, 6 },
331 .getDrawableInfo
= swrastGetDrawableInfo
,
332 .putImage
= swrastPutImage
,
333 .getImage
= swrastGetImage
,
334 .putImage2
= swrastPutImage2
,
335 .getImage2
= swrastGetImage2
,
336 .putImageShm
= swrastPutImageShm
,
337 .getImageShm
= swrastGetImageShm
,
338 .putImageShm2
= swrastPutImageShm2
,
339 .getImageShm2
= swrastGetImageShm2
,
342 static const __DRIextension
*loader_extensions_shm
[] = {
343 &swrastLoaderExtension_shm
.base
,
347 static const __DRIswrastLoaderExtension swrastLoaderExtension
= {
348 .base
= {__DRI_SWRAST_LOADER
, 3 },
350 .getDrawableInfo
= swrastGetDrawableInfo
,
351 .putImage
= swrastPutImage
,
352 .getImage
= swrastGetImage
,
353 .putImage2
= swrastPutImage2
,
354 .getImage2
= swrastGetImage2
,
357 static const __DRIextension
*loader_extensions_noshm
[] = {
358 &swrastLoaderExtension
.base
,
367 drisw_destroy_context(struct glx_context
*context
)
369 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
370 struct drisw_screen
*psc
= (struct drisw_screen
*) context
->psc
;
372 driReleaseDrawables(&pcp
->base
);
374 free((char *) context
->extensions
);
376 (*psc
->core
->destroyContext
) (pcp
->driContext
);
382 drisw_bind_context(struct glx_context
*context
, struct glx_context
*old
,
383 GLXDrawable draw
, GLXDrawable read
)
385 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
386 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
387 struct drisw_drawable
*pdraw
, *pread
;
389 pdraw
= (struct drisw_drawable
*) driFetchDrawable(context
, draw
);
390 pread
= (struct drisw_drawable
*) driFetchDrawable(context
, read
);
392 driReleaseDrawables(&pcp
->base
);
394 if ((*psc
->core
->bindContext
) (pcp
->driContext
,
395 pdraw
? pdraw
->driDrawable
: NULL
,
396 pread
? pread
->driDrawable
: NULL
))
399 return GLXBadContext
;
403 drisw_unbind_context(struct glx_context
*context
, struct glx_context
*new)
405 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
406 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
408 (*psc
->core
->unbindContext
) (pcp
->driContext
);
412 drisw_bind_tex_image(Display
* dpy
,
413 GLXDrawable drawable
,
414 int buffer
, const int *attrib_list
)
416 struct glx_context
*gc
= __glXGetCurrentContext();
417 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
418 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
419 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
420 struct drisw_screen
*psc
;
422 __glXInitialize(dpy
);
425 psc
= (struct drisw_screen
*) base
->psc
;
430 if (psc
->texBuffer
->base
.version
>= 2 &&
431 psc
->texBuffer
->setTexBuffer2
!= NULL
) {
432 (*psc
->texBuffer
->setTexBuffer2
) (pcp
->driContext
,
433 pdraw
->base
.textureTarget
,
434 pdraw
->base
.textureFormat
,
438 (*psc
->texBuffer
->setTexBuffer
) (pcp
->driContext
,
439 pdraw
->base
.textureTarget
,
446 drisw_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
448 struct glx_context
*gc
= __glXGetCurrentContext();
449 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
450 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
451 struct glx_display
*dpyPriv
= __glXInitialize(dpy
);
452 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
453 struct drisw_screen
*psc
;
455 if (dpyPriv
!= NULL
&& pdraw
!= NULL
) {
456 psc
= (struct drisw_screen
*) base
->psc
;
461 if (psc
->texBuffer
->base
.version
>= 3 &&
462 psc
->texBuffer
->releaseTexBuffer
!= NULL
) {
463 (*psc
->texBuffer
->releaseTexBuffer
) (pcp
->driContext
,
464 pdraw
->base
.textureTarget
,
470 static const struct glx_context_vtable drisw_context_vtable
= {
471 .destroy
= drisw_destroy_context
,
472 .bind
= drisw_bind_context
,
473 .unbind
= drisw_unbind_context
,
476 .use_x_font
= DRI_glXUseXFont
,
477 .bind_tex_image
= drisw_bind_tex_image
,
478 .release_tex_image
= drisw_release_tex_image
,
479 .get_proc_address
= NULL
,
482 static struct glx_context
*
483 drisw_create_context(struct glx_screen
*base
,
484 struct glx_config
*config_base
,
485 struct glx_context
*shareList
, int renderType
)
487 struct drisw_context
*pcp
, *pcp_shared
;
488 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
489 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
490 __DRIcontext
*shared
= NULL
;
492 if (!psc
->base
.driScreen
)
495 /* Check the renderType value */
496 if (!validate_renderType_against_config(config_base
, renderType
))
500 /* If the shareList context is not a DRISW context, we cannot possibly
501 * create a DRISW context that shares it.
503 if (shareList
->vtable
->destroy
!= drisw_destroy_context
) {
507 pcp_shared
= (struct drisw_context
*) shareList
;
508 shared
= pcp_shared
->driContext
;
511 pcp
= calloc(1, sizeof *pcp
);
515 if (!glx_context_init(&pcp
->base
, &psc
->base
, &config
->base
)) {
520 pcp
->base
.renderType
= renderType
;
523 (*psc
->core
->createNewContext
) (psc
->driScreen
,
524 config
->driConfig
, shared
, pcp
);
525 if (pcp
->driContext
== NULL
) {
530 pcp
->base
.vtable
= &drisw_context_vtable
;
535 static struct glx_context
*
536 drisw_create_context_attribs(struct glx_screen
*base
,
537 struct glx_config
*config_base
,
538 struct glx_context
*shareList
,
539 unsigned num_attribs
,
540 const uint32_t *attribs
,
543 struct drisw_context
*pcp
, *pcp_shared
;
544 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
545 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
546 __DRIcontext
*shared
= NULL
;
555 uint32_t ctx_attribs
[2 * 5];
556 unsigned num_ctx_attribs
= 0;
558 if (!psc
->base
.driScreen
)
561 if (psc
->swrast
->base
.version
< 3)
564 /* Remap the GLX tokens to DRI2 tokens.
566 if (!dri2_convert_glx_attribs(num_attribs
, attribs
,
567 &major_ver
, &minor_ver
, &renderType
, &flags
,
568 &api
, &reset
, &release
, error
))
571 if (!dri2_check_no_error(flags
, shareList
, major_ver
, error
))
574 /* Check the renderType value */
575 if (!validate_renderType_against_config(config_base
, renderType
)) {
579 if (reset
!= __DRI_CTX_RESET_NO_NOTIFICATION
)
582 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
&&
583 release
!= __DRI_CTX_RELEASE_BEHAVIOR_NONE
)
587 pcp_shared
= (struct drisw_context
*) shareList
;
588 shared
= pcp_shared
->driContext
;
591 pcp
= calloc(1, sizeof *pcp
);
595 if (!glx_context_init(&pcp
->base
, &psc
->base
, config_base
)) {
600 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
601 ctx_attribs
[num_ctx_attribs
++] = major_ver
;
602 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
603 ctx_attribs
[num_ctx_attribs
++] = minor_ver
;
604 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
) {
605 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
606 ctx_attribs
[num_ctx_attribs
++] = release
;
610 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_FLAGS
;
612 /* The current __DRI_CTX_FLAG_* values are identical to the
613 * GLX_CONTEXT_*_BIT values.
615 ctx_attribs
[num_ctx_attribs
++] = flags
;
617 if (flags
& __DRI_CTX_FLAG_NO_ERROR
)
618 pcp
->base
.noError
= GL_TRUE
;
621 pcp
->base
.renderType
= renderType
;
624 (*psc
->swrast
->createContextAttribs
) (psc
->driScreen
,
626 config
? config
->driConfig
: 0,
632 if (pcp
->driContext
== NULL
) {
637 pcp
->base
.vtable
= &drisw_context_vtable
;
643 driswDestroyDrawable(__GLXDRIdrawable
* pdraw
)
645 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
646 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
648 (*psc
->core
->destroyDrawable
) (pdp
->driDrawable
);
650 XDestroyDrawable(pdp
, pdraw
->psc
->dpy
, pdraw
->drawable
);
654 static __GLXDRIdrawable
*
655 driswCreateDrawable(struct glx_screen
*base
, XID xDrawable
,
656 GLXDrawable drawable
, struct glx_config
*modes
)
658 struct drisw_drawable
*pdp
;
659 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) modes
;
660 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
661 const __DRIswrastExtension
*swrast
= psc
->swrast
;
662 Display
*dpy
= psc
->base
.dpy
;
664 pdp
= calloc(1, sizeof(*pdp
));
668 pdp
->base
.xDrawable
= xDrawable
;
669 pdp
->base
.drawable
= drawable
;
670 pdp
->base
.psc
= &psc
->base
;
672 pdp
->gc
= XCreateGC(dpy
, xDrawable
, 0, NULL
);
675 /* Use the visual depth, if this fbconfig corresponds to a visual */
676 if (pdp
->config
->visualID
!= 0) {
678 XVisualInfo
*visinfo
, template;
680 template.visualid
= pdp
->config
->visualID
;
681 template.screen
= pdp
->config
->screen
;
682 visinfo
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
,
683 &template, &matches
);
685 if (visinfo
&& matches
) {
686 pdp
->xDepth
= visinfo
->depth
;
691 /* Otherwise, or if XGetVisualInfo failed, ask the server */
692 if (pdp
->xDepth
== 0) {
695 unsigned uw
, uh
, bw
, depth
;
697 XGetGeometry(dpy
, xDrawable
, &root
, &x
, &y
, &uw
, &uh
, &bw
, &depth
);
701 /* Create a new drawable */
703 (*swrast
->createNewDrawable
) (psc
->driScreen
, config
->driConfig
, pdp
);
705 if (!pdp
->driDrawable
) {
706 XDestroyDrawable(pdp
, psc
->base
.dpy
, xDrawable
);
711 pdp
->base
.destroyDrawable
= driswDestroyDrawable
;
717 driswSwapBuffers(__GLXDRIdrawable
* pdraw
,
718 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
721 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
722 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
732 (*psc
->core
->swapBuffers
) (pdp
->driDrawable
);
738 driswCopySubBuffer(__GLXDRIdrawable
* pdraw
,
739 int x
, int y
, int width
, int height
, Bool flush
)
741 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
742 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
748 (*psc
->copySubBuffer
->copySubBuffer
) (pdp
->driDrawable
,
749 x
, y
, width
, height
);
753 driswDestroyScreen(struct glx_screen
*base
)
755 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
757 /* Free the direct rendering per screen data */
758 (*psc
->core
->destroyScreen
) (psc
->driScreen
);
759 driDestroyConfigs(psc
->driver_configs
);
760 psc
->driScreen
= NULL
;
762 dlclose(psc
->driver
);
766 #define SWRAST_DRIVER_NAME "swrast"
768 static const struct glx_screen_vtable drisw_screen_vtable
= {
769 .create_context
= drisw_create_context
,
770 .create_context_attribs
= drisw_create_context_attribs
,
771 .query_renderer_integer
= drisw_query_renderer_integer
,
772 .query_renderer_string
= drisw_query_renderer_string
,
776 driswBindExtensions(struct drisw_screen
*psc
, const __DRIextension
**extensions
)
780 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_make_current_read");
782 if (psc
->swrast
->base
.version
>= 3) {
783 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context");
784 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context_profile");
786 /* DRISW version >= 2 implies support for OpenGL ES.
788 __glXEnableDirectExtension(&psc
->base
,
789 "GLX_EXT_create_context_es_profile");
790 __glXEnableDirectExtension(&psc
->base
,
791 "GLX_EXT_create_context_es2_profile");
794 if (psc
->copySubBuffer
)
795 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
797 /* FIXME: Figure out what other extensions can be ported here from dri2. */
798 for (i
= 0; extensions
[i
]; i
++) {
799 if ((strcmp(extensions
[i
]->name
, __DRI_TEX_BUFFER
) == 0)) {
800 psc
->texBuffer
= (__DRItexBufferExtension
*) extensions
[i
];
801 __glXEnableDirectExtension(&psc
->base
, "GLX_EXT_texture_from_pixmap");
803 /* DRISW version 3 is also required because GLX_MESA_query_renderer
804 * requires GLX_ARB_create_context_profile.
806 if (psc
->swrast
->base
.version
>= 3
807 && strcmp(extensions
[i
]->name
, __DRI2_RENDERER_QUERY
) == 0) {
808 psc
->rendererQuery
= (__DRI2rendererQueryExtension
*) extensions
[i
];
809 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_query_renderer");
811 if (strcmp(extensions
[i
]->name
, __DRI2_FLUSH_CONTROL
) == 0) {
812 __glXEnableDirectExtension(&psc
->base
,
813 "GLX_ARB_context_flush_control");
819 check_xshm(Display
*dpy
)
821 int (*old_handler
)(Display
*, XErrorEvent
*);
824 XShmSegmentInfo info
= { 0, };
826 if (!XQueryExtension(dpy
, "MIT-SHM", &xshm_opcode
, &ignore
, &ignore
))
829 old_handler
= XSetErrorHandler(handle_xerror
);
830 XShmDetach(dpy
, &info
);
832 (void) XSetErrorHandler(old_handler
);
834 /* BadRequest means we're a remote client. If we were local we'd
835 * expect BadValue since 'info' has an invalid segment name.
837 if (xshm_error
== BadRequest
)
844 static struct glx_screen
*
845 driswCreateScreen(int screen
, struct glx_display
*priv
)
848 const __DRIconfig
**driver_configs
;
849 const __DRIextension
**extensions
;
850 struct drisw_screen
*psc
;
851 struct glx_config
*configs
= NULL
, *visuals
= NULL
;
853 const __DRIextension
**loader_extensions_local
;
855 psc
= calloc(1, sizeof *psc
);
859 if (!glx_screen_init(&psc
->base
, screen
, priv
)) {
864 extensions
= driOpenDriver(SWRAST_DRIVER_NAME
, &psc
->driver
);
865 if (extensions
== NULL
)
868 if (!check_xshm(psc
->base
.dpy
))
869 loader_extensions_local
= loader_extensions_noshm
;
871 loader_extensions_local
= loader_extensions_shm
;
873 for (i
= 0; extensions
[i
]; i
++) {
874 if (strcmp(extensions
[i
]->name
, __DRI_CORE
) == 0)
875 psc
->core
= (__DRIcoreExtension
*) extensions
[i
];
876 if (strcmp(extensions
[i
]->name
, __DRI_SWRAST
) == 0)
877 psc
->swrast
= (__DRIswrastExtension
*) extensions
[i
];
878 if (strcmp(extensions
[i
]->name
, __DRI_COPY_SUB_BUFFER
) == 0)
879 psc
->copySubBuffer
= (__DRIcopySubBufferExtension
*) extensions
[i
];
882 if (psc
->core
== NULL
|| psc
->swrast
== NULL
) {
883 ErrorMessageF("core dri extension not found\n");
887 if (psc
->swrast
->base
.version
>= 4) {
889 psc
->swrast
->createNewScreen2(screen
, loader_extensions_local
,
891 &driver_configs
, psc
);
894 psc
->swrast
->createNewScreen(screen
, loader_extensions_local
,
895 &driver_configs
, psc
);
897 if (psc
->driScreen
== NULL
) {
898 ErrorMessageF("failed to create dri screen\n");
902 extensions
= psc
->core
->getExtensions(psc
->driScreen
);
903 driswBindExtensions(psc
, extensions
);
905 configs
= driConvertConfigs(psc
->core
, psc
->base
.configs
, driver_configs
);
906 visuals
= driConvertConfigs(psc
->core
, psc
->base
.visuals
, driver_configs
);
908 if (!configs
|| !visuals
) {
909 ErrorMessageF("No matching fbConfigs or visuals found\n");
913 glx_config_destroy_list(psc
->base
.configs
);
914 psc
->base
.configs
= configs
;
915 glx_config_destroy_list(psc
->base
.visuals
);
916 psc
->base
.visuals
= visuals
;
918 psc
->driver_configs
= driver_configs
;
920 psc
->base
.vtable
= &drisw_screen_vtable
;
922 psc
->base
.driScreen
= psp
;
923 psp
->destroyScreen
= driswDestroyScreen
;
924 psp
->createDrawable
= driswCreateDrawable
;
925 psp
->swapBuffers
= driswSwapBuffers
;
927 if (psc
->copySubBuffer
)
928 psp
->copySubBuffer
= driswCopySubBuffer
;
934 glx_config_destroy_list(configs
);
936 glx_config_destroy_list(visuals
);
938 psc
->core
->destroyScreen(psc
->driScreen
);
939 psc
->driScreen
= NULL
;
942 dlclose(psc
->driver
);
943 glx_screen_cleanup(&psc
->base
);
946 CriticalErrorMessageF("failed to load driver: %s\n", SWRAST_DRIVER_NAME
);
951 /* Called from __glXFreeDisplayPrivate.
954 driswDestroyDisplay(__GLXDRIdisplay
* dpy
)
960 * Allocate, initialize and return a __DRIdisplayPrivate object.
961 * This is called from __glXInitialize() when we are given a new
964 _X_HIDDEN __GLXDRIdisplay
*
965 driswCreateDisplay(Display
* dpy
)
967 struct drisw_display
*pdpyp
;
969 pdpyp
= malloc(sizeof *pdpyp
);
973 pdpyp
->base
.destroyDisplay
= driswDestroyDisplay
;
974 pdpyp
->base
.createScreen
= driswCreateScreen
;
979 #endif /* GLX_DIRECT_RENDERING */