1 /**************************************************************************
3 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sub license, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial portions
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
22 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Kevin E. Martin <kevin@precisioninsight.com>
31 * Brian Paul <brian@precisioninsight.com>
35 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
38 #include <X11/extensions/Xfixes.h>
39 #include <X11/extensions/Xdamage.h>
40 #include "glxclient.h"
45 #include <sys/types.h>
48 #include "dri_common.h"
55 ** XFree86-DRI version information
64 __GLXscreenConfigs base
;
66 __DRIscreen
*driScreen
;
67 __GLXDRIscreen vtable
;
68 const __DRIlegacyExtension
*legacy
;
69 const __DRIcoreExtension
*core
;
70 const __DRIswapControlExtension
*swapControl
;
71 const __DRImediaStreamCounterExtension
*msc
;
72 const __DRIconfig
**driver_configs
;
73 const __DRIcopySubBufferExtension
*driCopySubBuffer
;
82 __GLXDRIcontext dri_vtable
;
83 __DRIcontext
*driContext
;
85 __GLXscreenConfigs
*psc
;
90 __GLXDRIdrawable base
;
92 __DRIdrawable
*driDrawable
;
95 static const struct glx_context_vtable dri_context_vtable
;
98 * Given a display pointer and screen number, determine the name of
99 * the DRI driver for the screen. (I.e. "r128", "tdfx", etc).
100 * Return True for success, False for failure.
103 driGetDriverName(Display
* dpy
, int scrNum
, char **driverName
)
108 int driverMajor
, driverMinor
, driverPatch
;
112 if (XF86DRIQueryExtension(dpy
, &event
, &error
)) { /* DRI1 */
113 if (!XF86DRIQueryDirectRenderingCapable(dpy
, scrNum
, &directCapable
)) {
114 ErrorMessageF("XF86DRIQueryDirectRenderingCapable failed\n");
117 if (!directCapable
) {
118 ErrorMessageF("XF86DRIQueryDirectRenderingCapable returned false\n");
122 b
= XF86DRIGetClientDriverName(dpy
, scrNum
, &driverMajor
, &driverMinor
,
123 &driverPatch
, driverName
);
125 ErrorMessageF("Cannot determine driver name for screen %d\n",
130 InfoMessageF("XF86DRIGetClientDriverName: %d.%d.%d %s (screen %d)\n",
131 driverMajor
, driverMinor
, driverPatch
, *driverName
,
136 else if (DRI2QueryExtension(dpy
, &event
, &error
)) { /* DRI2 */
138 Bool ret
= DRI2Connect(dpy
, RootWindow(dpy
, scrNum
), driverName
, &dev
);
150 * Exported function for querying the DRI driver for a given screen.
152 * The returned char pointer points to a static array that will be
153 * overwritten by subsequent calls.
156 glXGetScreenDriver(Display
* dpy
, int scrNum
)
160 if (driGetDriverName(dpy
, scrNum
, &driverName
)) {
164 len
= strlen(driverName
);
167 memcpy(ret
, driverName
, len
+ 1);
175 * Exported function for obtaining a driver's option list (UTF-8 encoded XML).
177 * The returned char pointer points directly into the driver. Therefore
178 * it should be treated as a constant.
180 * If the driver was not found or does not support configuration NULL is
183 * Note: The driver remains opened after this function returns.
186 glXGetDriverConfig(const char *driverName
)
188 void *handle
= driOpenDriver(driverName
);
190 return dlsym(handle
, "__driConfigOptions");
195 #ifdef XDAMAGE_1_1_INTERFACE
198 has_damage_post(Display
* dpy
)
200 static GLboolean inited
= GL_FALSE
;
201 static GLboolean has_damage
;
206 if (XDamageQueryVersion(dpy
, &major
, &minor
) &&
207 major
== 1 && minor
>= 1) {
208 has_damage
= GL_TRUE
;
211 has_damage
= GL_FALSE
;
220 __glXReportDamage(__DRIdrawable
* driDraw
,
222 drm_clip_rect_t
* rects
, int num_rects
,
223 GLboolean front_buffer
, void *loaderPrivate
)
226 XserverRegion region
;
229 __GLXDRIdrawable
*glxDraw
= loaderPrivate
;
230 __GLXscreenConfigs
*psc
= glxDraw
->psc
;
231 Display
*dpy
= psc
->dpy
;
234 if (!has_damage_post(dpy
))
240 drawable
= RootWindow(dpy
, psc
->scr
);
245 drawable
= glxDraw
->xDrawable
;
248 xrects
= malloc(sizeof(XRectangle
) * num_rects
);
252 for (i
= 0; i
< num_rects
; i
++) {
253 xrects
[i
].x
= rects
[i
].x1
+ x_off
;
254 xrects
[i
].y
= rects
[i
].y1
+ y_off
;
255 xrects
[i
].width
= rects
[i
].x2
- rects
[i
].x1
;
256 xrects
[i
].height
= rects
[i
].y2
- rects
[i
].y1
;
258 region
= XFixesCreateRegion(dpy
, xrects
, num_rects
);
260 XDamageAdd(dpy
, drawable
, region
);
261 XFixesDestroyRegion(dpy
, region
);
264 static const __DRIdamageExtension damageExtension
= {
265 {__DRI_DAMAGE
, __DRI_DAMAGE_VERSION
},
272 __glXDRIGetDrawableInfo(__DRIdrawable
* drawable
,
273 unsigned int *index
, unsigned int *stamp
,
274 int *X
, int *Y
, int *W
, int *H
,
275 int *numClipRects
, drm_clip_rect_t
** pClipRects
,
276 int *backX
, int *backY
,
277 int *numBackClipRects
,
278 drm_clip_rect_t
** pBackClipRects
,
281 __GLXDRIdrawable
*glxDraw
= loaderPrivate
;
282 __GLXscreenConfigs
*psc
= glxDraw
->psc
;
283 Display
*dpy
= psc
->dpy
;
285 return XF86DRIGetDrawableInfo(dpy
, psc
->scr
, glxDraw
->drawable
,
286 index
, stamp
, X
, Y
, W
, H
,
287 numClipRects
, pClipRects
,
289 numBackClipRects
, pBackClipRects
);
292 static const __DRIgetDrawableInfoExtension getDrawableInfoExtension
= {
293 {__DRI_GET_DRAWABLE_INFO
, __DRI_GET_DRAWABLE_INFO_VERSION
},
294 __glXDRIGetDrawableInfo
297 static const __DRIextension
*loader_extensions
[] = {
298 &systemTimeExtension
.base
,
299 &getDrawableInfoExtension
.base
,
300 #ifdef XDAMAGE_1_1_INTERFACE
301 &damageExtension
.base
,
307 * Perform the required libGL-side initialization and call the client-side
308 * driver's \c __driCreateNewScreen function.
310 * \param dpy Display pointer.
311 * \param scrn Screen number on the display.
312 * \param psc DRI screen information.
313 * \param driDpy DRI display information.
314 * \param createNewScreen Pointer to the client-side driver's
315 * \c __driCreateNewScreen function.
316 * \returns A pointer to the \c __DRIscreen structure returned by
317 * the client-side driver on success, or \c NULL on failure.
320 CallCreateNewScreen(Display
*dpy
, int scrn
, struct dri_screen
*psc
,
321 struct dri_display
* driDpy
)
325 drmAddress pSAREA
= MAP_FAILED
;
327 __DRIversion ddx_version
;
328 __DRIversion dri_version
;
329 __DRIversion drm_version
;
330 __DRIframebuffer framebuffer
;
335 drmVersionPtr version
;
340 const __DRIconfig
**driver_configs
;
341 __GLcontextModes
*visual
;
343 /* DRI protocol version. */
344 dri_version
.major
= driDpy
->driMajor
;
345 dri_version
.minor
= driDpy
->driMinor
;
346 dri_version
.patch
= driDpy
->driPatch
;
348 framebuffer
.base
= MAP_FAILED
;
349 framebuffer
.dev_priv
= NULL
;
350 framebuffer
.size
= 0;
352 if (!XF86DRIOpenConnection(dpy
, scrn
, &hSAREA
, &BusID
)) {
353 ErrorMessageF("XF86DRIOpenConnection failed\n");
357 fd
= drmOpenOnce(NULL
, BusID
, &newlyopened
);
359 Xfree(BusID
); /* No longer needed */
362 ErrorMessageF("drmOpenOnce failed (%s)\n", strerror(-fd
));
366 if (drmGetMagic(fd
, &magic
)) {
367 ErrorMessageF("drmGetMagic failed\n");
371 version
= drmGetVersion(fd
);
373 drm_version
.major
= version
->version_major
;
374 drm_version
.minor
= version
->version_minor
;
375 drm_version
.patch
= version
->version_patchlevel
;
376 drmFreeVersion(version
);
379 drm_version
.major
= -1;
380 drm_version
.minor
= -1;
381 drm_version
.patch
= -1;
384 if (newlyopened
&& !XF86DRIAuthConnection(dpy
, scrn
, magic
)) {
385 ErrorMessageF("XF86DRIAuthConnection failed\n");
389 /* Get device name (like "tdfx") and the ddx version numbers.
390 * We'll check the version in each DRI driver's "createNewScreen"
392 if (!XF86DRIGetClientDriverName(dpy
, scrn
,
395 &ddx_version
.patch
, &driverName
)) {
396 ErrorMessageF("XF86DRIGetClientDriverName failed\n");
400 Xfree(driverName
); /* No longer needed. */
403 * Get device-specific info. pDevPriv will point to a struct
404 * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h) that
405 * has information about the screen size, depth, pitch, ancilliary
406 * buffers, DRM mmap handles, etc.
408 if (!XF86DRIGetDeviceInfo(dpy
, scrn
, &hFB
, &junk
,
409 &framebuffer
.size
, &framebuffer
.stride
,
410 &framebuffer
.dev_priv_size
,
411 &framebuffer
.dev_priv
)) {
412 ErrorMessageF("XF86DRIGetDeviceInfo failed");
416 framebuffer
.width
= DisplayWidth(dpy
, scrn
);
417 framebuffer
.height
= DisplayHeight(dpy
, scrn
);
419 /* Map the framebuffer region. */
420 status
= drmMap(fd
, hFB
, framebuffer
.size
,
421 (drmAddressPtr
) & framebuffer
.base
);
423 ErrorMessageF("drmMap of framebuffer failed (%s)", strerror(-status
));
427 /* Map the SAREA region. Further mmap regions may be setup in
428 * each DRI driver's "createNewScreen" function.
430 status
= drmMap(fd
, hSAREA
, SAREA_MAX
, &pSAREA
);
432 ErrorMessageF("drmMap of SAREA failed (%s)", strerror(-status
));
436 psp
= (*psc
->legacy
->createNewScreen
) (scrn
,
444 &driver_configs
, psc
);
447 ErrorMessageF("Calling driver entry point failed");
452 driConvertConfigs(psc
->core
, psc
->base
.configs
, driver_configs
);
454 driConvertConfigs(psc
->core
, psc
->base
.visuals
, driver_configs
);
456 psc
->driver_configs
= driver_configs
;
458 /* Visuals with depth != screen depth are subject to automatic compositing
459 * in the X server, so DRI1 can't render to them properly. Mark them as
460 * non-conformant to prevent apps from picking them up accidentally.
462 for (visual
= psc
->base
.visuals
; visual
; visual
= visual
->next
) {
463 XVisualInfo
template;
464 XVisualInfo
*visuals
;
468 template.visualid
= visual
->visualID
;
470 visuals
= XGetVisualInfo(dpy
, mask
, &template, &num_visuals
);
473 if (num_visuals
> 0 && visuals
->depth
!= DefaultDepth(dpy
, scrn
))
474 visual
->visualRating
= GLX_NON_CONFORMANT_CONFIG
;
483 if (pSAREA
!= MAP_FAILED
)
484 drmUnmap(pSAREA
, SAREA_MAX
);
486 if (framebuffer
.base
!= MAP_FAILED
)
487 drmUnmap((drmAddress
) framebuffer
.base
, framebuffer
.size
);
489 if (framebuffer
.dev_priv
!= NULL
)
490 Xfree(framebuffer
.dev_priv
);
495 XF86DRICloseConnection(dpy
, scrn
);
497 ErrorMessageF("reverting to software direct rendering\n");
503 dri_destroy_context(__GLXcontext
* context
)
505 struct dri_context
*pcp
= (struct dri_context
*) context
;
506 struct dri_screen
*psc
= (struct dri_screen
*) context
->psc
;
508 glx_send_destroy_context(psc
->base
.dpy
, context
->xid
);
510 if (context
->extensions
)
511 XFree((char *) context
->extensions
);
513 GarbageCollectDRIDrawables(context
->psc
);
515 (*psc
->core
->destroyContext
) (pcp
->driContext
);
517 XF86DRIDestroyContext(psc
->base
.dpy
, psc
->base
.scr
, pcp
->hwContextID
);
522 driBindContext(__GLXcontext
*context
,
523 __GLXDRIdrawable
*draw
, __GLXDRIdrawable
*read
)
525 struct dri_context
*pcp
= (struct dri_context
*) context
;
526 struct dri_screen
*psc
= (struct dri_screen
*) pcp
->psc
;
527 struct dri_drawable
*pdr
= (struct dri_drawable
*) draw
;
528 struct dri_drawable
*prd
= (struct dri_drawable
*) read
;
530 return (*psc
->core
->bindContext
) (pcp
->driContext
,
531 pdr
->driDrawable
, prd
->driDrawable
);
535 driUnbindContext(__GLXcontext
* context
)
537 struct dri_context
*pcp
= (struct dri_context
*) context
;
538 struct dri_screen
*psc
= (struct dri_screen
*) pcp
->psc
;
540 (*psc
->core
->unbindContext
) (pcp
->driContext
);
543 static const struct glx_context_vtable dri_context_vtable
= {
552 static __GLXcontext
*
553 driCreateContext(__GLXscreenConfigs
*base
,
554 const __GLcontextModes
* mode
,
555 GLXContext shareList
, int renderType
)
557 struct dri_context
*pcp
, *pcp_shared
;
558 struct dri_screen
*psc
= (struct dri_screen
*) base
;
559 drm_context_t hwContext
;
560 __DRIcontext
*shared
= NULL
;
561 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) mode
;
563 if (!psc
->base
.driScreen
)
567 pcp_shared
= (struct dri_context
*) shareList
->driContext
;
568 shared
= pcp_shared
->driContext
;
571 pcp
= Xmalloc(sizeof *pcp
);
575 memset(pcp
, 0, sizeof *pcp
);
576 if (!glx_context_init(&pcp
->base
, &psc
->base
, mode
)) {
581 if (!XF86DRICreateContextWithConfig(psc
->base
.dpy
, psc
->base
.scr
,
583 &pcp
->hwContextID
, &hwContext
)) {
589 (*psc
->legacy
->createNewContext
) (psc
->driScreen
,
591 renderType
, shared
, hwContext
, pcp
);
592 if (pcp
->driContext
== NULL
) {
593 XF86DRIDestroyContext(psc
->base
.dpy
, psc
->base
.scr
, pcp
->hwContextID
);
598 pcp
->base
.vtable
= &dri_context_vtable
;
599 pcp
->base
.driContext
= &pcp
->dri_vtable
;
600 pcp
->dri_vtable
.bindContext
= driBindContext
;
601 pcp
->dri_vtable
.unbindContext
= driUnbindContext
;
607 driDestroyDrawable(__GLXDRIdrawable
* pdraw
)
609 struct dri_screen
*psc
= (struct dri_screen
*) pdraw
->psc
;
610 struct dri_drawable
*pdp
= (struct dri_drawable
*) pdraw
;
612 (*psc
->core
->destroyDrawable
) (pdp
->driDrawable
);
613 XF86DRIDestroyDrawable(psc
->base
.dpy
, psc
->base
.scr
, pdraw
->drawable
);
617 static __GLXDRIdrawable
*
618 driCreateDrawable(__GLXscreenConfigs
*base
,
620 GLXDrawable drawable
, const __GLcontextModes
* modes
)
622 drm_drawable_t hwDrawable
;
623 void *empty_attribute_list
= NULL
;
624 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) modes
;
625 struct dri_screen
*psc
= (struct dri_screen
*) base
;
626 struct dri_drawable
*pdp
;
628 /* Old dri can't handle GLX 1.3+ drawable constructors. */
629 if (xDrawable
!= drawable
)
632 pdp
= Xmalloc(sizeof *pdp
);
636 pdp
->base
.drawable
= drawable
;
637 pdp
->base
.psc
= &psc
->base
;
639 if (!XF86DRICreateDrawable(psc
->base
.dpy
, psc
->base
.scr
,
640 drawable
, &hwDrawable
)) {
645 /* Create a new drawable */
647 (*psc
->legacy
->createNewDrawable
) (psc
->driScreen
,
651 empty_attribute_list
, pdp
);
653 if (!pdp
->driDrawable
) {
654 XF86DRIDestroyDrawable(psc
->base
.dpy
, psc
->base
.scr
, drawable
);
659 pdp
->base
.destroyDrawable
= driDestroyDrawable
;
665 driSwapBuffers(__GLXDRIdrawable
* pdraw
, int64_t unused1
, int64_t unused2
,
668 struct dri_screen
*psc
= (struct dri_screen
*) pdraw
->psc
;
669 struct dri_drawable
*pdp
= (struct dri_drawable
*) pdraw
;
671 (*psc
->core
->swapBuffers
) (pdp
->driDrawable
);
676 driCopySubBuffer(__GLXDRIdrawable
* pdraw
,
677 int x
, int y
, int width
, int height
)
679 struct dri_drawable
*pdp
= (struct dri_drawable
*) pdraw
;
680 struct dri_screen
*psc
= (struct dri_screen
*) pdp
->base
.psc
;
682 (*psc
->driCopySubBuffer
->copySubBuffer
) (pdp
->driDrawable
,
683 x
, y
, width
, height
);
687 driDestroyScreen(__GLXscreenConfigs
*base
)
689 struct dri_screen
*psc
= (struct dri_screen
*) base
;
691 /* Free the direct rendering per screen data */
693 (*psc
->core
->destroyScreen
) (psc
->driScreen
);
694 driDestroyConfigs(psc
->driver_configs
);
695 psc
->driScreen
= NULL
;
697 dlclose(psc
->driver
);
700 #ifdef __DRI_SWAP_BUFFER_COUNTER
703 driDrawableGetMSC(__GLXscreenConfigs
*base
, __GLXDRIdrawable
*pdraw
,
704 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
706 struct dri_screen
*psc
= (struct dri_screen
*) base
;
707 struct dri_drawable
*pdp
= (struct dri_drawable
*) pdraw
;
709 if (pdp
&& psc
->sbc
&& psc
->msc
)
710 return ( (*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0 &&
711 (*psc
->sbc
->getSBC
)(pdp
->driDrawable
, sbc
) == 0 &&
712 __glXGetUST(ust
) == 0 );
716 driWaitForMSC(__GLXDRIdrawable
*pdraw
, int64_t target_msc
, int64_t divisor
,
717 int64_t remainder
, int64_t *ust
, int64_t *msc
, int64_t *sbc
)
719 struct dri_screen
*psc
= (struct dri_screen
*) pdraw
->psc
;
720 struct dri_drawable
*pdp
= (struct dri_drawable
*) pdraw
;
722 if (pdp
!= NULL
&& psc
->msc
!= NULL
) {
723 ret
= (*psc
->msc
->waitForMSC
) (pdp
->driDrawable
, target_msc
,
724 divisor
, remainder
, msc
, sbc
);
726 /* __glXGetUST returns zero on success and non-zero on failure.
727 * This function returns True on success and False on failure.
729 return ret
== 0 && __glXGetUST(ust
) == 0;
734 driWaitForSBC(__GLXDRIdrawable
*pdraw
, int64_t target_sbc
, int64_t *ust
,
735 int64_t *msc
, int64_t *sbc
)
737 struct dri_drawable
*pdp
= (struct dri_drawable
*) pdraw
;
739 if (pdp
!= NULL
&& psc
->sbc
!= NULL
) {
741 (*psc
->sbc
->waitForSBC
) (pdp
->driDrawable
, target_sbc
, msc
, sbc
);
743 /* __glXGetUST returns zero on success and non-zero on failure.
744 * This function returns True on success and False on failure.
746 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
749 return DRI2WaitSBC(pdp
->base
.psc
->dpy
,
750 pdp
->base
.xDrawable
, target_sbc
, ust
, msc
, sbc
);
756 driSetSwapInterval(__GLXDRIdrawable
*pdraw
, int interval
)
758 GLXContext gc
= __glXGetCurrentContext();
759 struct dri_drawable
*pdp
= (struct dri_drawable
*) pdraw
;
760 struct dri_screen
*psc
;
762 if (gc
->driContext
) {
763 psc
= (struct dri_screen
*) pdraw
->psc
;
765 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
766 psc
->swapControl
->setSwapInterval(pdp
->driDrawable
, interval
);
771 return GLX_BAD_CONTEXT
;
775 driGetSwapInterval(__GLXDRIdrawable
*pdraw
)
777 GLXContext gc
= __glXGetCurrentContext();
778 struct dri_drawable
*pdp
= (struct dri_drawable
*) pdraw
;
779 struct dri_screen
*psc
;
781 if (gc
!= NULL
&& gc
->driContext
) {
782 psc
= (struct dri_screen
*) pdraw
->psc
;
784 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
785 return psc
->swapControl
->getSwapInterval(pdp
->driDrawable
);
792 /* Bind DRI1 specific extensions */
794 driBindExtensions(struct dri_screen
*psc
, const __DRIextension
**extensions
)
798 for (i
= 0; extensions
[i
]; i
++) {
799 /* No DRI2 support for swap_control at the moment, since SwapBuffers
800 * is done by the X server */
801 if (strcmp(extensions
[i
]->name
, __DRI_SWAP_CONTROL
) == 0) {
802 psc
->swapControl
= (__DRIswapControlExtension
*) extensions
[i
];
803 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_swap_control");
804 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_swap_control");
807 if (strcmp(extensions
[i
]->name
, __DRI_MEDIA_STREAM_COUNTER
) == 0) {
808 psc
->msc
= (__DRImediaStreamCounterExtension
*) extensions
[i
];
809 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_video_sync");
812 if (strcmp(extensions
[i
]->name
, __DRI_COPY_SUB_BUFFER
) == 0) {
813 psc
->driCopySubBuffer
= (__DRIcopySubBufferExtension
*) extensions
[i
];
814 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
817 if (strcmp(extensions
[i
]->name
, __DRI_READ_DRAWABLE
) == 0) {
818 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_make_current_read");
820 /* Ignore unknown extensions */
824 static __GLXscreenConfigs
*
825 driCreateScreen(int screen
, __GLXdisplayPrivate
*priv
)
827 struct dri_display
*pdp
;
829 const __DRIextension
**extensions
;
830 struct dri_screen
*psc
;
834 psc
= Xcalloc(1, sizeof *psc
);
838 memset(psc
, 0, sizeof *psc
);
839 if (!glx_screen_init(&psc
->base
, screen
, priv
))
842 if (!driGetDriverName(priv
->dpy
, screen
, &driverName
)) {
847 psc
->driver
= driOpenDriver(driverName
);
849 if (psc
->driver
== NULL
) {
854 extensions
= dlsym(psc
->driver
, __DRI_DRIVER_EXTENSIONS
);
855 if (extensions
== NULL
) {
856 ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
861 for (i
= 0; extensions
[i
]; i
++) {
862 if (strcmp(extensions
[i
]->name
, __DRI_CORE
) == 0)
863 psc
->core
= (__DRIcoreExtension
*) extensions
[i
];
864 if (strcmp(extensions
[i
]->name
, __DRI_LEGACY
) == 0)
865 psc
->legacy
= (__DRIlegacyExtension
*) extensions
[i
];
868 if (psc
->core
== NULL
|| psc
->legacy
== NULL
) {
873 pdp
= (struct dri_display
*) priv
->driDisplay
;
875 CallCreateNewScreen(psc
->base
.dpy
, screen
, psc
, pdp
);
876 if (psc
->driScreen
== NULL
) {
877 dlclose(psc
->driver
);
882 extensions
= psc
->core
->getExtensions(psc
->driScreen
);
883 driBindExtensions(psc
, extensions
);
886 psc
->base
.driScreen
= psp
;
887 if (psc
->driCopySubBuffer
)
888 psp
->copySubBuffer
= driCopySubBuffer
;
890 psp
->destroyScreen
= driDestroyScreen
;
891 psp
->createContext
= driCreateContext
;
892 psp
->createDrawable
= driCreateDrawable
;
893 psp
->swapBuffers
= driSwapBuffers
;
895 #ifdef __DRI_SWAP_BUFFER_COUNTER
896 psp
->getDrawableMSC
= driDrawableGetMSC
;
897 psp
->waitForMSC
= driWaitForMSC
;
898 psp
->waitForSBC
= driWaitForSBC
;
901 psp
->setSwapInterval
= driSetSwapInterval
;
902 psp
->getSwapInterval
= driGetSwapInterval
;
907 /* Called from __glXFreeDisplayPrivate.
910 driDestroyDisplay(__GLXDRIdisplay
* dpy
)
916 * Allocate, initialize and return a __DRIdisplayPrivate object.
917 * This is called from __glXInitialize() when we are given a new
920 _X_HIDDEN __GLXDRIdisplay
*
921 driCreateDisplay(Display
* dpy
)
923 struct dri_display
*pdpyp
;
924 int eventBase
, errorBase
;
925 int major
, minor
, patch
;
927 if (!XF86DRIQueryExtension(dpy
, &eventBase
, &errorBase
)) {
931 if (!XF86DRIQueryVersion(dpy
, &major
, &minor
, &patch
)) {
935 pdpyp
= Xmalloc(sizeof *pdpyp
);
940 pdpyp
->driMajor
= major
;
941 pdpyp
->driMinor
= minor
;
942 pdpyp
->driPatch
= patch
;
944 pdpyp
->base
.destroyDisplay
= driDestroyDisplay
;
945 pdpyp
->base
.createScreen
= driCreateScreen
;
950 #endif /* GLX_DIRECT_RENDERING */