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
||
77 event
->minor_code
!= X_ShmAttach
)
85 XCreateDrawable(struct drisw_drawable
* pdp
, int shmid
, Display
* dpy
)
88 XDestroyImage(pdp
->ximage
);
92 if (!xshm_error
&& shmid
>= 0) {
93 pdp
->shminfo
.shmid
= shmid
;
94 pdp
->ximage
= XShmCreateImage(dpy
,
99 &pdp
->shminfo
, /* shminfo */
100 0, 0); /* width, height */
101 if (pdp
->ximage
!= NULL
) {
102 int (*old_handler
)(Display
*, XErrorEvent
*);
104 /* dispatch pending errors */
107 old_handler
= XSetErrorHandler(handle_xerror
);
108 /* This may trigger the X protocol error we're ready to catch: */
109 XShmAttach(dpy
, &pdp
->shminfo
);
113 /* we are on a remote display, this error is normal, don't print it */
114 XDestroyImage(pdp
->ximage
);
118 (void) XSetErrorHandler(old_handler
);
122 if (pdp
->ximage
== NULL
) {
123 pdp
->shminfo
.shmid
= -1;
124 pdp
->ximage
= XCreateImage(dpy
,
125 pdp
->visinfo
->visual
,
127 ZPixmap
, 0, /* format, offset */
129 0, 0, /* width, height */
131 0); /* bytes_per_line */
135 * swrast does not handle 24-bit depth with 24 bpp, so let X do the
136 * the conversion for us.
138 if (pdp
->ximage
->bits_per_pixel
== 24)
139 pdp
->ximage
->bits_per_pixel
= 32;
145 XDestroyDrawable(struct drisw_drawable
* pdp
, Display
* dpy
, XID drawable
)
148 XDestroyImage(pdp
->ximage
);
152 XFreeGC(dpy
, pdp
->gc
);
153 XFreeGC(dpy
, pdp
->swapgc
);
157 * swrast loader functions
161 swrastGetDrawableInfo(__DRIdrawable
* draw
,
162 int *x
, int *y
, int *w
, int *h
,
165 struct drisw_drawable
*pdp
= loaderPrivate
;
166 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
167 Display
*dpy
= pdraw
->psc
->dpy
;
171 unsigned uw
, uh
, bw
, depth
;
173 drawable
= pdraw
->xDrawable
;
175 XGetGeometry(dpy
, drawable
, &root
, x
, y
, &uw
, &uh
, &bw
, &depth
);
181 * Align renderbuffer pitch.
183 * This should be chosen by the driver and the loader (libGL, xserver/glx)
184 * should use the driver provided pitch.
186 * It seems that the xorg loader (that is the xserver loading swrast_dri for
187 * indirect rendering, not client-side libGL) requires that the pitch is
188 * exactly the image width padded to 32 bits. XXX
190 * The above restriction can probably be overcome by using ScratchPixmap and
191 * CopyArea in the xserver, similar to ShmPutImage, and setting the width of
192 * the scratch pixmap to 'pitch / cpp'.
195 bytes_per_line(unsigned pitch_bits
, unsigned mul
)
197 unsigned mask
= mul
- 1;
199 return ((pitch_bits
+ mask
) & ~mask
) / 8;
203 swrastXPutImage(__DRIdrawable
* draw
, int op
,
204 int srcx
, int srcy
, int x
, int y
,
205 int w
, int h
, int stride
,
206 int shmid
, char *data
, void *loaderPrivate
)
208 struct drisw_drawable
*pdp
= loaderPrivate
;
209 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
210 Display
*dpy
= pdraw
->psc
->dpy
;
215 if (!pdp
->ximage
|| shmid
!= pdp
->shminfo
.shmid
) {
216 if (!XCreateDrawable(pdp
, shmid
, dpy
))
221 case __DRI_SWRAST_IMAGE_OP_DRAW
:
224 case __DRI_SWRAST_IMAGE_OP_SWAP
:
231 drawable
= pdraw
->xDrawable
;
232 ximage
= pdp
->ximage
;
233 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
236 if (pdp
->shminfo
.shmid
>= 0) {
237 ximage
->width
= ximage
->bytes_per_line
/ ((ximage
->bits_per_pixel
+ 7)/ 8);
239 XShmPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
, False
);
244 XPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
);
250 swrastPutImageShm(__DRIdrawable
* draw
, int op
,
251 int x
, int y
, int w
, int h
, int stride
,
252 int shmid
, char *shmaddr
, unsigned offset
,
255 struct drisw_drawable
*pdp
= loaderPrivate
;
257 pdp
->shminfo
.shmaddr
= shmaddr
;
258 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, shmid
,
259 shmaddr
+ offset
, loaderPrivate
);
263 swrastPutImageShm2(__DRIdrawable
* draw
, int op
,
265 int w
, int h
, int stride
,
266 int shmid
, char *shmaddr
, unsigned offset
,
269 struct drisw_drawable
*pdp
= loaderPrivate
;
271 pdp
->shminfo
.shmaddr
= shmaddr
;
272 swrastXPutImage(draw
, op
, x
, 0, x
, y
, w
, h
, stride
, shmid
,
273 shmaddr
+ offset
, loaderPrivate
);
277 swrastPutImage2(__DRIdrawable
* draw
, int op
,
278 int x
, int y
, int w
, int h
, int stride
,
279 char *data
, void *loaderPrivate
)
281 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, -1,
282 data
, loaderPrivate
);
286 swrastPutImage(__DRIdrawable
* draw
, int op
,
287 int x
, int y
, int w
, int h
,
288 char *data
, void *loaderPrivate
)
290 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, 0, -1,
291 data
, loaderPrivate
);
295 swrastGetImage2(__DRIdrawable
* read
,
296 int x
, int y
, int w
, int h
, int stride
,
297 char *data
, void *loaderPrivate
)
299 struct drisw_drawable
*prp
= loaderPrivate
;
300 __GLXDRIdrawable
*pread
= &(prp
->base
);
301 Display
*dpy
= pread
->psc
->dpy
;
305 if (!prp
->ximage
|| prp
->shminfo
.shmid
>= 0) {
306 if (!XCreateDrawable(prp
, -1, dpy
))
310 readable
= pread
->xDrawable
;
312 ximage
= prp
->ximage
;
316 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
318 XGetSubImage(dpy
, readable
, x
, y
, w
, h
, ~0L, ZPixmap
, ximage
, 0, 0);
324 swrastGetImage(__DRIdrawable
* read
,
325 int x
, int y
, int w
, int h
,
326 char *data
, void *loaderPrivate
)
328 swrastGetImage2(read
, x
, y
, w
, h
, 0, data
, loaderPrivate
);
332 swrastGetImageShm(__DRIdrawable
* read
,
333 int x
, int y
, int w
, int h
,
334 int shmid
, void *loaderPrivate
)
336 struct drisw_drawable
*prp
= loaderPrivate
;
337 __GLXDRIdrawable
*pread
= &(prp
->base
);
338 Display
*dpy
= pread
->psc
->dpy
;
342 if (!prp
->ximage
|| shmid
!= prp
->shminfo
.shmid
) {
343 if (!XCreateDrawable(prp
, shmid
, dpy
))
346 readable
= pread
->xDrawable
;
348 ximage
= prp
->ximage
;
349 ximage
->data
= prp
->shminfo
.shmaddr
; /* no offset */
352 ximage
->bytes_per_line
= bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
354 XShmGetImage(dpy
, readable
, ximage
, x
, y
, ~0L);
357 static const __DRIswrastLoaderExtension swrastLoaderExtension_shm
= {
358 .base
= {__DRI_SWRAST_LOADER
, 5 },
360 .getDrawableInfo
= swrastGetDrawableInfo
,
361 .putImage
= swrastPutImage
,
362 .getImage
= swrastGetImage
,
363 .putImage2
= swrastPutImage2
,
364 .getImage2
= swrastGetImage2
,
365 .putImageShm
= swrastPutImageShm
,
366 .getImageShm
= swrastGetImageShm
,
367 .putImageShm2
= swrastPutImageShm2
,
370 static const __DRIextension
*loader_extensions_shm
[] = {
371 &swrastLoaderExtension_shm
.base
,
375 static const __DRIswrastLoaderExtension swrastLoaderExtension
= {
376 .base
= {__DRI_SWRAST_LOADER
, 3 },
378 .getDrawableInfo
= swrastGetDrawableInfo
,
379 .putImage
= swrastPutImage
,
380 .getImage
= swrastGetImage
,
381 .putImage2
= swrastPutImage2
,
382 .getImage2
= swrastGetImage2
,
385 static const __DRIextension
*loader_extensions_noshm
[] = {
386 &swrastLoaderExtension
.base
,
395 drisw_destroy_context(struct glx_context
*context
)
397 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
398 struct drisw_screen
*psc
= (struct drisw_screen
*) context
->psc
;
400 driReleaseDrawables(&pcp
->base
);
402 free((char *) context
->extensions
);
404 (*psc
->core
->destroyContext
) (pcp
->driContext
);
410 drisw_bind_context(struct glx_context
*context
, struct glx_context
*old
,
411 GLXDrawable draw
, GLXDrawable read
)
413 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
414 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
415 struct drisw_drawable
*pdraw
, *pread
;
417 pdraw
= (struct drisw_drawable
*) driFetchDrawable(context
, draw
);
418 pread
= (struct drisw_drawable
*) driFetchDrawable(context
, read
);
420 driReleaseDrawables(&pcp
->base
);
422 if ((*psc
->core
->bindContext
) (pcp
->driContext
,
423 pdraw
? pdraw
->driDrawable
: NULL
,
424 pread
? pread
->driDrawable
: NULL
))
427 return GLXBadContext
;
431 drisw_unbind_context(struct glx_context
*context
, struct glx_context
*new)
433 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
434 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
436 (*psc
->core
->unbindContext
) (pcp
->driContext
);
440 drisw_bind_tex_image(Display
* dpy
,
441 GLXDrawable drawable
,
442 int buffer
, const int *attrib_list
)
444 struct glx_context
*gc
= __glXGetCurrentContext();
445 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
446 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
447 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
448 struct drisw_screen
*psc
;
450 __glXInitialize(dpy
);
453 psc
= (struct drisw_screen
*) base
->psc
;
458 if (psc
->texBuffer
->base
.version
>= 2 &&
459 psc
->texBuffer
->setTexBuffer2
!= NULL
) {
460 (*psc
->texBuffer
->setTexBuffer2
) (pcp
->driContext
,
461 pdraw
->base
.textureTarget
,
462 pdraw
->base
.textureFormat
,
466 (*psc
->texBuffer
->setTexBuffer
) (pcp
->driContext
,
467 pdraw
->base
.textureTarget
,
474 drisw_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
476 struct glx_context
*gc
= __glXGetCurrentContext();
477 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
478 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
479 struct glx_display
*dpyPriv
= __glXInitialize(dpy
);
480 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
481 struct drisw_screen
*psc
;
483 if (dpyPriv
!= NULL
&& pdraw
!= NULL
) {
484 psc
= (struct drisw_screen
*) base
->psc
;
489 if (psc
->texBuffer
->base
.version
>= 3 &&
490 psc
->texBuffer
->releaseTexBuffer
!= NULL
) {
491 (*psc
->texBuffer
->releaseTexBuffer
) (pcp
->driContext
,
492 pdraw
->base
.textureTarget
,
498 static const struct glx_context_vtable drisw_context_vtable
= {
499 .destroy
= drisw_destroy_context
,
500 .bind
= drisw_bind_context
,
501 .unbind
= drisw_unbind_context
,
504 .use_x_font
= DRI_glXUseXFont
,
505 .bind_tex_image
= drisw_bind_tex_image
,
506 .release_tex_image
= drisw_release_tex_image
,
507 .get_proc_address
= NULL
,
510 static struct glx_context
*
511 drisw_create_context(struct glx_screen
*base
,
512 struct glx_config
*config_base
,
513 struct glx_context
*shareList
, int renderType
)
515 struct drisw_context
*pcp
, *pcp_shared
;
516 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
517 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
518 __DRIcontext
*shared
= NULL
;
520 if (!psc
->base
.driScreen
)
523 /* Check the renderType value */
524 if (!validate_renderType_against_config(config_base
, renderType
))
528 /* If the shareList context is not a DRISW context, we cannot possibly
529 * create a DRISW context that shares it.
531 if (shareList
->vtable
->destroy
!= drisw_destroy_context
) {
535 pcp_shared
= (struct drisw_context
*) shareList
;
536 shared
= pcp_shared
->driContext
;
539 pcp
= calloc(1, sizeof *pcp
);
543 if (!glx_context_init(&pcp
->base
, &psc
->base
, &config
->base
)) {
548 pcp
->base
.renderType
= renderType
;
551 (*psc
->core
->createNewContext
) (psc
->driScreen
,
552 config
->driConfig
, shared
, pcp
);
553 if (pcp
->driContext
== NULL
) {
558 pcp
->base
.vtable
= &drisw_context_vtable
;
563 static struct glx_context
*
564 drisw_create_context_attribs(struct glx_screen
*base
,
565 struct glx_config
*config_base
,
566 struct glx_context
*shareList
,
567 unsigned num_attribs
,
568 const uint32_t *attribs
,
571 struct drisw_context
*pcp
, *pcp_shared
;
572 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
573 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
574 __DRIcontext
*shared
= NULL
;
583 uint32_t ctx_attribs
[2 * 5];
584 unsigned num_ctx_attribs
= 0;
586 if (!psc
->base
.driScreen
)
589 if (psc
->swrast
->base
.version
< 3)
592 /* Remap the GLX tokens to DRI2 tokens.
594 if (!dri2_convert_glx_attribs(num_attribs
, attribs
,
595 &major_ver
, &minor_ver
, &renderType
, &flags
,
596 &api
, &reset
, &release
, error
))
599 /* Check the renderType value */
600 if (!validate_renderType_against_config(config_base
, renderType
)) {
604 if (reset
!= __DRI_CTX_RESET_NO_NOTIFICATION
)
607 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
&&
608 release
!= __DRI_CTX_RELEASE_BEHAVIOR_NONE
)
612 pcp_shared
= (struct drisw_context
*) shareList
;
613 shared
= pcp_shared
->driContext
;
616 pcp
= calloc(1, sizeof *pcp
);
620 if (!glx_context_init(&pcp
->base
, &psc
->base
, config_base
)) {
625 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
626 ctx_attribs
[num_ctx_attribs
++] = major_ver
;
627 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
628 ctx_attribs
[num_ctx_attribs
++] = minor_ver
;
629 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
) {
630 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
631 ctx_attribs
[num_ctx_attribs
++] = release
;
635 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_FLAGS
;
637 /* The current __DRI_CTX_FLAG_* values are identical to the
638 * GLX_CONTEXT_*_BIT values.
640 ctx_attribs
[num_ctx_attribs
++] = flags
;
643 pcp
->base
.renderType
= renderType
;
646 (*psc
->swrast
->createContextAttribs
) (psc
->driScreen
,
648 config
? config
->driConfig
: 0,
654 if (pcp
->driContext
== NULL
) {
659 pcp
->base
.vtable
= &drisw_context_vtable
;
665 driswDestroyDrawable(__GLXDRIdrawable
* pdraw
)
667 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
668 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
670 (*psc
->core
->destroyDrawable
) (pdp
->driDrawable
);
672 XDestroyDrawable(pdp
, pdraw
->psc
->dpy
, pdraw
->drawable
);
676 static __GLXDRIdrawable
*
677 driswCreateDrawable(struct glx_screen
*base
, XID xDrawable
,
678 GLXDrawable drawable
, struct glx_config
*modes
)
680 struct drisw_drawable
*pdp
;
681 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) modes
;
682 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
684 const __DRIswrastExtension
*swrast
= psc
->swrast
;
686 pdp
= calloc(1, sizeof(*pdp
));
690 pdp
->base
.xDrawable
= xDrawable
;
691 pdp
->base
.drawable
= drawable
;
692 pdp
->base
.psc
= &psc
->base
;
694 ret
= XCreateGCs(pdp
, psc
->base
.dpy
, xDrawable
, modes
->visualID
);
700 /* Create a new drawable */
702 (*swrast
->createNewDrawable
) (psc
->driScreen
, config
->driConfig
, pdp
);
704 if (!pdp
->driDrawable
) {
705 XDestroyDrawable(pdp
, psc
->base
.dpy
, xDrawable
);
710 pdp
->base
.destroyDrawable
= driswDestroyDrawable
;
716 driswSwapBuffers(__GLXDRIdrawable
* pdraw
,
717 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
720 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
721 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
731 (*psc
->core
->swapBuffers
) (pdp
->driDrawable
);
737 driswCopySubBuffer(__GLXDRIdrawable
* pdraw
,
738 int x
, int y
, int width
, int height
, Bool flush
)
740 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
741 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
747 (*psc
->copySubBuffer
->copySubBuffer
) (pdp
->driDrawable
,
748 x
, y
, width
, height
);
752 driswDestroyScreen(struct glx_screen
*base
)
754 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
756 /* Free the direct rendering per screen data */
757 (*psc
->core
->destroyScreen
) (psc
->driScreen
);
758 driDestroyConfigs(psc
->driver_configs
);
759 psc
->driScreen
= NULL
;
761 dlclose(psc
->driver
);
765 #define SWRAST_DRIVER_NAME "swrast"
767 static const struct glx_screen_vtable drisw_screen_vtable
= {
768 .create_context
= drisw_create_context
,
769 .create_context_attribs
= drisw_create_context_attribs
,
770 .query_renderer_integer
= drisw_query_renderer_integer
,
771 .query_renderer_string
= drisw_query_renderer_string
,
775 driswBindExtensions(struct drisw_screen
*psc
, const __DRIextension
**extensions
)
779 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_make_current_read");
781 if (psc
->swrast
->base
.version
>= 3) {
782 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context");
783 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context_profile");
785 /* DRISW version >= 2 implies support for OpenGL ES.
787 __glXEnableDirectExtension(&psc
->base
,
788 "GLX_EXT_create_context_es_profile");
789 __glXEnableDirectExtension(&psc
->base
,
790 "GLX_EXT_create_context_es2_profile");
793 if (psc
->copySubBuffer
)
794 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
796 /* FIXME: Figure out what other extensions can be ported here from dri2. */
797 for (i
= 0; extensions
[i
]; i
++) {
798 if ((strcmp(extensions
[i
]->name
, __DRI_TEX_BUFFER
) == 0)) {
799 psc
->texBuffer
= (__DRItexBufferExtension
*) extensions
[i
];
800 __glXEnableDirectExtension(&psc
->base
, "GLX_EXT_texture_from_pixmap");
802 /* DRISW version 3 is also required because GLX_MESA_query_renderer
803 * requires GLX_ARB_create_context_profile.
805 if (psc
->swrast
->base
.version
>= 3
806 && strcmp(extensions
[i
]->name
, __DRI2_RENDERER_QUERY
) == 0) {
807 psc
->rendererQuery
= (__DRI2rendererQueryExtension
*) extensions
[i
];
808 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_query_renderer");
810 if (strcmp(extensions
[i
]->name
, __DRI2_FLUSH_CONTROL
) == 0) {
811 __glXEnableDirectExtension(&psc
->base
,
812 "GLX_ARB_context_flush_control");
818 check_xshm(Display
*dpy
)
822 return XQueryExtension(dpy
, "MIT-SHM", &xshm_opcode
, &ignore
, &ignore
);
825 static struct glx_screen
*
826 driswCreateScreen(int screen
, struct glx_display
*priv
)
829 const __DRIconfig
**driver_configs
;
830 const __DRIextension
**extensions
;
831 struct drisw_screen
*psc
;
832 struct glx_config
*configs
= NULL
, *visuals
= NULL
;
834 const __DRIextension
**loader_extensions_local
;
836 psc
= calloc(1, sizeof *psc
);
840 if (!glx_screen_init(&psc
->base
, screen
, priv
)) {
845 extensions
= driOpenDriver(SWRAST_DRIVER_NAME
, &psc
->driver
);
846 if (extensions
== NULL
)
849 if (!check_xshm(psc
->base
.dpy
))
850 loader_extensions_local
= loader_extensions_noshm
;
852 loader_extensions_local
= loader_extensions_shm
;
854 for (i
= 0; extensions
[i
]; i
++) {
855 if (strcmp(extensions
[i
]->name
, __DRI_CORE
) == 0)
856 psc
->core
= (__DRIcoreExtension
*) extensions
[i
];
857 if (strcmp(extensions
[i
]->name
, __DRI_SWRAST
) == 0)
858 psc
->swrast
= (__DRIswrastExtension
*) extensions
[i
];
859 if (strcmp(extensions
[i
]->name
, __DRI_COPY_SUB_BUFFER
) == 0)
860 psc
->copySubBuffer
= (__DRIcopySubBufferExtension
*) extensions
[i
];
863 if (psc
->core
== NULL
|| psc
->swrast
== NULL
) {
864 ErrorMessageF("core dri extension not found\n");
868 if (psc
->swrast
->base
.version
>= 4) {
870 psc
->swrast
->createNewScreen2(screen
, loader_extensions_local
,
872 &driver_configs
, psc
);
875 psc
->swrast
->createNewScreen(screen
, loader_extensions_local
,
876 &driver_configs
, psc
);
878 if (psc
->driScreen
== NULL
) {
879 ErrorMessageF("failed to create dri screen\n");
883 extensions
= psc
->core
->getExtensions(psc
->driScreen
);
884 driswBindExtensions(psc
, extensions
);
886 configs
= driConvertConfigs(psc
->core
, psc
->base
.configs
, driver_configs
);
887 visuals
= driConvertConfigs(psc
->core
, psc
->base
.visuals
, driver_configs
);
889 if (!configs
|| !visuals
) {
890 ErrorMessageF("No matching fbConfigs or visuals found\n");
894 glx_config_destroy_list(psc
->base
.configs
);
895 psc
->base
.configs
= configs
;
896 glx_config_destroy_list(psc
->base
.visuals
);
897 psc
->base
.visuals
= visuals
;
899 psc
->driver_configs
= driver_configs
;
901 psc
->base
.vtable
= &drisw_screen_vtable
;
903 psc
->base
.driScreen
= psp
;
904 psp
->destroyScreen
= driswDestroyScreen
;
905 psp
->createDrawable
= driswCreateDrawable
;
906 psp
->swapBuffers
= driswSwapBuffers
;
908 if (psc
->copySubBuffer
)
909 psp
->copySubBuffer
= driswCopySubBuffer
;
915 glx_config_destroy_list(configs
);
917 glx_config_destroy_list(visuals
);
919 psc
->core
->destroyScreen(psc
->driScreen
);
920 psc
->driScreen
= NULL
;
923 dlclose(psc
->driver
);
924 glx_screen_cleanup(&psc
->base
);
927 CriticalErrorMessageF("failed to load driver: %s\n", SWRAST_DRIVER_NAME
);
932 /* Called from __glXFreeDisplayPrivate.
935 driswDestroyDisplay(__GLXDRIdisplay
* dpy
)
941 * Allocate, initialize and return a __DRIdisplayPrivate object.
942 * This is called from __glXInitialize() when we are given a new
945 _X_HIDDEN __GLXDRIdisplay
*
946 driswCreateDisplay(Display
* dpy
)
948 struct drisw_display
*pdpyp
;
950 pdpyp
= malloc(sizeof *pdpyp
);
954 pdpyp
->base
.destroyDisplay
= driswDestroyDisplay
;
955 pdpyp
->base
.createScreen
= driswCreateScreen
;
960 #endif /* GLX_DIRECT_RENDERING */