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.

221 lines
6.3 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: dl_init.c
  3. *
  4. * Display list initialization and sharing rountines.
  5. *
  6. * Copyright (c) 1995-96 Microsoft Corporation
  7. \**************************************************************************/
  8. /*
  9. ** Copyright 1991-1993, Silicon Graphics, Inc.
  10. ** All Rights Reserved.
  11. **
  12. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  13. ** the contents of this file may not be disclosed to third parties, copied or
  14. ** duplicated in any form, in whole or in part, without the prior written
  15. ** permission of Silicon Graphics, Inc.
  16. **
  17. ** RESTRICTED RIGHTS LEGEND:
  18. ** Use, duplication or disclosure by the Government is subject to restrictions
  19. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  20. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  21. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  22. ** rights reserved under the Copyright Laws of the United States.
  23. **
  24. ** Display list init/destroy code.
  25. **
  26. ** $Revision: 1.7 $
  27. ** $Date: 1993/09/29 00:44:06 $
  28. */
  29. #include "precomp.h"
  30. #pragma hdrstop
  31. /*
  32. ** Empty data structure for display lists.
  33. */
  34. static __GLdlist emptyDlist = {
  35. 2, /* refcount, two so that it can never die */
  36. 0 /* Everything else, some initialized later */
  37. };
  38. static __GLnamesArrayTypeInfo dlistTypeInfo =
  39. {
  40. &emptyDlist,
  41. sizeof(__GLdlist),
  42. __glDisposeDlist,
  43. NULL
  44. };
  45. /*
  46. ** Used to share display lists between two different contexts.
  47. */
  48. #ifdef NT_SERVER_SHARE_LISTS
  49. GLboolean FASTCALL __glCanShareDlist(__GLcontext *gc, __GLcontext *shareMe)
  50. {
  51. GLboolean canShare = GL_TRUE;
  52. if (gc->dlist.namesArray != NULL)
  53. {
  54. __glNamesLockArray(gc, gc->dlist.namesArray);
  55. // Make sure we're not trying to replace a shared list
  56. // The spec also says that it is illegal for the new context
  57. // to have any display lists
  58. canShare = gc->dlist.namesArray->refcount == 1 &&
  59. gc->dlist.namesArray->tree == NULL &&
  60. shareMe->dlist.namesArray != NULL;
  61. __glNamesUnlockArray(gc, gc->dlist.namesArray);
  62. }
  63. return canShare;
  64. }
  65. #endif
  66. void FASTCALL __glShareDlist(__GLcontext *gc, __GLcontext *shareMe)
  67. {
  68. #ifdef NT_SERVER_SHARE_LISTS
  69. __glFreeDlistState(gc);
  70. __glNamesLockArray(gc, shareMe->dlist.namesArray);
  71. #endif
  72. gc->dlist.namesArray = shareMe->dlist.namesArray;
  73. gc->dlist.namesArray->refcount++;
  74. #ifdef NT_SERVER_SHARE_LISTS
  75. DBGLEVEL3(LEVEL_INFO, "Sharing dlists %p with %p, count %d\n", gc, shareMe,
  76. gc->dlist.namesArray->refcount);
  77. __glNamesUnlockArray(gc, shareMe->dlist.namesArray);
  78. #endif
  79. }
  80. void FASTCALL __glInitDlistState(__GLcontext *gc)
  81. {
  82. __GLdlistMachine *dlist;
  83. // This is required by the names management code
  84. ASSERTOPENGL(offsetof(__GLdlist, refcount) == 0,
  85. "Dlist refcount not at offset zero\n");
  86. // Set empty dlist to contain no entries
  87. emptyDlist.end = emptyDlist.head;
  88. dlist = &gc->dlist;
  89. dlist->nesting = 0;
  90. dlist->currentList = 0;
  91. dlist->listData = NULL;
  92. dlist->beginRec = NULL;
  93. ASSERTOPENGL(dlist->namesArray == NULL, "Dlist namesArray not NULL\n");
  94. dlist->namesArray = __glNamesNewArray(gc, &dlistTypeInfo);
  95. }
  96. void FASTCALL __glFreeDlistState(__GLcontext *gc)
  97. {
  98. __GLnamesArray *narray;
  99. narray = gc->dlist.namesArray;
  100. if (narray == NULL)
  101. {
  102. return;
  103. }
  104. #ifdef NT_SERVER_SHARE_LISTS
  105. __glNamesLockArray(gc, narray);
  106. // Clean up any lists that this context may have locked
  107. DlReleaseLocks(gc);
  108. #endif
  109. DBGLEVEL2(LEVEL_INFO, "Freeing dlists for %p, ref %d\n", gc,
  110. narray->refcount);
  111. narray->refcount--;
  112. if (narray->refcount == 0)
  113. {
  114. // NULL the array pointer first, preventing its reuse
  115. // after we unlock it. We need to unlock before we free it
  116. // because the critical section will be cleaned up in the
  117. // free
  118. gc->dlist.namesArray = NULL;
  119. // Decrement dlist refcounts and free them if they reach 0
  120. __glNamesFreeArray(gc, narray);
  121. }
  122. else
  123. {
  124. __glNamesUnlockArray(gc, narray);
  125. gc->dlist.namesArray = NULL;
  126. }
  127. if (gc->dlist.listData != NULL)
  128. {
  129. // We were in the middle of compiling a display list when this
  130. // function is called! Free the display list data.
  131. __glFreeDlist(gc, gc->dlist.listData);
  132. gc->dlist.listData = NULL;
  133. gc->dlist.currentList = 0;
  134. }
  135. }
  136. /******************************Public*Routine******************************\
  137. *
  138. * glsrvShareLists
  139. *
  140. * Server side implementation of wglShareLists
  141. *
  142. * History:
  143. * Tue Dec 13 17:14:18 1994 -by- Drew Bliss [drewb]
  144. * Created
  145. *
  146. \**************************************************************************/
  147. #ifdef NT_SERVER_SHARE_LISTS
  148. ULONG APIENTRY glsrvShareLists(__GLcontext *gcShare, __GLcontext *gcSource)
  149. {
  150. if (!__glCanShareDlist(gcShare, gcSource) ||
  151. !__glCanShareTextures(gcShare, gcSource))
  152. {
  153. return ERROR_INVALID_PARAMETER;
  154. }
  155. else
  156. {
  157. __glShareDlist(gcShare, gcSource);
  158. __glShareTextures(gcShare, gcSource);
  159. return ERROR_SUCCESS;
  160. }
  161. }
  162. #endif
  163. /******************************Public*Routine******************************\
  164. *
  165. * __glDlistThreadCleanup
  166. *
  167. * Performs thread-exit cleanup for dlist state
  168. *
  169. * History:
  170. * Mon Dec 19 13:22:38 1994 -by- Drew Bliss [drewb]
  171. * Created
  172. *
  173. \**************************************************************************/
  174. #ifdef NT_SERVER_SHARE_LISTS
  175. #if DBG
  176. // Critical section check routine from usersrv
  177. extern void APIENTRY CheckCritSectionOut(LPCRITICAL_SECTION pcs);
  178. #endif
  179. void __glDlistThreadCleanup(__GLcontext *gc)
  180. {
  181. #if DBG
  182. // Make sure we're not holding the display list critical section
  183. // We only hold this for short periods of time in our own code
  184. // so we should never be holding it unless we have bugs
  185. // In other words, it's ok to just assert this because no
  186. // client action can cause us to hold it
  187. CheckCritSectionOut(&gc->dlist.namesArray->critsec);
  188. #endif
  189. }
  190. #endif