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 x
, int y
, int w
, int h
, int stride
,
205 int shmid
, char *data
, void *loaderPrivate
)
207 struct drisw_drawable
*pdp
= loaderPrivate
;
208 __GLXDRIdrawable
*pdraw
= &(pdp
->base
);
209 Display
*dpy
= pdraw
->psc
->dpy
;
214 if (!pdp
->ximage
|| shmid
!= pdp
->shminfo
.shmid
) {
215 if (!XCreateDrawable(pdp
, shmid
, dpy
))
220 case __DRI_SWRAST_IMAGE_OP_DRAW
:
223 case __DRI_SWRAST_IMAGE_OP_SWAP
:
230 drawable
= pdraw
->xDrawable
;
231 ximage
= pdp
->ximage
;
232 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
235 if (pdp
->shminfo
.shmid
>= 0) {
236 ximage
->width
= ximage
->bytes_per_line
/ ((ximage
->bits_per_pixel
+ 7)/ 8);
238 XShmPutImage(dpy
, drawable
, gc
, ximage
, 0, 0, x
, y
, w
, h
, False
);
243 XPutImage(dpy
, drawable
, gc
, ximage
, 0, 0, x
, y
, w
, h
);
249 swrastPutImageShm(__DRIdrawable
* draw
, int op
,
250 int x
, int y
, int w
, int h
, int stride
,
251 int shmid
, char *shmaddr
, unsigned offset
,
254 struct drisw_drawable
*pdp
= loaderPrivate
;
256 pdp
->shminfo
.shmaddr
= shmaddr
;
257 swrastXPutImage(draw
, op
, x
, y
, w
, h
, stride
, shmid
,
258 shmaddr
+ offset
, loaderPrivate
);
262 swrastPutImage2(__DRIdrawable
* draw
, int op
,
263 int x
, int y
, int w
, int h
, int stride
,
264 char *data
, void *loaderPrivate
)
266 swrastXPutImage(draw
, op
, x
, y
, w
, h
, stride
, -1,
267 data
, loaderPrivate
);
271 swrastPutImage(__DRIdrawable
* draw
, int op
,
272 int x
, int y
, int w
, int h
,
273 char *data
, void *loaderPrivate
)
275 swrastXPutImage(draw
, op
, x
, y
, w
, h
, 0, -1,
276 data
, loaderPrivate
);
280 swrastGetImage2(__DRIdrawable
* read
,
281 int x
, int y
, int w
, int h
, int stride
,
282 char *data
, void *loaderPrivate
)
284 struct drisw_drawable
*prp
= loaderPrivate
;
285 __GLXDRIdrawable
*pread
= &(prp
->base
);
286 Display
*dpy
= pread
->psc
->dpy
;
290 if (!prp
->ximage
|| prp
->shminfo
.shmid
>= 0) {
291 if (!XCreateDrawable(prp
, -1, dpy
))
295 readable
= pread
->xDrawable
;
297 ximage
= prp
->ximage
;
301 ximage
->bytes_per_line
= stride
? stride
: bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
303 XGetSubImage(dpy
, readable
, x
, y
, w
, h
, ~0L, ZPixmap
, ximage
, 0, 0);
309 swrastGetImage(__DRIdrawable
* read
,
310 int x
, int y
, int w
, int h
,
311 char *data
, void *loaderPrivate
)
313 swrastGetImage2(read
, x
, y
, w
, h
, 0, data
, loaderPrivate
);
317 swrastGetImageShm(__DRIdrawable
* read
,
318 int x
, int y
, int w
, int h
,
319 int shmid
, void *loaderPrivate
)
321 struct drisw_drawable
*prp
= loaderPrivate
;
322 __GLXDRIdrawable
*pread
= &(prp
->base
);
323 Display
*dpy
= pread
->psc
->dpy
;
327 if (!prp
->ximage
|| shmid
!= prp
->shminfo
.shmid
) {
328 if (!XCreateDrawable(prp
, shmid
, dpy
))
331 readable
= pread
->xDrawable
;
333 ximage
= prp
->ximage
;
334 ximage
->data
= prp
->shminfo
.shmaddr
; /* no offset */
337 ximage
->bytes_per_line
= bytes_per_line(w
* ximage
->bits_per_pixel
, 32);
339 XShmGetImage(dpy
, readable
, ximage
, x
, y
, ~0L);
342 static const __DRIswrastLoaderExtension swrastLoaderExtension_shm
= {
343 .base
= {__DRI_SWRAST_LOADER
, 4 },
345 .getDrawableInfo
= swrastGetDrawableInfo
,
346 .putImage
= swrastPutImage
,
347 .getImage
= swrastGetImage
,
348 .putImage2
= swrastPutImage2
,
349 .getImage2
= swrastGetImage2
,
350 .putImageShm
= swrastPutImageShm
,
351 .getImageShm
= swrastGetImageShm
,
354 static const __DRIextension
*loader_extensions_shm
[] = {
355 &swrastLoaderExtension_shm
.base
,
359 static const __DRIswrastLoaderExtension swrastLoaderExtension
= {
360 .base
= {__DRI_SWRAST_LOADER
, 3 },
362 .getDrawableInfo
= swrastGetDrawableInfo
,
363 .putImage
= swrastPutImage
,
364 .getImage
= swrastGetImage
,
365 .putImage2
= swrastPutImage2
,
366 .getImage2
= swrastGetImage2
,
369 static const __DRIextension
*loader_extensions_noshm
[] = {
370 &swrastLoaderExtension
.base
,
379 drisw_destroy_context(struct glx_context
*context
)
381 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
382 struct drisw_screen
*psc
= (struct drisw_screen
*) context
->psc
;
384 driReleaseDrawables(&pcp
->base
);
386 free((char *) context
->extensions
);
388 (*psc
->core
->destroyContext
) (pcp
->driContext
);
394 drisw_bind_context(struct glx_context
*context
, struct glx_context
*old
,
395 GLXDrawable draw
, GLXDrawable read
)
397 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
398 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
399 struct drisw_drawable
*pdraw
, *pread
;
401 pdraw
= (struct drisw_drawable
*) driFetchDrawable(context
, draw
);
402 pread
= (struct drisw_drawable
*) driFetchDrawable(context
, read
);
404 driReleaseDrawables(&pcp
->base
);
406 if ((*psc
->core
->bindContext
) (pcp
->driContext
,
407 pdraw
? pdraw
->driDrawable
: NULL
,
408 pread
? pread
->driDrawable
: NULL
))
411 return GLXBadContext
;
415 drisw_unbind_context(struct glx_context
*context
, struct glx_context
*new)
417 struct drisw_context
*pcp
= (struct drisw_context
*) context
;
418 struct drisw_screen
*psc
= (struct drisw_screen
*) pcp
->base
.psc
;
420 (*psc
->core
->unbindContext
) (pcp
->driContext
);
424 drisw_bind_tex_image(Display
* dpy
,
425 GLXDrawable drawable
,
426 int buffer
, const int *attrib_list
)
428 struct glx_context
*gc
= __glXGetCurrentContext();
429 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
430 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
431 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
432 struct drisw_screen
*psc
;
434 __glXInitialize(dpy
);
437 psc
= (struct drisw_screen
*) base
->psc
;
442 if (psc
->texBuffer
->base
.version
>= 2 &&
443 psc
->texBuffer
->setTexBuffer2
!= NULL
) {
444 (*psc
->texBuffer
->setTexBuffer2
) (pcp
->driContext
,
445 pdraw
->base
.textureTarget
,
446 pdraw
->base
.textureFormat
,
450 (*psc
->texBuffer
->setTexBuffer
) (pcp
->driContext
,
451 pdraw
->base
.textureTarget
,
458 drisw_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
460 struct glx_context
*gc
= __glXGetCurrentContext();
461 struct drisw_context
*pcp
= (struct drisw_context
*) gc
;
462 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
463 struct glx_display
*dpyPriv
= __glXInitialize(dpy
);
464 struct drisw_drawable
*pdraw
= (struct drisw_drawable
*) base
;
465 struct drisw_screen
*psc
;
467 if (dpyPriv
!= NULL
&& pdraw
!= NULL
) {
468 psc
= (struct drisw_screen
*) base
->psc
;
473 if (psc
->texBuffer
->base
.version
>= 3 &&
474 psc
->texBuffer
->releaseTexBuffer
!= NULL
) {
475 (*psc
->texBuffer
->releaseTexBuffer
) (pcp
->driContext
,
476 pdraw
->base
.textureTarget
,
482 static const struct glx_context_vtable drisw_context_vtable
= {
483 .destroy
= drisw_destroy_context
,
484 .bind
= drisw_bind_context
,
485 .unbind
= drisw_unbind_context
,
488 .use_x_font
= DRI_glXUseXFont
,
489 .bind_tex_image
= drisw_bind_tex_image
,
490 .release_tex_image
= drisw_release_tex_image
,
491 .get_proc_address
= NULL
,
494 static struct glx_context
*
495 drisw_create_context(struct glx_screen
*base
,
496 struct glx_config
*config_base
,
497 struct glx_context
*shareList
, int renderType
)
499 struct drisw_context
*pcp
, *pcp_shared
;
500 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
501 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
502 __DRIcontext
*shared
= NULL
;
504 if (!psc
->base
.driScreen
)
507 /* Check the renderType value */
508 if (!validate_renderType_against_config(config_base
, renderType
))
512 /* If the shareList context is not a DRISW context, we cannot possibly
513 * create a DRISW context that shares it.
515 if (shareList
->vtable
->destroy
!= drisw_destroy_context
) {
519 pcp_shared
= (struct drisw_context
*) shareList
;
520 shared
= pcp_shared
->driContext
;
523 pcp
= calloc(1, sizeof *pcp
);
527 if (!glx_context_init(&pcp
->base
, &psc
->base
, &config
->base
)) {
532 pcp
->base
.renderType
= renderType
;
535 (*psc
->core
->createNewContext
) (psc
->driScreen
,
536 config
->driConfig
, shared
, pcp
);
537 if (pcp
->driContext
== NULL
) {
542 pcp
->base
.vtable
= &drisw_context_vtable
;
547 static struct glx_context
*
548 drisw_create_context_attribs(struct glx_screen
*base
,
549 struct glx_config
*config_base
,
550 struct glx_context
*shareList
,
551 unsigned num_attribs
,
552 const uint32_t *attribs
,
555 struct drisw_context
*pcp
, *pcp_shared
;
556 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
557 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
558 __DRIcontext
*shared
= NULL
;
567 uint32_t ctx_attribs
[2 * 5];
568 unsigned num_ctx_attribs
= 0;
570 if (!psc
->base
.driScreen
)
573 if (psc
->swrast
->base
.version
< 3)
576 /* Remap the GLX tokens to DRI2 tokens.
578 if (!dri2_convert_glx_attribs(num_attribs
, attribs
,
579 &major_ver
, &minor_ver
, &renderType
, &flags
,
580 &api
, &reset
, &release
, 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
;
627 pcp
->base
.renderType
= renderType
;
630 (*psc
->swrast
->createContextAttribs
) (psc
->driScreen
,
632 config
? config
->driConfig
: 0,
638 if (pcp
->driContext
== NULL
) {
643 pcp
->base
.vtable
= &drisw_context_vtable
;
649 driswDestroyDrawable(__GLXDRIdrawable
* pdraw
)
651 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
652 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
654 (*psc
->core
->destroyDrawable
) (pdp
->driDrawable
);
656 XDestroyDrawable(pdp
, pdraw
->psc
->dpy
, pdraw
->drawable
);
660 static __GLXDRIdrawable
*
661 driswCreateDrawable(struct glx_screen
*base
, XID xDrawable
,
662 GLXDrawable drawable
, struct glx_config
*modes
)
664 struct drisw_drawable
*pdp
;
665 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) modes
;
666 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
668 const __DRIswrastExtension
*swrast
= psc
->swrast
;
670 pdp
= calloc(1, sizeof(*pdp
));
674 pdp
->base
.xDrawable
= xDrawable
;
675 pdp
->base
.drawable
= drawable
;
676 pdp
->base
.psc
= &psc
->base
;
678 ret
= XCreateGCs(pdp
, psc
->base
.dpy
, xDrawable
, modes
->visualID
);
684 /* Create a new drawable */
686 (*swrast
->createNewDrawable
) (psc
->driScreen
, config
->driConfig
, pdp
);
688 if (!pdp
->driDrawable
) {
689 XDestroyDrawable(pdp
, psc
->base
.dpy
, xDrawable
);
694 pdp
->base
.destroyDrawable
= driswDestroyDrawable
;
700 driswSwapBuffers(__GLXDRIdrawable
* pdraw
,
701 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
704 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
705 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
715 (*psc
->core
->swapBuffers
) (pdp
->driDrawable
);
721 driswCopySubBuffer(__GLXDRIdrawable
* pdraw
,
722 int x
, int y
, int width
, int height
, Bool flush
)
724 struct drisw_drawable
*pdp
= (struct drisw_drawable
*) pdraw
;
725 struct drisw_screen
*psc
= (struct drisw_screen
*) pdp
->base
.psc
;
731 (*psc
->copySubBuffer
->copySubBuffer
) (pdp
->driDrawable
,
732 x
, y
, width
, height
);
736 driswDestroyScreen(struct glx_screen
*base
)
738 struct drisw_screen
*psc
= (struct drisw_screen
*) base
;
740 /* Free the direct rendering per screen data */
741 (*psc
->core
->destroyScreen
) (psc
->driScreen
);
742 driDestroyConfigs(psc
->driver_configs
);
743 psc
->driScreen
= NULL
;
745 dlclose(psc
->driver
);
749 #define SWRAST_DRIVER_NAME "swrast"
757 driver
= driOpenDriver(SWRAST_DRIVER_NAME
);
762 static const struct glx_screen_vtable drisw_screen_vtable
= {
763 .create_context
= drisw_create_context
,
764 .create_context_attribs
= drisw_create_context_attribs
,
765 .query_renderer_integer
= drisw_query_renderer_integer
,
766 .query_renderer_string
= drisw_query_renderer_string
,
770 driswBindExtensions(struct drisw_screen
*psc
, const __DRIextension
**extensions
)
774 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_make_current_read");
776 if (psc
->swrast
->base
.version
>= 3) {
777 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context");
778 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context_profile");
780 /* DRISW version >= 2 implies support for OpenGL ES.
782 __glXEnableDirectExtension(&psc
->base
,
783 "GLX_EXT_create_context_es_profile");
784 __glXEnableDirectExtension(&psc
->base
,
785 "GLX_EXT_create_context_es2_profile");
788 if (psc
->copySubBuffer
)
789 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
791 /* FIXME: Figure out what other extensions can be ported here from dri2. */
792 for (i
= 0; extensions
[i
]; i
++) {
793 if ((strcmp(extensions
[i
]->name
, __DRI_TEX_BUFFER
) == 0)) {
794 psc
->texBuffer
= (__DRItexBufferExtension
*) extensions
[i
];
795 __glXEnableDirectExtension(&psc
->base
, "GLX_EXT_texture_from_pixmap");
797 /* DRISW version 3 is also required because GLX_MESA_query_renderer
798 * requires GLX_ARB_create_context_profile.
800 if (psc
->swrast
->base
.version
>= 3
801 && strcmp(extensions
[i
]->name
, __DRI2_RENDERER_QUERY
) == 0) {
802 psc
->rendererQuery
= (__DRI2rendererQueryExtension
*) extensions
[i
];
803 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_query_renderer");
805 if (strcmp(extensions
[i
]->name
, __DRI2_FLUSH_CONTROL
) == 0) {
806 __glXEnableDirectExtension(&psc
->base
,
807 "GLX_ARB_context_flush_control");
813 check_xshm(Display
*dpy
)
817 return XQueryExtension(dpy
, "MIT-SHM", &xshm_opcode
, &ignore
, &ignore
);
820 static struct glx_screen
*
821 driswCreateScreen(int screen
, struct glx_display
*priv
)
824 const __DRIconfig
**driver_configs
;
825 const __DRIextension
**extensions
;
826 struct drisw_screen
*psc
;
827 struct glx_config
*configs
= NULL
, *visuals
= NULL
;
829 const __DRIextension
**loader_extensions_local
;
831 psc
= calloc(1, sizeof *psc
);
835 if (!glx_screen_init(&psc
->base
, screen
, priv
)) {
840 psc
->driver
= driOpenSwrast();
841 if (psc
->driver
== NULL
)
844 extensions
= driGetDriverExtensions(psc
->driver
, SWRAST_DRIVER_NAME
);
845 if (extensions
== NULL
)
848 if (!check_xshm(psc
->base
.dpy
))
849 loader_extensions_local
= loader_extensions_noshm
;
851 loader_extensions_local
= loader_extensions_shm
;
853 for (i
= 0; extensions
[i
]; i
++) {
854 if (strcmp(extensions
[i
]->name
, __DRI_CORE
) == 0)
855 psc
->core
= (__DRIcoreExtension
*) extensions
[i
];
856 if (strcmp(extensions
[i
]->name
, __DRI_SWRAST
) == 0)
857 psc
->swrast
= (__DRIswrastExtension
*) extensions
[i
];
858 if (strcmp(extensions
[i
]->name
, __DRI_COPY_SUB_BUFFER
) == 0)
859 psc
->copySubBuffer
= (__DRIcopySubBufferExtension
*) extensions
[i
];
862 if (psc
->core
== NULL
|| psc
->swrast
== NULL
) {
863 ErrorMessageF("core dri extension not found\n");
867 if (psc
->swrast
->base
.version
>= 4) {
869 psc
->swrast
->createNewScreen2(screen
, loader_extensions_local
,
871 &driver_configs
, psc
);
874 psc
->swrast
->createNewScreen(screen
, loader_extensions_local
,
875 &driver_configs
, psc
);
877 if (psc
->driScreen
== NULL
) {
878 ErrorMessageF("failed to create dri screen\n");
882 extensions
= psc
->core
->getExtensions(psc
->driScreen
);
883 driswBindExtensions(psc
, extensions
);
885 configs
= driConvertConfigs(psc
->core
, psc
->base
.configs
, driver_configs
);
886 visuals
= driConvertConfigs(psc
->core
, psc
->base
.visuals
, driver_configs
);
888 if (!configs
|| !visuals
) {
889 ErrorMessageF("No matching fbConfigs or visuals found\n");
893 glx_config_destroy_list(psc
->base
.configs
);
894 psc
->base
.configs
= configs
;
895 glx_config_destroy_list(psc
->base
.visuals
);
896 psc
->base
.visuals
= visuals
;
898 psc
->driver_configs
= driver_configs
;
900 psc
->base
.vtable
= &drisw_screen_vtable
;
902 psc
->base
.driScreen
= psp
;
903 psp
->destroyScreen
= driswDestroyScreen
;
904 psp
->createDrawable
= driswCreateDrawable
;
905 psp
->swapBuffers
= driswSwapBuffers
;
907 if (psc
->copySubBuffer
)
908 psp
->copySubBuffer
= driswCopySubBuffer
;
914 glx_config_destroy_list(configs
);
916 glx_config_destroy_list(visuals
);
918 psc
->core
->destroyScreen(psc
->driScreen
);
919 psc
->driScreen
= NULL
;
922 dlclose(psc
->driver
);
923 glx_screen_cleanup(&psc
->base
);
926 CriticalErrorMessageF("failed to load driver: %s\n", SWRAST_DRIVER_NAME
);
931 /* Called from __glXFreeDisplayPrivate.
934 driswDestroyDisplay(__GLXDRIdisplay
* dpy
)
940 * Allocate, initialize and return a __DRIdisplayPrivate object.
941 * This is called from __glXInitialize() when we are given a new
944 _X_HIDDEN __GLXDRIdisplay
*
945 driswCreateDisplay(Display
* dpy
)
947 struct drisw_display
*pdpyp
;
949 pdpyp
= malloc(sizeof *pdpyp
);
953 pdpyp
->base
.destroyDisplay
= driswDestroyDisplay
;
954 pdpyp
->base
.createScreen
= driswCreateScreen
;
959 #endif /* GLX_DIRECT_RENDERING */