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 driswCreateGCs(struct drisw_drawable
* pdp
,
36 Display
* dpy
, XID drawable
, int visualid
)
42 pdp
->gc
= XCreateGC(dpy
, drawable
, 0, NULL
);
45 visTemp
.visualid
= visualid
;
46 visMask
= VisualIDMask
;
47 pdp
->visinfo
= XGetVisualInfo(dpy
, visMask
, &visTemp
, &num_visuals
);
49 if (!pdp
->visinfo
|| num_visuals
== 0)
55 static int xshm_error
= 0;
56 static int xshm_opcode
= -1;
59 * Catches potential Xlib errors.
62 handle_xerror(Display
*dpy
, XErrorEvent
*event
)
66 assert(xshm_opcode
!= -1);
67 if (event
->request_code
!= xshm_opcode
)
70 xshm_error
= event
->error_code
;
75 XCreateDrawable(struct drisw_drawable
* pdp
, int shmid
, Display
* dpy
)
78 XDestroyImage(pdp
->ximage
);
82 if (!xshm_error
&& shmid
>= 0) {
83 pdp
->shminfo
.shmid
= shmid
;
84 pdp
->ximage
= XShmCreateImage(dpy
,
89 &pdp
->shminfo
, /* shminfo */
90 0, 0); /* width, height */
91 if (pdp
->ximage
!= NULL
) {
92 int (*old_handler
)(Display
*, XErrorEvent
*);
94 /* dispatch pending errors */
97 old_handler
= XSetErrorHandler(handle_xerror
);
98 /* This may trigger the X protocol error we're ready to catch: */
99 XShmAttach(dpy
, &pdp
->shminfo
);
103 /* we are on a remote display, this error is normal, don't print it */
104 XDestroyImage(pdp
->ximage
);
108 (void) XSetErrorHandler(old_handler
);
112 if (pdp
->ximage
== NULL
) {
113 pdp
->shminfo
.shmid
= -1;
114 pdp
->ximage
= XCreateImage(dpy
,
115 pdp
->visinfo
->visual
,
117 ZPixmap
, 0, /* format, offset */
119 0, 0, /* width, height */
121 0); /* bytes_per_line */
125 * swrast does not handle 24-bit depth with 24 bpp, so let X do the
126 * the conversion for us.
128 if (pdp
->ximage
->bits_per_pixel
== 24)
129 pdp
->ximage
->bits_per_pixel
= 32;
135 XDestroyDrawable(struct drisw_drawable
* pdp
, Display
* dpy
, XID drawable
)
138 XDestroyImage(pdp
->ximage
);
140 if (pdp
->shminfo
.shmid
> 0)
141 XShmDetach(dpy
, &pdp
->shminfo
);
145 XFreeGC(dpy
, pdp
->gc
);
149 * swrast loader functions
153 swrastGetDrawableInfo(__DRIdrawable
* draw
,
154 int *x
, int *y
, int *w
, int *h
,
157 struct drisw_drawable
*pdp
= loaderPrivate
;
158 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
159 Display
*dpy
= pdraw
->psc
->dpy
;
163 unsigned uw
, uh
, bw
, depth
;
165 drawable
= pdraw
->xDrawable
;
167 XGetGeometry(dpy
, drawable
, &root
, x
, y
, &uw
, &uh
, &bw
, &depth
);
173 * Align renderbuffer pitch.
175 * This should be chosen by the driver and the loader (libGL, xserver/glx)
176 * should use the driver provided pitch.
178 * It seems that the xorg loader (that is the xserver loading swrast_dri for
179 * indirect rendering, not client-side libGL) requires that the pitch is
180 * exactly the image width padded to 32 bits. XXX
182 * The above restriction can probably be overcome by using ScratchPixmap and
183 * CopyArea in the xserver, similar to ShmPutImage, and setting the width of
184 * the scratch pixmap to 'pitch / cpp'.
187 bytes_per_line(unsigned pitch_bits
, unsigned mul
)
189 unsigned mask
= mul
- 1;
191 return ((pitch_bits
+ mask
) & ~mask
) / 8;
195 swrastXPutImage(__DRIdrawable
* draw
, int op
,
196 int srcx
, int srcy
, int x
, int y
,
197 int w
, int h
, int stride
,
198 int shmid
, char *data
, void *loaderPrivate
)
200 struct drisw_drawable
*pdp
= loaderPrivate
;
201 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
202 Display
*dpy
= pdraw
->psc
->dpy
;
207 if (!pdp
->ximage
|| shmid
!= pdp
->shminfo
.shmid
) {
208 if (!XCreateDrawable(pdp
, shmid
, dpy
))
212 drawable
= pdraw
->xDrawable
;
213 ximage
= pdp
->ximage
;
214 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
217 if (pdp
->shminfo
.shmid
>= 0) {
218 ximage
->width
= ximage
->bytes_per_line
/ ((ximage
->bits_per_pixel
+ 7)/ 8);
220 XShmPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
, False
);
225 XPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
);
231 swrastPutImageShm(__DRIdrawable
* draw
, int op
,
232 int x
, int y
, int w
, int h
, int stride
,
233 int shmid
, char *shmaddr
, unsigned offset
,
236 struct drisw_drawable
*pdp
= loaderPrivate
;
238 pdp
->shminfo
.shmaddr
= shmaddr
;
239 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, shmid
,
240 shmaddr
+ offset
, loaderPrivate
);
244 swrastPutImageShm2(__DRIdrawable
* draw
, int op
,
246 int w
, int h
, int stride
,
247 int shmid
, char *shmaddr
, unsigned offset
,
250 struct drisw_drawable
*pdp
= loaderPrivate
;
252 pdp
->shminfo
.shmaddr
= shmaddr
;
253 swrastXPutImage(draw
, op
, x
, 0, x
, y
, w
, h
, stride
, shmid
,
254 shmaddr
+ offset
, loaderPrivate
);
258 swrastPutImage2(__DRIdrawable
* draw
, int op
,
259 int x
, int y
, int w
, int h
, int stride
,
260 char *data
, void *loaderPrivate
)
262 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, -1,
263 data
, loaderPrivate
);
267 swrastPutImage(__DRIdrawable
* draw
, int op
,
268 int x
, int y
, int w
, int h
,
269 char *data
, void *loaderPrivate
)
271 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, 0, -1,
272 data
, loaderPrivate
);
276 swrastGetImage2(__DRIdrawable
* read
,
277 int x
, int y
, int w
, int h
, int stride
,
278 char *data
, void *loaderPrivate
)
280 struct drisw_drawable
*prp
= loaderPrivate
;
281 __GLXDRIdrawable
*pread
= &(prp
->base
);
282 Display
*dpy
= pread
->psc
->dpy
;
286 if (!prp
->ximage
|| prp
->shminfo
.shmid
>= 0) {
287 if (!XCreateDrawable(prp
, -1, dpy
))
291 readable
= pread
->xDrawable
;
293 ximage
= prp
->ximage
;
297 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
299 XGetSubImage(dpy
, readable
, x
, y
, w
, h
, ~0L, ZPixmap
, ximage
, 0, 0);
305 swrastGetImage(__DRIdrawable
* read
,
306 int x
, int y
, int w
, int h
,
307 char *data
, void *loaderPrivate
)
309 swrastGetImage2(read
, x
, y
, w
, h
, 0, data
, loaderPrivate
);
313 swrastGetImageShm(__DRIdrawable
* read
,
314 int x
, int y
, int w
, int h
,
315 int shmid
, void *loaderPrivate
)
317 struct drisw_drawable
*prp
= loaderPrivate
;
318 __GLXDRIdrawable
*pread
= &(prp
->base
);
319 Display
*dpy
= pread
->psc
->dpy
;
323 if (!prp
->ximage
|| shmid
!= prp
->shminfo
.shmid
) {
324 if (!XCreateDrawable(prp
, shmid
, dpy
))
327 readable
= pread
->xDrawable
;
329 ximage
= prp
->ximage
;
330 ximage
->data
= prp
->shminfo
.shmaddr
; /* no offset */
333 ximage
->bytes_per_line
= bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
335 XShmGetImage(dpy
, readable
, ximage
, x
, y
, ~0L);
338 static const __DRIswrastLoaderExtension swrastLoaderExtension_shm
= {
339 .base
= {__DRI_SWRAST_LOADER
, 5 },
341 .getDrawableInfo
= swrastGetDrawableInfo
,
342 .putImage
= swrastPutImage
,
343 .getImage
= swrastGetImage
,
344 .putImage2
= swrastPutImage2
,
345 .getImage2
= swrastGetImage2
,
346 .putImageShm
= swrastPutImageShm
,
347 .getImageShm
= swrastGetImageShm
,
348 .putImageShm2
= swrastPutImageShm2
,
351 static const __DRIextension
*loader_extensions_shm
[] = {
352 &swrastLoaderExtension_shm
.base
,
356 static const __DRIswrastLoaderExtension swrastLoaderExtension
= {
357 .base
= {__DRI_SWRAST_LOADER
, 3 },
359 .getDrawableInfo
= swrastGetDrawableInfo
,
360 .putImage
= swrastPutImage
,
361 .getImage
= swrastGetImage
,
362 .putImage2
= swrastPutImage2
,
363 .getImage2
= swrastGetImage2
,
366 static const __DRIextension
*loader_extensions_noshm
[] = {
367 &swrastLoaderExtension
.base
,
376 drisw_destroy_context(struct glx_context
*context
)
378 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
379 struct drisw_screen
*psc
= (struct drisw_screen
*) context
->psc
;
381 driReleaseDrawables(&pcp
->base
);
383 free((char *) context
->extensions
);
385 (*psc
->core
->destroyContext
) (pcp
->driContext
);
391 drisw_bind_context(struct glx_context
*context
, struct glx_context
*old
,
392 GLXDrawable draw
, GLXDrawable read
)
394 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
395 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
396 struct drisw_drawable
*pdraw
, *pread
;
398 pdraw
= (struct drisw_drawable
*) driFetchDrawable(context
, draw
);
399 pread
= (struct drisw_drawable
*) driFetchDrawable(context
, read
);
401 driReleaseDrawables(&pcp
->base
);
403 if ((*psc
->core
->bindContext
) (pcp
->driContext
,
404 pdraw
? pdraw
->driDrawable
: NULL
,
405 pread
? pread
->driDrawable
: NULL
))
408 return GLXBadContext
;
412 drisw_unbind_context(struct glx_context
*context
, struct glx_context
*new)
414 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
415 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
417 (*psc
->core
->unbindContext
) (pcp
->driContext
);
421 drisw_bind_tex_image(Display
* dpy
,
422 GLXDrawable drawable
,
423 int buffer
, const int *attrib_list
)
425 struct glx_context
*gc
= __glXGetCurrentContext();
426 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
427 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
428 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
429 struct drisw_screen
*psc
;
431 __glXInitialize(dpy
);
434 psc
= (struct drisw_screen
*) base
->psc
;
439 if (psc
->texBuffer
->base
.version
>= 2 &&
440 psc
->texBuffer
->setTexBuffer2
!= NULL
) {
441 (*psc
->texBuffer
->setTexBuffer2
) (pcp
->driContext
,
442 pdraw
->base
.textureTarget
,
443 pdraw
->base
.textureFormat
,
447 (*psc
->texBuffer
->setTexBuffer
) (pcp
->driContext
,
448 pdraw
->base
.textureTarget
,
455 drisw_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
457 struct glx_context
*gc
= __glXGetCurrentContext();
458 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
459 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
460 struct glx_display
*dpyPriv
= __glXInitialize(dpy
);
461 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
462 struct drisw_screen
*psc
;
464 if (dpyPriv
!= NULL
&& pdraw
!= NULL
) {
465 psc
= (struct drisw_screen
*) base
->psc
;
470 if (psc
->texBuffer
->base
.version
>= 3 &&
471 psc
->texBuffer
->releaseTexBuffer
!= NULL
) {
472 (*psc
->texBuffer
->releaseTexBuffer
) (pcp
->driContext
,
473 pdraw
->base
.textureTarget
,
479 static const struct glx_context_vtable drisw_context_vtable
= {
480 .destroy
= drisw_destroy_context
,
481 .bind
= drisw_bind_context
,
482 .unbind
= drisw_unbind_context
,
485 .use_x_font
= DRI_glXUseXFont
,
486 .bind_tex_image
= drisw_bind_tex_image
,
487 .release_tex_image
= drisw_release_tex_image
,
488 .get_proc_address
= NULL
,
491 static struct glx_context
*
492 drisw_create_context(struct glx_screen
*base
,
493 struct glx_config
*config_base
,
494 struct glx_context
*shareList
, int renderType
)
496 struct drisw_context
*pcp
, *pcp_shared
;
497 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
498 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
499 __DRIcontext
*shared
= NULL
;
501 if (!psc
->base
.driScreen
)
504 /* Check the renderType value */
505 if (!validate_renderType_against_config(config_base
, renderType
))
509 /* If the shareList context is not a DRISW context, we cannot possibly
510 * create a DRISW context that shares it.
512 if (shareList
->vtable
->destroy
!= drisw_destroy_context
) {
516 pcp_shared
= (struct drisw_context
*) shareList
;
517 shared
= pcp_shared
->driContext
;
520 pcp
= calloc(1, sizeof *pcp
);
524 if (!glx_context_init(&pcp
->base
, &psc
->base
, &config
->base
)) {
529 pcp
->base
.renderType
= renderType
;
532 (*psc
->core
->createNewContext
) (psc
->driScreen
,
533 config
->driConfig
, shared
, pcp
);
534 if (pcp
->driContext
== NULL
) {
539 pcp
->base
.vtable
= &drisw_context_vtable
;
544 static struct glx_context
*
545 drisw_create_context_attribs(struct glx_screen
*base
,
546 struct glx_config
*config_base
,
547 struct glx_context
*shareList
,
548 unsigned num_attribs
,
549 const uint32_t *attribs
,
552 struct drisw_context
*pcp
, *pcp_shared
;
553 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
554 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
555 __DRIcontext
*shared
= NULL
;
564 uint32_t ctx_attribs
[2 * 5];
565 unsigned num_ctx_attribs
= 0;
567 if (!psc
->base
.driScreen
)
570 if (psc
->swrast
->base
.version
< 3)
573 /* Remap the GLX tokens to DRI2 tokens.
575 if (!dri2_convert_glx_attribs(num_attribs
, attribs
,
576 &major_ver
, &minor_ver
, &renderType
, &flags
,
577 &api
, &reset
, &release
, error
))
580 if (!dri2_check_no_error(flags
, shareList
, major_ver
, error
))
583 /* Check the renderType value */
584 if (!validate_renderType_against_config(config_base
, renderType
)) {
588 if (reset
!= __DRI_CTX_RESET_NO_NOTIFICATION
)
591 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
&&
592 release
!= __DRI_CTX_RELEASE_BEHAVIOR_NONE
)
596 pcp_shared
= (struct drisw_context
*) shareList
;
597 shared
= pcp_shared
->driContext
;
600 pcp
= calloc(1, sizeof *pcp
);
604 if (!glx_context_init(&pcp
->base
, &psc
->base
, config_base
)) {
609 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
610 ctx_attribs
[num_ctx_attribs
++] = major_ver
;
611 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
612 ctx_attribs
[num_ctx_attribs
++] = minor_ver
;
613 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
) {
614 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
615 ctx_attribs
[num_ctx_attribs
++] = release
;
619 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_FLAGS
;
621 /* The current __DRI_CTX_FLAG_* values are identical to the
622 * GLX_CONTEXT_*_BIT values.
624 ctx_attribs
[num_ctx_attribs
++] = flags
;
626 if (flags
& __DRI_CTX_FLAG_NO_ERROR
)
627 pcp
->base
.noError
= GL_TRUE
;
630 pcp
->base
.renderType
= renderType
;
633 (*psc
->swrast
->createContextAttribs
) (psc
->driScreen
,
635 config
? config
->driConfig
: 0,
641 if (pcp
->driContext
== NULL
) {
646 pcp
->base
.vtable
= &drisw_context_vtable
;
652 driswDestroyDrawable(__GLXDRIdrawable
* pdraw
)
654 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
655 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
657 (*psc
->core
->destroyDrawable
) (pdp
->driDrawable
);
659 XDestroyDrawable(pdp
, pdraw
->psc
->dpy
, pdraw
->drawable
);
663 static __GLXDRIdrawable
*
664 driswCreateDrawable(struct glx_screen
*base
, XID xDrawable
,
665 GLXDrawable drawable
, struct glx_config
*modes
)
667 struct drisw_drawable
*pdp
;
668 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) modes
;
669 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
671 const __DRIswrastExtension
*swrast
= psc
->swrast
;
673 pdp
= calloc(1, sizeof(*pdp
));
677 pdp
->base
.xDrawable
= xDrawable
;
678 pdp
->base
.drawable
= drawable
;
679 pdp
->base
.psc
= &psc
->base
;
681 ret
= driswCreateGCs(pdp
, psc
->base
.dpy
, xDrawable
, modes
->visualID
);
687 /* Create a new drawable */
689 (*swrast
->createNewDrawable
) (psc
->driScreen
, config
->driConfig
, pdp
);
691 if (!pdp
->driDrawable
) {
692 XDestroyDrawable(pdp
, psc
->base
.dpy
, xDrawable
);
697 pdp
->base
.destroyDrawable
= driswDestroyDrawable
;
703 driswSwapBuffers(__GLXDRIdrawable
* pdraw
,
704 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
707 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
708 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
718 (*psc
->core
->swapBuffers
) (pdp
->driDrawable
);
724 driswCopySubBuffer(__GLXDRIdrawable
* pdraw
,
725 int x
, int y
, int width
, int height
, Bool flush
)
727 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
728 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
734 (*psc
->copySubBuffer
->copySubBuffer
) (pdp
->driDrawable
,
735 x
, y
, width
, height
);
739 driswDestroyScreen(struct glx_screen
*base
)
741 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
743 /* Free the direct rendering per screen data */
744 (*psc
->core
->destroyScreen
) (psc
->driScreen
);
745 driDestroyConfigs(psc
->driver_configs
);
746 psc
->driScreen
= NULL
;
748 dlclose(psc
->driver
);
752 #define SWRAST_DRIVER_NAME "swrast"
754 static const struct glx_screen_vtable drisw_screen_vtable
= {
755 .create_context
= drisw_create_context
,
756 .create_context_attribs
= drisw_create_context_attribs
,
757 .query_renderer_integer
= drisw_query_renderer_integer
,
758 .query_renderer_string
= drisw_query_renderer_string
,
762 driswBindExtensions(struct drisw_screen
*psc
, const __DRIextension
**extensions
)
766 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_make_current_read");
768 if (psc
->swrast
->base
.version
>= 3) {
769 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context");
770 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context_profile");
772 /* DRISW version >= 2 implies support for OpenGL ES.
774 __glXEnableDirectExtension(&psc
->base
,
775 "GLX_EXT_create_context_es_profile");
776 __glXEnableDirectExtension(&psc
->base
,
777 "GLX_EXT_create_context_es2_profile");
780 if (psc
->copySubBuffer
)
781 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
783 /* FIXME: Figure out what other extensions can be ported here from dri2. */
784 for (i
= 0; extensions
[i
]; i
++) {
785 if ((strcmp(extensions
[i
]->name
, __DRI_TEX_BUFFER
) == 0)) {
786 psc
->texBuffer
= (__DRItexBufferExtension
*) extensions
[i
];
787 __glXEnableDirectExtension(&psc
->base
, "GLX_EXT_texture_from_pixmap");
789 /* DRISW version 3 is also required because GLX_MESA_query_renderer
790 * requires GLX_ARB_create_context_profile.
792 if (psc
->swrast
->base
.version
>= 3
793 && strcmp(extensions
[i
]->name
, __DRI2_RENDERER_QUERY
) == 0) {
794 psc
->rendererQuery
= (__DRI2rendererQueryExtension
*) extensions
[i
];
795 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_query_renderer");
797 if (strcmp(extensions
[i
]->name
, __DRI2_FLUSH_CONTROL
) == 0) {
798 __glXEnableDirectExtension(&psc
->base
,
799 "GLX_ARB_context_flush_control");
805 check_xshm(Display
*dpy
)
807 int (*old_handler
)(Display
*, XErrorEvent
*);
810 XShmSegmentInfo info
= { 0, };
812 if (!XQueryExtension(dpy
, "MIT-SHM", &xshm_opcode
, &ignore
, &ignore
))
815 old_handler
= XSetErrorHandler(handle_xerror
);
816 XShmDetach(dpy
, &info
);
818 (void) XSetErrorHandler(old_handler
);
820 /* BadRequest means we're a remote client. If we were local we'd
821 * expect BadValue since 'info' has an invalid segment name.
823 if (xshm_error
== BadRequest
)
830 static struct glx_screen
*
831 driswCreateScreen(int screen
, struct glx_display
*priv
)
834 const __DRIconfig
**driver_configs
;
835 const __DRIextension
**extensions
;
836 struct drisw_screen
*psc
;
837 struct glx_config
*configs
= NULL
, *visuals
= NULL
;
839 const __DRIextension
**loader_extensions_local
;
841 psc
= calloc(1, sizeof *psc
);
845 if (!glx_screen_init(&psc
->base
, screen
, priv
)) {
850 extensions
= driOpenDriver(SWRAST_DRIVER_NAME
, &psc
->driver
);
851 if (extensions
== NULL
)
854 if (!check_xshm(psc
->base
.dpy
))
855 loader_extensions_local
= loader_extensions_noshm
;
857 loader_extensions_local
= loader_extensions_shm
;
859 for (i
= 0; extensions
[i
]; i
++) {
860 if (strcmp(extensions
[i
]->name
, __DRI_CORE
) == 0)
861 psc
->core
= (__DRIcoreExtension
*) extensions
[i
];
862 if (strcmp(extensions
[i
]->name
, __DRI_SWRAST
) == 0)
863 psc
->swrast
= (__DRIswrastExtension
*) extensions
[i
];
864 if (strcmp(extensions
[i
]->name
, __DRI_COPY_SUB_BUFFER
) == 0)
865 psc
->copySubBuffer
= (__DRIcopySubBufferExtension
*) extensions
[i
];
868 if (psc
->core
== NULL
|| psc
->swrast
== NULL
) {
869 ErrorMessageF("core dri extension not found\n");
873 if (psc
->swrast
->base
.version
>= 4) {
875 psc
->swrast
->createNewScreen2(screen
, loader_extensions_local
,
877 &driver_configs
, psc
);
880 psc
->swrast
->createNewScreen(screen
, loader_extensions_local
,
881 &driver_configs
, psc
);
883 if (psc
->driScreen
== NULL
) {
884 ErrorMessageF("failed to create dri screen\n");
888 extensions
= psc
->core
->getExtensions(psc
->driScreen
);
889 driswBindExtensions(psc
, extensions
);
891 configs
= driConvertConfigs(psc
->core
, psc
->base
.configs
, driver_configs
);
892 visuals
= driConvertConfigs(psc
->core
, psc
->base
.visuals
, driver_configs
);
894 if (!configs
|| !visuals
) {
895 ErrorMessageF("No matching fbConfigs or visuals found\n");
899 glx_config_destroy_list(psc
->base
.configs
);
900 psc
->base
.configs
= configs
;
901 glx_config_destroy_list(psc
->base
.visuals
);
902 psc
->base
.visuals
= visuals
;
904 psc
->driver_configs
= driver_configs
;
906 psc
->base
.vtable
= &drisw_screen_vtable
;
908 psc
->base
.driScreen
= psp
;
909 psp
->destroyScreen
= driswDestroyScreen
;
910 psp
->createDrawable
= driswCreateDrawable
;
911 psp
->swapBuffers
= driswSwapBuffers
;
913 if (psc
->copySubBuffer
)
914 psp
->copySubBuffer
= driswCopySubBuffer
;
920 glx_config_destroy_list(configs
);
922 glx_config_destroy_list(visuals
);
924 psc
->core
->destroyScreen(psc
->driScreen
);
925 psc
->driScreen
= NULL
;
928 dlclose(psc
->driver
);
929 glx_screen_cleanup(&psc
->base
);
932 CriticalErrorMessageF("failed to load driver: %s\n", SWRAST_DRIVER_NAME
);
937 /* Called from __glXFreeDisplayPrivate.
940 driswDestroyDisplay(__GLXDRIdisplay
* dpy
)
946 * Allocate, initialize and return a __DRIdisplayPrivate object.
947 * This is called from __glXInitialize() when we are given a new
950 _X_HIDDEN __GLXDRIdisplay
*
951 driswCreateDisplay(Display
* dpy
)
953 struct drisw_display
*pdpyp
;
955 pdpyp
= malloc(sizeof *pdpyp
);
959 pdpyp
->base
.destroyDisplay
= driswDestroyDisplay
;
960 pdpyp
->base
.createScreen
= driswCreateScreen
;
965 #endif /* GLX_DIRECT_RENDERING */