Leaked source code of windows server 2003
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.

396 lines
12 KiB

  1. /***************************************************************************\
  2. * Module Name: subutil.c
  3. *
  4. * Section initialization code for client/server batching.
  5. *
  6. * Copyright (c) 1993-1996 Microsoft Corporation
  7. \***************************************************************************/
  8. #include "precomp.h"
  9. #pragma hdrstop
  10. #include "glsbmsg.h"
  11. #include "glgdimsg.h"
  12. #include "batchinf.h"
  13. #include "glsbcltu.h"
  14. #include "wgldef.h"
  15. #include "compsize.h"
  16. #include "context.h"
  17. #include "global.h"
  18. #include "parray.h"
  19. #include "lighting.h"
  20. /******************************Public*Routine******************************\
  21. * glsbAttentionAlt
  22. *
  23. * Calls glsbAttention() from the GLCLIENT_BEGIN macro.
  24. * It puts a null proc at the end of the current batch and flushes the batch.
  25. *
  26. * Returns the new message offset and updates pMsgBatchInfo->NextOffset.
  27. * This code is dependent on the GLCLIENT_BEGIN macro!
  28. *
  29. * History:
  30. * Thu Nov 11 18:02:26 1993 -by- Hock San Lee [hockl]
  31. * Wrote it.
  32. \**************************************************************************/
  33. #ifdef CHECK_HEAP
  34. PVOID AttnLastCaller = 0, AttnLastCallersCaller = 0;
  35. DWORD AttnCallThread = 0;
  36. #endif
  37. ULONG APIENTRY glsbAttentionAlt(ULONG Offset)
  38. {
  39. GLMSGBATCHINFO *pMsgBatchInfo;
  40. ULONG MsgSize;
  41. PULONG pNullProcOffset;
  42. POLYARRAY *pa;
  43. POLYMATERIAL *pm;
  44. #ifdef PRIMITIVE_TRACK
  45. DbgPrint("*** glsbAttentionAlt\n");
  46. #endif
  47. pa = GLTEB_CLTPOLYARRAY();
  48. pMsgBatchInfo = (GLMSGBATCHINFO *) pa->pMsgBatchInfo;
  49. #ifdef CHECK_HEAP
  50. AttnCallThread = GetCurrentThreadId();
  51. RtlValidateHeap(RtlProcessHeap(), 0, 0);
  52. RtlGetCallersAddress(&AttnLastCaller, &AttnLastCallersCaller);
  53. #endif
  54. if (Offset == pMsgBatchInfo->FirstOffset)
  55. return(pMsgBatchInfo->FirstOffset); // No messages, return
  56. MsgSize = pMsgBatchInfo->NextOffset - Offset;
  57. // If we are in the begin/end bracket, remove the invalid commands issued
  58. // since the last Begin call.
  59. if (pa->flags & POLYARRAY_IN_BEGIN)
  60. {
  61. // DrawElements should not cause a flush while building polydata's.
  62. // pa->aIndices can be reset by VA_DrawElementsBegin, so allow
  63. // this value as well.
  64. ASSERTOPENGL( (!pa->aIndices ||
  65. (pa->aIndices == PA_aIndices_INITIAL_VALUE)),
  66. "unexpected flush in DrawElements\n");
  67. if (Offset == pa->nextMsgOffset)
  68. return(Offset);
  69. GLSETERROR(GL_INVALID_OPERATION);
  70. pMsgBatchInfo->NextOffset = pa->nextMsgOffset + MsgSize;
  71. return(pa->nextMsgOffset);
  72. }
  73. #ifdef PRIMITIVE_TRACK
  74. DbgPrint("! Reset on attention\n");
  75. #endif
  76. pa->pdBufferNext = pa->pdBuffer0; // reset vertex buffer pointer
  77. pa->nextMsgOffset = PA_nextMsgOffset_RESET_VALUE;
  78. if (pm = GLTEB_CLTPOLYMATERIAL())
  79. pm->iMat = 0; // reset material pointer
  80. pNullProcOffset = (ULONG *)((BYTE *)pMsgBatchInfo + Offset);
  81. *pNullProcOffset = 0;
  82. // #define POLYARRAY_CHECK_COLOR_POINTERS 1
  83. #if POLYARRAY_CHECK_COLOR_POINTERS
  84. {
  85. POLYDATA *pd;
  86. for (pd = pa->pdBuffer0; pd < pa->pdBufferMax; pd++)
  87. {
  88. if (pd->color != &pd->colors[__GL_FRONTFACE])
  89. DbgPrint("glsbAttentionAlt: pd 0x%x has modified color pointer\n", pd);
  90. }
  91. }
  92. #endif
  93. (void) __wglAttention();
  94. #if POLYARRAY_CHECK_COLOR_POINTERS
  95. {
  96. POLYDATA *pd;
  97. for (pd = pa->pdBuffer0; pd < pa->pdBufferMax; pd++)
  98. {
  99. if (pd->color != &pd->colors[__GL_FRONTFACE])
  100. DbgPrint("glsbAttentionAlt: pd 0x%x has BAD color pointer\n", pd);
  101. }
  102. }
  103. #endif
  104. pMsgBatchInfo->NextOffset = pMsgBatchInfo->FirstOffset + MsgSize;
  105. return(pMsgBatchInfo->FirstOffset);
  106. }
  107. /******************************Public*Routine******************************\
  108. * glsbAttention
  109. *
  110. * Let the server know that the section needs attention
  111. *
  112. * History:
  113. * 15-Oct-1993 -by- Gilman Wong [gilmanw]
  114. * Added bCheckRC flag.
  115. \**************************************************************************/
  116. BOOL APIENTRY
  117. glsbAttention ( void )
  118. {
  119. BOOL bRet = FALSE;
  120. GLMSGBATCHINFO *pMsgBatchInfo;
  121. PULONG pNullProcOffset;
  122. POLYARRAY *pa;
  123. POLYMATERIAL *pm;
  124. DWORD flags;
  125. __GL_SETUP();
  126. pa = GLTEB_CLTPOLYARRAY();
  127. pMsgBatchInfo = (GLMSGBATCHINFO *) pa->pMsgBatchInfo;
  128. #ifdef CHECK_HEAP
  129. AttnCallThread = GetCurrentThreadId();
  130. RtlValidateHeap(RtlProcessHeap(), 0, 0);
  131. RtlGetCallersAddress(&AttnLastCaller, &AttnLastCallersCaller);
  132. #endif
  133. if (pMsgBatchInfo->NextOffset == pMsgBatchInfo->FirstOffset)
  134. return(TRUE); // No messages, return
  135. // If we are in the begin/end bracket, remove the invalid commands issued
  136. // since the last Begin call.
  137. if (pa->flags & POLYARRAY_IN_BEGIN)
  138. {
  139. // DrawElements should not cause a flush while building polydata's.
  140. // pa->aIndices can be reset by VA_DrawElementsBegin, so allow
  141. // the reset value as well.
  142. ASSERTOPENGL( (!pa->aIndices ||
  143. (pa->aIndices == PA_aIndices_INITIAL_VALUE)),
  144. "unexpected flush in DrawElements\n");
  145. if (pMsgBatchInfo->NextOffset == pa->nextMsgOffset)
  146. return(TRUE);
  147. GLSETERROR(GL_INVALID_OPERATION);
  148. pMsgBatchInfo->NextOffset = pa->nextMsgOffset;
  149. return(TRUE);
  150. }
  151. #ifdef PRIMITIVE_TRACK
  152. DbgPrint("! Reset on attention\n");
  153. #endif
  154. pa->pdBufferNext = pa->pdBuffer0; // reset vertex buffer pointer
  155. pa->nextMsgOffset = PA_nextMsgOffset_RESET_VALUE; // reset next DPA message offset
  156. if (pm = GLTEB_CLTPOLYMATERIAL())
  157. pm->iMat = 0; // reset material pointer
  158. pNullProcOffset = (ULONG *)((BYTE *)pMsgBatchInfo + pMsgBatchInfo->NextOffset);
  159. *pNullProcOffset = 0;
  160. #if POLYARRAY_CHECK_COLOR_POINTERS
  161. {
  162. POLYDATA *pd;
  163. for (pd = pa->pdBuffer0; pd < pa->pdBufferMax; pd++)
  164. {
  165. if (pd->color != &pd->colors[__GL_FRONTFACE])
  166. DbgPrint("glsbAttention: pd 0x%x has modified color pointer\n", pd);
  167. }
  168. }
  169. #endif
  170. bRet = __wglAttention();
  171. #if POLYARRAY_CHECK_COLOR_POINTERS
  172. {
  173. POLYDATA *pd;
  174. for (pd = pa->pdBuffer0; pd < pa->pdBufferMax; pd++)
  175. {
  176. if (pd->color != &pd->colors[__GL_FRONTFACE])
  177. DbgPrint("glsbAttention: pd 0x%x has BAD color pointer\n", pd);
  178. }
  179. }
  180. #endif
  181. // Clear the Evaluator state flags
  182. flags = GET_EVALSTATE (gc);
  183. flags = flags & ~(__EVALS_AFFECTS_1D_EVAL|
  184. __EVALS_AFFECTS_2D_EVAL|
  185. __EVALS_AFFECTS_ALL_EVAL|
  186. __EVALS_PUSH_EVAL_ATTRIB|
  187. __EVALS_POP_EVAL_ATTRIB);
  188. SET_EVALSTATE (gc, flags);
  189. pMsgBatchInfo->NextOffset = pMsgBatchInfo->FirstOffset;
  190. return(bRet);
  191. }
  192. /******************************Public*Routine******************************\
  193. * glsbResetBuffers
  194. *
  195. * Reset the command buffer, the poly array buffer, and the poly material
  196. * buffer.
  197. *
  198. * History:
  199. * Tue Jan 09 17:38:22 1996 -by- Hock San Lee [hockl]
  200. * Wrote it.
  201. \**************************************************************************/
  202. VOID APIENTRY glsbResetBuffers(BOOL bRestoreColorPointer)
  203. {
  204. GLMSGBATCHINFO *pMsgBatchInfo;
  205. POLYARRAY *pa;
  206. POLYMATERIAL *pm;
  207. GLMSG_DRAWPOLYARRAY *pMsgDrawPolyArray;
  208. pa = GLTEB_CLTPOLYARRAY();
  209. // Reset command buffer
  210. pMsgBatchInfo = (GLMSGBATCHINFO *) pa->pMsgBatchInfo;
  211. pMsgBatchInfo->NextOffset = pMsgBatchInfo->FirstOffset;
  212. #ifdef PRIMITIVE_TRACK
  213. DbgPrint("! Reset on ResetBuffers\n");
  214. #endif
  215. #if POLYARRAY_CHECK_COLOR_POINTERS
  216. {
  217. POLYDATA *pd;
  218. for (pd = pa->pdBuffer0; pd < pa->pdBufferMax; pd++)
  219. {
  220. if (pd->color != &pd->colors[__GL_FRONTFACE])
  221. DbgPrint("glsbResetBuffers: pd 0x%x has modified color pointer\n",pd);
  222. }
  223. }
  224. #endif
  225. // In COMPILE mode, restore color pointer in the vertex buffer that
  226. // may have been overwritten by the POLYARRAY structure. In normal
  227. // and COMPILE_AND_EXECUTE modes, the server takes care of this.
  228. // In addition, there can be no more than one DrawPolyArray command
  229. // in the batch in COMPILE mode.
  230. if (bRestoreColorPointer)
  231. {
  232. POLYARRAY *paCmd;
  233. POLYDATA *pd, *pdLast;
  234. // See also PolyArrayRestoreColorPointer
  235. #if DBG
  236. __GL_SETUP();
  237. ASSERTOPENGL(gc->dlist.mode == GL_COMPILE, "not in compile mode\n");
  238. #endif
  239. pMsgDrawPolyArray = (GLMSG_DRAWPOLYARRAY *)
  240. ((BYTE *) pMsgBatchInfo + pa->nextMsgOffset -
  241. GLMSG_ALIGN(sizeof(GLMSG_DRAWPOLYARRAY)));
  242. paCmd = (POLYARRAY *) pMsgDrawPolyArray->paLast;
  243. ASSERTOPENGL(pMsgDrawPolyArray->pa0 == pMsgDrawPolyArray->paLast &&
  244. paCmd->paNext == NULL,
  245. "DrawPolyArray chain unexpected in COMPILE mode\n");
  246. // Reset color pointer in output index array
  247. if (paCmd->aIndices && (paCmd->aIndices != PA_aIndices_INITIAL_VALUE))
  248. {
  249. pdLast = (POLYDATA *) (paCmd->aIndices + paCmd->nIndices);
  250. for (pd = (POLYDATA *) paCmd->aIndices; pd < pdLast; pd++)
  251. pd->color = &pd->colors[__GL_FRONTFACE];
  252. ASSERTOPENGL(pd >= pa->pdBuffer0 &&
  253. pd <= pa->pdBufferMax + 1,
  254. "bad polyarray pointer\n");
  255. }
  256. // Reset color pointer in the POLYARRAY structure last!
  257. ASSERTOPENGL((POLYDATA *) paCmd >= pa->pdBuffer0 &&
  258. (POLYDATA *) paCmd <= pa->pdBufferMax,
  259. "bad polyarray pointer\n");
  260. ((POLYDATA *) paCmd)->color =
  261. &((POLYDATA *) paCmd)->colors[__GL_FRONTFACE];
  262. }
  263. // Reset material pointer
  264. if (pm = GLTEB_CLTPOLYMATERIAL())
  265. pm->iMat = 0;
  266. // Reset vertex buffer pointer
  267. pa->pdBufferNext = pa->pdBuffer0;
  268. // Reset next DPA message offset
  269. pa->nextMsgOffset = PA_nextMsgOffset_RESET_VALUE;
  270. #if POLYARRAY_CHECK_COLOR_POINTERS
  271. {
  272. POLYDATA *pd;
  273. for (pd = pa->pdBuffer0; pd < pa->pdBufferMax; pd++)
  274. {
  275. if (pd->color != &pd->colors[__GL_FRONTFACE])
  276. DbgPrint("glsbResetBuffers: pd 0x%x has BAD color pointer\n", pd);
  277. }
  278. }
  279. #endif
  280. }
  281. #if 0
  282. // REWRITE THIS IF NEEDED
  283. /******************************Public*Routine******************************\
  284. * glsbMsgStats
  285. *
  286. * Batch area statistics.
  287. *
  288. *
  289. * History:
  290. \**************************************************************************/
  291. BOOL APIENTRY
  292. glsbMsgStats ( LONG Action, GLMSGBATCHSTATS *BatchStats )
  293. {
  294. #ifdef DOGLMSGBATCHSTATS
  295. ULONG Result;
  296. GLMSGBATCHINFO *pMsgBatchInfo;
  297. pMsgBatchInfo = GLTEB_SHAREDMEMORYSECTION();
  298. if ( GLMSGBATCHSTATS_GETSTATS == Action )
  299. {
  300. BatchStats->ClientCalls = pMsgBatchInfo->BatchStats.ClientCalls;
  301. }
  302. else
  303. {
  304. pMsgBatchInfo->BatchStats.ClientCalls = 0;
  305. }
  306. // reset user's poll count so it counts this as output
  307. // put it right next to BEGINMSG so that NtCurrentTeb() is optimized
  308. RESETUSERPOLLCOUNT();
  309. BEGINMSG( MSG_GLMSGBATCHSTATS, GLSBMSGSTATS )
  310. pmsg->Action = Action;
  311. Result = CALLSERVER();
  312. if ( TRUE == Result )
  313. {
  314. if ( GLMSGBATCHSTATS_GETSTATS == Action )
  315. {
  316. BatchStats->ServerTrips = pmsg->BatchStats.ServerTrips;
  317. BatchStats->ServerCalls = pmsg->BatchStats.ServerCalls;
  318. }
  319. }
  320. else
  321. {
  322. DBGERROR("glsbMsgStats(): Server returned FALSE\n");
  323. }
  324. ENDMSG
  325. MSGERROR:
  326. return((BOOL)Result);
  327. #else
  328. return(FALSE);
  329. #endif /* DOGLMSGBATCHSTATS */
  330. }
  331. #endif // 0