14642e01fSmrg/* 24642e01fSmrg * Copyright © 2007 Red Hat, Inc. 34642e01fSmrg * 44642e01fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 54642e01fSmrg * copy of this software and associated documentation files (the "Soft- 64642e01fSmrg * ware"), to deal in the Software without restriction, including without 74642e01fSmrg * limitation the rights to use, copy, modify, merge, publish, distribute, 84642e01fSmrg * and/or sell copies of the Software, and to permit persons to whom the 94642e01fSmrg * Software is furnished to do so, provided that the above copyright 104642e01fSmrg * notice(s) and this permission notice appear in all copies of the Soft- 114642e01fSmrg * ware and that both the above copyright notice(s) and this permission 124642e01fSmrg * notice appear in supporting documentation. 134642e01fSmrg * 144642e01fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 154642e01fSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- 164642e01fSmrg * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY 174642e01fSmrg * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN 184642e01fSmrg * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- 194642e01fSmrg * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 204642e01fSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 214642e01fSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- 224642e01fSmrg * MANCE OF THIS SOFTWARE. 234642e01fSmrg * 244642e01fSmrg * Except as contained in this notice, the name of a copyright holder shall 254642e01fSmrg * not be used in advertising or otherwise to promote the sale, use or 264642e01fSmrg * other dealings in this Software without prior written authorization of 274642e01fSmrg * the copyright holder. 284642e01fSmrg * 294642e01fSmrg * Authors: 304642e01fSmrg * Kristian Høgsberg (krh@redhat.com) 314642e01fSmrg */ 324642e01fSmrg 334642e01fSmrg#ifndef _DRI2_H_ 344642e01fSmrg#define _DRI2_H_ 354642e01fSmrg 364642e01fSmrg#include <X11/extensions/dri2tokens.h> 374642e01fSmrg 386747b715Smrg/* Version 2 structure (with format at the end) */ 394642e01fSmrgtypedef struct { 404642e01fSmrg unsigned int attachment; 414642e01fSmrg unsigned int name; 424642e01fSmrg unsigned int pitch; 434642e01fSmrg unsigned int cpp; 444642e01fSmrg unsigned int flags; 456747b715Smrg unsigned int format; 464642e01fSmrg void *driverPrivate; 474642e01fSmrg} DRI2BufferRec, *DRI2BufferPtr; 484642e01fSmrg 4935c4bbdfSmrgextern CARD8 dri2_major; /* version of DRI2 supported by DDX */ 506747b715Smrgextern CARD8 dri2_minor; 516747b715Smrg 526747b715Smrgtypedef DRI2BufferRec DRI2Buffer2Rec, *DRI2Buffer2Ptr; 5335c4bbdfSmrgtypedef void (*DRI2SwapEventPtr) (ClientPtr client, void *data, int type, 5435c4bbdfSmrg CARD64 ust, CARD64 msc, CARD32 sbc); 5535c4bbdfSmrg 5635c4bbdfSmrgtypedef DRI2BufferPtr(*DRI2CreateBuffersProcPtr) (DrawablePtr pDraw, 5735c4bbdfSmrg unsigned int *attachments, 5835c4bbdfSmrg int count); 5935c4bbdfSmrgtypedef void (*DRI2DestroyBuffersProcPtr) (DrawablePtr pDraw, 6035c4bbdfSmrg DRI2BufferPtr buffers, int count); 6135c4bbdfSmrgtypedef void (*DRI2CopyRegionProcPtr) (DrawablePtr pDraw, 6235c4bbdfSmrg RegionPtr pRegion, 6335c4bbdfSmrg DRI2BufferPtr pDestBuffer, 6435c4bbdfSmrg DRI2BufferPtr pSrcBuffer); 6535c4bbdfSmrgtypedef void (*DRI2WaitProcPtr) (WindowPtr pWin, unsigned int sequence); 6635c4bbdfSmrgtypedef int (*DRI2AuthMagicProcPtr) (int fd, uint32_t magic); 6735c4bbdfSmrgtypedef int (*DRI2AuthMagic2ProcPtr) (ScreenPtr pScreen, uint32_t magic); 684642e01fSmrg 696747b715Smrg/** 706747b715Smrg * Schedule a buffer swap 716747b715Smrg * 726747b715Smrg * This callback is used to support glXSwapBuffers and the OML_sync_control 736747b715Smrg * extension (see it for a description of the params). 746747b715Smrg * 756747b715Smrg * Drivers should queue an event for the frame count that satisfies the 766747b715Smrg * parameters passed in. If the event is in the future (i.e. the conditions 776747b715Smrg * aren't currently satisfied), the server may block the client at the next 786747b715Smrg * GLX request using DRI2WaitSwap. When the event arrives, drivers should call 796747b715Smrg * \c DRI2SwapComplete, which will handle waking the client and returning 806747b715Smrg * the appropriate data. 816747b715Smrg * 826747b715Smrg * The DDX is responsible for doing a flip, exchange, or blit of the swap 836747b715Smrg * when the corresponding event arrives. The \c DRI2CanFlip and 846747b715Smrg * \c DRI2CanExchange functions can be used as helpers for this purpose. 856747b715Smrg * 866747b715Smrg * \param client client pointer (used for block/unblock) 876747b715Smrg * \param pDraw drawable whose count we want 886747b715Smrg * \param pDestBuffer current front buffer 896747b715Smrg * \param pSrcBuffer current back buffer 906747b715Smrg * \param target_msc frame count to wait for 916747b715Smrg * \param divisor divisor for condition equation 926747b715Smrg * \param remainder remainder for division equation 936747b715Smrg * \param func function to call when the swap completes 946747b715Smrg * \param data data for the callback \p func. 956747b715Smrg */ 9635c4bbdfSmrgtypedef int (*DRI2ScheduleSwapProcPtr) (ClientPtr client, 9735c4bbdfSmrg DrawablePtr pDraw, 9835c4bbdfSmrg DRI2BufferPtr pDestBuffer, 9935c4bbdfSmrg DRI2BufferPtr pSrcBuffer, 10035c4bbdfSmrg CARD64 * target_msc, 10135c4bbdfSmrg CARD64 divisor, 10235c4bbdfSmrg CARD64 remainder, 10335c4bbdfSmrg DRI2SwapEventPtr func, void *data); 10435c4bbdfSmrgtypedef DRI2BufferPtr(*DRI2CreateBufferProcPtr) (DrawablePtr pDraw, 10535c4bbdfSmrg unsigned int attachment, 10635c4bbdfSmrg unsigned int format); 10735c4bbdfSmrgtypedef void (*DRI2DestroyBufferProcPtr) (DrawablePtr pDraw, 10835c4bbdfSmrg DRI2BufferPtr buffer); 10935c4bbdfSmrg/** 11035c4bbdfSmrg * Notifies driver when DRI2GetBuffers reuses a dri2 buffer. 11135c4bbdfSmrg * 11235c4bbdfSmrg * Driver may rename the dri2 buffer in this notify if it is required. 11335c4bbdfSmrg * 11435c4bbdfSmrg * \param pDraw drawable whose count we want 11535c4bbdfSmrg * \param buffer buffer that will be returned to client 11635c4bbdfSmrg */ 11735c4bbdfSmrgtypedef void (*DRI2ReuseBufferNotifyProcPtr) (DrawablePtr pDraw, 11835c4bbdfSmrg DRI2BufferPtr buffer); 1196747b715Smrg/** 1206747b715Smrg * Get current media stamp counter values 1216747b715Smrg * 1226747b715Smrg * This callback is used to support the SGI_video_sync and OML_sync_control 1236747b715Smrg * extensions. 1246747b715Smrg * 1256747b715Smrg * Drivers should return the current frame counter and the timestamp from 1266747b715Smrg * when the returned frame count was last incremented. 1276747b715Smrg * 1286747b715Smrg * The count should correspond to the screen where the drawable is currently 1296747b715Smrg * visible. If the drawable isn't visible (e.g. redirected), the server 1306747b715Smrg * should return BadDrawable to the client, pending GLX spec updates to 1316747b715Smrg * define this behavior. 1326747b715Smrg * 1336747b715Smrg * \param pDraw drawable whose count we want 1346747b715Smrg * \param ust timestamp from when the count was last incremented. 1356747b715Smrg * \param mst current frame count 1366747b715Smrg */ 13735c4bbdfSmrgtypedef int (*DRI2GetMSCProcPtr) (DrawablePtr pDraw, CARD64 * ust, 13835c4bbdfSmrg CARD64 * msc); 1396747b715Smrg/** 1406747b715Smrg * Schedule a frame count related wait 1416747b715Smrg * 1426747b715Smrg * This callback is used to support the SGI_video_sync and OML_sync_control 1436747b715Smrg * extensions. See those specifications for details on how to handle 1446747b715Smrg * the divisor and remainder parameters. 1456747b715Smrg * 1466747b715Smrg * Drivers should queue an event for the frame count that satisfies the 1476747b715Smrg * parameters passed in. If the event is in the future (i.e. the conditions 1486747b715Smrg * aren't currently satisfied), the driver should block the client using 1496747b715Smrg * \c DRI2BlockClient. When the event arrives, drivers should call 1506747b715Smrg * \c DRI2WaitMSCComplete, which will handle waking the client and returning 1516747b715Smrg * the appropriate data. 1526747b715Smrg * 1536747b715Smrg * \param client client pointer (used for block/unblock) 1546747b715Smrg * \param pDraw drawable whose count we want 1556747b715Smrg * \param target_msc frame count to wait for 1566747b715Smrg * \param divisor divisor for condition equation 1576747b715Smrg * \param remainder remainder for division equation 1586747b715Smrg */ 15935c4bbdfSmrgtypedef int (*DRI2ScheduleWaitMSCProcPtr) (ClientPtr client, 16035c4bbdfSmrg DrawablePtr pDraw, 16135c4bbdfSmrg CARD64 target_msc, 16235c4bbdfSmrg CARD64 divisor, CARD64 remainder); 16335c4bbdfSmrg 16435c4bbdfSmrgtypedef void (*DRI2InvalidateProcPtr) (DrawablePtr pDraw, void *data, XID id); 16535c4bbdfSmrg 16635c4bbdfSmrg/** 16735c4bbdfSmrg * DRI2 calls this hook when ever swap_limit is going to be changed. Default 16835c4bbdfSmrg * implementation for the hook only accepts one as swap_limit. If driver can 16935c4bbdfSmrg * support other swap_limits it has to implement supported limits with this 17035c4bbdfSmrg * callback. 17135c4bbdfSmrg * 172ed6184dfSmrg * \param pDraw drawable whose swap_limit is going to be changed 17335c4bbdfSmrg * \param swap_limit new swap_limit that going to be set 17435c4bbdfSmrg * \return TRUE if limit is support, FALSE if not. 17535c4bbdfSmrg */ 17635c4bbdfSmrgtypedef Bool (*DRI2SwapLimitValidateProcPtr) (DrawablePtr pDraw, 17735c4bbdfSmrg int swap_limit); 17835c4bbdfSmrg 17935c4bbdfSmrgtypedef DRI2BufferPtr(*DRI2CreateBuffer2ProcPtr) (ScreenPtr pScreen, 18035c4bbdfSmrg DrawablePtr pDraw, 18135c4bbdfSmrg unsigned int attachment, 18235c4bbdfSmrg unsigned int format); 18335c4bbdfSmrgtypedef void (*DRI2DestroyBuffer2ProcPtr) (ScreenPtr pScreen, DrawablePtr pDraw, 18435c4bbdfSmrg DRI2BufferPtr buffer); 1856747b715Smrg 18635c4bbdfSmrgtypedef void (*DRI2CopyRegion2ProcPtr) (ScreenPtr pScreen, DrawablePtr pDraw, 18735c4bbdfSmrg RegionPtr pRegion, 18835c4bbdfSmrg DRI2BufferPtr pDestBuffer, 18935c4bbdfSmrg DRI2BufferPtr pSrcBuffer); 19035c4bbdfSmrg 19135c4bbdfSmrg/** 19235c4bbdfSmrg * \brief Get the value of a parameter. 19335c4bbdfSmrg * 19435c4bbdfSmrg * The parameter's \a value is looked up on the screen associated with 19535c4bbdfSmrg * \a pDrawable. 19635c4bbdfSmrg * 19735c4bbdfSmrg * \return \c Success or error code. 19835c4bbdfSmrg */ 19935c4bbdfSmrgtypedef int (*DRI2GetParamProcPtr) (ClientPtr client, 20035c4bbdfSmrg DrawablePtr pDrawable, 20135c4bbdfSmrg CARD64 param, 20235c4bbdfSmrg BOOL *is_param_recognized, 20335c4bbdfSmrg CARD64 *value); 20452397711Smrg 20552397711Smrg/** 20652397711Smrg * Version of the DRI2InfoRec structure defined in this header 20752397711Smrg */ 20835c4bbdfSmrg#define DRI2INFOREC_VERSION 9 20952397711Smrg 2104642e01fSmrgtypedef struct { 21135c4bbdfSmrg unsigned int version; /**< Version of this struct */ 2124642e01fSmrg int fd; 2134642e01fSmrg const char *driverName; 2144642e01fSmrg const char *deviceName; 2154642e01fSmrg 21635c4bbdfSmrg DRI2CreateBufferProcPtr CreateBuffer; 21735c4bbdfSmrg DRI2DestroyBufferProcPtr DestroyBuffer; 21835c4bbdfSmrg DRI2CopyRegionProcPtr CopyRegion; 21935c4bbdfSmrg DRI2WaitProcPtr Wait; 2204642e01fSmrg 2216747b715Smrg /* added in version 4 */ 22252397711Smrg 22335c4bbdfSmrg DRI2ScheduleSwapProcPtr ScheduleSwap; 22435c4bbdfSmrg DRI2GetMSCProcPtr GetMSC; 22535c4bbdfSmrg DRI2ScheduleWaitMSCProcPtr ScheduleWaitMSC; 2266747b715Smrg 2276747b715Smrg /* number of drivers in the driverNames array */ 2286747b715Smrg unsigned int numDrivers; 2296747b715Smrg /* array of driver names, indexed by DRI2Driver* driver types */ 2306747b715Smrg /* a name of NULL means that driver is not supported */ 23135c4bbdfSmrg const char *const *driverNames; 2326747b715Smrg 2336747b715Smrg /* added in version 5 */ 2346747b715Smrg 23535c4bbdfSmrg DRI2AuthMagicProcPtr AuthMagic; 23635c4bbdfSmrg 23735c4bbdfSmrg /* added in version 6 */ 2384642e01fSmrg 23935c4bbdfSmrg DRI2ReuseBufferNotifyProcPtr ReuseBufferNotify; 24035c4bbdfSmrg DRI2SwapLimitValidateProcPtr SwapLimitValidate; 2416747b715Smrg 24235c4bbdfSmrg /* added in version 7 */ 24335c4bbdfSmrg DRI2GetParamProcPtr GetParam; 24435c4bbdfSmrg 24535c4bbdfSmrg /* added in version 8 */ 24635c4bbdfSmrg /* AuthMagic callback which passes extra context */ 24735c4bbdfSmrg /* If this is NULL the AuthMagic callback is used */ 24835c4bbdfSmrg /* If this is non-NULL the AuthMagic callback is ignored */ 24935c4bbdfSmrg DRI2AuthMagic2ProcPtr AuthMagic2; 25035c4bbdfSmrg 25135c4bbdfSmrg /* added in version 9 */ 25235c4bbdfSmrg DRI2CreateBuffer2ProcPtr CreateBuffer2; 25335c4bbdfSmrg DRI2DestroyBuffer2ProcPtr DestroyBuffer2; 25435c4bbdfSmrg DRI2CopyRegion2ProcPtr CopyRegion2; 25535c4bbdfSmrg} DRI2InfoRec, *DRI2InfoPtr; 25635c4bbdfSmrg 25735c4bbdfSmrgextern _X_EXPORT Bool DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info); 2584642e01fSmrg 2596747b715Smrgextern _X_EXPORT void DRI2CloseScreen(ScreenPtr pScreen); 2606747b715Smrg 2616747b715Smrgextern _X_EXPORT Bool DRI2HasSwapControl(ScreenPtr pScreen); 2624642e01fSmrg 26335c4bbdfSmrgextern _X_EXPORT Bool DRI2Connect(ClientPtr client, ScreenPtr pScreen, 26435c4bbdfSmrg unsigned int driverType, 26535c4bbdfSmrg int *fd, 26635c4bbdfSmrg const char **driverName, 26735c4bbdfSmrg const char **deviceName); 2684642e01fSmrg 26935c4bbdfSmrgextern _X_EXPORT Bool DRI2Authenticate(ClientPtr client, ScreenPtr pScreen, uint32_t magic); 2704642e01fSmrg 2716747b715Smrgextern _X_EXPORT int DRI2CreateDrawable(ClientPtr client, 27235c4bbdfSmrg DrawablePtr pDraw, 27335c4bbdfSmrg XID id, 27435c4bbdfSmrg DRI2InvalidateProcPtr invalidate, 27535c4bbdfSmrg void *priv); 27635c4bbdfSmrg 27735c4bbdfSmrgextern _X_EXPORT int DRI2CreateDrawable2(ClientPtr client, 27835c4bbdfSmrg DrawablePtr pDraw, 27935c4bbdfSmrg XID id, 28035c4bbdfSmrg DRI2InvalidateProcPtr invalidate, 28135c4bbdfSmrg void *priv, 28235c4bbdfSmrg XID *dri2_id_out); 2834642e01fSmrg 2846747b715Smrgextern _X_EXPORT DRI2BufferPtr *DRI2GetBuffers(DrawablePtr pDraw, 28535c4bbdfSmrg int *width, 28635c4bbdfSmrg int *height, 28735c4bbdfSmrg unsigned int *attachments, 28835c4bbdfSmrg int count, int *out_count); 2894642e01fSmrg 2906747b715Smrgextern _X_EXPORT int DRI2CopyRegion(DrawablePtr pDraw, 29135c4bbdfSmrg RegionPtr pRegion, 29235c4bbdfSmrg unsigned int dest, unsigned int src); 2934642e01fSmrg 29452397711Smrg/** 29552397711Smrg * Determine the major and minor version of the DRI2 extension. 29652397711Smrg * 29752397711Smrg * Provides a mechanism to other modules (e.g., 2D drivers) to determine the 29852397711Smrg * version of the DRI2 extension. While it is possible to peek directly at 29952397711Smrg * the \c XF86ModuleData from a layered module, such a module will fail to 30052397711Smrg * load (due to an unresolved symbol) if the DRI2 extension is not loaded. 30152397711Smrg * 302ed6184dfSmrg * \param major Location to store the major version of the DRI2 extension 303ed6184dfSmrg * \param minor Location to store the minor version of the DRI2 extension 30452397711Smrg * 30552397711Smrg * \note 30652397711Smrg * This interface was added some time after the initial release of the DRI2 30752397711Smrg * module. Layered modules that wish to use this interface must first test 308ed6184dfSmrg * its existence by calling \c xf86LoaderCheckSymbol. 30952397711Smrg */ 31052397711Smrgextern _X_EXPORT void DRI2Version(int *major, int *minor); 31152397711Smrg 3126747b715Smrgextern _X_EXPORT DRI2BufferPtr *DRI2GetBuffersWithFormat(DrawablePtr pDraw, 31335c4bbdfSmrg int *width, 31435c4bbdfSmrg int *height, 31535c4bbdfSmrg unsigned int 31635c4bbdfSmrg *attachments, 31735c4bbdfSmrg int count, 31835c4bbdfSmrg int *out_count); 31952397711Smrg 3206747b715Smrgextern _X_EXPORT void DRI2SwapInterval(DrawablePtr pDrawable, int interval); 32135c4bbdfSmrgextern _X_EXPORT Bool DRI2SwapLimit(DrawablePtr pDraw, int swap_limit); 3226747b715Smrgextern _X_EXPORT int DRI2SwapBuffers(ClientPtr client, DrawablePtr pDrawable, 32335c4bbdfSmrg CARD64 target_msc, CARD64 divisor, 32435c4bbdfSmrg CARD64 remainder, CARD64 * swap_target, 32535c4bbdfSmrg DRI2SwapEventPtr func, void *data); 3266747b715Smrgextern _X_EXPORT Bool DRI2WaitSwap(ClientPtr client, DrawablePtr pDrawable); 3276747b715Smrg 32835c4bbdfSmrgextern _X_EXPORT int DRI2GetMSC(DrawablePtr pDrawable, CARD64 * ust, 32935c4bbdfSmrg CARD64 * msc, CARD64 * sbc); 3306747b715Smrgextern _X_EXPORT int DRI2WaitMSC(ClientPtr client, DrawablePtr pDrawable, 33135c4bbdfSmrg CARD64 target_msc, CARD64 divisor, 33235c4bbdfSmrg CARD64 remainder); 3336747b715Smrgextern _X_EXPORT int ProcDRI2WaitMSCReply(ClientPtr client, CARD64 ust, 33435c4bbdfSmrg CARD64 msc, CARD64 sbc); 3356747b715Smrgextern _X_EXPORT int DRI2WaitSBC(ClientPtr client, DrawablePtr pDraw, 33635c4bbdfSmrg CARD64 target_sbc); 3376747b715Smrgextern _X_EXPORT Bool DRI2ThrottleClient(ClientPtr client, DrawablePtr pDraw); 3386747b715Smrg 3396747b715Smrgextern _X_EXPORT Bool DRI2CanFlip(DrawablePtr pDraw); 3406747b715Smrg 3416747b715Smrgextern _X_EXPORT Bool DRI2CanExchange(DrawablePtr pDraw); 3426747b715Smrg 3436747b715Smrg/* Note: use *only* for MSC related waits */ 3446747b715Smrgextern _X_EXPORT void DRI2BlockClient(ClientPtr client, DrawablePtr pDraw); 3456747b715Smrg 3466747b715Smrgextern _X_EXPORT void DRI2SwapComplete(ClientPtr client, DrawablePtr pDraw, 34735c4bbdfSmrg int frame, unsigned int tv_sec, 34835c4bbdfSmrg unsigned int tv_usec, int type, 34935c4bbdfSmrg DRI2SwapEventPtr swap_complete, 35035c4bbdfSmrg void *swap_data); 3516747b715Smrgextern _X_EXPORT void DRI2WaitMSCComplete(ClientPtr client, DrawablePtr pDraw, 35235c4bbdfSmrg int frame, unsigned int tv_sec, 35335c4bbdfSmrg unsigned int tv_usec); 35435c4bbdfSmrg 35535c4bbdfSmrgextern _X_EXPORT int DRI2GetParam(ClientPtr client, 35635c4bbdfSmrg DrawablePtr pDrawable, 35735c4bbdfSmrg CARD64 param, 35835c4bbdfSmrg BOOL *is_param_recognized, 35935c4bbdfSmrg CARD64 *value); 3606747b715Smrg 36135c4bbdfSmrgextern _X_EXPORT DrawablePtr DRI2UpdatePrime(DrawablePtr pDraw, DRI2BufferPtr pDest); 3624642e01fSmrg#endif 363