Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

311 lines
10 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: mcdrvint.h
  3. *
  4. * Internal server-side data structure for MCD driver interface. The driver
  5. * never sees these...
  6. *
  7. * Copyright (c) 1996 Microsoft Corporation
  8. *
  9. \**************************************************************************/
  10. #ifndef _MCDRVINT_H
  11. #define _MCDRVINT_H
  12. #define MCD_ALLOC_TAG 'xDCM'
  13. #define MCD_MAX_ALLOC 0x40000
  14. #if DBG
  15. #define PRIVATE
  16. VOID MCDDebugPrint(char *, ...);
  17. #define MCDBG_PRINT MCDDebugPrint
  18. VOID MCDAssertFailed(char *, char *, int);
  19. #define MCDASSERT(expr, msg) \
  20. if (!(expr)) MCDAssertFailed(msg, __FILE__, __LINE__); else 0
  21. #else
  22. #define MCDBG_PRINT
  23. #define MCDASSERT(expr, msg)
  24. #define PRIVATE static
  25. #endif
  26. // Inline function to find the intersection of two rectangles:
  27. _inline void MCDIntersectRect(RECTL *pRectInter, RECTL *pRectA, RECTL *pRectB)
  28. {
  29. // Get intersection of left, right, top, and bottom edges of the
  30. // two source rectangles:
  31. pRectInter->left = max(pRectA->left, pRectB->left);
  32. pRectInter->right = min(pRectA->right, pRectB->right);
  33. pRectInter->top = max(pRectA->top, pRectB->top);
  34. pRectInter->bottom = min(pRectA->bottom, pRectB->bottom);
  35. }
  36. #define CHECK_MEM_RANGE_RETVAL(ptr, pMin, pMax, retval)\
  37. {\
  38. if (((char *)(ptr) > (char *)(pMax)) ||\
  39. ((char *)(ptr) < (char *)(pMin)))\
  40. {\
  41. MCDBG_PRINT("%s(%d): Buffer pointer out of range (%x [%x] %x).",__FILE__,__LINE__,pMin, ptr, pMax);\
  42. return retval;\
  43. }\
  44. }
  45. #define CHECK_SIZE_IN(pExec, structure)\
  46. {\
  47. if (sizeof(structure) > ((char *)pExec->pCmdEnd - (char *)pExec->pCmd)) {\
  48. MCDBG_PRINT("%s(%d): Input buffer too small",__FILE__,__LINE__);\
  49. return FALSE;\
  50. }\
  51. }
  52. #define CHECK_SIZE_OUT(pExec, structure)\
  53. {\
  54. if ((sizeof(structure) > pExec->cjOut) || (!pExec->pvOut)) {\
  55. MCDBG_PRINT("%s(%d): Output buffer too small: ptr[%x], size %d",__FILE__,__LINE__, pExec->pvOut, pExec->cjOut);\
  56. return FALSE;\
  57. }\
  58. }
  59. #define CHECK_FOR_RC(pExec)\
  60. if (!pExec->pRcPriv){ \
  61. MCDBG_PRINT("%s(%d): Invalid (null) RC",__FILE__,__LINE__);\
  62. return FALSE;\
  63. }
  64. #define CHECK_FOR_MEM(pExec)\
  65. if (!pExec->pMemObj){ \
  66. MCDBG_PRINT("%s(%d): Invalid or null shared memory",__FILE__,__LINE__);\
  67. return FALSE;\
  68. }
  69. #define CHECK_FOR_WND(pExec)\
  70. if (!pExec->pWndPriv){ \
  71. MCDBG_PRINT("%s(%d): Invalid window region", __FILE__, __LINE__);\
  72. return FALSE;\
  73. }
  74. #define GET_MEMOBJ_RETVAL(pMemObj, hMemObj, retval) \
  75. (pMemObj) = (MCDMEMOBJ *)MCDEngGetPtrFromHandle((MCDHANDLE)(hMemObj), \
  76. MCDHANDLE_MEM); \
  77. if (!(pMemObj)) \
  78. { \
  79. MCDBG_PRINT("%s(%d): Invalid handle for shared memory.", \
  80. __FILE__, __LINE__); \
  81. return retval; \
  82. } \
  83. if ((pMemObj)->lockCount) \
  84. { \
  85. MCDBG_PRINT("%s(%d): memory is locked by driver.", \
  86. __FILE__, __LINE__); \
  87. return retval; \
  88. }
  89. #define ENTER_MCD_LOCK()
  90. #define LEAVE_MCD_LOCK()
  91. // Number of list rectangles we can keep in our default buffer:
  92. #define NUM_DEFAULT_CLIP_BUFFER_RECTS 20
  93. // Size in bytes of default buffer size for storing our list of
  94. // current clip rectangles:
  95. #define SIZE_DEFAULT_CLIP_BUFFER \
  96. 2 * ((NUM_DEFAULT_CLIP_BUFFER_RECTS * sizeof(RECTL)) + sizeof(ULONG))
  97. //
  98. //
  99. //
  100. // Structures.
  101. //
  102. //
  103. //
  104. //
  105. typedef struct _MCDLOCKINFO
  106. {
  107. BOOL bLocked;
  108. struct _MCDWINDOWPRIV *pWndPrivOwner;
  109. } MCDLOCKINFO;
  110. typedef struct _MCDGLOBALINFO
  111. {
  112. SURFOBJ *pso;
  113. MCDLOCKINFO lockInfo;
  114. ULONG verMajor;
  115. ULONG verMinor;
  116. MCDDRIVER mcdDriver;
  117. MCDGLOBALDRIVERFUNCS mcdGlobalFuncs;
  118. } MCDGLOBALINFO;
  119. typedef struct _MCDRCOBJ MCDRCOBJ;
  120. typedef struct _MCDWINDOWPRIV {
  121. MCDWINDOW MCDWindow; // Put this first since we'll be deriving
  122. // MCDWINDOWPRIV from MCDWINDOW
  123. MCDHANDLE handle; // Driver handle for this window
  124. HWND hWnd; // Window with which this is associated
  125. MCDRCOBJ *objectList; // List of objects associated with this
  126. // window
  127. BOOL bRegionValid; // Do we have a valid region?
  128. MCDGLOBALINFO *pGlobal; // Driver global information
  129. MCDENUMRECTS *pClipUnscissored; // List of rectangles describing the
  130. // entire current clip region
  131. MCDENUMRECTS *pClipScissored; // List of rectangles describing the
  132. // entire current clip region + scissors
  133. char defaultClipBuffer[SIZE_DEFAULT_CLIP_BUFFER];
  134. // Used for storing above rectangle lists
  135. // when they can fit
  136. char *pAllocatedClipBuffer; // Points to allocated storage for storing
  137. // rectangle lists when they don't fit
  138. // in 'defaultClipBuffer'. NULL if
  139. // not allocated.
  140. ULONG sizeClipBuffer; // Size of clip storage pointed to by
  141. // 'pClipScissored' taking both
  142. // lists into account.
  143. BOOL bBuffersValid; // Validity of buffer cache.
  144. MCDRECTBUFFERS mbufCache; // Cached buffer information.
  145. WNDOBJ *pwo; // WNDOBJ for this window.
  146. } MCDWINDOWPRIV;
  147. typedef struct _MCDRCPRIV {
  148. MCDRC MCDRc;
  149. BOOL bValid;
  150. BOOL bDrvValid;
  151. HWND hWnd;
  152. HDEV hDev;
  153. RECTL scissorsRect;
  154. BOOL scissorsEnabled;
  155. LONG reserved[4];
  156. ULONG surfaceFlags; // surface flags with which RC was created
  157. MCDGLOBALINFO *pGlobal;
  158. } MCDRCPRIV;
  159. typedef enum {
  160. MCDHANDLE_RC,
  161. MCDHANDLE_MEM,
  162. MCDHANDLE_TEXTURE,
  163. MCDHANDLE_WINDOW
  164. } MCDHANDLETYPE;
  165. typedef struct _MCDTEXOBJ {
  166. MCDHANDLETYPE type; // Object type
  167. MCDTEXTURE MCDTexture;
  168. ULONG_PTR pid; // creator process ID
  169. ULONG size; // size of this structure
  170. MCDGLOBALINFO *pGlobal;
  171. } MCDTEXOBJ;
  172. typedef struct _MCDMEMOBJ {
  173. MCDHANDLETYPE type; // Object type
  174. MCDMEM MCDMem; // meat of the object
  175. ULONG_PTR pid; // creator process ID
  176. ULONG size; // size of this structure
  177. ULONG lockCount; // number of locks on the memory
  178. UCHAR *pMemBaseInternal; // internal pointer to memory
  179. MCDGLOBALINFO *pGlobal;
  180. } MCDMEMOBJ;
  181. typedef struct _MCDRCOBJ {
  182. MCDHANDLETYPE type;
  183. MCDRCPRIV *pRcPriv; // need this for driver free function
  184. ULONG_PTR pid; // creator process ID
  185. ULONG size; // size of the RC-bound object
  186. MCDHANDLE handle;
  187. MCDRCOBJ *next;
  188. } MCDRCOBJ;
  189. typedef struct _MCDWINDOWOBJ {
  190. MCDHANDLETYPE type;
  191. MCDWINDOWPRIV MCDWindowPriv;
  192. } MCDWINDOWOBJ;
  193. typedef struct _MCDEXEC {
  194. MCDESC_HEADER *pmeh; // MCDESC_HEADER for command buffer
  195. MCDHANDLE hMCDMem; // handle to command memory
  196. MCDCMDI *pCmd; // start of current command
  197. MCDCMDI *pCmdEnd; // end of command buffer
  198. PVOID pvOut; // output buffer
  199. LONG cjOut; // output buffer size
  200. LONG inBufferSize; // input buffer size
  201. struct _MCDRCPRIV *pRcPriv; // current rendering context
  202. struct _MCDWINDOWPRIV *pWndPriv; // window info
  203. struct _MCDGLOBALINFO *pGlobal; // global info
  204. MCDMEMOBJ *pMemObj; // shared-memory cache for commands/data
  205. MCDSURFACE MCDSurface; // device surface
  206. WNDOBJ **ppwoMulti; // Array of WNDOBJs for multi-swap
  207. HDEV hDev; // Engine handle (NT only)
  208. } MCDEXEC;
  209. ULONG_PTR MCDSrvProcess(MCDEXEC *pMCDExec);
  210. MCDHANDLE MCDSrvCreateContext(MCDSURFACE *pMCDSurface,
  211. MCDRCINFOPRIV *pMcdRcInfo,
  212. MCDGLOBALINFO *pGlobal,
  213. LONG iPixelFormat, LONG iLayer, HWND hWnd,
  214. ULONG surfaceFlags, ULONG contextFlags);
  215. MCDHANDLE MCDSrvCreateTexture(MCDEXEC *pMCDExec, MCDTEXTUREDATA *pTexData,
  216. VOID *pSurface, ULONG flags);
  217. UCHAR * MCDSrvAllocMem(MCDEXEC *pMCDExec, ULONG numBytes,
  218. ULONG flags, MCDHANDLE *phMem);
  219. ULONG MCDSrvQueryMemStatus(MCDEXEC *pMCDExec, MCDHANDLE hMCDMem);
  220. BOOL MCDSrvSetScissor(MCDEXEC *pMCDExec, RECTL *pRect, BOOL bEnabled);
  221. MCDWINDOW *MCDSrvNewMCDWindow(MCDSURFACE *pMCDSurface, HWND hWnd,
  222. MCDGLOBALINFO *pGlobal, HDEV hdev);
  223. BOOL CALLBACK FreeMemObj(DRIVEROBJ *pDrvObj);
  224. BOOL CALLBACK FreeTexObj(DRIVEROBJ *pDrvObj);
  225. BOOL CALLBACK FreeRCObj(DRIVEROBJ *pDrvObj);
  226. BOOL DestroyMCDObj(MCDHANDLE handle, MCDHANDLETYPE handleType);
  227. VOID GetScissorClip(MCDWINDOWPRIV *pWndPriv, MCDRCPRIV *pRcPriv);
  228. // Internal engine functions:
  229. WNDOBJ *MCDEngGetWndObj(MCDSURFACE *pMCDSurface);
  230. VOID MCDEngUpdateClipList(WNDOBJ *pwo);
  231. DRIVEROBJ *MCDEngLockObject(MCDHANDLE hObj);
  232. VOID MCDEngUnlockObject(MCDHANDLE hObj);
  233. WNDOBJ *MCDEngCreateWndObj(MCDSURFACE *pMCDSurface, HWND hWnd,
  234. WNDOBJCHANGEPROC pChangeProc);
  235. MCDHANDLE MCDEngCreateObject(VOID *pOject, FREEOBJPROC pFreeObjFunc,
  236. HDEV hDevEng);
  237. BOOL MCDEngDeleteObject(MCDHANDLE hObj);
  238. UCHAR *MCDEngAllocSharedMem(ULONG numBytes);
  239. VOID MCDEngFreeSharedMem(UCHAR *pMem);
  240. VOID *MCDEngGetPtrFromHandle(HANDLE handle, MCDHANDLETYPE type);
  241. ULONG_PTR MCDEngGetProcessID();
  242. // Debugging stuff:
  243. #if DBG
  244. UCHAR *MCDSrvDbgLocalAlloc(UINT, UINT);
  245. VOID MCDSrvDbgLocalFree(UCHAR *);
  246. #define MCDSrvLocalAlloc MCDSrvDbgLocalAlloc
  247. #define MCDSrvLocalFree MCDSrvDbgLocalFree
  248. VOID MCDebugPrint(char *, ...);
  249. #define MCDBG_PRINT MCDDebugPrint
  250. #else
  251. UCHAR *MCDSrvLocalAlloc(UINT, UINT);
  252. VOID MCDSrvLocalFree(UCHAR *);
  253. #define MCDBG_PRINT
  254. #endif
  255. #endif