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.

262 lines
8.3 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: glteb.h
  3. *
  4. * TEB related structures.
  5. *
  6. * Created: 12/27/1993
  7. * Author: Hock San Lee [hockl]
  8. *
  9. * Copyright (c) 1993-96 Microsoft Corporation
  10. \**************************************************************************/
  11. #ifndef __GLTEB_H__
  12. #define __GLTEB_H__
  13. #include <gldrv.h> // Dispatch table sizes
  14. #include "oleauto.h"
  15. #include "exttable.h"
  16. // OpenGL reserves a few entries in the NT TEB and allocates TLS storage to
  17. // keep thread local states.
  18. //
  19. // In Win95, the NT TEB storage is not available in the TEB and is made
  20. // part of its TLS storage.
  21. //
  22. // For code simplicity, a special NT_CURRENT_TEB macro is used to access
  23. // fields that are defined in NT TEB. Another macro CURRENT_GLTEBINFO is
  24. // used to access the other fields. This convention should be followed.
  25. // Shared section size
  26. #define SHARED_SECTION_SIZE 8192
  27. // Number of entries in the extended dispatch table
  28. #define GL_EXT_PROC_TABLE_SIZE (sizeof(GLEXTDISPATCHTABLE)/sizeof(PROC))
  29. // Offset of entries for extension functions. This offset must
  30. // be greater than all possible non-extension entries
  31. #define GL_EXT_PROC_TABLE_OFFSET OPENGL_VERSION_110_ENTRIES
  32. typedef struct _GLTEBINFO {
  33. // glCltDispatchTable must be the first field for the assembly code to work.
  34. // We pad the table with an extra entry if necessary to make glMsgBatchInfo
  35. // start at a qword boundary.
  36. PVOID glCltDispatchTable[(OPENGL_VERSION_110_ENTRIES+GL_EXT_PROC_TABLE_SIZE+1)/2*2];
  37. // This field must be qword aligned!
  38. BYTE glMsgBatchInfo[SHARED_SECTION_SIZE];
  39. #ifdef _WIN95_
  40. // These fields must match the NT TEB definitions!
  41. PVOID glDispatchTable[233]; // fast dispatch table
  42. ULONG glReserved1[29]; // POLYARRAY structure
  43. PVOID glReserved2; // pointer to POLYMATERIAL structure
  44. PVOID glSectionInfo; // generic server GC
  45. PVOID glSection; // Not used
  46. PVOID glTable; // Used only for NT x86
  47. PVOID glCurrentRC; // generic client RC
  48. PVOID glContext; // reserved by OpenGL ICD drivers
  49. #endif // _WIN95_
  50. } GLTEBINFO, *PGLTEBINFO;
  51. extern DWORD dwTlsOffset;
  52. #if !defined(_WIN95_)
  53. #if defined(_WIN64)
  54. #define TeglDispatchTable 0x9f0
  55. #define TeglReserved1 0x1138
  56. #define TeglReserved2 0x1220
  57. #define TeglSectionInfo 0x1228
  58. #define TeglSection 0x1230
  59. #define TeglTable 0x1238
  60. #define TeglCurrentRC 0x1240
  61. #define TeglContext 0x1248
  62. #else
  63. #define TeglDispatchTable 0x7c4
  64. #define TeglReserved1 0xb68
  65. #define TeglPaTeb 0xbb0
  66. #define TeglReserved2 0xbdc
  67. #define TeglSectionInfo 0xbe0
  68. #define TeglSection 0xbe4
  69. #define TeglTable 0xbe8
  70. #define TeglCurrentRC 0xbec
  71. #define TeglContext 0xbf0
  72. #endif
  73. #endif
  74. #if defined(_WIN95_) || !defined(_X86_)
  75. // Use NT_CURRENT_TEB to access the fields defined in NT TEB only!
  76. // Do not use it to access other fields such as glCltDispatchTable and
  77. // glMsgBatchInfo.
  78. // Use CURRENT_GLTEBINFO to access the fields *not* defined in NT TEB only!
  79. // E.g. glCltDispatchTable and glMsgBatchInfo.
  80. #ifdef _WIN95_
  81. #define NT_CURRENT_TEB() \
  82. (*(PGLTEBINFO *)((PBYTE)NtCurrentTeb()+dwTlsOffset))
  83. #else
  84. #define NT_CURRENT_TEB() \
  85. (NtCurrentTeb())
  86. #endif
  87. #define CURRENT_GLTEBINFO() \
  88. (*(PGLTEBINFO *)((PBYTE)NtCurrentTeb()+dwTlsOffset))
  89. #define SET_CURRENT_GLTEBINFO(pglti) \
  90. (*(PGLTEBINFO *)((PBYTE)NtCurrentTeb()+dwTlsOffset) = (pglti))
  91. // Cached POLYARRAY structure.
  92. #define GLTEB_CLTPOLYARRAY() \
  93. ((struct _POLYARRAY *)(NT_CURRENT_TEB()->glReserved1))
  94. // Pointer to POLYMATERIAL structure.
  95. #define GLTEB_CLTPOLYMATERIAL() \
  96. ((POLYMATERIAL *)(NT_CURRENT_TEB()->glReserved2))
  97. #define GLTEB_SET_CLTPOLYMATERIAL(pm) \
  98. (NT_CURRENT_TEB()->glReserved2 = (PVOID)(pm))
  99. // Table containing OpenGL function pointers for faster dispatch. Use this
  100. // table where possible.
  101. #define GLTEB_CLTDISPATCHTABLE_FAST() \
  102. ((PGLDISPATCHTABLE_FAST)(NT_CURRENT_TEB()->glDispatchTable))
  103. // Client side RC structure.
  104. #ifdef _WIN95_
  105. #define GLTEB_CLTCURRENTRC() \
  106. (NT_CURRENT_TEB() ? (PLRC)NT_CURRENT_TEB()->glCurrentRC : (PLRC)0)
  107. #else
  108. #define GLTEB_CLTCURRENTRC() \
  109. ((PLRC)NT_CURRENT_TEB()->glCurrentRC)
  110. #endif
  111. #define GLTEB_SET_CLTCURRENTRC(RC) \
  112. (NT_CURRENT_TEB()->glCurrentRC = (PVOID)(RC))
  113. // Client driver private data.
  114. #define GLTEB_CLTDRIVERSLOT() \
  115. (NT_CURRENT_TEB()->glContext)
  116. #define GLTEB_SET_CLTDRIVERSLOT(pv) \
  117. (NT_CURRENT_TEB()->glContext = (pv))
  118. #define GLTEB_SRVCONTEXT() \
  119. ((struct __GLcontextRec *)(NT_CURRENT_TEB()->glSectionInfo))
  120. #define GLTEB_SET_SRVCONTEXT(Context) \
  121. (NT_CURRENT_TEB()->glSectionInfo = (PVOID)(Context))
  122. #else // _WIN95_ || !_X86_
  123. #pragma warning(disable:4035) // Function doesn't return a value
  124. #define NT_CURRENT_TEB() \
  125. (NtCurrentTeb())
  126. __inline PGLTEBINFO CURRENT_GLTEBINFO(void)
  127. {
  128. __asm mov eax, [dwTlsOffset]
  129. __asm mov eax, fs:[eax]
  130. }
  131. __inline void SET_CURRENT_GLTEBINFO(PGLTEBINFO pglti)
  132. {
  133. __asm mov eax, pglti
  134. __asm mov edx, [dwTlsOffset]
  135. __asm mov fs:[edx], eax
  136. }
  137. // Cached POLYARRAY structure.
  138. // Returns cached linear pointer into TEB
  139. __inline struct _POLYARRAY *GLTEB_CLTPOLYARRAY(void)
  140. {
  141. __asm mov eax, fs:[TeglPaTeb]
  142. }
  143. // Pointer to POLYMATERIAL structure.
  144. __inline struct _POLYMATERIAL *GLTEB_CLTPOLYMATERIAL(void)
  145. {
  146. __asm mov eax, fs:[TeglReserved2]
  147. }
  148. __inline void GLTEB_SET_CLTPOLYMATERIAL(struct _POLYMATERIAL *pm)
  149. {
  150. __asm mov eax, pm
  151. __asm mov fs:[TeglReserved2], eax
  152. }
  153. // Table containing OpenGL function pointers for faster dispatch. Use this
  154. // table where possible.
  155. // Returns cached linear pointer into TEB
  156. __inline struct _GLDISPATCHTABLE_FAST *GLTEB_CLTDISPATCHTABLE_FAST(void)
  157. {
  158. __asm mov eax, fs:[TeglTable]
  159. }
  160. // Client side RC structure.
  161. __inline struct _LRC *GLTEB_CLTCURRENTRC(void)
  162. {
  163. __asm mov eax, fs:[TeglCurrentRC]
  164. }
  165. __inline void GLTEB_SET_CLTCURRENTRC(struct _LRC *RC)
  166. {
  167. __asm mov eax, RC
  168. __asm mov fs:[TeglCurrentRC], eax
  169. }
  170. // Client driver private data.
  171. __inline PVOID GLTEB_CLTDRIVERSLOT(void)
  172. {
  173. __asm mov eax, fs:[TeglContext]
  174. }
  175. __inline void GLTEB_SET_CLTDRIVERSLOT(PVOID pv)
  176. {
  177. __asm mov eax, pv
  178. __asm mov fs:[TeglContext], eax
  179. }
  180. __inline struct __GLcontextRec *GLTEB_SRVCONTEXT(void)
  181. {
  182. __asm mov eax, fs:[TeglSectionInfo]
  183. }
  184. __inline void GLTEB_SET_SRVCONTEXT(struct __GLcontextRec *Context)
  185. {
  186. __asm mov eax, Context
  187. __asm mov fs:[TeglSectionInfo], eax
  188. }
  189. #pragma warning(default:4035) // Reset to default
  190. #endif // _WIN95_ || !_X86_
  191. // Table containing all OpenGL API function pointers.
  192. #define GLTEB_CLTDISPATCHTABLE() \
  193. ((PGLDISPATCHTABLE)(CURRENT_GLTEBINFO()->glCltDispatchTable))
  194. // Table containing all generic implementation's extension function pointers.
  195. #define GLTEB_EXTDISPATCHTABLE() \
  196. ((PGLEXTDISPATCHTABLE)(CURRENT_GLTEBINFO()->glCltDispatchTable+GL_EXT_PROC_TABLE_OFFSET))
  197. // Command buffer for batching.
  198. #define GLTEB_SHAREDMEMORYSECTION() \
  199. ((GLMSGBATCHINFO *) (CURRENT_GLTEBINFO()->glMsgBatchInfo))
  200. // OpenGL function return value subbatch storage
  201. #define GLTEB_RETURNVALUE() \
  202. GLTEB_SHAREDMEMORYSECTION()->ReturnValue
  203. // Initialize both glCltDispatchTable and glDispatchTable with the new
  204. // function pointers.
  205. // glCltDispatchTable contains all OpenGL API function pointers followed
  206. // by the generic implementation's extension function pointers.
  207. // glDispatchTable contains a subset of OpenGL function pointers for "fast"
  208. // dispatch.
  209. extern void vInitTebCache(PVOID);
  210. extern void SetCltProcTable(struct _GLCLTPROCTABLE *pgcpt,
  211. struct _GLEXTPROCTABLE *pgept,
  212. BOOL fForce);
  213. extern void GetCltProcTable(struct _GLCLTPROCTABLE *pgcpt,
  214. struct _GLEXTPROCTABLE *pgept,
  215. BOOL fForce);
  216. #endif /* __GLTEB_H__ */