3 * DRI utility functions.
5 * This module acts as glue between GLX and the actual hardware driver. A DRI
6 * driver doesn't really \e have to use any of this - it's optional. But, some
7 * useful stuff is done here that otherwise would have to be duplicated in most
10 * Basically, these utility functions take care of some of the dirty details of
11 * screen initialization, context creation, context binding, DRM setup, etc.
13 * These functions are compiled into each DRI driver so libGL.so knows nothing
25 #define MAP_FAILED ((void *)-1)
28 #include "main/imports.h"
32 #include "drm_sarea.h"
36 PUBLIC
const char __dri2ConfigOptions
[] =
38 DRI_CONF_SECTION_PERFORMANCE
39 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_1
)
43 static const uint __dri2NConfigOptions
= 1;
45 #ifndef GLX_OML_sync_control
46 typedef GLboolean ( * PFNGLXGETMSCRATEOMLPROC
) (__DRIdrawable
*drawable
, int32_t *numerator
, int32_t *denominator
);
49 static void dri_get_drawable(__DRIdrawable
*pdp
);
50 static void dri_put_drawable(__DRIdrawable
*pdp
);
53 * This is just a token extension used to signal that the driver
54 * supports setting a read drawable.
56 const __DRIextension driReadDrawableExtension
= {
57 __DRI_READ_DRAWABLE
, __DRI_READ_DRAWABLE_VERSION
61 driIntersectArea( drm_clip_rect_t rect1
, drm_clip_rect_t rect2
)
63 if (rect2
.x1
> rect1
.x1
) rect1
.x1
= rect2
.x1
;
64 if (rect2
.x2
< rect1
.x2
) rect1
.x2
= rect2
.x2
;
65 if (rect2
.y1
> rect1
.y1
) rect1
.y1
= rect2
.y1
;
66 if (rect2
.y2
< rect1
.y2
) rect1
.y2
= rect2
.y2
;
68 if (rect1
.x1
> rect1
.x2
|| rect1
.y1
> rect1
.y2
) return 0;
70 return (rect1
.x2
- rect1
.x1
) * (rect1
.y2
- rect1
.y1
);
73 /*****************************************************************/
74 /** \name Context (un)binding functions */
75 /*****************************************************************/
81 * \param scrn the screen.
84 * \return \c GL_TRUE on success, or \c GL_FALSE on failure.
87 * This function calls __DriverAPIRec::UnbindContext, and then decrements
88 * __DRIdrawableRec::refcount which must be non-zero for a successful
91 * While casting the opaque private pointers associated with the parameters
92 * into their respective real types it also assures they are not \c NULL.
94 static int driUnbindContext(__DRIcontext
*pcp
)
101 ** Assume error checking is done properly in glXMakeCurrent before
102 ** calling driUnbindContext.
108 psp
= pcp
->driScreenPriv
;
109 pdp
= pcp
->driDrawablePriv
;
110 prp
= pcp
->driReadablePriv
;
112 /* already unbound */
115 /* Let driver unbind drawable from context */
116 (*psp
->DriverAPI
.UnbindContext
)(pcp
);
119 if (pdp
->refcount
== 0) {
124 dri_put_drawable(pdp
);
127 if (prp
->refcount
== 0) {
132 dri_put_drawable(prp
);
136 /* XXX this is disabled so that if we call SwapBuffers on an unbound
137 * window we can determine the last context bound to the window and
138 * use that context's lock. (BrianP, 2-Dec-2000)
140 pcp
->driDrawablePriv
= pcp
->driReadablePriv
= NULL
;
146 * This function takes both a read buffer and a draw buffer. This is needed
147 * for \c glXMakeCurrentReadSGI or GLX 1.3's \c glXMakeContextCurrent
150 static int driBindContext(__DRIcontext
*pcp
,
154 __DRIscreen
*psp
= NULL
;
157 ** Assume error checking is done properly in glXMakeCurrent before
158 ** calling driUnbindContext.
164 /* Bind the drawable to the context */
165 psp
= pcp
->driScreenPriv
;
166 pcp
->driDrawablePriv
= pdp
;
167 pcp
->driReadablePriv
= prp
;
169 pdp
->driContextPriv
= pcp
;
170 dri_get_drawable(pdp
);
172 if (prp
&& pdp
!= prp
) {
173 dri_get_drawable(prp
);
177 ** Now that we have a context associated with this drawable, we can
178 ** initialize the drawable information if has not been done before.
181 if (!psp
->dri2
.enabled
) {
182 if (pdp
&& !pdp
->pStamp
) {
183 DRM_SPINLOCK(&psp
->pSAREA
->drawable_lock
, psp
->drawLockID
);
184 __driUtilUpdateDrawableInfo(pdp
);
185 DRM_SPINUNLOCK(&psp
->pSAREA
->drawable_lock
, psp
->drawLockID
);
187 if (prp
&& pdp
!= prp
&& !prp
->pStamp
) {
188 DRM_SPINLOCK(&psp
->pSAREA
->drawable_lock
, psp
->drawLockID
);
189 __driUtilUpdateDrawableInfo(prp
);
190 DRM_SPINUNLOCK(&psp
->pSAREA
->drawable_lock
, psp
->drawLockID
);
194 /* Call device-specific MakeCurrent */
195 return (*psp
->DriverAPI
.MakeCurrent
)(pcp
, pdp
, prp
);
201 /*****************************************************************/
202 /** \name Drawable handling functions */
203 /*****************************************************************/
207 * Update private drawable information.
209 * \param pdp pointer to the private drawable information to update.
211 * This function basically updates the __DRIdrawable struct's
212 * cliprect information by calling \c __DRIinterfaceMethods::getDrawableInfo.
213 * This is usually called by the DRI_VALIDATE_DRAWABLE_INFO macro which
214 * compares the __DRIdrwablePrivate pStamp and lastStamp values. If
215 * the values are different that means we have to update the clipping
219 __driUtilUpdateDrawableInfo(__DRIdrawable
*pdp
)
221 __DRIscreen
*psp
= pdp
->driScreenPriv
;
222 __DRIcontext
*pcp
= pdp
->driContextPriv
;
225 || ((pdp
!= pcp
->driDrawablePriv
) && (pdp
!= pcp
->driReadablePriv
))) {
227 * ...but we must ignore it. There can be many contexts bound to a
232 if (pdp
->pClipRects
) {
233 free(pdp
->pClipRects
);
234 pdp
->pClipRects
= NULL
;
237 if (pdp
->pBackClipRects
) {
238 free(pdp
->pBackClipRects
);
239 pdp
->pBackClipRects
= NULL
;
242 DRM_SPINUNLOCK(&psp
->pSAREA
->drawable_lock
, psp
->drawLockID
);
244 if (! (*psp
->getDrawableInfo
->getDrawableInfo
)(pdp
,
245 &pdp
->index
, &pdp
->lastStamp
,
246 &pdp
->x
, &pdp
->y
, &pdp
->w
, &pdp
->h
,
247 &pdp
->numClipRects
, &pdp
->pClipRects
,
250 &pdp
->numBackClipRects
,
251 &pdp
->pBackClipRects
,
252 pdp
->loaderPrivate
)) {
253 /* Error -- eg the window may have been destroyed. Keep going
256 pdp
->pStamp
= &pdp
->lastStamp
; /* prevent endless loop */
257 pdp
->numClipRects
= 0;
258 pdp
->pClipRects
= NULL
;
259 pdp
->numBackClipRects
= 0;
260 pdp
->pBackClipRects
= NULL
;
263 pdp
->pStamp
= &(psp
->pSAREA
->drawableTable
[pdp
->index
].stamp
);
265 DRM_SPINLOCK(&psp
->pSAREA
->drawable_lock
, psp
->drawLockID
);
270 /*****************************************************************/
271 /** \name GLX callbacks */
272 /*****************************************************************/
275 static void driReportDamage(__DRIdrawable
*pdp
,
276 struct drm_clip_rect
*pClipRects
, int numClipRects
)
278 __DRIscreen
*psp
= pdp
->driScreenPriv
;
280 /* Check that we actually have the new damage report method */
282 /* Report the damage. Currently, all our drivers draw
283 * directly to the front buffer, so we report the damage there
284 * rather than to the backing storein (if any).
286 (*psp
->damage
->reportDamage
)(pdp
,
288 pClipRects
, numClipRects
,
289 GL_TRUE
, pdp
->loaderPrivate
);
297 * \param drawablePrivate opaque pointer to the per-drawable private info.
300 * This function calls __DRIdrawable::swapBuffers.
302 * Is called directly from glXSwapBuffers().
304 static void driSwapBuffers(__DRIdrawable
*dPriv
)
306 __DRIscreen
*psp
= dPriv
->driScreenPriv
;
307 drm_clip_rect_t
*rects
;
310 psp
->DriverAPI
.SwapBuffers(dPriv
);
312 if (!dPriv
->numClipRects
)
315 rects
= malloc(sizeof(*rects
) * dPriv
->numClipRects
);
320 for (i
= 0; i
< dPriv
->numClipRects
; i
++) {
321 rects
[i
].x1
= dPriv
->pClipRects
[i
].x1
- dPriv
->x
;
322 rects
[i
].y1
= dPriv
->pClipRects
[i
].y1
- dPriv
->y
;
323 rects
[i
].x2
= dPriv
->pClipRects
[i
].x2
- dPriv
->x
;
324 rects
[i
].y2
= dPriv
->pClipRects
[i
].y2
- dPriv
->y
;
327 driReportDamage(dPriv
, rects
, dPriv
->numClipRects
);
331 static int driDrawableGetMSC( __DRIscreen
*sPriv
, __DRIdrawable
*dPriv
,
334 return sPriv
->DriverAPI
.GetDrawableMSC(sPriv
, dPriv
, msc
);
338 static int driWaitForMSC(__DRIdrawable
*dPriv
, int64_t target_msc
,
339 int64_t divisor
, int64_t remainder
,
340 int64_t * msc
, int64_t * sbc
)
345 status
= dPriv
->driScreenPriv
->DriverAPI
.WaitForMSC( dPriv
, target_msc
,
349 /* GetSwapInfo() may not be provided by the driver if GLX_SGI_video_sync
350 * is supported but GLX_OML_sync_control is not. Therefore, don't return
351 * an error value if GetSwapInfo() is not implemented.
354 && dPriv
->driScreenPriv
->DriverAPI
.GetSwapInfo
) {
355 status
= dPriv
->driScreenPriv
->DriverAPI
.GetSwapInfo( dPriv
, & sInfo
);
356 *sbc
= sInfo
.swap_count
;
363 const __DRImediaStreamCounterExtension driMediaStreamCounterExtension
= {
364 { __DRI_MEDIA_STREAM_COUNTER
, __DRI_MEDIA_STREAM_COUNTER_VERSION
},
370 static void driCopySubBuffer(__DRIdrawable
*dPriv
,
371 int x
, int y
, int w
, int h
)
373 drm_clip_rect_t rect
;
376 rect
.y1
= dPriv
->h
- y
- h
;
378 rect
.y2
= rect
.y1
+ h
;
379 driReportDamage(dPriv
, &rect
, 1);
381 dPriv
->driScreenPriv
->DriverAPI
.CopySubBuffer(dPriv
, x
, y
, w
, h
);
384 const __DRIcopySubBufferExtension driCopySubBufferExtension
= {
385 { __DRI_COPY_SUB_BUFFER
, __DRI_COPY_SUB_BUFFER_VERSION
},
389 static void driSetSwapInterval(__DRIdrawable
*dPriv
, unsigned int interval
)
391 dPriv
->swap_interval
= interval
;
394 static unsigned int driGetSwapInterval(__DRIdrawable
*dPriv
)
396 return dPriv
->swap_interval
;
399 const __DRIswapControlExtension driSwapControlExtension
= {
400 { __DRI_SWAP_CONTROL
, __DRI_SWAP_CONTROL_VERSION
},
407 * This is called via __DRIscreenRec's createNewDrawable pointer.
409 static __DRIdrawable
*
410 driCreateNewDrawable(__DRIscreen
*psp
, const __DRIconfig
*config
,
411 drm_drawable_t hwDrawable
, int renderType
,
412 const int *attrs
, void *data
)
416 /* Since pbuffers are not yet supported, no drawable attributes are
421 pdp
= malloc(sizeof *pdp
);
426 pdp
->driContextPriv
= NULL
;
427 pdp
->loaderPrivate
= data
;
428 pdp
->hHWDrawable
= hwDrawable
;
437 pdp
->numClipRects
= 0;
438 pdp
->numBackClipRects
= 0;
439 pdp
->pClipRects
= NULL
;
440 pdp
->pBackClipRects
= NULL
;
444 pdp
->driScreenPriv
= psp
;
446 if (!(*psp
->DriverAPI
.CreateBuffer
)(psp
, pdp
, &config
->modes
,
447 renderType
== GLX_PIXMAP_BIT
)) {
454 /* This special default value is replaced with the configured
455 * default value when the drawable is first bound to a direct
458 pdp
->swap_interval
= (unsigned)-1;
464 static __DRIdrawable
*
465 dri2CreateNewDrawable(__DRIscreen
*screen
,
466 const __DRIconfig
*config
,
469 __DRIdrawable
*pdraw
;
471 pdraw
= driCreateNewDrawable(screen
, config
, 0, 0, NULL
, loaderPrivate
);
475 pdraw
->pClipRects
= &pdraw
->dri2
.clipRect
;
476 pdraw
->pBackClipRects
= &pdraw
->dri2
.clipRect
;
478 pdraw
->pStamp
= &pdraw
->dri2
.stamp
;
479 *pdraw
->pStamp
= pdraw
->lastStamp
+ 1;
485 dri2ConfigQueryb(__DRIscreen
*screen
, const char *var
, GLboolean
*val
)
487 if (!driCheckOption(&screen
->optionCache
, var
, DRI_BOOL
))
490 *val
= driQueryOptionb(&screen
->optionCache
, var
);
496 dri2ConfigQueryi(__DRIscreen
*screen
, const char *var
, GLint
*val
)
498 if (!driCheckOption(&screen
->optionCache
, var
, DRI_INT
) &&
499 !driCheckOption(&screen
->optionCache
, var
, DRI_ENUM
))
502 *val
= driQueryOptioni(&screen
->optionCache
, var
);
508 dri2ConfigQueryf(__DRIscreen
*screen
, const char *var
, GLfloat
*val
)
510 if (!driCheckOption(&screen
->optionCache
, var
, DRI_FLOAT
))
513 *val
= driQueryOptionf(&screen
->optionCache
, var
);
519 static void dri_get_drawable(__DRIdrawable
*pdp
)
524 static void dri_put_drawable(__DRIdrawable
*pdp
)
533 psp
= pdp
->driScreenPriv
;
534 (*psp
->DriverAPI
.DestroyBuffer
)(pdp
);
535 if (pdp
->pClipRects
&& pdp
->pClipRects
!= &pdp
->dri2
.clipRect
) {
536 free(pdp
->pClipRects
);
537 pdp
->pClipRects
= NULL
;
539 if (pdp
->pBackClipRects
&& pdp
->pClipRects
!= &pdp
->dri2
.clipRect
) {
540 free(pdp
->pBackClipRects
);
541 pdp
->pBackClipRects
= NULL
;
548 driDestroyDrawable(__DRIdrawable
*pdp
)
550 dri_put_drawable(pdp
);
556 /*****************************************************************/
557 /** \name Context handling functions */
558 /*****************************************************************/
562 * Destroy the per-context private information.
565 * This function calls __DriverAPIRec::DestroyContext on \p contextPrivate, calls
566 * drmDestroyContext(), and finally frees \p contextPrivate.
569 driDestroyContext(__DRIcontext
*pcp
)
572 (*pcp
->driScreenPriv
->DriverAPI
.DestroyContext
)(pcp
);
579 * Create the per-drawable private driver information.
581 * \param render_type Type of rendering target. \c GLX_RGBA is the only
582 * type likely to ever be supported for direct-rendering.
583 * \param shared Context with which to share textures, etc. or NULL
585 * \returns An opaque pointer to the per-context private information on
586 * success, or \c NULL on failure.
589 * This function allocates and fills a __DRIcontextRec structure. It
590 * performs some device independent initialization and passes all the
591 * relevent information to __DriverAPIRec::CreateContext to create the
595 static __DRIcontext
*
596 driCreateNewContext(__DRIscreen
*psp
, const __DRIconfig
*config
,
597 int render_type
, __DRIcontext
*shared
,
598 drm_context_t hwContext
, void *data
)
601 void * const shareCtx
= (shared
!= NULL
) ? shared
->driverPrivate
: NULL
;
603 pcp
= malloc(sizeof *pcp
);
607 pcp
->driScreenPriv
= psp
;
608 pcp
->driDrawablePriv
= NULL
;
609 pcp
->loaderPrivate
= data
;
611 pcp
->dri2
.draw_stamp
= 0;
612 pcp
->dri2
.read_stamp
= 0;
614 pcp
->hHWContext
= hwContext
;
616 if ( !(*psp
->DriverAPI
.CreateContext
)(API_OPENGL
,
617 &config
->modes
, pcp
, shareCtx
) ) {
626 dri2GetAPIMask(__DRIscreen
*screen
)
628 return screen
->api_mask
;
631 static __DRIcontext
*
632 dri2CreateNewContextForAPI(__DRIscreen
*screen
, int api
,
633 const __DRIconfig
*config
,
634 __DRIcontext
*shared
, void *data
)
636 __DRIcontext
*context
;
637 void *shareCtx
= (shared
!= NULL
) ? shared
->driverPrivate
: NULL
;
640 if (!(screen
->api_mask
& (1 << api
)))
644 case __DRI_API_OPENGL
:
645 mesa_api
= API_OPENGL
;
648 mesa_api
= API_OPENGLES
;
650 case __DRI_API_GLES2
:
651 mesa_api
= API_OPENGLES2
;
655 context
= malloc(sizeof *context
);
659 context
->driScreenPriv
= screen
;
660 context
->driDrawablePriv
= NULL
;
661 context
->loaderPrivate
= data
;
663 if (!(*screen
->DriverAPI
.CreateContext
)(api
, &config
->modes
,
664 context
, shareCtx
) ) {
673 static __DRIcontext
*
674 dri2CreateNewContext(__DRIscreen
*screen
, const __DRIconfig
*config
,
675 __DRIcontext
*shared
, void *data
)
677 return dri2CreateNewContextForAPI(screen
, __DRI_API_OPENGL
,
678 config
, shared
, data
);
682 driCopyContext(__DRIcontext
*dest
, __DRIcontext
*src
, unsigned long mask
)
690 /*****************************************************************/
691 /** \name Screen handling functions */
692 /*****************************************************************/
696 * Destroy the per-screen private information.
699 * This function calls __DriverAPIRec::DestroyScreen on \p screenPrivate, calls
700 * drmClose(), and finally frees \p screenPrivate.
702 static void driDestroyScreen(__DRIscreen
*psp
)
705 /* No interaction with the X-server is possible at this point. This
706 * routine is called after XCloseDisplay, so there is no protocol
707 * stream open to the X-server anymore.
710 if (psp
->DriverAPI
.DestroyScreen
)
711 (*psp
->DriverAPI
.DestroyScreen
)(psp
);
713 if (!psp
->dri2
.enabled
) {
714 (void)drmUnmap((drmAddress
)psp
->pSAREA
, SAREA_MAX
);
715 (void)drmUnmap((drmAddress
)psp
->pFB
, psp
->fbSize
);
716 (void)drmCloseOnce(psp
->fd
);
724 setupLoaderExtensions(__DRIscreen
*psp
,
725 const __DRIextension
**extensions
)
729 for (i
= 0; extensions
[i
]; i
++) {
730 if (strcmp(extensions
[i
]->name
, __DRI_GET_DRAWABLE_INFO
) == 0)
731 psp
->getDrawableInfo
= (__DRIgetDrawableInfoExtension
*) extensions
[i
];
732 if (strcmp(extensions
[i
]->name
, __DRI_DAMAGE
) == 0)
733 psp
->damage
= (__DRIdamageExtension
*) extensions
[i
];
734 if (strcmp(extensions
[i
]->name
, __DRI_SYSTEM_TIME
) == 0)
735 psp
->systemTime
= (__DRIsystemTimeExtension
*) extensions
[i
];
736 if (strcmp(extensions
[i
]->name
, __DRI_DRI2_LOADER
) == 0)
737 psp
->dri2
.loader
= (__DRIdri2LoaderExtension
*) extensions
[i
];
738 if (strcmp(extensions
[i
]->name
, __DRI_IMAGE_LOOKUP
) == 0)
739 psp
->dri2
.image
= (__DRIimageLookupExtension
*) extensions
[i
];
740 if (strcmp(extensions
[i
]->name
, __DRI_USE_INVALIDATE
) == 0)
741 psp
->dri2
.useInvalidate
= (__DRIuseInvalidateExtension
*) extensions
[i
];
746 * This is the bootstrap function for the driver. libGL supplies all of the
747 * requisite information about the system, and the driver initializes itself.
748 * This routine also fills in the linked list pointed to by \c driver_modes
749 * with the \c __GLcontextModes that the driver can support for windows or
754 * \param scrn Index of the screen
755 * \param ddx_version Version of the 2D DDX. This may not be meaningful for
757 * \param dri_version Version of the "server-side" DRI.
758 * \param drm_version Version of the kernel DRM.
759 * \param frame_buffer Data describing the location and layout of the
761 * \param pSAREA Pointer to the SAREA.
762 * \param fd Device handle for the DRM.
763 * \param extensions ??
764 * \param driver_modes Returns modes suppoted by the driver
765 * \param loaderPrivate ??
767 * \note There is no need to check the minimum API version in this
768 * function. Since the name of this function is versioned, it is
769 * impossible for a loader that is too old to even load this driver.
772 driCreateNewScreen(int scrn
,
773 const __DRIversion
*ddx_version
,
774 const __DRIversion
*dri_version
,
775 const __DRIversion
*drm_version
,
776 const __DRIframebuffer
*frame_buffer
,
777 drmAddress pSAREA
, int fd
,
778 const __DRIextension
**extensions
,
779 const __DRIconfig
***driver_modes
,
782 static const __DRIextension
*emptyExtensionList
[] = { NULL
};
785 psp
= calloc(1, sizeof *psp
);
789 setupLoaderExtensions(psp
, extensions
);
792 ** NOT_DONE: This is used by the X server to detect when the client
793 ** has died while holding the drawable lock. The client sets the
794 ** drawable lock to this value.
798 psp
->drm_version
= *drm_version
;
799 psp
->ddx_version
= *ddx_version
;
800 psp
->dri_version
= *dri_version
;
802 psp
->pSAREA
= pSAREA
;
803 psp
->lock
= (drmLock
*) &psp
->pSAREA
->lock
;
805 psp
->pFB
= frame_buffer
->base
;
806 psp
->fbSize
= frame_buffer
->size
;
807 psp
->fbStride
= frame_buffer
->stride
;
808 psp
->fbWidth
= frame_buffer
->width
;
809 psp
->fbHeight
= frame_buffer
->height
;
810 psp
->devPrivSize
= frame_buffer
->dev_priv_size
;
811 psp
->pDevPriv
= frame_buffer
->dev_priv
;
812 psp
->fbBPP
= psp
->fbStride
* 8 / frame_buffer
->width
;
814 psp
->extensions
= emptyExtensionList
;
817 psp
->dri2
.enabled
= GL_FALSE
;
819 psp
->DriverAPI
= driDriverAPI
;
820 psp
->api_mask
= (1 << __DRI_API_OPENGL
);
822 *driver_modes
= driDriverAPI
.InitScreen(psp
);
823 if (*driver_modes
== NULL
) {
835 dri2CreateNewScreen(int scrn
, int fd
,
836 const __DRIextension
**extensions
,
837 const __DRIconfig
***driver_configs
, void *data
)
839 static const __DRIextension
*emptyExtensionList
[] = { NULL
};
841 drmVersionPtr version
;
842 driOptionCache options
;
844 if (driDriverAPI
.InitScreen2
== NULL
)
847 psp
= calloc(1, sizeof(*psp
));
851 setupLoaderExtensions(psp
, extensions
);
853 version
= drmGetVersion(fd
);
855 psp
->drm_version
.major
= version
->version_major
;
856 psp
->drm_version
.minor
= version
->version_minor
;
857 psp
->drm_version
.patch
= version
->version_patchlevel
;
858 drmFreeVersion(version
);
861 psp
->extensions
= emptyExtensionList
;
864 psp
->dri2
.enabled
= GL_TRUE
;
866 psp
->DriverAPI
= driDriverAPI
;
867 psp
->api_mask
= (1 << __DRI_API_OPENGL
);
868 *driver_configs
= driDriverAPI
.InitScreen2(psp
);
869 if (*driver_configs
== NULL
) {
874 psp
->DriverAPI
= driDriverAPI
;
876 driParseOptionInfo(&options
, __dri2ConfigOptions
, __dri2NConfigOptions
);
877 driParseConfigFiles(&psp
->optionCache
, &options
, psp
->myNum
, "dri2");
882 static const __DRIextension
**driGetExtensions(__DRIscreen
*psp
)
884 return psp
->extensions
;
887 /** Core interface */
888 const __DRIcoreExtension driCoreExtension
= {
889 { __DRI_CORE
, __DRI_CORE_VERSION
},
894 driIndexConfigAttrib
,
905 /** Legacy DRI interface */
906 const __DRIlegacyExtension driLegacyExtension
= {
907 { __DRI_LEGACY
, __DRI_LEGACY_VERSION
},
909 driCreateNewDrawable
,
913 /** DRI2 interface */
914 const __DRIdri2Extension driDRI2Extension
= {
915 { __DRI_DRI2
, __DRI_DRI2_VERSION
},
917 dri2CreateNewDrawable
,
918 dri2CreateNewContext
,
920 dri2CreateNewContextForAPI
923 const __DRI2configQueryExtension dri2ConfigQueryExtension
= {
924 { __DRI2_CONFIG_QUERY
, __DRI2_CONFIG_QUERY_VERSION
},
931 driFrameTracking(__DRIdrawable
*drawable
, GLboolean enable
)
933 return GLX_BAD_CONTEXT
;
937 driQueryFrameTracking(__DRIdrawable
*dpriv
,
938 int64_t * sbc
, int64_t * missedFrames
,
939 float * lastMissedUsage
, float * usage
)
944 __DRIscreen
*psp
= dpriv
->driScreenPriv
;
946 status
= dpriv
->driScreenPriv
->DriverAPI
.GetSwapInfo( dpriv
, & sInfo
);
948 *sbc
= sInfo
.swap_count
;
949 *missedFrames
= sInfo
.swap_missed_count
;
950 *lastMissedUsage
= sInfo
.swap_missed_usage
;
952 (*psp
->systemTime
->getUST
)( & ust
);
953 *usage
= driCalculateSwapUsage( dpriv
, sInfo
.swap_ust
, ust
);
959 const __DRIframeTrackingExtension driFrameTrackingExtension
= {
960 { __DRI_FRAME_TRACKING
, __DRI_FRAME_TRACKING_VERSION
},
962 driQueryFrameTracking
966 * Calculate amount of swap interval used between GLX buffer swaps.
968 * The usage value, on the range [0,max], is the fraction of total swap
969 * interval time used between GLX buffer swaps is calculated.
971 * \f$p = t_d / (i * t_r)\f$
973 * Where \f$t_d\f$ is the time since the last GLX buffer swap, \f$i\f$ is the
974 * swap interval (as set by \c glXSwapIntervalSGI), and \f$t_r\f$ time
975 * required for a single vertical refresh period (as returned by \c
978 * See the documentation for the GLX_MESA_swap_frame_usage extension for more
981 * \param dPriv Pointer to the private drawable structure.
982 * \return If less than a single swap interval time period was required
983 * between GLX buffer swaps, a number greater than 0 and less than
984 * 1.0 is returned. If exactly one swap interval time period is
985 * required, 1.0 is returned, and if more than one is required then
986 * a number greater than 1.0 will be returned.
988 * \sa glXSwapIntervalSGI glXGetMscRateOML
990 * \todo Instead of caching the \c glXGetMscRateOML function pointer, would it
991 * be possible to cache the sync rate?
994 driCalculateSwapUsage( __DRIdrawable
*dPriv
, int64_t last_swap_ust
,
995 int64_t current_ust
)
1001 __DRIscreen
*psp
= dPriv
->driScreenPriv
;
1003 if ( (*psp
->systemTime
->getMSCRate
)(dPriv
, &n
, &d
, dPriv
->loaderPrivate
) ) {
1004 interval
= (dPriv
->swap_interval
!= 0) ? dPriv
->swap_interval
: 1;
1007 /* We want to calculate
1008 * (current_UST - last_swap_UST) / (interval * us_per_refresh). We get
1009 * current_UST by calling __glXGetUST. last_swap_UST is stored in
1010 * dPriv->swap_ust. interval has already been calculated.
1012 * The only tricky part is us_per_refresh. us_per_refresh is
1013 * 1000000 / MSC_rate. We know the MSC_rate is n / d. We can flip it
1014 * around and say us_per_refresh = 1000000 * d / n. Since this goes in
1015 * the denominator of the final calculation, we calculate
1016 * (interval * 1000000 * d) and move n into the numerator.
1019 usage
= (current_ust
- last_swap_ust
);
1021 usage
/= (interval
* d
);
1029 dri2InvalidateDrawable(__DRIdrawable
*drawable
)
1031 drawable
->dri2
.stamp
++;