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
);
150 if (pdp
->shminfo
.shmid
> 0)
151 XShmDetach(dpy
, &pdp
->shminfo
);
155 XFreeGC(dpy
, pdp
->gc
);
156 XFreeGC(dpy
, pdp
->swapgc
);
160 * swrast loader functions
164 swrastGetDrawableInfo(__DRIdrawable
* draw
,
165 int *x
, int *y
, int *w
, int *h
,
168 struct drisw_drawable
*pdp
= loaderPrivate
;
169 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
170 Display
*dpy
= pdraw
->psc
->dpy
;
174 unsigned uw
, uh
, bw
, depth
;
176 drawable
= pdraw
->xDrawable
;
178 XGetGeometry(dpy
, drawable
, &root
, x
, y
, &uw
, &uh
, &bw
, &depth
);
184 * Align renderbuffer pitch.
186 * This should be chosen by the driver and the loader (libGL, xserver/glx)
187 * should use the driver provided pitch.
189 * It seems that the xorg loader (that is the xserver loading swrast_dri for
190 * indirect rendering, not client-side libGL) requires that the pitch is
191 * exactly the image width padded to 32 bits. XXX
193 * The above restriction can probably be overcome by using ScratchPixmap and
194 * CopyArea in the xserver, similar to ShmPutImage, and setting the width of
195 * the scratch pixmap to 'pitch / cpp'.
198 bytes_per_line(unsigned pitch_bits
, unsigned mul
)
200 unsigned mask
= mul
- 1;
202 return ((pitch_bits
+ mask
) & ~mask
) / 8;
206 swrastXPutImage(__DRIdrawable
* draw
, int op
,
207 int srcx
, int srcy
, int x
, int y
,
208 int w
, int h
, int stride
,
209 int shmid
, char *data
, void *loaderPrivate
)
211 struct drisw_drawable
*pdp
= loaderPrivate
;
212 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
213 Display
*dpy
= pdraw
->psc
->dpy
;
218 if (!pdp
->ximage
|| shmid
!= pdp
->shminfo
.shmid
) {
219 if (!XCreateDrawable(pdp
, shmid
, dpy
))
224 case __DRI_SWRAST_IMAGE_OP_DRAW
:
227 case __DRI_SWRAST_IMAGE_OP_SWAP
:
234 drawable
= pdraw
->xDrawable
;
235 ximage
= pdp
->ximage
;
236 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
239 if (pdp
->shminfo
.shmid
>= 0) {
240 ximage
->width
= ximage
->bytes_per_line
/ ((ximage
->bits_per_pixel
+ 7)/ 8);
242 XShmPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
, False
);
247 XPutImage(dpy
, drawable
, gc
, ximage
, srcx
, srcy
, x
, y
, w
, h
);
253 swrastPutImageShm(__DRIdrawable
* draw
, int op
,
254 int x
, int y
, int w
, int h
, int stride
,
255 int shmid
, char *shmaddr
, unsigned offset
,
258 struct drisw_drawable
*pdp
= loaderPrivate
;
260 pdp
->shminfo
.shmaddr
= shmaddr
;
261 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, shmid
,
262 shmaddr
+ offset
, loaderPrivate
);
266 swrastPutImageShm2(__DRIdrawable
* draw
, int op
,
268 int w
, int h
, int stride
,
269 int shmid
, char *shmaddr
, unsigned offset
,
272 struct drisw_drawable
*pdp
= loaderPrivate
;
274 pdp
->shminfo
.shmaddr
= shmaddr
;
275 swrastXPutImage(draw
, op
, x
, 0, x
, y
, w
, h
, stride
, shmid
,
276 shmaddr
+ offset
, loaderPrivate
);
280 swrastPutImage2(__DRIdrawable
* draw
, int op
,
281 int x
, int y
, int w
, int h
, int stride
,
282 char *data
, void *loaderPrivate
)
284 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, stride
, -1,
285 data
, loaderPrivate
);
289 swrastPutImage(__DRIdrawable
* draw
, int op
,
290 int x
, int y
, int w
, int h
,
291 char *data
, void *loaderPrivate
)
293 swrastXPutImage(draw
, op
, 0, 0, x
, y
, w
, h
, 0, -1,
294 data
, loaderPrivate
);
298 swrastGetImage2(__DRIdrawable
* read
,
299 int x
, int y
, int w
, int h
, int stride
,
300 char *data
, void *loaderPrivate
)
302 struct drisw_drawable
*prp
= loaderPrivate
;
303 __GLXDRIdrawable
*pread
= &(prp
->base
);
304 Display
*dpy
= pread
->psc
->dpy
;
308 if (!prp
->ximage
|| prp
->shminfo
.shmid
>= 0) {
309 if (!XCreateDrawable(prp
, -1, dpy
))
313 readable
= pread
->xDrawable
;
315 ximage
= prp
->ximage
;
319 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
321 XGetSubImage(dpy
, readable
, x
, y
, w
, h
, ~0L, ZPixmap
, ximage
, 0, 0);
327 swrastGetImage(__DRIdrawable
* read
,
328 int x
, int y
, int w
, int h
,
329 char *data
, void *loaderPrivate
)
331 swrastGetImage2(read
, x
, y
, w
, h
, 0, data
, loaderPrivate
);
335 swrastGetImageShm(__DRIdrawable
* read
,
336 int x
, int y
, int w
, int h
,
337 int shmid
, void *loaderPrivate
)
339 struct drisw_drawable
*prp
= loaderPrivate
;
340 __GLXDRIdrawable
*pread
= &(prp
->base
);
341 Display
*dpy
= pread
->psc
->dpy
;
345 if (!prp
->ximage
|| shmid
!= prp
->shminfo
.shmid
) {
346 if (!XCreateDrawable(prp
, shmid
, dpy
))
349 readable
= pread
->xDrawable
;
351 ximage
= prp
->ximage
;
352 ximage
->data
= prp
->shminfo
.shmaddr
; /* no offset */
355 ximage
->bytes_per_line
= bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
357 XShmGetImage(dpy
, readable
, ximage
, x
, y
, ~0L);
360 static const __DRIswrastLoaderExtension swrastLoaderExtension_shm
= {
361 .base
= {__DRI_SWRAST_LOADER
, 5 },
363 .getDrawableInfo
= swrastGetDrawableInfo
,
364 .putImage
= swrastPutImage
,
365 .getImage
= swrastGetImage
,
366 .putImage2
= swrastPutImage2
,
367 .getImage2
= swrastGetImage2
,
368 .putImageShm
= swrastPutImageShm
,
369 .getImageShm
= swrastGetImageShm
,
370 .putImageShm2
= swrastPutImageShm2
,
373 static const __DRIextension
*loader_extensions_shm
[] = {
374 &swrastLoaderExtension_shm
.base
,
378 static const __DRIswrastLoaderExtension swrastLoaderExtension
= {
379 .base
= {__DRI_SWRAST_LOADER
, 3 },
381 .getDrawableInfo
= swrastGetDrawableInfo
,
382 .putImage
= swrastPutImage
,
383 .getImage
= swrastGetImage
,
384 .putImage2
= swrastPutImage2
,
385 .getImage2
= swrastGetImage2
,
388 static const __DRIextension
*loader_extensions_noshm
[] = {
389 &swrastLoaderExtension
.base
,
398 drisw_destroy_context(struct glx_context
*context
)
400 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
401 struct drisw_screen
*psc
= (struct drisw_screen
*) context
->psc
;
403 driReleaseDrawables(&pcp
->base
);
405 free((char *) context
->extensions
);
407 (*psc
->core
->destroyContext
) (pcp
->driContext
);
413 drisw_bind_context(struct glx_context
*context
, struct glx_context
*old
,
414 GLXDrawable draw
, GLXDrawable read
)
416 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
417 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
418 struct drisw_drawable
*pdraw
, *pread
;
420 pdraw
= (struct drisw_drawable
*) driFetchDrawable(context
, draw
);
421 pread
= (struct drisw_drawable
*) driFetchDrawable(context
, read
);
423 driReleaseDrawables(&pcp
->base
);
425 if ((*psc
->core
->bindContext
) (pcp
->driContext
,
426 pdraw
? pdraw
->driDrawable
: NULL
,
427 pread
? pread
->driDrawable
: NULL
))
430 return GLXBadContext
;
434 drisw_unbind_context(struct glx_context
*context
, struct glx_context
*new)
436 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
437 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
439 (*psc
->core
->unbindContext
) (pcp
->driContext
);
443 drisw_bind_tex_image(Display
* dpy
,
444 GLXDrawable drawable
,
445 int buffer
, const int *attrib_list
)
447 struct glx_context
*gc
= __glXGetCurrentContext();
448 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
449 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
450 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
451 struct drisw_screen
*psc
;
453 __glXInitialize(dpy
);
456 psc
= (struct drisw_screen
*) base
->psc
;
461 if (psc
->texBuffer
->base
.version
>= 2 &&
462 psc
->texBuffer
->setTexBuffer2
!= NULL
) {
463 (*psc
->texBuffer
->setTexBuffer2
) (pcp
->driContext
,
464 pdraw
->base
.textureTarget
,
465 pdraw
->base
.textureFormat
,
469 (*psc
->texBuffer
->setTexBuffer
) (pcp
->driContext
,
470 pdraw
->base
.textureTarget
,
477 drisw_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
479 struct glx_context
*gc
= __glXGetCurrentContext();
480 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
481 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
482 struct glx_display
*dpyPriv
= __glXInitialize(dpy
);
483 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
484 struct drisw_screen
*psc
;
486 if (dpyPriv
!= NULL
&& pdraw
!= NULL
) {
487 psc
= (struct drisw_screen
*) base
->psc
;
492 if (psc
->texBuffer
->base
.version
>= 3 &&
493 psc
->texBuffer
->releaseTexBuffer
!= NULL
) {
494 (*psc
->texBuffer
->releaseTexBuffer
) (pcp
->driContext
,
495 pdraw
->base
.textureTarget
,
501 static const struct glx_context_vtable drisw_context_vtable
= {
502 .destroy
= drisw_destroy_context
,
503 .bind
= drisw_bind_context
,
504 .unbind
= drisw_unbind_context
,
507 .use_x_font
= DRI_glXUseXFont
,
508 .bind_tex_image
= drisw_bind_tex_image
,
509 .release_tex_image
= drisw_release_tex_image
,
510 .get_proc_address
= NULL
,
513 static struct glx_context
*
514 drisw_create_context(struct glx_screen
*base
,
515 struct glx_config
*config_base
,
516 struct glx_context
*shareList
, int renderType
)
518 struct drisw_context
*pcp
, *pcp_shared
;
519 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
520 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
521 __DRIcontext
*shared
= NULL
;
523 if (!psc
->base
.driScreen
)
526 /* Check the renderType value */
527 if (!validate_renderType_against_config(config_base
, renderType
))
531 /* If the shareList context is not a DRISW context, we cannot possibly
532 * create a DRISW context that shares it.
534 if (shareList
->vtable
->destroy
!= drisw_destroy_context
) {
538 pcp_shared
= (struct drisw_context
*) shareList
;
539 shared
= pcp_shared
->driContext
;
542 pcp
= calloc(1, sizeof *pcp
);
546 if (!glx_context_init(&pcp
->base
, &psc
->base
, &config
->base
)) {
551 pcp
->base
.renderType
= renderType
;
554 (*psc
->core
->createNewContext
) (psc
->driScreen
,
555 config
->driConfig
, shared
, pcp
);
556 if (pcp
->driContext
== NULL
) {
561 pcp
->base
.vtable
= &drisw_context_vtable
;
566 static struct glx_context
*
567 drisw_create_context_attribs(struct glx_screen
*base
,
568 struct glx_config
*config_base
,
569 struct glx_context
*shareList
,
570 unsigned num_attribs
,
571 const uint32_t *attribs
,
574 struct drisw_context
*pcp
, *pcp_shared
;
575 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
576 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
577 __DRIcontext
*shared
= NULL
;
586 uint32_t ctx_attribs
[2 * 5];
587 unsigned num_ctx_attribs
= 0;
589 if (!psc
->base
.driScreen
)
592 if (psc
->swrast
->base
.version
< 3)
595 /* Remap the GLX tokens to DRI2 tokens.
597 if (!dri2_convert_glx_attribs(num_attribs
, attribs
,
598 &major_ver
, &minor_ver
, &renderType
, &flags
,
599 &api
, &reset
, &release
, error
))
602 /* Check the renderType value */
603 if (!validate_renderType_against_config(config_base
, renderType
)) {
607 if (reset
!= __DRI_CTX_RESET_NO_NOTIFICATION
)
610 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
&&
611 release
!= __DRI_CTX_RELEASE_BEHAVIOR_NONE
)
615 pcp_shared
= (struct drisw_context
*) shareList
;
616 shared
= pcp_shared
->driContext
;
619 pcp
= calloc(1, sizeof *pcp
);
623 if (!glx_context_init(&pcp
->base
, &psc
->base
, config_base
)) {
628 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
629 ctx_attribs
[num_ctx_attribs
++] = major_ver
;
630 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
631 ctx_attribs
[num_ctx_attribs
++] = minor_ver
;
632 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
) {
633 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
634 ctx_attribs
[num_ctx_attribs
++] = release
;
638 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_FLAGS
;
640 /* The current __DRI_CTX_FLAG_* values are identical to the
641 * GLX_CONTEXT_*_BIT values.
643 ctx_attribs
[num_ctx_attribs
++] = flags
;
646 pcp
->base
.renderType
= renderType
;
649 (*psc
->swrast
->createContextAttribs
) (psc
->driScreen
,
651 config
? config
->driConfig
: 0,
657 if (pcp
->driContext
== NULL
) {
662 pcp
->base
.vtable
= &drisw_context_vtable
;
668 driswDestroyDrawable(__GLXDRIdrawable
* pdraw
)
670 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
671 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
673 (*psc
->core
->destroyDrawable
) (pdp
->driDrawable
);
675 XDestroyDrawable(pdp
, pdraw
->psc
->dpy
, pdraw
->drawable
);
679 static __GLXDRIdrawable
*
680 driswCreateDrawable(struct glx_screen
*base
, XID xDrawable
,
681 GLXDrawable drawable
, struct glx_config
*modes
)
683 struct drisw_drawable
*pdp
;
684 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) modes
;
685 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
687 const __DRIswrastExtension
*swrast
= psc
->swrast
;
689 pdp
= calloc(1, sizeof(*pdp
));
693 pdp
->base
.xDrawable
= xDrawable
;
694 pdp
->base
.drawable
= drawable
;
695 pdp
->base
.psc
= &psc
->base
;
697 ret
= XCreateGCs(pdp
, psc
->base
.dpy
, xDrawable
, modes
->visualID
);
703 /* Create a new drawable */
705 (*swrast
->createNewDrawable
) (psc
->driScreen
, config
->driConfig
, pdp
);
707 if (!pdp
->driDrawable
) {
708 XDestroyDrawable(pdp
, psc
->base
.dpy
, xDrawable
);
713 pdp
->base
.destroyDrawable
= driswDestroyDrawable
;
719 driswSwapBuffers(__GLXDRIdrawable
* pdraw
,
720 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
723 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
724 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
734 (*psc
->core
->swapBuffers
) (pdp
->driDrawable
);
740 driswCopySubBuffer(__GLXDRIdrawable
* pdraw
,
741 int x
, int y
, int width
, int height
, Bool flush
)
743 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
744 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
750 (*psc
->copySubBuffer
->copySubBuffer
) (pdp
->driDrawable
,
751 x
, y
, width
, height
);
755 driswDestroyScreen(struct glx_screen
*base
)
757 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
759 /* Free the direct rendering per screen data */
760 (*psc
->core
->destroyScreen
) (psc
->driScreen
);
761 driDestroyConfigs(psc
->driver_configs
);
762 psc
->driScreen
= NULL
;
764 dlclose(psc
->driver
);
768 #define SWRAST_DRIVER_NAME "swrast"
770 static const struct glx_screen_vtable drisw_screen_vtable
= {
771 .create_context
= drisw_create_context
,
772 .create_context_attribs
= drisw_create_context_attribs
,
773 .query_renderer_integer
= drisw_query_renderer_integer
,
774 .query_renderer_string
= drisw_query_renderer_string
,
778 driswBindExtensions(struct drisw_screen
*psc
, const __DRIextension
**extensions
)
782 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_make_current_read");
784 if (psc
->swrast
->base
.version
>= 3) {
785 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context");
786 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context_profile");
788 /* DRISW version >= 2 implies support for OpenGL ES.
790 __glXEnableDirectExtension(&psc
->base
,
791 "GLX_EXT_create_context_es_profile");
792 __glXEnableDirectExtension(&psc
->base
,
793 "GLX_EXT_create_context_es2_profile");
796 if (psc
->copySubBuffer
)
797 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
799 /* FIXME: Figure out what other extensions can be ported here from dri2. */
800 for (i
= 0; extensions
[i
]; i
++) {
801 if ((strcmp(extensions
[i
]->name
, __DRI_TEX_BUFFER
) == 0)) {
802 psc
->texBuffer
= (__DRItexBufferExtension
*) extensions
[i
];
803 __glXEnableDirectExtension(&psc
->base
, "GLX_EXT_texture_from_pixmap");
805 /* DRISW version 3 is also required because GLX_MESA_query_renderer
806 * requires GLX_ARB_create_context_profile.
808 if (psc
->swrast
->base
.version
>= 3
809 && strcmp(extensions
[i
]->name
, __DRI2_RENDERER_QUERY
) == 0) {
810 psc
->rendererQuery
= (__DRI2rendererQueryExtension
*) extensions
[i
];
811 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_query_renderer");
813 if (strcmp(extensions
[i
]->name
, __DRI2_FLUSH_CONTROL
) == 0) {
814 __glXEnableDirectExtension(&psc
->base
,
815 "GLX_ARB_context_flush_control");
821 check_xshm(Display
*dpy
)
825 return XQueryExtension(dpy
, "MIT-SHM", &xshm_opcode
, &ignore
, &ignore
);
828 static struct glx_screen
*
829 driswCreateScreen(int screen
, struct glx_display
*priv
)
832 const __DRIconfig
**driver_configs
;
833 const __DRIextension
**extensions
;
834 struct drisw_screen
*psc
;
835 struct glx_config
*configs
= NULL
, *visuals
= NULL
;
837 const __DRIextension
**loader_extensions_local
;
839 psc
= calloc(1, sizeof *psc
);
843 if (!glx_screen_init(&psc
->base
, screen
, priv
)) {
848 extensions
= driOpenDriver(SWRAST_DRIVER_NAME
, &psc
->driver
);
849 if (extensions
== NULL
)
852 if (!check_xshm(psc
->base
.dpy
))
853 loader_extensions_local
= loader_extensions_noshm
;
855 loader_extensions_local
= loader_extensions_shm
;
857 for (i
= 0; extensions
[i
]; i
++) {
858 if (strcmp(extensions
[i
]->name
, __DRI_CORE
) == 0)
859 psc
->core
= (__DRIcoreExtension
*) extensions
[i
];
860 if (strcmp(extensions
[i
]->name
, __DRI_SWRAST
) == 0)
861 psc
->swrast
= (__DRIswrastExtension
*) extensions
[i
];
862 if (strcmp(extensions
[i
]->name
, __DRI_COPY_SUB_BUFFER
) == 0)
863 psc
->copySubBuffer
= (__DRIcopySubBufferExtension
*) extensions
[i
];
866 if (psc
->core
== NULL
|| psc
->swrast
== NULL
) {
867 ErrorMessageF("core dri extension not found\n");
871 if (psc
->swrast
->base
.version
>= 4) {
873 psc
->swrast
->createNewScreen2(screen
, loader_extensions_local
,
875 &driver_configs
, psc
);
878 psc
->swrast
->createNewScreen(screen
, loader_extensions_local
,
879 &driver_configs
, psc
);
881 if (psc
->driScreen
== NULL
) {
882 ErrorMessageF("failed to create dri screen\n");
886 extensions
= psc
->core
->getExtensions(psc
->driScreen
);
887 driswBindExtensions(psc
, extensions
);
889 configs
= driConvertConfigs(psc
->core
, psc
->base
.configs
, driver_configs
);
890 visuals
= driConvertConfigs(psc
->core
, psc
->base
.visuals
, driver_configs
);
892 if (!configs
|| !visuals
) {
893 ErrorMessageF("No matching fbConfigs or visuals found\n");
897 glx_config_destroy_list(psc
->base
.configs
);
898 psc
->base
.configs
= configs
;
899 glx_config_destroy_list(psc
->base
.visuals
);
900 psc
->base
.visuals
= visuals
;
902 psc
->driver_configs
= driver_configs
;
904 psc
->base
.vtable
= &drisw_screen_vtable
;
906 psc
->base
.driScreen
= psp
;
907 psp
->destroyScreen
= driswDestroyScreen
;
908 psp
->createDrawable
= driswCreateDrawable
;
909 psp
->swapBuffers
= driswSwapBuffers
;
911 if (psc
->copySubBuffer
)
912 psp
->copySubBuffer
= driswCopySubBuffer
;
918 glx_config_destroy_list(configs
);
920 glx_config_destroy_list(visuals
);
922 psc
->core
->destroyScreen(psc
->driScreen
);
923 psc
->driScreen
= NULL
;
926 dlclose(psc
->driver
);
927 glx_screen_cleanup(&psc
->base
);
930 CriticalErrorMessageF("failed to load driver: %s\n", SWRAST_DRIVER_NAME
);
935 /* Called from __glXFreeDisplayPrivate.
938 driswDestroyDisplay(__GLXDRIdisplay
* dpy
)
944 * Allocate, initialize and return a __DRIdisplayPrivate object.
945 * This is called from __glXInitialize() when we are given a new
948 _X_HIDDEN __GLXDRIdisplay
*
949 driswCreateDisplay(Display
* dpy
)
951 struct drisw_display
*pdpyp
;
953 pdpyp
= malloc(sizeof *pdpyp
);
957 pdpyp
->base
.destroyDisplay
= driswDestroyDisplay
;
958 pdpyp
->base
.createScreen
= driswCreateScreen
;
963 #endif /* GLX_DIRECT_RENDERING */