1706f2543Smrg/* 2706f2543Smrg * Copyright © 2007 Red Hat, Inc. 3706f2543Smrg * 4706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5706f2543Smrg * copy of this software and associated documentation files (the "Soft- 6706f2543Smrg * ware"), to deal in the Software without restriction, including without 7706f2543Smrg * limitation the rights to use, copy, modify, merge, publish, distribute, 8706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the 9706f2543Smrg * Software is furnished to do so, provided that the above copyright 10706f2543Smrg * notice(s) and this permission notice appear in all copies of the Soft- 11706f2543Smrg * ware and that both the above copyright notice(s) and this permission 12706f2543Smrg * notice appear in supporting documentation. 13706f2543Smrg * 14706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15706f2543Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- 16706f2543Smrg * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY 17706f2543Smrg * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN 18706f2543Smrg * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- 19706f2543Smrg * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 20706f2543Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 21706f2543Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- 22706f2543Smrg * MANCE OF THIS SOFTWARE. 23706f2543Smrg * 24706f2543Smrg * Except as contained in this notice, the name of a copyright holder shall 25706f2543Smrg * not be used in advertising or otherwise to promote the sale, use or 26706f2543Smrg * other dealings in this Software without prior written authorization of 27706f2543Smrg * the copyright holder. 28706f2543Smrg * 29706f2543Smrg * Authors: 30706f2543Smrg * Kristian Høgsberg (krh@redhat.com) 31706f2543Smrg */ 32706f2543Smrg 33706f2543Smrg#ifndef _DRI2_H_ 34706f2543Smrg#define _DRI2_H_ 35706f2543Smrg 36706f2543Smrg#include <X11/extensions/dri2tokens.h> 37706f2543Smrg 38706f2543Smrg/* Version 2 structure (with format at the end) */ 39706f2543Smrgtypedef struct { 40706f2543Smrg unsigned int attachment; 41706f2543Smrg unsigned int name; 42706f2543Smrg unsigned int pitch; 43706f2543Smrg unsigned int cpp; 44706f2543Smrg unsigned int flags; 45706f2543Smrg unsigned int format; 46706f2543Smrg void *driverPrivate; 47706f2543Smrg} DRI2BufferRec, *DRI2BufferPtr; 48706f2543Smrg 49706f2543Smrgextern CARD8 dri2_major; /* version of DRI2 supported by DDX */ 50706f2543Smrgextern CARD8 dri2_minor; 51706f2543Smrg 52706f2543Smrgtypedef DRI2BufferRec DRI2Buffer2Rec, *DRI2Buffer2Ptr; 53706f2543Smrgtypedef void (*DRI2SwapEventPtr)(ClientPtr client, void *data, int type, 54706f2543Smrg CARD64 ust, CARD64 msc, CARD64 sbc); 55706f2543Smrg 56706f2543Smrg 57706f2543Smrgtypedef DRI2BufferPtr (*DRI2CreateBuffersProcPtr)(DrawablePtr pDraw, 58706f2543Smrg unsigned int *attachments, 59706f2543Smrg int count); 60706f2543Smrgtypedef void (*DRI2DestroyBuffersProcPtr)(DrawablePtr pDraw, 61706f2543Smrg DRI2BufferPtr buffers, 62706f2543Smrg int count); 63706f2543Smrgtypedef void (*DRI2CopyRegionProcPtr)(DrawablePtr pDraw, 64706f2543Smrg RegionPtr pRegion, 65706f2543Smrg DRI2BufferPtr pDestBuffer, 66706f2543Smrg DRI2BufferPtr pSrcBuffer); 67706f2543Smrgtypedef void (*DRI2WaitProcPtr)(WindowPtr pWin, 68706f2543Smrg unsigned int sequence); 69706f2543Smrgtypedef int (*DRI2AuthMagicProcPtr)(int fd, uint32_t magic); 70706f2543Smrg 71706f2543Smrg/** 72706f2543Smrg * Schedule a buffer swap 73706f2543Smrg * 74706f2543Smrg * This callback is used to support glXSwapBuffers and the OML_sync_control 75706f2543Smrg * extension (see it for a description of the params). 76706f2543Smrg * 77706f2543Smrg * Drivers should queue an event for the frame count that satisfies the 78706f2543Smrg * parameters passed in. If the event is in the future (i.e. the conditions 79706f2543Smrg * aren't currently satisfied), the server may block the client at the next 80706f2543Smrg * GLX request using DRI2WaitSwap. When the event arrives, drivers should call 81706f2543Smrg * \c DRI2SwapComplete, which will handle waking the client and returning 82706f2543Smrg * the appropriate data. 83706f2543Smrg * 84706f2543Smrg * The DDX is responsible for doing a flip, exchange, or blit of the swap 85706f2543Smrg * when the corresponding event arrives. The \c DRI2CanFlip and 86706f2543Smrg * \c DRI2CanExchange functions can be used as helpers for this purpose. 87706f2543Smrg * 88706f2543Smrg * \param client client pointer (used for block/unblock) 89706f2543Smrg * \param pDraw drawable whose count we want 90706f2543Smrg * \param pDestBuffer current front buffer 91706f2543Smrg * \param pSrcBuffer current back buffer 92706f2543Smrg * \param target_msc frame count to wait for 93706f2543Smrg * \param divisor divisor for condition equation 94706f2543Smrg * \param remainder remainder for division equation 95706f2543Smrg * \param func function to call when the swap completes 96706f2543Smrg * \param data data for the callback \p func. 97706f2543Smrg */ 98706f2543Smrgtypedef int (*DRI2ScheduleSwapProcPtr)(ClientPtr client, 99706f2543Smrg DrawablePtr pDraw, 100706f2543Smrg DRI2BufferPtr pDestBuffer, 101706f2543Smrg DRI2BufferPtr pSrcBuffer, 102706f2543Smrg CARD64 *target_msc, 103706f2543Smrg CARD64 divisor, 104706f2543Smrg CARD64 remainder, 105706f2543Smrg DRI2SwapEventPtr func, 106706f2543Smrg void *data); 107706f2543Smrgtypedef DRI2BufferPtr (*DRI2CreateBufferProcPtr)(DrawablePtr pDraw, 108706f2543Smrg unsigned int attachment, 109706f2543Smrg unsigned int format); 110706f2543Smrgtypedef void (*DRI2DestroyBufferProcPtr)(DrawablePtr pDraw, 111706f2543Smrg DRI2BufferPtr buffer); 112706f2543Smrg/** 113706f2543Smrg * Get current media stamp counter values 114706f2543Smrg * 115706f2543Smrg * This callback is used to support the SGI_video_sync and OML_sync_control 116706f2543Smrg * extensions. 117706f2543Smrg * 118706f2543Smrg * Drivers should return the current frame counter and the timestamp from 119706f2543Smrg * when the returned frame count was last incremented. 120706f2543Smrg * 121706f2543Smrg * The count should correspond to the screen where the drawable is currently 122706f2543Smrg * visible. If the drawable isn't visible (e.g. redirected), the server 123706f2543Smrg * should return BadDrawable to the client, pending GLX spec updates to 124706f2543Smrg * define this behavior. 125706f2543Smrg * 126706f2543Smrg * \param pDraw drawable whose count we want 127706f2543Smrg * \param ust timestamp from when the count was last incremented. 128706f2543Smrg * \param mst current frame count 129706f2543Smrg */ 130706f2543Smrgtypedef int (*DRI2GetMSCProcPtr)(DrawablePtr pDraw, CARD64 *ust, 131706f2543Smrg CARD64 *msc); 132706f2543Smrg/** 133706f2543Smrg * Schedule a frame count related wait 134706f2543Smrg * 135706f2543Smrg * This callback is used to support the SGI_video_sync and OML_sync_control 136706f2543Smrg * extensions. See those specifications for details on how to handle 137706f2543Smrg * the divisor and remainder parameters. 138706f2543Smrg * 139706f2543Smrg * Drivers should queue an event for the frame count that satisfies the 140706f2543Smrg * parameters passed in. If the event is in the future (i.e. the conditions 141706f2543Smrg * aren't currently satisfied), the driver should block the client using 142706f2543Smrg * \c DRI2BlockClient. When the event arrives, drivers should call 143706f2543Smrg * \c DRI2WaitMSCComplete, which will handle waking the client and returning 144706f2543Smrg * the appropriate data. 145706f2543Smrg * 146706f2543Smrg * \param client client pointer (used for block/unblock) 147706f2543Smrg * \param pDraw drawable whose count we want 148706f2543Smrg * \param target_msc frame count to wait for 149706f2543Smrg * \param divisor divisor for condition equation 150706f2543Smrg * \param remainder remainder for division equation 151706f2543Smrg */ 152706f2543Smrgtypedef int (*DRI2ScheduleWaitMSCProcPtr)(ClientPtr client, 153706f2543Smrg DrawablePtr pDraw, 154706f2543Smrg CARD64 target_msc, 155706f2543Smrg CARD64 divisor, 156706f2543Smrg CARD64 remainder); 157706f2543Smrg 158706f2543Smrgtypedef void (*DRI2InvalidateProcPtr)(DrawablePtr pDraw, 159706f2543Smrg void *data); 160706f2543Smrg 161706f2543Smrg/** 162706f2543Smrg * Version of the DRI2InfoRec structure defined in this header 163706f2543Smrg */ 164706f2543Smrg#define DRI2INFOREC_VERSION 5 165706f2543Smrg 166706f2543Smrgtypedef struct { 167706f2543Smrg unsigned int version; /**< Version of this struct */ 168706f2543Smrg int fd; 169706f2543Smrg const char *driverName; 170706f2543Smrg const char *deviceName; 171706f2543Smrg 172706f2543Smrg DRI2CreateBufferProcPtr CreateBuffer; 173706f2543Smrg DRI2DestroyBufferProcPtr DestroyBuffer; 174706f2543Smrg DRI2CopyRegionProcPtr CopyRegion; 175706f2543Smrg DRI2WaitProcPtr Wait; 176706f2543Smrg 177706f2543Smrg /* added in version 4 */ 178706f2543Smrg 179706f2543Smrg DRI2ScheduleSwapProcPtr ScheduleSwap; 180706f2543Smrg DRI2GetMSCProcPtr GetMSC; 181706f2543Smrg DRI2ScheduleWaitMSCProcPtr ScheduleWaitMSC; 182706f2543Smrg 183706f2543Smrg /* number of drivers in the driverNames array */ 184706f2543Smrg unsigned int numDrivers; 185706f2543Smrg /* array of driver names, indexed by DRI2Driver* driver types */ 186706f2543Smrg /* a name of NULL means that driver is not supported */ 187706f2543Smrg const char * const *driverNames; 188706f2543Smrg 189706f2543Smrg /* added in version 5 */ 190706f2543Smrg 191706f2543Smrg DRI2AuthMagicProcPtr AuthMagic; 192706f2543Smrg} DRI2InfoRec, *DRI2InfoPtr; 193706f2543Smrg 194706f2543Smrgextern _X_EXPORT int DRI2EventBase; 195706f2543Smrg 196706f2543Smrgextern _X_EXPORT Bool DRI2ScreenInit(ScreenPtr pScreen, 197706f2543Smrg DRI2InfoPtr info); 198706f2543Smrg 199706f2543Smrgextern _X_EXPORT void DRI2CloseScreen(ScreenPtr pScreen); 200706f2543Smrg 201706f2543Smrgextern _X_EXPORT Bool DRI2HasSwapControl(ScreenPtr pScreen); 202706f2543Smrg 203706f2543Smrgextern _X_EXPORT Bool DRI2Connect(ScreenPtr pScreen, 204706f2543Smrg unsigned int driverType, 205706f2543Smrg int *fd, 206706f2543Smrg const char **driverName, 207706f2543Smrg const char **deviceName); 208706f2543Smrg 209706f2543Smrgextern _X_EXPORT Bool DRI2Authenticate(ScreenPtr pScreen, uint32_t magic); 210706f2543Smrg 211706f2543Smrgextern _X_EXPORT int DRI2CreateDrawable(ClientPtr client, 212706f2543Smrg DrawablePtr pDraw, 213706f2543Smrg XID id, 214706f2543Smrg DRI2InvalidateProcPtr invalidate, 215706f2543Smrg void *priv); 216706f2543Smrg 217706f2543Smrgextern _X_EXPORT void DRI2DestroyDrawable(DrawablePtr pDraw); 218706f2543Smrg 219706f2543Smrgextern _X_EXPORT DRI2BufferPtr *DRI2GetBuffers(DrawablePtr pDraw, 220706f2543Smrg int *width, 221706f2543Smrg int *height, 222706f2543Smrg unsigned int *attachments, 223706f2543Smrg int count, 224706f2543Smrg int *out_count); 225706f2543Smrg 226706f2543Smrgextern _X_EXPORT int DRI2CopyRegion(DrawablePtr pDraw, 227706f2543Smrg RegionPtr pRegion, 228706f2543Smrg unsigned int dest, 229706f2543Smrg unsigned int src); 230706f2543Smrg 231706f2543Smrg/** 232706f2543Smrg * Determine the major and minor version of the DRI2 extension. 233706f2543Smrg * 234706f2543Smrg * Provides a mechanism to other modules (e.g., 2D drivers) to determine the 235706f2543Smrg * version of the DRI2 extension. While it is possible to peek directly at 236706f2543Smrg * the \c XF86ModuleData from a layered module, such a module will fail to 237706f2543Smrg * load (due to an unresolved symbol) if the DRI2 extension is not loaded. 238706f2543Smrg * 239706f2543Smrg * \param major Location to store the major verion of the DRI2 extension 240706f2543Smrg * \param minor Location to store the minor verion of the DRI2 extension 241706f2543Smrg * 242706f2543Smrg * \note 243706f2543Smrg * This interface was added some time after the initial release of the DRI2 244706f2543Smrg * module. Layered modules that wish to use this interface must first test 245706f2543Smrg * its existance by calling \c xf86LoaderCheckSymbol. 246706f2543Smrg */ 247706f2543Smrgextern _X_EXPORT void DRI2Version(int *major, int *minor); 248706f2543Smrg 249706f2543Smrgextern _X_EXPORT DRI2BufferPtr *DRI2GetBuffersWithFormat(DrawablePtr pDraw, 250706f2543Smrg int *width, int *height, unsigned int *attachments, int count, 251706f2543Smrg int *out_count); 252706f2543Smrg 253706f2543Smrgextern _X_EXPORT void DRI2SwapInterval(DrawablePtr pDrawable, int interval); 254706f2543Smrgextern _X_EXPORT int DRI2SwapBuffers(ClientPtr client, DrawablePtr pDrawable, 255706f2543Smrg CARD64 target_msc, CARD64 divisor, 256706f2543Smrg CARD64 remainder, CARD64 *swap_target, 257706f2543Smrg DRI2SwapEventPtr func, void *data); 258706f2543Smrgextern _X_EXPORT Bool DRI2WaitSwap(ClientPtr client, DrawablePtr pDrawable); 259706f2543Smrg 260706f2543Smrgextern _X_EXPORT int DRI2GetMSC(DrawablePtr pDrawable, CARD64 *ust, 261706f2543Smrg CARD64 *msc, CARD64 *sbc); 262706f2543Smrgextern _X_EXPORT int DRI2WaitMSC(ClientPtr client, DrawablePtr pDrawable, 263706f2543Smrg CARD64 target_msc, CARD64 divisor, 264706f2543Smrg CARD64 remainder); 265706f2543Smrgextern _X_EXPORT int ProcDRI2WaitMSCReply(ClientPtr client, CARD64 ust, 266706f2543Smrg CARD64 msc, CARD64 sbc); 267706f2543Smrgextern _X_EXPORT int DRI2WaitSBC(ClientPtr client, DrawablePtr pDraw, 268706f2543Smrg CARD64 target_sbc); 269706f2543Smrgextern _X_EXPORT Bool DRI2ThrottleClient(ClientPtr client, DrawablePtr pDraw); 270706f2543Smrg 271706f2543Smrgextern _X_EXPORT Bool DRI2CanFlip(DrawablePtr pDraw); 272706f2543Smrg 273706f2543Smrgextern _X_EXPORT Bool DRI2CanExchange(DrawablePtr pDraw); 274706f2543Smrg 275706f2543Smrg/* Note: use *only* for MSC related waits */ 276706f2543Smrgextern _X_EXPORT void DRI2BlockClient(ClientPtr client, DrawablePtr pDraw); 277706f2543Smrg 278706f2543Smrgextern _X_EXPORT void DRI2SwapComplete(ClientPtr client, DrawablePtr pDraw, 279706f2543Smrg int frame, unsigned int tv_sec, 280706f2543Smrg unsigned int tv_usec, int type, 281706f2543Smrg DRI2SwapEventPtr swap_complete, 282706f2543Smrg void *swap_data); 283706f2543Smrgextern _X_EXPORT void DRI2WaitMSCComplete(ClientPtr client, DrawablePtr pDraw, 284706f2543Smrg int frame, unsigned int tv_sec, 285706f2543Smrg unsigned int tv_usec); 286706f2543Smrg 287706f2543Smrg#endif 288